Skip to content

Fix infrastructure leak in template from volume creation error message - #12650

Open
erikbocks wants to merge 4 commits into
apache:mainfrom
scclouds:changes-to-template-exception-message
Open

Fix infrastructure leak in template from volume creation error message#12650
erikbocks wants to merge 4 commits into
apache:mainfrom
scclouds:changes-to-template-exception-message

Conversation

@erikbocks

Copy link
Copy Markdown
Collaborator

Description

Currently, if an error occurs when trying to obtain a secondary storage for the creation of a template from a volume, or when uploading a volume, the message from the thrown exception exposes the zone's internal ID. Thus, the exception message was changed, and the descriptive message was moved to the logs.

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):

How Has This Been Tested?

In an environment with only one secondary storage, I set it as read-only. Then, I tried to create a template from a volume. An exception was thrown, informing that an error had occurred, but no infrastructure leak was present. I accessed the logs, and validated that the log with more information was shown, as well as the new exception message.

2026-02-16 13:01:37,560 ERROR [c.c.t.TemplateManagerImpl] (API-Job-Executor-11:[ctx-5f80938b, job-46, ctx-c87d05bc]) (logid:8879f16f) Cannot find an image store for zone [1].


2026-02-16 13:01:37,576 ERROR [c.c.a.ApiAsyncJobDispatcher] (API-Job-Executor-11:[ctx-5f80938b, job-46]) (logid:8879f16f) Unexpected exception while executing org.apache.cloudstack.api.command.admin.template.CreateTemplateCmdByAdmin com.cloud.utils.exception.CloudRuntimeException: Failed to create template. Please contact the cloud administrator.

@codecov

codecov Bot commented Feb 16, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 19.79%. Comparing base (9ae696d) to head (8fa607e).
⚠️ Report is 1152 commits behind head on main.

Files with missing lines Patch % Lines
...n/java/com/cloud/template/TemplateManagerImpl.java 0.00% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main   #12650      +/-   ##
============================================
+ Coverage     16.26%   19.79%   +3.53%     
- Complexity    13428    20019    +6591     
============================================
  Files          5660     6371     +711     
  Lines        499963   575958   +75995     
  Branches      60708    70521    +9813     
============================================
+ Hits          81330   114028   +32698     
- Misses       409559   449495   +39936     
- Partials       9074    12435    +3361     
Flag Coverage Δ
uitests 3.52% <ø> (-0.64%) ⬇️
unittests 21.07% <0.00%> (+3.95%) ⬆️

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

☔ View full report in Codecov by Harness.
📢 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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR updates error handling around selecting an image (secondary) datastore so that API-facing exceptions no longer expose internal zone IDs, moving the detailed context into server logs instead.

Changes:

  • Replace zone-ID-containing exception messages with a sanitized, user-facing CloudRuntimeException message.
  • Add error logging that retains the detailed context (zone ID) for operators.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread server/src/main/java/com/cloud/template/TemplateManagerImpl.java Outdated
Comment thread server/src/main/java/com/cloud/template/TemplateManagerImpl.java Outdated
Comment thread server/src/main/java/com/cloud/template/TemplateManagerImpl.java Outdated
@winterhazel

Copy link
Copy Markdown
Member

@erikbocks could you have a look at Copilot's reviews?

Comment thread server/src/main/java/com/cloud/template/TemplateManagerImpl.java Outdated
Co-authored-by: Suresh Kumar Anaparti <sureshkumar.anaparti@gmail.com>
@weizhouapache weizhouapache modified the milestones: 4.23.0, 4.22.2 Jun 30, 2026
@DaanHoogland DaanHoogland self-assigned this Aug 10, 2026
@DaanHoogland DaanHoogland moved this from Backlog to Ready in CloudStack Testing Aug 31, 2026
@DaanHoogland
DaanHoogland requested a lite review from Copilot September 7, 2026 07:18

@DaanHoogland DaanHoogland left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

clgtm, trivial change, smoke tests should do

@DaanHoogland

DaanHoogland commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

clgtm, trivial change, smoke tests should do

@winterhazel , can you concur?

