diff --git a/instances/tests/test_detail_reads.py b/instances/tests/test_detail_reads.py index 3e4f667d..a4816169 100644 --- a/instances/tests/test_detail_reads.py +++ b/instances/tests/test_detail_reads.py @@ -5,6 +5,7 @@ on libvirt's test driver.""" from unittest.mock import patch import libvirt +from appsettings.models import AppSettings from computes.models import Compute from django.contrib.auth import get_user_model from django.test import TestCase @@ -107,3 +108,14 @@ class DetailReadsTests(TestCase): proxy.set_console_keymap("de") self.assertEqual(proxy.get_console_passwd(), "pass1") self.assertEqual(proxy.get_console_keymap(), "de") + + def test_the_drbd_state_does_not_bring_back_a_vm_deleted_meanwhile(self): + AppSettings.objects.filter(key="VM_DRBD_STATUS").update(value="True") + + def deleted_meanwhile(request, pk): + Instance.objects.filter(pk=pk).delete() + return "None DRBD" + + with patch("instances.views.drbd_status", side_effect=deleted_meanwhile): + self.render() + self.assertFalse(Instance.objects.filter(pk=self.vm.pk).exists()) diff --git a/instances/views.py b/instances/views.py index c334db53..759cb58a 100755 --- a/instances/views.py +++ b/instances/views.py @@ -342,7 +342,8 @@ def _instance_page(request, pk, instance, compute): if app_settings.VM_DRBD_STATUS == "True": instance.drbd = drbd_status(request, pk) - instance.save() + # the state alone: a whole-row save would undo a migration or delete finished meanwhile + Instance.objects.filter(pk=instance.pk).update(drbd=instance.drbd) usb_hostdevs, pci_hostdevs, other_hostdevs = instance.proxy.get_hostdevs() if usb_hostdevs or pci_hostdevs: