diff --git a/nwfilters/tests/test_filters.py b/nwfilters/tests/test_filters.py index 476d06a9..84bea436 100644 --- a/nwfilters/tests/test_filters.py +++ b/nwfilters/tests/test_filters.py @@ -27,7 +27,7 @@ def nwfilter(name, xml, uuid=UUID): def vm(name, xml, saved=None, active=False, persistent=True): def describe(flags=0): - return saved if flags else xml + return (saved or xml) if flags else xml return MagicMock(**{"name.return_value": name, "XMLDesc.side_effect": describe, "isActive.return_value": active, "isPersistent.return_value": persistent}) @@ -70,7 +70,7 @@ class UsersTests(SimpleTestCase): ]) self.assertEqual(conn.get_users(), {"a": ["stopped"], "b": ["running"], "c": ["running"], "d": ["transient"]}) stopped, running, transient = conn.wvm.listAllDomains.return_value - self.assertEqual((stopped.XMLDesc.call_count, running.XMLDesc.call_count, transient.XMLDesc.call_count), (1, 2, 1)) + self.assertEqual((stopped.XMLDesc.call_count, running.XMLDesc.call_count, transient.XMLDesc.call_count), (2, 2, 1)) def test_a_vm_gone_meanwhile_uses_nothing_other_errors_are_raised(self): gone = vm("gone", "") diff --git a/storages/tests/test_audit_rows.py b/storages/tests/test_audit_rows.py index 1163af15..a30914b7 100644 --- a/storages/tests/test_audit_rows.py +++ b/storages/tests/test_audit_rows.py @@ -127,7 +127,7 @@ class PoolAndVolumeRowTests(TransactionTestCase): conn.get_size.return_value = (1, 1) conn.get_storages_info.return_value = [] conn.get_storages.return_value = ["default"] - conn.get_secrets.return_value = [] + conn.get_secrets_info.return_value = [] conn.update_volumes.return_value = [] conn.create_volume.return_value = "disk1.qcow2" setattr(self, name, conn) diff --git a/storages/tests/test_new_pool.py b/storages/tests/test_new_pool.py index 3634f319..b28262fb 100644 --- a/storages/tests/test_new_pool.py +++ b/storages/tests/test_new_pool.py @@ -2,13 +2,13 @@ path another one has, an RBD pool only a Ceph secret of the host; a refused pool opens the dialog again with what was entered and why.""" -from unittest.mock import MagicMock, patch +from unittest.mock import patch 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 libvirt import VIR_SECRET_USAGE_TYPE_CEPH, VIR_SECRET_USAGE_TYPE_VOLUME, libvirtError +from libvirt import libvirtError from lxml import html from storages.forms import AddStgPool @@ -63,11 +63,10 @@ class DialogTests(TestCase): self.addCleanup(patcher.stop) pools = [{**pool, "status": 1, "autostart": 1, "volumes": 0, "size": 1, "free": 1, "used_percent": 0} for pool in POOLS] self.conn.get_storages_info.return_value = pools - secrets = {SECRET: (VIR_SECRET_USAGE_TYPE_CEPH, "client.libvirt"), - "00000000-0000-0000-0000-000000000003": (VIR_SECRET_USAGE_TYPE_VOLUME, "/var/lib/libvirt/images/a.img")} - self.conn.get_secrets.return_value = list(secrets) - self.conn.get_secret.side_effect = lambda uuid: MagicMock(**{"usageType.return_value": secrets[uuid][0], - "usageID.return_value": secrets[uuid][1]}) + self.conn.get_secrets_info.return_value = [ + {"uuid": SECRET, "usage_type": "ceph", "usage": "client.libvirt"}, + {"uuid": "00000000-0000-0000-0000-000000000003", "usage_type": "volume", "usage": "/var/lib/libvirt/images/a.img"}, + ] self.url = reverse("storages", args=[self.compute.pk]) def page(self, response): diff --git a/storages/tests/test_pool_page.py b/storages/tests/test_pool_page.py index fb623785..23e61556 100644 --- a/storages/tests/test_pool_page.py +++ b/storages/tests/test_pool_page.py @@ -139,7 +139,7 @@ class PoolListTests(TestCase): ] with patch("storages.views.wvmStorages") as storages: storages.return_value.get_storages_info.return_value = pools - storages.return_value.get_secrets.return_value = [] + storages.return_value.get_secrets_info.return_value = [] page = html.fromstring(self.client.get(reverse("storages", args=[compute.pk])).content) cards = [" ".join(" ".join(card.itertext()).split()) for card in page.xpath("//div[@class='card h-100']")] self.assertEqual(cards, [ diff --git a/storages/views.py b/storages/views.py index 0eb657a9..eef84bbf 100644 --- a/storages/views.py +++ b/storages/views.py @@ -10,7 +10,7 @@ from django.http import HttpResponseRedirect, JsonResponse from django.shortcuts import get_object_or_404, redirect, render from django.urls import reverse from django.utils.translation import gettext_lazy as _ -from libvirt import VIR_SECRET_USAGE_TYPE_CEPH, libvirtError +from libvirt import libvirtError from operations import claims, jobs from operations.utils import busy_message from logs.audit import audit, failed @@ -79,11 +79,7 @@ def storages(request, compute_id): storages = conn.get_storages_info() iso_pool = next((pool for pool in storages if pool["name"] == "iso"), None) # the secrets an RBD pool can use, by the name they were given - ceph_secrets = [] - for uuid in conn.get_secrets(): - secret = conn.get_secret(uuid) - if secret.usageType() == VIR_SECRET_USAGE_TYPE_CEPH: - ceph_secrets.append({"uuid": uuid, "usage": secret.usageID()}) + ceph_secrets = [secret for secret in conn.get_secrets_info() if secret["usage_type"] == "ceph"] if request.method == "POST" and "create" in request.POST: form = AddStgPool(request.POST, pools=storages, ceph_secrets=[s["uuid"] for s in ceph_secrets]) diff --git a/virtsecrets/forms.py b/virtsecrets/forms.py index 232973ad..be266ef5 100644 --- a/virtsecrets/forms.py +++ b/virtsecrets/forms.py @@ -1,11 +1,13 @@ from django import forms +from django.utils.translation import gettext_lazy as _ class AddSecret(forms.Form): - ephemeral = forms.ChoiceField(required=True, choices=(("no", "no"), ("yes", "yes"))) - private = forms.ChoiceField(required=True, choices=(("no", "no"), ("yes", "yes"))) usage_type = forms.ChoiceField( - required=True, - choices=(("ceph", "ceph"), ("volume", "volume"), ("iscsi", "iscsi")), + choices=(("ceph", "Ceph"), ("iscsi", "iSCSI"), ("volume", _("Volume")), ("tls", "TLS"), ("vtpm", "vTPM")), ) - data = forms.CharField(max_length=100, required=True) + usage = forms.CharField() + # a password keeps its spaces; none defines the secret without a value + value = forms.CharField(required=False, strip=False) + ephemeral = forms.BooleanField(required=False) + private = forms.BooleanField(required=False) diff --git a/virtsecrets/templates/create_secret_block.html b/virtsecrets/templates/create_secret_block.html index 9ab34929..26e33296 100644 --- a/virtsecrets/templates/create_secret_block.html +++ b/virtsecrets/templates/create_secret_block.html @@ -15,24 +15,6 @@