From 65423d1b1a9c1fff16b70173a6313e6401e977ed Mon Sep 17 00:00:00 2001 From: Daniel Diblik Date: Tue, 5 Nov 2024 14:59:09 +0100 Subject: [PATCH] Add check to verify deprecated envar message Signed-off-by: Daniel Diblik --- .../test_release_version.py | 6 ++++ .../test_verify_strings_in_log.py | 28 ++++++++++++++++--- .../test_helpers/checks_nondestructive.py | 26 +++++++++++++++++ .../test_helpers/common_functions.py | 3 +- .../basic-sanity-checks/main.fmf | 2 -- .../test_system_not_up_to_date.py | 4 +-- 6 files changed, 59 insertions(+), 10 deletions(-) create mode 100644 tests/integration/test_helpers/checks_nondestructive.py diff --git a/tests/integration/common/checks-after-conversion/test_release_version.py b/tests/integration/common/checks-after-conversion/test_release_version.py index d9a23339a..49fb687c1 100644 --- a/tests/integration/common/checks-after-conversion/test_release_version.py +++ b/tests/integration/common/checks-after-conversion/test_release_version.py @@ -33,6 +33,12 @@ def test_conversion_sanity_red_hat_in_os_release(shell): {"id": "Seafoam Ocelot", "name": "AlmaLinux", "version": "9.4"}, {"id": "Blue Onyx", "name": "Rocky Linux", "version": "9.4"}, ), + "Red Hat Enterprise Linux release 9.5 (Plow)": ( + {"id": "null", "name": "Oracle Linux Server", "version": "9.5"}, + {"id": "null", "name": "CentOS Stream", "version": "9"}, + {"id": "Seafoam Ocelot", "name": "AlmaLinux", "version": "9.5"}, + {"id": "Blue Onyx", "name": "Rocky Linux", "version": "9.5"}, + ), } diff --git a/tests/integration/common/checks-after-conversion/test_verify_strings_in_log.py b/tests/integration/common/checks-after-conversion/test_verify_strings_in_log.py index 796aa6eff..88d5b0a0b 100644 --- a/tests/integration/common/checks-after-conversion/test_verify_strings_in_log.py +++ b/tests/integration/common/checks-after-conversion/test_verify_strings_in_log.py @@ -1,7 +1,13 @@ +import os import re +import pytest +from test_helpers.common_functions import get_log_file_data -def test_verify_initramfs_and_vmlinuz_present(log_file_data): +log_data = get_log_file_data() + + +def test_verify_initramfs_and_vmlinuz_present(log_file_data=log_data): """ Verify that after a successful conversion the kernel boot files are present. @@ -13,7 +19,7 @@ def test_verify_initramfs_and_vmlinuz_present(log_file_data): assert "The initramfs and vmlinuz files are valid." in log_file_data -def test_failed_to_parse_package_info_empty_arch_not_present(log_file_data): +def test_failed_to_parse_package_info_empty_arch_not_present(log_file_data=log_data): """ Verify that in case of package with the `arch` field missing in its information, the message Failed to parse a package does not appear during the conversion run. @@ -24,7 +30,7 @@ def test_failed_to_parse_package_info_empty_arch_not_present(log_file_data): assert match is None, f"{failed_to_parse} is present in the log file data." -def test_traceback_not_present(log_file_data): +def test_traceback_not_present(log_file_data=log_data): """ Verify that there is not a traceback raised in the log file during the conversion run. """ @@ -33,7 +39,7 @@ def test_traceback_not_present(log_file_data): assert match is None, "Traceback found in the log file data." -def test_check_empty_exclude_in_critical_commands(log_file_data): +def test_check_empty_exclude_in_critical_commands(log_file_data=log_data): """ Verify that convert2rhel used `--setopt=exclude=` in every `repoquery` and `yumdownloader` call. Reference ticket: https://issues.redhat.com/browse/RHELC-774 @@ -50,3 +56,17 @@ def test_check_empty_exclude_in_critical_commands(log_file_data): re.findall("Calling command 'yumdownloader.*--setopt=exclude=\s.*", log_file_data) ) assert number_of_yumdownloader_calls == number_of_yumdownloader_calls_with_exclude + + +def test_check_deprecated_envar_message(log_file_data=log_data): + """ + Validate that the warning message for deprecated environment variables is present, + if the respective environment variable is used. + """ + missing_envar_messages = [] + for key in os.environ.keys(): + if re.match("CONVERT2RHEL_", key): + if not re.search(f"The environment variable {key} is deprecated", log_file_data): + missing_envar_messages.append(key) + if missing_envar_messages: + pytest.fail(f"The warning message for deprecated envars {missing_envar_messages} is not not present.") diff --git a/tests/integration/test_helpers/checks_nondestructive.py b/tests/integration/test_helpers/checks_nondestructive.py new file mode 100644 index 000000000..c64c80fad --- /dev/null +++ b/tests/integration/test_helpers/checks_nondestructive.py @@ -0,0 +1,26 @@ +import os +import re + +import pytest + +from test_helpers.common_functions import get_log_file_data as log_file_data + + +@pytest.fixture(autouse=True) +def check_validate_deprecated_envar_message(): + """ + Check fixture. + Validate that the warning message for deprecated environment variables is present, + if the respective environment variable is used. + """ + + yield + + if "C2R_TESTS_NONDESTRUCTIVE" in os.environ: + missing_envar_messages = [] + for key in os.environ.keys(): + if re.match("CONVERT2RHEL_", key): + if not re.search(f"The environment variable {key} is deprecated", log_file_data): + missing_envar_messages.append(key) + if missing_envar_messages: + pytest.fail(f"The warning message for deprecated envars {missing_envar_messages} is not not present.") diff --git a/tests/integration/test_helpers/common_functions.py b/tests/integration/test_helpers/common_functions.py index 069626b1c..7846352ea 100644 --- a/tests/integration/test_helpers/common_functions.py +++ b/tests/integration/test_helpers/common_functions.py @@ -110,8 +110,7 @@ def get_custom_repos_names(): return repos -@pytest.fixture() -def log_file_data(): +def get_log_file_data(): """ Helper fixture. Reads and returns data from the convert2rhel.log file. diff --git a/tests/integration/tier0/non-destructive/basic-sanity-checks/main.fmf b/tests/integration/tier0/non-destructive/basic-sanity-checks/main.fmf index cdd8e68f1..248695f39 100644 --- a/tests/integration/tier0/non-destructive/basic-sanity-checks/main.fmf +++ b/tests/integration/tier0/non-destructive/basic-sanity-checks/main.fmf @@ -166,8 +166,6 @@ tag+: This test verifies a basic incompatibility of the analyze and --no-rpm-va options. The user should be warned that the --no-rpm-va option will be ignored and the command will be called. - environment+: - CONVERT2RHEL_INCOMPLETE_ROLLBACK: 1 tag+: - analyze-no-rpm-va-option - sanity diff --git a/tests/integration/tier1/destructive/system-not-up-to-date/test_system_not_up_to_date.py b/tests/integration/tier1/destructive/system-not-up-to-date/test_system_not_up_to_date.py index fcfad0d37..204602f13 100644 --- a/tests/integration/tier1/destructive/system-not-up-to-date/test_system_not_up_to_date.py +++ b/tests/integration/tier1/destructive/system-not-up-to-date/test_system_not_up_to_date.py @@ -55,9 +55,9 @@ def test_system_not_updated(shell, convert2rhel, downgrade_and_versionlock): ) as c2r: c2r.expect("WARNING - YUM/DNF versionlock plugin is in use. It may cause the conversion to fail.") c2r.expect(r"WARNING - The system has \d+ package\(s\) not updated") - c2r.expect_exact("ERROR - (OVERRIDABLE) PACKAGE_UPDATES::OUT_OF_DATE_PACKAGES - Outdated packages detected") + c2r.expect_exact("(WARNING) PACKAGE_UPDATES::OUT_OF_DATE_PACKAGES - Outdated packages detected") - assert c2r.exitstatus == 2 + assert c2r.exitstatus == 0 # Run utility until the reboot with convert2rhel(