diff --git a/server/src/main/java/com/cloud/template/HypervisorTemplateAdapter.java b/server/src/main/java/com/cloud/template/HypervisorTemplateAdapter.java index d8132df6d28f..7f99e6423bbc 100644 --- a/server/src/main/java/com/cloud/template/HypervisorTemplateAdapter.java +++ b/server/src/main/java/com/cloud/template/HypervisorTemplateAdapter.java @@ -306,12 +306,12 @@ protected void createTemplateWithinZones(TemplateProfile profile, VMTemplateVO t zonesIds = _dcDao.listAllZones().stream().map(DataCenterVO::getId).collect(Collectors.toList()); } - List imageStores = getImageStoresThrowsExceptionIfNotFound(zonesIds, profile); for (long zoneId : zonesIds) { DataStore imageStore = verifyHeuristicRulesForZone(template, zoneId); if (imageStore == null) { + List imageStores = getImageStoresThrowsExceptionIfNotFound(List.of(zoneId), profile); standardImageStoreAllocation(imageStores, template); } else { validateSecondaryStorageAndCreateTemplate(List.of(imageStore), template, null); diff --git a/server/src/test/java/com/cloud/template/HypervisorTemplateAdapterTest.java b/server/src/test/java/com/cloud/template/HypervisorTemplateAdapterTest.java index 8657c07b5ef5..4f0fcdb9e4e2 100644 --- a/server/src/test/java/com/cloud/template/HypervisorTemplateAdapterTest.java +++ b/server/src/test/java/com/cloud/template/HypervisorTemplateAdapterTest.java @@ -323,7 +323,6 @@ public void createTemplateWithinZonesTestZoneIdsNullShouldCallListAllZones() { VMTemplateVO vmTemplateVOMock = Mockito.mock(VMTemplateVO.class); Mockito.when(templateProfileMock.getZoneIdList()).thenReturn(null); - Mockito.doReturn(null).when(_adapter).getImageStoresThrowsExceptionIfNotFound(Mockito.any(List.class), Mockito.any(TemplateProfile.class)); _adapter.createTemplateWithinZones(templateProfileMock, vmTemplateVOMock); @@ -370,7 +369,6 @@ public void createTemplateWithinZonesTestZoneWithHeuristicRuleShouldCallValidate List zoneIds = List.of(1L); Mockito.when(templateProfileMock.getZoneIdList()).thenReturn(zoneIds); - Mockito.doReturn(null).when(_adapter).getImageStoresThrowsExceptionIfNotFound(Mockito.any(List.class), Mockito.any(TemplateProfile.class)); Mockito.doReturn(dataStoreMock).when(_adapter).verifyHeuristicRulesForZone(Mockito.any(VMTemplateVO.class), Mockito.anyLong()); Mockito.doNothing().when(_adapter).validateSecondaryStorageAndCreateTemplate(Mockito.any(List.class), Mockito.any(VMTemplateVO.class), Mockito.isNull());