mirror of
https://github.com/retspen/webvirtcloud
synced 2026-12-03 17:36:05 +00:00
fix(storages): a volume another compute's VM uses on shared storage is not deleted
A pool on shared storage (an NFS share, or a directory mounted from one) holds the same file at the same path on every host that mounts it. A VM's delete checks the panel's other computes before it deletes its disk files, but the pool page, its API and a VM's disk delete checked only their own host: a disk of a VM on another compute could be deleted. They now ask the other computes too, and refuse while one uses the file or cannot be reached. The other computes are asked before this host's lock is taken, and before a VM's disk is detached.
This commit is contained in:
parent
fb3b2f479e
commit
143a74b145
11 changed files with 277 additions and 196 deletions
|
|
@ -113,6 +113,31 @@ class VolumeDeleteTests(TestCase):
|
|||
request()
|
||||
self.assertEqual(inside, [[(self.compute.pk, False)]])
|
||||
|
||||
def test_the_other_computes_are_asked_before_the_lock(self):
|
||||
# shared storage: another host's VM may use the file at the same path;
|
||||
# a host that does not answer does not hold this one's lock meanwhile
|
||||
for module, request in (
|
||||
("storages.views", lambda: self.client.post(reverse("storage", args=[self.compute.id, "default"]),
|
||||
{"del_volume": "1", "volname": "disk.qcow2"})),
|
||||
("storages.api.viewsets", lambda: self.client.delete(
|
||||
f"/api/v1/computes/{self.compute.id}/storages/default/volumes/disk.qcow2/")),
|
||||
):
|
||||
with self.subTest(module), patch(f"{module}.wvmStorage") as mock_wvm, \
|
||||
patch(f"{module}.libvirt_compute_lock") as lock, \
|
||||
patch(f"{module}.paths_used_on_other_computes", return_value=set()) as others:
|
||||
conn = mock_wvm.return_value
|
||||
conn.is_active.return_value = True
|
||||
conn.get_size.return_value = (1, 1)
|
||||
|
||||
def check(name, elsewhere, lock=lock):
|
||||
lock.assert_not_called()
|
||||
elsewhere(["/pool/disk.qcow2"])
|
||||
|
||||
conn.check_unused_elsewhere.side_effect = check
|
||||
request()
|
||||
others.assert_called_once_with(self.compute, ["/pool/disk.qcow2"])
|
||||
conn.del_volume.assert_called_once_with("disk.qcow2")
|
||||
|
||||
@patch("storages.views.wvmStorage")
|
||||
def test_a_busy_compute_is_a_message(self, mock_wvm):
|
||||
conn = self.refused(mock_wvm)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue