Skip to content

Commit

Permalink
[tests] Allow tests to restrict OS version
Browse files Browse the repository at this point in the history
Add a new `versions` class attribute that allows test classes
to specify which version(s) are allowed/designed to execute on.
If the test is attempted to be executed on a version that's not
specified, the test will be skipped and a message will be printed.

By default, the list of versions will be empty, which means that
the test should run in all versions of the OS.

This patch contains a change to restrict the execution of Teamd
to RHEL 8, because it was deprecated for RHEL 9 and later.

Resolves: #3782

Signed-off-by: Jose Castillo <[email protected]>
  • Loading branch information
pmoravec committed Nov 13, 2024
1 parent 32af5d5 commit a2bac16
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
3 changes: 3 additions & 0 deletions tests/report_tests/plugin_tests/teamd.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ class TeamdPluginTest(StageTwoReportTest):
sos_cmd = '-o teamd'
redhat_only = True

# teaming has been deprecated from RHEL 9
only_os_versions = ['8']

def pre_sos_setup(self):
# restart NetworkManager to account for the new package
nmout = process.run('systemctl restart NetworkManager', timeout=30)
Expand Down
24 changes: 21 additions & 3 deletions tests/sos_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
RH_DIST = ['rhel', 'centos', 'fedora', 'centos-stream']
UBUNTU_DIST = ['Ubuntu', 'debian']

_distro = distro.detect()


def skipIf(cond, message=None):
# pylint: disable=unused-argument
Expand All @@ -51,15 +53,15 @@ def wrapper(self, *args, **kwargs):
# pylint: disable=unused-argument
def redhat_only(tst):
def wrapper(func):
if distro.detect().name not in RH_DIST:
if _distro.name not in RH_DIST:
raise TestSkipError('Not running on a Red Hat distro')
return wrapper


# pylint: disable=unused-argument
def ubuntu_only(tst):
def wrapper(func):
if distro.detect().name not in UBUNTU_DIST:
if _distro.name not in UBUNTU_DIST:
raise TestSkipError('Not running on a Ubuntu or Debian distro')
return wrapper

Expand All @@ -82,6 +84,7 @@ class BaseSoSTest(Test):
ubuntu_only = False
end_of_test_case = False
arch = []
only_os_versions = []

@property
def klass_name(self):
Expand Down Expand Up @@ -261,14 +264,29 @@ def check_arch_for_enablement(self):
raise TestSkipError(f"Unsupported architecture {sys_arch} for test "
f"(supports: {self.arch})")

def check_os_version_for_enablement(self):
"""
Check if the test case is meant only for a specific version or versions
Takes the `versions` class attribute, a list that specifies
the versions where the test applies. If the list is empty, assume all
versions of the OS are acceptable. Otherwise, raise a TestSkipError.
"""
os_version = _distro.version
if not self.only_os_versions or os_version in self.only_os_versions:
return True
raise TestSkipError(f"Unsupported OS version {os_version} "
f"(supports: {self.only_os_versions})")

def setUp(self):
"""Setup the tmpdir and any needed mocking for the test, then execute
the defined sos command. Ensure that we only run the sos command once
for every test case, instead of once for every test_* method defined.
"""
self.local_distro = distro.detect().name
self.local_distro = _distro.name
self.check_distro_for_enablement()
self.check_arch_for_enablement()
self.check_os_version_for_enablement()
# check to prevent multiple setUp() runs
if not os.path.isdir(self.tmpdir):
# setup our class-shared tmpdir
Expand Down

0 comments on commit a2bac16

Please sign in to comment.