From 22ad8aad19952d7f50b85466d8c578cd161faeb4 Mon Sep 17 00:00:00 2001 From: David Moore Date: Thu, 5 Dec 2024 11:07:10 -0500 Subject: [PATCH] CP rhel_ver_match(N-x) optional format --- pytest_plugins/fixture_markers.py | 29 +++++++++++++++++++++-------- pytest_plugins/markers.py | 2 +- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/pytest_plugins/fixture_markers.py b/pytest_plugins/fixture_markers.py index 33d8732fdb1..81c611dc025 100644 --- a/pytest_plugins/fixture_markers.py +++ b/pytest_plugins/fixture_markers.py @@ -24,6 +24,7 @@ def pytest_generate_tests(metafunc): # process eventual rhel_version_list markers matchers = [i.args for i in function_marks if i.name == 'rhel_ver_list'] list_params = [] + # check if param matches format 'N-x' for matcher in matchers: list_params.extend( [ @@ -35,14 +36,26 @@ def pytest_generate_tests(metafunc): # process eventual rhel_version_match markers matchers = [i.args for i in function_marks if i.name == 'rhel_ver_match'] match_params = [] - for matcher in matchers: - match_params.extend( - [ - setting_rhel_ver - for setting_rhel_ver in settings.supportability.content_hosts.rhel.versions - if re.fullmatch(str(matcher[0]), str(setting_rhel_ver)) - ] - ) + if matchers and len(matchers[0][0]) == 3 and matchers[0][0].startswith('N-'): + # num of desired prior versions + num_versions = int(matchers[0][0].split('-')[1]) + # grab major versions, excluding fips, from tail of supportability list + filtered_versions = [ + setting_rhel_ver + for setting_rhel_ver in settings.supportability.content_hosts.rhel.versions + if 'fips' not in str(setting_rhel_ver) + ][-(num_versions + 1) :] # inclusive (+1) to collect N as well + match_params.extend(filtered_versions) + # match versions with existing regex markers + else: + for matcher in matchers: + match_params.extend( + [ + setting_rhel_ver + for setting_rhel_ver in settings.supportability.content_hosts.rhel.versions + if re.fullmatch(str(matcher[0]), str(setting_rhel_ver)) + ] + ) network_params = ['ipv6' if settings.server.is_ipv6 else 'ipv4'] rhel_params = [] ids = [] diff --git a/pytest_plugins/markers.py b/pytest_plugins/markers.py index 5398dbb3588..17b96e649d5 100644 --- a/pytest_plugins/markers.py +++ b/pytest_plugins/markers.py @@ -20,7 +20,7 @@ def pytest_configure(config): "run_in_one_thread: Sequential tests", "build_sanity: Fast, basic tests that confirm build is ready for full test suite", "rhel_ver_list: Filter rhel_contenthost versions by list", - "rhel_ver_match: Filter rhel_contenthost versions by regexp", + "rhel_ver_match: Filter rhel_contenthost versions by regexp, or format 'N-x'", "no_containers: Disable container hosts from being used in favor of VMs", "include_capsule: For satellite-maintain tests to run on Satellite and Capsule both", "capsule_only: For satellite-maintain tests to run only on Capsules",