Skip to content

Commit

Permalink
[Sanity Testing] Capsule Sanity Testing for capsule sync (#16558)
Browse files Browse the repository at this point in the history
Capsule Sanity Testing for capsule sync
  • Loading branch information
jyejare authored Oct 25, 2024
1 parent 59f2b4a commit 952b960
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 4 deletions.
5 changes: 4 additions & 1 deletion pytest_fixtures/core/sat_cap_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
8 changes: 7 additions & 1 deletion pytest_fixtures/core/xdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -16,6 +16,12 @@ 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 Capsule finally
if settings.capsule.hostname:
sanity_cap = Capsule.get_host_by_hostname(settings.capsule.hostname)
sanity_cap.unregister()
Broker(hosts=[sanity_cap]).checkin()
# Checkout Sanity Satellite finally
if settings.server.hostname:
sanity_sat = Satellite(settings.server.hostname)
sanity_sat.unregister()
Expand Down
8 changes: 8 additions & 0 deletions robottelo/hosts.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from fauxfactory import gen_alpha, gen_string
from nailgun import entities
from packaging.version import Version
import pytest
import requests
from ssh2.exceptions import AuthenticationError
from wait_for import TimedOutError, wait_for
Expand Down Expand Up @@ -344,6 +345,13 @@ 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):
if (
hasattr(pytest, 'capsule_sanity')
and pytest.capsule_sanity is True
and type(self) is Capsule
):
logger.debug('END: Skipping tearing down caspule host %s for sanity', self)
return
self.unregister()
if type(self) is not Satellite: # do not delete Satellite's host record
self._delete_host_record()
Expand Down
2 changes: 2 additions & 0 deletions tests/foreman/api/test_capsulecontent.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
13 changes: 11 additions & 2 deletions tests/foreman/installer/test_installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,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
Expand All @@ -372,6 +372,12 @@ 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
pytest.capsule_sanity = True

# Create testing organization
org = sat_fapolicyd_install.api.Organization().create()

Expand All @@ -386,7 +392,6 @@ def test_capsule_installation(
ak = sat_fapolicyd_install.api.ActivationKey(
organization=org, environment=org.library, content_view=org.default_content_view
).create()

setup_capsule_repos(sat_fapolicyd_install, cap_ready_rhel, org, ak)

cap_ready_rhel.register(org, None, ak.name, sat_fapolicyd_install)
Expand Down Expand Up @@ -432,6 +437,10 @@ def test_capsule_installation(
result = cap_ready_rhel.execute(r'grep -iR "error" /var/log/foreman-proxy/*')
assert len(result.stdout) == 0

# Enabling firewall
cap_ready_rhel.execute('firewall-cmd --add-service RH-Satellite-6-capsule')
cap_ready_rhel.execute('firewall-cmd --runtime-to-permanent')

result = cap_ready_rhel.cli.Health.check()
assert 'FAIL' not in result.stdout

Expand Down

0 comments on commit 952b960

Please sign in to comment.