mirror of
https://github.com/retspen/webvirtcloud
synced 2026-12-02 08:56:07 +00:00
fix(instances): a new VM's vCPUs, memory and disk size are at least 1
The create form and the API took 0 or a negative number for vCPUs, memory and a new disk's size: the API queued the job (202) and it failed later in libvirt; the page did the same, its formnovalidate skipping the browser's min. The create model's fields now refuse values below 1, so the form shows the error beside its field and the API answers 400 naming it. The form also checks the MAC addresses as the API and the job do (one per NIC at most, each a MAC address), so a bad one is an error on the form instead of a job that fails. Closes #175
This commit is contained in:
parent
0a37ca8b70
commit
999480301e
4 changed files with 40 additions and 3 deletions
|
|
@ -81,6 +81,22 @@ class CreateFormInputTests(TestCase):
|
|||
self.assertTrue(any("Choose one disk source" in str(m) for m in response.context["messages"]))
|
||||
self.assertFalse(Operation.objects.exists())
|
||||
|
||||
def test_impossible_sizes_are_refused_beside_their_fields(self):
|
||||
_, response = render_create_page(self, valid(vcpu="0", memory="-1", hdd_size="0", storage="default-pool"))
|
||||
self.assertEqual(response.status_code, 200)
|
||||
page = html.fromstring(response.content)
|
||||
for field in ("vm_vcpu", "vm_memory", "vm_hdd_size"):
|
||||
with self.subTest(field=field):
|
||||
self.assertIn("greater than or equal to 1", page.get_element_by_id(f"{field}_error").text_content())
|
||||
self.assertFalse(Operation.objects.exists())
|
||||
|
||||
def test_a_bad_mac_is_refused_by_the_form(self):
|
||||
_, response = render_create_page(self, valid(hdd_size="10", storage="default-pool",
|
||||
networks="default,isolated", mac="52:54:00:00:00:01,aa:"))
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertIn("Invalid MAC address", " ".join(response.context["vm_form"].errors.get("mac", [])))
|
||||
self.assertFalse(Operation.objects.exists())
|
||||
|
||||
def test_only_the_chosen_disk_source_is_enabled(self):
|
||||
for posted, chosen in (("template", "template"), ("existing", "existing"), ("nonsense", "new")):
|
||||
with self.subTest(posted=posted):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue