From e3f549eb1486818f2a36103a791a54f462d0309e Mon Sep 17 00:00:00 2001 From: jyejare Date: Fri, 5 Jan 2024 19:50:41 +0530 Subject: [PATCH] Registering n-minus capsule to CDN for rhel contents --- pytest_fixtures/core/sat_cap_factory.py | 9 +++++++++ pytest_plugins/capsule_n-minus.py | 13 ++++++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/pytest_fixtures/core/sat_cap_factory.py b/pytest_fixtures/core/sat_cap_factory.py index f446199331e..647308cf027 100644 --- a/pytest_fixtures/core/sat_cap_factory.py +++ b/pytest_fixtures/core/sat_cap_factory.py @@ -1,4 +1,5 @@ from contextlib import contextmanager +from functools import lru_cache from broker import Broker from packaging.version import Version @@ -37,6 +38,12 @@ def _target_satellite_host(request, satellite_factory): yield +@lru_cache +def capsule_cdn_register(hostname=None): + cap = Capsule(hostname=hostname) + cap.register_to_cdn() + + @contextmanager def _target_capsule_host(request, capsule_factory): if 'sanity' not in request.config.option.markexpr and not request.config.option.n_minus: @@ -49,6 +56,8 @@ def _target_capsule_host(request, capsule_factory): hosts = Capsule.get_hosts_from_inventory(filter="'cap' in @inv.name") settings.capsule.hostname = hosts[0].hostname caps = Capsule(hostname=settings.capsule.hostname) + # Capsule needs RHEL contents for some tests + capsule_cdn_register(hostname=settings.capsule.hostname) yield caps else: yield diff --git a/pytest_plugins/capsule_n-minus.py b/pytest_plugins/capsule_n-minus.py index 8c7ae97a6c9..d89f6d58974 100644 --- a/pytest_plugins/capsule_n-minus.py +++ b/pytest_plugins/capsule_n-minus.py @@ -2,6 +2,9 @@ # No destructive tests # Adjust capsule host and capsule_configured host behavior for n_minus testing # Calculate capsule hostname from inventory just as we do in xDist.py +from robottelo.config import settings +from robottelo.hosts import Capsule + def pytest_addoption(parser): """Add options for pytest to collect tests based on fixtures its using""" @@ -12,9 +15,7 @@ def pytest_addoption(parser): example: pytest --n-minus tests/foreman ''' - parser.addoption( - "--n-minus", action='store_true', default=False, - help=help_text) + parser.addoption("--n-minus", action='store_true', default=False, help=help_text) def pytest_collection_modifyitems(items, config): @@ -41,3 +42,9 @@ def pytest_collection_modifyitems(items, config): config.hook.pytest_deselected(items=deselected) items[:] = selected + + +# Unregiter the capsule from CDN after all tests +def pytest_sessionfinish(session, exitstatus): + caps = Capsule(hostname=settings.capsule.hostname) + caps.unregister()