From 14d1e0547b4e747d262f748fd360caf3923021c3 Mon Sep 17 00:00:00 2001 From: Daniel Diblik <8378124+danmyway@users.noreply.github.com> Date: Tue, 23 May 2023 10:07:49 +0200 Subject: [PATCH] tests/hotfix/Remove parsing .env in conftest (#838) * we do not have any .env file in the repository, the line is redundant Signed-off-by: Daniel Diblik Modify tests * use `CONVERT2RHEL_SKIP_KERNEL_CURRENCY_CHECK` instead of deprecated `CONVERT2RHEL_UNSUPPORTED_SKIP_KERNEL_CURRENCY_CHECK` Signed-off-by: Daniel Diblik 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 Use the deprecated envar in latest_kernel_check_skip Signed-off-by: Daniel Diblik --- .../system_checks/is_loaded_kernel_latest.py | 24 ++++++-- .../is_loaded_kernel_latest_test.py | 13 ++-- plans/tier1.fmf | 60 +++++++++---------- .../system-release-backup/main.fmf | 2 +- .../test_system_release_backup.py | 4 +- .../destructive/kernel-check-skip/main.fmf | 2 +- .../test_latest_kernel_check_skip.py | 3 +- .../one-kernel-scenario/run_conversion.py | 2 +- .../test_system_up_to_date.py | 4 +- 9 files changed, 64 insertions(+), 50 deletions(-) diff --git a/convert2rhel/actions/system_checks/is_loaded_kernel_latest.py b/convert2rhel/actions/system_checks/is_loaded_kernel_latest.py index 1d03868ce2..f8b50a177a 100644 --- a/convert2rhel/actions/system_checks/is_loaded_kernel_latest.py +++ b/convert2rhel/actions/system_checks/is_loaded_kernel_latest.py @@ -71,12 +71,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 ) @@ -124,7 +138,7 @@ def run(self): # pylint: disable= too-many-return-statements "Could not find any %s from repositories to compare against the loaded kernel.\n" "Please, check if you have any vendor repositories enabled to proceed with the conversion.\n" "If you wish to ignore this message, set the environment variable " - "'CONVERT2RHEL_UNSUPPORTED_SKIP_KERNEL_CURRENCY_CHECK' to 1." % package_to_check + "'CONVERT2RHEL_SKIP_KERNEL_CURRENCY_CHECK' to 1." % package_to_check ), ) return diff --git a/convert2rhel/unit_tests/actions/system_checks/is_loaded_kernel_latest_test.py b/convert2rhel/unit_tests/actions/system_checks/is_loaded_kernel_latest_test.py index 47a7bfe366..978278fab6 100644 --- a/convert2rhel/unit_tests/actions/system_checks/is_loaded_kernel_latest_test.py +++ b/convert2rhel/unit_tests/actions/system_checks/is_loaded_kernel_latest_test.py @@ -342,7 +342,7 @@ def test_is_loaded_kernel_latest_eus_system_no_connection( "", 0, "1", - "Detected 'CONVERT2RHEL_UNSUPPORTED_SKIP_KERNEL_CURRENCY_CHECK' environment variable", + "Detected 'CONVERT2RHEL_SKIP_KERNEL_CURRENCY_CHECK' environment variable", id="Unsupported skip with environment var set to 1", ), pytest.param( @@ -389,11 +389,12 @@ def test_is_loaded_kernel_latest_unsupported_skip_warnings( "run_subprocess", value=run_subprocess_mocked, ) - monkeypatch.setattr( - os, - "environ", - {"CONVERT2RHEL_UNSUPPORTED_SKIP_KERNEL_CURRENCY_CHECK": unsupported_skip}, - ) + if unsupported_skip: + monkeypatch.setattr( + os, + "environ", + {"CONVERT2RHEL_SKIP_KERNEL_CURRENCY_CHECK": unsupported_skip}, + ) is_loaded_kernel_latest_action.run() diff --git a/plans/tier1.fmf b/plans/tier1.fmf index 3b8cc81048..f286efa7d3 100644 --- a/plans/tier1.fmf +++ b/plans/tier1.fmf @@ -277,33 +277,33 @@ description+: | how: ansible playbook: tests/ansible_collections/roles/reboot/main.yml - /latest_kernel_check_skip: - #TODO(danmyway) merge under system_not_updated in #757 - enabled: false - adjust+: - - enabled: true - when: distro == centos-7, oraclelinux-7 - environment+: - CONVERT2RHEL_UNSUPPORTED_SKIP_KERNEL_CURRENCY_CHECK: 1 - # Since we are removing all the repositories other than rhel-7-server-rpms - # we need pass CONVERT2RHEL_UNSUPPORTED_INCOMPLETE_ROLLBACK due to the inability - # to download and backup packages - CONVERT2RHEL_UNSUPPORTED_INCOMPLETE_ROLLBACK: 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. - CONVERT2RHEL_ALLOW_UNAVAILABLE_KMODS: 1 - discover+: - filter: tag:checks-after-conversion - prepare+: - - name: prepare non latest kernel - how: shell - script: pytest -svv tests/integration/*/destructive/system-up-to-date/install_non_latest_kernel.py - - name: add custom repos - how: ansible - playbook: tests/ansible_collections/roles/add-custom-repos/main.yml - - name: reboot machine - how: ansible - playbook: tests/ansible_collections/roles/reboot/main.yml - - name: main conversion - how: shell - script: pytest -svv tests/integration/*/destructive/kernel-check-skip/test_latest_kernel_check_skip.py +/latest_kernel_check_skip: + #TODO(danmyway) merge under system_not_updated in #757 + enabled: false + adjust+: + - enabled: true + when: distro == centos-7, oraclelinux-7 + environment+: + CONVERT2RHEL_UNSUPPORTED_SKIP_KERNEL_CURRENCY_CHECK: 1 + # Since we are removing all the repositories other than rhel-7-server-rpms + # we need pass CONVERT2RHEL_UNSUPPORTED_INCOMPLETE_ROLLBACK due to the inability + # to download and backup packages + CONVERT2RHEL_UNSUPPORTED_INCOMPLETE_ROLLBACK: 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. + CONVERT2RHEL_ALLOW_UNAVAILABLE_KMODS: 1 + discover+: + filter: tag:checks-after-conversion + prepare+: + - name: prepare non latest kernel + how: shell + script: pytest -svv tests/integration/tier1/system-up-to-date/install_non_latest_kernel.py + - name: add custom repos + how: ansible + playbook: tests/ansible_collections/roles/add-custom-repos/main.yml + - name: reboot machine + how: ansible + playbook: tests/ansible_collections/roles/reboot/main.yml + - name: main conversion + how: shell + script: pytest -svv tests/integration/tier1/kernel-check-skip/test_latest_kernel_check_skip.py diff --git a/tests/integration/tier0/non-destructive/system-release-backup/main.fmf b/tests/integration/tier0/non-destructive/system-release-backup/main.fmf index a36e0185f9..1d62c1a3a6 100644 --- a/tests/integration/tier0/non-destructive/system-release-backup/main.fmf +++ b/tests/integration/tier0/non-destructive/system-release-backup/main.fmf @@ -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+: | diff --git a/tests/integration/tier0/non-destructive/system-release-backup/test_system_release_backup.py b/tests/integration/tier0/non-destructive/system-release-backup/test_system_release_backup.py index 2b3ab02532..929c165347 100644 --- a/tests/integration/tier0/non-destructive/system-release-backup/test_system_release_backup.py +++ b/tests/integration/tier0/non-destructive/system-release-backup/test_system_release_backup.py @@ -76,12 +76,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 diff --git a/tests/integration/tier1/destructive/kernel-check-skip/main.fmf b/tests/integration/tier1/destructive/kernel-check-skip/main.fmf index 040166cf1c..c7e9f3f9e6 100644 --- a/tests/integration/tier1/destructive/kernel-check-skip/main.fmf +++ b/tests/integration/tier1/destructive/kernel-check-skip/main.fmf @@ -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 diff --git a/tests/integration/tier1/destructive/kernel-check-skip/test_latest_kernel_check_skip.py b/tests/integration/tier1/destructive/kernel-check-skip/test_latest_kernel_check_skip.py index b82ab02496..a48338e827 100644 --- a/tests/integration/tier1/destructive/kernel-check-skip/test_latest_kernel_check_skip.py +++ b/tests/integration/tier1/destructive/kernel-check-skip/test_latest_kernel_check_skip.py @@ -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( [ diff --git a/tests/integration/tier1/destructive/one-kernel-scenario/run_conversion.py b/tests/integration/tier1/destructive/one-kernel-scenario/run_conversion.py index 1454adf741..fa7bbff91f 100644 --- a/tests/integration/tier1/destructive/one-kernel-scenario/run_conversion.py +++ b/tests/integration/tier1/destructive/one-kernel-scenario/run_conversion.py @@ -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" diff --git a/tests/integration/tier1/destructive/system-up-to-date/test_system_up_to_date.py b/tests/integration/tier1/destructive/system-up-to-date/test_system_up_to_date.py index d36a8bc4bb..6cfd3902b3 100644 --- a/tests/integration/tier1/destructive/system-up-to-date/test_system_up_to_date.py +++ b/tests/integration/tier1/destructive/system-up-to-date/test_system_up_to_date.py @@ -34,7 +34,7 @@ def test_skip_kernel_check(shell, convert2rhel): c2r.expect("Could not find any kernel-core from repositories to compare against the loaded kernel.") assert c2r.exitstatus != 0 - os.environ["CONVERT2RHEL_UNSUPPORTED_SKIP_KERNEL_CURRENCY_CHECK"] = "1" + os.environ["CONVERT2RHEL_SKIP_KERNEL_CURRENCY_CHECK"] = "1" with convert2rhel( "--no-rpm-va --serverurl {} --username {} --password {} --pool {} --debug".format( @@ -48,7 +48,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