@github-project-automation github-project-automation Bot moved this from Ready to Done in CloudStack Testing Sep 7, 2026
@DaanHoogland DaanHoogland reopened this Sep 7, 2026
@DaanHoogland

Copy link
Copy Markdown
Contributor

@blueorangutan package

@DaanHoogland DaanHoogland moved this from Done to In progress in CloudStack Testing Sep 7, 2026
@blueorangutan

Copy link
Copy Markdown

@DaanHoogland a [SL] Jenkins job has been kicked to build packages. It will be bundled with no SystemVM templates. I'll keep you posted as I make progress.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

The changes are small, localized, and align with the stated goal of preventing zone ID exposure in API error messages.

Review details
  • Files reviewed: 1/1 changed files
  • Comments generated: 1
  • Review effort level: Lite

Comment thread server/src/main/java/com/cloud/template/TemplateManagerImpl.java
@blueorangutan

Copy link
Copy Markdown

Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ el10 ✔️ debian ✔️ suse15. SL-JID 19118

@DaanHoogland DaanHoogland removed their assignment Sep 7, 2026
@DaanHoogland DaanHoogland moved this from In progress to In review in CloudStack Testing Sep 7, 2026
@DaanHoogland

Copy link
Copy Markdown
Contributor

@blueorangutan test

@blueorangutan

Copy link
Copy Markdown

@DaanHoogland a [SL] Trillian-Jenkins test job (ol8 mgmt + kvm-ol8) has been kicked to run smoke tests

@blueorangutan

Copy link
Copy Markdown

[SF] Trillian test result (tid-16914)
Environment: kvm-ol8 (x2), zone: Advanced Networking with Mgmt server ol8
Total time taken: 58011 seconds
Marvin logs: https://github.com/blueorangutan/acs-prs/releases/download/trillian/pr12650-t16914-kvm-ol8.zip
Smoke tests completed. 154 look OK, 2 have errors, 0 did not run
Only failed and skipped tests results shown below:

Test Result Time (s) Test File
ContextSuite context=TestAccounts>:setup Error 0.00 test_accounts.py
ContextSuite context=TestAddVmToSubDomain>:setup Error 0.00 test_accounts.py
test_DeleteDomain Error 8.28 test_accounts.py
test_forceDeleteDomain Failure 8.29 test_accounts.py
ContextSuite context=TestRemoveUserFromAccount>:setup Error 8.85 test_accounts.py
ContextSuite context=TestTemplateHierarchy>:setup Error 10.26 test_accounts.py
ContextSuite context=TestDeployVmWithAffinityGroup>:setup Error 0.00 test_affinity_groups_projects.py

@blueorangutan

Copy link
Copy Markdown

[SF] Trillian test result (tid-16926)
Environment: kvm-ol8 (x2), zone: Advanced Networking with Mgmt server ol8
Total time taken: 57634 seconds
Marvin logs: https://github.com/blueorangutan/acs-prs/releases/download/trillian/pr12650-t16926-kvm-ol8.zip
Smoke tests completed. 156 look OK, 0 have errors, 0 did not run
Only failed and skipped tests results shown below:

Test Result Time (s) Test File

@DaanHoogland

Copy link
Copy Markdown
Contributor

@erikbocks @winterhazel , what is the status/your view on this?

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings September 9, 2026 16:48

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 3 comments.

DataStore store = _dataStoreMgr.getImageStoreWithFreeCapacity(zoneId);
if (store == null) {
throw new CloudRuntimeException("cannot find an image store for zone " + zoneId);
throwExceptionForImageStoreObtentionFailure(zoneId, "create template");
Comment on lines +2483 to +2485
private void throwExceptionForImageStoreObtentionFailure(Long zoneId, String operation) {
logger.error("Cannot find an image store for zone [{}] while trying to {}.", zoneId, operation);
throw new CloudRuntimeException(String.format("Failed to %s. Please contact the cloud administrator.", operation));
return _tmpltDao.findById(template.getId());
}

private void throwExceptionForImageStoreObtentionFailure(Long zoneId, String operation) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: In review

Development

Successfully merging this pull request may close these issues.

8 participants