mirror of
https://github.com/retspen/webvirtcloud
synced 2026-12-03 09:26:03 +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:
parent
eaf1d9c36d
commit
3965abd7ec
10 changed files with 375 additions and 277 deletions
|
|
@ -31,7 +31,7 @@ from instances import utils
|
|||
from instances.models import Instance
|
||||
from logs.audit import write
|
||||
from operations import claims
|
||||
from operations.utils import safe_text, say
|
||||
from operations.utils import REPORTED, safe_text, say
|
||||
from operations.jobs import Cancelled, Kind, Outcome, Plan, register
|
||||
from operations.models import Claim, Operation
|
||||
|
||||
|
|
@ -666,7 +666,10 @@ class CloneInstance(Kind):
|
|||
except libvirtError as err:
|
||||
thawed = say(THAW_FAILED, error=err, vm=op.resource_label.rpartition("/")[2])
|
||||
outcome = self._live_outcome(proxy, op)
|
||||
outcome.error += thawed
|
||||
if thawed and outcome.state == Operation.SUCCEEDED: # a warning of the clone, as when the job made it
|
||||
outcome.result["warning"] = [*outcome.result.get("warning", []), *thawed]
|
||||
else:
|
||||
outcome.error += thawed
|
||||
return outcome
|
||||
|
||||
def _live_outcome(self, proxy, op):
|
||||
|
|
@ -899,6 +902,10 @@ class CreateInstance(Kind):
|
|||
conn.delete_volume(path)
|
||||
except libvirtError:
|
||||
leftovers.append(path)
|
||||
if leftovers and not isinstance(err, REPORTED): # a fault of the panel is not shown as it is
|
||||
raise util.OperationError(_("The panel failed unexpectedly; its log has the details. "
|
||||
"Remove these volumes by hand: %(volumes)s"),
|
||||
volumes=", ".join(leftovers)) from err
|
||||
if leftovers:
|
||||
raise util.OperationError(_("%(error)s. Remove these volumes by hand: %(volumes)s"),
|
||||
error=err, volumes=", ".join(leftovers)) from err
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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": ""},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue