Skip to content

Commit

Permalink
tests/hotfix/Remove parsing .env in conftest (oamg#838)
Browse files Browse the repository at this point in the history
* we do not have any .env file in the repository, the line is redundant

Signed-off-by: Daniel Diblik <[email protected]>

Modify tests

* use `CONVERT2RHEL_SKIP_KERNEL_CURRENCY_CHECK` instead of deprecated `CONVERT2RHEL_UNSUPPORTED_SKIP_KERNEL_CURRENCY_CHECK`

Signed-off-by: Daniel Diblik <[email protected]>

Revised checks.py and checks_test.py

* After Rebasing some of the code changed, and added in code not from
  this PR.
* In checks.py the log message was edited and the rest of the code.
* In checks_test.py edited is_loaded_kernel_latet_unsupported_skip, and
  added is_loaded_kernel_latet_unsupported_skip_env_var
* Use `CONVERT2RHEL_SKIP_KERNEL_CURRENCY_CHECK` instead of deprecated `CONVERT2RHEL_UNSUPPORTED_SKIP_KERNEL_CURRENCY_CHECK`

Signed-off-by: Daniel Diblik <[email protected]>

Use the deprecated envar in latest_kernel_check_skip

Signed-off-by: Daniel Diblik <[email protected]>
  • Loading branch information
danmyway authored and Andrew-ang9 committed Sep 26, 2023
1 parent aeca505 commit cf923b1
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 12 deletions.
22 changes: 18 additions & 4 deletions convert2rhel/actions/system_checks/is_loaded_kernel_latest.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,26 @@ def run(self): # pylint: disable= too-many-return-statements
# Append the package name as the last item on the list
cmd.append(package_to_check)

unsupported_skip = os.environ.get("CONVERT2RHEL_UNSUPPORTED_SKIP_KERNEL_CURRENCY_CHECK", None)
# Repoquery failed to detected any kernel or kernel-core packages in it's repositories
# we allow the user to provide a environment variable to override the functionality and proceed
# with the conversion, otherwise, we just throw an critical logging to them.
allow_older_envvar_names = (
"CONVERT2RHEL_SKIP_KERNEL_CURRENCY_CHECK",
"CONVERT2RHEL_UNSUPPORTED_SKIP_KERNEL_CURRENCY_CHECK",
)
# This check is to see which environment variable is set, To allow users in the next version
# to adjust their environmental variable names. This check will be removed in the future and
# will only have the 'CONVERT2RHEL_SKIP_KERNEL_CURRENCY_CHECK' environment variable
if any(envvar in os.environ for envvar in allow_older_envvar_names):
if "CONVERT2RHEL_UNSUPPORTED_SKIP_KERNEL_CURRENCY_CHECK" in os.environ:
logger.warning(
"You are using the deprecated 'CONVERT2RHEL_UNSUPPORTED_SKIP_KERNEL_CURRENCY_CHECK'"
" environment variable. Please switch to 'CONVERT2RHEL_SKIP_KERNEL_CURRENCY_CHECK'"
" instead."
)

# Skip the kernel package check and print a warning if the user used the special environment variable for it
if unsupported_skip:
logger.warning(
"Detected 'CONVERT2RHEL_UNSUPPORTED_SKIP_KERNEL_CURRENCY_CHECK' environment variable, we will skip "
"Detected 'CONVERT2RHEL_SKIP_KERNEL_CURRENCY_CHECK' environment variable, we will skip "
"the %s comparison.\n"
"Beware, this could leave your system in a broken state." % package_to_check
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ tag+:
description+: |
Install subscription-manager and katello package from the Satellite.
Remove all repositories from the system.
Set the "CONVERT2RHEL_UNSUPPORTED_SKIP_KERNEL_CURRENCY_CHECK" envar to bypass kernel check.
Set the "CONVERT2RHEL_SKIP_KERNEL_CURRENCY_CHECK" envar to bypass kernel check.
Verify that the /etc/os-release file is restored after the rollback.
/backup_os_release_no_envar:
summary+: |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@ def kernel_check_envar(shell):
to skip the kernel currency check.
"""
# Since we are moving all repos away, we need to bypass kernel check
os.environ["CONVERT2RHEL_UNSUPPORTED_SKIP_KERNEL_CURRENCY_CHECK"] = "1"
os.environ["CONVERT2RHEL_SKIP_KERNEL_CURRENCY_CHECK"] = "1"

yield

# Remove the envar skipping the kernel check
del os.environ["CONVERT2RHEL_UNSUPPORTED_SKIP_KERNEL_CURRENCY_CHECK"]
del os.environ["CONVERT2RHEL_SKIP_KERNEL_CURRENCY_CHECK"]


@pytest.mark.test_unsuccessful_satellite_registration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ description+: |
Verify that it's possible to run the full conversion with older kernel,
than available in the RHEL repositories.
1/ Install older kernel on the system
2/ Make sure the `CONVERT2RHEL_UNSUPPORTED_SKIP_KERNEL_CURRENCY_CHECK` is in place
2/ Make sure the `CONVERT2RHEL_SKIP_KERNEL_CURRENCY_CHECK` is in place
* doing that we also verify, the deprecated envar is still allowed
3/ Enable *just* the rhel-7-server-rpms repository
4/ Run conversion verifying the conversion is not inhibited and completes successfully
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ def test_skip_kernel_check(shell, convert2rhel):
)
) as c2r:
# Verify that using the deprecated environment variable is still allowed and continues the conversion
# TODO(danmyway) uncomment in #684
# assert c2r.expect("You are using the deprecated 'CONVERT2RHEL_UNSUPPORTED_SKIP_KERNEL_CURRENCY_CHECK'") == 0
assert c2r.expect("You are using the deprecated 'CONVERT2RHEL_UNSUPPORTED_SKIP_KERNEL_CURRENCY_CHECK'") == 0
# Make sure the kernel comparison is skipped
c2r_expect_index = c2r.expect(
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def test_run_conversion_using_custom_repos(shell, convert2rhel):
shell("rm /etc/yum.repos.d/copr_build-convert2rhel-1.repo")

os.environ["CONVERT2RHEL_UNSUPPORTED_INCOMPLETE_ROLLBACK"] = "1"
os.environ["CONVERT2RHEL_UNSUPPORTED_SKIP_KERNEL_CURRENCY_CHECK"] = "1"
os.environ["CONVERT2RHEL_SKIP_KERNEL_CURRENCY_CHECK"] = "1"
# Unavailable kmods may be present on the system due to the kernel package
# not being updated. Mitigate the issues by exporting CONVERT2RHEL_ALLOW_UNAVAILABLE_KMODS.
os.environ["CONVERT2RHEL_ALLOW_UNAVAILABLE_KMODS"] = "1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,23 @@ def test_skip_kernel_check(shell, convert2rhel):
assert shell("mv /usr/share/convert2rhel/repos/* /tmp/s_backup_eus/").returncode == 0

os.environ["CONVERT2RHEL_UNSUPPORTED_SKIP_KERNEL_CURRENCY_CHECK"] = "1"

with convert2rhel(
"-y --no-rpm-va --serverurl {} --username {} --password {} --pool {} --debug".format(
env.str("RHSM_SERVER_URL"),
env.str("RHSM_USERNAME"),
env.str("RHSM_USERNAME"),
env.str("RHSM_PASSWORD"),
env.str("RHSM_POOL"),
)
) as c2r:
if SYSTEM_RELEASE_ENV in ("centos-7", "oracle-7"):
c2r.expect("Could not find any kernel from repositories to compare against the loaded kernel.")
else:
c2r.expect("Could not find any kernel-core from repositories to compare against the loaded kernel.")
assert c2r.exitstatus != 0

os.environ["CONVERT2RHEL_SKIP_KERNEL_CURRENCY_CHECK"] = "1"

with convert2rhel(
"--no-rpm-va --serverurl {} --username {} --password {} --pool {} --debug".format(
Expand All @@ -35,7 +52,7 @@ def test_skip_kernel_check(shell, convert2rhel):
c2r.expect("Continue with the system conversion?")
c2r.sendline("y")

c2r.expect("Detected 'CONVERT2RHEL_UNSUPPORTED_SKIP_KERNEL_CURRENCY_CHECK' environment variable")
c2r.expect("Detected 'CONVERT2RHEL_SKIP_KERNEL_CURRENCY_CHECK' environment variable")
c2r.sendcontrol("c")
assert c2r.exitstatus != 0

Expand Down

0 comments on commit cf923b1

Please sign in to comment.