mirror of
https://github.com/retspen/webvirtcloud
synced 2026-12-03 09:26:03 +00:00
fix(virtsecrets): a secret in use is not deleted by its UUID in capitals
libvirt finds a secret by its UUID in capitals too, but its users were looked up by the UUID as posted: a secret a VM's disk or a pool named was deleted, and that VM or pool no longer started. They are now looked up by the secret's own UUID. A usage with a control character made the page fail (lxml refuses it in XML text) and libvirt dropped a line break silently; the form refuses both. An empty value set later showed libvirt's "value in virSecretSetValue must not be NULL"; it is refused in words.
This commit is contained in:
parent
159049736d
commit
b7724928fd
8 changed files with 104 additions and 49 deletions
|
|
@ -76,6 +76,11 @@ class SecretValueTests(SimpleTestCase):
|
|||
self.set_value("ceph", value)
|
||||
self.assertNotIn(value, str(refused.exception))
|
||||
|
||||
def test_an_empty_value_is_refused_in_words(self):
|
||||
# libvirt says "value in virSecretSetValue must not be NULL"
|
||||
with self.assertRaisesRegex(OperationError, "Type the secret's value"):
|
||||
self.set_value("iscsi", "")
|
||||
|
||||
|
||||
ISCSI = "8f2c0000-0000-4000-8000-000000000002"
|
||||
|
||||
|
|
@ -177,10 +182,19 @@ class DeleteTests(SimpleTestCase):
|
|||
def test_a_secret_a_vm_or_a_pool_names_is_not_deleted(self):
|
||||
conn = connection(domains=[vm("db-2", f"<disk><auth><secret type='ceph' uuid='{CEPH}'/></auth></disk>")],
|
||||
pools=[pool("ceph-rbd", "<auth type='ceph'><secret usage='client.libvirt'/></auth>")])
|
||||
conn.wvm.secretLookupByUUIDString.return_value.UUIDString.return_value = CEPH
|
||||
with self.assertRaisesRegex(OperationError, f"Secret {CEPH} is used by VMs db-2; pools ceph-rbd"):
|
||||
conn.delete_secret(CEPH)
|
||||
conn.wvm.secretLookupByUUIDString.return_value.undefine.assert_not_called()
|
||||
|
||||
def test_a_secret_in_use_named_in_capitals_is_not_deleted(self):
|
||||
# libvirt finds it by the UUID in capitals, its users name it in small letters
|
||||
conn = connection(domains=[vm("db-2", f"<disk><auth><secret type='ceph' uuid='{CEPH}'/></auth></disk>")])
|
||||
conn.wvm.secretLookupByUUIDString.return_value.UUIDString.return_value = CEPH
|
||||
with self.assertRaisesRegex(OperationError, "is used by VMs db-2"):
|
||||
conn.delete_secret(CEPH.upper())
|
||||
conn.wvm.secretLookupByUUIDString.return_value.undefine.assert_not_called()
|
||||
|
||||
def test_an_unused_secret_is_deleted(self):
|
||||
conn = connection(domains=[vm("web-1", f"<disk><auth><secret type='ceph' uuid='{CEPH}'/></auth></disk>")])
|
||||
conn.delete_secret(ISCSI)
|
||||
|
|
|
|||
|
|
@ -101,6 +101,8 @@ class wvmSecrets(wvmConnect):
|
|||
def set_secret_value(self, uuid, value):
|
||||
"""value as typed on the page; its bytes follow the secret's usage
|
||||
type (value_bytes)."""
|
||||
if not value: # libvirt takes none
|
||||
raise util.OperationError(gettext_noop("Type the secret's value"))
|
||||
secret = self.wvm.secretLookupByUUIDString(uuid)
|
||||
usage_type = etree.fromstring(secret.XMLDesc(0)).xpath("string(usage/@type)")
|
||||
secret.setValue(value_bytes(usage_type, value))
|
||||
|
|
@ -109,6 +111,7 @@ class wvmSecrets(wvmConnect):
|
|||
"""Refused while a VM or a pool names it (get_users): without it that
|
||||
VM or pool would no longer start."""
|
||||
secret = self.wvm.secretLookupByUUIDString(uuid)
|
||||
uuid = secret.UUIDString() # as its users name it: libvirt takes it in capitals too
|
||||
if users := self.get_users(self.get_secrets_info()).get(uuid):
|
||||
named = []
|
||||
if users["vms"]:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue