1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-11-10 04:06:47 +00:00

fix(quota): a disk whose size is unknown is not counted as 0 GiB

A disk of the user's VMs whose size could not be read (its volume not in a
pool, the pool stopped) counted as 0 GiB, so a disk-limited user's increase
could pass over the limit. A disk no pool holds now has the size libvirt
reads from the file or device (blockInfo, also for a shut-off VM); one whose
size is still unknown makes the usage unverified and the increase is
refused, as when a host cannot be reached. Users without a disk limit are
not affected.
This commit is contained in:
catborise 2026-11-07 16:00:35 +03:00
parent d8a184eff7
commit 0b4a601ecb
9 changed files with 215 additions and 184 deletions

View file

@ -48,6 +48,15 @@ class DeviceGettersTestCase(unittest.TestCase):
self.assertEqual([(n["inbound"], n["outbound"]) for n in nics[1:]], [([], [])] * 2)
self.assertEqual([(n["nic"], n["model"]) for n in nics], [("default", "virtio"), ("br0", ""), ("", "")])
def test_a_disk_no_pool_holds_has_the_size_libvirt_reads(self):
p = proxy()
p.instance = MagicMock()
# vda: libvirt reads it, by its path; vdb: it cannot
p.instance.blockInfo.side_effect = lambda path: [20 << 30, 5 << 30, 20 << 30] if path == "/pool/a.qcow2" else \
(_ for _ in ()).throw(libvirtError("cannot read"))
self.assertEqual([(d["dev"], d["size"], d["used"]) for d in p.get_disk_devices()],
[("vda", 20 << 30, 5 << 30), ("vdb", None, None)])
def test_an_empty_cdrom_shows_no_pool(self):
media = proxy().get_media_devices()
self.assertEqual(