Skip to content

Commit c6f9f4e

Browse files
Add initial tests to validate foremanctl
Signed-off-by: Gaurav Talreja <gtalreja@redhat.com>
1 parent 3d70fad commit c6f9f4e

File tree

5 files changed

+198
-1
lines changed

5 files changed

+198
-1
lines changed

conftest.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import pytest
44

5+
from robottelo.config import settings
6+
57
pytest_plugins = [
68
# Plugins
79
'pytest_plugins.auto_vault',
@@ -94,3 +96,14 @@ def pytest_runtest_makereport(item, call):
9496
# be "setup", "call", "teardown"
9597

9698
setattr(item, "report_" + report.when, report)
99+
100+
101+
@pytest.hookimpl(hookwrapper=True)
102+
def pytest_runtest_protocol(item, nextitem):
103+
"""Set version source to upstream for tests marked with foremanctl."""
104+
if item.get_closest_marker('foremanctl'):
105+
settings.set('server.version.source', 'upstream')
106+
yield
107+
settings.set('server.version.source', 'internal')
108+
else:
109+
yield

pytest_plugins/markers.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ def pytest_configure(config):
2525
"ldap: Tests related to ldap authentication",
2626
"no_compose : Skip the marked sanity test for nightly compose",
2727
"network: Restrict test to specific network environments",
28+
"foremanctl: Tests that require foremanctl",
2829
]
2930
markers.extend(module_markers())
3031
for marker in markers:

