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

Fix iteration over os.environ from script worker and correctly strip prefixes #87

Merged
merged 1 commit into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
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
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