mirror of
https://github.com/retspen/webvirtcloud
synced 2026-11-10 20:26:48 +00:00
fix(instances): a custom VM gets the MAC addresses its create form shows
The custom create form shows a MAC per network (random, or typed in), but had no mac field: the script wrote the joined list into every name="mac" input of the page, the other six-plus forms' own MAC fields, so a flavor form then sent one MAC per custom network and was refused, and the custom VM got other MACs from libvirt. The custom form gets its own hidden mac field and the script writes only there. The field took 17 characters, one MAC, so the API also refused a VM with two NICs and their MACs; it takes 255. The serializer's test sent no submission_key, so its check for more MACs than networks never ran; it does now, next to the case of two networks with two MACs.
This commit is contained in:
parent
d14a311862
commit
35468bc0fd
4 changed files with 40 additions and 11 deletions
|
|
@ -157,12 +157,17 @@ class NicMacsTestCase(TestCase):
|
|||
with self.subTest(mac=mac), self.assertRaises(ValueError):
|
||||
nic_macs(mac, networks)
|
||||
|
||||
def test_api_serializer_refuses_extra_macs(self):
|
||||
serializer = CreateInstanceSerializer(data={
|
||||
"name": "api-vm", "vcpu": 1, "vcpu_mode": "host-model", "memory": 512,
|
||||
"networks": "default", "mac": "52:54:00:00:00:01,52:54:00:00:00:02", "nwfilter": "",
|
||||
"storage": "default", "hdd_size": 1, "cache_mode": "none", "meta_prealloc": False,
|
||||
"virtio": True, "qemu_ga": True, "video": "vga", "listener_addr": "0.0.0.0",
|
||||
})
|
||||
self.assertFalse(serializer.is_valid())
|
||||
self.assertIn("mac", serializer.errors)
|
||||
def test_api_serializer_takes_a_mac_per_network(self):
|
||||
def serializer(networks):
|
||||
return CreateInstanceSerializer(data={
|
||||
"name": "api-vm", "vcpu": 1, "vcpu_mode": "host-model", "memory": 512,
|
||||
"networks": networks, "mac": "52:54:00:00:00:01,52:54:00:00:00:02", "nwfilter": "",
|
||||
"storage": "default", "hdd_size": 1, "cache_mode": "none", "meta_prealloc": False,
|
||||
"virtio": True, "qemu_ga": True, "video": "vga", "listener_addr": "0.0.0.0",
|
||||
"submission_key": "test-key",
|
||||
})
|
||||
two_nics = serializer("default,second")
|
||||
self.assertTrue(two_nics.is_valid(), two_nics.errors)
|
||||
extra = serializer("default")
|
||||
self.assertFalse(extra.is_valid())
|
||||
self.assertEqual(extra.errors["mac"], ["More MAC addresses than networks"])
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue