Skip to content

Commit 4e74a18

Browse files
authored
Merge pull request #177 from abnamro/2672644-improve-pipeline-execution-time
[#2672644] Improve resc-backend pipeline execution time, updated test dependencies for resc-backend, resc-vcs-scraper, resc-vcs-scanner and resc-helm-wizard
2 parents 742dcee + 5284b8c commit 4e74a18

File tree

24 files changed

+63
-65
lines changed

24 files changed

+63
-65
lines changed

.github/workflows/backend-ci.yaml

-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ jobs:
4848
run: |
4949
cd ${{ env.RESC_BACKEND_DIR }}
5050
pip install -r test-requirements.txt
51-
tox
5251
5352
- name: Test with pytest
5453
run: |

.github/workflows/vcs-scanner-ci.yaml

-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ jobs:
4949
run: |
5050
cd ${{ env.RESC_VCS_SCANNER_DIR }}
5151
pip install -r test-requirements.txt
52-
tox
5352
5453
- name: Test with pytest
5554
run: |

.github/workflows/vcs-scraper-ci.yaml

-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ jobs:
4848
run: |
4949
cd ${{ env.RESC_VCS_SCRAPER_DIR }}
5050
pip install -r test-requirements.txt
51-
tox
5251
5352
- name: Test with pytest
5453
run: |

components/resc-backend/requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ tomlkit==0.12.1
1515
python-multipart==0.0.6
1616
aiofiles==0.8.0
1717
GitPython==3.1.32
18-
packaging==21.3
18+
packaging==23.1
1919
fastapi-cache2==0.2.1
2020
redis==4.6.0

components/resc-backend/src/resc_backend/bin/rabbitmq_bootup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,5 @@ def bootstrap_rabbitmq_users():
5555

5656
server_up = wait_for_rabbitmq_server_to_up(rabbitmq_api_base_url=args.rabbitmq_url)
5757
if not server_up:
58-
raise Exception("Wait for rabbitmq server to up has been failed.")
58+
raise TimeoutError("Wait for rabbitmq server to up has been failed.")
5959
create_queue_user_and_set_permission(rabbitmq_api_base_url=args.rabbitmq_url)

components/resc-backend/src/resc_backend/helpers/rabbitmq/rabbitmq_initialization.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def create_user(rabbitmq_api_base_url: str, username: str, password: str, role:
7070
uri = rabbitmq_api_base_url + "/api/users/" + username
7171
user_data = {"password": password, "tags": role}
7272
response = requests.put(uri, json=user_data,
73-
auth=HTTPBasicAuth(rabbitmq_admin_user, rabbitmq_admin_password))
73+
auth=HTTPBasicAuth(rabbitmq_admin_user, rabbitmq_admin_password), timeout=10)
7474

7575
if hasattr(response, "status_code") and int(response.status_code) == 201:
7676
logger.info(f"User: {username} with role: {role} created successfully.")
@@ -110,7 +110,7 @@ def set_resource_permissions(rabbitmq_api_base_url: str, v_host: str, username:
110110
"read": read_resources_regex}
111111

112112
response = requests.put(uri, json=permission_data,
113-
auth=HTTPBasicAuth(rabbitmq_admin_user, rabbitmq_admin_password))
113+
auth=HTTPBasicAuth(rabbitmq_admin_user, rabbitmq_admin_password), timeout=10)
114114
if hasattr(response, "status_code") and int(response.status_code) == 201:
115115
logger.debug(f"vHost permission successfully assigned to user: {username} for vHost: {v_host}.")
116116
return True
@@ -155,7 +155,7 @@ def set_topic_permissions(rabbitmq_api_base_url: str, v_host: str, username: str
155155
topic_permission_data = {"exchange": topic_name, "write": write_permission, "read": read_permission}
156156

157157
response = requests.put(uri, json=topic_permission_data,
158-
auth=HTTPBasicAuth(rabbitmq_admin_user, rabbitmq_admin_password))
158+
auth=HTTPBasicAuth(rabbitmq_admin_user, rabbitmq_admin_password), timeout=10)
159159

