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

@ -621,6 +621,16 @@ class LiveCloneJobTestCase(TransactionTestCase):
self.proxy.resize_mem.assert_not_called()
self.proxy.start.assert_called_once_with()
def test_a_thaw_that_fails_in_the_recovery_of_a_made_clone_is_a_warning_of_the_clone(self):
# the job panel shows a succeeded job's warning; an error of it was not shown
self.proxy.get_status.return_value = 1
self.proxy.fs_thaw.side_effect = libvirt_error(libvirt.VIR_ERR_AGENT_UNRESPONSIVE)
self.proxy.backup_result.return_value = None
self.proxy.backup_targets.return_value = {"/other/x.qcow2"}
outcome, _op = self.recovered(defined=True, frozen=True)
self.assertEqual((outcome.state, outcome.error), (Operation.SUCCEEDED, []))
self.assertIn("virsh domfsthaw", words(outcome.result["warning"]))
def test_recovery_of_a_defined_clone_succeeds(self):
self.proxy.backup_result.return_value = None # libvirtd restarted after the clone was defined
self.proxy.backup_targets.return_value = {"/other/x.qcow2"} # checked after it

View file

@ -16,6 +16,8 @@ from instances.models import Instance
from instances.tests.create_page import BODY
from operations.jobs import Context
from operations.models import Operation, acquire
from operations.utils import traceback_of
from vrtManager.util import OperationError
class CreateJobTestCase(TransactionTestCase):
@ -100,6 +102,22 @@ class CreateJobTestCase(TransactionTestCase):
self.assertEqual(response.status_code, 409)
self.assertEqual(Operation.objects.count(), 1)
def test_a_fault_of_the_panel_with_volumes_left_is_not_shown_as_it_is(self):
# its text names nothing users can act on; the volumes to remove are
self.client.post(f"/api/v1/computes/{self.compute.pk}/instances/create/x86_64/q35/", BODY,
content_type="application/json")
op = Operation.objects.get()
acquire("wvc-test:1:a", "wvc-test")
Operation.objects.filter(pk=op.pk).update(state=Operation.RUNNING, worker="wvc-test:1:a")
op.refresh_from_db()
self.conn.create_instance.side_effect = RuntimeError("no such bus")
self.conn.delete_volume.side_effect = libvirt.libvirtError("volume is busy")
with self.assertRaises(OperationError) as raised:
CreateInstance().run(op, Context(op, SimpleNamespace(identity="wvc-test:1:a")))
self.assertEqual(str(raised.exception), "The panel failed unexpectedly; its log has the details. "
"Remove these volumes by hand: /srv/default/api-vm.qcow2")
self.assertIn("RuntimeError: no such bus", traceback_of(raised.exception))
@patch("instances.jobs.wvmConnect")
def test_a_create_that_left_nothing_failed(self, conn):
op = Operation(params={**BODY, "template": ""},