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
|
|
@ -17,6 +17,7 @@ from django.utils import timezone
|
|||
|
||||
from appsettings.models import AppSettings
|
||||
from appsettings.settings import app_settings
|
||||
from operations.utils import words
|
||||
from operations import jobs
|
||||
from operations.models import Claim, Operation, WorkerLease
|
||||
from operations.tests import fakes
|
||||
|
|
@ -77,7 +78,7 @@ class WorkerTestCase(TransactionTestCase):
|
|||
self.start()
|
||||
self.assertTrue(wait_for(lambda: state(op) in Operation.TERMINAL))
|
||||
op.refresh_from_db()
|
||||
self.assertEqual((op.state, op.result), (Operation.SUCCEEDED, {"value": "42"}), op.error)
|
||||
self.assertEqual((op.state, op.result), (Operation.SUCCEEDED, {"value": "42"}), words(op.error))
|
||||
|
||||
def test_an_error_before_effects_fails_the_job(self):
|
||||
op = self.submit("test.scripted", {"fail_before": True}, "key-00000001")
|
||||
|
|
@ -90,7 +91,7 @@ class WorkerTestCase(TransactionTestCase):
|
|||
with patch.object(fakes.NoopKind, "precheck", side_effect=failure):
|
||||
self.start()
|
||||
self.assertTrue(wait_for(lambda: state(op) == Operation.FAILED))
|
||||
error = Operation.objects.get(pk=op.pk).error
|
||||
error = words(Operation.objects.get(pk=op.pk).error)
|
||||
self.assertEqual(error, "The host of this virtual machine cannot be reached right now.")
|
||||
self.assertNotIn("example.com", error)
|
||||
|
||||
|
|
@ -221,7 +222,7 @@ class WorkerTestCase(TransactionTestCase):
|
|||
with patch("operations.jobs.Context", side_effect=RuntimeError("no context")):
|
||||
self.start()
|
||||
self.assertTrue(wait_for(lambda: state(op) == Operation.FAILED))
|
||||
self.assertIn("no context", Operation.objects.get(pk=op.pk).error)
|
||||
self.assertIn("no context", words(Operation.objects.get(pk=op.pk).error))
|
||||
self.assertFalse(Claim.objects.filter(operation=op).exists())
|
||||
|
||||
def test_a_failing_manager_loop_ends_the_process(self):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue