From a1beb4d29530d64d197a11954c01ba09f55fcd62 Mon Sep 17 00:00:00 2001 From: Gianluca Zuccarelli Date: Wed, 10 Jul 2024 14:20:52 +0100 Subject: [PATCH] stages/oscap.remediation: setup env helper Add a small helper function to setup the mountpoints and symlink for the stage. This will help in making the stage easier to test. --- stages/org.osbuild.oscap.remediation | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/stages/org.osbuild.oscap.remediation b/stages/org.osbuild.oscap.remediation index 5b8c1d02..54ebd177 100755 --- a/stages/org.osbuild.oscap.remediation +++ b/stages/org.osbuild.oscap.remediation @@ -11,6 +11,14 @@ XCCDF_RESULTS = "oscap_eval_xccdf_results.xml" REMEDIATION_SCRIPT = "oscap_remediation.bash" +def setup_env(tree): + for source in ("/dev", "/proc"): + target = os.path.join(tree, source.lstrip("/")) + os.makedirs(target, exist_ok=True) + mount(source, target, ro=False) + os.symlink("/proc/self/fd", f"{tree}/dev/fd") + + # pylint: disable=too-many-statements,too-many-branches def main(tree, options): # required vars @@ -32,11 +40,7 @@ def main(tree, options): data_dir = data_dir.lstrip('/') os.makedirs(f"{tree}/{data_dir}", exist_ok=True) - for source in ("/dev", "/proc"): - target = os.path.join(tree, source.lstrip("/")) - os.makedirs(target, exist_ok=True) - mount(source, target, ro=False) - os.symlink("/proc/self/fd", f"{tree}/dev/fd") + setup_env(tree) # build common data stream-related args list ds_args = ["--profile", profile_id]