Skip to content

Fix pci_diff_detach: add --live to detach and wait for async hotunplug#6815

Open
BulaYoungR wants to merge 1 commit intoautotest:masterfrom
BulaYoungR:attach_interface
Open

Fix pci_diff_detach: add --live to detach and wait for async hotunplug#6815
BulaYoungR wants to merge 1 commit intoautotest:masterfrom
BulaYoungR:attach_interface

Conversation

@BulaYoungR
Copy link

@BulaYoungR BulaYoungR commented Mar 3, 2026

The detach used only --persistent, which doesn't remove the interface from active XML of a running VM. Added --live flag and replaced the immediate XML check with utils_misc.wait_for() polling, since PCI hotunplug is asynchronous and the device may not disappear instantly.

Committer: Bolatbek Issakh bissakh@redhat.com

Summary by CodeRabbit

Release Notes

  • Tests
    • Enhanced virtual network interface hotplug testing with more robust verification of interface removal.
    • Introduced polling-based approach for interface state verification with improved timeout handling.
    • Strengthened test coverage for live and persistent interface attachment and detachment operations.

The detach used only --persistent, which doesn't remove the interface
from active XML of a running VM. Added --live flag and replaced the
immediate XML check with utils_misc.wait_for() polling, since PCI
hotunplug is asynchronous and the device may not disappear instantly.

Committer: Bolatbek Issakh <bissakh@redhat.com>
@coderabbitai
Copy link

coderabbitai bot commented Mar 3, 2026

Walkthrough

A test file for virtual network interface hotplug operations has been modified to change how interface detachment is verified. The detach interface command now includes both --live and --persistent flags. The verification process has been updated from immediate XML checks to a polling-based approach using a new _check_interface_detached() function that waits up to 60 seconds for the interface to disappear from active XML before proceeding with inactive XML verification. The utils_misc module has been imported to support these changes.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and specifically describes the main changes: adding --live flag to detach and implementing wait-based polling for async hotunplug.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).
Share your feedback on Discord.


Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
libvirt/tests/src/virtual_network/hotplug/attach_detach_interface/attach_interface_with_options_and_vm_status.py (1)

265-277: Correct approach for handling asynchronous PCI hotunplug.

The polling mechanism using utils_misc.wait_for() is the right solution since PCI hotunplug is asynchronous and the device may not disappear from the XML immediately. The 60-second timeout with 5-second steps provides reasonable tolerance for the operation to complete.

Consider parameterizing the timeout and step values for easier adjustment in different test environments:

+    detach_timeout = params.get_numeric("detach_timeout", 60)
+    detach_step = params.get_numeric("detach_step", 5)
     ...
-    if not utils_misc.wait_for(_check_interface_detached, timeout=60, step=5):
+    if not utils_misc.wait_for(_check_interface_detached, timeout=detach_timeout, step=detach_step):
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@libvirt/tests/src/virtual_network/hotplug/attach_detach_interface/attach_interface_with_options_and_vm_status.py`
around lines 265 - 277, Parameterize the hard-coded polling values used for PCI
hotunplug by replacing the inline numbers in the utils_misc.wait_for call inside
the _check_interface_detached block with configurable variables (e.g.,
HOTUNPLUG_TIMEOUT and HOTUNPLUG_STEP) so tests can adjust timing per
environment; update the call to utils_misc.wait_for(_check_interface_detached,
timeout=HOTUNPLUG_TIMEOUT, step=HOTUNPLUG_STEP) and ensure any related checks
(the subsequent check_interface_xml calls and the test.fail messages) reference
or document these parameters so maintainers can tune the timeout and step
without changing the function body.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In
`@libvirt/tests/src/virtual_network/hotplug/attach_detach_interface/attach_interface_with_options_and_vm_status.py`:
- Around line 265-277: Parameterize the hard-coded polling values used for PCI
hotunplug by replacing the inline numbers in the utils_misc.wait_for call inside
the _check_interface_detached block with configurable variables (e.g.,
HOTUNPLUG_TIMEOUT and HOTUNPLUG_STEP) so tests can adjust timing per
environment; update the call to utils_misc.wait_for(_check_interface_detached,
timeout=HOTUNPLUG_TIMEOUT, step=HOTUNPLUG_STEP) and ensure any related checks
(the subsequent check_interface_xml calls and the test.fail messages) reference
or document these parameters so maintainers can tune the timeout and step
without changing the function body.

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5a1710f and fefb1b3.

📒 Files selected for processing (1)
  • libvirt/tests/src/virtual_network/hotplug/attach_detach_interface/attach_interface_with_options_and_vm_status.py

@BulaYoungR
Copy link
Author

Before fix

JOB ID     : 947a7c3930eddcff1023f34bc4282b8eb0af0cab
JOB LOG    : /var/log/avocado/job-results/job-2026-03-03T11.46-947a7c3/job.log
 (1/1) type_specific.io-github-autotest-libvirt.virtual_network.hotplug.attach_interface.options_and_vm_status.persistent_option.diff_pci_for_active_and_inactive_xml.vm_running: STARTED
 (1/1) type_specific.io-github-autotest-libvirt.virtual_network.hotplug.attach_interface.options_and_vm_status.persistent_option.diff_pci_for_active_and_inactive_xml.vm_running: ERROR: module 'virttest.utils_net' has no attribute 'wait_for' (35.71 s)
RESULTS    : PASS 0 | ERROR 1 | FAIL 0 | SKIP 0 | WARN 0 | INTERRUPT 0 | CANCEL 0
JOB HTML   : /var/log/avocado/job-results/job-2026-03-03T11.46-947a7c3/results.html
JOB TIME   : 36.89 s

Test summary:
1-type_specific.io-github-autotest-libvirt.virtual_network.hotplug.attach_interface.options_and_vm_status.persistent_option.diff_pci_for_active_and_inactive_xml.vm_running: ERROR

After fix

JOB ID     : 06bd40e012b9ab8ac45659f5d2fe1655d76a2398
JOB LOG    : /var/log/avocado/job-results/job-2026-03-03T11.51-06bd40e/job.log
 (1/1) type_specific.io-github-autotest-libvirt.virtual_network.hotplug.attach_interface.options_and_vm_status.persistent_option.diff_pci_for_active_and_inactive_xml.vm_running: STARTED
 (1/1) type_specific.io-github-autotest-libvirt.virtual_network.hotplug.attach_interface.options_and_vm_status.persistent_option.diff_pci_for_active_and_inactive_xml.vm_running: PASS (41.70 s)
RESULTS    : PASS 1 | ERROR 0 | FAIL 0 | SKIP 0 | WARN 0 | INTERRUPT 0 | CANCEL 0
JOB HTML   : /var/log/avocado/job-results/job-2026-03-03T11.51-06bd40e/results.html
JOB TIME   : 42.78 s

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant