1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-12-02 08:56:07 +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

@ -104,7 +104,8 @@ class NewVMForm(forms.Form):
"""The new VM form (create_instance_w2.html); the API takes CreateInstanceSerializer."""
name = forms.CharField(max_length=64)
firmware = forms.CharField(max_length=64)
# empty: the machine's own, for an architecture with no firmware choice
firmware = forms.CharField(max_length=64, required=False)
# an emulated TPM 2.0, as Windows 11 needs
tpm = forms.BooleanField(required=False)
vcpu = forms.IntegerField(min_value=1)

View file

@ -905,6 +905,8 @@ class CreateInstance(Kind):
raise util.OperationError(_("Invalid cache mode"))
if data["vcpu_mode"] not in cpu_choices(conn.get_dom_capabilities(data["arch"], data["machine"])):
raise util.OperationError(_("This host offers no CPU mode or model %(mode)s"), mode=data["vcpu_mode"])
if data["net_model"] and data["net_model"] not in conn.get_network_models(data["arch"]):
raise util.OperationError(_("A %(arch)s VM cannot have a %(model)s network card"), arch=data["arch"], model=data["net_model"])
if data["add_cdrom"] != "None" and data["add_cdrom"] not in cdrom_buses:
raise util.OperationError(_("A CD-ROM cannot use the %(bus)s bus"), bus=data["add_cdrom"])
if data["cloud_init"]:

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

View file

@ -343,7 +343,7 @@ def _instance_page(request, pk, instance, compute):
interfaces_host = sorted(instance.proxy.get_ifaces())
nwfilters_host = instance.proxy.get_nwfilters()
storages_host = sorted(instance.proxy.get_storages(True))
net_models_host = instance.proxy.get_network_models()
net_models_host = instance.proxy.get_network_models(instance.arch)
if app_settings.VM_DRBD_STATUS == "True":
instance.drbd = drbd_status(request, pk)
@ -2602,7 +2602,7 @@ def create_instance(request, compute_id, arch, machine):
default_bus = app_settings.INSTANCE_VOLUME_DEFAULT_BUS
networks = sorted(conn.get_networks())
nwfilters = conn.get_nwfilters()
net_models_host = conn.get_network_models()
net_models_host = conn.get_network_models(arch)
default_nic_type = app_settings.INSTANCE_NIC_DEFAULT_TYPE
storages = sorted(conn.get_storages(only_actives=True))
default_cdrom = app_settings.INSTANCE_CDROM_ADD

Binary file not shown.

View file

