kvm: honor templateId passed in importVM API (#11640)

This commit is contained in:
Manoj Kumar 2025-09-24 12:04:18 +05:30 committed by GitHub
parent a749206eb8
commit a18b5514e6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 2 additions and 13 deletions

View File

@ -1493,7 +1493,7 @@ public class UnmanagedVMsManagerImpl implements UnmanagedVMsManager {
if (templateId == null) {
template = templateDao.findByName(VM_IMPORT_DEFAULT_TEMPLATE_NAME);
if (template == null) {
template = createDefaultDummyVmImportTemplate(false);
template = createDefaultDummyVmImportTemplate(Hypervisor.HypervisorType.KVM == hypervisorType);
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()));
}
@ -2331,14 +2331,7 @@ public class UnmanagedVMsManagerImpl implements UnmanagedVMsManager {
if (CollectionUtils.isNotEmpty(userVOs)) {
userId = userVOs.get(0).getId();
}
VMTemplateVO template = templateDao.findByName(KVM_VM_IMPORT_DEFAULT_TEMPLATE_NAME);
if (template == null) {
template = createDefaultDummyVmImportTemplate(true);
if (template == null) {
throw new InvalidParameterValueException("Error while creating default Import Vm Template");
}
}
VMTemplateVO template = getTemplateForImportInstance(cmd.getTemplateId(), Hypervisor.HypervisorType.KVM);
final Long serviceOfferingId = cmd.getServiceOfferingId();
if (serviceOfferingId == null) {
throw new InvalidParameterValueException(String.format("Service offering ID cannot be null"));

View File

@ -504,8 +504,6 @@ public class UnmanagedVMsManagerImplTest {
when(cmd.getPassword()).thenReturn("pass");
when(cmd.getImportSource()).thenReturn("external");
when(cmd.getDomainId()).thenReturn(null);
VMTemplateVO template = Mockito.mock(VMTemplateVO.class);
when(templateDao.findByName(anyString())).thenReturn(template);
HostVO host = Mockito.mock(HostVO.class);
DeployDestination mockDest = Mockito.mock(DeployDestination.class);
when(deploymentPlanningManager.planDeployment(any(), any(), any(), any())).thenReturn(mockDest);
@ -736,8 +734,6 @@ public class UnmanagedVMsManagerImplTest {
when(cmd.getImportSource()).thenReturn(source);
when(cmd.getDiskPath()).thenReturn("/var/lib/libvirt/images/test.qcow2");
when(cmd.getDomainId()).thenReturn(null);
VMTemplateVO template = Mockito.mock(VMTemplateVO.class);
when(templateDao.findByName(anyString())).thenReturn(template);
HostVO host = Mockito.mock(HostVO.class);
when(hostDao.findById(anyLong())).thenReturn(host);
NetworkOffering netOffering = Mockito.mock(NetworkOffering.class);