1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-12-01 08:26:03 +00:00

fix(vrtManager): a disk in an inactive pool keeps the files it may be made from

Only a running disk's definition has its backing chain; for the others the
in-use check reads it from the volumes of active pools. With such a disk's
overlay in an inactive pool (a stopped VM's, the next start's, a saved
state's or a snapshot's), its backing file counted as unused, so deleting
another VM with its disks, or the volume itself, could delete it. The check
now refuses (InUse) while a disk that is not running and not raw has its
file in an inactive pool, and says to start the pool. A snapshot delete
that is done reports no left-behind files then, rather than failing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kk4h2TcUiaWmU5MUszYSea
This commit is contained in:
catborise 2026-11-11 14:32:46 +03:00
parent effe2a33f0
commit b91daf0525
8 changed files with 413 additions and 338 deletions

View file

@ -612,6 +612,13 @@ class LeftBehindTestCase(unittest.TestCase):
# their own backing files do not keep each other
in_use.assert_called_once_with(own=["/pool/a.one", "/pool/vm.one.mem"])
def test_nothing_is_reported_when_another_vm_s_files_cannot_be_read(self):
# a disk in an inactive pool: any file may be one it grows from; the delete itself is done
refused = util.InUse("Pool %(pool)s is not active", pool="overlays")
with patch.object(wvmInstance, "paths_in_use", side_effect=refused):
left = self.run_delete({"/pool/a.one", "/pool/vm.one.mem", "/pool/a.two", "/pool/a.qcow2"})
self.assertEqual(left, [])
def test_a_file_below_one_another_vm_uses_is_not_reported(self):
# the other VM is shut off: its definition does not list the backing
# file, and the in-use top's own backing reference does not count

View file

@ -126,6 +126,39 @@ class PathsInUseTestCase(unittest.TestCase):
conn.wvm.storagePoolLookupByName.return_value = conn.pool
self.assertIn("/pool/disk.qcow2", conn.paths_in_use())
def test_a_disk_not_running_in_an_inactive_pool_is_refused(self):
# its overlay's backing file is in the volume's XML, which an inactive pool does not give
inactive = MagicMock(**{"isActive.return_value": False, "name.return_value": "overlays",
"XMLDesc.return_value": "<pool><target><path>/overlays</path></target></pool>"})
overlay = "<disk type='file' device='disk'><source file='/overlays/b.qcow2'/></disk>"
raw = "<disk type='file' device='disk'><driver type='raw'/><source file='/overlays/b.qcow2'/></disk>"
other = "<disk type='file' device='disk'><source file='/overlays-2/b.qcow2'/></disk>"
def check(live, config, active, refused, saved=None):
dom = domain("u1")
dom.XMLDesc.side_effect = lambda flags: f"<domain><devices>{config if flags else live}</devices></domain>"
dom.isActive.return_value = active
if saved:
dom.hasManagedSaveImage.return_value = 1
dom.managedSaveGetXMLDesc.return_value = f"<domain><devices>{saved}</devices></domain>"
conn, _ = storage(domains=[dom])
conn.wvm.listAllStoragePools.return_value = [conn.pool, inactive]
if refused:
with self.assertRaisesRegex(util.InUse, "Pool overlays is not active"):
conn.paths_in_use()
else:
conn.paths_in_use() # answers
for case, args in (("stopped", (overlay, overlay, False, True)),
("running: the live definition has the chain", (overlay, overlay, True, False)),
("the next start's disk", ("", overlay, True, True)),
("a raw disk grows from nothing", (raw, raw, False, False)),
("another directory", (other, other, False, False))):
with self.subTest(case):
check(*args)
with self.subTest("a saved state's disk"):
check("", "", False, True, saved=overlay)
def test_a_volume_that_cannot_be_read_is_not_taken_as_unused(self):
removed, unreadable = volume("/pool/gone.qcow2"), volume("/pool/top.qcow2")
error = libvirtError("removed")