Skip to content

Commit

Permalink
Fix iteration over os.environ from script worker and correctly strip …
Browse files Browse the repository at this point in the history
…prefixes (#87)

Signed-off-by: Andrea Waltlova <[email protected]>
  • Loading branch information
andywaltlova authored Apr 26, 2024
1 parent a267e65 commit 7c18e62
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
11 changes: 7 additions & 4 deletions scripts/c2r_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -618,19 +618,22 @@ def run_convert2rhel():
Run the convert2rhel tool assigning the correct environment variables.
"""
logger.info("Running Convert2RHEL %s", (SCRIPT_TYPE.title()))
env = os.environ

for key in env:
new_env = {}
for key, value in os.environ.items():
valid_prefix = "RHC_WORKER_"
if key.startswith(valid_prefix):
env[key.replace(valid_prefix, "")] = env.pop(key)
# This also removes multiple valid prefixes
new_env[key.replace(valid_prefix, "")] = value
else:
new_env[key] = value

command = ["/usr/bin/convert2rhel"]
if IS_ANALYSIS:
command.append("analyze")

command.append("-y")
output, returncode = run_subprocess(command, env=env)
output, returncode = run_subprocess(command, env=new_env)
return output, returncode


Expand Down
2 changes: 2 additions & 0 deletions tests/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def test_run_convert2rhel_conversion():
"PATH": "/fake/path",
"RHC_WORKER_CONVERT2RHEL_DISABLE_TELEMETRY": "1",
"RHC_WORKER_FOO": "1",
"RHC_WORKER_RHC_WORKER_BAR": "1",
}

with patch("os.environ", mock_env), patch(
Expand All @@ -38,6 +39,7 @@ def test_run_convert2rhel_conversion():
"PATH": "/fake/path",
"CONVERT2RHEL_DISABLE_TELEMETRY": "1",
"FOO": "1",
"BAR": "1",
},
)

Expand Down

0 comments on commit 7c18e62

Please sign in to comment.