Skip to content

Commit

Permalink
Add check to verify deprecated envar message (#1423)
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Diblik <[email protected]>
  • Loading branch information
danmyway authored Nov 27, 2024
1 parent 61fc455 commit c83d7b6
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 27 deletions.
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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.
Expand All @@ -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.
"""
Expand All @@ -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
Expand All @@ -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.")
5 changes: 1 addition & 4 deletions tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,7 @@
# We use pytest_plugins to allow us to use fixtures we define in other files without the need to explicitly import them
# inside each test file.
# LINK - https://docs.pytest.org/en/7.0.x/reference/reference.html#globalvar-pytest_plugins
pytest_plugins = (
"test_helpers.common_functions",
"test_helpers.workarounds",
)
pytest_plugins = ("test_helpers.common_functions", "test_helpers.workarounds", "test_helpers.checks_nondestructive")


def pytest_collection_modifyitems(items):
Expand Down
27 changes: 27 additions & 0 deletions tests/integration/test_helpers/checks_nondestructive.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import os
import re

import pytest

from test_helpers.common_functions import get_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 = []
log_file_data = get_log_file_data()
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.")
3 changes: 1 addition & 2 deletions tests/integration/test_helpers/common_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ tag+:
This test marks the kernel as tainted which is not supported by convert2rhel.
We need to install specific kernel packages to build own custom kernel module.
Verify TAINTED_KMODS.TAINTED_KMODS_DETECTED is raised.
adjust+:
- enabled: false
when: distro == stream-9
because: |
Loading the kernel module on CentOS Stream 9 is flaky.
tag+:
- custom-built-tainted-kernel-module
test: |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ tag+:
adjust+:
environment+:
CONVERT2RHEL_ALLOW_UNAVAILABLE_KMODS: 1
when: distro == oracle-8
when: distro == oracle-8, oracle-9
because: |
When we install the older kernel, RHEL incompatible kernel modules are inserted in as well,
raising an inhibitor during the conversion.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,9 @@ def test_override_exclude_list_in_yum_config(convert2rhel, outdated_kernel, yum_
4/ Run the analysis and check that the transaction was successful.
"""
if os.environ["TMT_REBOOT_COUNT"] == "1":
# The downgrade of a kernel causes an unavailable kernel module to load
if "oracle" in SystemInformationRelease.distribution:
shell("rmmod nvme_common")
try:
with convert2rhel(
"analyze --serverurl {} --username {} --password {} --debug -y".format(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,5 @@ 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")

assert c2r.exitstatus == 2

# Run utility until the reboot
with convert2rhel(
"-y --serverurl {} --username {} --password {} --debug".format(
TEST_VARS["RHSM_SERVER_URL"],
TEST_VARS["RHSM_SCA_USERNAME"],
TEST_VARS["RHSM_SCA_PASSWORD"],
)
) 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("(WARNING) PACKAGE_UPDATES::OUT_OF_DATE_PACKAGES - Outdated packages detected")
assert c2r.exitstatus == 0

0 comments on commit c83d7b6

Please sign in to comment.