1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-12-03 17:36:05 +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:
catborise 2026-11-12 15:49:24 +03:00
parent 159049736d
commit b7724928fd
8 changed files with 104 additions and 49 deletions

View file

@ -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)