mirror of
https://github.com/retspen/webvirtcloud
synced 2026-11-11 04:36:48 +00:00
test: each test is in the tests package of the code it tests
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.
This commit is contained in:
parent
4e0952aa50
commit
bdc8a6755c
73 changed files with 2231 additions and 2132 deletions
|
|
@ -5,79 +5,12 @@ value refused leaves no secret behind."""
|
|||
|
||||
from unittest.mock import patch
|
||||
|
||||
import libvirt
|
||||
from computes.models import Compute
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.test import SimpleTestCase, TestCase
|
||||
from django.urls import reverse
|
||||
from lxml import etree, html
|
||||
from lxml import html
|
||||
from virtsecrets.forms import AddSecret
|
||||
from vrtManager.util import OperationError
|
||||
from vrtManager.virtsecrets import wvmSecrets
|
||||
|
||||
|
||||
def connection():
|
||||
with patch("vrtManager.connection.connection_manager.get_connection") as get:
|
||||
conn = wvmSecrets("host", "login", "pw", 1)
|
||||
return conn, get.return_value
|
||||
|
||||
|
||||
class CreateSecretTests(SimpleTestCase):
|
||||
def test_the_usage_is_text_of_its_element(self):
|
||||
for usage_type, element, usage in (
|
||||
("volume", "volume", "/var/lib/libvirt/images/vm-1.qcow2"),
|
||||
("iscsi", "target", "iqn.2026-10.test.wvc:lun"),
|
||||
("ceph", "name", "client.libvirt secret"),
|
||||
("tls", "name", "migration"),
|
||||
("vtpm", "name", "VM web-1's vTPM"),
|
||||
("volume", "volume", "/a'b<c>&d\""),
|
||||
):
|
||||
with self.subTest(usage_type=usage_type, usage=usage):
|
||||
conn, wvm = connection()
|
||||
conn.create_secret(usage_type, usage, private=True)
|
||||
secret = etree.fromstring(wvm.secretDefineXML.call_args.args[0])
|
||||
self.assertEqual((secret.get("ephemeral"), secret.get("private")), ("no", "yes"))
|
||||
self.assertEqual(secret.find("usage").get("type"), usage_type)
|
||||
self.assertEqual(secret.findtext(f"usage/{element}"), usage)
|
||||
wvm.secretDefineXML.return_value.setValue.assert_not_called()
|
||||
|
||||
def test_a_new_secret_takes_its_value_at_once(self):
|
||||
for usage_type, value, stored in (("ceph", "cHcA/w==", b"pw\x00\xff"), ("iscsi", " pass word ", b" pass word ")):
|
||||
with self.subTest(usage_type=usage_type):
|
||||
conn, wvm = connection()
|
||||
conn.create_secret(usage_type, "lun", value)
|
||||
wvm.secretDefineXML.return_value.setValue.assert_called_once_with(stored)
|
||||
|
||||
def test_a_value_refused_leaves_no_secret(self):
|
||||
conn, wvm = connection()
|
||||
with self.assertRaisesRegex(OperationError, "base64"):
|
||||
conn.create_secret("ceph", "client.libvirt", "not base64!")
|
||||
wvm.secretDefineXML.assert_not_called()
|
||||
wvm.secretDefineXML.return_value.setValue.side_effect = libvirt.libvirtError("refused")
|
||||
with self.assertRaises(libvirt.libvirtError):
|
||||
conn.create_secret("iscsi", "lun", "pw")
|
||||
wvm.secretDefineXML.return_value.undefine.assert_called_once_with()
|
||||
|
||||
|
||||
class SecretValueTests(SimpleTestCase):
|
||||
def set_value(self, usage_type, value):
|
||||
conn, wvm = connection()
|
||||
secret = wvm.secretLookupByUUIDString.return_value
|
||||
secret.XMLDesc.return_value = f"<secret><usage type='{usage_type}'><name>x</name></usage></secret>"
|
||||
conn.set_secret_value("uuid", value)
|
||||
return secret.setValue
|
||||
|
||||
def test_a_ceph_key_is_stored_as_its_bytes_a_password_as_typed(self):
|
||||
self.set_value("ceph", "cHcA/w==").assert_called_once_with(b"pw\x00\xff")
|
||||
# a password that happens to be base64 is not decoded
|
||||
self.set_value("iscsi", "cHcA/w==").assert_called_once_with(b"cHcA/w==")
|
||||
self.set_value("vtpm", " pässword ").assert_called_once_with(" pässword ".encode())
|
||||
|
||||
def test_a_ceph_key_that_is_not_base64_is_refused_without_the_value(self):
|
||||
for value in ("b'cHc='", "not base64!", "kéy"):
|
||||
with self.subTest(value=value), self.assertRaises(OperationError) as refused:
|
||||
self.set_value("ceph", value)
|
||||
self.assertNotIn(value, str(refused.exception))
|
||||
|
||||
|
||||
class CreateSecretFormTests(SimpleTestCase):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue