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

fix: a test alert button; damage shown and warned of on restore

Audit of the alerts and backup verification: an operator could learn
that the alert mail or webhook works only from a real failure. Settings
> Alerts gets "Send a test alert", sent at once to the channels saved,
each channel's result shown. A damaged backup's reasons were only in a
tooltip, so not on a touch screen: they show under the badge. A restore
of a backup that a verification found damaged, or of an incremental on
a damaged base (shown as Ready), said nothing: the restore pages warn.
This commit is contained in:
catborise 2026-11-19 17:14:03 +03:00
parent dcd7e32df7
commit 2c8493ba8c
15 changed files with 254 additions and 70 deletions

View file

@ -136,6 +136,14 @@ class Backup(models.Model):
deleted like a failed one."""
return self.state == self.CREATING and self.operation_id is not None and self.operation.state in Operation.ACTIVE
def damaged_in_chain(self):
"""It, or the first backup it builds on, that a verification found damaged; None."""
backup, seen = self, set()
while backup is not None and not backup.damage and backup.pk not in seen: # a broken chain may loop
seen.add(backup.pk)
backup = backup.parent
return backup if backup is not None and backup.damage else None
def depended_on(self):
"""Whether a backup builds on this one: a failed one holds nothing."""
return self.children.filter(state__in=self.LIVING).exists()

View file

@ -0,0 +1,7 @@
{% load i18n %}{% load operations %}{% load bootstrap_icons %}{# a restore page: the backup or one it builds on found damaged #}
{% with damaged=backup.damaged_in_chain %}{% if damaged %}
<div class="alert alert-danger" role="alert">{% bs_icon 'exclamation-triangle' %}
{% if damaged == backup %}{% trans "A verification found this backup damaged:" %}{% else %}{% blocktrans with time=damaged.created_at|date:"Y-m-d H:i" %}It builds on the backup taken {{ time }}, which a verification found damaged:{% endblocktrans %}{% endif %}
{{ damaged.damage|words }} {% trans "The restored disks may be damaged too." %}
</div>
{% endif %}{% endwith %}

View file

@ -10,6 +10,7 @@
{% block content %}
<p>{% blocktrans with vm=backup.vm_name time=backup.created_at|date:"Y-m-d H:i" target=backup.target.name %}The backup of {{ vm }} taken {{ time }}, in {{ target }}, is restored as a new VM with its own UUID and MAC addresses.{% endblocktrans %}</p>
{% include "vmbackups/damage_warning.html" %}
<div class="card" style="max-width: 40rem;">
<div class="card-body">
<form method="post">

View file

@ -10,6 +10,7 @@
{% block content %}
<p>{% blocktrans with vm=backup.vm_name time=backup.created_at|date:"Y-m-d H:i" target=backup.target.name %}A disk of the backup of {{ vm }} taken {{ time }}, in {{ target }}, is copied as a new volume, attached to no VM.{% endblocktrans %}</p>
{% include "vmbackups/damage_warning.html" %}
<div class="card" style="max-width: 40rem;">
<div class="card-body">
<form method="post">

View file

@ -9,6 +9,7 @@
{% block content %}
<p>{% blocktrans with vm=backup.vm_name time=backup.created_at|date:"Y-m-d H:i" target=backup.target.name %}The backup of {{ vm }} taken {{ time }}, in {{ target }}, is restored over the VM: its disks are copied as new volumes and the VM is switched to them. Its settings, MAC addresses and UUID stay.{% endblocktrans %}</p>
{% include "vmbackups/damage_warning.html" %}
{% if problem %}
<div class="alert alert-warning" role="status">{% bs_icon 'exclamation-triangle' %} {{ problem }}</div>
{% else %}

View file

@ -1 +1 @@
{% load i18n %}{% load operations %}{% if backup.uuid|stringformat:"s" in pending_deletes %}<span class="badge text-bg-warning" data-backup-pending>{% trans "Deleting" %}</span>{% elif backup.state == "deleting" %}<span class="badge text-bg-warning" title="{% trans "Its deletion did not end; delete it again" %}">{% trans "Deleting" %}</span>{% elif backup.state == "ready" and backup.damage %}<span class="badge text-bg-danger" title="{{ backup.damage|words }}">{% trans "Damaged" %}</span>{% elif backup.state == "ready" %}<span class="badge text-bg-success"{% if backup.verified_at %} title="{% blocktrans with time=backup.verified_at|date:"Y-m-d H:i" %}Verified {{ time }}{% endblocktrans %}"{% endif %}>{% trans "Ready" %}</span>{% if backup.verified_at %} <span class="small text-body-secondary">{% trans "verified" %}</span>{% endif %}{% elif backup.being_made %}<span class="badge text-bg-info" data-backup-pending>{% trans "Creating" %}</span>{% if backup.operation_id %}{% if user.is_superuser or backup.operation.user_id == user.id %} <a class="small" href="{% url 'operations:job' backup.operation_id %}">{% trans "Progress" %}</a>{% endif %}{% endif %}{% elif backup.state == "missing" %}<span class="badge text-bg-danger" title="{% trans "Files of the backup are missing from the target" %}">{% trans "Missing" %}</span>{% else %}<span class="badge text-bg-danger">{% trans "Failed" %}</span>{% if backup.operation_id %}{% if user.is_superuser or backup.operation.user_id == user.id %} <a class="small" href="{% url 'operations:job' backup.operation_id %}">{% trans "Why?" %}</a>{% endif %}{% endif %}{% endif %}
{% load i18n %}{% load operations %}{% if backup.uuid|stringformat:"s" in pending_deletes %}<span class="badge text-bg-warning" data-backup-pending>{% trans "Deleting" %}</span>{% elif backup.state == "deleting" %}<span class="badge text-bg-warning" title="{% trans "Its deletion did not end; delete it again" %}">{% trans "Deleting" %}</span>{% elif backup.state == "ready" and backup.damage %}<span class="badge text-bg-danger">{% trans "Damaged" %}</span><div class="small text-danger text-break">{{ backup.damage|words }}</div>{% elif backup.state == "ready" %}<span class="badge text-bg-success"{% if backup.verified_at %} title="{% blocktrans with time=backup.verified_at|date:"Y-m-d H:i" %}Verified {{ time }}{% endblocktrans %}"{% endif %}>{% trans "Ready" %}</span>{% if backup.verified_at %} <span class="small text-body-secondary">{% trans "verified" %}</span>{% endif %}{% elif backup.being_made %}<span class="badge text-bg-info" data-backup-pending>{% trans "Creating" %}</span>{% if backup.operation_id %}{% if user.is_superuser or backup.operation.user_id == user.id %} <a class="small" href="{% url 'operations:job' backup.operation_id %}">{% trans "Progress" %}</a>{% endif %}{% endif %}{% elif backup.state == "missing" %}<span class="badge text-bg-danger" title="{% trans "Files of the backup are missing from the target" %}">{% trans "Missing" %}</span>{% else %}<span class="badge text-bg-danger">{% trans "Failed" %}</span>{% if backup.operation_id %}{% if user.is_superuser or backup.operation.user_id == user.id %} <a class="small" href="{% url 'operations:job' backup.operation_id %}">{% trans "Why?" %}</a>{% endif %}{% endif %}{% endif %}

View file

@ -289,3 +289,18 @@ class VerifyBackupTests(TransactionTestCase):
page = self.client.get(reverse("vmbackups:index"))
self.assertContains(page, "Damaged")
self.assertContains(page, "The backup&#x27;s file f is missing from the target")
def test_a_restore_page_tells_of_damage_in_the_chain(self):
self.client.force_login(self.admin)
damage = [{"text": "The backup's file %(name)s is missing from the target", "values": {"name": "base-vda.qcow2"}}]
page = self.client.get(reverse("vmbackups:restore_disk", args=[self.incremental.uuid]))
self.assertNotContains(page, "found damaged")
Backup.objects.filter(pk=self.full.pk).update(damage=damage)
self.assertEqual(Backup.objects.get(pk=self.incremental.pk).damaged_in_chain(), Backup.objects.get(pk=self.full.pk))
page = self.client.get(reverse("vmbackups:restore_disk", args=[self.incremental.uuid]))
self.assertContains(page, "which a verification found damaged")
self.assertContains(page, "base-vda.qcow2 is missing from the target")
page = self.client.get(reverse("vmbackups:index"))
self.assertContains(page, "base-vda.qcow2 is missing from the target") # under the badge, not only a tooltip
Backup.objects.filter(pk=self.full.pk).update(damage=[], parent=self.incremental) # a chain that loops
self.assertIsNone(Backup.objects.get(pk=self.incremental.pk).damaged_in_chain())