Skip to content

[6.18.z] Fix Discovery provisioning tests - #21062

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

[6.18.z] Fix Discovery provisioning tests#21062
Satellite-QE wants to merge 1 commit into
6.18.zfrom
cherry-pick-6.18.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 provisioning tests and fixtures to better handle discovered host assignment and cleanup for discovery-based provisioning.

Bug Fixes:

  • Work around SAT-33477 by reassigning discovered hosts to the correct organization and location via the UI when CLI listing returns no hosts.
  • Prevent interference between discovery provisioning runs by deleting existing discovered hosts when provisioning type is discovery.

Tests:

  • Update UI discovery provisioning tests to conditionally manage discovered host org/location assignment based on current system behavior.
  • Simplify API discovery host reboot test by removing unnecessary hostgroup and build configuration steps.

@Satellite-QE Satellite-QE added 6.18.z Introduced in or relating directly to Satellite 6.18 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

This PR stabilizes discovery provisioning tests by cleaning up discovered hosts during provisioning setup and conditionally reassigning organization/location for discovered hosts in UI tests when a known bug is open, while leaving API tests to rely on automatic assignment and not forcing hostgroup/build via the API.

Sequence diagram for discovery provisioning fixture with discovered host cleanup

sequenceDiagram
    actor Tester
    participant Pytest as pytest_runner
    participant Fixture as module_provisioning_sat
    participant Sat as Satellite
    participant DHCPD as dhcpd_service

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

    rect rgb(230,230,250)
        Fixture ->> Sat: api.DiscoveredHost().search()
        Sat -->> Fixture: discovered_hosts_list
        loop for_each_discovered_host
            Fixture ->> Sat: host.delete()
            Sat -->> Fixture: host_deleted
        end
    end

    alt network_type_is_IPV4
        Fixture ->> Sat: execute(cat_null_dhcpd_leases)
        Sat -->> Fixture: status_0
        Fixture ->> Sat: execute(systemctl_restart_dhcpd)
        Sat ->> DHCPD: restart()
        DHCPD -->> Sat: restarted
        Sat -->> Fixture: status_0
    end

    Fixture -->> Pytest: ready_for_discovery_provisioning
    Pytest -->> Tester: run_tests_with_clean_discovery_state
Loading

Class diagram for Satellite discovery API usage in provisioning and tests

classDiagram
    class Satellite {
        +NetworkType network_type
        +API api
        +CommandResult execute(command)
    }

    class API {
        +DiscoveredHost DiscoveredHost()
    }

    class DiscoveredHost {
        +int id
        +string name
        +string organization
        +string location
        +string hostgroup
        +bool build
        +list~DiscoveredHost~ search()
        +void delete()
        +void assign_organization(organization)
        +void assign_location(location)
        +void set_hostgroup(hostgroup)
        +void set_build(build)
        +void save()
    }

    class CommandResult {
        +int status
        +string stdout
        +string stderr
    }

    class TestDiscoveredHostAPI {
        +void test_discovered_host_provisioning_uses_auto_assignment()
    }

    class TestDiscoveredHostUI {
        +void test_discovered_host_provisioning_with_conditional_reassignment()
    }

    Satellite --> API : has
    API --> DiscoveredHost : creates
    Satellite --> CommandResult : returns
    TestDiscoveredHostAPI --> Satellite : uses_api
    TestDiscoveredHostUI --> DiscoveredHost : reassigns_org_location_conditionally
    TestDiscoveredHostUI --> Satellite : uses_ui_and_api
Loading

File-Level Changes

Change Details Files
Add conditional UI-based org/location assignment workaround for discovered hosts in discovery provisioning UI tests when SAT-33477 is open and no discovered hosts are listed for the scoped org/location.
  • Wrap post-discovery host initialization in a conditional that checks is_open('SAT-33477') and an empty CLI DiscoveredHost list scoped by module_org and module_location.
  • Open a temporary UI session that switches org and location context to 'Any organization'/'Any location' to access the discovered host.
  • Apply UI actions to assign the correct organization and location to the discovered host using the discovered host name and module_org/module_location values.
tests/foreman/ui/test_discoveredhost.py
Adjust provisioning fixture to clean up discovered hosts before discovery provisioning and keep DHCP restart logic for IPv4 environments.
  • In the provisioning Satellite fixture, when provisioning_type is 'discovery', search for all DiscoveredHost records via the API and delete them to ensure a clean slate before tests run.
  • Retain existing IPv4-specific cleanup by truncating dhcpd.leases and restarting the dhcpd service.
