1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-12-03 17:36:05 +00:00

fix(instances): a VM's destruction checks its files on every host first

Destroying a VM with its disk files forced it off first and then
worked out which files to delete, so a check that failed left the VM
stopped, and only this host's VMs and volumes were checked: a file on
shared storage that a VM on another host uses was deleted.

The files are now worked out before the VM is stopped: the disks it
runs with and those of its next start, as before with their snapshot
files and seed. A file a VM or volume of another of the panel's hosts
uses at the same path (shared storage is mounted at one path on every
host, as migration needs) is kept like one used here; another record
of the VM's own host is skipped, as there the VM itself uses them. A
host that cannot be read stops the destruction with its name, before
anything is stopped or deleted.
This commit is contained in:
catborise 2026-10-31 01:08:42 +03:00
parent 79b257ab80
commit e2b9598074
8 changed files with 125 additions and 12 deletions

View file

@ -88,7 +88,7 @@ class DeleteWithDisksTestCase(unittest.TestCase):
vm.wvm = MagicMock()
vm.refresh_instance_pools = MagicMock()
vm.get_uuid = lambda: UUID
vm.get_disk_devices = lambda: [{"path": "/pool/web-1.qcow2"}]
vm.get_disk_devices = lambda config=False: [{"path": "/pool/web-1.qcow2"}]
vm._snapshot_chain_files = lambda own: []
vm.paths_used_by_other_domains = lambda own: set()
vm.backing_path = lambda path: None
@ -112,6 +112,13 @@ class DeleteWithDisksTestCase(unittest.TestCase):
vm, _ = self.vm(seed_in_pool=False)
self.assertEqual(vm.split_disk_paths_by_use(), (["/pool/web-1.qcow2"], []))
def test_its_next_start_disks_and_the_files_other_hosts_use(self):
vm, _ = self.vm(seed_in_pool=False)
vm.get_disk_devices = lambda config=False: [{"path": "/pool/web-1.qcow2"}] + (
[{"path": "/nfs/pending.qcow2"}] if config else [])
self.assertEqual(vm.split_disk_paths_by_use(lambda own: {"/nfs/pending.qcow2"} & set(own)),
(["/pool/web-1.qcow2"], ["/nfs/pending.qcow2"]))
class CloneTestCase(unittest.TestCase):
def test_a_clone_does_not_take_the_vms_seed(self):

View file

@ -766,7 +766,7 @@ class DestroyFilesTestCase(unittest.TestCase):
"<devices/>", f"<devices><disk type='file' device='disk'><source file='{point}'/><target dev='vda'/></disk></devices>"
)
p = proxy(external=[snap for snap, _ in snaps], xml=self.TOP)
p.get_disk_devices = lambda: [{"path": top}]
p.get_disk_devices = lambda config=False: [{"path": top}]
backing = {
"/pool/a.two": "/pool/a.one", "/pool/a.one": "/pool/a.qcow2", "/pool/a.qcow2": "/templates/base.qcow2",
}