From d05812dc57909ed9e7f5689a85e1b5620637871d Mon Sep 17 00:00:00 2001 From: Griffin-Sullivan Date: Fri, 8 Mar 2024 09:37:27 -0500 Subject: [PATCH] Update Platform tests that have hard coded content host versions --- pytest_fixtures/core/contenthosts.py | 15 ++++- .../destructive/test_capsule_loadbalancer.py | 58 ++++++++++++------- tests/foreman/maintain/test_upgrade.py | 15 ++++- 3 files changed, 61 insertions(+), 27 deletions(-) diff --git a/pytest_fixtures/core/contenthosts.py b/pytest_fixtures/core/contenthosts.py index 485591ed7d9..6a4b18dbaf6 100644 --- a/pytest_fixtures/core/contenthosts.py +++ b/pytest_fixtures/core/contenthosts.py @@ -45,6 +45,15 @@ def rhel_contenthost(request): yield host +@pytest.fixture(scope='module') +def module_rhel_contenthost(request): + """A function-level fixture that provides a content host object parametrized""" + # Request should be parametrized through pytest_fixtures.fixture_markers + # unpack params dict + with Broker(**host_conf(request), host_class=ContentHost) as host: + yield host + + @pytest.fixture(params=[{'rhel_version': '7'}]) def rhel7_contenthost(request): """A function-level fixture that provides a rhel7 content host object""" @@ -268,8 +277,10 @@ def sat_upgrade_chost(): def custom_host(request): """A rhel content host that passes custom host config through request.param""" deploy_args = request.param - # if 'deploy_rhel_version' is not set, let's default to RHEL 8 - deploy_args['deploy_rhel_version'] = deploy_args.get('deploy_rhel_version', '8') + # if 'deploy_rhel_version' is not set, let's default to what's in server.yaml + deploy_args['deploy_rhel_version'] = deploy_args.get( + 'deploy_rhel_version', settings.server.version.rhel_version + ) deploy_args['workflow'] = 'deploy-rhel' with Broker(**deploy_args, host_class=Satellite) as host: yield host diff --git a/tests/foreman/destructive/test_capsule_loadbalancer.py b/tests/foreman/destructive/test_capsule_loadbalancer.py index a0675abec2b..2f81aa5d16d 100644 --- a/tests/foreman/destructive/test_capsule_loadbalancer.py +++ b/tests/foreman/destructive/test_capsule_loadbalancer.py @@ -22,34 +22,47 @@ @pytest.fixture(scope='module') -def content_for_client(module_target_sat, module_org, module_lce, module_cv, module_ak): +def content_for_client(request, module_target_sat, module_org, module_lce, module_cv, module_ak): """Setup content to be used by haproxy and client :return: Activation key, client lifecycle environment(used by setup_capsules()) """ - module_target_sat.cli_factory.setup_org_for_a_custom_repo( - { - 'url': settings.repos.RHEL7_OS, - 'organization-id': module_org.id, - 'content-view-id': module_cv.id, - 'lifecycle-environment-id': module_lce.id, - 'activationkey-id': module_ak.id, - } - ) + rhel_ver = settings.content_host.default_rhel_version + if rhel_ver > 7: + for repo in eval(f'settings.repos.RHEL{rhel_ver}_OS'): + module_target_sat.cli_factory.setup_org_for_a_custom_repo( + { + 'url': repo, + 'organization-id': module_org.id, + 'content-view-id': module_cv.id, + 'lifecycle-environment-id': module_lce.id, + 'activationkey-id': module_ak.id, + } + ) + else: + module_target_sat.cli_factory.setup_org_for_a_custom_repo( + { + 'url': eval(f'settings.repos.RHEL{rhel_ver}_OS'), + 'organization-id': module_org.id, + 'content-view-id': module_cv.id, + 'lifecycle-environment-id': module_lce.id, + 'activationkey-id': module_ak.id, + } + ) return {'client_ak': module_ak, 'client_lce': module_lce} @pytest.fixture(scope='module') def setup_capsules( module_org, - rhel7_contenthost_module, + module_rhel_contenthost, module_lb_capsule, module_target_sat, content_for_client, ): """Install capsules with loadbalancer options""" - extra_cert_var = {'foreman-proxy-cname': rhel7_contenthost_module.hostname} - extra_installer_var = {'certs-cname': rhel7_contenthost_module.hostname} + extra_cert_var = {'foreman-proxy-cname': module_rhel_contenthost.hostname} + extra_installer_var = {'certs-cname': module_rhel_contenthost.hostname} for capsule in module_lb_capsule: capsule.register_to_cdn() @@ -92,13 +105,13 @@ def setup_capsules( @pytest.fixture(scope='module') def setup_haproxy( module_org, - rhel7_contenthost_module, + module_rhel_contenthost, content_for_client, module_target_sat, setup_capsules, ): """Install and configure haproxy and setup logging""" - haproxy = rhel7_contenthost_module + haproxy = module_rhel_contenthost # Using same AK for haproxy just for packages haproxy_ak = content_for_client['client_ak'] haproxy.execute('firewall-cmd --add-service RH-Satellite-6-capsule') @@ -171,8 +184,9 @@ def loadbalancer_setup( @pytest.mark.e2e @pytest.mark.tier1 +@pytest.mark.rhel_ver_list([settings.content_host.default_rhel_version]) def test_loadbalancer_install_package( - loadbalancer_setup, setup_capsules, rhel7_contenthost, module_org, module_location, request + loadbalancer_setup, setup_capsules, rhel_contenthost, module_org, module_location, request ): r"""Install packages on a content host regardless of the registered capsule being available @@ -192,7 +206,7 @@ def test_loadbalancer_install_package( """ # Register content host - result = rhel7_contenthost.register( + result = rhel_contenthost.register( org=module_org, loc=module_location, activation_keys=loadbalancer_setup['content_for_client']['client_ak'].name, @@ -202,15 +216,15 @@ def test_loadbalancer_install_package( assert result.status == 0, f'Failed to register host: {result.stderr}' # Try package installation - result = rhel7_contenthost.execute('yum install -y tree') + result = rhel_contenthost.execute('yum install -y tree') assert result.status == 0 hosts = loadbalancer_setup['module_target_sat'].cli.Host.list( {'organization-id': loadbalancer_setup['module_org'].id} ) - assert rhel7_contenthost.hostname in [host['name'] for host in hosts] + assert rhel_contenthost.hostname in [host['name'] for host in hosts] - result = rhel7_contenthost.execute('rpm -qa | grep katello-ca-consumer') + result = rhel_contenthost.execute('rpm -qa | grep katello-ca-consumer') # Find which capsule the host is registered to since it's RoundRobin # The following also asserts the above result @@ -221,14 +235,14 @@ def test_loadbalancer_install_package( ) # Remove the packages from the client - result = rhel7_contenthost.execute('yum remove -y tree') + result = rhel_contenthost.execute('yum remove -y tree') assert result.status == 0 # Power off the capsule that the client is registered to registered_to_capsule.power_control(state=VmState.STOPPED, ensure=True) # Try package installation again - result = rhel7_contenthost.execute('yum install -y tree') + result = rhel_contenthost.execute('yum install -y tree') assert result.status == 0 @request.addfinalizer diff --git a/tests/foreman/maintain/test_upgrade.py b/tests/foreman/maintain/test_upgrade.py index 13ea31a5de0..9434337b3b6 100644 --- a/tests/foreman/maintain/test_upgrade.py +++ b/tests/foreman/maintain/test_upgrade.py @@ -98,8 +98,14 @@ def test_positive_repositories_validate(sat_maintain): @pytest.mark.parametrize( 'custom_host', [ - {'deploy_rhel_version': '8', 'deploy_flavor': 'satqe-ssd.disk.xxxl'}, - {'deploy_rhel_version': '8', 'deploy_flavor': 'satqe-ssd.standard.std'}, + { + 'deploy_rhel_version': settings.server.version.rhel_version, + 'deploy_flavor': 'satqe-ssd.disk.xxxl', + }, + { + 'deploy_rhel_version': settings.server.version.rhel_version, + 'deploy_flavor': 'satqe-ssd.standard.std', + }, ], ids=['default', 'medium'], indirect=True, @@ -118,6 +124,7 @@ def test_negative_pre_upgrade_tuning_profile_check(request, custom_host): :expectedresults: Pre-upgrade check fails. """ profile = request.node.callspec.id + rhel_major = settings.server.version.rhel_version[0] sat_version = ".".join(settings.server.version.release.split('.')[0:2]) # Register to CDN for RHEL8 repos, download and enable last y stream's ohsnap repos, # and enable the satellite module and install it on the host @@ -126,7 +133,9 @@ def test_negative_pre_upgrade_tuning_profile_check(request, custom_host): SATELLITE_VERSION if sat_version == 'stream' else sat_version ) custom_host.download_repofile(product='satellite', release=last_y_stream) - custom_host.execute('dnf -y module enable satellite:el8 && dnf -y install satellite') + custom_host.execute( + f'dnf -y module enable satellite:el{rhel_major} && dnf -y install satellite' + ) # Install with development tuning profile to get around installer checks custom_host.execute( 'satellite-installer --scenario satellite --tuning development',