1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-11-08 11:16:47 +00:00
webvirtcloud/instances/tests/create_page.py
catborise 2e1f29961c 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.
2026-10-29 11:17:38 +03:00

30 lines
1.5 KiB
Python

"""The VM create page rendered on libvirt's test driver, for the tests of
that page."""
from unittest.mock import patch
import libvirt
from computes.models import Compute
from django.contrib.auth import get_user_model
from django.urls import reverse
def render_create_page(testcase, data=None):
"""GET the create page, or POST data (a create submission) to it, as a
superuser on a test-driver compute; returns (compute, response)."""
conn = libvirt.open("test:///default")
testcase.addCleanup(conn.close)
compute, _ = Compute.objects.get_or_create(name="testdrv", hostname="localhost", login="", password="", type=4)
user = get_user_model().objects.filter(username="page").first() or \
get_user_model().objects.create_superuser("page", "page@example.com", "pw")
testcase.client.force_login(user)
url = reverse("instances:create_instance", args=[compute.id, "i686", "pc"])
with patch("vrtManager.connection.connection_manager.get_connection", return_value=conn), \
patch("vrtManager.connection.wvmConnect.get_machine_types", return_value=["pc"]), \
patch("vrtManager.connection.wvmConnect.get_nwfilters", return_value=[]), \
patch("vrtManager.connection.wvmConnect.get_cpu_modes", return_value=["host-model"]): # the test driver has none
if data is None:
response = testcase.client.get(url)
else:
response = testcase.client.post(url, {"create": "", **data})
return compute, response