1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-12-01 16:36:06 +00:00

fix(instances): a new VM's existing volume or template is taken from the chosen pool

The create job looked volumes up by name in every active pool and took
the first match, so a volume of the same name in another pool could be
attached or copied in place of the chosen one. The form now sends each
existing volume as pool/volume and the template's pool, and the job
looks each up in its own pool.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kk4h2TcUiaWmU5MUszYSea
This commit is contained in:
catborise 2026-11-08 14:33:10 +03:00
parent d2383be914
commit 8f09812b7d
7 changed files with 41 additions and 22 deletions

View file

@ -45,6 +45,25 @@ class CreateInstanceViewTests(TestCase):
self.assertEqual(conn.create_instance.call_args.kwargs["volumes"][0]["bus"], "virtio")
self.assertTrue(Instance.objects.filter(name="new-vm").exists())
@patch("instances.views.wvmCreate", new=wvm_create)
@patch("instances.views.NewVMForm")
def test_a_volume_is_taken_from_its_own_pool(self, form_class):
# another pool may have a volume of the same name
_, conn = self.create(form_class)
run(Operation.objects.get())
conn.get_volume_path.assert_called_once_with("base.qcow2", "pool-b")
Operation.objects.all().delete()
Instance.objects.all().delete()
paths = {("base.qcow2", "pool-b"): "/pool-b/base.qcow2"} # the copy's name is free
conn.get_volume_path.side_effect = lambda name, pool: paths.get((name, pool))
try:
_, conn = self.create(form_class, images="", template="base.qcow2", template_pool="pool-b", storage="default")
run(Operation.objects.get())
finally:
conn.get_volume_path.side_effect = None
self.assertEqual(conn.clone_from_template.call_args.args[:3], ("new-vm", "/pool-b/base.qcow2", "default"))
@patch("instances.views.wvmCreate", new=wvm_create)
@patch("instances.views.NewVMForm")
def test_secure_boot_and_a_tpm_reach_the_definition(self, form_class):
@ -120,7 +139,7 @@ class CreateInstanceViewTests(TestCase):
form.is_valid.return_value = True
form.cleaned_data = {
"name": "new-vm", "meta_prealloc": False, "hdd_size": 0,
"template": "", "images": "base.qcow2", "cache_mode": "default",
"template": "", "template_pool": "", "images": "pool-b/base.qcow2", "cache_mode": "default",
"firmware": "BIOS", "net_model": "virtio", "memory": 1024,
"vcpu": 1, "vcpu_mode": "host-model", "networks": "default",
"virtio": True, "listener_addr": "0.0.0.0", "nwfilter": "",