Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions tests/foreman/cli/test_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,3 +460,52 @@ def test_positive_foremanctl_log_level(module_target_sat):
'foreman_proxy_log_level still present in parameters after reset'
)
assert 'log_level' not in params, 'log_level still present in parameters after reset'


@pytest.mark.foremanctl
def test_positive_foremanctl_pulp_log_level(module_target_sat):
"""Verify foremanctl deploy --pulp-log-level persists and applies to Pulp services.

:id: de48bbb5-7a0f-48fd-a984-98b26dad45e1

:steps:
1. Deploy with --pulp-log-level=error
2. Verify pulp_log_level is persisted in parameters file
3. Verify PULP_LOG_LEVEL=error is applied on pulp-api
Comment on lines +465 to +474

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (testing): Test does not validate foremanctl deploy --help output for --pulp-log-level options as described in the PR

The test currently covers deploy behavior and configuration only. Please add assertions that foremanctl deploy --help exits successfully and that its help text includes the --pulp-log-level option and all expected log level choices (debug, info, warning, error, critical), so the CLI interface is also validated as described in the PR.

4. Trigger Pulp activity and verify DEBUG is absent from pulp-api journal

:expectedresults:
1. pulp_log_level=error is persisted correctly
2. pulp-api environment has PULP_LOG_LEVEL=error
3. pulp-api journal has no DEBUG messages after activity
"""
sat = module_target_sat

result = sat.execute(
'foremanctl deploy --pulp-log-level=error',
timeout='30m',
)
assert result.status == 0, f'foremanctl deploy --pulp-log-level=error failed:\n{result.stderr}'

params = sat.load_remote_yaml_file(FOREMANCTL_PARAMETERS_FILE)
assert params.pulp_log_level == 'error', (
f'pulp_log_level not persisted correctly: {params.get("pulp_log_level")}'
)

result = sat.execute(
"podman inspect pulp-api --format '{{range .Config.Env}}{{println .}}{{end}}' "
"| grep '^PULP_LOG_LEVEL='"
)
assert result.status == 0, f'Failed to read PULP_LOG_LEVEL from pulp-api:\n{result.stderr}'
assert 'PULP_LOG_LEVEL=error' in result.stdout, (
f'Expected PULP_LOG_LEVEL=error, got:\n{result.stdout}'
)

# With level=error, DEBUG must not appear (ERROR lines are not guaranteed on happy path)
sat.execute('hammer ping')
result = sat.execute(
r'journalctl --no-pager -u pulp-api.service --since "-2 min" | grep -i ":DEBUG:"'
)
assert result.status != 0, (
Comment on lines +505 to +509

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (testing): Reliance on grep -i ":DEBUG:" exit code may be brittle; consider a more explicit assertion on journal output

This check depends on grep -i ":DEBUG:" returning non-zero, which tightly couples the test to the current log format and grep’s exit behavior. Instead, capture the journalctl output in Python and assert there are no matching DEBUG entries, so you can clearly distinguish a journalctl failure from the absence of DEBUG logs and avoid format-dependent behavior. You might also widen the --since range slightly to avoid flakiness if hammer ping is slow.

Suggested implementation:

    # With level=error, DEBUG must not appear (ERROR lines are not guaranteed on happy path)
    sat.execute('hammer ping')
    journal = sat.execute(
        'journalctl --no-pager -u pulp-api.service --since "-5 min"'
    )
    assert journal.status == 0, (
        f'Failed to read pulp-api.service journal when pulp_log_level=error:\n{journal.stderr}'
    )
    assert 'debug' not in journal.stdout.lower(), (
        'DEBUG messages found in pulp-api.service journal when pulp_log_level=error'
    )

    assert 'log_level' not in params, 'log_level still present in parameters after reset'
  1. If other parts of the test file assume the old grep-based behavior or reuse similar patterns, consider updating them to follow this direct-output assertion style for consistency.
  2. If sat.execute raises on non-zero exit codes instead of just returning status, you may need to adjust the assert journal.status == 0 line to match the helper’s actual behavior (e.g., catching exceptions or using a different attribute).

'DEBUG messages found in pulp-api.service journal when pulp_log_level=error'
)
Loading