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

feat(instances): a protected VM is not deleted nor restored over

A superuser turns a VM's protection on or off on its Settings tab, not while
a job holds the VM (a deletion or a restore over it that runs would not
stop). While it is on, its deletion (page, API, a queued job at its start)
and a restore of a backup over it are refused; the Destroy tab, the destroy
page and the restore page say so. A VM moved outside the panel keeps it.
The API shows the flag read-only.
This commit is contained in:
catborise 2026-11-19 21:45:57 +03:00
parent 57e90e0d27
commit adb4231db7
21 changed files with 706 additions and 491 deletions

View file

@ -66,6 +66,24 @@ class DestroyOrderTestCase(TransactionTestCase):
(f"compute:{self.instance.compute_id}", "exclusive"), (f"instance:{UUID}", "exclusive")})
self.assertEqual(self.proxy.mock_calls, [])
def test_a_protected_vm_is_not_deleted(self):
Instance.objects.filter(pk=self.instance.pk).update(protected=True)
response = self.client.post(reverse("instances:destroy", args=[self.instance.id]),
{"submission_key": "key-destroy01"}, follow=True)
self.assertContains(response, "destroy-vm is protected")
url = f"/api/v1/computes/{self.instance.compute_id}/instances/{self.instance.id}/"
response = self.client.delete(url, {"submission_key": "key-api00003"}, content_type="application/json")
self.assertContains(response, "destroy-vm is protected", status_code=400)
self.assertFalse(Operation.objects.exists())
# protected after the delete was queued: refused before any effect
Instance.objects.filter(pk=self.instance.pk).update(protected=False)
op = self.queue()
Instance.objects.filter(pk=self.instance.pk).update(protected=True)
self.proxy.reset_mock() # what the pages read
with self.assertRaisesMessage(OperationError, "destroy-vm is protected"):
self.run_job(op)
self.assertEqual(self.proxy.mock_calls, [])
def test_backup_checkpoints_go_with_the_vm(self):
# libvirt refuses to undefine a VM that has checkpoints without this flag
self.run_job(self.queue())