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

fix(instances): NIC edits keep their settings; edits keep metadata

- change_network detached the NIC and attached one built from scratch,
  dropping its QoS, link state and other settings. It now edits the NIC
  of the persistent definition in place and defines once; a running VM
  gets the change at its next start, as the UI already says.
- add_network, delete_network and set_link_state did nothing on a
  paused VM, and set_link_state rewrote the persistent NIC from the live
  XML. They now update the running definition when the VM is active and
  the persistent one always, each from its own XML.
- Boot and console edits used xml.etree, which renamed the namespace
  prefixes of other tools' metadata (<app:info> became <ns0:info>); they
  use lxml now.
- The NIC table and the clone form are filled from the persistent
  definition (Instance.config_networks, config_disks), so a pending NIC
  change is shown and can be edited again.

A live test runs 18 domain edits on stopped, running and paused VMs
whose definition has elements WebVirtCloud does not manage, and checks
for each the effect, that nothing else in the persistent definition
changed, and that persistent-only edits leave the running VM alone.
This commit is contained in:
catborise 2026-10-04 00:27:55 +03:00
parent 57cf49262a
commit 5def4e41fd
8 changed files with 444 additions and 89 deletions

View file

@ -63,8 +63,8 @@ class LiveDataLossTestCase(TestCase):
# helpers
def vm(self, name, disks, uefi=False):
dom = livetest.define_vm(self.conn, P + name, disks, uefi=uefi)
def vm(self, name, disks, uefi=False, extra_devices=""):
dom = livetest.define_vm(self.conn, P + name, disks, uefi=uefi, extra_devices=extra_devices)
refr(self.compute)
return dom, Instance.objects.get(compute=self.compute, uuid=dom.UUIDString())
@ -268,3 +268,23 @@ class LiveDataLossTestCase(TestCase):
self.post("change_options", inst, {"title": "for-old", "description": ""})
self.assertNotIn("<title>for-old</title>", dom_new.XMLDesc(0))
# NIC edits of a running VM are pending until restart; the form must show them
def test_pending_nic_change_is_shown_and_can_be_edited_again(self):
nic = "<interface type='network'><mac address='52:54:00:aa:05:01'/><source network='default'/></interface>"
dom, inst = self.vm("nic-pending", [], extra_devices=nic)
dom.create()
def change(old, new):
return self.post("change_network", inst, {
"net-old-mac-0": old, "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")
page = self.client.get(reverse("instances:instance", args=[inst.id])).content.decode()
self.assertIn('name="net-old-mac-0" value="52:54:00:aa:05:02"', page)
change("52:54:00:aa:05:02", "52:54:00:aa:05:03")
self.assertIn("52:54:00:aa:05:03", dom.XMLDesc(libvirt.VIR_DOMAIN_XML_INACTIVE))