160160
if hasattr(response, "status_code") and (int(response.status_code) == 201 or int(response.status_code) == 204):
161161
logger.debug(

components/resc-backend/src/resc_backend/resc_web_service/dependencies.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,8 @@ def check_db_initialized():
172172
not_found_tables.append(table_name)
173173

174174
if len(not_found_tables) > 0:
175-
raise Exception(f"Unable to determine existence of required table(s) "
176-
f"{', '.join(not_found_tables)}")
175+
raise RuntimeError(f"Unable to determine existence of required table(s) "
176+
f"{', '.join(not_found_tables)}")
177177
except Exception as ex:
178178
logger.error(f"Database is NOT connected or initialized | {ex} | Retrying...")
179179
raise

components/resc-backend/src/resc_backend/resc_web_service/schema/detailed_finding.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def build_commit_url(cls, values) -> Dict:
9898
file_path=values["file_path"],
9999
commit_id=values["commit_id"])
100100
else:
101-
raise Exception(f"Unsupported VCSProvider: {values['vcs_provider']}")
101+
raise NotImplementedError(f"Unsupported VCSProvider: {values['vcs_provider']}")
102102
return values
103103

104104
class Config:

components/resc-backend/src/resc_backend/resc_web_service_interface/findings.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def create_findings(url: str, findings: List[FindingCreate]) -> requests.Respons
2020
for finding in findings:
2121
findings_json.append(json.loads(finding.json()))
2222

23-
response = requests.post(api_url, json=findings_json, proxies={"http": "", "https": ""})
23+
response = requests.post(api_url, json=findings_json, proxies={"http": "", "https": ""}, timeout=10)
2424
return response
2525

2626

