X Tutup
Skip to content

Fix duplicate dummy templates, and update guest os for dummy template#12780

Draft
sureshanaparti wants to merge 2 commits intoapache:4.22from
shapeblue:fix-duplicate-dummy-templates
Draft

Fix duplicate dummy templates, and update guest os for dummy template#12780
sureshanaparti wants to merge 2 commits intoapache:4.22from
shapeblue:fix-duplicate-dummy-templates

Conversation

@sureshanaparti
Copy link
Contributor

@sureshanaparti sureshanaparti commented Mar 10, 2026

Description

This PR fixes duplicate dummy templates, and updates guest os to "Other Linux (64-bit)", id: 99 for dummy template from existing "CentOS 4.5 (32-bit)", id: 1.

mysql> select id,type,format,guest_os_id from vm_template where name='kvm-default-vm-import-dummy-template';
+-----+--------+--------+-------------+
| id  | type   | format | guest_os_id |
+-----+--------+--------+-------------+
| 203 | SYSTEM | ISO    |           1 |
| 204 | SYSTEM | ISO    |           1 |
| 205 | SYSTEM | ISO    |           1 |
| 213 | SYSTEM | ISO    |           1 |
| 214 | SYSTEM | ISO    |           1 |
| 215 | SYSTEM | ISO    |           1 |
| 216 | SYSTEM | ISO    |           1 |
| 217 | SYSTEM | ISO    |           1 |
| 218 | SYSTEM | ISO    |           1 |
| 219 | SYSTEM | ISO    |           1 |
| 220 | SYSTEM | ISO    |           1 |
| 221 | SYSTEM | ISO    |           1 |
| 222 | SYSTEM | ISO    |           1 |
| 223 | SYSTEM | ISO    |           1 |
| 224 | SYSTEM | ISO    |           1 |
| 225 | SYSTEM | ISO    |           1 |
| 226 | SYSTEM | ISO    |           1 |
| 227 | SYSTEM | ISO    |           1 |
| 228 | SYSTEM | ISO    |           1 |
| 229 | SYSTEM | ISO    |           1 |
| 230 | SYSTEM | ISO    |           1 |
| 231 | SYSTEM | ISO    |           1 |
+-----+--------+--------+-------------+

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?

@sureshanaparti
Copy link
Contributor Author

@blueorangutan package

@blueorangutan
Copy link

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

@codecov
Copy link

codecov bot commented Mar 10, 2026

Codecov Report

❌ Patch coverage is 50.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 17.61%. Comparing base (7aa0558) to head (08cf2be).

Files with missing lines Patch % Lines
.../apache/cloudstack/vm/UnmanagedVMsManagerImpl.java 50.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               4.22   #12780      +/-   ##
============================================
- Coverage     17.61%   17.61%   -0.01%     
  Complexity    15664    15664              
============================================
  Files          5917     5917              
  Lines        531402   531405       +3     
  Branches      64971    64971              
============================================
- Hits          93596    93595       -1     
- Misses       427252   427255       +3     
- Partials      10554    10555       +1     
Flag Coverage Δ
uitests 3.70% <ø> (ø)
unittests 18.68% <50.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.

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

Stops creation of duplicate KVM VM-import dummy templates by selecting the correct template name per hypervisor, and updates the KVM dummy template’s guest OS to “Other Linux (64-bit)” (id 99).

Changes:

  • Use a KVM-specific dummy template name when importing on KVM to avoid repeatedly creating new templates.
  • Change the dummy template guest OS id from 1 to 99 in code.
  • Add a DB migration to update existing KVM dummy templates’ guest_os_id to 99.

Reviewed changes

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

File Description
server/src/main/java/org/apache/cloudstack/vm/UnmanagedVMsManagerImpl.java Uses KVM-specific template lookup/creation and updates dummy template guest OS to id 99.
engine/schema/src/main/resources/META-INF/db/schema-42200to42210.sql Migrates existing KVM dummy template rows to guest_os_id = 99.

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

You can also share your feedback on Copilot code review. Take the survey.

template = createDefaultDummyVmImportTemplate(Hypervisor.HypervisorType.KVM == hypervisorType);
template = createDefaultDummyVmImportTemplate(isKVMHypervisor);
if (template == null) {
throw new InvalidParameterValueException(String.format("Default VM import template with unique name: %s for hypervisor: %s cannot be created. Please use templateid parameter for import", VM_IMPORT_DEFAULT_TEMPLATE_NAME, hypervisorType.toString()));
Copy link

Copilot AI Mar 10, 2026

Choose a reason for hiding this comment

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

The exception message always formats the template name using VM_IMPORT_DEFAULT_TEMPLATE_NAME, even though the code now conditionally uses templateName (e.g., KVM_VM_IMPORT_DEFAULT_TEMPLATE_NAME for KVM). This will report the wrong template name for KVM and mislead operators. Use templateName in the formatted message (and you can pass hypervisorType directly instead of hypervisorType.toString()).

Suggested change
throw new InvalidParameterValueException(String.format("Default VM import template with unique name: %s for hypervisor: %s cannot be created. Please use templateid parameter for import", VM_IMPORT_DEFAULT_TEMPLATE_NAME, hypervisorType.toString()));
throw new InvalidParameterValueException(String.format("Default VM import template with unique name: %s for hypervisor: %s cannot be created. Please use templateid parameter for import", templateName, hypervisorType));

Copilot uses AI. Check for mistakes.
template = VMTemplateVO.createSystemIso(templateDao.getNextInSequence(Long.class, "id"), templateName, templateName, true,
"", true, 64, Account.ACCOUNT_ID_SYSTEM, "",
"VM Import Default Template", false, 1);
"VM Import Default Template", false, 99);
Copy link

Copilot AI Mar 10, 2026

Choose a reason for hiding this comment

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

The guest OS id 99 is a magic number here, which makes the intent harder to understand and couples behavior to a specific seeded DB id. Prefer using a named constant (e.g., OTHER_LINUX_64_GUEST_OS_ID) or resolving the guest OS id via a DAO lookup by a stable key/name, so this remains readable and robust across variations in guest OS seed data.

Copilot uses AI. Check for mistakes.
-- Update configuration 'kvm.ssh.to.agent' description and is_dynamic fields
UPDATE `cloud`.`configuration` SET description = 'True if the management server will restart the agent service via SSH into the KVM hosts after or during maintenance operations', is_dynamic = 1 WHERE name = 'kvm.ssh.to.agent';

UPDATE `cloud`.`vm_template` SET guest_os_id = 99 WHERE name = 'kvm-default-vm-import-dummy-template';
Copy link

Copilot AI Mar 10, 2026

Choose a reason for hiding this comment

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

This UPDATE targets rows by name only. To reduce the risk of unintentionally modifying non-system templates (or future templates) that happen to share the same name, consider narrowing the predicate (e.g., also filter on type = 'SYSTEM' and format = 'ISO' if that matches the intended rows).

Suggested change
UPDATE `cloud`.`vm_template` SET guest_os_id = 99 WHERE name = 'kvm-default-vm-import-dummy-template';
UPDATE `cloud`.`vm_template`
SET guest_os_id = 99
WHERE name = 'kvm-default-vm-import-dummy-template'
AND type = 'SYSTEM'
AND format = 'ISO';

Copilot uses AI. Check for mistakes.
-- Update configuration 'kvm.ssh.to.agent' description and is_dynamic fields
UPDATE `cloud`.`configuration` SET description = 'True if the management server will restart the agent service via SSH into the KVM hosts after or during maintenance operations', is_dynamic = 1 WHERE name = 'kvm.ssh.to.agent';

UPDATE `cloud`.`vm_template` SET guest_os_id = 99 WHERE name = 'kvm-default-vm-import-dummy-template';
Copy link

Copilot AI Mar 10, 2026

Choose a reason for hiding this comment

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

The PR description shows many duplicate rows for kvm-default-vm-import-dummy-template. This migration updates guest_os_id but does not address the existing duplicates, so the system can continue operating with ambiguous data (and findByName may pick an arbitrary row depending on query ordering). Consider adding a migration step to de-duplicate (e.g., keep a single canonical row and mark others removed/unused) to make behavior deterministic and align with the PR’s stated goal of fixing duplicates.

Suggested change
UPDATE `cloud`.`vm_template` SET guest_os_id = 99 WHERE name = 'kvm-default-vm-import-dummy-template';
-- De-duplicate 'kvm-default-vm-import-dummy-template' entries and update guest_os_id
-- Keep the template with the smallest id as the canonical one and mark others as removed
UPDATE `cloud`.`vm_template` t
JOIN (
SELECT MIN(id) AS keep_id
FROM `cloud`.`vm_template`
WHERE name = 'kvm-default-vm-import-dummy-template'
) k ON t.id != k.keep_id
SET t.removed = NOW()
WHERE t.name = 'kvm-default-vm-import-dummy-template'
AND t.removed IS NULL;
-- Update guest_os_id only for the canonical template
UPDATE `cloud`.`vm_template` t
JOIN (
SELECT MIN(id) AS keep_id
FROM `cloud`.`vm_template`
WHERE name = 'kvm-default-vm-import-dummy-template'
AND removed IS NULL
) k ON t.id = k.keep_id
SET t.guest_os_id = 99;

Copilot uses AI. Check for mistakes.
@blueorangutan
Copy link

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

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.

3 participants

X Tutup