use of com.cloud.agent.api.storage.ListTemplateAnswer in project cloudstack by apache.
the class LocalNfsSecondaryStorageResourceTest method testExecuteRequest.
@Test
public void testExecuteRequest() throws Exception {
TemplateObjectTO template = Mockito.mock(TemplateObjectTO.class);
NfsTO cacheStore = Mockito.mock(NfsTO.class);
Mockito.when(cacheStore.getUrl()).thenReturn("nfs://nfs2.lab.vmops.com/export/home/edison/");
SwiftTO swift = Mockito.mock(SwiftTO.class);
Mockito.when(swift.getEndPoint()).thenReturn("https://objects.dreamhost.com/auth");
Mockito.when(swift.getAccount()).thenReturn("cloudstack");
Mockito.when(swift.getUserName()).thenReturn("images");
Mockito.when(swift.getKey()).thenReturn("oxvELQaOD1U5_VyosGfA-wpZ7uBWEff-CUBGCM0u");
Mockito.when(template.getDataStore()).thenReturn(swift);
Mockito.when(template.getPath()).thenReturn("template/1/1/");
Mockito.when(template.isRequiresHvm()).thenReturn(true);
Mockito.when(template.getId()).thenReturn(1L);
Mockito.when(template.getFormat()).thenReturn(Storage.ImageFormat.VHD);
Mockito.when(template.getOrigUrl()).thenReturn("http://nfs1.lab.vmops.com/templates/test.bz2");
Mockito.when(template.getName()).thenReturn(UUID.randomUUID().toString());
Mockito.when(template.getObjectType()).thenReturn(DataObjectType.TEMPLATE);
DownloadCommand cmd = new DownloadCommand(template, 100000L);
cmd.setCacheStore(cacheStore);
DownloadAnswer answer = (DownloadAnswer) resource.executeRequest(cmd);
Assert.assertTrue(answer.getResult());
Mockito.when(template.getPath()).thenReturn(answer.getInstallPath());
Mockito.when(template.getDataStore()).thenReturn(swift);
// download swift:
Mockito.when(cacheStore.getRole()).thenReturn(DataStoreRole.ImageCache);
TemplateObjectTO destTemplate = Mockito.mock(TemplateObjectTO.class);
Mockito.when(destTemplate.getPath()).thenReturn("template/1/2");
Mockito.when(destTemplate.getDataStore()).thenReturn(cacheStore);
Mockito.when(destTemplate.getObjectType()).thenReturn(DataObjectType.TEMPLATE);
CopyCommand cpyCmd = new CopyCommand(template, destTemplate, 10000, true);
CopyCmdAnswer copyCmdAnswer = (CopyCmdAnswer) resource.executeRequest(cpyCmd);
Assert.assertTrue(copyCmdAnswer.getResult());
// list template
ListTemplateCommand listCmd = new ListTemplateCommand(swift);
ListTemplateAnswer listAnswer = (ListTemplateAnswer) resource.executeRequest(listCmd);
Assert.assertTrue(listAnswer.getTemplateInfo().size() > 0);
}
use of com.cloud.agent.api.storage.ListTemplateAnswer in project cloudstack by apache.
the class TemplateServiceImpl method listTemplate.
private Map<String, TemplateProp> listTemplate(DataStore ssStore) {
String nfsVersion = imageStoreDetailsUtil.getNfsVersion(ssStore.getId());
ListTemplateCommand cmd = new ListTemplateCommand(ssStore.getTO(), nfsVersion);
EndPoint ep = _epSelector.select(ssStore);
Answer answer = null;
if (ep == null) {
String errMsg = "No remote endpoint to send command, check if host or ssvm is down?";
s_logger.error(errMsg);
answer = new Answer(cmd, false, errMsg);
} else {
answer = ep.sendMessage(cmd);
}
if (answer != null && answer.getResult()) {
ListTemplateAnswer tanswer = (ListTemplateAnswer) answer;
return tanswer.getTemplateInfo();
} else {
if (s_logger.isDebugEnabled()) {
s_logger.debug("can not list template for secondary storage host " + ssStore.getId());
}
}
return null;
}
Aggregations