fix: list every project in template/image in-use refusal, not just the first

The usage scans broke out of the whole (project, node) iteration at the
first matching node, so deleting a template or image used by several
projects reported only one project name while the error message says
'one or more projects'. Keep scanning and list each project once.

Caught on a live server: an IOU L3 template used by two projects
(one of them closed) was refused citing only one of them.
This commit is contained in:
YueGuobin committed 2026-08-31 23:04:00 +08:00
1 parent 13548deae8
commit 823cf37287
2 files changed
+29 -6

No files matched your search

+27 -2
View File
@@ -575,11 +575,36 @@ async def test_find_projects_using_template_and_images(controller):
assert "base.qcow2" in referenced
assert "disk.qcow2" in referenced
# a second node from the same template in the same project must not
# list the project twice
await project1.add_node(
compute,
"n1-bis",
None,
node_type="vpcs",
template_id=template_id,
properties={},
)
assert controller.find_projects_using_template(template_id) == ["Test1"]
# a second project using the same template and image must be listed too
await project2.add_node(
compute,
"n2-bis",
None,
node_type="vpcs",
template_id=template_id,
properties={"hda_disk_image_backing_file": "base.qcow2"},
)
assert controller.find_projects_using_template(template_id) == ["Test1", "Test2"]
assert controller.find_projects_using_image("base.qcow2") == ["Test1", "Test2"]
assert controller.find_projects_using_image("disk.qcow2") == ["Test1"]
# closed projects: same answers from the .gns3 file on disk
await project1.close()
await project2.close()
assert controller.find_projects_using_template(template_id) == ["Test1"]
assert controller.find_projects_using_image("base.qcow2") == ["Test1"]
assert controller.find_projects_using_template(template_id) == ["Test1", "Test2"]
assert controller.find_projects_using_image("base.qcow2") == ["Test1", "Test2"]
assert controller.find_projects_using_image("disk.qcow2") == ["Test1"]