Skip to content

Replace virsh.managedsave() with vm.managedsave() for console handling#6830

Merged
cliping merged 1 commit intoautotest:masterfrom
liang-cong-red-hat:lifecycle_replace_with_vm_managedsave
Mar 30, 2026
Merged

Replace virsh.managedsave() with vm.managedsave() for console handling#6830
cliping merged 1 commit intoautotest:masterfrom
liang-cong-red-hat:lifecycle_replace_with_vm_managedsave

Conversation

@liang-cong-red-hat
Copy link
Copy Markdown
Contributor

@liang-cong-red-hat liang-cong-red-hat commented Mar 17, 2026

This change replaces direct virsh.managedsave() calls with the VM instance method
vm.managedsave() in memory related lifecycle tests. The new approach inherently
manages the guest's serial console connection during state saving, eliminating potential connection timeouts when reattaching to the console during guest reboot.

Test results:
(1/2) type_specific.io-github-autotest-libvirt.memory.devices.virtio_mem.lifecycle.all_requested_and_address.nodemask_pagesize.4k: STARTED
(1/2) type_specific.io-github-autotest-libvirt.memory.devices.virtio_mem.lifecycle.all_requested_and_address.nodemask_pagesize.4k: PASS (206.91 s)
(2/2) type_specific.io-github-autotest-libvirt.memory.devices.virtio_mem.lifecycle.part_requested_and_no_address.nodemask_pagesize.4k: STARTED
(2/2) type_specific.io-github-autotest-libvirt.memory.devices.virtio_mem.lifecycle.part_requested_and_no_address.nodemask_pagesize.4k: PASS (210.23 s)
(1/2) type_specific.io-github-autotest-libvirt.memory.devices.dimm.lifecycle.no_address.nodemask_pagesize.4k: STARTED
(1/2) type_specific.io-github-autotest-libvirt.memory.devices.dimm.lifecycle.no_address.nodemask_pagesize.4k: PASS (163.69 s)
(2/2) type_specific.io-github-autotest-libvirt.memory.devices.dimm.lifecycle.slot_base.nodemask_pagesize.4k: STARTED
(2/2) type_specific.io-github-autotest-libvirt.memory.devices.dimm.lifecycle.slot_base.nodemask_pagesize.4k: PASS (180.50 s)

Summary by CodeRabbit

  • Refactor
    • Tests updated to use direct VM object methods instead of CLI-based operations.
    • Improves test execution efficiency and reduces reliance on external command-line tooling.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 17, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: ff286931-62dd-494a-b3ba-ad04f3338594

📥 Commits

Reviewing files that changed from the base of the PR and between 15c6b9c and 75d191c.

📒 Files selected for processing (2)
  • libvirt/tests/src/memory/memory_devices/dimm_memory_lifecycle.py
  • libvirt/tests/src/memory/memory_devices/virtio_mem_device_lifecycle.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • libvirt/tests/src/memory/memory_devices/dimm_memory_lifecycle.py

Walkthrough

Two test files in the memory devices lifecycle suite were modified to replace direct virsh CLI invocations with VM object method calls: virsh.managedsave(vm_name, **virsh_dargs) was replaced by vm.managedsave() in dimm_memory_lifecycle.py and virtio_mem_device_lifecycle.py. No other test logic, VM startup, or XML verification steps were changed.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: replacing virsh.managedsave() calls with vm.managedsave() across memory device lifecycle tests, which is reflected in both modified files.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
📝 Coding Plan
  • Generate coding plan for human review comments

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

Tip

Flake8 can be used to improve the quality of Python code reviews.

Flake8 is a Python linter that wraps PyFlakes, pycodestyle and Ned Batchelder's McCabe script.

To configure Flake8, add a '.flake8' or 'setup.cfg' file to your project root.

See Flake8 Documentation for more details.

This change replaces direct virsh.managedsave() calls with the VM instance method
 vm.managedsave() in memory related lifecycle tests. The new approach inherently
manages the guest's serial console connection during state saving, eliminating
potential connection timeouts when reattaching to the console during guest reboot.

Signed-off-by: Liang Cong <lcong@redhat.com>
@liang-cong-red-hat liang-cong-red-hat force-pushed the lifecycle_replace_with_vm_managedsave branch from 15c6b9c to 75d191c Compare March 17, 2026 07:56
check_dimm_mem_device_xml(
{init_alias_name: init_xpath_list, plug_alias_name: plug_xpath_list})

virsh.managedsave(vm_name, **virsh_dargs)
Copy link
Copy Markdown
Contributor

@iccaszhulili iccaszhulili Mar 25, 2026

Choose a reason for hiding this comment

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

Hi, I checked the managedsave function in libvirt_vm.py.

def managedsave(self):
"""
Managed save of VM's state
"""
if self.is_dead():
raise virt_vm.VMStatusError("Cannot save a VM that is %s" % self.state())
LOG.debug("Managed saving VM %s" % self.name)
result = virsh.managedsave(self.name, uri=self.connect_uri)
if result.exit_status:
raise virt_vm.VMError(
"Managed save VM failed.\n" "Detail: %s." % result.stderr_text
)
if self.is_alive():
raise virt_vm.VMStatusError("VM not shut off after managed save")
self.cleanup_serial_console()

There is no option for debug. For the virsh object. its debug option is default to false
`class VirshBase(propcan.PropCanBase):
"""
Base Class storing libvirt Connection & state to a host
"""

__slots__ = ("uri", "ignore_status", "debug", "virsh_exec", "readonly")

def __init__(self, *args, **dargs):
    """
    Initialize instance with virsh_exec always set to something
    """
    init_dict = dict(*args, **dargs)
    init_dict["virsh_exec"] = init_dict.get("virsh_exec", VIRSH_EXEC)
    init_dict["uri"] = init_dict.get("uri", None)
    init_dict["debug"] = init_dict.get("debug", False)
    init_dict["ignore_status"] = init_dict.get("ignore_status", False)
    init_dict["readonly"] = init_dict.get("readonly", False)
    super(VirshBase, self).__init__(init_dict)

`

In the original code, virsh_dargs = {"debug": True, "ignore_status": False}. How can we replace virsh.managedsave to vm.managedsave while enabling debug?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

for vm.managedsave(), we don't need any parameter.

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.

Yes. There is no way to enable debug. Do we need to add a parameter to vm.managedsave in avocado-vt?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Not very necessary, vm.managedsave() handles error scenarios, I think that's enough.

@cliping cliping merged commit f2d0adb into autotest:master Mar 30, 2026
6 checks passed
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.

3 participants