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.
42 lines
2.1 KiB
Python
42 lines
2.1 KiB
Python
"""The host, pool, user and format values of a new Ceph or NFS pool go into
|
|
its XML as text, whatever characters they hold; a new pool that does not
|
|
start is not left defined."""
|
|
|
|
from unittest.mock import patch
|
|
|
|
from django.test import SimpleTestCase
|
|
from libvirt import libvirtError
|
|
from lxml import etree
|
|
from vrtManager.storage import wvmStorages
|
|
|
|
ODD = "a'b\"c<d>&e"
|
|
|
|
|
|
class PoolXmlTests(SimpleTestCase):
|
|
def defined_xml(self, create, *args):
|
|
with patch("vrtManager.connection.connection_manager.get_connection") as get:
|
|
getattr(wvmStorages("host", "login", "pw", 1), create)(*args)
|
|
return etree.fromstring(get.return_value.storagePoolDefineXML.call_args.args[0])
|
|
|
|
def test_ceph_values_are_text(self):
|
|
pool = self.defined_xml("create_storage_ceph", "rbd", "pool1", ODD + "pool", ODD + "host", ODD + "user", ODD + "secret")
|
|
self.assertEqual(pool.findtext("source/name"), ODD + "pool")
|
|
self.assertEqual(pool.find("source/host").get("name"), ODD + "host")
|
|
self.assertEqual(pool.find("source/auth").get("username"), ODD + "user")
|
|
self.assertEqual(pool.find("source/auth/secret").get("uuid"), ODD + "secret")
|
|
|
|
def test_nfs_values_are_text(self):
|
|
pool = self.defined_xml("create_storage_netfs", "netfs", "pool1", ODD + "host", "/srv/nfs", ODD + "fmt", "/mnt/pool1")
|
|
self.assertEqual(pool.find("source/host").get("name"), ODD + "host")
|
|
self.assertEqual(pool.find("source/format").get("type"), ODD + "fmt")
|
|
self.assertEqual(pool.find("source/dir").get("path"), "/srv/nfs")
|
|
|
|
def test_a_pool_that_does_not_start_is_undefined(self):
|
|
with patch("vrtManager.connection.connection_manager.get_connection") as get:
|
|
pool = get.return_value.storagePoolDefineXML.return_value
|
|
pool.create.side_effect = libvirtError("mount failed")
|
|
with self.assertRaises(libvirtError):
|
|
wvmStorages("host", "login", "pw", 1).create_storage_netfs(
|
|
"netfs", "pool1", "nfs.example.com", "/srv/nfs", "auto", "/mnt/pool1")
|
|
pool.undefine.assert_called_once_with()
|
|
pool.setAutostart.assert_not_called()
|