mirror of
https://github.com/retspen/webvirtcloud
synced 2026-12-01 16:36:06 +00:00
fix(instances): a volume already named as a new VM's disk refuses the create
A new disk or template copy whose name a volume of its pool already had made the job fail on it; recovery then took that volume for the job's own, ended the job uncertain and kept its claims, so no VM could be created on that compute until an admin resolved it. Recovery also took a volume of the same name in any other pool for the job's, and one in a stopped pool for nothing left. The form, the API and the worker now refuse a name a volume of the disk's pool already has, as they did for a template copy's .img only. Recovery looks in the job's own pools; one that is not running cannot be listed, so recovery waits for it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Kk4h2TcUiaWmU5MUszYSea
This commit is contained in:
parent
417be11616
commit
b7c5f98ba5
3 changed files with 62 additions and 20 deletions
|
|
@ -94,8 +94,8 @@ class CloudInitCreateTestCase(TransactionTestCase):
|
|||
missing = libvirt.libvirtError("no domain")
|
||||
missing.get_error_code = lambda: libvirt.VIR_ERR_NO_DOMAIN
|
||||
conn.return_value.wvm.lookupByUUIDString.side_effect = missing
|
||||
conn.return_value.wvm.listAllStoragePools.return_value = [
|
||||
SimpleNamespace(listVolumes=lambda: ["cidata-abababab-0000-1111-2222-333333333333.iso"])]
|
||||
conn.return_value.wvm.storagePoolLookupByName.return_value = SimpleNamespace(
|
||||
listVolumes=lambda: ["cidata-abababab-0000-1111-2222-333333333333.iso"])
|
||||
outcome = CreateInstance().reconcile(op)
|
||||
self.assertEqual(outcome.state, Operation.UNCERTAIN)
|
||||
self.assertIn("cidata-abababab-0000-1111-2222-333333333333.iso", words(outcome.error))
|
||||
|
|
|
|||
|
|
@ -126,12 +126,32 @@ class CreateJobTestCase(TransactionTestCase):
|
|||
missing = libvirt.libvirtError("no domain")
|
||||
missing.err = (libvirt.VIR_ERR_NO_DOMAIN, libvirt.VIR_FROM_QEMU, "no domain")
|
||||
conn.return_value.wvm.lookupByUUIDString.side_effect = missing
|
||||
pool = MagicMock()
|
||||
pool.listVolumes.return_value = ["other.qcow2"]
|
||||
conn.return_value.wvm.listAllStoragePools.return_value = [pool]
|
||||
pools = {"default": MagicMock(), "other": MagicMock()}
|
||||
conn.return_value.wvm.storagePoolLookupByName.side_effect = pools.get
|
||||
pools["default"].listVolumes.return_value = ["other.qcow2"]
|
||||
pools["other"].listVolumes.return_value = ["api-vm.qcow2"] # not the job's pool
|
||||
self.assertEqual(CreateInstance().reconcile(op).state, Operation.FAILED)
|
||||
pool.listVolumes.return_value = ["api-vm.qcow2"]
|
||||
pools["default"].listVolumes.return_value = ["api-vm.qcow2"]
|
||||
self.assertEqual(CreateInstance().reconcile(op).state, Operation.UNCERTAIN)
|
||||
# a pool that is not running may hold the disk: recovery waits for it
|
||||
pools["default"].listVolumes.side_effect = libvirt.libvirtError("storage pool 'default' is not active")
|
||||
with self.assertRaises(libvirt.libvirtError):
|
||||
CreateInstance().reconcile(op)
|
||||
|
||||
def test_a_volume_already_named_as_the_new_disk_is_refused(self):
|
||||
# else the job would fail on it and recovery take it for the job's own
|
||||
url = f"/api/v1/computes/{self.compute.pk}/instances/create/x86_64/q35/"
|
||||
self.conn.get_storage.return_value.listVolumes.return_value = ["api-vm.qcow2"]
|
||||
response = self.client.post(url, BODY, content_type="application/json")
|
||||
self.assertContains(response, "Image has already exist", status_code=400)
|
||||
self.assertFalse(Operation.objects.exists())
|
||||
self.conn.get_storage.assert_called_with("default")
|
||||
# one made after the job was queued
|
||||
self.conn.get_storage.return_value.listVolumes.return_value = []
|
||||
self.client.post(url, BODY, content_type="application/json")
|
||||
self.conn.get_storage.return_value.listVolumes.return_value = ["api-vm.img"]
|
||||
with self.assertRaisesMessage(libvirt.libvirtError, "Image has already exist"):
|
||||
CreateInstance().precheck(Operation.objects.get(), None)
|
||||
|
||||
def test_the_worker_checks_the_user_and_the_name_again(self):
|
||||
response = self.client.post(f"/api/v1/computes/{self.compute.pk}/instances/create/x86_64/q35/", BODY,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue