Skip to content

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

Open
weizhouapache wants to merge 3 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 3 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.66%. Comparing base (a951ac6) to head (bfdaf5f).

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.67%   17.66%   -0.01%     
+ Complexity    15797    15794       -3     
============================================
  Files          5923     5923              
  Lines        533349   533355       +6     
  Branches      65248    65250       +2     
============================================
- Hits          94253    94242      -11     
- Misses       428437   428453      +16     
- Partials      10659    10660       +1     
Flag Coverage Δ
uitests 3.69% <ø> (ø)
unittests 18.74% <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

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

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

@weizhouapache weizhouapache force-pushed the 4.22-import-vm-copy-template-details branch from 7dc8127 to 0ed525a Compare May 11, 2026 09:43

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.

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