Skip to content

server: copy template details to vm instance details when import VM - #12793

Merged
weizhouapache merged 4 commits into
apache:4.22from
weizhouapache:4.22-import-vm-copy-template-details
Sep 14, 2026
Merged

weizhouapache merged 4 commits into
apache:4.22from
weizhouapache:4.22-import-vm-copy-template-details

Conversation

@weizhouapache

@weizhouapache weizhouapache commented Mar 11, 2026

Copy link
Copy Markdown
Member

Description

This PR fixes #12594

Tested

  • Unmanage a VM on KVM
  • Import it with the vm template with setting guest.cpu.mode=host-passthrough
image

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
Copy Markdown
Member Author

@blueorangutan package

@blueorangutan

Copy link
Copy Markdown

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

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 aims to fix VM import so that a template’s details are loaded and then copied into the imported VM’s instance details.

Changes:

  • Fetches the template VO from the DAO and explicitly loads its details prior to commitUserVm.
  • Switches downstream calls (checkIfDynamicScalingCanBeEnabled, commitUserVm, ISO format check) to use the DAO-loaded VMTemplateVO.

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

Comment thread server/src/main/java/com/cloud/vm/UserVmManagerImpl.java
Comment thread server/src/main/java/com/cloud/vm/UserVmManagerImpl.java Outdated
@codecov

codecov Bot commented Mar 11, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 17.91%. Comparing base (c467686) to head (f560307).
⚠️ Report is 20 commits behind head on 4.22.

Files with missing lines Patch % Lines
.../src/main/java/com/cloud/vm/UserVmManagerImpl.java 0.00% 8 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##               4.22   #12793   +/-   ##
=========================================
  Coverage     17.91%   17.91%           
  Complexity    16113    16113           
=========================================
  Files          5928     5928           
  Lines        535057   535063    +6     
  Branches      65480    65482    +2     
=========================================
+ Hits          95879    95882    +3     
- Misses       428269   428274    +5     
+ Partials      10909    10907    -2     
Flag Coverage Δ
uitests 4.02% <ø> (ø)
unittests 18.98% <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.

@blueorangutan

Copy link
Copy Markdown

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

@weizhouapache

Copy link
Copy Markdown
Member Author

@blueorangutan test

@blueorangutan

Copy link
Copy Markdown

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

@blueorangutan

blueorangutan commented Mar 12, 2026

Copy link
Copy Markdown

[SF] Trillian test result (tid-15611)
Environment: kvm-ol8 (x2), zone: Advanced Networking with Mgmt server ol8
Total time taken: 50536 seconds
Marvin logs: [archive could not be removed: not found]
Smoke tests completed. 144 look OK, 5 have errors, 0 did not run
Only failed and skipped tests results shown below:

Test Result Time (s) Test File
ContextSuite context=TestListIdsParams>:teardown Error 1.16 test_list_ids_parameter.py
test_01_primary_storage_nfs Error 0.16 test_primary_storage.py
ContextSuite context=TestStorageTags>:setup Error 0.26 test_primary_storage.py
test_01_primary_storage_scope_change Error 0.11 test_primary_storage_scope.py
test_01_snapshot_root_disk Error 5.84 test_snapshots.py
test_02_list_snapshots_with_removed_data_store Error 46.63 test_snapshots.py
test_02_list_snapshots_with_removed_data_store Error 46.63 test_snapshots.py
ContextSuite context=TestSnapshotStandaloneBackup>:teardown Error 28.38 test_snapshots.py
test_01_snapshot_usage Error 25.66 test_usage.py
test_01_vpn_usage Error 1.11 test_usage.py

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

@weizhouapache
weizhouapache marked this pull request as ready for review March 12, 2026 10:37

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

@github-actions

Copy link
Copy Markdown

This pull request has merge conflicts. Dear author, please fix the conflicts and sync your branch with the base branch.

@sureshanaparti

Copy link
Copy Markdown
Contributor

@weizhouapache can you resolve the conflicts.

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

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

Comment on lines +9515 to +9520
// Ensure template details are loaded so that commitUserVm can copy them into the VM's details map
VMTemplateVO vmTemplateVO = _templateDao.findById(template.getId());
if (vmTemplateVO == null) {
throw new InvalidParameterValueException("Unable to find template with id " + template.getId() + " for virtual machine import");
}
_templateDao.loadDetails(vmTemplateVO);
final Boolean dynamicScalingEnabled = checkIfDynamicScalingCanBeEnabled(null, serviceOffering, vmTemplateVO, zone.getId());
return commitUserVm(true, zone, host, lastHost, vmTemplateVO, hostName, displayName, owner,
null, null, userData, null, null, isDisplayVm, keyboard,
accountId, userId, serviceOffering, template.getFormat().equals(ImageFormat.ISO), sshPublicKeys, networkNicMap,
@github-actions

Copy link
Copy Markdown

This pull request has merge conflicts. Dear author, please fix the conflicts and sync your branch with the base branch.

@vladimirpetrov

Copy link
Copy Markdown
Contributor

@blueorangutan package

@blueorangutan

Copy link
Copy Markdown

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

@blueorangutan

Copy link
Copy Markdown

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

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

LGTM based on manual testing, tested with a custom template and unmanage/reimport running VM.

@vladimirpetrov

Copy link
Copy Markdown
Contributor

@blueorangutan test

@blueorangutan

Copy link
Copy Markdown

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

@weizhouapache

Copy link
Copy Markdown
Member Author

LGTM based on manual testing, tested with a custom template and unmanage/reimport running VM.

cool, thanks @vladimirpetrov

@blueorangutan

blueorangutan commented Sep 12, 2026

Copy link
Copy Markdown

[SF] Trillian test result (tid-16979)
Environment: kvm-ol8 (x2), zone: Advanced Networking with Mgmt server ol8
Total time taken: 47825 seconds
Marvin logs: [archive removed]
Smoke tests completed. 149 look OK, 0 have errors, 0 did not run
Only failed and skipped tests results shown below:

Test Result Time (s) Test File

@weizhouapache

Copy link
Copy Markdown
Member Author

merging based on approvals and Vladi's manual verification
thanks @vladimirpetrov and reviewers

@weizhouapache
weizhouapache merged commit a01fb0b into apache:4.22 Sep 14, 2026
25 of 26 checks passed
@github-project-automation github-project-automation Bot moved this from conflict/waiting to Done in CloudStack Testing Sep 14, 2026
@weizhouapache
weizhouapache deleted the 4.22-import-vm-copy-template-details branch September 14, 2026 06:05
@weizhouapache

Copy link
Copy Markdown
Member Author

@abh1sar has found an issue caused by this PR, when importvm which uses dummy template (existed in database but marked as remvoed)

@abh1sar

abh1sar commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

Created pr #14195

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

Projects

Development

Successfully merging this pull request may close these issues.

Template setting 'guest.cpu.mode' is not set on instances imported from QCOW2

9 participants