Skip to content

[6.17.z] Fix Discovery provisioning tests - #21061

Closed
Satellite-QE wants to merge 1 commit into
6.17.zfrom
cherry-pick-6.17.z-9ff92d0ce1daf9b9ab0fed89f0861b2e1449e1aa
Closed

[6.17.z] Fix Discovery provisioning tests#21061
Satellite-QE wants to merge 1 commit into
6.17.zfrom
cherry-pick-6.17.z-9ff92d0ce1daf9b9ab0fed89f0861b2e1449e1aa

Conversation

@Satellite-QE

@Satellite-QE Satellite-QE commented Mar 19, 2026

Copy link
Copy Markdown
Collaborator

Cherrypick of PR: #20638

Problem Statement

Discovery provisioning tests are failing because dhcpd is not restarted after building PXE templates in the module_discovery_sat fixture. Without the restart, dhcpd serves old cached configuration.

Solution

Added dhcpd service restart in the module_discovery_sat fixture after all discovery configuration is complete. This ensures dhcpd picks up the updated PXE boot configuration and serves the correct discovery boot files to VMs.

Related Issues

Fixes: SAT-39920

Summary by Sourcery

Adjust discovery host provisioning tests and fixtures to handle discovery-specific preconditions and avoid relying on deprecated host assignment paths.

Bug Fixes:

  • Work around SAT-33477 in UI discovery provisioning tests by ensuring discovered hosts are assigned to the correct organization and location when they are missing from the CLI list.
  • Prevent stale discovered hosts from interfering with discovery provisioning by clearing existing discovered hosts in the provisioning fixture for discovery runs.

Tests:

  • Update UI discovery provisioning scenarios to use conditional organization/location assignment instead of directly setting provisioning attributes on discovered hosts.
  • Simplify API discovery reboot tests by removing unnecessary hostgroup and provisioning attribute assignments that are no longer required for the scenario.

* Fix Discovery provisioning tests

* Apply SAT-33477 workaround to UI tests

(cherry picked from commit 9ff92d0)
@Satellite-QE Satellite-QE added 6.17.z Auto_Cherry_Picked Automatically cherrypicked PR using GHA No-CherryPick PR doesnt need CherryPick to previous branches labels Mar 19, 2026
@Satellite-QE

Copy link
Copy Markdown
Collaborator Author
trigger: test-robottelo
pytest: tests/foreman/ --component DiscoveryImage
provisioning: true

@Satellite-QE Satellite-QE added the AutoMerge_Cherry_Picked The cherrypicked PRs of master PR would be automerged if all checks passing label Mar 19, 2026
@sourcery-ai

sourcery-ai Bot commented Mar 19, 2026

Copy link
Copy Markdown
Contributor

Reviewer's Guide

Adjusts discovery host provisioning tests to handle an open bug around missing org/location assignments, cleans discovery hosts before discovery provisioning, and relies on provisioning flow rather than direct field mutation in API tests.

Sequence diagram for discovery provisioning test flow with dhcpd restart and host cleanup

sequenceDiagram
    actor Tester
    participant Pytest as pytest_runner
    participant Fixture as module_provisioning_sat
    participant Sat as sat_instance
    participant API as sat_api
    participant DHCP as dhcpd_service

    Tester->>Pytest: run discovery_provisioning_tests
    Pytest->>Fixture: module_provisioning_sat(provisioning_type=discovery)

    Fixture->>Sat: configure_discovery_settings()
    Fixture->>Sat: build_PXE_templates()

    Note over Fixture,API: New behavior: clean preexisting discovered hosts
    Fixture->>API: DiscoveredHost().search()
    API-->>Fixture: list of discovered_hosts
    loop for each discovered_host
        Fixture->>API: discovered_host.delete()
        API-->>Fixture: delete_result
    end

    alt sat.network_type == IPV4
        Fixture->>Sat: execute(cat /dev/null > /var/lib/dhcpd/dhcpd.leases)
        Sat-->>Fixture: status 0
        Fixture->>Sat: execute(systemctl restart dhcpd)
        Sat-->>Fixture: status 0
        Sat->>DHCP: restart
        DHCP-->>Sat: ready_with_fresh_config
    end

    Fixture-->>Pytest: satellite_ready_for_discovery
    Pytest->>Sat: boot_discovery_VM()
    Sat->>DHCP: serve_PXE_config_for_discovery
    DHCP-->>Sat: correct_discovery_boot_files
    Sat-->>Pytest: discovered_hosts_created
    Pytest-->>Tester: tests_pass
Loading

Flow diagram for module_provisioning_sat discovery provisioning preparation

flowchart TD
    A[start module_provisioning_sat] --> B[Create hostgroup with provisioning settings]
    B --> C{provisioning_type == discovery?}

    C -- No --> E{sat.network_type == IPV4?}
    C -- Yes --> D[Search all DiscoveredHost via API]

    D --> D1[Iterate discovered_hosts]
    D1 --> D2[Call delete on each discovered_host]
    D2 --> E{sat.network_type == IPV4?}

    E -- No --> G[Return satellite_ready_for_provisioning]
    E -- Yes --> F[Clear /var/lib/dhcpd/dhcpd.leases and restart dhcpd]

    F --> G[Return satellite_ready_for_provisioning]
Loading

File-Level Changes

Change Details Files
Guard discovery UI tests with a workaround for SAT-33477 when discovered hosts are missing org/location assignments.
  • Replace direct assignment of hostgroup, organization, location, and build flag on discovered hosts with a conditional workaround guarded by is_open('SAT-33477').
  • When the bug is open and the discovered host list filtered by module org/location is empty, open a temporary UI session, switch to "Any organization" and "Any location", and use UI bulk actions to assign the correct organization and location to the discovered host.
  • Reuse the existing discovered_host object and subsequent logic (name/domain/host creation) without further behavioral changes.
tests/foreman/ui/test_discoveredhost.py
Ensure a clean discovery environment for provisioning tests that use discovery.
  • In the module_provisioning_sat fixture, when provisioning_type == 'discovery', delete all existing DiscoveredHost API objects prior to further configuration.
  • Keep existing IPv4-specific lease file cleanup and dhcpd restart behavior unchanged.
pytest_fixtures/component/provision_pxe.py
Rely on API reboot_all behavior without manually setting provisioning attributes in the discovered host reboot test.
  • Remove explicit assignments of hostgroup, location, organization, and build flag before calling reboot_all() on the discovered host in the API test.
  • Allow reboot_all() to operate on the discovered host as discovered, aligning the test with the new provisioning flow.
tests/foreman/api/test_discoveredhost.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

@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 left some high level feedback:

  • The SAT-33477 workaround logic in both test_positive_custom_provision_pxe_host and test_positive_auto_provision_host_with_rule is duplicated; consider extracting a small helper to assign organization/location to a discovered host to keep the tests easier to maintain.
  • In module_provisioning_sat, deleting all discovered hosts when provisioning_type == 'discovery' is a fairly broad side effect for a fixture; consider narrowing the deletion to the hosts created by this fixture or clearly scoping when this cleanup happens to avoid surprising interactions with other tests.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The SAT-33477 workaround logic in both `test_positive_custom_provision_pxe_host` and `test_positive_auto_provision_host_with_rule` is duplicated; consider extracting a small helper to assign organization/location to a discovered host to keep the tests easier to maintain.
- In `module_provisioning_sat`, deleting all discovered hosts when `provisioning_type == 'discovery'` is a fairly broad side effect for a fixture; consider narrowing the deletion to the hosts created by this fixture or clearly scoping when this cleanup happens to avoid surprising interactions with other tests.

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.

@github-actions

github-actions Bot commented May 4, 2026

Copy link
Copy Markdown

This pull request has not been updated in the past 45 days.

@github-actions github-actions Bot added the Stale Stale issue or Pull Request label May 4, 2026
@JacobCallahan

Copy link
Copy Markdown
Member

Hey @archanaserver, this cherry-pick PR has a PRT failure. Could you take a look and let us know if it's ready to merge despite the failure?

@github-actions github-actions Bot removed the Stale Stale issue or Pull Request label May 9, 2026
@github-actions

Copy link
Copy Markdown

This pull request has not been updated in the past 45 days.

@github-actions github-actions Bot added the Stale Stale issue or Pull Request label Jun 23, 2026
@github-actions

github-actions Bot commented Jul 1, 2026

Copy link
Copy Markdown

This pull request is now being closed after stale warnings.

@github-actions github-actions Bot closed this Jul 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

6.17.z Auto_Cherry_Picked Automatically cherrypicked PR using GHA AutoMerge_Cherry_Picked The cherrypicked PRs of master PR would be automerged if all checks passing No-CherryPick PR doesnt need CherryPick to previous branches Stale Stale issue or Pull Request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants