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

fix(computes): a VM that returns gets its protection, schedules and backups back

A VM that vanished from its compute, or whose compute was deleted and added
again, came back with its owners and tags only: it was no longer protected,
its schedules no longer backed it up, and its backups stayed unlinked, so its
Backups tab no longer listed them and retention left them for good. The
Removed VMs record now keeps its protection, its schedules and its own
backups (not those of a copy under the same UUID), and gives them back.
Turning protection on or off waits for the ownership step, so a VM dropped
from its host's list meanwhile is not told protected.
This commit is contained in:
catborise 2026-11-20 07:55:26 +03:00
parent 5c7687c60d
commit dc5b1dbb2a
14 changed files with 251 additions and 138 deletions

View file

@ -1,5 +1,7 @@
"""A protected VM: only a superuser turns its protection on or off; while on, the VM is not deleted nor
restored over (refusals in test_destroy and vmbackups.tests.test_restore_over)."""
from unittest.mock import patch
from django.contrib.auth import get_user_model
from django.test import TestCase
from django.urls import reverse
@ -50,6 +52,18 @@ class ProtectedTestCase(TestCase):
self.client.post(reverse("instances:set_protected", args=[self.instance.id]), {"protected": "True"})
self.assertFalse(Instance.objects.get(pk=self.instance.pk).protected)
def test_not_changed_when_the_vm_left_its_host_meanwhile(self):
# its record may be kept, unprotected, for the Removed VMs page: no success is told
# the first check is the claim's (serialize_instance_mutation); the VM goes after it
with patch("instances.views._moved_meanwhile", side_effect=[False, True]), \
patch("instances.views.lock_ownership") as lock:
response = self.client.post(reverse("instances:set_protected", args=[self.instance.id]),
{"protected": "True"}, HTTP_X_REQUESTED_WITH="XMLHttpRequest")
lock.assert_called_once()
self.assertEqual(response.status_code, 409)
self.assertFalse(Instance.objects.get(pk=self.instance.pk).protected)
self.assertFalse(Logs.objects.filter(instance="pe-vm").exists())
def test_the_destroy_page_offers_no_form(self):
Instance.objects.filter(pk=self.instance.pk).update(protected=True)
page = self.client.get(reverse("instances:destroy", args=[self.instance.id]))