Changes to the error message displayed during the removal of public templates that are used#12373
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## 4.20 #12373 +/- ##
============================================
- Coverage 16.26% 16.25% -0.02%
+ Complexity 13428 13418 -10
============================================
Files 5660 5662 +2
Lines 499959 500164 +205
Branches 60707 60731 +24
============================================
- Hits 81326 81279 -47
- Misses 409560 409801 +241
- Partials 9073 9084 +11
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
server/src/main/java/com/cloud/template/TemplateManagerImpl.java
Outdated
Show resolved
Hide resolved
|
@erikbocks could you target 4.20 as this is a simple enhancement? |
…emplates that are used
b50eca4 to
73a254a
Compare
|
This pull request has merge conflicts. Dear author, please fix the conflicts and sync your branch with the base branch. |
73a254a to
f9e815e
Compare
|
@blueorangutan package |
|
@sureshanaparti a [SL] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress. |
|
Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ el10 ✔️ debian ✔️ suse15. SL-JID 16840 |
|
@blueorangutan test |
|
@sureshanaparti a [SL] Trillian-Jenkins test job (ol8 mgmt + kvm-ol8) has been kicked to run smoke tests |
server/src/main/java/com/cloud/template/TemplateManagerImpl.java
Outdated
Show resolved
Hide resolved
server/src/main/java/com/cloud/template/TemplateManagerImpl.java
Outdated
Show resolved
Hide resolved
Co-authored-by: Suresh Kumar Anaparti <sureshkumar.anaparti@gmail.com>
|
@blueorangutan package |
|
@DaanHoogland a [SL] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress. |
There was a problem hiding this comment.
Pull request overview
This PR updates the exception message thrown when deleting a template that is still in use by VM instances, limiting the VM instance list exposure to RootAdmin callers while keeping detailed information in management server logs.
Changes:
- Replace the previous error message that always included the full VM instance list with a generic message for non-RootAdmin users.
- Append the VM instances list to the thrown exception only when the caller is a
RootAdmin. - Remove the Guava
Joinerusage/import and build the instances list string usingStringUtils.join.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ el10 ✔️ debian ✔️ suse15. SL-JID 16873 |
RosiKyu
left a comment
There was a problem hiding this comment.
LGTM
Tested the error message differentiation between regular User and RootAdmin accounts via both CLI and UI; the VM instances list is correctly hidden from non-admin users and always present in management server logs.
| # | Test Case | Method | Status |
|---|---|---|---|
| TC1 | Regular user deletes public template in use — error shows VM count only, no VM list | CLI + UI | PASS |
| TC2 | RootAdmin deletes public template in use — error shows VM count + full VM instances list | CLI + UI | PASS |
| TC3 | Management server logs always contain full VM instances list regardless of caller | CLI (log grep) | PASS |
Result: 3/3 PASS
TC1: Regular user deletes public template in use: generic error without VM list
Objective
Verify that a non-RootAdmin user attempting to delete a public template that is in use by VMs belonging to another account receives an error message with only the VM count, without exposing the list of VM instances.
Test Steps
- As RootAdmin, create two User accounts:
templateaccandinstanceacc - Register a public template (
pr12373-public-tmpl) owned bytemplateacc - Deploy a VM (
pr12373-test-vm) using that template underinstanceacc - Register API keys for
templateaccand configure a cmk profile - As
templateacc, attempt to delete the template:delete template id=b84d638a-42fe-4da5-8de2-ae2f1f7f9de1
Expected Result:
The delete operation should fail with an error message stating the template is in use by N VM instances, without listing the actual VM instance details.
Actual Result:
The delete operation failed with error code 431 and the message:
"Unable to delete template [Template {...}] because there are [1] VM instances using it."
The VM instances list was not included in the error message.
Test Evidence:
(templateacc) 🐱 > delete template id=b84d638a-42fe-4da5-8de2-ae2f1f7f9de1
{
"jobresult": {
"errorcode": 431,
"errortext": "Unable to delete template [Template {\"format\":\"QCOW2\",\"id\":202,\"name\":\"pr12373-public-tmpl\",\"uniqueName\":\"202-5-d5dcffa6-38d4-3d3b-bf67-ec85ca2f1008\",\"uuid\":\"b84d638a-42fe-4da5-8de2-ae2f1f7f9de1\"}] because there are [1] VM instances using it."
},
"jobresultcode": 431,
"jobstatus": 2
}
TC2: RootAdmin deletes public template in use - detailed error with VM list
Objective
Verify that a RootAdmin user attempting to delete a public template that is in use by VMs receives an error message that includes both the VM count AND the full list of VM instances using the template.
Test Steps
- Using the same setup from TC1 (template
pr12373-public-tmplowned bytemplateacc, VMpr12373-test-vmdeployed underinstanceacc) - Switch to RootAdmin cmk profile:
set profile localcloud - As RootAdmin, attempt to delete the template:
delete template id=b84d638a-42fe-4da5-8de2-ae2f1f7f9de1
Expected Result:
The delete operation should fail with an error message stating the template is in use, including the full list of VM instances (id, instanceName, state, type, uuid).
Actual Result:
The delete operation failed with error code 431 and the message:
"Unable to delete template [...] because there are [1] VM instances using it. Instances list: [VM instance {"id":3,"instanceName":"i-6-3-VM","state":"Running","type":"User","uuid":"e5a80723-59a2-48cf-9e52-6dc008472056"}]."
The VM instances list was included in the error message for RootAdmin.
Test Evidence:
(localcloud) 🐱 > delete template id=b84d638a-42fe-4da5-8de2-ae2f1f7f9de1
{
"jobresult": {
"errorcode": 431,
"errortext": "Unable to delete template [Template {\"format\":\"QCOW2\",\"id\":202,\"name\":\"pr12373-public-tmpl\",\"uniqueName\":\"202-5-d5dcffa6-38d4-3d3b-bf67-ec85ca2f1008\",\"uuid\":\"b84d638a-42fe-4da5-8de2-ae2f1f7f9de1\"}] because there are [1] VM instances using it. Instances list: [VM instance {\"id\":3,\"instanceName\":\"i-6-3-VM\",\"state\":\"Running\",\"type\":\"User\",\"uuid\":\"e5a80723-59a2-48cf-9e52-6dc008472056\"}]."
},
"jobresultcode": 431,
"jobstatus": 2
}
UI test
TC3: Management server logs always contain full VM instances list
Objective
Verify that the management server logs always record the complete VM instances list in the WARN message, regardless of whether the caller is a regular User or a RootAdmin.
Test Steps
- Using the same setup from TC1/TC2
- On the management server, run:
grep "Unable to delete template" /var/log/cloudstack/management/management-server.log - Verify that all WARN entries include the full Instances list
Expected Result:
All WARN log entries should contain the full Instances list: [...] with VM details, regardless of the caller's account type. The API response (DEBUG lines) should differ: no Instances list for regular users, full list for RootAdmin.
Actual Result:
All 5 WARN entries (from both templateAcc and admin attempts via CLI and UI) contain the full Instances list: Instances list: [VM instance {"id":3,"instanceName":"i-6-3-VM","state":"Running","type":"User","uuid":"e5a80723-59a2-48cf-9e52-6dc008472056"}].
Additionally, the DEBUG lines confirm the API response behavior:
- templateAcc (job-38): errortext ends with
"...VM instances using it."- NO Instances list - admin (job-41): errortext ends with
"...Instances list: [...]."- WITH Instances list
Test Evidence:
# templateAcc attempt (job-38) - WARN has full list, API response does not:
2026-02-23 09:32:14,844 WARN [c.c.t.TemplateManagerImpl] (API-Job-Executor-30:[ctx-78d721b9, job-38, ctx-1e1e02a4]) (logid:695f59a2) Unable to delete template [...] because there are [1] VM instances using it. Instances list: [VM instance {"id":3,"instanceName":"i-6-3-VM","state":"Running","type":"User","uuid":"e5a80723-59a2-48cf-9e52-6dc008472056"}].
2026-02-23 09:32:14,852 DEBUG [o.a.c.f.j.i.AsyncJobManagerImpl] (API-Job-Executor-30:[ctx-78d721b9, job-38]) (logid:695f59a2) Complete async job-38, jobStatus: FAILED, resultCode: 431, result: ...errortext":"Unable to delete template [...] because there are [1] VM instances using it."}
# admin attempt (job-41) - WARN has full list, API response also has it:
2026-02-23 09:34:48,143 WARN [c.c.t.TemplateManagerImpl] (API-Job-Executor-33:[ctx-b3a256cf, job-41, ctx-bbf0c04f]) (logid:dff3d2f7) Unable to delete template [...] because there are [1] VM instances using it. Instances list: [VM instance {"id":3,"instanceName":"i-6-3-VM","state":"Running","type":"User","uuid":"e5a80723-59a2-48cf-9e52-6dc008472056"}].
2026-02-23 09:34:48,147 DEBUG [o.a.c.f.j.i.AsyncJobManagerImpl] (API-Job-Executor-33:[ctx-b3a256cf, job-41]) (logid:dff3d2f7) Complete async job-41, jobStatus: FAILED, resultCode: 431, result: ...errortext":"Unable to delete template [...] because there are [1] VM instances using it. Instances list: [VM instance {"id":3,"instanceName":"i-6-3-VM","state":"Running","type":"User","uuid":"e5a80723-59a2-48cf-9e52-6dc008472056"}]."}

Description
During the removal of public templates, if it is being used by VMs, an error message is displayed informing that the removal could not proceed because it is being used by VMs, and the list of VMs using it is returned. However, sometimes the user that is trying to remove the template does not have access to these resources. Thus, the error message was changed, in order to return the list of VMs only to users with
RootAdminaccounts and for the others users, the message only states that the template is being used by VMs.Types of changes
Feature/Enhancement Scale or Bug Severity
Feature/Enhancement Scale
Screenshots (if appropriate):
Exception message for
Usertype accountsException message for
Root Admintype accountsHow Has This Been Tested?
First, two
Usertype accounts were created:templateAccandinstanceAcc. ThetemplateAccaccount was accessed and a public template was registered. After that, theinstanceAccwas accessed and a VM was deployed using the template registered bytemplateAcc.Logged in as
templateAccagain, I tried to remove the registered template, and it was possible to validate that the error message was displayed without the VMs list. By logging in with aRoot Adminaccount, it was possible to validate that the error message contained the VMs lists. Through the Management Server's logs it was also possible to validate that the log message displayed the VMs list:Updated log message