Skip to content

Commit 7a2a9d5

Browse files
Code fixes
1 parent b3232a4 commit 7a2a9d5

File tree

3 files changed

+30
-16
lines changed

3 files changed

+30
-16
lines changed

engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/StorageOrchestrator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ public Future<TemplateApiResult> orchestrateTemplateCopyToImageStore(TemplateInf
325325
public Future<TemplateApiResult> orchestrateTemplateCopyAcrossZones(TemplateInfo templateInfo, DataStore sourceStore, DataStore destStore) {
326326
Long dstZoneId = destStore.getScope().getScopeId();
327327
DataCenterVO dstZone = dcDao.findById(dstZoneId);
328-
Long userId = CallContext.current().getCallingUserId();
328+
long userId = CallContext.current().getCallingUserId();
329329
return submit(dstZoneId, new CrossZoneCopyTemplateTask(userId, templateInfo, sourceStore, dstZone));
330330
}
331331

engine/storage/image/src/main/java/org/apache/cloudstack/storage/image/TemplateServiceImpl.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,7 @@ protected boolean tryCopyingTemplateToImageStore(VMTemplateVO tmplt, DataStore d
622622
return true;
623623
}
624624

625-
logger.debug("Template [{}] not found in any image store of zone [{}]. Checking other zones",
625+
logger.debug("Template [{}] not found in any image store of zone [{}]. Checking other zones.",
626626
tmplt.getUniqueName(), destZoneId);
627627

628628
return searchAndCopyAcrossZones(tmplt, destStore, destZoneId);
@@ -650,6 +650,13 @@ private boolean searchAndCopyAcrossZones(VMTemplateVO tmplt, DataStore destStore
650650
continue;
651651
}
652652

653+
TemplateObject sourceTmpl = (TemplateObject) _templateFactory.getTemplate(tmplt.getId(), sourceStore);
654+
if (sourceTmpl.getInstallPath() == null) {
655+
logger.warn("Cannot copy template [{}] from image store [{}]; install path is null.",
656+
tmplt.getUniqueName(), sourceStore.getName());
657+
continue;
658+
}
659+
653660
logger.info("Template [{}] found in zone [{}]. Initiating cross-zone copy to zone [{}].",
654661
tmplt.getUniqueName(), otherZoneId, destZoneId);
655662

@@ -701,7 +708,7 @@ private boolean copyTemplateAcrossZones(DataStore sourceStore,
701708
DataCenterVO dstZone = _dcDao.findById(dstZoneId);
702709

703710
if (dstZone == null) {
704-
logger.warn("Destination zone [{}] not found for template [{}]",
711+
logger.warn("Destination zone [{}] not found for template [{}].",
705712
dstZoneId, tmplt.getUniqueName());
706713
return false;
707714
}
@@ -711,7 +718,7 @@ private boolean copyTemplateAcrossZones(DataStore sourceStore,
711718
storageOrchestrator.orchestrateTemplateCopyAcrossZones(sourceTmpl, sourceStore, destStore);
712719
return true;
713720
} catch (Exception e) {
714-
logger.error("Failed to copy template [{}] from zone [{}] to zone [{}]",
721+
logger.error("Failed to copy template [{}] from zone [{}] to zone [{}].",
715722
tmplt.getUniqueName(),
716723
sourceStore.getScope().getScopeId(),
717724
dstZoneId,

engine/storage/image/src/test/java/org/apache/cloudstack/storage/image/TemplateServiceImplTest.java

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -201,10 +201,11 @@ public void tryCopyingTemplateToImageStoreTestReturnsTrueWhenTemplateExistsInAno
201201
}
202202

203203
@Test
204-
public void tryCopyingTemplateToImageStoreTestReturnsTrueWhenTemplateExistsInAnotherZone() throws StorageUnavailableException, ResourceAllocationException {
204+
public void tryCopyingTemplateToImageStoreTestReturnsTrueWhenTemplateExistsInAnotherZone() {
205205
Scope scopeMock = Mockito.mock(Scope.class);
206206
Mockito.doReturn(scopeMock).when(destStoreMock).getScope();
207207
Mockito.doReturn(1L).when(scopeMock).getScopeId();
208+
Mockito.doReturn(100L).when(tmpltMock).getId();
208209
Mockito.doReturn(List.of(sourceStoreMock)).when(dataStoreManagerMock).getImageStoresByZoneIds(1L);
209210
Mockito.doReturn(null).when(templateService).listTemplate(sourceStoreMock);
210211
Mockito.doReturn(List.of(1L, 2L)).when(_dcDao).listAllIds();
@@ -216,6 +217,10 @@ public void tryCopyingTemplateToImageStoreTestReturnsTrueWhenTemplateExistsInAno
216217
templatesInOtherZone.put(tmpltMock.getUniqueName(), tmpltPropMock);
217218
Mockito.doReturn(templatesInOtherZone).when(templateService).listTemplate(otherZoneStoreMock);
218219

220+
TemplateObject sourceTmplMock = Mockito.mock(TemplateObject.class);
221+
Mockito.doReturn(sourceTmplMock).when(templateDataFactoryMock).getTemplate(100L, otherZoneStoreMock);
222+
Mockito.doReturn("/mnt/secondary/template.qcow2").when(sourceTmplMock).getInstallPath();
223+
219224
DataCenterVO dstZoneMock = Mockito.mock(DataCenterVO.class);
220225
Mockito.doReturn(dstZoneMock).when(_dcDao).findById(1L);
221226

@@ -229,6 +234,7 @@ public void tryCopyingTemplateToImageStoreTestReturnsFalseWhenDestinationZoneIsM
229234
Scope scopeMock = Mockito.mock(Scope.class);
230235
Mockito.doReturn(scopeMock).when(destStoreMock).getScope();
231236
Mockito.doReturn(1L).when(scopeMock).getScopeId();
237+
Mockito.doReturn(100L).when(tmpltMock).getId();
232238
Mockito.doReturn(List.of(1L, 2L)).when(_dcDao).listAllIds();
233239
Mockito.doReturn(List.of()).when(dataStoreManagerMock).getImageStoresByZoneIds(1L);
234240

@@ -238,6 +244,10 @@ public void tryCopyingTemplateToImageStoreTestReturnsFalseWhenDestinationZoneIsM
238244
Map<String, TemplateProp> templates = new HashMap<>();
239245
templates.put(tmpltMock.getUniqueName(), tmpltPropMock);
240246
Mockito.doReturn(templates).when(templateService).listTemplate(otherZoneStoreMock);
247+
248+
TemplateObject sourceTmplMock = Mockito.mock(TemplateObject.class);
249+
Mockito.doReturn(sourceTmplMock).when(templateDataFactoryMock).getTemplate(100L, otherZoneStoreMock);
250+
Mockito.doReturn("/mnt/secondary/template.qcow2").when(sourceTmplMock).getInstallPath();
241251
Mockito.doReturn(null).when(_dcDao).findById(1L);
242252

243253
boolean result = templateService.tryCopyingTemplateToImageStore(tmpltMock, destStoreMock);
@@ -250,23 +260,20 @@ public void tryCopyingTemplateToImageStoreTestReturnsTrueWhenCrossZoneCopyTaskIs
250260
Scope scopeMock = Mockito.mock(Scope.class);
251261
Mockito.doReturn(scopeMock).when(destStoreMock).getScope();
252262
Mockito.doReturn(1L).when(scopeMock).getScopeId();
253-
263+
Mockito.doReturn(100L).when(tmpltMock).getId();
254264
Mockito.doReturn(List.of(1L, 2L)).when(_dcDao).listAllIds();
255-
256-
Mockito.doReturn(List.of())
257-
.when(dataStoreManagerMock)
258-
.getImageStoresByZoneIds(1L);
265+
Mockito.doReturn(List.of()).when(dataStoreManagerMock).getImageStoresByZoneIds(1L);
259266

260267
DataStore otherZoneStoreMock = Mockito.mock(DataStore.class);
261-
Mockito.doReturn(List.of(otherZoneStoreMock))
262-
.when(dataStoreManagerMock)
263-
.getImageStoresByZoneIds(2L);
268+
Mockito.doReturn(List.of(otherZoneStoreMock)).when(dataStoreManagerMock).getImageStoresByZoneIds(2L);
264269

265270
Map<String, TemplateProp> templates = new HashMap<>();
266271
templates.put(tmpltMock.getUniqueName(), tmpltPropMock);
267-
Mockito.doReturn(templates)
268-
.when(templateService)
269-
.listTemplate(otherZoneStoreMock);
272+
Mockito.doReturn(templates).when(templateService).listTemplate(otherZoneStoreMock);
273+
274+
TemplateObject sourceTmplMock = Mockito.mock(TemplateObject.class);
275+
Mockito.doReturn(sourceTmplMock).when(templateDataFactoryMock).getTemplate(100L, otherZoneStoreMock);
276+
Mockito.doReturn("/mnt/secondary/template.qcow2").when(sourceTmplMock).getInstallPath();
270277

271278
DataCenterVO dstZoneMock = Mockito.mock(DataCenterVO.class);
272279
Mockito.doReturn(dstZoneMock).when(_dcDao).findById(1L);

0 commit comments

Comments
 (0)