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

fix(operations): a job's unexpected error is not shown raw; the log has its traceback

A job that failed on an exception that is not libvirt's or a refusal
showed its raw text to users (a SQL error such as "UNIQUE constraint
failed: instances_instance.uuid", a KeyError's key), and the worker
logged only that text. Users now read "The panel failed unexpectedly;
its log has the details." and the worker logs the exception with its
traceback.

A live clone whose recovery found the clone made but could not thaw the
source's file systems kept that in the error of a succeeded job, which
the job panel does not show. It is a warning of the clone's result, as
when the job itself made the clone.
This commit is contained in:
catborise 2026-11-06 23:10:59 +03:00
parent eaf1d9c36d
commit 3965abd7ec
10 changed files with 375 additions and 277 deletions

View file

@ -21,7 +21,7 @@ from operations.utils import words
from operations import jobs
from operations.models import Claim, Operation, WorkerLease
from operations.tests import fakes
from operations.worker import Worker, data_dir, host_identity, housekeeping
from operations.worker import Worker, data_dir, host_identity, housekeeping, traceback_of
from vrtManager.util import ConnectionFailed
@ -250,12 +250,25 @@ class WorkerTestCase(TransactionTestCase):
def test_a_job_thread_that_raised_before_its_effects_fails(self):
op = self.submit("test.noop", {}, "key-00000001")
with patch("operations.jobs.Context", side_effect=RuntimeError("no context")):
with patch("operations.jobs.Context", side_effect=RuntimeError("no context")), \
self.assertLogs("operations.worker", "WARNING") as logs:
self.start()
self.assertTrue(wait_for(lambda: state(op) == Operation.FAILED))
self.assertIn("no context", words(Operation.objects.get(pk=op.pk).error))
# a fault of the panel: users read that, the log has the exception with its traceback
self.assertEqual(words(Operation.objects.get(pk=op.pk).error), "The panel failed unexpectedly; its log has the details.")
self.assertTrue(any("no context" in line and "Traceback" in line for line in logs.output))
self.assertFalse(Claim.objects.filter(operation=op).exists())
def test_a_traceback_in_the_log_has_no_secret(self):
# as the message: the exception's text is written again at its end
try:
raise RuntimeError("password=review-dummy-secret")
except RuntimeError as err:
trace = traceback_of(err)
self.assertIn("Traceback", trace)
self.assertIn("password=***", trace)
self.assertNotIn("review-dummy-secret", trace)
def test_a_database_error_skips_a_tick(self):
directory = tempfile.TemporaryDirectory()
self.addCleanup(directory.cleanup)