1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-12-03 17:36:05 +00:00

fix(instances): a VM of an architecture without firmware choices or PCI cards can be created

The create page shows no firmware choice for an architecture whose host
offers none, yet the form required one, so such a VM could never be
created from the page. The firmware is now optional there: the machine's
own is used, as the job and the API already did.

s390x machines have no PCI bus for the emulated network cards (e1000,
e1000e, rtl8139), yet the create page and the VM's network tab offered
them for every architecture. They now offer default and virtio there,
and a create job refuses a card model the VM's architecture cannot have.
This commit is contained in:
catborise 2026-11-12 14:13:30 +03:00
parent 3bd519c935
commit 159049736d
12 changed files with 107 additions and 80 deletions

View file

@ -36,6 +36,7 @@ class CloudInitCreateTestCase(TransactionTestCase):
self.conn.wvm.lookupByUUIDString.side_effect = missing # until the job defines the VM
self.conn.get_instances.return_value = []
self.conn.get_networks.return_value = ["default"]
self.conn.get_network_models.return_value = ["default", "virtio"]
self.conn.get_cache_modes.return_value = {"none": "Disable cache"}
self.conn.get_firmwares.return_value = ["BIOS", "UEFI", "UEFI Secure Boot"]
self.conn.get_dom_capabilities.return_value = {"cpu_modes": ["host-model"]}

View file

@ -181,15 +181,15 @@ class CreateFormValuesTests(TestCase):
page = self.page(networks="")
self.assertIn("Networks: This field is required.", self.summary(page))
def test_a_firmware_error_without_a_firmware_choice_is_in_the_summary(self):
# an architecture with no firmware choice renders no firmware select
def test_an_architecture_without_a_firmware_choice_needs_none(self):
# its page renders no firmware select: the machine's own firmware is used
with patch("vrtManager.connection.wvmConnect.get_firmwares", return_value=[]):
fields = valid()
del fields["firmware"]
_, response = render_create_page(self, fields)
page = html.fromstring(response.content)
self.assertEqual(page.xpath("//select[@name='firmware']"), [])
self.assertIn("Firmware: This field is required.", self.summary(page))
self.assertNotIn("Firmware", self.summary(page))
class FlavorPresetTests(TestCase):

View file

@ -13,6 +13,7 @@ from appsettings.settings import get_settings
from computes.models import Compute
from instances.jobs import CreateInstance
from instances.models import Instance
from vrtManager.connection import wvmConnect
from instances.tests.create_page import BODY
from operations.jobs import Context
from operations.models import Operation, acquire
@ -31,6 +32,7 @@ class CreateJobTestCase(TransactionTestCase):
self.addCleanup(patcher.stop)
self.conn.get_instances.return_value = []
self.conn.get_networks.return_value = ["default"]
self.conn.get_network_models.side_effect = lambda arch: wvmConnect.get_network_models(None, arch)
self.conn.get_nwfilters.return_value = ["clean-traffic"]
self.conn.get_cache_modes.return_value = {"none": "Disable cache"}
self.conn.get_firmwares.return_value = ["BIOS", "UEFI", "UEFI Secure Boot"]
@ -212,6 +214,15 @@ class CreateJobTestCase(TransactionTestCase):
self.assertContains(response, "Each network card needs a network", status_code=400)
self.assertFalse(Operation.objects.exists())
def test_a_network_card_model_the_architecture_lacks_is_refused(self):
# s390x machines have no PCI bus for an emulated card
admin = get_user_model().objects.get(username="create_admin")
params = CreateInstance().normalize({**BODY, "compute": self.compute.pk, "arch": "s390x",
"machine": "s390-ccw-virtio", "net_model": "e1000"})
with self.assertRaisesMessage(libvirt.libvirtError, "A s390x VM cannot have a e1000 network card"):
CreateInstance().validate(admin, params)
CreateInstance().validate(admin, {**params, "net_model": "virtio"})
def test_a_mac_of_another_vm_on_the_host_is_refused(self):
url = f"/api/v1/computes/{self.compute.pk}/instances/create/x86_64/q35/"
nic = "<domain><devices><interface><mac address='%s'/></interface></devices></domain>"

View file

@ -37,6 +37,7 @@ class CreateRollbackTestCase(TestCase):
conn.get_dom_capabilities.return_value = {"cpu_modes": ["host-model"]}
conn.get_instances.return_value = []
conn.get_networks.return_value = ["default"]
conn.get_network_models.return_value = ["default", "virtio"]
conn.create_volume.return_value = "/pool/rb-vm.qcow2"
missing = libvirtError("no domain")
missing.get_error_code = lambda: VIR_ERR_NO_DOMAIN