Skip to content

Commit

Permalink
Registering n-minus capsule to CDN for rhel contents
Browse files Browse the repository at this point in the history
  • Loading branch information
jyejare committed Jan 5, 2024
1 parent 5799eb2 commit e3f549e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
9 changes: 9 additions & 0 deletions pytest_fixtures/core/sat_cap_factory.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from contextlib import contextmanager
from functools import lru_cache

from broker import Broker
from packaging.version import Version
Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand Down
13 changes: 10 additions & 3 deletions pytest_plugins/capsule_n-minus.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand All @@ -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):
Expand All @@ -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()

0 comments on commit e3f549e

Please sign in to comment.