-
Couldn't load subscription status.
- Fork 179
Network: Add case for detach-interface with --persistent when live xm… #6627
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Network: Add case for detach-interface with --persistent when live xm… #6627
Conversation
…l and inactive xml have different pci address xxx-299225: Detach-interface with --persistent when live xml and inactive xml have difference pci address for interface Signed-off-by: Yiqian Wei <[email protected]>
WalkthroughAdds a new test configuration and implementation script for testing libvirt virtual network hotplug detach interface behavior with persistent interfaces. The test verifies that detached persistent interfaces are properly removed from both active and inactive VM configurations. Changes
Sequence DiagramsequenceDiagram
participant Test
participant VM
participant libvirt
participant XML
Test->>VM: Start VM
Test->>libvirt: Attach initial interfaces (default 3)
libvirt->>VM: Configure interfaces
Test->>libvirt: Attach persistent interface with MAC
libvirt->>VM: Configure persistent interface
Test->>XML: Get PCI address from active XML
Test->>XML: Get PCI address from inactive XML
rect rgb(200, 220, 255)
Note over Test: Verify PCI addresses differ
end
Test->>libvirt: Detach persistent interface (--persistent)
libvirt->>VM: Remove persistent interface
Test->>XML: Verify interface removed from active XML
Test->>XML: Verify interface removed from inactive XML
rect rgb(220, 255, 220)
Note over Test: Cleanup and restore VM state
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes The additions include a straightforward configuration file (trivial) and a new test script with helper functions for interface operations, XML parsing, and verification logic. The script demonstrates moderate complexity through multi-step test orchestration and state validation across active and inactive configurations. Suggested reviewers
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (4)
libvirt/tests/src/virtual_network/hotplug/attach_detach_interface/detach_interface_persistent_pci_diff.py (4)
208-215: Reduce flakiness: replace fixed sleep with a short poll for XML readiness.Polling avoids race with libvirt XML updates.
Apply this diff:
- # Wait a moment for XML to stabilize - time.sleep(2) - - active_pci = get_interface_pci_address( - vm_name, persistent_mac, True) - inactive_pci = get_interface_pci_address( - vm_name, persistent_mac, False) + # Wait for both active/inactive XML to expose addresses + active_pci = inactive_pci = None + for _ in range(10): # ~10s max + active_pci = get_interface_pci_address(vm_name, persistent_mac, True) + inactive_pci = get_interface_pci_address(vm_name, persistent_mac, False) + if active_pci and inactive_pci: + break + time.sleep(1)
261-271: Reduce flakiness: poll for interface removal instead of fixed sleep.Wait until the interface disappears from both XMLs, then assert.
Apply this diff:
- # Wait a moment for XML to update - time.sleep(2) - - if check_interface_in_xml(vm_name, persistent_mac, True): - test.fail( - "Interface %s still exists in active XML after detach" % persistent_mac) - - if check_interface_in_xml(vm_name, persistent_mac, False): - test.fail( - "Interface %s still exists in inactive XML after detach" % persistent_mac) + # Wait for XMLs to reflect the detach + active_present = inactive_present = True + for _ in range(10): # ~10s max + active_present = check_interface_in_xml(vm_name, persistent_mac, True) + inactive_present = check_interface_in_xml(vm_name, persistent_mac, False) + if not active_present and not inactive_present: + break + time.sleep(1) + + if active_present: + test.fail("Interface %s still exists in active XML after detach" % persistent_mac) + if inactive_present: + test.fail("Interface %s still exists in inactive XML after detach" % persistent_mac)
285-293: Tighten cleanup error handling; avoid broadexcept Exception(Ruff BLE001).With
ignore_status=True, virsh returns a result; checkexit_statusand log details.Apply this diff:
- for mac in attached_macs: - try: - cleanup_options = set_interface_options( - iface_type, None, mac, "", "detach", None) - virsh.detach_interface( - vm_ref, cleanup_options, **virsh_dargs) - logging.info("Cleaned up interface with MAC %s", mac) - except Exception as e: - logging.warning( - "Failed to cleanup interface with MAC %s: %s", mac, e) + for mac in attached_macs: + cleanup_options = set_interface_options( + iface_type, None, mac, "", "detach", None) + res = virsh.detach_interface(vm_ref, cleanup_options, **virsh_dargs) + if res.exit_status != 0: + logging.warning("Cleanup detach failed for %s (rc=%s): %s", + mac, res.exit_status, res.stderr) + else: + logging.info("Cleaned up interface with MAC %s", mac)
11-14: Logger naming: avoid shadowing theloggingmodule.Rename the logger variable (e.g.,
LOGGER = log.getLogger(...)) and useLOGGER.info/debug(...)throughout for clarity.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
libvirt/tests/cfg/virtual_network/hotplug/attach_detach_interface/detach_interface_persistent_pci_diff.cfg(1 hunks)libvirt/tests/src/virtual_network/hotplug/attach_detach_interface/detach_interface_persistent_pci_diff.py(1 hunks)
🧰 Additional context used
🪛 Ruff (0.14.1)
libvirt/tests/src/virtual_network/hotplug/attach_detach_interface/detach_interface_persistent_pci_diff.py
291-291: Do not catch blind exception: Exception
(BLE001)
🔇 Additional comments (1)
libvirt/tests/cfg/virtual_network/hotplug/attach_detach_interface/detach_interface_persistent_pci_diff.cfg (1)
1-10: Config looks consistent with the new test.Parameters match the script defaults and flow; no blockers from config side.
| if active_pci == inactive_pci: | ||
| test.fail( | ||
| "PCI addresses are the same in active and inactive XML: %s", active_pci) | ||
| else: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix: incorrect use of test.fail with multiple args (TypeError).
test.fail() accepts a single string. Current code passes a format string plus a second arg, causing a runtime error.
Apply this diff:
- if active_pci == inactive_pci:
- test.fail(
- "PCI addresses are the same in active and inactive XML: %s", active_pci)
+ if active_pci == inactive_pci:
+ test.fail(
+ f"PCI addresses are the same in active and inactive XML: {active_pci}")🤖 Prompt for AI Agents
In
libvirt/tests/src/virtual_network/hotplug/attach_detach_interface/detach_interface_persistent_pci_diff.py
around lines 227-230, test.fail is called with multiple arguments which raises a
TypeError because test.fail accepts a single string; change the call to pass a
single formatted string (for example use an f-string, .format(), or %
interpolation) so the PCI value is embedded into the message, e.g.
test.fail(f"PCI addresses are the same in active and inactive XML:
{active_pci}").
|
Test results: |
…l and inactive xml have different pci address
xxx-299225: Detach-interface with --persistent when live xml and inactive xml have difference pci address for interface
Summary by CodeRabbit