-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for input parameters (#102)
* Add support for input parameters This patch introduces the support for input parameters that will come from the Insights UI. Regarding the environment variables value that will be passed down to us, there is no change that we need to do in order to receive it. The only change that was necessary was to adapt the code to receive the CLI switches. In this case, we are handling it pretty simple, only identifying the two possibilities for now and working with it. In the future, if more options appear, we can improve the code. * Skip environmnet variables that have value as 0 If an environment variable has value as 0, we will skip setting them in the subprocess. The reason for this is that convert2rhel does not handle well the case for values in those env vars. Convert2rhel currently only checks for the presence of the env var in the os.environ object. If it is set, then it will skip the check, otherwise, it will follow the execution normally.
- Loading branch information
Showing
5 changed files
with
386 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import os | ||
import pytest | ||
|
||
from convert2rhel_insights_tasks import main | ||
|
||
|
||
@pytest.mark.parametrize( | ||
("env", "expected"), | ||
( | ||
({"RHC_WORKER_SCRIPT_MODE": "CONVERSION"}, {"SCRIPT_MODE": "CONVERSION"}), | ||
( | ||
{"RHC_WORKER_FOO": "BAR", "RHC_WORKER_BAR": "FOO"}, | ||
{"FOO": "BAR", "BAR": "FOO"}, | ||
), | ||
( | ||
{"RHC_WORKER_FOO": "BAR", "RHC_BAR": "FOO"}, | ||
{"FOO": "BAR", "RHC_BAR": "FOO"}, | ||
), | ||
( | ||
{"FOO": "BAR", "BAR": "FOO"}, | ||
{"FOO": "BAR", "BAR": "FOO"}, | ||
), | ||
), | ||
) | ||
def test_parse_environment_variables(env, expected, monkeypatch): | ||
monkeypatch.setattr(os, "environ", env) | ||
result = main.parse_environment_variables() | ||
|
||
assert result == expected | ||
|
||
|
||
def test_parse_environment_variables_empty(monkeypatch): | ||
monkeypatch.setattr(os, "environ", {}) | ||
result = main.parse_environment_variables() | ||
assert not result | ||
|
||
|
||
@pytest.mark.parametrize( | ||
("env", "expected"), | ||
( | ||
( | ||
{}, | ||
{}, | ||
), | ||
( | ||
{"CONVERT2RHEL_ALLOW_UNAVAILABLE_KMODS": 0}, | ||
{}, | ||
), | ||
( | ||
{"CONVERT2RHEL_ALLOW_UNAVAILABLE_KMODS": 1}, | ||
{"CONVERT2RHEL_ALLOW_UNAVAILABLE_KMODS": 1}, | ||
), | ||
( | ||
{"CONVERT2RHEL_CONFIGURE_HOST_METERING": "auto"}, | ||
{"CONVERT2RHEL_CONFIGURE_HOST_METERING": "auto"}, | ||
), | ||
( | ||
{"CONVERT2RHEL_ALLOW_UNAVAILABLE_KMODS": 0, "SCRIPT_MODE": "ANALYSIS"}, | ||
{"SCRIPT_MODE": "ANALYSIS"}, | ||
), | ||
( | ||
{ | ||
"CONVERT2RHEL_OUTDATED_PACKAGE_CHECK_SKIP": 1, | ||
"CONVERT2RHEL_ALLOW_UNAVAILABLE_KMODS": 0, | ||
"SCRIPT_MODE": "ANALYSIS", | ||
}, | ||
{"CONVERT2RHEL_OUTDATED_PACKAGE_CHECK_SKIP": 1, "SCRIPT_MODE": "ANALYSIS"}, | ||
), | ||
), | ||
) | ||
def test_prepare_environment_variables(env, expected, monkeypatch): | ||
monkeypatch.setattr(os, "environ", env) | ||
result = main.prepare_environment_variables(env) | ||
|
||
assert result == expected |
Oops, something went wrong.