Skip to content

Commit a18b551

Browse files
authored
kvm: honor templateId passed in importVM API (#11640)
1 parent a749206 commit a18b551

File tree

2 files changed

+2
-13
lines changed

2 files changed

+2
-13
lines changed

server/src/main/java/org/apache/cloudstack/vm/UnmanagedVMsManagerImpl.java

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1493,7 +1493,7 @@ protected VMTemplateVO getTemplateForImportInstance(Long templateId, Hypervisor.
14931493
if (templateId == null) {
14941494
template = templateDao.findByName(VM_IMPORT_DEFAULT_TEMPLATE_NAME);
14951495
if (template == null) {
1496-
template = createDefaultDummyVmImportTemplate(false);
1496+
template = createDefaultDummyVmImportTemplate(Hypervisor.HypervisorType.KVM == hypervisorType);
14971497
if (template == null) {
14981498
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()));
14991499
}
@@ -2331,14 +2331,7 @@ private UserVmResponse importKvmInstance(ImportVmCmd cmd) {
23312331
if (CollectionUtils.isNotEmpty(userVOs)) {
23322332
userId = userVOs.get(0).getId();
23332333
}
2334-
VMTemplateVO template = templateDao.findByName(KVM_VM_IMPORT_DEFAULT_TEMPLATE_NAME);
2335-
if (template == null) {
2336-
template = createDefaultDummyVmImportTemplate(true);
2337-
if (template == null) {
2338-
throw new InvalidParameterValueException("Error while creating default Import Vm Template");
2339-
}
2340-
}
2341-
2334+
VMTemplateVO template = getTemplateForImportInstance(cmd.getTemplateId(), Hypervisor.HypervisorType.KVM);
23422335
final Long serviceOfferingId = cmd.getServiceOfferingId();
23432336
if (serviceOfferingId == null) {
23442337
throw new InvalidParameterValueException(String.format("Service offering ID cannot be null"));

server/src/test/java/org/apache/cloudstack/vm/UnmanagedVMsManagerImplTest.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -504,8 +504,6 @@ public void testImportFromExternalTest() throws InsufficientServerCapacityExcept
504504
when(cmd.getPassword()).thenReturn("pass");
505505
when(cmd.getImportSource()).thenReturn("external");
506506
when(cmd.getDomainId()).thenReturn(null);
507-
VMTemplateVO template = Mockito.mock(VMTemplateVO.class);
508-
when(templateDao.findByName(anyString())).thenReturn(template);
509507
HostVO host = Mockito.mock(HostVO.class);
510508
DeployDestination mockDest = Mockito.mock(DeployDestination.class);
511509
when(deploymentPlanningManager.planDeployment(any(), any(), any(), any())).thenReturn(mockDest);
@@ -736,8 +734,6 @@ private void importFromDisk(String source) throws InsufficientServerCapacityExce
736734
when(cmd.getImportSource()).thenReturn(source);
737735
when(cmd.getDiskPath()).thenReturn("/var/lib/libvirt/images/test.qcow2");
738736
when(cmd.getDomainId()).thenReturn(null);
739-
VMTemplateVO template = Mockito.mock(VMTemplateVO.class);
740-
when(templateDao.findByName(anyString())).thenReturn(template);
741737
HostVO host = Mockito.mock(HostVO.class);
742738
when(hostDao.findById(anyLong())).thenReturn(host);
743739
NetworkOffering netOffering = Mockito.mock(NetworkOffering.class);

0 commit comments

Comments
 (0)