mirror of
https://github.com/retspen/webvirtcloud
synced 2026-11-09 19:56: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.
66 lines
2.7 KiB
Python
66 lines
2.7 KiB
Python
"""Live check that a directory or NFS pool created on the storages page
|
|
starts when its directory does not exist yet: libvirt builds it. Runs only
|
|
with TEST_LIBVIRT_HOST set; the NFS case needs TEST_LIBVIRT_NFS_EXPORT, a
|
|
directory the host exports to its 127.0.0.1 (the Vagrant computes do)."""
|
|
|
|
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
|
|
|
|
|
|
@unittest.skipUnless(livetest.enabled(), "Set TEST_LIBVIRT_HOST to run the live libvirt tests")
|
|
class LivePoolsTestCase(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", 1)),
|
|
)
|
|
self.conn = connection_manager.get_connection(*args.values())
|
|
self.compute = Compute.objects.create(name="live-pools", **args)
|
|
self.client.force_login(get_user_model().objects.create_superuser("live-pools", "lp@example.com", "x"))
|
|
|
|
def remove_pool(self, name):
|
|
try:
|
|
pool = self.conn.storagePoolLookupByName(name)
|
|
except libvirt.libvirtError:
|
|
return
|
|
if pool.isActive():
|
|
pool.destroy() # unmounts an NFS pool
|
|
pool.delete(0) # removes the directory
|
|
pool.undefine()
|
|
|
|
def assert_created(self, data):
|
|
self.remove_pool(data["name"])
|
|
self.addCleanup(self.remove_pool, data["name"])
|
|
response = self.client.post(reverse("storages", args=[self.compute.id]), {"create": "", **data})
|
|
self.assertRedirects(
|
|
response, reverse("storage", args=[self.compute.id, data["name"]]), fetch_redirect_response=False
|
|
)
|
|
pool = self.conn.storagePoolLookupByName(data["name"])
|
|
self.assertTrue(pool.isActive())
|
|
self.assertTrue(pool.autostart())
|
|
|
|
def test_a_missing_directory_is_built(self):
|
|
self.assert_created({"name": P + "dir", "stg_type": "dir", "target": f"/var/lib/libvirt/{P}dir"})
|
|
|
|
@unittest.skipUnless(os.environ.get("TEST_LIBVIRT_NFS_EXPORT"), "Set TEST_LIBVIRT_NFS_EXPORT to run the NFS pool test")
|
|
def test_a_missing_mount_point_is_built(self):
|
|
self.assert_created({
|
|
"name": P + "nfs",
|
|
"stg_type": "netfs",
|
|
"netfs_host": "127.0.0.1",
|
|
"source": os.environ["TEST_LIBVIRT_NFS_EXPORT"],
|
|
"source_format": "nfs",
|
|
"target": f"/var/lib/libvirt/{P}nfs",
|
|
})
|