mirror of
https://github.com/retspen/webvirtcloud
synced 2026-11-08 19:26:48 +00:00
Tests that build vrtManager objects and touch no view, form or model of an app lived in that app; vrtManager/tests already holds such tests, so the convention was split. They move to vrtManager/tests: the firmware, CPU mode and PCIe port definitions of a new VM (test_create), USB and PCI host devices, the console listener, host CPU reads, interface reads, deletes and XML, network filters, PCI passthrough rules, node devices, network changes, addresses and leases, pool XML, secrets, and the live tests that use vrtManager only (disk resize, ISO, snapshots, XML, live clone). livetest.py, the live-test helper six apps import, and the network test driver move with them. Others go to their app: the quota with a host down to instances, the 401/403 Logs rows (webvirtcloud's middleware) to webvirtcloud, the VM page's tab script test to instances, novncd's own tests out of the console views tests, the compute lock and input validation tests out of the computes views tests, the interface views out of the forms tests. instances/tests/test_views.py, entirely live, is test_live_views.py. Test modules imported fixtures from each other; shared ones are now in vrtManager/tests/fakes.py (migration fakes, node devices, IOMMU groups, leases, a NAT network, a Ceph secret), interfaces/tests/fakes.py, console/tests/daemons.py (novncd loaded once), livetest.wait_for and instances/tests/create_page.BODY. Every live test checks livetest.enabled(). The suite runs the same 2097 tests.
46 lines
2.1 KiB
Python
46 lines
2.1 KiB
Python
"""The network page's fixed-address dialog takes real MAC addresses and host
|
|
names: the browser refuses what its pattern attributes do not match. Runs
|
|
on a private libvirt test driver."""
|
|
|
|
import re
|
|
import tempfile
|
|
from unittest.mock import patch
|
|
|
|
import libvirt
|
|
from computes.models import Compute
|
|
from django.contrib.auth import get_user_model
|
|
from django.test import TestCase
|
|
from django.urls import reverse
|
|
from lxml import html
|
|
from vrtManager.tests.driver import without_inactive_flag
|
|
|
|
NODE = """<node><network><name>lab</name><bridge name='virbr9'/>
|
|
<ip address='192.0.2.1' netmask='255.255.255.0'><dhcp><range start='192.0.2.10' end='192.0.2.20'/></dhcp></ip>
|
|
</network></node>"""
|
|
|
|
|
|
class FixedAddressFormTests(TestCase):
|
|
def test_macs_and_host_names_are_accepted(self):
|
|
node = tempfile.NamedTemporaryFile("w", suffix=".xml")
|
|
self.addCleanup(node.close)
|
|
node.write(NODE)
|
|
node.flush()
|
|
conn = libvirt.open(f"test://{node.name}")
|
|
self.addCleanup(conn.close)
|
|
without_inactive_flag(self)
|
|
compute = Compute.objects.create(name="fixed", hostname="localhost", login="", password="", type=4)
|
|
self.client.force_login(get_user_model().objects.create_superuser("fixed", "fixed@example.com", "pw"))
|
|
with patch("vrtManager.connection.connection_manager.get_connection", return_value=conn):
|
|
page = html.fromstring(self.client.get(reverse("network", args=[compute.id, "lab"])).content)
|
|
dialog = page.get_element_by_id("FixedAddress")
|
|
mac = re.compile(dialog.xpath(".//input[@name='mac']/@pattern")[0])
|
|
name = re.compile(dialog.xpath(".//input[@name='name']/@pattern")[0])
|
|
for value in ("52:54:00:ab:cd:ef", "52:54:00:AB:CD:EF", "0:1:0:1:2a:3b"):
|
|
with self.subTest(mac=value):
|
|
self.assertTrue(mac.fullmatch(value))
|
|
for value in ("web-01", "db.lan", "vm_1"):
|
|
with self.subTest(name=value):
|
|
self.assertTrue(name.fullmatch(value))
|
|
for value in ("a b", 'x"<'):
|
|
with self.subTest(refused=value):
|
|
self.assertFalse(name.fullmatch(value))
|