@@ -31,5 +31,5 @@ def create_findings_with_scan_id(url: str, findings: List[FindingCreate], scan_i
3131
for finding in findings:
3232
findings_json.append(json.loads(finding.json()))
3333

34-
response = requests.post(api_url, json=findings_json, proxies={"http": "", "https": ""})
34+
response = requests.post(api_url, json=findings_json, proxies={"http": "", "https": ""}, timeout=10)
3535
return response

components/resc-backend/src/resc_backend/resc_web_service_interface/repositories.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313

1414
def create_repository(url: str, repository: Repository):
1515
api_url = f"{url}{RWS_VERSION_PREFIX}{RWS_ROUTE_REPOSITORIES}"
16-
response = requests.post(api_url, data=repository.json(), proxies={"http": "", "https": ""})
16+
response = requests.post(api_url, data=repository.json(), proxies={"http": "", "https": ""}, timeout=10)
1717
return response
1818

1919

2020
def get_last_scan_for_repository(url: str, repository_id: int):
2121
api_url = f"{url}{RWS_VERSION_PREFIX}{RWS_ROUTE_REPOSITORIES}/{repository_id}{RWS_ROUTE_LAST_SCAN}"
22-
response = requests.get(api_url, proxies={"http": "", "https": ""})
22+
response = requests.get(api_url, proxies={"http": "", "https": ""}, timeout=10)
2323
return response

components/resc-backend/src/resc_backend/resc_web_service_interface/rule_packs.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
def upload_rule_pack_toml_file(url: str, rule_file_path: str):
1616
with open(rule_file_path, "rb") as toml_file:
1717
files = {"rule_file": ("RESC-SECRETS-RULE.toml", toml_file, "application/octet-stream")}
18-
response = requests.post(url=url, files=files, proxies={"http": "", "https": ""})
18+
response = requests.post(url=url, files=files, proxies={"http": "", "https": ""}, timeout=10)
1919
toml_file.close()
2020
return response
2121

@@ -25,7 +25,7 @@ def download_rule_pack_toml_file(rws_url: str, rule_pack_version: Optional[str]
2525
if rule_pack_version:
2626
params = {"rule_pack_version": rule_pack_version}
2727
response = requests.get(url=f"{rws_url}{RWS_VERSION_PREFIX}{RWS_ROUTE_RULE_PACKS}",
28-
params=params)
28+
params=params, timeout=10)
2929

3030
if response.status_code == 200:
3131
logger.debug(
@@ -42,5 +42,5 @@ def get_rule_packs(url: str, version: Optional[str] = None, active: Optional[boo
4242
params = {"active": active, "skip": skip, "limit": limit}
4343
if version:
4444
params["version"] = version
45-
response = requests.get(api_url, params=params, proxies={"http": "", "https": ""})
45+
response = requests.get(api_url, params=params, proxies={"http": "", "https": ""}, timeout=10)
4646
return response

components/resc-backend/src/resc_backend/resc_web_service_interface/scans.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@
1313

1414
def create_scan(url: str, scan: ScanCreate):
1515
api_url = f"{url}{RWS_VERSION_PREFIX}{RWS_ROUTE_SCANS}"
16-
response = requests.post(api_url, data=scan.json(), proxies={"http": "", "https": ""})
16+
response = requests.post(api_url, data=scan.json(), proxies={"http": "", "https": ""}, timeout=10)
1717
return response

components/resc-backend/src/resc_backend/resc_web_service_interface/vcs_instances.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@
1313

1414
def create_vcs_instance(url: str, vcs_instance: VCSInstanceCreate):
1515
api_url = f"{url}{RWS_VERSION_PREFIX}{RWS_ROUTE_VCS}"
16-
response = requests.post(api_url, data=vcs_instance.json(), proxies={"http": "", "https": ""})
16+
response = requests.post(api_url, data=vcs_instance.json(), proxies={"http": "", "https": ""}, timeout=10)
1717
return response
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
flake8==4.0.1
22
flake8-blind-except==0.2.1
3-
flake8-builtins==1.5.3
3+
flake8-builtins==2.1.0
44
flake8-polyfill==1.0.2
55
flake8-tabs==2.2.2
6-
flake8-variables-names==0.0.5
7-
isort==5.10.1
8-
pytest==7.1.2
9-
mock==4.0.2
10-
pytest-cov==2.10.0
11-
tox==3.23.1
12-
pylint==2.14.0
6+
flake8-variables-names==0.0.6
7+
isort==5.12.0
8+
pytest==7.4.1
9+
mock==5.1.0
10+
pytest-cov==4.1.0
11+
tox==4.11.1
12+
pylint==2.17.5
1313
pytest-asyncio==0.21.1
1414
httpx==0.24.1

components/resc-backend/tests/resc_backend/resc_web_service_interface/test_client_findings.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,4 @@ def test_create_findings(post):
3838

3939
_ = create_findings(url, findings)
4040
post.assert_called_once()
41-
post.assert_called_with(expected_url, json=findings_json, proxies={'http': '', 'https': ''})
41+
post.assert_called_with(expected_url, json=findings_json, proxies={'http': '', 'https': ''}, timeout=10)

components/resc-backend/tests/resc_backend/resc_web_service_interface/test_client_repositories.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ def test_create_repository(post):
2020

2121
_ = create_repository(url, repository)
2222
post.assert_called_once()
23-
post.assert_called_with(expected_url, data=expected_json, proxies={'http': '', 'https': ''})
23+
post.assert_called_with(expected_url, data=expected_json, proxies={'http': '', 'https': ''}, timeout=10)

components/resc-backend/tests/resc_backend/resc_web_service_interface/test_client_rule_packs.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def test_get_rule_packs(get):
1313

1414
_ = get_rule_packs(url)
1515
get.assert_called_once()
16-
get.assert_called_with(expected_url, params=expected_params, proxies={'http': '', 'https': ''})
16+
get.assert_called_with(expected_url, params=expected_params, proxies={'http': '', 'https': ''}, timeout=10)
1717

1818

1919
@patch("requests.get")
@@ -24,7 +24,7 @@ def test_get_rule_packs_when_version_provided(get):
2424

2525
_ = get_rule_packs(url=url, version="1.0.0")
2626
get.assert_called_once()
27-
get.assert_called_with(expected_url, params=expected_params, proxies={'http': '', 'https': ''})
27+
get.assert_called_with(expected_url, params=expected_params, proxies={'http': '', 'https': ''}, timeout=10)
2828

2929

3030
@patch("requests.get")
@@ -35,7 +35,7 @@ def test_get_rule_packs_when_active_provided(get):
3535

3636
_ = get_rule_packs(url=url, active=True)
3737
get.assert_called_once()
38-
get.assert_called_with(expected_url, params=expected_params, proxies={'http': '', 'https': ''})
38+
get.assert_called_with(expected_url, params=expected_params, proxies={'http': '', 'https': ''}, timeout=10)
3939

4040

4141
@patch("requests.get")
@@ -46,4 +46,4 @@ def test_get_rule_packs_when_version_and_active_provided(get):
4646

4747
_ = get_rule_packs(url=url, version="1.0.0", active=False)
4848
get.assert_called_once()
49-
get.assert_called_with(expected_url, params=expected_params, proxies={'http': '', 'https': ''})
49+
get.assert_called_with(expected_url, params=expected_params, proxies={'http': '', 'https': ''}, timeout=10)

components/resc-backend/tests/resc_backend/resc_web_service_interface/test_client_scans.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ def test_create_scan(post):
1818

1919
_ = create_scan(url, scan)
2020
post.assert_called_once()
21-
post.assert_called_with(expected_url, data=expected_json, proxies={'http': '', 'https': ''})
21+
post.assert_called_with(expected_url, data=expected_json, proxies={'http': '', 'https': ''}, timeout=10)

components/resc-backend/tests/resc_backend/resc_web_service_interface/test_client_vcs_instances.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ def test_create_vcs_instance(post):
1919

2020
_ = create_vcs_instance(url, vcs_instance)
2121
post.assert_called_once()
22-
post.assert_called_with(expected_url, data=expected_json, proxies={'http': '', 'https': ''})
22+
post.assert_called_with(expected_url, data=expected_json, proxies={'http': '', 'https': ''}, timeout=10)
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
flake8==4.0.1
22
flake8-blind-except==0.2.1
3-
flake8-builtins==1.5.3
3+
flake8-builtins==2.1.0
44
flake8-polyfill==1.0.2
55
flake8-tabs==2.2.2
6-
flake8-variables-names==0.0.5
7-
isort==5.10.1
8-
pytest==7.1.2
9-
mock==4.0.2
10-
pytest-cov==2.10.0
11-
tox==3.23.1
12-
pylint==2.14.0
6+
flake8-variables-names==0.0.6
7+
isort==5.12.0
8+
pytest==7.4.1
9+
mock==5.1.0
10+
pytest-cov==4.1.0
11+
tox==4.11.1
12+
pylint==2.17.5

components/resc-vcs-scraper/src/vcs_scraper/project_collector/common.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import logging
33

44
# Third Party
5+
from celery.exceptions import CeleryError
56
from tenacity import RetryError, Retrying, stop_after_attempt, wait_exponential
67

78
# First Party
@@ -67,7 +68,7 @@ def collect_projects_from_vcs_instance(vcs_instance: VCSInstance) -> None:
6768
celery_client.send_task(task_name, kwargs={"project_key": project_name,
6869
"vcs_instance_name": vcs_instance.name},
6970
queue=destination_message_queue)
70-
except Exception as exc:
71+
except CeleryError as exc:
7172
logger.error(f"{exc} sending '{project_name}' to 'projects'. Retrying ...")
7273
raise
7374
projects_sent += 1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
flake8==3.9.2
2-
flake8-blind-except==0.1.1
3-
flake8-builtins==1.5.3
1+
flake8==4.0.1
2+
flake8-blind-except==0.2.1
3+
flake8-builtins==2.1.0
44
flake8-polyfill==1.0.2
55
flake8-tabs==2.2.2
6-
flake8-variables-names==0.0.3
7-
isort==4.3.21
8-
pytest==7.1.2
9-
mock==4.0.2
10-
pytest-cov==2.10.0
11-
tox==3.23.1
12-
pylint==2.14.5
6+
flake8-variables-names==0.0.6
7+
isort==5.12.0
8+
pytest==7.4.1
9+
mock==5.1.0
10+
pytest-cov==4.1.0
11+
tox==4.11.1
12+
pylint==2.17.5

deployment/resc-helm-wizard/README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,10 @@ See below commands for running various (unit/linting) tests locally. To run thes
8585

8686
Run below commands to make sure that the unit tests are running and that the code matches quality standards:
8787
```bash
88-
pip install tox # install tox locally
88+
pip install tox # install tox locally
8989

90-
tox -v -e sort # Run this command to validate the import sorting
91-
tox -v -e lint # Run this command to lint the code according to this repository's standard
92-
tox -v -e pytest # Run this command to run the unit tests
93-
tox -v # Run this command to run all of the above tests
90+
tox run -e py -v # Run this command to run the unit tests
91+
tox run -e isort -v # Run this command to validate the import sorting
92+
tox run -e pylint -v # Run this command for Python static code analysis
93+
tox run -e flake8 -v # Run this command for Python linting
9494
```
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
flake8==6.0.0
1+
flake8==6.1.0
22
isort==5.12.0
3-
pytest==7.2.1
4-
pytest-cov==4.0.0
5-
tox==3.23.1
6-
pylint==2.16.2
3+
pytest==7.4.1
4+
pytest-cov==4.1.0
5+
tox==4.11.1
6+
pylint==2.17.5

0 commit comments

Comments
 (0)