From 3686636cf159534df0d42ef75c7da4b14cbd3a55 Mon Sep 17 00:00:00 2001 From: jyejare Date: Fri, 27 Sep 2024 21:14:50 +0530 Subject: [PATCH] Capsule Sanity Testing for capsule sync --- pytest_fixtures/core/sat_cap_factory.py | 5 ++++- pytest_fixtures/core/xdist.py | 8 +++++++- robottelo/hosts.py | 7 +++++-- tests/foreman/api/test_capsulecontent.py | 2 ++ tests/foreman/installer/test_installer.py | 7 ++++++- 5 files changed, 24 insertions(+), 5 deletions(-) diff --git a/pytest_fixtures/core/sat_cap_factory.py b/pytest_fixtures/core/sat_cap_factory.py index ea88852f86a..d4e48a73ed4 100644 --- a/pytest_fixtures/core/sat_cap_factory.py +++ b/pytest_fixtures/core/sat_cap_factory.py @@ -199,8 +199,11 @@ def large_capsule_configured(large_capsule_host, target_sat): @pytest.fixture(scope='module') def module_capsule_configured(request, module_capsule_host, module_target_sat): """Configure the capsule instance with the satellite from settings.server.hostname""" - if not request.config.option.n_minus: + if not any([request.config.option.n_minus, 'build_sanity' in request.config.option.markexpr]): module_capsule_host.capsule_setup(sat_host=module_target_sat) + # The capsule is being set here by capsule installation test of `test_installer.py` for sanity + if 'build_sanity' in request.config.option.markexpr: + return Capsule.get_host_by_hostname(settings.capsule.hostname) return module_capsule_host diff --git a/pytest_fixtures/core/xdist.py b/pytest_fixtures/core/xdist.py index 216589e85d7..9e58e61fb47 100644 --- a/pytest_fixtures/core/xdist.py +++ b/pytest_fixtures/core/xdist.py @@ -6,7 +6,7 @@ import pytest from robottelo.config import configure_airgun, configure_nailgun, settings -from robottelo.hosts import Satellite +from robottelo.hosts import Capsule, Satellite from robottelo.logging import logger @@ -16,12 +16,18 @@ def align_to_satellite(request, worker_id, satellite_factory): if 'build_sanity' in request.config.option.markexpr: settings.set("server.hostname", None) yield + # Checkout Sanity Satellite finally if settings.server.hostname: sanity_sat = Satellite(settings.server.hostname) sanity_sat.unregister() if settings.server.auto_checkin: broker_sat = Satellite.get_host_by_hostname(sanity_sat.hostname) Broker(hosts=[broker_sat]).checkin() + # Checkout Sanity Capsule finally + if settings.capsule.hostname: + sanity_cap = Capsule.get_host_by_hostname(settings.server.hostname) + sanity_cap.unregister() + Broker(hosts=[sanity_cap]).checkin() else: # clear any hostname that may have been previously set settings.set("server.hostname", None) diff --git a/robottelo/hosts.py b/robottelo/hosts.py index 6833b14440c..008b8fa5c38 100644 --- a/robottelo/hosts.py +++ b/robottelo/hosts.py @@ -344,8 +344,11 @@ def setup(self): def teardown(self): logger.debug('START: tearing down host %s', self) if not self.blank and not getattr(self, '_skip_context_checkin', False): - self.unregister() - if type(self) is not Satellite: # do not delete Satellite's host record + if type(self) is not Capsule: + self.unregister() + if ( + type(self) is not Satellite or type(self) is not Capsule + ): # do not delete Satellite's host record self._delete_host_record() logger.debug('END: tearing down host %s', self) diff --git a/tests/foreman/api/test_capsulecontent.py b/tests/foreman/api/test_capsulecontent.py index f8467f32d24..8b18a7a4cbd 100644 --- a/tests/foreman/api/test_capsulecontent.py +++ b/tests/foreman/api/test_capsulecontent.py @@ -575,6 +575,8 @@ def test_positive_iso_library_sync( assert set(sat_isos) == set(caps_isos) @pytest.mark.tier4 + @pytest.mark.build_sanity + @pytest.mark.order(after="tests/foreman/installer/test_installer.py::test_capsule_installation") @pytest.mark.skip_if_not_set('capsule', 'fake_manifest') def test_positive_on_demand_sync( self, diff --git a/tests/foreman/installer/test_installer.py b/tests/foreman/installer/test_installer.py index fd5a7da1484..a5d09370d5e 100644 --- a/tests/foreman/installer/test_installer.py +++ b/tests/foreman/installer/test_installer.py @@ -319,7 +319,7 @@ def sat_non_default_install(module_sat_ready_rhels): ids=["un_auth_proxy"], ) def test_capsule_installation( - sat_fapolicyd_install, cap_ready_rhel, module_sca_manifest, setting_update + pytestconfig, sat_fapolicyd_install, cap_ready_rhel, module_sca_manifest, setting_update ): """Run a basic Capsule installation with fapolicyd @@ -345,6 +345,11 @@ def test_capsule_installation( :customerscenario: true """ + # Setup Capsule Hostname for further sanity caspule testing + if 'build_sanity' in pytestconfig.option.markexpr: + settings.capsule.hostname = cap_ready_rhel.hostname + cap_ready_rhel._skip_context_checkin = True + # Create testing organization org = sat_fapolicyd_install.api.Organization().create()