robottelo/config/validators.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@
1414
Validator('server.hostname', is_type_of=str),
1515
Validator('server.hostnames', must_exist=True, is_type_of=list),
1616
Validator('server.version.release', must_exist=True),
17-
Validator('server.version.source', default='internal', is_in=['internal', 'ga', 'nightly']),
17+
Validator(
18+
'server.version.source',
19+
default='internal',
20+
is_in=['internal', 'ga', 'nightly', 'upstream'],
21+
),
1822
Validator('server.version.rhel_version', must_exist=True, cast=str),
1923
Validator(
2024
'server.xdist_behavior', must_exist=True, is_in=['run-on-one', 'balance', 'on-demand']

robottelo/hosts.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1577,6 +1577,12 @@ def setup_satellite_repos(self):
15771577
satellite_repo=settings.repos.satellite_repo,
15781578
satmaintenance_repo=settings.repos.satmaintenance_repo,
15791579
)
1580+
elif settings.server.version.source == 'upstream':
1581+
self.create_custom_repos(
1582+
foreman='https://yum.theforeman.org/nightly/el9/x86_64/',
1583+
foreman_plugins='https://yum.theforeman.org/plugins/nightly/el9/x86_64/',
1584+
katello='https://yum.theforeman.org/katello/nightly/katello/el9/x86_64/',
1585+
)
15801586
else:
15811587
# get ohsnap repofile
15821588
self.download_repofile(
@@ -1955,6 +1961,55 @@ def install_satellite_or_capsule_package(self):
19551961
self.enable_satellite_or_capsule_module_for_rhel8()
19561962
assert self.execute(f'dnf -y install {self.product_rpm_name}').status == 0
19571963

1964+
def install_satellite_foremanctl(self, enable_fapolicyd=False, enable_fips=False):
1965+
# Enable RHEL and Satellite repos
1966+
self.register_to_cdn()
1967+
self.setup_rhel_repos()
1968+
self.setup_satellite_repos()
1969+
assert self.execute('dnf copr enable -y @theforeman/foremanctl rhel-9-x86_64').status == 0
1970+
assert self.execute('dnf install -y foremanctl').status == 0
1971+
1972+
if enable_fapolicyd:
1973+
assert self.execute('dnf -y install fapolicyd').status == 0
1974+
assert self.execute('systemctl enable --now fapolicyd').status == 0
1975+
assert self.execute('systemctl is-active fapolicyd').status == 0
1976+
if enable_fips:
1977+
Broker().execute(
1978+
workflow='enable-fips',
1979+
target_vm=self.name,
1980+
)
1981+
self.connect()
1982+
assert self.is_fips_enabled()
1983+
1984+
# Configure Satellite firewall to open communication
1985+
assert (
1986+
self.execute(
1987+
'(which firewall-cmd || dnf -y install firewalld) && systemctl enable --now firewalld'
1988+
).status
1989+
== 0
1990+
), 'firewalld is not present and can\'t be installed'
1991+
assert (
1992+
self.execute(
1993+
'firewall-cmd --permanent --add-service RH-Satellite-6 && firewall-cmd --reload'
1994+
).status
1995+
== 0
1996+
)
1997+
# Install Satellite and return result
1998+
assert (
1999+
self.execute(
2000+
f'foremanctl deploy --foreman-initial-admin-username {settings.server.admin_username} --foreman-initial-admin-password {settings.server.admin_password}',
2001+
timeout='30m',
2002+
).status
2003+
== 0
2004+
)
2005+
assert (
2006+
self.execute(
2007+
'foremanctl deploy --add-feature foreman-proxy --add-feature hammer'
2008+
).status
2009+
== 0
2010+
)
2011+
return
2012+
19582013
def query_db(self, query, db='foreman', output_format='json'):
19592014
"""Execute a PostgreSQL query and return the result.
19602015
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
"""Smoke tests to check installation health
2+
3+
:Requirement: Installation
4+
5+
:CaseAutomation: Automated
6+
7+
:CaseComponent: Installation
8+
9+
:Team: Rocket
10+
11+
:CaseImportance: Critical
12+
13+
"""
14+
15+
from broker import Broker
16+
import pytest
17+
18+
from robottelo.config import settings
19+
from robottelo.hosts import Satellite
20+
from robottelo.utils.issue_handlers import is_open
21+
22+
pytestmark = [pytest.mark.foremanctl, pytest.mark.build_sanity, pytest.mark.upgrade]
23+
24+
SATELLITE_SERVICES = [
25+
'candlepin',
26+
'dynflow-sidekiq@orchestrator',
27+
'dynflow-sidekiq@worker',
28+
'dynflow-sidekiq@worker-hosts-queue',
29+
'foreman-proxy',
30+
'foreman',
31+
'httpd',
32+
'postgresql',
33+
'pulp-api',
34+
'pulp-content',
35+
'pulp-worker@*',
36+
'redis',
37+
]
38+
39+
40+
def common_sat_install_assertions(satellite):
41+
# no errors/failures in journald
42+
result = satellite.execute(
43+
r'journalctl --quiet --no-pager --boot --grep ERROR -u "dynflow-sidekiq*" -u "foreman-proxy" -u "foreman" -u "httpd" -u "postgresql" -u "pulp-api" -u "pulp-content" -u "pulp-worker*" -u "redis" -u "candlepin"'
44+
)
45+
if is_open('SAT-21086'):
46+
assert not list(filter(lambda x: 'PG::' not in x, result.stdout.splitlines()))
47+
else:
48+
assert not result.stdout
49+
# no errors/failures in /var/log/httpd/*
50+
result = satellite.execute(r'grep -iR "error" /var/log/httpd/*')
51+
assert not result.stdout
52+
httpd_log = satellite.execute('journalctl --unit=httpd')
53+
assert 'WARNING' not in httpd_log.stdout
54+
55+
56+
@pytest.fixture(scope='module')
57+
def module_sat_ready_rhel(request):
58+
with Broker(
59+
workflow=settings.server.deploy_workflows.os,
60+
deploy_rhel_version=settings.server.version.rhel_version,
61+
deploy_flavor=settings.flavors.default,
62+
deploy_network_type=settings.server.network_type,
63+
host_class=Satellite,
64+
) as sat:
65+
sat.install_satellite_foremanctl(
66+
enable_fapolicyd=(request.param == 'fapolicyd'), enable_fips=(request.param == 'fips')
67+
)
68+
yield sat
69+
70+
71+
@pytest.mark.first_sanity
72+
@pytest.mark.parametrize('module_sat_ready_rhel', ['default'], indirect=True)
73+
def test_satellite_installation_with_foremanctl(module_sat_ready_rhel):
74+
"""Run a basic Satellite installation
75+
76+
:id: 661206f3-2eec-403c-af26-3c5cadcd5769
77+
78+
:steps:
79+
1. Get RHEL Host
80+
2. Configure satellite repos
81+
3. Install satellite using foremanctl
82+
4. Run foremanctl deploy
83+
84+
:expectedresults:
85+
1. foremanctl deploy runs successfully
86+
2. no unexpected errors in logs
87+
"""
88+
common_sat_install_assertions(module_sat_ready_rhel)
89+
90+
91+
@pytest.mark.parametrize('module_sat_ready_rhel', ['default'], indirect=True)
92+
@pytest.mark.parametrize('service', SATELLITE_SERVICES)
93+
def test_positive_check_installer_service_running(service, module_sat_ready_rhel):
94+
"""Check if all Satellite services is running
95+
96+
:id: 5389c174-7ab1-4e9d-b2aa-66d80fd6dc5h
97+
98+
:steps:
99+
1. Verify a service is active with systemctl is-active
100+
101+
:expectedresults: All Satellite services are active
102+
"""
103+
is_active = module_sat_ready_rhel.execute(f'systemctl is-active {service}')
104+
status = module_sat_ready_rhel.execute(f'systemctl status {service}')
105+
assert is_active.status == 0, status.stdout
106+
107+
108+
@pytest.mark.parametrize('module_sat_ready_rhel', ['default'], indirect=True)
109+
def test_positive_check_installer_hammer_ping(module_sat_ready_rhel):
110+
"""Check if hammer ping reports all services as ok
111+
112+
:id: 85fd4388-6d94-42f5-bed2-24be38e9f111
113+
114+
:steps:
115+
1. Run the 'hammer ping' command on satellite.
116+
117+
:expectedresults: All services are active (running)
118+
"""
119+
# check status reported by hammer ping command
120+
result = module_sat_ready_rhel.execute('hammer ping')
121+
assert result.status == 0
122+
for line in result.stdout.split('\n'):
123+
if 'Status' in line:
124+
assert 'ok' in line

0 commit comments

Comments
 (0)