[6.17.z] Modifications in CLI and UI Libvirt CR to resolve key error #20176 - #20791
Conversation
Reviewer's guide (collapsed on small PRs)Reviewer's GuideUpdates 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 resetsequenceDiagram
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
File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- In
test_positive_provision_end_to_end(UI test),resultis reused for both the host search result and thevirshcommand 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, thecat /dev/null > /var/lib/dhcpd/dhcpd.leasespattern depends on shell redirection semantics; ifsat.executeever runs without a shell this will break—using something liketruncate -s 0 /var/lib/dhcpd/dhcpd.leaseswould 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>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| request.addfinalizer(lambda: sat.provisioning_cleanup(name)) | ||
| assert session.host.search(name)[0]['Name'] == name | ||
|
|
There was a problem hiding this comment.
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.
| 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 |
|
|
1 similar comment
|
|
Required UI and CLI test cases are passed |
|
Ack |
Problem Statement
Cherry pick of
Modifications in CLI and UI Libvirt CR to resolve key error failedSolution
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:
Enhancements: