1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-12-03 17:36:05 +00:00

fix: a backup's files say so on the pool page; Removed VMs names schedules and backups

On a backup target's pool every backup file was "Not used on this host" and
listed with the unused volumes, though its deletion there is refused: it is
deleted with its backup. The column now says "Backup of <VM>" and counts it
as in use. A VM kept on the Removed VMs page for its schedules or backups
alone showed no owner and no reason; its row now names its schedules and
counts its backups.
This commit is contained in:
catborise 2026-11-20 08:50:29 +03:00
parent aeef837afa
commit 981ff7b294
11 changed files with 227 additions and 135 deletions

View file

@ -139,7 +139,7 @@
<tr>
<th scope="col">{% trans "Name" %}</th>
<th scope="col">{% trans "Format" %}</th>
{% if users_read %}<th scope="col" data-sort-method="text">{% trans "Used by" %}</th>{% endif %}
{% if users_read or has_backups %}<th scope="col" data-sort-method="text">{% trans "Used by" %}</th>{% endif %}
<th scope="col" class="d-none d-sm-table-cell" data-sort-method="number">{% trans "Capacity" %}</th>
<th scope="col" data-sort-method="none"><span class="visually-hidden">{% trans "Actions" %}</span></th>
</tr>
@ -149,12 +149,13 @@
<tr data-search="{{ volume.name }}{% for vm in volume.users %} {{ vm }}{% endfor %}">
<td class="text-break">{{ volume.name }}</td>
<td><span class="badge text-bg-light border">{{ volume.type }}</span></td>
{% if users_read %}
{% if users_read or has_backups %}
{# a delete still asks the other hosts: one sharing this storage may use the volume #}
<td class="text-break small">
{% if volume.users %}<span data-state="used">{{ volume.users|join:", " }}</span>
{% if volume.backup %}<span data-state="used">{% blocktrans with vm=volume.backup.vm_name %}Backup of {{ vm }}{% endblocktrans %}</span>
{% elif volume.users %}<span data-state="used">{{ volume.users|join:", " }}</span>
{% elif volume.users is not None %}<span data-state="used" title="{% trans "Another volume is built on it" %}">{% trans "In use" %}</span>
{% else %}<span class="text-body-secondary" data-state="unused">{% trans "Not used on this host" %}</span>{% endif %}
{% elif users_read %}<span class="text-body-secondary" data-state="unused">{% trans "Not used on this host" %}</span>{% endif %}
</td>
{% endif %}
{# capacity: what the guest sees; allocated: what it takes on the storage now #}

View file

@ -13,6 +13,7 @@ from libvirt import libvirtError
from lxml import html
from storages.forms import CreateVolumeForm
from vmbackups.models import Backup, BackupTarget, BackupTargetPool
class PoolPageTests(TestCase):
@ -138,6 +139,27 @@ class PoolPageTests(TestCase):
self.assertEqual(page.xpath("//tbody/tr/@data-search"), ["a.img vm1 vm2", "b.img", "c.img"])
self.assertEqual(page.xpath("//div[@id='state-pills']/button/@data-pill"), ["", "used", "unused"])
def test_a_backups_files_say_whose_backup_they_are(self):
# in a backup target's pool: deleted with their backup, not as unused volumes
target = BackupTarget.objects.create(name="t")
BackupTargetPool.objects.create(target=target, compute=self.compute, pool="default", pool_uuid="u")
backup = Backup.objects.create(target=target, vm_uuid="00000000-0000-4000-8000-000000000001", vm_name="web",
compute_name="pp", state=Backup.READY)
self.conn.get_size.return_value = (10, 4)
self.conn.update_volumes.return_value = [
{"name": name, "path": f"/p/{name}", "size": 1, "allocation": 1, "type": "qcow2"}
for name in (f"{backup.prefix}-vda.qcow2", "left.qcow2")]
page = html.fromstring(self.client.get(reverse("storage", args=[self.compute.pk, "default"])).content)
self.assertEqual([" ".join(t.split()) for t in page.xpath("//tbody/tr/td[3]//text()[normalize-space()]")],
["Backup of web", "Not used on this host"])
self.assertEqual(page.xpath("//tbody/tr//@data-state"), ["used", "unused"])
# the VMs' use not read: the backup is still told, the other volume is not called unused
self.conn.volume_users.side_effect = libvirtError("cannot read the domains")
page = html.fromstring(self.client.get(reverse("storage", args=[self.compute.pk, "default"])).content)
self.assertEqual([" ".join(t.split()) for t in page.xpath("//tbody/tr/td[3]//text()[normalize-space()]")],
["Backup of web"])
self.assertFalse(page.xpath("//div[@id='state-pills']"))
def test_volumes_whose_use_cannot_be_read_are_listed(self):
self.conn.get_size.return_value = (10, 4)
self.conn.update_volumes.return_value = [{"name": "a.img", "path": "/p/a.img", "size": 1, "allocation": 1,

View file

@ -23,7 +23,7 @@ from vrtManager.storage import wvmStorage, wvmStorages
from storages.forms import AddStgPool, CloneImage, CreateVolumeForm
from storages.jobs import is_iso
from storages.upload import write_chunk
from vmbackups.utils import refuse_backup_volume, refuse_target_pool
from vmbackups.utils import backups_of, refuse_backup_volume, refuse_target_pool
from webvirtcloud.gunicorn_worker import request_progressed
@ -237,8 +237,10 @@ def storage(request, compute_id, pool):
# which VMs of this host use each volume; the page lists them without it when it cannot be read
with contextlib.suppress(libvirtError):
users = conn.volume_users()
backups = backups_of(compute, pool, [volume["name"] for volume in volumes or []])
for volume in volumes or []:
volume["iso"] = is_iso(volume["name"])
volume["backup"] = backups.get(volume["name"])
volume["users"] = users.get(volume["path"]) if users is not None else None
try:
size, free = conn.get_size()
@ -258,6 +260,7 @@ def storage(request, compute_id, pool):
"state": state,
"volumes": volumes,
"users_read": users is not None,
"has_backups": bool(backups),
"size": size,
"free": free,
"used": used,