mirror of
https://github.com/retspen/webvirtcloud
synced 2026-12-01 16:36:06 +00:00
fix(instances): a VM's saved state keeps the disks it starts with
A VM with a saved state (managed save, as libvirt-guests leaves VMs when
its host shuts down) shows as shut off, and its start restores the
definition it was saved with. The panel let the VM's Delete remove a disk
of it, and the storage pool delete a volume detached since: the VM then
did not start ("Cannot access storage file"), and the panel has no way to
drop the saved state.
A VM's Delete now refuses a disk while the VM has a saved state, and a
volume in a domain's saved state is in use for every delete check.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kk4h2TcUiaWmU5MUszYSea
This commit is contained in:
parent
a4bfe77949
commit
a53a3623d2
7 changed files with 59 additions and 2 deletions
|
|
@ -15,6 +15,7 @@ from vrtManager.storage import wvmStorage
|
|||
def domain(uuid, disks=(), snapshots=()):
|
||||
dom = MagicMock()
|
||||
dom.UUIDString.return_value = uuid
|
||||
dom.hasManagedSaveImage.return_value = 0
|
||||
devices = "".join(f"<disk type='file' device='disk'><source file='{d}'/></disk>" for d in disks)
|
||||
dom.XMLDesc.return_value = f"<domain><devices>{devices}</devices></domain>"
|
||||
snaps = []
|
||||
|
|
@ -66,6 +67,30 @@ class PathsInUseTestCase(unittest.TestCase):
|
|||
{"/pool/vm.now", "/pool/vm.s", "/pool/vm.s.mem", "/pool/vm.qcow2", "/pool/template.qcow2"},
|
||||
)
|
||||
|
||||
def test_a_disk_detached_since_the_vm_was_saved_is_in_use(self):
|
||||
dom = domain("u1", ["/pool/vm.qcow2"])
|
||||
dom.hasManagedSaveImage.return_value = 1
|
||||
dom.managedSaveGetXMLDesc.return_value = (
|
||||
"<domain><devices><disk type='file' device='disk'><source file='/pool/vm.qcow2'/></disk>"
|
||||
"<disk type='file' device='disk'><source file='/pool/data.qcow2'/></disk></devices></domain>")
|
||||
conn, _ = storage(domains=[dom])
|
||||
self.assertEqual(conn.paths_in_use(), {"/pool/vm.qcow2", "/pool/data.qcow2"})
|
||||
|
||||
def test_a_saved_state_gone_meanwhile_counts_the_disks_the_vm_started_with(self):
|
||||
dom = domain("u1", ["/pool/vm.qcow2"])
|
||||
dom.hasManagedSaveImage.return_value = 1
|
||||
error = libvirtError("no saved state")
|
||||
error.get_error_code = lambda: libvirt.VIR_ERR_OPERATION_INVALID
|
||||
dom.managedSaveGetXMLDesc.side_effect = error
|
||||
conn, _ = storage(domains=[dom])
|
||||
self.assertEqual(conn.paths_in_use(), {"/pool/vm.qcow2"})
|
||||
self.assertEqual(dom.XMLDesc.call_args_list[-1].args, (0,))
|
||||
# a VM removed meanwhile uses nothing
|
||||
error.get_error_code = lambda: libvirt.VIR_ERR_NO_DOMAIN
|
||||
dom.XMLDesc.reset_mock()
|
||||
self.assertEqual(conn.paths_in_use(), {"/pool/vm.qcow2"})
|
||||
self.assertEqual(dom.XMLDesc.call_count, 2)
|
||||
|
||||
def test_one_domain_and_the_backing_files_of_own_volumes_can_be_left_out(self):
|
||||
conn, _ = storage(
|
||||
domains=[domain("u1", ["/pool/a.qcow2"]), domain("u2", ["/pool/b.qcow2"])],
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue