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

fix(instances): the VM page's DRBD state does not rewrite the VM's record

With VM DRBD Status on, the VM page saved the whole record it had read
after waiting up to its ssh timeout for the host. A migration or delete
that finished meanwhile was undone: the record moved back to the old
compute, or came back without its owners. Only the DRBD state is written.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kk4h2TcUiaWmU5MUszYSea
This commit is contained in:
catborise 2026-11-09 21:24:00 +03:00
parent 12e33f7964
commit b95f2a28d7
2 changed files with 14 additions and 1 deletions

View file

@ -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())

View file

@ -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: