mirror of
https://github.com/retspen/webvirtcloud
synced 2026-12-02 17:06:09 +00:00
feat(storages): the pool page tells which VMs use each volume
A volume left behind (a disk kept when its VM was deleted, an old image) was not told apart from one a VM needs until its deletion was refused. The pool page now has a "Used by" column: the VMs of this host whose disks, UEFI variables, saved state or snapshots are the volume or are built on it, "In use" for one only another volume is built on, else "Not used on this host"; buttons list each kind, and a VM's name finds its volumes. Its deletion still asks the other hosts, as one sharing the storage may use it. When the host's VMs cannot be read the page lists the volumes without the column. The scan that refuses deleting a used volume now also counts a VM's UEFI variables file and a snapshot's block device, and reads each VM once.
This commit is contained in:
parent
dc5b1dbb2a
commit
aeef837afa
12 changed files with 248 additions and 88 deletions
|
|
@ -264,7 +264,8 @@ class StoragesInfoTestCase(unittest.TestCase):
|
|||
|
||||
|
||||
def volume(name, capacity, allocation, fmt=None, error=None):
|
||||
target = f"<target><format type='{fmt}'/></target>" if fmt else "<target/>"
|
||||
fmt_xml = f"<format type='{fmt}'/>" if fmt else ""
|
||||
target = f"<target><path>/p/{name}</path>{fmt_xml}</target>"
|
||||
xml = (f"<volume type='file'><name>{name}</name><capacity unit='bytes'>{capacity}</capacity>"
|
||||
f"<allocation unit='bytes'>{allocation}</allocation>{target}</volume>")
|
||||
return MagicMock(**{"XMLDesc.side_effect": error} if error else {"XMLDesc.return_value": xml})
|
||||
|
|
@ -288,8 +289,8 @@ class VolumesTestCase(unittest.TestCase):
|
|||
vols = [volume("b.qcow2", 2048, 512, "qcow2"), volume("a-lv", 1024, 1024)]
|
||||
stg = self.storage(vols)
|
||||
self.assertEqual(stg.update_volumes(), [
|
||||
{"name": "a-lv", "size": 1024, "allocation": 1024, "type": None}, # a logical volume has no format
|
||||
{"name": "b.qcow2", "size": 2048, "allocation": 512, "type": "qcow2"},
|
||||
{"name": "a-lv", "size": 1024, "allocation": 1024, "type": None, "path": "/p/a-lv"}, # a logical volume has no format
|
||||
{"name": "b.qcow2", "size": 2048, "allocation": 512, "type": "qcow2", "path": "/p/b.qcow2"},
|
||||
])
|
||||
self.assertEqual([c[0] for c in stg.pool.mock_calls], ["refresh", "listAllVolumes"])
|
||||
for vol in vols:
|
||||
|
|
@ -312,7 +313,8 @@ class VolumesTestCase(unittest.TestCase):
|
|||
def test_one_volume(self):
|
||||
stg = self.storage([])
|
||||
stg.pool.storageVolLookupByName.return_value = volume("a.img", 4096, 0, "raw")
|
||||
self.assertEqual(stg.get_volume_details("a.img"), {"name": "a.img", "size": 4096, "allocation": 0, "type": "raw"})
|
||||
self.assertEqual(stg.get_volume_details("a.img"), {"name": "a.img", "size": 4096, "allocation": 0, "type": "raw",
|
||||
"path": "/p/a.img"})
|
||||
|
||||
def test_the_pool_size_is_one_info_call(self):
|
||||
stg = self.storage([])
|
||||
|
|
|
|||
|
|
@ -12,9 +12,10 @@ from vrtManager import util
|
|||
from vrtManager.storage import wvmStorage
|
||||
|
||||
|
||||
def domain(uuid, disks=(), snapshots=()):
|
||||
def domain(uuid, disks=(), snapshots=(), name=None):
|
||||
dom = MagicMock()
|
||||
dom.UUIDString.return_value = uuid
|
||||
dom.name.return_value = name or uuid
|
||||
dom.hasManagedSaveImage.return_value = 0
|
||||
devices = "".join(f"<disk type='file' device='disk'><source file='{d}'/></disk>" for d in disks)
|
||||
dom.XMLDesc.return_value = f"<domain><devices>{devices}</devices></domain>"
|
||||
|
|
@ -172,6 +173,40 @@ class PathsInUseTestCase(unittest.TestCase):
|
|||
conn.paths_in_use()
|
||||
|
||||
|
||||
class VolumeUsersTestCase(unittest.TestCase):
|
||||
def test_the_vms_that_use_each_path(self):
|
||||
conn, _ = storage(
|
||||
domains=[domain("u1", ["/pool/vm.now", "/pool/shared.iso"], [SNAPSHOT], name="vm1"),
|
||||
domain("u2", ["/pool/shared.iso"], name="vm2")],
|
||||
volumes=[volume("/pool/clone.qcow2", backing="/pool/template.qcow2"), volume("/pool/spare.qcow2")],
|
||||
)
|
||||
# a snapshot's files are its VM's; another volume's backing file is no VM's
|
||||
self.assertEqual(conn.volume_users(), {
|
||||
"/pool/vm.now": ["vm1"], "/pool/shared.iso": ["vm1", "vm2"],
|
||||
"/pool/vm.s": ["vm1"], "/pool/vm.s.mem": ["vm1"], "/pool/vm.qcow2": ["vm1"], "/pool/template.qcow2": [],
|
||||
})
|
||||
|
||||
def test_uefi_variables_and_a_snapshots_block_device_are_in_use(self):
|
||||
dom = domain("u1", ["/pool/vm.qcow2"], ["<domainsnapshot><disks><disk name='vda' snapshot='external'>"
|
||||
"<source dev='/dev/vg/vm-snap'/></disk></disks></domainsnapshot>"])
|
||||
dom.XMLDesc.return_value = ("<domain><os><nvram>/pool/vm_VARS.fd</nvram></os><devices><disk type='file' "
|
||||
"device='disk'><source file='/pool/vm.qcow2'/></disk></devices></domain>")
|
||||
conn, _ = storage(domains=[dom])
|
||||
self.assertEqual(conn.paths_in_use(), {"/pool/vm.qcow2", "/pool/vm_VARS.fd", "/dev/vg/vm-snap"})
|
||||
dom.XMLDesc.return_value = "<domain><os><nvram type='block'><source dev='/dev/vg/vars'/></nvram></os></domain>"
|
||||
dom.listAllSnapshots.return_value = []
|
||||
self.assertEqual(conn.paths_in_use(), {"/dev/vg/vars"})
|
||||
|
||||
def test_a_shut_off_vms_base_images_are_its(self):
|
||||
# its definition names the top volume only; the volumes tell what each is built on
|
||||
conn, _ = storage(domains=[domain("u1", ["/pool/top.qcow2"], name="vm1")],
|
||||
volumes=[volume("/pool/top.qcow2", backing="/pool/mid.qcow2"),
|
||||
volume("/pool/mid.qcow2", backing="/pool/base.qcow2"),
|
||||
volume("/pool/other.qcow2", backing="/pool/base.qcow2")])
|
||||
self.assertEqual(conn.volume_users(), {"/pool/top.qcow2": ["vm1"], "/pool/mid.qcow2": ["vm1"],
|
||||
"/pool/base.qcow2": ["vm1"]})
|
||||
|
||||
|
||||
class DeleteVolumeTestCase(unittest.TestCase):
|
||||
def test_a_volume_in_use_is_refused(self):
|
||||
for case, domains, volumes in (
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue