mirror of
https://github.com/retspen/webvirtcloud
synced 2026-11-09 19:56:48 +00:00
feat(operations): a job's error and warning show in the reader's language
A job stored its error and its result's warning as English text, much of it built with the values in it (volume paths, a disk, libvirt's error), so no catalog could translate it, and the job pages and panel showed English whatever the language. A job now stores them as messages: our English text, marked for translation, and its values; libvirt's own text is a message without values and is shown as it is. The jobs API and pages put them in the reader's language. OperationError keeps its text and values apart for the same reason, so a refusal raised while a job is submitted is shown translated too. Messages one after another still read as sentences. Errors stored before are kept as one message each, shown as they were.
This commit is contained in:
parent
0eab09e19d
commit
1e66367bb4
29 changed files with 927 additions and 333 deletions
|
|
@ -15,6 +15,7 @@ from appsettings.settings import get_settings
|
|||
from computes.models import Compute
|
||||
from instances.jobs import CloneInstance
|
||||
from instances.models import Instance
|
||||
from operations.utils import words
|
||||
from operations.jobs import Cancelled, Context
|
||||
from vrtManager.util import OperationError
|
||||
from operations.models import Claim, Operation, acquire
|
||||
|
|
@ -119,7 +120,7 @@ class CloneJobTestCase(TransactionTestCase):
|
|||
self.proxy.start.side_effect = libvirt.libvirtError("no memory")
|
||||
op, result = self.clone_with(**{"clone-start": "true"})
|
||||
self.assertTrue(Instance.objects.filter(uuid=op.intent["uuid"]).exists())
|
||||
self.assertIn("The clone is made, but not as asked", result["warning"])
|
||||
self.assertIn("The clone is made, but not as asked", words(result["warning"]))
|
||||
|
||||
def queued(self):
|
||||
self.client.post(reverse("instances:clone", args=[self.source.pk]),
|
||||
|
|
@ -155,7 +156,7 @@ class CloneJobTestCase(TransactionTestCase):
|
|||
conn.return_value.wvm.listAllStoragePools.return_value = [pool(["copy.qcow2", "other.qcow2"])]
|
||||
outcome = CloneInstance().reconcile(op)
|
||||
self.assertEqual(outcome.state, Operation.UNCERTAIN)
|
||||
self.assertIn("copy.qcow2", outcome.error)
|
||||
self.assertIn("copy.qcow2", words(outcome.error))
|
||||
|
||||
@patch("instances.jobs.wvmConnect")
|
||||
def test_a_clone_that_left_nothing_failed(self, conn):
|
||||
|
|
@ -360,7 +361,7 @@ class LiveCloneJobTestCase(TransactionTestCase):
|
|||
self.assertLess(self.events.index("discard_backup_result"), self.events.index(("intent", "copy_started")))
|
||||
self.assertEqual(self.deleted(), []) # recovery deletes them
|
||||
outcome = self.recover(op)
|
||||
self.assertEqual((outcome.state, outcome.error), (Operation.FAILED, "libvirt error"))
|
||||
self.assertEqual((outcome.state, words(outcome.error)), (Operation.FAILED, "libvirt error"))
|
||||
self.assertNotIn("define_clone", self.events)
|
||||
self.assertEqual(self.deleted(), ["/real/copy-vda.qcow2", "/real/copy-vdb.qcow2"])
|
||||
|
||||
|
|
@ -386,7 +387,7 @@ class LiveCloneJobTestCase(TransactionTestCase):
|
|||
outcome = self.recover(op)
|
||||
self.assertEqual(self.events[0], "fs_thaw")
|
||||
self.assertEqual(outcome.state, Operation.FAILED)
|
||||
self.assertIn("virsh domfsthaw src", outcome.error)
|
||||
self.assertIn("virsh domfsthaw src", words(outcome.error))
|
||||
|
||||
def test_a_lost_connection_while_the_backup_starts_is_recoverys(self):
|
||||
self.track("begin_clone_backup", libvirt_error(libvirt.VIR_ERR_INTERNAL_ERROR))
|
||||
|
|
@ -418,8 +419,8 @@ class LiveCloneJobTestCase(TransactionTestCase):
|
|||
def test_a_thaw_error_is_a_warning_of_the_result(self):
|
||||
self.track("fs_thaw", libvirt_error(libvirt.VIR_ERR_AGENT_UNRESPONSIVE))
|
||||
result = self.run_job(self.op())
|
||||
self.assertIn("could not be thawed", result["warning"])
|
||||
self.assertIn("thaw them with: virsh domfsthaw src", result["warning"])
|
||||
self.assertIn("could not be thawed", words(result["warning"]))
|
||||
self.assertIn("thaw them with: virsh domfsthaw src", words(result["warning"]))
|
||||
self.proxy.define_clone.assert_called_once()
|
||||
|
||||
def test_a_failed_copy_deletes_only_what_the_job_created(self):
|
||||
|
|
@ -528,7 +529,7 @@ class LiveCloneJobTestCase(TransactionTestCase):
|
|||
outcome, _op = self.recovered(copy_started=None, created=[],
|
||||
planned=[{"dev": "vda", "path": "/pool/copy-vda.qcow2"}])
|
||||
self.assertEqual(outcome.state, Operation.UNCERTAIN)
|
||||
self.assertIn("/pool/copy-vda.qcow2", outcome.error)
|
||||
self.assertIn("/pool/copy-vda.qcow2", words(outcome.error))
|
||||
self.proxy.wvm.storagePoolLookupByName.assert_called_with("default")
|
||||
self.proxy.wvm.storagePoolLookupByName.return_value.storageVolLookupByName.assert_called_with("copy-vda.qcow2")
|
||||
self.proxy.get_volume_by_path.return_value.delete.assert_not_called()
|
||||
|
|
@ -581,7 +582,7 @@ class LiveCloneJobTestCase(TransactionTestCase):
|
|||
def test_recovery_of_a_failed_copy_deletes_what_was_created(self):
|
||||
outcome, _op = self.recovered(copy_result=[False, "No space left on device"])
|
||||
self.assertEqual(outcome.state, Operation.FAILED)
|
||||
self.assertIn("No space left on device", outcome.error)
|
||||
self.assertIn("No space left on device", words(outcome.error))
|
||||
self.assertEqual(self.deleted(), ["/real/copy-vda.qcow2"])
|
||||
outcome, _op = self.recovered(copy_result=[False, "Operation canceled"], cancel=True)
|
||||
self.assertEqual(outcome.state, Operation.CANCELLED)
|
||||
|
|
@ -589,7 +590,7 @@ class LiveCloneJobTestCase(TransactionTestCase):
|
|||
def test_a_recorded_failure_wins_over_another_tools_backup(self):
|
||||
self.proxy.backup_targets.return_value = {"/other/x.qcow2"}
|
||||
outcome, _op = self.recovered(copy_result=[False, "another backup runs"])
|
||||
self.assertEqual((outcome.state, outcome.error), (Operation.FAILED, "another backup runs"))
|
||||
self.assertEqual((outcome.state, words(outcome.error)), (Operation.FAILED, "another backup runs"))
|
||||
self.assertEqual(self.deleted(), ["/real/copy-vda.qcow2"])
|
||||
outcome, _op = self.recovered(copy_result=[False, "another backup runs"], cancel=True)
|
||||
self.assertEqual(outcome.state, Operation.CANCELLED)
|
||||
|
|
@ -598,7 +599,7 @@ class LiveCloneJobTestCase(TransactionTestCase):
|
|||
self.proxy.backup_result.return_value = None
|
||||
outcome, _op = self.recovered()
|
||||
self.assertEqual(outcome.state, Operation.UNCERTAIN)
|
||||
self.assertIn("/real/copy-vda.qcow2", outcome.error)
|
||||
self.assertIn("/real/copy-vda.qcow2", words(outcome.error))
|
||||
self.assertEqual(self.deleted(), [])
|
||||
|
||||
def test_recovery_thaws_a_guest_left_frozen_first(self):
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ from computes.models import Compute
|
|||
from django.contrib.auth import get_user_model
|
||||
from django.test import TransactionTestCase
|
||||
from instances.jobs import CreateInstance
|
||||
from operations.utils import words
|
||||
from operations.jobs import Context
|
||||
from operations.models import Operation, acquire
|
||||
from vrtManager.util import OperationError
|
||||
|
|
@ -97,4 +98,4 @@ class CloudInitCreateTestCase(TransactionTestCase):
|
|||
SimpleNamespace(listVolumes=lambda: ["cidata-abababab-0000-1111-2222-333333333333.iso"])]
|
||||
outcome = CreateInstance().reconcile(op)
|
||||
self.assertEqual(outcome.state, Operation.UNCERTAIN)
|
||||
self.assertIn("cidata-abababab-0000-1111-2222-333333333333.iso", outcome.error)
|
||||
self.assertIn("cidata-abababab-0000-1111-2222-333333333333.iso", words(outcome.error))
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ from appsettings.settings import get_settings
|
|||
from computes.models import Compute
|
||||
from instances.jobs import MoveDisk
|
||||
from instances.models import Instance
|
||||
from operations.utils import words
|
||||
from operations.jobs import Cancelled, Context, get_kind
|
||||
from operations.models import Claim, Operation, acquire
|
||||
|
||||
|
|
@ -116,7 +117,7 @@ class MoveDiskJobTestCase(TransactionTestCase):
|
|||
def test_recovery_reads_the_definitions(self):
|
||||
self.assertEqual(self.reconcile({NEW}).state, Operation.SUCCEEDED)
|
||||
failed = self.reconcile({OLD})
|
||||
self.assertEqual((failed.state, failed.error), (Operation.FAILED, f"The disk stayed in {OLD}; remove {NEW} "
|
||||
self.assertEqual((failed.state, words(failed.error)), (Operation.FAILED, f"The disk stayed in {OLD}; remove {NEW} "
|
||||
"if it is there"))
|
||||
self.assertEqual(self.reconcile({OLD, NEW}).state, Operation.UNCERTAIN)
|
||||
self.proxy.instance.blockJobAbort.assert_not_called()
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ from computes.models import Compute
|
|||
from instances.jobs import DeleteExternalSnapshot
|
||||
from instances.models import Instance
|
||||
from logs.models import Logs
|
||||
from operations.utils import say, words
|
||||
from operations import jobs
|
||||
from operations.jobs import Context, Outcome
|
||||
from operations.models import Claim, Operation, acquire
|
||||
|
|
@ -109,7 +110,7 @@ class SnapshotDeleteJobTestCase(TransactionTestCase):
|
|||
Logs.objects.all().delete()
|
||||
Operation.objects.all().delete()
|
||||
op = self.submitted()
|
||||
jobs.finish(op, Outcome(state, error="x"))
|
||||
jobs.finish(op, Outcome(state, error=say("x")))
|
||||
self.assertEqual(self.logged(), [("job_admin", "job-compute", "job-vm",
|
||||
f"VM job-vm: delete external snapshot one ({state})")])
|
||||
Logs.objects.all().delete()
|
||||
|
|
@ -125,7 +126,7 @@ class SnapshotDeleteJobTestCase(TransactionTestCase):
|
|||
|
||||
def test_a_resolved_job_is_logged_on_its_vm(self):
|
||||
op = self.submitted()
|
||||
jobs.finish(op, Outcome(Operation.UNCERTAIN, error="x"))
|
||||
jobs.finish(op, Outcome(Operation.UNCERTAIN, error=say("x")))
|
||||
Logs.objects.all().delete()
|
||||
jobs.resolve(op.pk, self.admin, Operation.FAILED, "disks checked")
|
||||
self.assertEqual(self.logged(), [("job_admin", "job-compute", "job-vm",
|
||||
|
|
@ -134,7 +135,7 @@ class SnapshotDeleteJobTestCase(TransactionTestCase):
|
|||
|
||||
def test_retention_keeps_the_log(self):
|
||||
op = self.submitted()
|
||||
jobs.finish(op, Outcome(Operation.FAILED, error="x"))
|
||||
jobs.finish(op, Outcome(Operation.FAILED, error=say("x")))
|
||||
Operation.objects.filter(pk=op.pk).update(finished_at=timezone.now() - timedelta(days=400))
|
||||
housekeeping()
|
||||
self.assertFalse(Operation.objects.filter(pk=op.pk).exists())
|
||||
|
|
@ -171,7 +172,7 @@ class SnapshotDeleteJobTestCase(TransactionTestCase):
|
|||
interrupted = self.reconcile()
|
||||
self.assertEqual(interrupted.state, Operation.UNCERTAIN)
|
||||
self.assertIn("It cannot be told whether the disks changed; check the VM before deleting the snapshot again",
|
||||
interrupted.error)
|
||||
words(interrupted.error))
|
||||
|
||||
def test_reconcile_reports_a_merge_that_stays_at_its_end_as_stalled(self):
|
||||
at_end = self.reconcile(jobs=[{"dev": "vda", "cur": 2, "end": 2}, {"dev": "vdb", "cur": 5, "end": 5}])
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue