Skip to content

Commit 74be69b

Browse files
committed
add logging in test_safety to continue when there is an exception
1 parent 5c3b37e commit 74be69b

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

test/dlc_tests/sanity/test_safety_check.py

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1098,22 +1098,33 @@ def test_safety(image):
10981098
json_str_safety_result = extract_json_from_safety_output(
10991099
safety_check.run_safety_check_on_container(docker_exec_cmd)
11001100
)
1101+
LOGGER.info(f"Safety check raw output: {json_str_safety_result}")
11011102
safety_result = json.loads(json_str_safety_result)["vulnerabilities"]
11021103
for vulnerability in safety_result:
11031104
package = vulnerability["package_name"]
11041105
affected_versions = vulnerability["vulnerable_spec"]
11051106
vulnerability_id = vulnerability["vulnerability_id"]
11061107

11071108
# Get the latest version of the package with vulnerability
1109+
LOGGER.info(f"Getting latest version for package: {package}")
11081110
latest_version = _get_latest_package_version(package)
1109-
# If the latest version of the package is also affected, igvnore this vulnerability
1110-
if Version(latest_version) in SpecifierSet(affected_versions):
1111-
# Version(x) gives an object that can be easily compared with another version, or with a SpecifierSet.
1112-
# Comparing two versions as a string has some edge cases which require us to write more code.
1113-
# SpecifierSet(x) takes a version constraint, such as "<=4.5.6", ">1.2.3", or ">=1.2,<3.4.5", and
1114-
# gives an object that can be easily compared against a Version object.
1115-
# https://packaging.pypa.io/en/latest/specifiers/
1116-
ignore_str += f" -i {vulnerability_id}"
1111+
LOGGER.info(f"Got latest version: {latest_version}")
1112+
try:
1113+
LOGGER.info(
1114+
f"Checking versions for {package}: latest={latest_version}, affected={affected_versions}"
1115+
)
1116+
# If the latest version of the package is also affected, igvnore this vulnerability
1117+
if Version(latest_version) in SpecifierSet(affected_versions):
1118+
# Version(x) gives an object that can be easily compared with another version, or with a SpecifierSet.
1119+
# Comparing two versions as a string has some edge cases which require us to write more code.
1120+
# SpecifierSet(x) takes a version constraint, such as "<=4.5.6", ">1.2.3", or ">=1.2,<3.4.5", and
1121+
# gives an object that can be easily compared against a Version object.
1122+
# https://packaging.pypa.io/en/latest/specifiers/
1123+
ignore_str += f" -i {vulnerability_id}"
1124+
except Exception as e:
1125+
LOGGER.error(f"Version check failed for {package}: {str(e)}")
1126+
continue
1127+
LOGGER.info(f"Running final safety check with ignore list: {ignore_str}")
11171128
assert (
11181129
safety_check.run_safety_check_with_ignore_list(docker_exec_cmd, ignore_str) == 0
11191130
), f"Safety test failed for {image}"

0 commit comments

Comments
 (0)