Skip to content

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

Open
weizhouapache wants to merge 2 commits into
apache:4.22from
weizhouapache:4.22-import-vm-copy-template-details
Open

server: copy template details to vm instance details when import VM#12793
weizhouapache wants to merge 2 commits into
apache:4.22from
weizhouapache:4.22-import-vm-copy-template-details

Conversation

@weizhouapache
Copy link
Copy Markdown
Member

@weizhouapache weizhouapache commented Mar 11, 2026

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.

Copy link
Copy Markdown
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

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
Copy link
Copy Markdown

codecov Bot commented Mar 11, 2026

Codecov Report

❌ Patch coverage is 85.71429% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 17.68%. Comparing base (c3d6a8c) to head (0ed525a).
⚠️ Report is 142 commits behind head on 4.22.

Files with missing lines Patch % Lines
.../src/main/java/com/cloud/vm/UserVmManagerImpl.java 85.71% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               4.22   #12793      +/-   ##
============================================
+ Coverage     17.61%   17.68%   +0.06%     
- Complexity    15661    15791     +130     
============================================
  Files          5917     5922       +5     
  Lines        531402   533125    +1723     
  Branches      64971    65203     +232     
============================================
+ Hits          93586    94259     +673     
- Misses       427262   428223     +961     
- Partials      10554    10643      +89     
Flag Coverage Δ
uitests 3.69% <ø> (-0.01%) ⬇️
unittests 18.75% <85.71%> (+0.07%) ⬆️

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.

@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
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: https://github.com/blueorangutan/acs-prs/releases/download/trillian/pr12793-t15611-kvm-ol8.zip
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

Copy link
Copy Markdown
Contributor

@sureshanaparti sureshanaparti left a comment

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
Copy link
Copy Markdown
Contributor

@sudo87 sudo87 left a comment

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.

@weizhouapache weizhouapache force-pushed the 4.22-import-vm-copy-template-details branch from 7dc8127 to 0ed525a Compare May 11, 2026 09:43
Copy link
Copy Markdown
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

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,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

6 participants