Skip to content

Commit be2add9

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

1 file changed

Lines changed: 101 additions & 0 deletions

File tree

tests/foreman/cli/test_logging.py

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

2020
from robottelo.config import settings
21+
from robottelo.constants import FOREMANCTL_PARAMETERS_FILE
2122
from robottelo.logging import logger
2223

2324
pytestmark = pytest.mark.e2e
@@ -246,3 +247,103 @@ def test_positive_logging_from_pulp3(module_org, target_sat):
246247
# verify pulp correlation id in message
247248
message_log = target_sat.execute(f'cat {test_logfile} | grep {pulp_correlation_id}')
248249
assert message_log.status == 0
250+
251+
252+
class TestSosreportForemanctl:
253+
"""Tests for the foremanctl sos plugin on containerized Satellite."""
254+
255+
SOS_CMD = 'sos report -o foremanctl --batch --tmp-dir /var/tmp'
256+
EXTRACT_DIR = '/var/tmp/sosreport-extract'
257+
258+
@pytest.fixture(scope="module")
259+
def sosreport_extract(self, module_target_sat):
260+
"""Run sosreport and yield the extracted report directory path."""
261+
result = module_target_sat.execute(self.SOS_CMD, timeout='10m')
262+
assert result.status == 0, f'sosreport failed:\n{result.stdout}\n{result.stderr}'
263+
264+
tarball = module_target_sat.execute(
265+
'ls /var/tmp/sosreport-*.tar.xz | head -1'
266+
).stdout.strip()
267+
assert tarball, 'No sosreport tarball found'
268+
269+
module_target_sat.execute(f'mkdir -p {self.EXTRACT_DIR}')
270+
module_target_sat.execute(f'tar xf {tarball} -C {self.EXTRACT_DIR}')
271+
272+
report_dir = module_target_sat.execute(
273+
f'ls -d {self.EXTRACT_DIR}/sosreport-*'
274+
).stdout.strip()
275+
yield report_dir
276+
module_target_sat.execute(f'rm -rf /var/tmp/sosreport-* {self.EXTRACT_DIR}')
277+
278+
@pytest.mark.foremanctl
279+
def test_positive_sosreport_foremanctl_collects_data(
280+
self, module_target_sat, sosreport_extract
281+
):
282+
"""Verify the foremanctl sos plugin activates on a containerized
283+
Satellite and collects expected configuration files and command output.
284+
285+
:id: dc91bb91-d785-49f9-b19d-b0484662ce3f
286+
287+
:steps:
288+
1. Run sosreport with the foremanctl plugin
289+
2. Verify foremanctl configuration files are collected
290+
3. Verify foremanctl command outputs are collected
291+
292+
:expectedresults:
293+
1. parameters.yaml and inventory files are present in the report
294+
2. foremanctl features and foremanctl health output are collected
295+
"""
296+
report = sosreport_extract
297+
298+
params = module_target_sat.execute(f'test -f {report}/var/lib/foremanctl/parameters.yaml')
299+
assert params.status == 0, 'parameters.yaml not collected'
300+
301+
inventory = module_target_sat.execute(f'test -f {report}/etc/foremanctl/inventory')
302+
assert inventory.status == 0, 'foremanctl inventory not collected'
303+
304+
features = module_target_sat.execute(
305+
f'test -f {report}/sos_commands/foremanctl/foremanctl_features'
306+
)
307+
assert features.status == 0, 'foremanctl features output not collected'
308+
309+
health = module_target_sat.execute(
310+
f'test -f {report}/sos_commands/foremanctl/foremanctl_health'
311+
)
312+
assert health.status == 0, 'foremanctl health output not collected'
313+
314+
@pytest.mark.foremanctl
315+
def test_positive_sosreport_foremanctl_scrubs_passwords(
316+
self, module_target_sat, sosreport_extract
317+
):
318+
"""Verify the foremanctl sos plugin scrubs sensitive credentials
319+
from parameters.yaml while preserving non-sensitive values.
320+
321+
:id: a8bdb8f7-dd0f-44ee-9722-af4b1815aad2
322+
323+
:steps:
324+
1. Verify passwords exist in the original parameters.yaml
325+
2. Run sosreport with the foremanctl plugin
326+
3. Check password values are replaced with '********'
327+
4. Check non-sensitive values are NOT scrubbed
328+
329+
:expectedresults:
330+
1. All password/secret/token values are replaced with '********'
331+
2. Non-sensitive values like database names remain intact
332+
"""
333+
334+
SENSITIVE_KEYWORD = ('password',)
335+
SCRUB_MARKER = '********'
336+
337+
original = module_target_sat.execute(f'grep -i password {FOREMANCTL_PARAMETERS_FILE}')
338+
assert original.stdout.strip(), f'No password entries found in {FOREMANCTL_PARAMETERS_FILE}'
339+
340+
report = sosreport_extract
341+
collected = module_target_sat.execute(f'cat {report}/var/lib/foremanctl/parameters.yaml')
342+
assert collected.status == 0, 'Could not read collected parameters.yaml'
343+
344+
for keyword in SENSITIVE_KEYWORD:
345+
matching_lines = [
346+
line for line in collected.stdout.splitlines() if keyword in line.lower()
347+
]
348+
for line in matching_lines:
349+
assert SCRUB_MARKER in line, f'Sensitive value not scrubbed in line: {line}'

0 commit comments

Comments
 (0)