mirror of
https://github.com/retspen/webvirtcloud
synced 2026-11-08 11:16:47 +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.
52 lines
2.2 KiB
Python
52 lines
2.2 KiB
Python
"""Live check that the secrets page creates a secret for each usage type
|
|
with a real usage value: a volume path, an iSCSI IQN and a Ceph name. Runs
|
|
only with TEST_LIBVIRT_HOST set."""
|
|
|
|
import os
|
|
import unittest
|
|
|
|
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 vrtManager.tests import livetest
|
|
from vrtManager.connection import connection_manager
|
|
|
|
P = livetest.PREFIX
|
|
USAGES = {
|
|
libvirt.VIR_SECRET_USAGE_TYPE_VOLUME: ("volume", f"/var/lib/libvirt/{P}secrets/vm-1.qcow2"),
|
|
libvirt.VIR_SECRET_USAGE_TYPE_ISCSI: ("iscsi", f"iqn.2026-10.test.wvc:{P}secret"),
|
|
libvirt.VIR_SECRET_USAGE_TYPE_CEPH: ("ceph", f"client.{P}secret secret"),
|
|
}
|
|
|
|
|
|
@unittest.skipUnless(livetest.enabled(), "Set TEST_LIBVIRT_HOST to run the live libvirt tests")
|
|
class LiveSecretsTestCase(TestCase):
|
|
def setUp(self):
|
|
args = dict(
|
|
hostname=os.environ["TEST_LIBVIRT_HOST"],
|
|
login=os.environ.get("TEST_LIBVIRT_LOGIN", ""),
|
|
password=os.environ.get("TEST_LIBVIRT_PASSWORD", ""),
|
|
type=int(os.environ.get("TEST_LIBVIRT_TYPE", 4)),
|
|
)
|
|
self.conn = connection_manager.get_connection(*args.values())
|
|
self.remove_secrets()
|
|
self.addCleanup(self.remove_secrets)
|
|
self.compute = Compute.objects.create(name="live-secrets", **args)
|
|
self.client.force_login(get_user_model().objects.create_superuser("live-secrets", "ls@example.com", "x"))
|
|
|
|
def remove_secrets(self):
|
|
for secret in self.conn.listAllSecrets():
|
|
if (secret.usageType(), secret.usageID()) in {(t, v) for t, (_, v) in USAGES.items()}:
|
|
secret.undefine()
|
|
|
|
def test_each_usage_type_takes_a_real_value(self):
|
|
for usage_type, (name, value) in USAGES.items():
|
|
with self.subTest(name):
|
|
response = self.client.post(
|
|
reverse("virtsecrets", args=[self.compute.id]),
|
|
{"create": "", "usage_type": name, "usage": value},
|
|
)
|
|
self.assertEqual(response.status_code, 302)
|
|
self.assertEqual(self.conn.secretLookupByUsage(usage_type, value).usageID(), value)
|