1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-11-11 12:46:49 +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

@ -40,7 +40,8 @@ def vm_reader(vcpu=2, memory=1024, disk_gib=10, pending=None):
return values(config)["memory"]
def get_disk_devices(self, config=False):
return [{"size": values(config)["disk_gib"] << 30}]
size = values(config)["disk_gib"]
return [{"size": None if size is None else size << 30}]
def values(persistent):
return config if persistent else live
@ -98,6 +99,13 @@ class QuotaTests(TestCase):
self.assertEqual(self.check(0, 0, 512, 0, reader=gone)[0], QUOTA_UNVERIFIED)
def test_a_disk_whose_size_is_unknown_refuses_an_increase(self):
# not 0 GiB: a volume not read (its pool stopped) may be the largest
self.own(self.up, 1)
self.assertEqual(self.check(0, 1, 0, 0, reader=vm_reader(disk_gib=None))[0], QUOTA_UNVERIFIED)
UserAttributes.objects.filter(user=self.user).update(max_disk_size=-1) # disks not limited: not needed
self.assertEqual(self.check(0, 1, 0, 0, reader=vm_reader(disk_gib=None))[0], "")
def test_each_host_is_checked_once(self):
for n in range(3):
self.own(self.up, n)