pytest_fixtures/component/provision_pxe.py
Simplify API-based discovered host reboot test to rely on existing org/location/hostgroup assignment instead of setting those attributes and build state explicitly.
  • Remove lines that explicitly set hostgroup, location, organization, and build=True on the discovered host before calling reboot_all().
  • Leave the test to validate the reboot_all() behavior with whatever assignments are made by the preceding 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 found 1 issue, and left some high level feedback:

  • The is_open('SAT-33477') UI-based reassignment logic for discovered hosts is duplicated in multiple tests; consider extracting this into a small helper to keep the tests DRY and make the workaround easier to remove once the bug is closed.
  • In module_provisioning_sat, deleting all DiscoveredHost records when provisioning_type == 'discovery' is quite broad; if possible, scope the cleanup (e.g., by org/location or a naming convention) to avoid unintended removal of unrelated discovered hosts used by other tests.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The `is_open('SAT-33477')` UI-based reassignment logic for discovered hosts is duplicated in multiple tests; consider extracting this into a small helper to keep the tests DRY and make the workaround easier to remove once the bug is closed.
- In `module_provisioning_sat`, deleting all `DiscoveredHost` records when `provisioning_type == 'discovery'` is quite broad; if possible, scope the cleanup (e.g., by org/location or a naming convention) to avoid unintended removal of unrelated discovered hosts used by other tests.

## Individual Comments

### Comment 1
<location path="pytest_fixtures/component/provision_pxe.py" line_range="214-216" />
<code_context>
         remote_execution_proxy=[module_provisioning_capsule.id],
         domain=[domain.id],
     ).create()
+    if provisioning_type == 'discovery':
+        for host in sat.api.DiscoveredHost().search():
+            host.delete()
+
     if sat.network_type == NetworkType.IPV4:
</code_context>
<issue_to_address>
**issue (bug_risk):** Narrow the scope of discovered host deletion to avoid removing unrelated hosts.

This currently deletes all discovered hosts whenever `provisioning_type == 'discovery'`, which can remove hosts belonging to other tests or users on the same Satellite. Please restrict the search (e.g., by org/location, hostname pattern, or run-specific metadata) so only resources created by this scenario are deleted.
</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 +214 to +216
if provisioning_type == 'discovery':
for host in sat.api.DiscoveredHost().search():
host.delete()

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.

issue (bug_risk): Narrow the scope of discovered host deletion to avoid removing unrelated hosts.

This currently deletes all discovered hosts whenever provisioning_type == 'discovery', which can remove hosts belonging to other tests or users on the same Satellite. Please restrict the search (e.g., by org/location, hostname pattern, or run-specific metadata) so only resources created by this scenario are deleted.

* Fix Discovery provisioning tests

* Apply SAT-33477 workaround to UI tests

(cherry picked from commit 9ff92d0)
@Gauravtalreja1
Gauravtalreja1 force-pushed the cherry-pick-6.18.z-9ff92d0ce1daf9b9ab0fed89f0861b2e1449e1aa branch from 01477e2 to e05941d Compare March 30, 2026 10:57
@Gauravtalreja1

Copy link
Copy Markdown
Member

trigger: test-robottelo
pytest: tests/foreman/ --component DiscoveryImage
provisioning: true

@Satellite-QE

Copy link
Copy Markdown
Collaborator Author

PRT Result

Build Number: 95
Build Status: UNSTABLE
PRT Comment: pytest tests/foreman/ --component DiscoveryImage --external-logging --include-onprem-provisioning
Test Result : = 7 failed, 15 passed, 5783 deselected, 587 warnings, 8 errors in 16584.10s (4:36:24) =

@Satellite-QE Satellite-QE added the PRT-Failed Indicates that latest PRT run is failed for the PR label Apr 1, 2026
@Satellite-QE

Copy link
Copy Markdown
Collaborator Author

PRT Result

Build Number: 14960
Build Status: UNSTABLE
PRT Comment: pytest tests/foreman/ --component DiscoveryImage --external-logging --include-onprem-provisioning
Test Result : = 13 failed, 15 passed, 5783 deselected, 705 warnings, 7 errors in 29967.97s (8:19:27) =

@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

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.18.z Introduced in or relating directly to Satellite 6.18 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 PRT-Failed Indicates that latest PRT run is failed for the PR Stale Stale issue or Pull Request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants