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.
44 lines
2.4 KiB
Python
44 lines
2.4 KiB
Python
"""A secret a VM or a pool needs is not deleted: without it that VM or pool
|
|
no longer starts. A VM names its secret in a disk, a host device or its vTPM,
|
|
a pool in its source, by UUID or by usage within the usage type; as they run
|
|
and as saved. libvirt's test driver has no secrets, so the connection is a
|
|
mock."""
|
|
|
|
from unittest.mock import patch
|
|
|
|
import libvirt
|
|
from computes.models import Compute
|
|
from django.contrib.auth import get_user_model
|
|
from django.contrib.messages import get_messages
|
|
from django.test import TestCase
|
|
from django.urls import reverse
|
|
from vrtManager.util import OperationError
|
|
from vrtManager.tests.fakes import CEPH
|
|
|
|
|
|
class SecretInUsePageTests(TestCase):
|
|
def setUp(self):
|
|
compute = Compute.objects.create(name="secret-use", hostname="localhost", login="", password="", type=4)
|
|
self.client.force_login(get_user_model().objects.create_superuser("secret-use", "su@example.com", "pw"))
|
|
self.url = reverse("virtsecrets", args=[compute.id])
|
|
|
|
def test_the_page_says_who_needs_it(self):
|
|
with patch("virtsecrets.views.wvmSecrets") as conn:
|
|
conn.return_value.delete_secret.side_effect = OperationError(f"Secret {CEPH} is used by VMs db-2")
|
|
response = self.client.post(self.url, {"delete": "", "uuid": CEPH})
|
|
self.assertRedirects(response, self.url, fetch_redirect_response=False)
|
|
self.assertEqual([str(m) for m in get_messages(response.wsgi_request)], [f"Secret {CEPH} is used by VMs db-2"])
|
|
|
|
def test_a_post_to_a_host_not_reached_is_redirected(self):
|
|
with patch("virtsecrets.views.wvmSecrets", side_effect=libvirt.libvirtError("unable to connect")):
|
|
response = self.client.post(self.url, {"delete": "", "uuid": CEPH})
|
|
self.assertRedirects(response, self.url, fetch_redirect_response=False)
|
|
|
|
def test_the_list_is_not_shown_without_its_users(self):
|
|
# it would offer to delete the secrets in use
|
|
with patch("virtsecrets.views.wvmSecrets") as conn:
|
|
conn.return_value.get_secrets_info.return_value = [{"uuid": CEPH, "usage_type": "ceph", "usage": "client.libvirt",
|
|
"ephemeral": False, "private": False}]
|
|
conn.return_value.get_users.side_effect = libvirt.libvirtError("connection reset")
|
|
response = self.client.get(self.url)
|
|
self.assertEqual(response.context["secrets_all"], [])
|