Skip to content

Conversation

synkd
Copy link
Contributor

@synkd synkd commented Oct 17, 2025

Problem Statement

The CLI test for syncing Lightpseed inventory status is failing due to its reliance on the foreman-rake rh_cloud_inventory:sync rake task. This command syncs the inventory for all organization on a Satellite and does not respect options passed in to restrict the scope of the command to a single org. As a result, in CI, when the test searches for an inventory sync task on which to make assertions, it often erroneously finds a sync task for an organization other than the one being tested.

Additionally, syncing the inventory via the foreman-rake CLI is not a documented approach, and the foreman-rake CLI is typically not a supported customer use case.

Solution

Convert the CLI inventory sync test to a UI test, which uses a supported workflow and restricts the sync to the selected org by default.

@synkd synkd requested a review from a team as a code owner October 17, 2025 18:40
Copy link

@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 there - I've reviewed your changes - here's some feedback:

  • There’s a typo in the decorator: you’ve used @pytest.mark_pit_client instead of @pytest.mark.pit_client, so that marker won’t actually be applied.
  • The UI test never asserts any visible confirmation after calling session.cloudinventory.sync_inventory_status(); consider adding a check for a toast or status indicator to ensure the sync was initiated in the UI before polling the API.
  • The timestamp + wait_for polling logic is duplicated here and in other tests—extract that into a shared helper to avoid repetition and make the test easier to maintain.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- There’s a typo in the decorator: you’ve used `@pytest.mark_pit_client` instead of `@pytest.mark.pit_client`, so that marker won’t actually be applied.
- The UI test never asserts any visible confirmation after calling `session.cloudinventory.sync_inventory_status()`; consider adding a check for a toast or status indicator to ensure the sync was initiated in the UI before polling the API.
- The timestamp + `wait_for` polling logic is duplicated here and in other tests—extract that into a shared helper to avoid repetition and make the test easier to maintain.

## Individual Comments

### Comment 1
<location> `tests/foreman/cli/test_rhcloud_inventory.py:548` </location>
<code_context>
def generate_report(rhcloud_manifest_org, module_target_sat, disconnected=False):
    """Download generated report job via cli"""
    org = rhcloud_manifest_org
    params = {'organization-id': org.id}
    if disconnected:
        params['no-upload'] = True

    result = module_target_sat.cli.Insights.inventory_generate_report(params)
    success_msg = "Report generation started successfully"
    timestamp = datetime.now(UTC).strftime('%Y-%m-%d %H:%M')
    assert success_msg in result
    # Check task details
    generate_job_name = 'ForemanInventoryUpload::Async::GenerateReportJob'
    wait_for(
        lambda: module_target_sat.api.ForemanTask()
        .search(query={'search': f'{generate_job_name} and started_at >= "{timestamp}"'})[0]
        .result
        == 'success',
        timeout=400,
        delay=15,
        silent_failure=True,
        handle_exception=True,
    )
    task_output = module_target_sat.api.ForemanTask().search(
        query={'search': f'{generate_job_name} and started_at >= "{timestamp}"'}
    )
    assert task_output[0].result == "success"

    report_log = module_target_sat.api.Organization(id=org.id).rh_cloud_fetch_last_report_log()
    expected = f'Check the Uploading tab for report uploading status'
    assert expected in report_log['output']

</code_context>

