|
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,116 @@ 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 | +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( |
| 299 | + f'test -f {report}/var/lib/foremanctl/parameters.yaml' |
| 300 | + ) |
| 301 | + assert params.status == 0, 'parameters.yaml not collected' |
| 302 | + |
| 303 | + inventory = module_target_sat.execute( |
| 304 | + f'test -f {report}/etc/foremanctl/inventory' |
| 305 | + ) |
| 306 | + assert inventory.status == 0, 'foremanctl inventory not collected' |
| 307 | + |
| 308 | + features = module_target_sat.execute( |
| 309 | + f'test -f {report}/sos_commands/foremanctl/foremanctl_features' |
| 310 | + ) |
| 311 | + assert features.status == 0, 'foremanctl features output not collected' |
| 312 | + |
| 313 | + health = module_target_sat.execute( |
| 314 | + f'test -f {report}/sos_commands/foremanctl/foremanctl_health' |
| 315 | + ) |
| 316 | + assert health.status == 0, 'foremanctl health output not collected' |
| 317 | + |
| 318 | + @pytest.mark.foremanctl |
| 319 | + def test_positive_sosreport_foremanctl_scrubs_passwords( |
| 320 | + self, module_target_sat, sosreport_extract |
| 321 | + ): |
| 322 | + """Verify the foremanctl sos plugin scrubs sensitive credentials |
| 323 | + from parameters.yaml while preserving non-sensitive values. |
| 324 | +
|
| 325 | + :id: a8bdb8f7-dd0f-44ee-9722-af4b1815aad2 |
| 326 | +
|
| 327 | + :steps: |
| 328 | + 1. Verify passwords exist in the original parameters.yaml |
| 329 | + 2. Run sosreport with the foremanctl plugin |
| 330 | + 3. Check password values are replaced with '********' |
| 331 | + 4. Check non-sensitive values are NOT scrubbed |
| 332 | +
|
| 333 | + :expectedresults: |
| 334 | + 1. All password/secret/token values are replaced with '********' |
| 335 | + 2. Non-sensitive values like database names remain intact |
| 336 | + """ |
| 337 | + |
| 338 | + SENSITIVE_KEYWORD = ('password', ) |
| 339 | + SCRUB_MARKER = '********' |
| 340 | + |
| 341 | + original = module_target_sat.execute( |
| 342 | + f'grep -i password {FOREMANCTL_PARAMETERS_FILE}' |
| 343 | + ) |
| 344 | + assert original.stdout.strip(), ( |
| 345 | + f'No password entries found in {FOREMANCTL_PARAMETERS_FILE}' |
| 346 | + ) |
| 347 | + |
| 348 | + report = sosreport_extract |
| 349 | + collected = module_target_sat.execute( |
| 350 | + f'cat {report}/var/lib/foremanctl/parameters.yaml' |
| 351 | + ) |
| 352 | + assert collected.status == 0, 'Could not read collected parameters.yaml' |
| 353 | + |
| 354 | + for keyword in SENSITIVE_KEYWORD: |
| 355 | + matching_lines = [ |
| 356 | + line for line in collected.stdout.splitlines() |
| 357 | + if keyword in line.lower() |
| 358 | + ] |
| 359 | + for line in matching_lines: |
| 360 | + assert SCRUB_MARKER in line, ( |
| 361 | + f'Sensitive value not scrubbed in line: {line}' |
| 362 | + ) |
0 commit comments