Skip to content

Commit 05025f8

Browse files
Add initial tests to validate foremanctl
Signed-off-by: Gaurav Talreja <gtalreja@redhat.com>
1 parent 026e561 commit 05025f8

File tree

5 files changed

+197
-1
lines changed

5 files changed

+197
-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: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
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+
21+
pytestmark = [pytest.mark.foremanctl, pytest.mark.build_sanity, pytest.mark.upgrade]
22+
23+
SATELLITE_SERVICES = [
24+
'candlepin',
25+
'dynflow-sidekiq@orchestrator',
26+
'dynflow-sidekiq@worker',
27+
'dynflow-sidekiq@worker-hosts-queue',
28+
'foreman-proxy',
29+
'foreman',
30+
'httpd',
31+
'postgresql',
32+
'pulp-api',
33+
'pulp-content',
34+
'pulp-worker@*',
35+
'redis',
36+
]
37+
38+
39+
def common_sat_install_assertions(satellite):
40+
# no errors/failures in journald
41+
result = satellite.execute(
42+
r'journalctl --quiet --no-pager --boot --priority err -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"'
43+
)
44+
assert not result.stdout
45+
# no errors/failures in /var/log/httpd/*
46+
result = satellite.execute(r'grep -iR "error" /var/log/httpd/*')
47+
assert not result.stdout
48+
# # no errors/failures in /var/log/candlepin/*
49+
result = satellite.execute(r'grep -iR "error" /var/log/candlepin/*')
50+
assert not result.stdout
51+
httpd_log = satellite.execute('journalctl --unit=httpd')
52+
assert 'WARNING' not in httpd_log.stdout
53+
54+
55+
@pytest.fixture(scope='module')
56+
def module_sat_ready_rhel(request):
57+
with Broker(
58+
workflow=settings.server.deploy_workflows.os,
59+
deploy_rhel_version=settings.server.version.rhel_version,
60+
deploy_flavor=settings.flavors.default,
61+
deploy_network_type=settings.server.network_type,
62+
host_class=Satellite,
63+
) as sat:
64+
sat.install_satellite_foremanctl(
65+
enable_fapolicyd=(request.param == 'fapolicyd'), enable_fips=(request.param == 'fips')
66+
)
67+
yield sat
68+
69+
70+
@pytest.mark.first_sanity
71+
@pytest.mark.parametrize('module_sat_ready_rhel', ['default'], indirect=True)
72+
def test_satellite_installation_with_foremanctl(module_sat_ready_rhel):
73+
"""Run a basic Satellite installation
74+
75+
:id: 661206f3-2eec-403c-af26-3c5cadcd5769
76+
77+
:steps:
78+
1. Get RHEL Host
79+
2. Configure satellite repos
80+
3. Install satellite using foremanctl
81+
4. Run foremanctl deploy
82+
83+
:expectedresults:
84+
1. foremanctl deploy runs successfully
85+
2. no unexpected errors in logs
86+
"""
87+
common_sat_install_assertions(module_sat_ready_rhel)
88+
89+
90+
@pytest.mark.parametrize('module_sat_ready_rhel', ['default'], indirect=True)
91+
@pytest.mark.parametrize('service', SATELLITE_SERVICES)
92+
def test_positive_check_installer_service_running(service, module_sat_ready_rhel):
93+
"""Check if all Satellite services is running
94+
95+
:id: 5389c174-7ab1-4e9d-b2aa-66d80fd6dc5h
96+
97+
:steps:
98+
1. Verify a service is active with systemctl is-active
99+
100+
:expectedresults: All Satellite services are active
101+
"""
102+
is_active = module_sat_ready_rhel.execute(f'systemctl is-active {service}')
103+
status = module_sat_ready_rhel.execute(f'systemctl status {service}')
104+
assert is_active.status == 0, status.stdout
105+
106+
107+
@pytest.mark.parametrize('module_sat_ready_rhel', ['default'], indirect=True)
108+
def test_positive_check_installer_hammer_ping(module_sat_ready_rhel):
109+
"""Check if hammer ping reports all services as ok
110+
111+
:id: 85fd4388-6d94-42f5-bed2-24be38e9f111
112+
113+
:steps:
114+
1. Run the 'hammer ping' command on satellite.
115+
116+
:expectedresults: All services are active (running)
117+
"""
118+
response = module_sat_ready_rhel.api.Ping().search_json()
119+
assert response['status'] == 'ok' # overall status
120+
services = response['services']
121+
assert all([service['status'] == 'ok' for service in services.values()]), (
122+
'Not all services seem to be up and running!'
123+
)

0 commit comments

Comments
 (0)