Skip to content

Commit 0814d26

Browse files
committed
Improve pre_scan_fix
Move the calls into `with` statement so that manual cleanup won't be needed. Also, do not catch output of the bash remediation to let the user watch the progress of the script.
1 parent 687a0b4 commit 0814d26

1 file changed

Lines changed: 13 additions & 16 deletions

File tree

utils/oscap-im

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -111,22 +111,19 @@ def pre_scan_fix(args):
111111
"--output", remediation_script.name]
112112
add_common_args(args, gen_fix_cmd)
113113
gen_fix_cmd.append(args.data_stream)
114-
try:
115-
subprocess.run(gen_fix_cmd, check=True, capture_output=True)
116-
except subprocess.CalledProcessError as e:
117-
raise RuntimeError(
118-
f"OpenSCAP generate fix failed with return code {e.returncode}.\n"
119-
f"Output: {e.stderr.decode()}")
120-
try:
121-
subprocess.run(
122-
["bash", remediation_script.name], check=True,
123-
capture_output=True)
124-
except subprocess.CalledProcessError as e:
125-
raise RuntimeError(
126-
f"Remediation script failed with return code {e.returncode}.\n"
127-
f"Output: {e.stderr.decode()}")
128-
finally:
129-
Path(remediation_script.name).unlink()
114+
try:
115+
subprocess.run(gen_fix_cmd, check=True, capture_output=True)
116+
except subprocess.CalledProcessError as e:
117+
raise RuntimeError(
118+
f"OpenSCAP generate fix failed with return code "
119+
f"{e.returncode}.\nOutput: {e.stderr.decode()}")
120+
try:
121+
subprocess.run(["bash", remediation_script.name], check=True)
122+
except subprocess.CalledProcessError as e:
123+
raise RuntimeError(
124+
f"Remediation script failed with return code "
125+
f"{e.returncode}.")
126+
130127

131128
def scan_and_remediate(args):
132129
oscap_cmd = ["oscap", "xccdf", "eval", "--progress", "--remediate"]

0 commit comments

Comments
 (0)