Skip to content

Fix/13612 template cleanup on domain delete#13614

Open
Chinmay048 wants to merge 2 commits into
apache:mainfrom
Chinmay048:fix/13612-template-cleanup-on-domain-delete
Open

Fix/13612 template cleanup on domain delete#13614
Chinmay048 wants to merge 2 commits into
apache:mainfrom
Chinmay048:fix/13612-template-cleanup-on-domain-delete

Conversation

@Chinmay048

Copy link
Copy Markdown
Contributor

Description

This PR fixes an issue where templates belonging to child accounts within a domain were not properly tracked during automated account and domain cleanup, causing domain deletion to fail due to orphaned storage resources.

Functional Changes:

  • Updated AccountManagerImpl.cleanupAccount to explicitly check the boolean return value of _tmpltMgr.delete(...).
  • Prevented the allTemplatesDeleted tracking flag from being overwritten on subsequent loop iterations if an earlier template deletion fails.
  • Ensured that any failed template deletion correctly sets accountCleanupNeeded = true, preventing premature domain teardowns when child resources remain active in secondary storage.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • I have read the CONTRIBUTING document.
  • My changes generate no new warnings or checkstyle errors.

Copilot AI review requested due to automatic review settings July 14, 2026 13:14
@boring-cyborg

boring-cyborg Bot commented Jul 14, 2026

Copy link
Copy Markdown

Congratulations on your first Pull Request and welcome to the Apache CloudStack community! If you have any issues or are unsure about any anything please check our Contribution Guide (https://github.com/apache/cloudstack/blob/main/CONTRIBUTING.md)
Here are some useful points:

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 addresses a cleanup edge case during account/domain teardown where template deletions that return false could be effectively “masked” by later successful deletions, leading to premature domain deletion attempts while template artifacts still remained in secondary storage.

Changes:

  • Update template cleanup loop in AccountManagerImpl.cleanupAccount to treat any false return from _tmpltMgr.delete(...) as a persistent failure signal (without being overwritten by later iterations).
  • Improve logging for the false return case and ensure exceptions also force allTemplatesDeleted = false.
  • Ensure accountCleanupNeeded is set when any template deletion fails, preventing premature teardown.

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

logger.debug("Successfully deleted snapshots directories for all volumes under account {} across all zones", account);
}


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.

Suggested change

if (template.getRemoved() == null) {
try {
allTemplatesDeleted = _tmpltMgr.delete(callerUserId, template.getId(), null);
// Fix 1: Prevent boolean overwriting by checking failure explicitly

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.

Suggested change
// Fix 1: Prevent boolean overwriting by checking failure explicitly
// Prevent boolean overwriting by checking failure explicitly

}
} catch (Exception e) {
logger.warn("Failed to delete template {} while removing account {} due to: ", template, account, e);
logger.warn("Failed to delete template {} while removing account {} due to exception: ", template, account, e);

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.

this is a bit unusual. the “due to” is generally thought to already imply an exception.

@codecov

codecov Bot commented Jul 20, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 19.49%. Comparing base (0e43c6a) to head (e7c4135).
⚠️ Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
...c/main/java/com/cloud/user/AccountManagerImpl.java 0.00% 4 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main   #13614      +/-   ##
============================================
- Coverage     19.50%   19.49%   -0.01%     
+ Complexity    19444    19435       -9     
============================================
  Files          6303     6303              
  Lines        569286   569288       +2     
  Branches      69791    69792       +1     
============================================
- Hits         111040   111010      -30     
- Misses       446093   446123      +30     
- Partials      12153    12155       +2     
Flag Coverage Δ
uitests 3.41% <ø> (ø)
unittests 20.77% <0.00%> (-0.01%) ⬇️

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.

@kiranchavala

Copy link
Copy Markdown
Member

@Chinmay048

Can we close the pr as @Damans227 has also created a pr to resolve the issue

cc @DaanHoogland

#13630

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.

4 participants