mirror of
https://github.com/retspen/webvirtcloud
synced 2026-11-11 12:46:49 +00:00
fix(instances): a refused custom VM form comes back with its disks and networks
A refused custom create form came back with its image pool unselected and its disk and network lists empty: every disk's device and bus and every MAC had to be chosen again. Adding a disk or a network also reset the rows already there: each addition rebuilt all rows from an HTML string, so the earlier disks fell back to the default device and bus and every NIC got a new random MAC, a typed one included. The view sends the submitted pool, disks (volume, device, bus) and networks (name, MAC) back with json_script, built field by field from the POST (submitted_custom_lists). The rows are cloned from two <template> elements and filled with textContent and listeners; one function, sync_custom_lists, derives the images, networks and mac fields and the device<i>/bus<i> names from the rows in order. Adding or removing a row leaves the others as they are, and a random MAC that arrives after one was typed is dropped. On load the page selects the pool, waits for its volumes, rebuilds each disk with its device, waits for that device's bus list and selects its bus, rebuilds the networks with their MACs, and then focuses the first error. A submitted value the loaded lists no longer have stays selected. The bus and volume loaders return their requests so that the page can wait on them.
This commit is contained in:
parent
0d5014d9ef
commit
96141c3ef7
5 changed files with 349 additions and 111 deletions
|
|
@ -1,6 +1,7 @@
|
|||
"""A refused VM create form comes back bound and open, with what was
|
||||
entered; the other create forms keep their own defaults."""
|
||||
|
||||
import json
|
||||
import uuid
|
||||
from unittest.mock import patch
|
||||
|
||||
|
|
@ -179,3 +180,36 @@ class FlavorFormTests(TestCase):
|
|||
form = page.get_element_by_id(f"addVMflavor{self.first.id}").xpath(".//form")[0]
|
||||
self.assertEqual(len(form.xpath(".//*[@name='cache_mode']")), 1)
|
||||
self.assertEqual(form.xpath(".//input[@name='form_id']/@value"), [f"flavor{self.first.id}"])
|
||||
|
||||
|
||||
class CustomListsTests(TestCase):
|
||||
"""The custom form's disks and networks come back with a refusal."""
|
||||
|
||||
def custom_lists(self, response):
|
||||
"""The custom form's disks and networks the page restores, or None."""
|
||||
element = html.fromstring(response.content).get_element_by_id("custom-lists", None)
|
||||
return None if element is None else json.loads(element.text)
|
||||
|
||||
def test_a_refused_custom_form_sends_back_its_lists(self):
|
||||
_, response = render_create_page(self, valid(
|
||||
form_id="custom", name="bad name!", **{"storage-control": "default"}, images="a.qcow2,b.qcow2",
|
||||
device0="cdrom", bus0="sata", device1="disk", bus1="virtio",
|
||||
networks="default,isolated", mac="52:54:00:00:00:01"))
|
||||
self.assertEqual(self.custom_lists(response), {
|
||||
"pool": "default",
|
||||
"disks": [{"volume": "a.qcow2", "device": "cdrom", "bus": "sata"},
|
||||
{"volume": "b.qcow2", "device": "disk", "bus": "virtio"}],
|
||||
"networks": [{"name": "default", "mac": "52:54:00:00:00:01"}, {"name": "isolated", "mac": ""}],
|
||||
})
|
||||
|
||||
def test_a_hostile_volume_name_round_trips_through_the_lists(self):
|
||||
name = "x'\"><img src=x>"
|
||||
_, response = render_create_page(self, valid(form_id="custom", name="bad name!", images=name))
|
||||
self.assertEqual(self.custom_lists(response)["disks"][0]["volume"], name)
|
||||
self.assertNotIn(b"<img src=x>", response.content)
|
||||
|
||||
def test_only_a_refused_custom_form_sends_lists(self):
|
||||
_, response = render_create_page(self)
|
||||
self.assertIsNone(self.custom_lists(response))
|
||||
_, response = render_create_page(self, valid(form_id="template", name="bad name!", images="a.qcow2"))
|
||||
self.assertIsNone(self.custom_lists(response))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue