Skip to content

Commit 0d26954

Browse files
committed
Add tests for sos report
Signed-off-by: Shubham Ganar <shubhamsg123m@gmail.com>
1 parent e0fc0f6 commit 0d26954

1 file changed

Lines changed: 136 additions & 0 deletions

File tree

tests/foreman/cli/test_logging.py

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818
import pytest
1919

2020
from robottelo.config import settings
21+
from robottelo.constants import FOREMANCTL_PARAMETERS_FILE
2122
from robottelo.logging import logger
23+
from robottelo.utils.issue_handlers import is_open
2224

2325
pytestmark = pytest.mark.e2e
2426

@@ -246,3 +248,137 @@ def test_positive_logging_from_pulp3(module_org, target_sat):
246248
# verify pulp correlation id in message
247249
message_log = target_sat.execute(f'cat {test_logfile} | grep {pulp_correlation_id}')
248250
assert message_log.status == 0
251+
252+
253+
@pytest.mark.foremanctl
254+
class TestSOSReportForemanctl:
255+
"""Tests for the foremanctl sos plugin on containerized Satellite."""
256+
257+
SOS_CMD = 'sos report -o foremanctl --batch --tmp-dir /var/tmp'
258+
EXTRACT_DIR = '/var/tmp/sosreport-extract'
259+
260+
@pytest.fixture(scope="module")
261+
def sosreport_extract(self, module_target_sat):
262+
# Use the sos packit build until the RHEL issue is resolved
263+
if is_open('RHEL-208899'):
264+
assert (
265+
module_target_sat.execute(
266+
'dnf copr enable packit/sosreport-sos-4376 centos-stream-9-x86_64'
267+
).status
268+
== 0
269+
)
270+
assert (
271+
module_target_sat.execute(
272+
'dnf install -y sos-4.11.2-1.20260710083645300958.pr4376.22.g3fc1dc6b.el9.noarch'
273+
).status
274+
== 0
275+
)
276+
277+
# Run sosreport and yield the extracted report directory path.
278+
result = module_target_sat.execute(self.SOS_CMD, timeout='10m')
279+
assert result.status == 0, f'sosreport failed:\n{result.stdout}\n{result.stderr}'
280+
281+
tarball = module_target_sat.execute(
282+
'ls /var/tmp/sosreport-*.tar.xz | head -1'
283+
).stdout.strip()
284+
assert tarball, 'No sosreport tarball found'
285+
286+
module_target_sat.execute(f'mkdir -p {self.EXTRACT_DIR}')
287+
module_target_sat.execute(f'tar xf {tarball} -C {self.EXTRACT_DIR}')
288+
289+
report_dir = module_target_sat.execute(
290+
f'ls -d {self.EXTRACT_DIR}/sosreport-*'
291+
).stdout.strip()
292+
yield report_dir
293+
module_target_sat.execute(f'rm -rf /var/tmp/sosreport-* {self.EXTRACT_DIR}')
294+
295+
def test_positive_sosreport_foremanctl_collects_data(
296+
self, module_target_sat, sosreport_extract
297+
):
298+
"""Verify the foremanctl sos plugin activates on a containerized
299+
Satellite and collects expected configuration files and command output.
300+
301+
:id: dc91bb91-d785-49f9-b19d-b0484662ce3f
302+
303+
:steps:
304+
1. Run sosreport with the foremanctl plugin
305+
2. Verify foremanctl configuration files are collected
306+
3. Verify foremanctl command outputs are collected
307+
308+
:expectedresults:
309+
1. parameters.yaml and inventory files are present in the report
310+
2. foremanctl features and foremanctl health output are collected
311+
"""
312+
report = sosreport_extract
313+
314+
params = module_target_sat.execute(f'test -f {report}/var/lib/foremanctl/parameters.yaml')
315+
assert params.status == 0, 'parameters.yaml not collected'
316+
317+
inventory = module_target_sat.execute(f'test -f {report}/etc/foremanctl/inventory')
318+
assert inventory.status == 0, 'foremanctl inventory not collected'
319+
320+
features = module_target_sat.execute(
321+
f'test -f {report}/sos_commands/foremanctl/foremanctl_features'
322+
)
323+
assert features.status == 0, 'foremanctl features output not collected'
324+
325+
health = module_target_sat.execute(
326+
f'test -f {report}/sos_commands/foremanctl/foremanctl_health'
327+
)
328+
assert health.status == 0, 'foremanctl health output not collected'
329+
330+
def test_positive_sosreport_foremanctl_scrub_sensitive_values(
331+
self, module_target_sat, sosreport_extract
332+
):
333+
"""Verify the foremanctl sos plugin scrubs sensitive credentials
334+
from parameters.yaml and foremanctl log files while preserving
335+
non-sensitive values.
336+
337+
:id: a8bdb8f7-dd0f-44ee-9722-af4b1815aad2
338+
339+
:steps:
340+
1. Verify passwords exist in the original parameters.yaml
341+
2. Run sosreport with the foremanctl plugin
342+
3. Check password values in parameters.yaml are scrubbed
343+
4. Check non-sensitive values are NOT scrubbed
344+
5. Verify foremanctl log files are collected
345+
6. Check that sensitive values in logs are scrubbed
346+
347+
:expectedresults:
348+
1. All password values in parameters.yaml are scrubbed
349+
2. Non-sensitive values like database names remain intact
350+
3. foremanctl log files are present in the report
351+
4. Any lines matching sensitive value patterns in logs
352+
have their values scrubbed'
353+
"""
354+
# only password exists for now on the default deploy and more can be added in future
355+
SENSITIVE_KEYWORD = ('password',)
356+
SCRUB_MARKER = '***'
357+
358+
original = module_target_sat.execute(f'grep -i password {FOREMANCTL_PARAMETERS_FILE}')
359+
assert original.stdout.strip(), f'No password entries found in {FOREMANCTL_PARAMETERS_FILE}'
360+
361+
report = sosreport_extract
362+
363+
# Verify parameters.yaml scrubbing
364+
collected = module_target_sat.execute(f'cat {report}/var/lib/foremanctl/parameters.yaml')
365+
assert collected.status == 0, 'Could not read collected parameters.yaml'
366+
367+
for keyword in SENSITIVE_KEYWORD:
368+
matching_lines = [
369+
line for line in collected.stdout.splitlines() if keyword in line.lower()
370+
]
371+
for line in matching_lines:
372+
assert SCRUB_MARKER in line, f'Sensitive value not scrubbed in line: {line}'
373+
374+
# Verify log file scrubbing
375+
log_dir = f'{report}/var/log/foremanctl'
376+
log_files = module_target_sat.execute(f'ls {log_dir}/foremanctl*log* 2>/dev/null')
377+
assert log_files.status == 0, 'Failed to list foremanctl log files in sosreport'
378+
379+
sensitive_check = module_target_sat.execute(
380+
f'grep -hEi "passw|cred|token|secret" {log_dir}/foremanctl*log* 2>/dev/null'
381+
)
382+
if sensitive_check.stdout.strip():
383+
for line in sensitive_check.stdout.splitlines():
384+
assert SCRUB_MARKER in line, f'Sensitive value not scrubbed in log line: {line}'

0 commit comments

Comments
 (0)