Improve VM lifecycle management for iface_update#6810
Improve VM lifecycle management for iface_update#6810yanglei-rh wants to merge 1 commit intoautotest:masterfrom
Conversation
WalkthroughAdds libvirt-related configuration keys to the iface_update test config to enable libvirt VM creation, skip reboots, and force libvirt VM kill with OVMF NVRAM options. In test code, introduces a Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
libvirt/tests/src/virtual_network/iface_update.py (2)
254-277: Avoid redundant libvirtd restarts when MTU already triggers one.
Withiface_mtuset, you restart once in the MTU block and again here; a simple flag keeps the workaround while preventing an extra bounce.♻️ Suggested diff
- if iface_mtu: + libvirtd_restarted = False + if iface_mtu: # Do check for mtu size after start vm target_dev = libvirt.get_interface_details(vm_name)[0]['interface'] cmd = "ip link show %s | grep 'mtu %s'" % (target_dev, eval(iface_mtu)['size']) @@ check_mtu() utils_libvirtd.libvirtd_restart() + libvirtd_restarted = True check_mtu() # This is a workaround to let virt-install create vm can be management by domif-setlink # and cleanup exists serial session, since restart libvirtd will render the original invalid - if not cold_update and vm.is_alive(): + if not cold_update and vm.is_alive() and not libvirtd_restarted: logging.info("Restart libvirtd server") libvirtd = utils_libvirtd.Libvirtd() libvirtd.restart() + libvirtd_restarted = True🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@libvirt/tests/src/virtual_network/iface_update.py` around lines 254 - 277, The code may restart libvirtd twice when iface_mtu is set (once via utils_libvirtd.libvirtd_restart() in the MTU block and again later via libvirtd.restart()); add a simple boolean flag (e.g., mturestarted) set to True after calling utils_libvirtd.libvirtd_restart() inside the iface_mtu branch, then in the later workaround before calling libvirtd.restart() check both not cold_update and vm.is_alive() and that mturestarted is False to skip the redundant restart; update references in this function to use the new flag around the utils_libvirtd.libvirtd_restart() and libvirtd.restart() calls so the restart only happens once.
323-329: Consider recreating the serial console only when libvirtd was actually restarted.
This avoids unnecessary console resets when no restart occurred.♻️ Suggested diff
- # Cleanup and recreate serial console since libvirtd was restarted - if vm.serial_console: - vm.cleanup_serial_console() - - # Recreate serial console after libvirtd restart - vm.create_serial_console() + # Cleanup and recreate serial console since libvirtd was restarted + if libvirtd_restarted: + if vm.serial_console: + vm.cleanup_serial_console() + # Recreate serial console after libvirtd restart + vm.create_serial_console()🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@libvirt/tests/src/virtual_network/iface_update.py` around lines 323 - 329, The code always cleans up and recreates the serial console regardless of whether libvirtd was restarted; change it to only run vm.cleanup_serial_console() and vm.create_serial_console() when a libvirtd-restart condition is true (e.g., check a restart flag or call a detection helper such as vm.was_libvirtd_restarted() or a local libvirtd_restarted variable). Wrap the existing vm.serial_console check and the recreate call inside a conditional that verifies libvirtd was actually restarted so the console is only reset after an actual restart.
🤖 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/iface_update.py`:
- Around line 254-277: The code may restart libvirtd twice when iface_mtu is set
(once via utils_libvirtd.libvirtd_restart() in the MTU block and again later via
libvirtd.restart()); add a simple boolean flag (e.g., mturestarted) set to True
after calling utils_libvirtd.libvirtd_restart() inside the iface_mtu branch,
then in the later workaround before calling libvirtd.restart() check both not
cold_update and vm.is_alive() and that mturestarted is False to skip the
redundant restart; update references in this function to use the new flag around
the utils_libvirtd.libvirtd_restart() and libvirtd.restart() calls so the
restart only happens once.
- Around line 323-329: The code always cleans up and recreates the serial
console regardless of whether libvirtd was restarted; change it to only run
vm.cleanup_serial_console() and vm.create_serial_console() when a
libvirtd-restart condition is true (e.g., check a restart flag or call a
detection helper such as vm.was_libvirtd_restarted() or a local
libvirtd_restarted variable). Wrap the existing vm.serial_console check and the
recreate call inside a conditional that verifies libvirtd was actually restarted
so the console is only reset after an actual restart.
ℹ️ Review info
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
libvirt/tests/cfg/virtual_network/iface_update.cfglibvirt/tests/src/virtual_network/iface_update.py
c8724e9 to
5df6e35
Compare
|
Test pass. |
1.Add some parameters to allow the framework provide guest xml 2.Restart libvirt service as a woraround for using virt-install bootup guest and create an new serial session for guest 3.Add "only Linux" to limit guest type Signed-off-by: Lei Yang <leiyang@redhat.com>
5df6e35 to
501f553
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@libvirt/tests/src/virtual_network/iface_update.py`:
- Around line 273-279: The libvirtd restart is currently unconditionally run for
live updates; change the guard in the block that checks not cold_update,
vm.is_alive() and not libvirtd_restarted to also require a new explicit flag
(e.g., create_vm_libvirt) so the restart only happens when the virt-install flow
requested it; update the function or test harness to accept/pass
create_vm_libvirt, and wrap the restart logic around that flag (references:
variables cold_update, vm.is_alive(), libvirtd_restarted and calls
utils_libvirtd.Libvirtd() / libvirtd.restart()) so other live-update cases won’t
trigger a restart unless create_vm_libvirt is true.
ℹ️ Review info
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
libvirt/tests/cfg/virtual_network/iface_update.cfglibvirt/tests/src/virtual_network/iface_update.py
🚧 Files skipped from review as they are similar to previous changes (1)
- libvirt/tests/cfg/virtual_network/iface_update.cfg
1.Add some parameters to allow the framework provide guest xml
2.Restart libvirt service as a woraround for using virt-install bootup guest and create an new serial session for guest
3.Add "only Linux" to limit guest type
ID: LIBVIRTAT-22324
Signed-off-by: Lei Yang leiyang@redhat.com
Summary by CodeRabbit
Bug Fixes
Tests