diff options
author | Jake Hunsaker <jhunsake@redhat.com> | 2023-05-01 09:05:27 -0400 |
---|---|---|
committer | Jake Hunsaker <jhunsake@redhat.com> | 2023-05-02 08:44:33 -0400 |
commit | dbed338bd13e5abda817175cd698a8664349f89a (patch) | |
tree | 50b57f6e22d69ad709810b74ed5c03f022933510 | |
parent | c675e5eb3af7d0f301af2e21a321a1841c199126 (diff) | |
download | sos-dbed338bd13e5abda817175cd698a8664349f89a.tar.gz |
[tests] Allow tests to restrict execution architecture
Adds a new `arch` class attr that allows test classes to specify which
architecture(s) they are allowed/designed to execute on. If the test is
attempted to be executed on an architecture that is not in the specified
list, we will skip the test before any setup or sos executions are done.
By default, the `arch` class attr is an empty list, which implies that
the test can run on _any_ architecture. Tests should specify `arch` as a
list even for single-arch tests.
Included in this change is restricting the Foreman tests to x86_64 only,
as that is the only architecture on which that product is supported.
Closes: #3186
Signed-off-by: Jake Hunsaker <jhunsake@redhat.com>
-rw-r--r-- | tests/product_tests/foreman/foreman_tests.py | 4 | ||||
-rw-r--r-- | tests/sos_tests.py | 19 |
2 files changed, 23 insertions, 0 deletions
diff --git a/tests/product_tests/foreman/foreman_tests.py b/tests/product_tests/foreman/foreman_tests.py index 7813b6a4..dd37f793 100644 --- a/tests/product_tests/foreman/foreman_tests.py +++ b/tests/product_tests/foreman/foreman_tests.py @@ -26,6 +26,7 @@ class ForemanBasicTest(StageOneReportTest): """ sos_cmd = '-v' + arch = ['x86_64'] def test_tfm_plugins_ran(self): self.assertPluginIncluded([ @@ -102,6 +103,7 @@ class ForemanWithOptionsTest(StageOneReportTest): """ sos_cmd = '-v -k foreman.proxyfeatures=on' + arch = ['x86_64'] @redhat_only def test_proxyfeatures_collected(self): @@ -115,6 +117,7 @@ class ForemanInstallerTest(StageOneReportTest): """ sos_cmd = '-v -o foreman_installer' + arch = ['x86_64'] def test_foreman_installer_etc_collected(self): self.assertFileCollected("/etc/foreman-installer/scenarios.d") @@ -127,6 +130,7 @@ class ForemanProxyTest(StageOneReportTest): """ sos_cmd = '-v -o foreman_proxy' + arch = ['x86_64'] def test_foreman_proxy_settings_collected(self): self.assertFileCollected("/etc/foreman-proxy/settings.yml") diff --git a/tests/sos_tests.py b/tests/sos_tests.py index 3e4154b1..78c23e43 100644 --- a/tests/sos_tests.py +++ b/tests/sos_tests.py @@ -11,6 +11,7 @@ from avocado.core.exceptions import TestSkipError from avocado.core.output import LOG_UI from avocado import Test from avocado.utils import archive, process, distro, software_manager +from avocado.utils.cpu import get_arch from fnmatch import fnmatch import glob @@ -71,6 +72,7 @@ class BaseSoSTest(Test): redhat_only = False ubuntu_only = False end_of_test_case = False + arch = [] @property def klass_name(self): @@ -227,6 +229,22 @@ class BaseSoSTest(Test): if self.local_distro not in UBUNTU_DIST: raise TestSkipError("Not running on a Ubuntu or Debian distro") + def check_arch_for_enablement(self): + """ + Check if the test case is meant only for a specific architecture, and + if it is, that we're also currently running on (one of) those arches. + + This relies on the `arch` class attr, which should be a list. If the + list is empty, assume all arches are acceptable. Otherwise, raise a + TestSkipError. + """ + sys_arch = get_arch() + if not self.arch or sys_arch in self.arch: + return True + raise TestSkipError(f"Unsupported architecture {sys_arch} for test " + f"(supports: {self.arch})") + + 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 @@ -234,6 +252,7 @@ class BaseSoSTest(Test): """ self.local_distro = distro.detect().name self.check_distro_for_enablement() + self.check_arch_for_enablement() # check to prevent multiple setUp() runs if not os.path.isdir(self.tmpdir): # setup our class-shared tmpdir |