mirror of
https://github.com/retspen/webvirtcloud
synced 2026-12-02 17:06:09 +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:
parent
aeef837afa
commit
981ff7b294
11 changed files with 227 additions and 135 deletions
|
|
@ -35,6 +35,12 @@
|
|||
{% trans "Left" %} <span class="fw-semibold">{{ tombstone.host }}</span>
|
||||
<span class="text-body-secondary">· {% trans "Owners" %}:</span> {{ tombstone.owner_names|join:", "|default:"–" }}
|
||||
</div>
|
||||
{% if tombstone.policy_names or tombstone.backup_count %}
|
||||
<div class="mt-1">
|
||||
{% if tombstone.policy_names %}<span class="text-body-secondary">{% trans "Schedules" %}:</span> {{ tombstone.policy_names|join:", " }}{% endif %}
|
||||
{% if tombstone.backup_count %}{% if tombstone.policy_names %} · {% endif %}{% blocktrans count counter=tombstone.backup_count %}{{ counter }} backup{% plural %}{{ counter }} backups{% endblocktrans %}{% endif %}
|
||||
</div>
|
||||
{% endif %}
|
||||
<div class="text-body-secondary mt-1">
|
||||
{% trans "Removed" %} <span class="text-nowrap">{{ tombstone.removed|date:"Y-m-d H:i" }}</span>
|
||||
· {% trans "expires" %} <span class="text-nowrap">{{ tombstone.expires|date:"Y-m-d H:i" }}</span>
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
"""Superusers list the ownership kept for VMs that vanished and can remove it."""
|
||||
|
||||
from datetime import timedelta
|
||||
from datetime import time, timedelta
|
||||
|
||||
from django.contrib.auth.models import User
|
||||
from django.test import TestCase, override_settings
|
||||
|
|
@ -9,6 +9,9 @@ from django.utils import timezone
|
|||
|
||||
from instances.models import InstanceTombstone
|
||||
from logs.models import Logs
|
||||
from lxml import html
|
||||
from computes.models import Tag
|
||||
from vmbackups.models import Backup, BackupPolicy, BackupTarget
|
||||
|
||||
UUID = "00000000-0000-4000-8000-000000000001"
|
||||
|
||||
|
|
@ -50,6 +53,22 @@ class TombstoneTests(TestCase):
|
|||
self.assertEqual(self.client.post(url).status_code, 403)
|
||||
self.assertTrue(InstanceTombstone.objects.exists())
|
||||
|
||||
def test_the_list_names_its_schedules_and_counts_its_backups(self):
|
||||
# a VM kept for its backups or schedules alone has no owner to show; only what would come back is told
|
||||
target = BackupTarget.objects.create(name="t")
|
||||
chosen, by_tag = (BackupPolicy.objects.create(name=name, target=target, time=time(2), keep=1)
|
||||
for name in ("nightly", "by-tag"))
|
||||
BackupPolicy.objects.filter(pk=by_tag.pk).update(tag=Tag.objects.create(name="web"))
|
||||
kept = [Backup.objects.create(target=target, vm_uuid=UUID, vm_name="ts-vm", compute_name="ts-host").pk
|
||||
for _ in range(2)]
|
||||
InstanceTombstone.objects.filter(pk=self.tombstone.pk).update(
|
||||
owners=[], tags=[], policies=[chosen.pk, by_tag.pk, 999999], backups=[*kept, 999999])
|
||||
page = html.fromstring(self.client.get(reverse("admin:tombstone_list")).content)
|
||||
(row,) = page.xpath("//div[@data-search][contains(@data-search, 'ts-vm')]")
|
||||
text = " ".join(row.text_content().split())
|
||||
self.assertIn("Schedules: nightly · 2 backups", text)
|
||||
self.assertNotIn("by-tag", text)
|
||||
|
||||
def test_a_get_only_asks_for_confirmation(self):
|
||||
response = self.client.get(reverse("admin:tombstone_delete", args=[self.tombstone.pk]))
|
||||
self.assertContains(response, "ts-vm")
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ from logs.models import Logs
|
|||
from operations import claims
|
||||
from operations.utils import busy_message
|
||||
from vrtManager import util
|
||||
from vmbackups.models import Backup, BackupPolicy
|
||||
|
||||
from . import forms
|
||||
from .decorators import superuser_only
|
||||
|
|
@ -442,8 +443,15 @@ def tombstone_list(request):
|
|||
ids = {owner["user"] for tombstone in tombstones for owner in tombstone.owners}
|
||||
names = dict(User.objects.filter(id__in=ids).values_list("id", "username"))
|
||||
retention = timedelta(days=getattr(settings, "INSTANCE_OWNERSHIP_RETENTION_DAYS", 30))
|
||||
# what would come back (computes.utils._restore): schedules that choose their VMs one by one, backups unlinked
|
||||
policies = dict(BackupPolicy.objects.filter(pk__in={pk for t in tombstones for pk in t.policies}, compute=None,
|
||||
tag=None).values_list("pk", "name"))
|
||||
backups = set(Backup.objects.filter(pk__in={pk for t in tombstones for pk in t.backups}, instance=None)
|
||||
.values_list("pk", flat=True))
|
||||
for tombstone in tombstones:
|
||||
tombstone.owner_names = [names.get(owner["user"], _("deleted user")) for owner in tombstone.owners]
|
||||
tombstone.policy_names = sorted(policies[pk] for pk in tombstone.policies if pk in policies)
|
||||
tombstone.backup_count = len(backups.intersection(tombstone.backups))
|
||||
tombstone.expires = tombstone.removed + retention
|
||||
return render(request, "admin/tombstone_list.html", {"tombstones": tombstones})
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue