Skip to content

Commit

Permalink
Add check to verify deprecated envar message
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Diblik <[email protected]>
  • Loading branch information
danmyway committed Nov 12, 2024
1 parent 822a2d2 commit 85aae3e
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
),
}


Expand Down
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.")
26 changes: 26 additions & 0 deletions tests/integration/test_helpers/checks_nondestructive.py
Original file line number Diff line number Diff line change
@@ -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.")
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 @@ -47,17 +47,17 @@ def test_system_not_updated(shell, convert2rhel, downgrade_and_versionlock):
Display a warning about used version lock.
"""
with convert2rhel(
"-y --serverurl {} --username {} --password {} --debug".format(
"analyze -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("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(
Expand Down

0 comments on commit 85aae3e

Please sign in to comment.