Skip to content

Add test for foremanctl --pulp-log-level - #22316

Open
Alleny244 wants to merge 1 commit into
SatelliteQE:masterfrom
Alleny244:tests/foremanctl-pulp-log-level
Open

Add test for foremanctl --pulp-log-level#22316
Alleny244 wants to merge 1 commit into
SatelliteQE:masterfrom
Alleny244:tests/foremanctl-pulp-log-level

Conversation

@Alleny244

@Alleny244 Alleny244 commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Problem Statement

foremanctl added the --pulp-log-level option in foremanctl#697 to configure Pulp logging (debug, info, warning, error, critical).

Solution

Add test_positive_foremanctl_pulp_log_level to verify that:

  • foremanctl deploy --help lists all supported Pulp log levels.
  • foremanctl deploy --pulp-log-level=error persists pulp_log_level in parameters.yaml.
  • PULP_LOG_LEVEL=error is applied to the pulp-api container.
  • The pulp-api journal contains no DEBUG messages after generating activity.

Related Issues

PRT Example

trigger: test-robottelo
pytest: tests/foreman/cli/test_logging.py -k test_positive_foremanctl_pulp_log_level
deployment_type: container

Summary by Sourcery

Tests:

  • Add a positive foremanctl CLI test that validates pulp_log_level persistence, container environment configuration, and logging behavior for the pulp-api service.

@Alleny244
Alleny244 requested a review from a team as a code owner July 31, 2026 13:28
@Alleny244
Alleny244 removed the request for review from a team July 31, 2026 13:28
@sourcery-ai

sourcery-ai Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Reviewer's Guide

Adds a focused integration test to validate that the new foremanctl --pulp-log-level option is persisted to parameters.yaml and correctly applied to the pulp-api container and its logging behavior.

File-Level Changes

Change Details Files
Add a new foremanctl CLI logging test to validate pulp log level behavior end-to-end.
  • Introduce test_positive_foremanctl_pulp_log_level as a foremanctl-marked pytest test case.
  • Deploy Satellite via foremanctl with --pulp-log-level=error and assert successful execution.
  • Verify pulp_log_level=error is persisted in the remote FOREMANCTL parameters YAML file.
  • Inspect the pulp-api container environment to ensure PULP_LOG_LEVEL=error is set.
  • Trigger Pulp activity with hammer ping and confirm DEBUG messages are absent from pulp-api systemd journal within a recent time window.
tests/foreman/cli/test_logging.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@Alleny244 Alleny244 added Stream Introduced in or relating directly to Satellite Stream/Master No-CherryPick PR doesnt need CherryPick to previous branches labels Jul 31, 2026
@Alleny244

Copy link
Copy Markdown
Contributor Author

trigger: test-robottelo
pytest: tests/foreman/cli/test_logging.py -k test_positive_foremanctl_pulp_log_level
deployment_type: container

@sourcery-ai sourcery-ai Bot left a comment

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.

Hey - I've found 2 issues, and left some high level feedback:

  • The test description mentions verifying foremanctl deploy --help lists all supported Pulp log levels, but the implementation only exercises --pulp-log-level=error; consider adding an explicit assertion on the help output to cover that behavior.
  • The journalctl --since "-2 min" | grep -i ":DEBUG:" check combined with hammer ping may be timing-sensitive and brittle; you might want to widen the time window or make the DEBUG check more robust to avoid flakes.
  • In the parameters check you mix attribute and dict-style access (params.pulp_log_level vs params.get("pulp_log_level")); standardizing on one access pattern would make the test clearer and less error-prone.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The test description mentions verifying `foremanctl deploy --help` lists all supported Pulp log levels, but the implementation only exercises `--pulp-log-level=error`; consider adding an explicit assertion on the help output to cover that behavior.
- The `journalctl --since "-2 min" | grep -i ":DEBUG:"` check combined with `hammer ping` may be timing-sensitive and brittle; you might want to widen the time window or make the DEBUG check more robust to avoid flakes.
- In the parameters check you mix attribute and dict-style access (`params.pulp_log_level` vs `params.get("pulp_log_level")`); standardizing on one access pattern would make the test clearer and less error-prone.

## Individual Comments

### Comment 1
<location path="tests/foreman/cli/test_logging.py" line_range="465-474" />
<code_context>
     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
+        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
</code_context>
<issue_to_address>
**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.
</issue_to_address>

### Comment 2
<location path="tests/foreman/cli/test_logging.py" line_range="505-509" />
<code_context>
+    )
+
+    # 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, (
+        'DEBUG messages found in pulp-api.service journal when pulp_log_level=error'
+    )
</code_context>
<issue_to_address>
**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:

```python
    # 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).
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines +465 to +474
@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

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.

Comment on lines +505 to +509
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, (

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).

@Satellite-QE

Copy link
Copy Markdown
Collaborator

PRT Result

Build Number: 16308
Build Status: UNSTABLE
PRT Comment: pytest tests/foreman/cli/test_logging.py -k test_positive_foremanctl_pulp_log_level --external-logging
Test Result : =========== 8 deselected, 20 warnings, 1 error in 5330.80s (1:28:50) ===========

@Satellite-QE Satellite-QE added the PRT-Failed Indicates that latest PRT run is failed for the PR label Jul 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

No-CherryPick PR doesnt need CherryPick to previous branches PRT-Failed Indicates that latest PRT run is failed for the PR Stream Introduced in or relating directly to Satellite Stream/Master

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants