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

fix(instances): a new VM's CPU is a mode or a model the host offers, checked by libvirt

- A named CPU model is written without check='none' and with
  fallback='forbid': libvirt checks before the start that the host runs
  it, and it is not swapped for another model.
- Mode maximum is written as that mode; it was written as a model named
  maximum.
- Model names up to 64 characters: the -noTSX and -IBRS models, the ones a
  mixed set of hosts needs, were refused at 20.
- The mode or model is checked against the host's capabilities when the VM
  is defined, from the page and the API alike; no CPU element (QEMU's
  oldest default CPU) is no longer offered.
- The default CPU mode setting offers the modes the new VM dialog has;
  no-model and custom, which matched none of them, become host-model.
This commit is contained in:
catborise 2026-10-29 10:50:20 +03:00
parent d5ef7cff75
commit 5eb544eb8a
15 changed files with 139 additions and 19 deletions

View file

@ -32,6 +32,8 @@ class CreateJobTestCase(TransactionTestCase):
self.conn.get_instances.return_value = []
self.conn.get_cache_modes.return_value = {"none": "Disable cache"}
self.conn.get_disk_bus_types.return_value = ["virtio", "sata"]
self.conn.get_dom_capabilities.return_value = {"cpu_modes": ["host-model", "custom"],
"cpu_custom_models": ["Skylake-Server-noTSX-IBRS"]}
self.conn.create_volume.return_value = "/srv/default/api-vm.qcow2"
def test_the_api_queues_the_create_and_the_worker_defines_and_records_it(self):
@ -55,6 +57,18 @@ class CreateJobTestCase(TransactionTestCase):
self.assertEqual(response.status_code, 400)
self.assertFalse(Operation.objects.exists())
def test_the_cpu_is_a_mode_or_a_model_the_host_offers(self):
url = f"/api/v1/computes/{self.compute.pk}/instances/create/x86_64/q35/"
# a model name longer than 20 characters is taken; none, or one the host lacks, is refused
response = self.client.post(url, {**BODY, "vcpu_mode": "Skylake-Server-noTSX-IBRS"}, content_type="application/json")
self.assertEqual(response.status_code, 202)
for vcpu_mode in ("", "maximum", "EPYC-Genoa", "x" * 65):
with self.subTest(vcpu_mode=vcpu_mode):
body = {**BODY, "vcpu_mode": vcpu_mode, "name": "api-vm2", "submission_key": f"key-{len(vcpu_mode):08}"}
response = self.client.post(url, body, content_type="application/json")
self.assertEqual(response.status_code, 400)
self.assertEqual(Operation.objects.count(), 1)
def test_impossible_sizes_are_refused_by_the_api(self):
url = f"/api/v1/computes/{self.compute.pk}/instances/create/x86_64/q35/"
for field, value in (("vcpu", 0), ("memory", -512), ("hdd_size", 0)):