From 0d688885106c2bc643553be9998bc6c2cae6fc47 Mon Sep 17 00:00:00 2001 From: catborise Date: Sat, 14 Nov 2026 14:38:25 +0300 Subject: [PATCH] test(instances): live disk and NIC posts send what their forms send Since ad9c3ad9 a disk's detach and delete forms post the disk's path, and since b664e341 a NIC's form posts net-seen, its saved definition as the page read it; a post without them is refused as made from a stale page. Four live tests still posted the old fields, were refused and failed; test_clone then failed too, on the extra disk the refused delete left. They now post the same values as the forms. --- instances/tests/test_live_dataloss.py | 5 ++++- instances/tests/test_live_views.py | 10 ++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/instances/tests/test_live_dataloss.py b/instances/tests/test_live_dataloss.py index cbc21cc9..3a0da533 100644 --- a/instances/tests/test_live_dataloss.py +++ b/instances/tests/test_live_dataloss.py @@ -432,8 +432,11 @@ class LiveDataLossTestCase(TestCase): dom.create() def change(old, new): + # the form posts the NIC's saved definition as the page read it + seen = next(net["seen"] for net in Instance.objects.get(pk=inst.pk).config_networks if net["mac"] == old) return self.post("change_network", inst, { - "net-old-mac-0": old, "net-mac-0": new, "net-source-0": "net:default", "net-model-0": "virtio", + "net-old-mac-0": old, "net-seen-0": seen, "net-mac-0": new, "net-source-0": "net:default", + "net-model-0": "virtio", }) change("52:54:00:aa:05:01", "52:54:00:aa:05:02") diff --git a/instances/tests/test_live_views.py b/instances/tests/test_live_views.py index 39d331dd..51fcbbe1 100644 --- a/instances/tests/test_live_views.py +++ b/instances/tests/test_live_views.py @@ -412,6 +412,7 @@ class InstancesTestCase(TestCase): { "storage": livetest.POOL, "dev": "vdb", + "path": self.instance.disks[1]["path"], "name": "wvc-test-volume-2.qcow2", }, HTTP_REFERER=reverse("index"), @@ -427,6 +428,7 @@ class InstancesTestCase(TestCase): reverse("instances:detach_vol", args=[self.instance.id]), { "dev": "vda", + "path": self.instance.disks[0]["path"], }, HTTP_REFERER=reverse("index"), ) @@ -884,12 +886,18 @@ class InstancesTestCase(TestCase): ) self.assertEqual(response.status_code, 302) + def nic_seen(self, mac): + """What the NIC's form posts as net-seen: its saved definition as the page read it.""" + self.instance.__dict__.pop("config_networks", None) + return next(net["seen"] for net in self.instance.config_networks if net["mac"] == mac) + def test_change_network(self): self.assertEqual(self.instance.networks[0]["mac"], "52:54:00:a2:3c:e7") response = self.client.post( reverse("instances:change_network", args=[self.instance.id]), { "net-old-mac-0": "52:54:00:a2:3c:e7", + "net-seen-0": self.nic_seen("52:54:00:a2:3c:e7"), "net-mac-0": "52:54:00:a2:3c:e8", "net-source-0": "net:default", "net-nwfilter-0": "", @@ -913,6 +921,7 @@ class InstancesTestCase(TestCase): reverse("instances:change_network", args=[self.instance.id]), { "net-old-mac-1": "52:54:00:a2:3c:e9", + "net-seen-1": self.nic_seen("52:54:00:a2:3c:e9"), "net-mac-1": "52:54:00:a2:3c:ea", "net-source-1": "net:default", "net-nwfilter-1": "", @@ -934,6 +943,7 @@ class InstancesTestCase(TestCase): reverse("instances:change_network", args=[self.instance.id]), { "net-old-mac-0": "52:54:00:a2:3c:e8", + "net-seen-0": self.nic_seen("52:54:00:a2:3c:e8"), "net-mac-0": "52:54:00:a2:3c:e7", "net-source-0": "net:default", "net-model-0": "virtio",