@ -2803,7 +2803,7 @@ msgstr ""
"Konsol localhost dışında da dinliyor; parolasını yalnızca bir yönetici "
"kaldırabilir."
#: instances/forms.py:141
#: instances/forms.py:142
msgid "The name of the virtual machine must not contain any special characters"
msgstr "Sanal makine adı özel karakterler içeremez"
@ -2985,7 +2985,7 @@ msgstr ""
msgid "Clone VM"
msgstr "Sanal makineyi klonla"
#: instances/jobs.py:637 instances/jobs.py:644 instances/jobs.py:967
#: instances/jobs.py:637 instances/jobs.py:644 instances/jobs.py:969
msgid "Copying disks"
msgstr "Diskler kopyalanıyor"
@ -3090,11 +3090,11 @@ msgstr ""
msgid "Create VM"
msgstr "Sanal makine oluştur"
#: instances/jobs.py:895 instances/jobs.py:938 instances/views.py:2519
#: instances/jobs.py:895 instances/jobs.py:940 instances/views.py:2519
msgid "A virtual machine with this name already exists"
msgstr "Bu isimde bir sanal makine mevcut"
#: instances/jobs.py:897 instances/jobs.py:934
#: instances/jobs.py:897 instances/jobs.py:936
msgid "There is an instance with same name. Remove it and try again!"
msgstr "Aynı isimde başka bir sanal makine var. Onu silip yeniden deneyin!"
@ -3118,35 +3118,40 @@ msgstr "Bu sunucu %(mode)s CPU modunu veya modelini sunmuyor"
#: instances/jobs.py:909
#, python-format
msgid "A %(arch)s VM cannot have a %(model)s network card"
msgstr "Bir %(arch)s VM'inde %(model)s ağ kartı olamaz"
#: instances/jobs.py:911
#, python-format
msgid "A CD-ROM cannot use the %(bus)s bus"
msgstr "CD-ROM %(bus)s veri yolunu kullanamaz"
#: instances/jobs.py:912
#: instances/jobs.py:914
msgid "The cloud-init seed is read from a CD-ROM: choose its bus"
msgstr "cloud-init tohumu bir CD-ROM'dan okunur: veri yolunu seçin"
#: instances/jobs.py:915
#: instances/jobs.py:917
msgid "The cloud-init seed needs a directory storage pool for the disk"
msgstr "cloud-init tohumu, disk için bir dizin depolama havuzu gerektirir"
#: instances/jobs.py:919
#: instances/jobs.py:921
#, python-format
msgid "This host offers no firmware %(firmware)s"
msgstr "Bu sunucu %(firmware)s firmware'ini sunmuyor"
#: instances/jobs.py:921 vrtManager/instance.py:3116
#: instances/jobs.py:923 vrtManager/instance.py:3116
msgid "This host offers no TPM 2.0: install swtpm on it"
msgstr "Bu sunucu TPM 2.0 sunmuyor: üzerine swtpm kurun"
#: instances/jobs.py:987
#: instances/jobs.py:989
msgid "Writing the cloud-init seed"
msgstr "cloud-init tohumu yazılıyor"
#: instances/jobs.py:994
#: instances/jobs.py:996
msgid "Defining the VM"
msgstr "Sanal makine tanımlanıyor"
#: instances/jobs.py:1036
#: instances/jobs.py:1038
#, python-format
msgid ""
"The panel failed unexpectedly; its log has the details. Remove these volumes "
@ -3155,114 +3160,114 @@ msgstr ""
"Panel beklenmedik bir hatayla karşılaştı; ayrıntılar panelin günlüğünde. Bu "
"birimleri elle kaldırın: %(volumes)s"
#: instances/jobs.py:1040
#: instances/jobs.py:1042
#, python-format
msgid "%(error)s. Remove these volumes by hand: %(volumes)s"
msgstr "%(error)s. Şu birimleri elle silin: %(volumes)s"
#: instances/jobs.py:1067
#: instances/jobs.py:1069
#, python-format
msgid "The instance is already on %(compute)s"
msgstr "Sanal makine zaten %(compute)s üzerinde"
#: instances/jobs.py:1069
#: instances/jobs.py:1071
#, python-format
msgid "%(compute)s is not reachable"
msgstr "%(compute)s sunucusuna ulaşılamıyor"
#: instances/jobs.py:1071
#: instances/jobs.py:1073
#, python-format
msgid "%(compute)s is the VM's own host under another name"
msgstr "%(compute)s, sanal makinenin kendi sunucusunun başka bir adı"
#: instances/jobs.py:1128
#: instances/jobs.py:1130
#, python-format
msgid ""
"The VM migrated, but autostart could not be set on the destination: %(error)s"
msgstr ""
"Sanal makine taşındı, ancak hedefte otomatik başlatma ayarlanamadı: %(error)s"
#: instances/jobs.py:1135
#: instances/jobs.py:1137
#, python-format
msgid "The VM migrated, but its NVRAM file stays on the source: %(error)s"
msgstr "Sanal makine taşındı, ancak NVRAM dosyası kaynakta kaldı: %(error)s"
#: instances/jobs.py:1143
#: instances/jobs.py:1145
msgid "Migrate VM"
msgstr "Sanal makineyi taşı"
#: instances/jobs.py:1190
#: instances/jobs.py:1192
msgid "Migrating the VM"
msgstr "Sanal makine taşınıyor"
#: instances/jobs.py:1239
#: instances/jobs.py:1241
msgid "libvirt is still migrating the VM"
msgstr "libvirt sanal makineyi hâlâ taşıyor"
#: instances/jobs.py:1251
#: instances/jobs.py:1253
msgid "The VM stayed on the source host"
msgstr "Sanal makine kaynak sunucuda kaldı"
#: instances/jobs.py:1253
#: instances/jobs.py:1255
msgid ""
"The VM is on both computes or on neither; check them, then resolve this job."
msgstr ""
"Sanal makine ya iki sunucuda da var ya da hiçbirinde yok; kontrol edin, sonra"
" bu işi çözün."
#: instances/jobs.py:1272
#: instances/jobs.py:1274
msgid "Move disk"
msgstr "Diski taşı"
#: instances/jobs.py:1279
#: instances/jobs.py:1281
msgid "Choose a disk of the VM"
msgstr "Sanal makinenin bir diskini seçin"
#: instances/jobs.py:1303
#: instances/jobs.py:1305
msgid "Copying the disk"
msgstr "Disk kopyalanıyor"
#: instances/jobs.py:1345
#: instances/jobs.py:1347
#, python-format
msgid "Another block job runs on %(dev)s; check the VM"
msgstr ""
"%(dev)s üzerinde başka bir blok işi çalışıyor; sanal makineyi kontrol edin"
#: instances/jobs.py:1351
#: instances/jobs.py:1353
#, python-format
msgid "The disk stayed in %(path)s; remove %(dest)s if it is there"
msgstr "Disk %(path)s içinde kaldı; varsa %(dest)s dosyasını silin"
#: instances/jobs.py:1353
#: instances/jobs.py:1355
#, python-format
msgid "The definitions of %(dev)s name %(paths)s; check the VM"
msgstr "%(dev)s tanımları %(paths)s gösteriyor; sanal makineyi kontrol edin"
#: instances/jobs.py:1360
#: instances/jobs.py:1362
#, python-format
msgid "Disk %(path)s was kept: a disk file that stays needs it"
msgstr "%(path)s diski korundu: kalan bir disk dosyası ona ihtiyaç duyuyor"
#: instances/jobs.py:1361
#: instances/jobs.py:1363
#, python-format
msgid "The VM is removed, but disk %(path)s was not deleted: %(err)s"
msgstr "Sanal makine kaldırıldı, ancak %(path)s diski silinmedi: %(err)s"
#: instances/jobs.py:1362
#: instances/jobs.py:1364
#, python-format
msgid "Disk %(path)s is used by another VM and was kept"
msgstr ""
"%(path)s diski başka bir sanal makine tarafından kullanılıyor ve korundu"
#: instances/jobs.py:1416
#: instances/jobs.py:1418
msgid "Delete VM"
msgstr "Sanal makineyi sil"
#: instances/jobs.py:1446
#: instances/jobs.py:1448
msgid "Deleting the VM"
msgstr "Sanal makine siliniyor"
#: instances/jobs.py:1458
#: instances/jobs.py:1460
msgid "The VM was not deleted; it may have been shut off"
msgstr "Sanal makine silinmedi; kapatılmış olabilir"
@ -9133,7 +9138,7 @@ msgstr "Bağlantı başarısız: %(host)s bağlı değil"
msgid "This host has no architecture %(arch)s"
msgstr "Bu sunucuda %(arch)s mimarisi yok"
#: vrtManager/connection.py:1190
#: vrtManager/connection.py:1191
#, python-format
msgid ""
"Pool %(pool)s is not active: the files the disks of the VMs in it are made "

Binary file not shown.

View file

@ -2696,7 +2696,7 @@ msgid ""
"password."
msgstr "控制台监听的不只是 localhost;只有管理员可以移除其密码。"
#: instances/forms.py:141
#: instances/forms.py:142
msgid "The name of the virtual machine must not contain any special characters"
msgstr "虚拟机名称不能包含任何特殊字符"
@ -2865,7 +2865,7 @@ msgstr "无法解冻客户机的文件系统(%(error)s);请用以下命令
msgid "Clone VM"
msgstr "克隆虚拟机"
#: instances/jobs.py:637 instances/jobs.py:644 instances/jobs.py:967
#: instances/jobs.py:637 instances/jobs.py:644 instances/jobs.py:969
msgid "Copying disks"
msgstr "正在复制磁盘"
@ -2955,11 +2955,11 @@ msgstr "MAC 地址 %(mac)s 已属于此主机上另一台虚拟机的网卡"
msgid "Create VM"
msgstr "创建虚拟机"
#: instances/jobs.py:895 instances/jobs.py:938 instances/views.py:2519
#: instances/jobs.py:895 instances/jobs.py:940 instances/views.py:2519
msgid "A virtual machine with this name already exists"
msgstr "同名虚拟机已存在"
#: instances/jobs.py:897 instances/jobs.py:934
#: instances/jobs.py:897 instances/jobs.py:936
msgid "There is an instance with same name. Remove it and try again!"
msgstr "已存在同名虚拟机。请删除后重试!"
@ -2982,144 +2982,149 @@ msgstr "此主机不提供 CPU 模式或型号 %(mode)s"
#: instances/jobs.py:909
#, python-format
msgid "A %(arch)s VM cannot have a %(model)s network card"
msgstr "%(arch)s 虚拟机不能使用 %(model)s 网卡"
#: instances/jobs.py:911
#, python-format
msgid "A CD-ROM cannot use the %(bus)s bus"
msgstr "CD-ROM 不能使用 %(bus)s 总线"
#: instances/jobs.py:912
#: instances/jobs.py:914
msgid "The cloud-init seed is read from a CD-ROM: choose its bus"
msgstr "cloud-init 种子从 CD-ROM 读取:请选择其总线"
#: instances/jobs.py:915
#: instances/jobs.py:917
msgid "The cloud-init seed needs a directory storage pool for the disk"
msgstr "cloud-init 种子需要为磁盘使用目录类型的存储池"
#: instances/jobs.py:919
#: instances/jobs.py:921
#, python-format
msgid "This host offers no firmware %(firmware)s"
msgstr "此主机不提供固件 %(firmware)s"
#: instances/jobs.py:921 vrtManager/instance.py:3116
#: instances/jobs.py:923 vrtManager/instance.py:3116
msgid "This host offers no TPM 2.0: install swtpm on it"
msgstr "此主机不提供 TPM 2.0:请在主机上安装 swtpm"
#: instances/jobs.py:987
#: instances/jobs.py:989
msgid "Writing the cloud-init seed"
msgstr "正在写入 cloud-init 种子"
#: instances/jobs.py:994
#: instances/jobs.py:996
msgid "Defining the VM"
msgstr "正在定义虚拟机"
#: instances/jobs.py:1036
#: instances/jobs.py:1038
#, python-format
msgid ""
"The panel failed unexpectedly; its log has the details. Remove these volumes "
"by hand: %(volumes)s"
msgstr "面板发生意外错误;详细信息见面板日志。请手动删除这些卷:%(volumes)s"
#: instances/jobs.py:1040
#: instances/jobs.py:1042
#, python-format
msgid "%(error)s. Remove these volumes by hand: %(volumes)s"
msgstr "%(error)s。请手动删除这些卷:%(volumes)s"
#: instances/jobs.py:1067
#: instances/jobs.py:1069
#, python-format
msgid "The instance is already on %(compute)s"
msgstr "虚拟机已在 %(compute)s 上"
#: instances/jobs.py:1069
#: instances/jobs.py:1071
#, python-format
msgid "%(compute)s is not reachable"
msgstr "无法连接 %(compute)s"
#: instances/jobs.py:1071
#: instances/jobs.py:1073
#, python-format
msgid "%(compute)s is the VM's own host under another name"
msgstr "%(compute)s 是该虚拟机所在主机的另一个名称"
#: instances/jobs.py:1128
#: instances/jobs.py:1130
#, python-format
msgid ""
"The VM migrated, but autostart could not be set on the destination: %(error)s"
msgstr "虚拟机已迁移,但无法在目标主机上设置自动启动:%(error)s"
#: instances/jobs.py:1135
#: instances/jobs.py:1137
#, python-format
msgid "The VM migrated, but its NVRAM file stays on the source: %(error)s"
msgstr "虚拟机已迁移,但其 NVRAM 文件仍留在源主机上:%(error)s"
#: instances/jobs.py:1143
#: instances/jobs.py:1145
msgid "Migrate VM"
msgstr "迁移虚拟机"
#: instances/jobs.py:1190
#: instances/jobs.py:1192
msgid "Migrating the VM"
msgstr "正在迁移虚拟机"
#: instances/jobs.py:1239
#: instances/jobs.py:1241
msgid "libvirt is still migrating the VM"
msgstr "libvirt 仍在迁移虚拟机"
#: instances/jobs.py:1251
#: instances/jobs.py:1253
msgid "The VM stayed on the source host"
msgstr "虚拟机留在了源主机上"
#: instances/jobs.py:1253
#: instances/jobs.py:1255
msgid ""
"The VM is on both computes or on neither; check them, then resolve this job."
msgstr "虚拟机同时位于两个计算节点上,或都不在;请检查后处理此任务。"
#: instances/jobs.py:1272
#: instances/jobs.py:1274
msgid "Move disk"
msgstr "移动磁盘"
#: instances/jobs.py:1279
#: instances/jobs.py:1281
msgid "Choose a disk of the VM"
msgstr "请选择虚拟机的一个磁盘"
#: instances/jobs.py:1303
#: instances/jobs.py:1305
msgid "Copying the disk"
msgstr "正在复制磁盘"
#: instances/jobs.py:1345
#: instances/jobs.py:1347
#, python-format
msgid "Another block job runs on %(dev)s; check the VM"
msgstr "%(dev)s 上正在运行另一个块任务;请检查虚拟机"
#: instances/jobs.py:1351
#: instances/jobs.py:1353
#, python-format
msgid "The disk stayed in %(path)s; remove %(dest)s if it is there"
msgstr "磁盘仍在 %(path)s;如果 %(dest)s 存在,请将其删除"
#: instances/jobs.py:1353
#: instances/jobs.py:1355
#, python-format
msgid "The definitions of %(dev)s name %(paths)s; check the VM"
msgstr "%(dev)s 的定义指向 %(paths)s;请检查虚拟机"
#: instances/jobs.py:1360
#: instances/jobs.py:1362
#, python-format
msgid "Disk %(path)s was kept: a disk file that stays needs it"
msgstr "磁盘 %(path)s 已保留:某个保留的磁盘文件依赖它"
#: instances/jobs.py:1361
#: instances/jobs.py:1363
#, python-format
msgid "The VM is removed, but disk %(path)s was not deleted: %(err)s"
msgstr "虚拟机已删除,但磁盘 %(path)s 未被删除:%(err)s"
#: instances/jobs.py:1362
#: instances/jobs.py:1364
#, python-format
msgid "Disk %(path)s is used by another VM and was kept"
msgstr "磁盘 %(path)s 正被另一台虚拟机使用,已保留"
#: instances/jobs.py:1416
#: instances/jobs.py:1418
msgid "Delete VM"
msgstr "删除虚拟机"
#: instances/jobs.py:1446
#: instances/jobs.py:1448
msgid "Deleting the VM"
msgstr "正在删除虚拟机"
#: instances/jobs.py:1458
#: instances/jobs.py:1460
msgid "The VM was not deleted; it may have been shut off"
msgstr "虚拟机未被删除;它可能已被关闭"
@ -8633,7 +8638,7 @@ msgstr "连接失败:%(host)s 未连接"
msgid "This host has no architecture %(arch)s"
msgstr "此主机没有 %(arch)s 架构"
#: vrtManager/connection.py:1190
#: vrtManager/connection.py:1191
#, python-format
msgid ""
"Pool %(pool)s is not active: the files the disks of the VMs in it are made "

View file

@ -893,10 +893,11 @@ class wvmConnect(object):
return util.get_xml_path(self.get_dom_cap_xml(arch, machine), func=get_hostdev_list)
def get_network_models(self):
"""
:return: network card models
"""
def get_network_models(self, arch):
"""The network card models for a VM of arch: s390x machines have no
PCI bus for the emulated ones."""
if arch == "s390x":
return ["default", "virtio"]
return ["default", "e1000", "e1000e", "rtl8139", "virtio"]
def get_image_formats(self):