Skip to content

Conversation

@erikbocks
Copy link
Collaborator

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 RootAdmin accounts and for the others users, the message only states that the template is being used by VMs.

Types of changes

  • Breaking change (fix or feature that would cause existing functionality to change)
  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Enhancement (improves an existing feature and functionality)
  • Cleanup (Code refactoring and cleanup, that may add test cases)
  • Build/CI
  • Test (unit or integration test code)

Feature/Enhancement Scale or Bug Severity

Feature/Enhancement Scale

  • Major
  • Minor

Screenshots (if appropriate):

Exception message for User type accounts image
Exception message for Root Admin type accounts image

How Has This Been Tested?

First, two User type accounts were created: templateAcc and instanceAcc. The templateAcc account was accessed and a public template was registered. After that, the instanceAcc was accessed and a VM was deployed using the template registered by templateAcc.

Logged in as templateAcc again, 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 a Root Admin account, 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
2025-12-17 12:58:08,815 [management] WARN  [c.c.t.TemplateManagerImpl:1360] (API-Job-Executor-1:[ctx-106b8b79, job-448, ctx-e8ca5865]) (logid:c41a7e6a) Unable to delete template with ID 210, because there are VM instances using it. Instances list: [VM instance {"id":33,"instanceName":"i-13-33-VM","type":"User","uuid":"a15065e6-5422-4eca-ae8a-e4f0d8887a99"}].

@codecov
Copy link

codecov bot commented Jan 5, 2026

Codecov Report

❌ Patch coverage is 60.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 17.76%. Comparing base (4628385) to head (2862b36).

Files with missing lines Patch % Lines
...n/java/com/cloud/template/TemplateManagerImpl.java 60.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##               main   #12373   +/-   ##
=========================================
  Coverage     17.76%   17.76%           
- Complexity    15861    15862    +1     
=========================================
  Files          5923     5923           
  Lines        530470   530473    +3     
  Branches      64823    64824    +1     
=========================================
+ Hits          94253    94255    +2     
  Misses       425673   425673           
- Partials      10544    10545    +1     
Flag Coverage Δ
uitests 3.57% <ø> (ø)
unittests 18.85% <60.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

if(!cmd.isForced() && CollectionUtils.isNotEmpty(vmInstanceVOList)) {
final String message = String.format("Unable to delete Template: %s because Instance: [%s] are using it.", template, Joiner.on(",").join(vmInstanceVOList));
logger.warn(message);
String message = String.format("Unable to delete template with ID %s, because there are VM instances using it.", templateId);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO, it would be better to log the template instead of templateId.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants