mirror of
				https://github.com/apache/cloudstack.git
				synced 2025-10-26 08:42:29 +01:00 
			
		
		
		
	kvm: honor templateId passed in importVM API (#11640)
This commit is contained in:
		
							parent
							
								
									a749206eb8
								
							
						
					
					
						commit
						a18b5514e6
					
				| @ -1493,7 +1493,7 @@ public class UnmanagedVMsManagerImpl implements UnmanagedVMsManager { | |||||||
|         if (templateId == null) { |         if (templateId == null) { | ||||||
|             template = templateDao.findByName(VM_IMPORT_DEFAULT_TEMPLATE_NAME); |             template = templateDao.findByName(VM_IMPORT_DEFAULT_TEMPLATE_NAME); | ||||||
|             if (template == null) { |             if (template == null) { | ||||||
|                 template = createDefaultDummyVmImportTemplate(false); |                 template = createDefaultDummyVmImportTemplate(Hypervisor.HypervisorType.KVM == hypervisorType); | ||||||
|                 if (template == null) { |                 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())); |                     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())); | ||||||
|                 } |                 } | ||||||
| @ -2331,14 +2331,7 @@ public class UnmanagedVMsManagerImpl implements UnmanagedVMsManager { | |||||||
|         if (CollectionUtils.isNotEmpty(userVOs)) { |         if (CollectionUtils.isNotEmpty(userVOs)) { | ||||||
|             userId = userVOs.get(0).getId(); |             userId = userVOs.get(0).getId(); | ||||||
|         } |         } | ||||||
|         VMTemplateVO template = templateDao.findByName(KVM_VM_IMPORT_DEFAULT_TEMPLATE_NAME); |         VMTemplateVO template = getTemplateForImportInstance(cmd.getTemplateId(), Hypervisor.HypervisorType.KVM); | ||||||
|         if (template == null) { |  | ||||||
|             template = createDefaultDummyVmImportTemplate(true); |  | ||||||
|             if (template == null) { |  | ||||||
|                 throw new InvalidParameterValueException("Error while creating default Import Vm Template"); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|         final Long serviceOfferingId = cmd.getServiceOfferingId(); |         final Long serviceOfferingId = cmd.getServiceOfferingId(); | ||||||
|         if (serviceOfferingId == null) { |         if (serviceOfferingId == null) { | ||||||
|             throw new InvalidParameterValueException(String.format("Service offering ID cannot be null")); |             throw new InvalidParameterValueException(String.format("Service offering ID cannot be null")); | ||||||
|  | |||||||
| @ -504,8 +504,6 @@ public class UnmanagedVMsManagerImplTest { | |||||||
|         when(cmd.getPassword()).thenReturn("pass"); |         when(cmd.getPassword()).thenReturn("pass"); | ||||||
|         when(cmd.getImportSource()).thenReturn("external"); |         when(cmd.getImportSource()).thenReturn("external"); | ||||||
|         when(cmd.getDomainId()).thenReturn(null); |         when(cmd.getDomainId()).thenReturn(null); | ||||||
|         VMTemplateVO template = Mockito.mock(VMTemplateVO.class); |  | ||||||
|         when(templateDao.findByName(anyString())).thenReturn(template); |  | ||||||
|         HostVO host = Mockito.mock(HostVO.class); |         HostVO host = Mockito.mock(HostVO.class); | ||||||
|         DeployDestination mockDest = Mockito.mock(DeployDestination.class); |         DeployDestination mockDest = Mockito.mock(DeployDestination.class); | ||||||
|         when(deploymentPlanningManager.planDeployment(any(), any(), any(), any())).thenReturn(mockDest); |         when(deploymentPlanningManager.planDeployment(any(), any(), any(), any())).thenReturn(mockDest); | ||||||
| @ -736,8 +734,6 @@ public class UnmanagedVMsManagerImplTest { | |||||||
|         when(cmd.getImportSource()).thenReturn(source); |         when(cmd.getImportSource()).thenReturn(source); | ||||||
|         when(cmd.getDiskPath()).thenReturn("/var/lib/libvirt/images/test.qcow2"); |         when(cmd.getDiskPath()).thenReturn("/var/lib/libvirt/images/test.qcow2"); | ||||||
|         when(cmd.getDomainId()).thenReturn(null); |         when(cmd.getDomainId()).thenReturn(null); | ||||||
|         VMTemplateVO template = Mockito.mock(VMTemplateVO.class); |  | ||||||
|         when(templateDao.findByName(anyString())).thenReturn(template); |  | ||||||
|         HostVO host = Mockito.mock(HostVO.class); |         HostVO host = Mockito.mock(HostVO.class); | ||||||
|         when(hostDao.findById(anyLong())).thenReturn(host); |         when(hostDao.findById(anyLong())).thenReturn(host); | ||||||
|         NetworkOffering netOffering = Mockito.mock(NetworkOffering.class); |         NetworkOffering netOffering = Mockito.mock(NetworkOffering.class); | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user