|
18 | 18 | import pytest |
19 | 19 |
|
20 | 20 | from robottelo.config import settings |
| 21 | +from robottelo.constants import FOREMANCTL_PARAMETERS_FILE |
21 | 22 | from robottelo.logging import logger |
22 | 23 |
|
23 | 24 | pytestmark = pytest.mark.e2e |
@@ -246,3 +247,122 @@ def test_positive_logging_from_pulp3(module_org, target_sat): |
246 | 247 | # verify pulp correlation id in message |
247 | 248 | message_log = target_sat.execute(f'cat {test_logfile} | grep {pulp_correlation_id}') |
248 | 249 | assert message_log.status == 0 |
| 250 | + |
| 251 | + |
| 252 | +@pytest.mark.foremanctl |
| 253 | +class TestSOSReportForemanctl: |
| 254 | + """Tests for the foremanctl sos plugin on containerized Satellite.""" |
| 255 | + |
| 256 | + SOS_CMD = 'sos report -o foremanctl --batch --tmp-dir /var/tmp' |
| 257 | + EXTRACT_DIR = '/var/tmp/sosreport-extract' |
| 258 | + |
| 259 | + @pytest.fixture(scope="module") |
| 260 | + def sosreport_extract(self, module_target_sat): |
| 261 | + """Run sosreport and yield the extracted report directory path.""" |
| 262 | + result = module_target_sat.execute(self.SOS_CMD, timeout='10m') |
| 263 | + assert result.status == 0, f'sosreport failed:\n{result.stdout}\n{result.stderr}' |
| 264 | + |
| 265 | + tarball = module_target_sat.execute( |
| 266 | + 'ls /var/tmp/sosreport-*.tar.xz | head -1' |
| 267 | + ).stdout.strip() |
| 268 | + assert tarball, 'No sosreport tarball found' |
| 269 | + |
| 270 | + module_target_sat.execute(f'mkdir -p {self.EXTRACT_DIR}') |
| 271 | + module_target_sat.execute(f'tar xf {tarball} -C {self.EXTRACT_DIR}') |
| 272 | + |
| 273 | + report_dir = module_target_sat.execute( |
| 274 | + f'ls -d {self.EXTRACT_DIR}/sosreport-*' |
| 275 | + ).stdout.strip() |
| 276 | + yield report_dir |
| 277 | + module_target_sat.execute(f'rm -rf /var/tmp/sosreport-* {self.EXTRACT_DIR}') |
| 278 | + |
| 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 | + def test_positive_sosreport_foremanctl_scrub_sensitive_values( |
| 315 | + self, module_target_sat, sosreport_extract |
| 316 | + ): |
| 317 | + """Verify the foremanctl sos plugin scrubs sensitive credentials |
| 318 | + from parameters.yaml and foremanctl log files while preserving |
| 319 | + 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 in parameters.yaml are scrubbed |
| 327 | + 4. Check non-sensitive values are NOT scrubbed |
| 328 | + 5. Verify foremanctl log files are collected |
| 329 | + 6. Check that sensitive values in logs are scrubbed |
| 330 | +
|
| 331 | + :expectedresults: |
| 332 | + 1. All password values in parameters.yaml are scrubbed |
| 333 | + 2. Non-sensitive values like database names remain intact |
| 334 | + 3. foremanctl log files are present in the report |
| 335 | + 4. Any lines matching sensitive value patterns in logs |
| 336 | + have their values scrubbed' |
| 337 | + """ |
| 338 | + # only password exists for now on the default deploy and more can be added in future |
| 339 | + SENSITIVE_KEYWORD = ('password',) |
| 340 | + SCRUB_MARKER = '***' |
| 341 | + |
| 342 | + original = module_target_sat.execute(f'grep -i password {FOREMANCTL_PARAMETERS_FILE}') |
| 343 | + assert original.stdout.strip(), f'No password entries found in {FOREMANCTL_PARAMETERS_FILE}' |
| 344 | + |
| 345 | + report = sosreport_extract |
| 346 | + |
| 347 | + # Verify parameters.yaml scrubbing |
| 348 | + collected = module_target_sat.execute(f'cat {report}/var/lib/foremanctl/parameters.yaml') |
| 349 | + assert collected.status == 0, 'Could not read collected parameters.yaml' |
| 350 | + |
| 351 | + for keyword in SENSITIVE_KEYWORD: |
| 352 | + matching_lines = [ |
| 353 | + line for line in collected.stdout.splitlines() if keyword in line.lower() |
| 354 | + ] |
| 355 | + for line in matching_lines: |
| 356 | + assert SCRUB_MARKER in line, f'Sensitive value not scrubbed in line: {line}' |
| 357 | + |
| 358 | + # Verify log file scrubbing |
| 359 | + log_dir = f'{report}/var/log/foremanctl' |
| 360 | + log_files = module_target_sat.execute(f'ls {log_dir}/foremanctl*log* 2>/dev/null') |
| 361 | + assert log_files.status == 0, 'Failed to list foremanctl log files in sosreport' |
| 362 | + |
| 363 | + sensitive_check = module_target_sat.execute( |
| 364 | + f'grep -hEi "passw|cred|token|secret" {log_dir}/foremanctl*log* 2>/dev/null' |
| 365 | + ) |
| 366 | + if sensitive_check.stdout.strip(): |
| 367 | + for line in sensitive_check.stdout.splitlines(): |
| 368 | + assert SCRUB_MARKER in line, f'Sensitive value not scrubbed in log line: {line}' |
0 commit comments