1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-11-11 12:46:49 +00:00

fix(instances): reverting a running VM to an internal snapshot fails before any effect

The internal revert's shut-off check ran in the job's run, after its
intent was recorded, so the refusal went to recovery: the job ended
uncertain and kept the VM's claim until a superuser resolved it. The check
(check_internal_revert) now runs in precheck too, so a page older than the
VM's start, or a direct POST, fails the job with the reason.
This commit is contained in:
catborise 2026-11-05 16:00:32 +03:00
parent fe102f98c8
commit 62976cbd55
3 changed files with 18 additions and 3 deletions

View file

@ -449,6 +449,8 @@ class RevertSnapshot(Kind):
proxy = _checked_proxy(op)
if op.params["external"]:
proxy.check_external_revert(op.params["name"])
else:
proxy.check_internal_revert()
# a revert gives the VM the host devices it had then: not one given since to another VM
has_hostdevs, definitions = _snapshot_definitions(proxy, op.params)
if has_hostdevs:

View file

@ -92,6 +92,14 @@ class SnapshotJobsTestCase(TransactionTestCase):
self.queue_and_run("revert_external_snapshot", {"name": "a"})
self.assertFalse(Operation.objects.get().effects_started)
def test_an_internal_revert_of_a_running_vm_is_refused_before_effects(self):
# the page disables the button, but it may be older than the VM's start
self.proxy.check_internal_revert.side_effect = OperationError("Shut the VM down to revert to an internal snapshot")
with self.assertRaises(OperationError):
self.queue_and_run("revert_snapshot", {"name": "b"})
self.assertFalse(Operation.objects.get().effects_started)
self.proxy.snapshot_revert.assert_not_called()
def test_an_internal_revert_is_made_by_the_worker(self):
self.queue_and_run("revert_snapshot", {"name": "b"})
self.proxy.snapshot_revert.assert_called_once_with("b")