Skip to content

Alter API Ping usage in tests to match new endpoint#20909

Merged
pondrejk merged 2 commits intoSatelliteQE:masterfrom
LadislavVasina1:AlterApiPingUsage
Mar 2, 2026
Merged

Alter API Ping usage in tests to match new endpoint#20909
pondrejk merged 2 commits intoSatelliteQE:masterfrom
LadislavVasina1:AlterApiPingUsage

Conversation

@LadislavVasina1
Copy link
Contributor

@LadislavVasina1 LadislavVasina1 commented Feb 27, 2026

With the API endpoint changed from katello/api/v2/ping to api/v2/ping in SatelliteQE/nailgun#1406 (read the reasoning for the change in nailgun PR), some tests need updating.

Summary by Sourcery

Update API ping tests to align with the new ping endpoint response structure focused on Katello-specific results.

Bug Fixes:

  • Adjust ping and subscription tests to read Katello service status and candlepin event data from the nested results.katello structure instead of the top-level services/status fields.

Enhancements:

  • Clarify test expectations to explicitly reference Katello services and document the updated ping API response format in test comments.

Tests:

  • Update positive and negative ping tests to assert status from results.katello, and subscription tests to parse candlepin_events data from the nested Katello services section.

@LadislavVasina1 LadislavVasina1 self-assigned this Feb 27, 2026
@LadislavVasina1 LadislavVasina1 requested review from a team as code owners February 27, 2026 09:07
@LadislavVasina1 LadislavVasina1 added No-CherryPick PR doesnt need CherryPick to previous branches Stream Introduced in or relating directly to Satellite Stream/Master labels Feb 27, 2026
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Feb 27, 2026

Reviewer's Guide

Update Foreman ping-related tests to reflect the new API ping response structure, focusing on Katello-specific results instead of the legacy flat services/status layout.

File-Level Changes

Change Details Files
Adapt ping test to the nested results/katello structure and clarify expectations around Katello services.
  • Update expected results docstring to mention Katello services specifically instead of generic services.
  • Replace top-level status assertion with one that reads status from the nested results['katello'] object.
  • Adjust services extraction to use results['katello']['services'] instead of a top-level services key and keep asserting all service statuses are ok.
  • Update the inline response example comment to show the new nested ping response format, including foreman, foreman_rh_cloud, and katello sections.
tests/foreman/api/test_ping.py
Update subscription tests relying on Ping to read candlepin_events from the nested Katello services structure.
  • Change pre_candlepin_events lookup to use results['katello']['services']['candlepin_events']['message'].
  • Update the wait_for polling lambda to fetch the candlepin_events message from the nested Katello services structure before parsing.
  • Adjust the assertion on candlepin_events status to read from results['katello']['services']['candlepin_events']['status'].
  • Change post_candlepin_events lookup to use the nested Katello services path before parsing and comparing Processed/Failed counts.
tests/foreman/api/test_subscription.py
Update destructive ping failure test to assert failure in the Katello section of the ping results.
  • Replace assertion on top-level response['status'] with response['results']['katello']['status'] == 'FAIL' to align with the new ping response format.
tests/foreman/destructive/test_ping.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

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've found 1 issue, and left some high level feedback:

  • In multiple places you now repeat the long indexing chain target_sat.api.Ping().search_json()['results']['katello']['services']['candlepin_events']; consider introducing a small helper (e.g. get_katello_ping(target_sat)) or at least a local variable to hold response['results']['katello'] to reduce duplication and improve readability.
  • The tests now assume that response['results']['katello'] is always present and correctly shaped; if this can vary between environments or versions, you might want to add a small guard or a clearer failure message when that structure is missing to make debugging easier.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In multiple places you now repeat the long indexing chain `target_sat.api.Ping().search_json()['results']['katello']['services']['candlepin_events']`; consider introducing a small helper (e.g. `get_katello_ping(target_sat)`) or at least a local variable to hold `response['results']['katello']` to reduce duplication and improve readability.
- The tests now assume that `response['results']['katello']` is always present and correctly shaped; if this can vary between environments or versions, you might want to add a small guard or a clearer failure message when that structure is missing to make debugging easier.

## Individual Comments

### Comment 1
<location path="tests/foreman/destructive/test_ping.py" line_range="60" />
<code_context>
     """
     response = tomcat_service_teardown.api.Ping().search_json()
-    assert response['status'] == 'FAIL'
+    assert response['results']['katello']['status'] == 'FAIL'
</code_context>
<issue_to_address>
**issue (testing):** Align assertion with the test’s "API ping fails" expectation by also checking the global failure indicator

Previously this test asserted the top-level `response['status'] == 'FAIL'`, matching the docstring "API ping fails and shows FAIL status." It now only checks `response['results']['katello']['status']`. If the new API still exposes a global failure indicator (e.g. a top-level `status`), please assert both the global status and the Katello status so the test verifies a full API ping failure, not just Katello. If the global flag no longer exists, update the docstring to state that this test now only validates the Katello section’s failure state.
</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.

"""
response = tomcat_service_teardown.api.Ping().search_json()
assert response['status'] == 'FAIL'
assert response['results']['katello']['status'] == 'FAIL'
Copy link
Contributor

Choose a reason for hiding this comment

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

issue (testing): Align assertion with the test’s "API ping fails" expectation by also checking the global failure indicator

Previously this test asserted the top-level response['status'] == 'FAIL', matching the docstring "API ping fails and shows FAIL status." It now only checks response['results']['katello']['status']. If the new API still exposes a global failure indicator (e.g. a top-level status), please assert both the global status and the Katello status so the test verifies a full API ping failure, not just Katello. If the global flag no longer exists, update the docstring to state that this test now only validates the Katello section’s failure state.

@LadislavVasina1
Copy link
Contributor Author

trigger: test-robottelo
pytest: tests/foreman/api/test_ping.py::test_positive_ping tests/foreman/api/test_subscription.py::test_positive_candlepin_events_processed_by_stomp tests/foreman/destructive/test_ping.py::test_negative_api_ping_fail_status
nailgun: 1406

@LadislavVasina1 LadislavVasina1 changed the title Alter API Ping usage Alter API Ping usage in tests to match new endpoint Feb 27, 2026
Copy link
Contributor

@vsedmik vsedmik left a comment

Choose a reason for hiding this comment

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

One proposal and tiny request for change, otherwise looks good!

@Satellite-QE
Copy link
Collaborator

PRT Result

Build Number: 14527
Build Status: SUCCESS
PRT Comment: pytest tests/foreman/api/test_ping.py::test_positive_ping tests/foreman/api/test_subscription.py::test_positive_candlepin_events_processed_by_stomp tests/foreman/destructive/test_ping.py::test_negative_api_ping_fail_status --external-logging
Test Result : ================= 3 passed, 27 warnings in 2496.49s (0:41:36) ==================

@Satellite-QE Satellite-QE added the PRT-Passed Indicates that latest PRT run is passed for the PR label Feb 27, 2026
Copy link
Contributor

@jnagare-redhat jnagare-redhat left a comment

Choose a reason for hiding this comment

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

LGTM

@pondrejk pondrejk merged commit 45d2464 into SatelliteQE:master Mar 2, 2026
10 checks passed
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-Passed Indicates that latest PRT run is passed 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.

5 participants