diff --git a/conf/supportability.yaml b/conf/supportability.yaml index 5e6c6680895..81fab5824f9 100644 --- a/conf/supportability.yaml +++ b/conf/supportability.yaml @@ -1,4 +1,5 @@ supportability: content_hosts: + default_os_name: "RedHat" rhel: versions: [6, 7,'7_fips', 8, '8_fips', 9, '9_fips'] diff --git a/pytest_fixtures/component/os.py b/pytest_fixtures/component/os.py index 0c94baa09ce..dbf7a277690 100644 --- a/pytest_fixtures/component/os.py +++ b/pytest_fixtures/component/os.py @@ -2,6 +2,8 @@ from nailgun import entities import pytest +from robottelo.config import settings + @pytest.fixture(scope='session') def default_os( @@ -9,6 +11,7 @@ def default_os( default_partitiontable, default_pxetemplate, request, + session_target_sat, ): """Returns an Operating System entity read from searching Redhat family @@ -17,16 +20,28 @@ def default_os( """ os = getattr(request, 'param', None) if os is None: - search_string = 'name="RedHat" AND (major="6" OR major="7" OR major="8")' + default_name = settings.supportability.content_hosts.default_os_name + default_major_versions = " OR ".join( + [f'major="{v}"' for v in settings.supportability.content_hosts.rhel.versions] + ) + search_string = f'name="{default_name}" AND ({default_major_versions})' else: - version = os.split(' ')[1].split('.') - search_string = f'family="Redhat" AND major="{version[0]}" AND minor="{version[1]}"' - os = entities.OperatingSystem().search(query={'search': search_string})[0].read() + name, version = os.split(' ') + version = version.split('.') + search_string = f'name="{name}" AND major="{version[0]}" AND minor="{version[1]}"' + try: + os = ( + session_target_sat.api.OperatingSystem() + .search(query={'search': search_string})[0] + .read() + ) + except IndexError as e: + raise RuntimeError(f"Could not find operating system for '{search_string}'") from e os.architecture.append(default_architecture) os.ptable.append(default_partitiontable) os.provisioning_template.append(default_pxetemplate) os.update(['architecture', 'ptable', 'provisioning_template']) - return entities.OperatingSystem(id=os.id).read() + return session_target_sat.api.OperatingSystem(id=os.id).read() @pytest.fixture(scope='module') @@ -36,8 +51,6 @@ def module_os(): @pytest.fixture(scope='module') def os_path(default_os): - from robottelo.config import settings - # Check what OS was found to use correct media if default_os.major == "6": os_distr_url = settings.repos.rhel6_os diff --git a/robottelo/config/validators.py b/robottelo/config/validators.py index 013be110fe0..de87978dc13 100644 --- a/robottelo/config/validators.py +++ b/robottelo/config/validators.py @@ -4,7 +4,10 @@ VALIDATORS = dict( supportability=[ - Validator('supportability.content_hosts.rhel.versions', must_exist=True, is_type_of=list) + Validator('supportability.content_hosts.rhel.versions', must_exist=True, is_type_of=list), + Validator( + 'supportability.content_hosts.default_os_name', must_exist=True, default='RedHat' + ), ], server=[ Validator('server.hostname', default=''),