disk capacity is less than disk usage

If the virtual machine mounts cd-rom, libvirt will align by 4K bytes,
causing the disk capacity is less than the disk usage, which does not
seem reasonable.

Maybe we shoulde use the bigger one as disk capacity.

Change-Id: I25808856bce27483da0cb2583ae94e8dc162d647
Closes-Bug: #1819107
This commit is contained in:
zhang-shaoman 2019-03-08 14:48:40 +08:00
parent 062e02c612
commit 194c882864
2 changed files with 6 additions and 2 deletions

View File

@ -154,8 +154,12 @@ class LibvirtInspector(virt_inspector.Inspector):
domain = self._get_domain_not_shut_off_or_raise(instance)
for device in self._get_disk_devices(domain):
block_info = domain.blockInfo(device)
# if vm mount cdrom, libvirt will align by 4K bytes, capacity may
# be smaller than physical, avoid with this.
# https://libvirt.org/html/libvirt-libvirt-domain.html
disk_capacity = max(block_info[0], block_info[2])
yield virt_inspector.DiskInfo(device=device,
capacity=block_info[0],
capacity=disk_capacity,
allocation=block_info[1],
physical=block_info[2])

View File

@ -351,7 +351,7 @@ class TestLibvirtInspection(base.BaseTestCase):
self.assertEqual(1, len(disks))
self.assertEqual('vda', disks[0].device)
self.assertEqual(1, disks[0].capacity)
self.assertEqual(3, disks[0].capacity)
self.assertEqual(2, disks[0].allocation)
self.assertEqual(3, disks[0].physical)