Skip to content

Commit 344885c

Browse files
Add initial tests to validate foremanctl
Signed-off-by: Gaurav Talreja <gtalreja@redhat.com>
1 parent 0dd4748 commit 344885c

File tree

5 files changed

+175
-2
lines changed

5 files changed

+175
-2
lines changed

pytest_fixtures/core/xdist.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
def align_to_satellite(request, worker_id, satellite_factory):
1515
"""Attempt to align a Satellite to the current xdist worker"""
1616
if 'build_sanity' in request.config.option.markexpr:
17-
settings.set("server.hostname", None)
17+
settings.set('server.hostname', None)
18+
if 'new_installer' in request.config.option.markexpr:
19+
settings.set('server.version.source', 'upstream')
1820
yield
1921
# Checkout Sanity Capsule finally
2022
for host in [settings.capsule.hostname, settings.server.hostname]:

pytest_plugins/markers.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ def pytest_configure(config):
2424
"ldap: Tests related to ldap authentication",
2525
"no_compose : Skip the marked sanity test for nightly compose",
2626
"network: Restrict test to specific network environments",
27+
"new_installer: Tests that require foremanctl",
2728
]
2829
markers.extend(module_markers())
2930
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: 44 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,44 @@ 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 install -y foremanctl').status == 0
1970+
1971+
if enable_fapolicyd:
1972+
assert self.execute('dnf -y install fapolicyd').status == 0
1973+
assert self.execute('systemctl enable --now fapolicyd').status == 0
1974+
assert self.execute('systemctl is-active fapolicyd').status == 0
1975+
if enable_fips:
1976+
Broker().execute(
1977+
workflow='enable-fips',
1978+
target_vm=self.name,
1979+
)
1980+
self.connect()
1981+
assert self.is_fips_enabled()
1982+
1983+
# Configure Satellite firewall to open communication
1984+
assert (
1985+
self.execute(
1986+
'(which firewall-cmd || dnf -y install firewalld) && systemctl enable --now firewalld'
1987+
).status
1988+
== 0
1989+
), 'firewalld is not present and can\'t be installed'
1990+
assert (
1991+
self.execute(
1992+
'firewall-cmd --permanent --add-service RH-Satellite-6 && firewall-cmd --reload'
1993+
).status
1994+
== 0
1995+
)
1996+
# Install Satellite and return result
1997+
return self.execute(
1998+
f'foremanctl deploy --foreman-initial-admin-username {settings.server.admin_username} --foreman-initial-admin-password {settings.server.admin_password}',
1999+
timeout='30m',
2000+
)
2001+
19582002
def query_db(self, query, db='foreman', output_format='json'):
19592003
"""Execute a PostgreSQL query and return the result.
19602004
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
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, get_sat_rhel_version
20+
21+
pytestmark = [pytest.mark.build_sanity, pytest.mark.new_installer, pytest.mark.upgrade]
22+
23+
SATELLITE_SERVICES = [
24+
'dynflow-sidekiq@orchestrator',
25+
'dynflow-sidekiq@worker',
26+
'dynflow-sidekiq@worker-hosts-queue',
27+
'foreman-proxy',
28+
'foreman',
29+
'httpd',
30+
'postgresql',
31+
'pulp-api',
32+
'pulp-content',
33+
'pulp-worker@*',
34+
'candlepin',
35+
]
36+
37+
38+
def common_sat_install_assertions(satellite):
39+
# no errors/failures in journald
40+
result = satellite.execute(
41+
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"'
42+
)
43+
assert not result.stdout
44+
# no errors/failures in /var/log/httpd/*
45+
result = satellite.execute(r'grep -iR "error" /var/log/httpd/*')
46+
assert not result.stdout
47+
# # no errors/failures in /var/log/candlepin/*
48+
result = satellite.execute(r'grep -iR "error" /var/log/candlepin/*')
49+
assert not result.stdout
50+
httpd_log = satellite.execute('journalctl --unit=httpd')
51+
assert 'WARNING' not in httpd_log.stdout
52+
53+
54+
@pytest.fixture(scope='module')
55+
def module_sat_ready_rhel(request):
56+
with Broker(
57+
workflow=settings.server.deploy_workflows.os,
58+
deploy_rhel_version=get_sat_rhel_version().major,
59+
deploy_flavor=settings.flavors.default,
60+
deploy_network_type=settings.server.network_type,
61+
host_class=Satellite,
62+
) as sat:
63+
sat.install_satellite_foremanctl(
64+
enable_fapolicyd=(request.param == 'fapolicyd'), enable_fips=(request.param == 'fips')
65+
)
66+
yield sat
67+
68+
69+
@pytest.mark.first_sanity
70+
@pytest.mark.parametrize('module_sat_ready_rhel', ['default', 'fips', 'fapolicyd'], indirect=True)
71+
def test_satellite_installation_with_foremanctl(module_sat_ready_rhel):
72+
"""Run a basic Satellite installation
73+
74+
:id: 661206f3-2eec-403c-af26-3c5cadcd5769
75+
76+
:steps:
77+
1. Get RHEL Host
78+
2. Configure satellite repos
79+
3. Install satellite using foremanctl
80+
4. Run foremanctl deploy
81+
82+
:expectedresults:
83+
1. foremanctl deploy runs successfully
84+
2. no unexpected errors in logs
85+
"""
86+
common_sat_install_assertions(module_sat_ready_rhel)
87+
88+
89+
@pytest.mark.parametrize('module_sat_ready_rhel', ['default', 'fips', 'fapolicyd'], indirect=True)
90+
def test_positive_check_installer_service_running(module_sat_ready_rhel):
91+
"""Check if all Satellite services is running
92+
93+
:id: 5389c174-7ab1-4e9d-b2aa-66d80fd6dc5h
94+
95+
:steps:
96+
1. Verify a service is active with systemctl is-active
97+
98+
:expectedresults: All Satellite services are active
99+
"""
100+
for service in SATELLITE_SERVICES:
101+
is_active = module_sat_ready_rhel.execute(f'systemctl is-active {service}')
102+
status = module_sat_ready_rhel.execute(f'systemctl status {service}')
103+
assert is_active.status == 0, status.stdout
104+
105+
106+
@pytest.mark.parametrize('module_sat_ready_rhel', ['default', 'fips', 'fapolicyd'], indirect=True)
107+
def test_positive_check_installer_hammer_ping(module_sat_ready_rhel):
108+
"""Check if hammer ping reports all services as ok
109+
110+
:id: 85fd4388-6d94-42f5-bed2-24be38e9f111
111+
112+
:steps:
113+
1. Run the 'hammer ping' command on satellite.
114+
115+
:expectedresults: All services are active (running)
116+
"""
117+
# check status reported by hammer ping command
118+
result = module_sat_ready_rhel.execute('hammer ping')
119+
assert result.status == 0
120+
for line in result.stdout.split('\n'):
121+
if 'Status' in line:
122+
assert 'ok' in line

0 commit comments

Comments
 (0)