<issue_to_address>
**suggestion (code-quality):** Replace f-string with no interpolated values with string ([`remove-redundant-fstring`](https://docs.sourcery.ai/Reference/Default-Rules/refactorings/remove-redundant-fstring/))

```suggestion
    expected = 'Check the Uploading tab for report uploading status'
```
</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.

@synkd synkd force-pushed the convert_cloud_inventory_status_sync_to_ui branch 2 times, most recently from ac37c1a to 9da6946 Compare October 17, 2025 18:52
@synkd synkd added CherryPick PR needs CherryPick to previous branches 6.16.z 6.17.z 6.18.z Introduced in or relating directly to Satellite 6.18 labels Oct 17, 2025
@synkd
Copy link
Contributor Author

synkd commented Oct 17, 2025

trigger: test-robottelo
pytest: tests/foreman/ui/test_rhcloud_inventory.py::test_sync_inventory_status

@Satellite-QE
Copy link
Collaborator

PRT Result

Build Number: 13232
Build Status: SUCCESS
PRT Comment: pytest tests/foreman/ui/test_rhcloud_inventory.py::test_sync_inventory_status --external-logging
Test Result : ================= 8 passed, 799 warnings in 3244.98s (0:54:04) =================

@Satellite-QE Satellite-QE added the PRT-Passed Indicates that latest PRT run is passed for the PR label Oct 17, 2025
Copy link
Contributor

@LadislavVasina1 LadislavVasina1 left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@ColeHiggins2 ColeHiggins2 left a comment

Choose a reason for hiding this comment

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

Looks good to me, just a few comments on typos :)

@pytest.mark.pit_server
@pytest.mark.pit_client
def test_sync_inventory_status(rhcloud_manifest_org, rhcloud_registered_hosts, module_target_sat):
"""Test syncing Lighstpeed inventory status
Copy link
Member

Choose a reason for hiding this comment

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

Fix typo here

:id: 1fe47111-8831-4168-b79e-ca7c1f6aa343
:steps:
1. Register 2 hosts to Satellite to an org with a manifest importedand set up Lightspeed.
Copy link
Member

Choose a reason for hiding this comment

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

and here

synkd added 2 commits October 20, 2025 15:01
The CLI test for syncing Lightpseed inventory status is failing due to
its reliance on the `foreman-rake rh_cloud_inventory:sync` rake task.
This command syncs the inventory for all organization on a Satellite and
does not respect options passed in to restrict the scope of the command
to a single org. As a result, in CI, when the test searches for an
inventory sync task on which to make assertions, it often erroneously
finds a sync task for an organization other than the one being tested.

Additionally, syncing the inventory via the `foreman-rake` CLI is not a
documented approach, and the `foreman-rake` CLI is typically not a
supported customer use case.

This PR converts the CLI inventory sync test to a UI test, which uses a
supported workflow and restricts the sync to the selected org by
default.
@synkd synkd force-pushed the convert_cloud_inventory_status_sync_to_ui branch from 9da6946 to 02884d0 Compare October 20, 2025 19:01
@Satellite-QE Satellite-QE removed the PRT-Passed Indicates that latest PRT run is passed for the PR label Oct 20, 2025
@synkd synkd added the AutoMerge_Cherry_Picked The cherrypicked PRs of master PR would be automerged if all checks passing label Oct 20, 2025
@synkd synkd added the PRT-Passed Indicates that latest PRT run is passed for the PR label Oct 20, 2025
@ColeHiggins2 ColeHiggins2 merged commit 3ee1bef into SatelliteQE:master Oct 21, 2025
12 checks passed
github-actions bot pushed a commit that referenced this pull request Oct 21, 2025
* Convert Lightspeed inventory sync from CLI to UI

The CLI test for syncing Lightpseed inventory status is failing due to
its reliance on the `foreman-rake rh_cloud_inventory:sync` rake task.
This command syncs the inventory for all organization on a Satellite and
does not respect options passed in to restrict the scope of the command
to a single org. As a result, in CI, when the test searches for an
inventory sync task on which to make assertions, it often erroneously
finds a sync task for an organization other than the one being tested.

Additionally, syncing the inventory via the `foreman-rake` CLI is not a
documented approach, and the `foreman-rake` CLI is typically not a
supported customer use case.

This PR converts the CLI inventory sync test to a UI test, which uses a
supported workflow and restricts the sync to the selected org by
default.

* Address reviewer feedback

(cherry picked from commit 3ee1bef)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

6.16.z 6.17.z 6.18.z Introduced in or relating directly to Satellite 6.18 AutoMerge_Cherry_Picked The cherrypicked PRs of master PR would be automerged if all checks passing CherryPick PR needs CherryPick to previous branches PRT-Passed Indicates that latest PRT run is passed for the PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants