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

fix(vmbackups): a schedule run's failure reason in the reader's language

A failed run kept the error as English text and the schedule page passed
the whole sentence to gettext, which found no catalog entry once values
were filled in. The run now keeps the error as messages (text and values),
as jobs do, and the page shows them with the new words filter.
This commit is contained in:
catborise 2026-11-18 14:05:38 +03:00
parent fb6a427a47
commit e1611efd53
7 changed files with 40 additions and 15 deletions

View file

@ -12,6 +12,7 @@ from computes.models import Compute
from instances.models import Instance
from instances.tests.test_page_controls import PageControls
from logs.models import Logs
from operations.utils import say
from vmbackups.models import Backup, BackupPolicy, BackupRun, BackupTarget, BackupTargetPool
@ -85,7 +86,7 @@ class PolicyPageTests(TestCase):
def test_edit_and_the_runs(self):
policy = self.schedule()
BackupRun.objects.create(policy=policy, instance=self.vm1, day=datetime.date.today(), state=BackupRun.SKIPPED,
note="The host was in maintenance")
note=say("The host was in maintenance"))
url = reverse("vmbackups:policy", args=[policy.pk])
page = self.client.get(url)
self.assertContains(page, "The host was in maintenance")

View file

@ -9,7 +9,7 @@ from unittest.mock import MagicMock, patch
import libvirt
from django.contrib.auth import get_user_model
from django.test import TransactionTestCase, override_settings
from django.utils import timezone
from django.utils import timezone, translation
from appsettings.settings import get_settings
from computes.models import Compute
@ -17,6 +17,7 @@ from instances.models import Instance
from operations import jobs
from operations.jobs import Context
from operations.models import Operation, acquire
from operations.utils import words
from vmbackups import schedule
from vmbackups.jobs import CheckTarget, DeleteBackup, _beyond_keep
from vmbackups.models import Backup, BackupFile, BackupPolicy, BackupRun, BackupTarget, BackupTargetPool
@ -192,7 +193,7 @@ class ScheduleTests(TransactionTestCase):
self.pass_at(at(2026, 11, 17, 8, 1))
run = BackupRun.objects.get()
self.assertEqual(run.state, BackupRun.SKIPPED)
self.assertIn("maintenance", run.note)
self.assertIn("maintenance", words(run.note))
self.assertEqual(self.creates(), [])
def test_maintenance_ended_inside_the_window(self):
@ -212,7 +213,7 @@ class ScheduleTests(TransactionTestCase):
self.pass_at(at(2026, 11, 17, 8, 1)) # the worker was down from before 02:00
run = BackupRun.objects.get()
self.assertEqual(run.state, BackupRun.SKIPPED)
self.assertIn("6 hours", run.note)
self.assertIn("6 hours", words(run.note))
self.assertEqual(self.creates(), [])
def test_a_new_schedule_does_not_skip_the_times_before_it(self):
@ -270,14 +271,16 @@ class ScheduleTests(TransactionTestCase):
self.pass_at(at(2026, 11, 17, 2, 0))
run = BackupRun.objects.get()
self.assertEqual(run.state, BackupRun.FAILED)
self.assertIn("owner", run.note)
self.assertIn("owner", words(run.note))
def test_a_vm_that_cannot_be_backed_up_fails_once_with_the_reason(self):
self.proxy.backup_plan.side_effect = OperationError("%(vm)s has TPM state; TPM backups come later", vm="vm1")
self.proxy.backup_plan.side_effect = OperationError("%(vm)s has TPM state; shut it down to back it up", vm="vm1")
self.pass_at(at(2026, 11, 17, 2, 0))
self.pass_at(at(2026, 11, 17, 2, 1))
run = BackupRun.objects.get()
self.assertEqual((run.state, run.note), (BackupRun.FAILED, "vm1 has TPM state; TPM backups come later"))
self.assertEqual((run.state, words(run.note)), (BackupRun.FAILED, "vm1 has TPM state; shut it down to back it up"))
with translation.override("tr"): # in the reader's language, its values in place
self.assertEqual(words(run.note), "vm1 TPM durumu taşıyor; yedeklemek için kapatın")
def test_an_unreachable_host_is_tried_again(self):
from vrtManager.util import ConnectionFailed