Skip to content

server: set template type to ROUTING or USER if template type is not specified when upload a template#12768

Draft
weizhouapache wants to merge 5 commits intoapache:4.22from
weizhouapache:4.22-fix-template-type-upload-template
Draft

server: set template type to ROUTING or USER if template type is not specified when upload a template#12768
weizhouapache wants to merge 5 commits intoapache:4.22from
weizhouapache:4.22-fix-template-type-upload-template

Conversation

@weizhouapache
Copy link
Member

Description

This PR fixes #12763

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

Bug Severity

  • BLOCKER
  • Critical
  • Major
  • Minor
  • Trivial

Screenshots (if appropriate):

How Has This Been Tested?

How did you try to break this feature and the system with this change?

@weizhouapache
Copy link
Member Author

@DaanHoogland @vishesh92 @vladimirpetrov
do you think we should set the template type to USER in the upgrade sql ?

UPDATE `cloud`.`vm_template` SET `type` = "USER" WHERE `type` IS NULL;

@weizhouapache weizhouapache force-pushed the 4.22-fix-template-type-upload-template branch from e6d952c to 9dd0695 Compare March 9, 2026 11:25
@weizhouapache
Copy link
Member Author

@blueorangutan package

@blueorangutan
Copy link

@weizhouapache 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.

@DaanHoogland
Copy link
Contributor

@DaanHoogland @vishesh92 @vladimirpetrov
do you think we should set the template type to USER in the upgrade sql ?

UPDATE `cloud`.`vm_template` SET `type` = "USER" WHERE `type` IS NULL;

Sounds good, is type null leading to NPEs?

@codecov
Copy link

codecov bot commented Mar 9, 2026

Codecov Report

❌ Patch coverage is 0% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 17.61%. Comparing base (c3d6a8c) to head (e01730a).
⚠️ Report is 2 commits behind head on 4.22.

Files with missing lines Patch % Lines
...n/java/com/cloud/template/TemplateManagerImpl.java 0.00% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               4.22   #12768      +/-   ##
============================================
- Coverage     17.61%   17.61%   -0.01%     
- Complexity    15661    15662       +1     
============================================
  Files          5917     5917              
  Lines        531402   531404       +2     
  Branches      64971    64972       +1     
============================================
- Hits          93586    93585       -1     
- Misses       427262   427264       +2     
- Partials      10554    10555       +1     
Flag Coverage Δ
uitests 3.70% <ø> (ø)
unittests 18.68% <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 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.

@weizhouapache
Copy link
Member Author

@DaanHoogland @vishesh92 @vladimirpetrov
do you think we should set the template type to USER in the upgrade sql ?

UPDATE `cloud`.`vm_template` SET `type` = "USER" WHERE `type` IS NULL;

Sounds good, is type null leading to NPEs?

I think it does not lead to NPEs, but template/iso are not usable as the type is NULL.
In several places (UI and source code), cloudstack only lists templates with USER template type.

@blueorangutan
Copy link

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

@vishesh92 vishesh92 requested a review from Copilot March 9, 2026 12:40
Copy link
Member

@vishesh92 vishesh92 left a comment

Choose a reason for hiding this comment

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

clgtm. didn't test.

@vishesh92
Copy link
Member

@blueorangutan package

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates template upload/registration validation to default the template type to ROUTING or USER when not explicitly provided, and aligns existing DB records by backfilling vm_template.type when it is NULL.

Changes:

  • Extend template-type defaulting logic to GetUploadParamsForTemplateCmd.
  • Add permission validation/error for non-admin users requesting upload params for non-USER template types.
  • Backfill cloud.vm_template.type to USER where it is currently NULL.

Reviewed changes

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

File Description
server/src/main/java/com/cloud/template/TemplateManagerImpl.java Default template type for upload-params requests and restrict non-admin usage for non-USER types.
engine/schema/src/main/resources/META-INF/db/schema-42200to42210.sql Data migration to set vm_template.type to USER for existing NULL rows.

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

weizhouapache and others added 2 commits March 9, 2026 13:48
…10.sql

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@weizhouapache
Copy link
Member Author

@blueoranguran package

1 similar comment
@weizhouapache
Copy link
Member Author

@blueoranguran package

@blueorangutan
Copy link

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

@weizhouapache
Copy link
Member Author

@blueorangutan test

@blueorangutan
Copy link

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

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.

Locally uploaded template is not shown in the deploy instance dialog

5 participants