Skip to content

improved rex UI tests reliability#21742

Open
rmynar wants to merge 1 commit into
SatelliteQE:masterfrom
rmynar:sat-41520
Open

improved rex UI tests reliability#21742
rmynar wants to merge 1 commit into
SatelliteQE:masterfrom
rmynar:sat-41520

Conversation

@rmynar

@rmynar rmynar commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

Together with changes to airgun SatelliteQE/airgun#2454 this improves reliability of REX UI tests.

  • improved retry on host search page
  • re-factored test_positive_run_scheduled_job_template_by_ip
  • reusing wait_for results (in some cases there was a wait_for used properly, but then the page was reloaded and search was applied again without wait_for)

Summary by Sourcery

Improve reliability and robustness of remote execution (REX) UI tests by adding resilient host lookup and more deterministic job scheduling assertions.

Bug Fixes:

  • Use a retrying wait_for-based host search in REX UI tests to handle delayed host visibility and prevent flaky lookups.
  • Stabilize the scheduled job execution test by polling and validating realistic job state transitions before asserting success.

Tests:

  • Harden multiple REX UI tests to use shared wait_for results for host searches instead of immediate re-searching.
  • Rework the scheduled job-by-IP test to track and assert the sequence of job status transitions through completion.

@rmynar rmynar self-assigned this Jun 4, 2026
@rmynar rmynar requested a review from a team as a code owner June 4, 2026 10:53
@rmynar rmynar added CherryPick PR needs CherryPick to previous branches AutoMerge_Cherry_Picked The cherrypicked PRs of master PR would be automerged if all checks passing Stream Introduced in or relating directly to Satellite Stream/Master 6.19.z labels Jun 4, 2026
@sourcery-ai

sourcery-ai Bot commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

Reviewer's Guide

Improves reliability and robustness of Remote Execution (REX) UI tests by adding wait/retry around host searches and by rewriting the scheduled-job-by-IP test to poll and validate realistic job state transitions instead of relying on fixed sleeps and narrow status expectations.

File-Level Changes

Change Details Files
Make host search steps in REX UI tests more robust by adding wait/retry logic.
  • Wrap host search calls in wait_for with a 30s timeout, 2s polling delay, and an empty-list fail condition to handle indexing/context delays before asserting on the first result.
  • Ensure multi-host searches use a lambda that captures the host name correctly per iteration.
  • Select the default location before host lookup in the custom job template test to match the expected search context.
tests/foreman/ui/test_remoteexecution.py
Refactor scheduled job by IP test to poll for and validate realistic job status progression instead of using fixed sleep-based timing assumptions.
  • Keep using the scheduled plan_time but assert immediately that there is still positive time left, with a clearer failure message if not.
  • Replace the previous combination of time.sleep and wait_for calls on specific statuses with a polling loop that repeatedly reads job status until it reaches a terminal state or a calculated timeout.
  • Track all observed status transitions in a list and assert that the job ends in Succeeded while having passed through appropriate pre-run and running states (or a valid direct transition), emitting clear diagnostics if expectations are not met.
  • Reuse the final job status both for state validation and final assertions on overall success and host name instead of mixing interim and final reads.
tests/foreman/ui/test_remoteexecution.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

@rmynar

rmynar commented Jun 4, 2026

Copy link
Copy Markdown
Contributor Author

trigger: test-robottelo
pytest: tests/foreman/ui/test_remoteexecution.py
airgun: 2454

@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 1 issue, and left some high level feedback:

  • The host search with wait_for is now duplicated in several tests; consider extracting a small helper (e.g. wait_for_host(session, hostname)) to remove repetition and keep search behavior consistent across tests.
  • The manual polling loop for job state transitions in test_positive_run_scheduled_job_template_by_ip reimplements timeout/loop logic; consider expressing this with one or more wait_for calls so the timing, retry behavior, and failure messages are consistent with the rest of the suite.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The host search with `wait_for` is now duplicated in several tests; consider extracting a small helper (e.g. `wait_for_host(session, hostname)`) to remove repetition and keep search behavior consistent across tests.
- The manual polling loop for job state transitions in `test_positive_run_scheduled_job_template_by_ip` reimplements timeout/loop logic; consider expressing this with one or more `wait_for` calls so the timing, retry behavior, and failure messages are consistent with the rest of the suite.

## Individual Comments

### Comment 1
<location path="tests/foreman/ui/test_remoteexecution.py" line_range="133-139" />
<code_context>
         session.organization.select(module_org.name)
-        assert session.host.search(hostname)[0]['Name'] == hostname
+        # Search with retry to handle potential context/indexing delays
+        result = wait_for(
+            lambda: session.host.search(hostname),
+            timeout=30,
+            delay=2,
+            fail_condition=[],
+        ).out
+        assert result[0]['Name'] == hostname
         command = 'ls'
         session.jobinvocation.run(
</code_context>
<issue_to_address>
**suggestion:** Consider extracting the retrying host search into a shared helper to avoid duplication and keep behavior consistent across tests.

This retrying `session.host.search` logic now appears in several tests (`test_positive_run_default_job_template`, `test_positive_run_custom_job_template`, `test_positive_run_job_template_multiple_hosts`, `test_positive_run_scheduled_job_template_by_ip`). Please consider a small helper (e.g. `search_host_with_retry(session, hostname)`) that wraps `wait_for` with the shared timeout/delay/fail_condition so tests share the same semantics and future changes only need to be made in one place.

Suggested implementation:

```python
    with target_sat.ui_session() as session:
        session.organization.select(module_org.name)
        result = search_host_with_retry(session, hostname)
        assert result[0]['Name'] == hostname
        command = 'ls'
        session.jobinvocation.run(
            {

```

```python
    job_template_name = gen_string('alpha')
    with target_sat.ui_session() as session:
        session.organization.select(module_org.name)
        session.location.select(default_location.name)
        result = search_host_with_retry(session, hostname)

```

To fully implement the helper and remove duplication across the file, also make these changes:

1. **Add the shared helper** near the top of `tests/foreman/ui/test_remoteexecution.py`, at module scope (outside any test functions), after the existing imports and any module-level constants:

```python
def search_host_with_retry(session, hostname):
    """Search host with retry to handle potential context/indexing delays."""
    return wait_for(
        lambda: session.host.search(hostname),
        timeout=30,
        delay=2,
        fail_condition=[],
    ).out
```

`wait_for` is already imported in this file (since the current code uses it), so no new imports should be necessary.

2. **Update all other duplicated usages** in the same file (e.g. in `test_positive_run_default_job_template`, `test_positive_run_custom_job_template`, `test_positive_run_job_template_multiple_hosts`, `test_positive_run_scheduled_job_template_by_ip`) by replacing the inline `wait_for(...).out` blocks that wrap `session.host.search(...)` with:

```python
result = search_host_with_retry(session, hostname)
```

(or the appropriate variable such as `hostname_1`, `hostname_2`, etc.).

Once these changes are applied, all tests will share the same retry semantics and future adjustments to timeout/delay/fail_condition can be made in a single place.
</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 +133 to +139
result = wait_for(
lambda: session.host.search(hostname),
timeout=30,
delay=2,
fail_condition=[],
).out
assert result[0]['Name'] == hostname

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: Consider extracting the retrying host search into a shared helper to avoid duplication and keep behavior consistent across tests.

This retrying session.host.search logic now appears in several tests (test_positive_run_default_job_template, test_positive_run_custom_job_template, test_positive_run_job_template_multiple_hosts, test_positive_run_scheduled_job_template_by_ip). Please consider a small helper (e.g. search_host_with_retry(session, hostname)) that wraps wait_for with the shared timeout/delay/fail_condition so tests share the same semantics and future changes only need to be made in one place.

Suggested implementation:

    with target_sat.ui_session() as session:
        session.organization.select(module_org.name)
        result = search_host_with_retry(session, hostname)
        assert result[0]['Name'] == hostname
        command = 'ls'
        session.jobinvocation.run(
            {
    job_template_name = gen_string('alpha')
    with target_sat.ui_session() as session:
        session.organization.select(module_org.name)
        session.location.select(default_location.name)
        result = search_host_with_retry(session, hostname)

To fully implement the helper and remove duplication across the file, also make these changes:

  1. Add the shared helper near the top of tests/foreman/ui/test_remoteexecution.py, at module scope (outside any test functions), after the existing imports and any module-level constants:
def search_host_with_retry(session, hostname):
    """Search host with retry to handle potential context/indexing delays."""
    return wait_for(
        lambda: session.host.search(hostname),
        timeout=30,
        delay=2,
        fail_condition=[],
    ).out

wait_for is already imported in this file (since the current code uses it), so no new imports should be necessary.

  1. Update all other duplicated usages in the same file (e.g. in test_positive_run_default_job_template, test_positive_run_custom_job_template, test_positive_run_job_template_multiple_hosts, test_positive_run_scheduled_job_template_by_ip) by replacing the inline wait_for(...).out blocks that wrap session.host.search(...) with:
result = search_host_with_retry(session, hostname)

(or the appropriate variable such as hostname_1, hostname_2, etc.).

Once these changes are applied, all tests will share the same retry semantics and future adjustments to timeout/delay/fail_condition can be made in a single place.

@Satellite-QE

Copy link
Copy Markdown
Collaborator

PRT Result

Build Number: 15706
Build Status: UNSTABLE
PRT Comment: pytest tests/foreman/ui/test_remoteexecution.py --external-logging
Test Result : ============ 3 failed, 5 passed, 69 warnings in 4405.26s (1:13:25) =============

@Satellite-QE Satellite-QE added the PRT-Failed Indicates that latest PRT run is failed for the PR label Jun 4, 2026
@pnovotny pnovotny self-requested a review June 4, 2026 12:26
@Satellite-QE

Copy link
Copy Markdown
Collaborator

PRT Result

Build Number: 15708
Build Status: UNSTABLE
PRT Comment: pytest tests/foreman/ui/test_remoteexecution.py --external-logging
Test Result : ============ 3 failed, 5 passed, 68 warnings in 3664.52s (1:01:04) =============

@rmynar rmynar force-pushed the sat-41520 branch 2 times, most recently from a89f97f to 83f9ec1 Compare June 11, 2026 17:37
@rmynar

rmynar commented Jun 16, 2026

Copy link
Copy Markdown
Contributor Author

trigger: test-robottelo
pytest: tests/foreman/ui/test_remoteexecution.py
airgun: 2454

@Satellite-QE

Copy link
Copy Markdown
Collaborator

PRT Result

Build Number: 15854
Build Status: UNSTABLE
PRT Comment: pytest tests/foreman/ui/test_remoteexecution.py --external-logging
Test Result : ============ 2 failed, 6 passed, 69 warnings in 4369.40s (1:12:49) =============

@rmynar

rmynar commented Jun 30, 2026

Copy link
Copy Markdown
Contributor Author

trigger: test-robottelo
pytest: tests/foreman/ui/test_remoteexecution.py
airgun: 2454

@Satellite-QE

Copy link
Copy Markdown
Collaborator

PRT Result

Build Number: 15987
Build Status: SUCCESS
PRT Comment: pytest tests/foreman/ui/test_remoteexecution.py --external-logging
Test Result : ================= 8 passed, 69 warnings in 3943.89s (1:05:43) ==================

@Satellite-QE Satellite-QE added PRT-Passed Indicates that latest PRT run is passed for the PR and removed PRT-Failed Indicates that latest PRT run is failed for the PR labels Jun 30, 2026
LadislavVasina1
LadislavVasina1 previously approved these changes Jul 1, 2026
@Satellite-QE Satellite-QE removed the PRT-Passed Indicates that latest PRT run is passed for the PR label Jul 7, 2026
@rmynar

rmynar commented Jul 8, 2026

Copy link
Copy Markdown
Contributor Author

trigger: test-robottelo
pytest: tests/foreman/ui/test_remoteexecution.py
airgun: 2454

@Satellite-QE

Copy link
Copy Markdown
Collaborator

PRT Result

Build Number: 16062
Build Status: SUCCESS
PRT Comment: pytest tests/foreman/ui/test_remoteexecution.py --external-logging
Test Result : ================= 8 passed, 69 warnings in 4722.17s (1:18:42) ==================

@Satellite-QE Satellite-QE added the PRT-Passed Indicates that latest PRT run is passed for the PR label Jul 8, 2026
@LadislavVasina1 LadislavVasina1 dismissed their stale review July 8, 2026 11:20

Want to check related airgun implementation as it has new changes.

Comment thread tests/foreman/ui/test_remoteexecution.py Outdated
Comment thread tests/foreman/ui/test_remoteexecution.py Outdated
@rmynar

rmynar commented Jul 13, 2026

Copy link
Copy Markdown
Contributor Author
trigger: test-robottelo
pytest: tests/foreman/ui/test_remoteexecution.py
airgun: 2454

@Satellite-QE

Copy link
Copy Markdown
Collaborator

PRT Result

Build Number: 16114
Build Status: UNSTABLE
PRT Comment: pytest tests/foreman/ui/test_remoteexecution.py --external-logging
Test Result : ============ 2 failed, 6 passed, 69 warnings in 4180.12s (1:09:40) =============

@Satellite-QE Satellite-QE added PRT-Failed Indicates that latest PRT run is failed for the PR and removed PRT-Passed Indicates that latest PRT run is passed for the PR labels Jul 13, 2026
@rmynar

rmynar commented Jul 13, 2026

Copy link
Copy Markdown
Contributor Author
trigger: test-robottelo
pytest: tests/foreman/ui/test_remoteexecution.py
airgun: 2454

@Satellite-QE

Copy link
Copy Markdown
Collaborator

PRT Result

Build Number: 16116
Build Status: SUCCESS
PRT Comment: pytest tests/foreman/ui/test_remoteexecution.py --external-logging
Test Result : ================= 8 passed, 69 warnings in 4574.86s (1:16:14) ==================

@Satellite-QE Satellite-QE added PRT-Passed Indicates that latest PRT run is passed for the PR and removed PRT-Failed Indicates that latest PRT run is failed for the PR labels Jul 13, 2026
@rmynar

rmynar commented Jul 14, 2026

Copy link
Copy Markdown
Contributor Author
trigger: test-robottelo
pytest: tests/foreman/ui/test_remoteexecution.py
airgun: 2454

@Satellite-QE

Copy link
Copy Markdown
Collaborator

PRT Result

Build Number: 16122
Build Status: SUCCESS
PRT Comment: pytest tests/foreman/ui/test_remoteexecution.py --external-logging
Test Result : ================= 8 passed, 68 warnings in 4794.70s (1:19:54) ==================

Comment thread tests/foreman/ui/test_remoteexecution.py Outdated
@Satellite-QE Satellite-QE removed the PRT-Passed Indicates that latest PRT run is passed for the PR label Jul 15, 2026
@rmynar

rmynar commented Jul 15, 2026

Copy link
Copy Markdown
Contributor Author
trigger: test-robottelo
pytest: tests/foreman/ui/test_remoteexecution.py
airgun: 2454

@LadislavVasina1 LadislavVasina1 requested a review from pondrejk July 15, 2026 11:11
@LadislavVasina1

Copy link
Copy Markdown
Contributor
trigger: test-robottelo
pytest: tests/foreman/ui/test_remoteexecution.py
airgun: 2454

@devendra104

Copy link
Copy Markdown
Member

trigger: test-robottelo
pytest: tests/foreman/ui/test_remoteexecution.py
airgun: 2454

1 similar comment
@devendra104

Copy link
Copy Markdown
Member

trigger: test-robottelo
pytest: tests/foreman/ui/test_remoteexecution.py
airgun: 2454

@Satellite-QE

Copy link
Copy Markdown
Collaborator

PRT Result

Build Number: 16132
Build Status: UNSTABLE
PRT Comment: pytest tests/foreman/ui/test_remoteexecution.py --external-logging
Test Result : ================= 16 warnings, 8 errors in 4632.99s (1:17:12) ==================

@Satellite-QE Satellite-QE added the PRT-Failed Indicates that latest PRT run is failed for the PR label Jul 15, 2026
@LadislavVasina1

Copy link
Copy Markdown
Contributor
trigger: test-robottelo
pytest: tests/foreman/ui/test_remoteexecution.py
airgun: 2454

@Satellite-QE

Copy link
Copy Markdown
Collaborator

PRT Result

Build Number: 16136
Build Status: UNSTABLE
PRT Comment: pytest tests/foreman/ui/test_remoteexecution.py --external-logging
Test Result : ================= 16 warnings, 8 errors in 4870.95s (1:21:10) ==================

@rmynar

rmynar commented Jul 16, 2026

Copy link
Copy Markdown
Contributor Author
trigger: test-robottelo
pytest: tests/foreman/ui/test_remoteexecution.py
airgun: 2454
env:
  ROBOTTELO_server__version__release: 'stream'
  ROBOTTELO_server__version__snap: '199.0'
  ROBOTTELO_server__deploy_arguments__deploy_sat_version: 'stream'
  ROBOTTELO_server__deploy_arguments__deploy_snap_version: '199.0'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

6.19.z AutoMerge_Cherry_Picked The cherrypicked PRs of master PR would be automerged if all checks passing CherryPick PR needs 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.

5 participants