From b95f2a28d70cce930eaae20b08a52cf8fc299bf0 Mon Sep 17 00:00:00 2001 From: catborise Date: Mon, 9 Nov 2026 21:24:00 +0300 Subject: [PATCH] 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 Claude-Session: https://claude.ai/code/session_01Kk4h2TcUiaWmU5MUszYSea --- instances/tests/test_detail_reads.py | 12 ++++++++++++ instances/views.py | 3 ++- 2 files changed, 14 insertions(+), 1 deletion(-) 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: