Skip to content

[6.17.z] Modifications in CLI and UI Libvirt CR to resolve key error #20176 - #20791

Merged
amolpati30 merged 1 commit into
SatelliteQE:6.17.zfrom
nacoool:test_6.17.z
Feb 18, 2026
Merged

[6.17.z] Modifications in CLI and UI Libvirt CR to resolve key error #20176#20791
amolpati30 merged 1 commit into
SatelliteQE:6.17.zfrom
nacoool:test_6.17.z

Conversation

@nacoool

@nacoool nacoool commented Feb 12, 2026

Copy link
Copy Markdown
Contributor

Problem Statement

Cherry pick of Modifications in CLI and UI Libvirt CR to resolve key error failed

Solution

New PR to add CP manually for #20176

Related Issues

Summary by Sourcery

Adjust Libvirt compute resource provisioning tests and fixtures to improve robustness and alignment with current APIs.

Bug Fixes:

  • Prevent key errors in CLI provisioning status checks by safely accessing host status fields and enabling exception handling in the wait loop.
  • Update UI provisioning tests to use the correct host search API and query format when validating created hosts and secure boot configuration.
  • Ensure IPv4 provisioning reliably obtains addresses by clearing DHCP leases and restarting the DHCP service before tests.

Enhancements:

  • Skip the Libvirt CLI end-to-end provisioning test when a known issue affecting UEFI or SecureBoot firmware is still open.

@nacoool nacoool added TestFailure Issues and PRs related to a test failing in automation No-CherryPick PR doesnt need CherryPick to previous branches Failed_AutoCherryPick Issue for failed/conflicted auto cherry pick of PRs 6.17.z labels Feb 12, 2026
@sourcery-ai

sourcery-ai Bot commented Feb 12, 2026

Copy link
Copy Markdown
Contributor
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Updates Libvirt compute resource provisioning tests to be more robust against environment differences (UEFI/SecureBoot, missing status fields, DHCP lease issues) and aligns UI tests with the current host search API.

Sequence diagram for provisioning_sat with DHCP lease reset

sequenceDiagram
    participant Test as pytest_test
    participant Fixture as module_provisioning_sat
    participant Sat as satellite_server
    participant DHCP as dhcpd_service

    Test->>Fixture: request provisioning with parameters
    Fixture->>Sat: obtain module_target_sat
    Fixture->>Sat: configure provisioning entities
    Note over Fixture,Sat: Create subnet, domain, compute resource, etc.

    alt network_type is 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
        Fixture->>DHCP: DHCP leases cleared and service restarted
    else network_type is not IPv4
        Fixture-->>Fixture: skip DHCP lease reset
    end

    Fixture-->>Test: return Box sat domain subnet provisioning_type
Loading

File-Level Changes

Change Details Files
Harden CLI Libvirt end-to-end provisioning test against UEFI loaders, missing status fields, and transient CLI errors.
  • Skip the test when SAT-41340 is open and the PXE loader firmware is UEFI or UEFI SecureBoot.
  • Wrap Host.info status lookup in dict.get calls to avoid KeyError when the status or build-status fields are missing, while keeping the pending-installation wait condition intact.
  • Enable exception handling in the wait_for loop to tolerate intermittent CLI failures during host status polling.
tests/foreman/cli/test_computeresource_libvirt.py
Align UI Libvirt provisioning test with updated host search interface and more reliable host lookup.
  • Use session.host_new.search instead of session.host.search when verifying the created host and assert on the returned Name field.
  • Change the SecureBoot verification host lookup to search by fully qualified host name via the API search parameter instead of the older host parameter.
tests/foreman/ui/test_computeresource_libvirt.py
Improve provisioning fixture reliability on IPv4 networks by clearing stale DHCP leases and restarting dhcpd.
  • Document that IPv4 provisioning clears DHCP leases and restarts dhcpd to ensure new addresses can be obtained.
  • When the Satellite network type is IPv4, clear /var/lib/dhcpd/dhcpd.leases via a remote command and restart the dhcpd service, asserting both commands succeed before returning the fixture state.
pytest_fixtures/component/provision_pxe.py

Possibly linked issues

  • #Failed-AutoCherryPick: The PR manually cherry-picks the same Libvirt CLI/UI key error changes that the failed auto-cherry-pick targeted.
  • #[Failed-AutoCherryPick]: They refer to the same Libvirt CLI/UI CR key error fix; PR manually replaces the failed auto-cherrypick.
  • #[Failed-AutoCherryPick]: Link: PR is the manual cherry-pick implementing the Libvirt CLI/UI key error fix that auto-cherry-pick failed.

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:

  • In test_positive_provision_end_to_end (UI test), result is reused for both the host search result and the virsh command output, which makes the code harder to read and reason about; consider using more descriptive, distinct variable names for these different values.
  • In module_provisioning_sat, the cat /dev/null > /var/lib/dhcpd/dhcpd.leases pattern depends on shell redirection semantics; if sat.execute ever runs without a shell this will break—using something like truncate -s 0 /var/lib/dhcpd/dhcpd.leases would be more robust.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `test_positive_provision_end_to_end` (UI test), `result` is reused for both the host search result and the `virsh` command output, which makes the code harder to read and reason about; consider using more descriptive, distinct variable names for these different values.
- In `module_provisioning_sat`, the `cat /dev/null > /var/lib/dhcpd/dhcpd.leases` pattern depends on shell redirection semantics; if `sat.execute` ever runs without a shell this will break—using something like `truncate -s 0 /var/lib/dhcpd/dhcpd.leases` would be more robust.

## Individual Comments

### Comment 1
<location> `tests/foreman/ui/test_computeresource_libvirt.py:183-185` </location>
<code_context>
         )
         name = f'{hostname}.{module_libvirt_provisioning_sat.domain.name}'
         request.addfinalizer(lambda: sat.provisioning_cleanup(name))
-        assert session.host.search(name)[0]['Name'] == name
-
+        result = session.host_new.search(name)[0]
+        assert result['Name'] == name
         # Check on Libvirt, if VM exists
         result = sat.execute(
</code_context>

<issue_to_address>
**suggestion:** Guard against empty search results before indexing to improve test failure messages.

`session.host_new.search(name)[0]` will raise `IndexError` if no host is found, instead of a clear assertion failure. Capture the results first and assert they are non-empty (e.g. `results = session.host_new.search(name); assert results, 'Expected host ...'; result = results[0]`) before asserting `result['Name'] == name`.

```suggestion
        request.addfinalizer(lambda: sat.provisioning_cleanup(name))
        results = session.host_new.search(name)
        assert results, f"Expected host '{name}' to be present in session.host_new.search results"
        result = results[0]
        assert result['Name'] == name
```
</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 183 to -185
request.addfinalizer(lambda: sat.provisioning_cleanup(name))
assert session.host.search(name)[0]['Name'] == name

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: Guard against empty search results before indexing to improve test failure messages.

session.host_new.search(name)[0] will raise IndexError if no host is found, instead of a clear assertion failure. Capture the results first and assert they are non-empty (e.g. results = session.host_new.search(name); assert results, 'Expected host ...'; result = results[0]) before asserting result['Name'] == name.

Suggested change
request.addfinalizer(lambda: sat.provisioning_cleanup(name))
assert session.host.search(name)[0]['Name'] == name
request.addfinalizer(lambda: sat.provisioning_cleanup(name))
results = session.host_new.search(name)
assert results, f"Expected host '{name}' to be present in session.host_new.search results"
result = results[0]
assert result['Name'] == name

@nacoool

nacoool commented Feb 12, 2026

Copy link
Copy Markdown
Contributor Author
trigger: test-robottelo
pytest: tests/foreman/ui/test_computeresource_libvirt.py -k "test_positive_provision_end_to_end"
provisioning: true

@Gauravtalreja1 Gauravtalreja1 changed the title cherrypick : Modifications in CLI and UI Libvirt CR to resolve key error #20176 [6.17.z] Modifications in CLI and UI Libvirt CR to resolve key error #20176 Feb 12, 2026
@nacoool

nacoool commented Feb 17, 2026

Copy link
Copy Markdown
Contributor Author
trigger: test-robottelo
pytest: tests/foreman/cli/test_computeresource_libvirt.py -k "test_positive_provision_end_to_end"
provisioning: true

1 similar comment
@devendra104

Copy link
Copy Markdown
Member
trigger: test-robottelo
pytest: tests/foreman/cli/test_computeresource_libvirt.py -k "test_positive_provision_end_to_end"
provisioning: true

@nacoool

nacoool commented Feb 18, 2026

Copy link
Copy Markdown
Contributor Author

Required UI and CLI test cases are passed

@amolpati30

Copy link
Copy Markdown
Contributor

Ack

@amolpati30
amolpati30 merged commit 4ce3685 into SatelliteQE:6.17.z Feb 18, 2026
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

6.17.z Failed_AutoCherryPick Issue for failed/conflicted auto cherry pick of PRs No-CherryPick PR doesnt need CherryPick to previous branches TestFailure Issues and PRs related to a test failing in automation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants