Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not retry hardened test if report was already generated #380

Merged
merged 2 commits into from
Apr 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions usr/share/lib/img_proof/tests/SLES/test_sles_hardened.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# Workaround for OOM killer triggered by the issue
# https://github.com/OpenSCAP/openscap/issues/1796
def setup_swap(host, swap_file=SWAP_FILE):
if os.path.exists(swap_file):
if host.file(swap_file).exists:
return True
# Follow steps in https://btrfs.readthedocs.io/en/latest/Swapfile.html
for command in [
Expand Down Expand Up @@ -41,6 +41,16 @@ def test_sles_hardened(host, get_release_value, is_sles_sap, is_sle_micro):
if is_sle_micro():
pytest.skip('Skipping SLE Micro')

scap_report = os.environ.get("SCAP_REPORT", "")
if scap_report:
if not scap_report.endswith(".html"):
print("Ignoring SCAP_REPORT: {}".format(scap_report))
elif host.file(scap_report).exists:
# Do not retry this expensive test if a report already exists
pytest.fail(reason="{} exists".format(scap_report), pytrace=False)
else:
scap_report = "--report {}".format(scap_report)

if not setup_swap(host):
pytest.skip("Failed to setup swap, not enough memory.")

Expand All @@ -60,13 +70,6 @@ def test_sles_hardened(host, get_release_value, is_sles_sap, is_sle_micro):
)
)

scap_report = os.environ.get("SCAP_REPORT", "")
if scap_report:
if os.path.exists(scap_report) or not scap_report.endswith(".html"):
print("Ignoring SCAP_REPORT: {}".format(scap_report))
else:
scap_report = "--report {}".format(scap_report)

result = host.run(
"sudo oscap xccdf eval {scap_report} --local-files {dir} --profile {profile} {file}".format(
scap_report=scap_report,
Expand Down