use of org.apache.cloudstack.storage.LocalHostEndpoint in project cloudstack by apache.
the class TemplateTest method setUp.
@Test(priority = -1)
public void setUp() {
ComponentContext.initComponentsLifeCycle();
// create data center
DataCenterVO dc = new DataCenterVO(UUID.randomUUID().toString(), "test", "8.8.8.8", null, "10.0.0.1", null, "10.0.0.1/24", null, null, NetworkType.Basic, null, null, true, true, null, null);
dc = dcDao.persist(dc);
dcId = dc.getId();
imageStore = new ImageStoreVO();
imageStore.setName("test");
imageStore.setDataCenterId(dcId);
imageStore.setProviderName(DataStoreProvider.NFS_IMAGE);
imageStore.setRole(DataStoreRole.Image);
imageStore.setUrl(this.getSecondaryStorage());
imageStore.setUuid(UUID.randomUUID().toString());
imageStore.setProtocol("nfs");
imageStore = imageStoreDao.persist(imageStore);
VMTemplateVO image = new VMTemplateVO();
image.setTemplateType(TemplateType.USER);
image.setUrl(this.getTemplateUrl());
image.setUniqueName(UUID.randomUUID().toString());
image.setName(UUID.randomUUID().toString());
image.setPublicTemplate(true);
image.setFeatured(true);
image.setRequiresHvm(true);
image.setBits(64);
image.setFormat(Storage.ImageFormat.VHD);
image.setEnablePassword(true);
image.setEnableSshKey(true);
image.setGuestOSId(1);
image.setBootable(true);
image.setPrepopulate(true);
image.setCrossZones(true);
image.setExtractable(true);
// image.setImageDataStoreId(storeId);
image = templateDao.persist(image);
templateId = image.getId();
// inject mockito
LocalHostEndpoint ep = new LocalHostEndpoint();
ep.setResource(new MockLocalNfsSecondaryStorageResource());
Mockito.when(epSelector.select(Matchers.any(DataObject.class))).thenReturn(ep);
Mockito.when(epSelector.select(Matchers.any(DataStore.class))).thenReturn(ep);
}
use of org.apache.cloudstack.storage.LocalHostEndpoint in project cloudstack by apache.
the class SnapshotTest method createSnapshot.
@Test
public void createSnapshot() throws InterruptedException, ExecutionException {
VolumeInfo vol = createCopyBaseImage();
SnapshotVO snapshotVO = createSnapshotInDb(vol);
SnapshotInfo snapshot = this.snapshotFactory.getSnapshot(snapshotVO.getId(), vol.getDataStore());
SnapshotInfo newSnapshot = null;
SnapshotStrategy snapshotStrategy = storageStrategyFactory.getSnapshotStrategy(snapshot, SnapshotOperation.TAKE);
if (snapshotStrategy != null) {
newSnapshot = snapshotStrategy.takeSnapshot(snapshot);
}
AssertJUnit.assertNotNull(newSnapshot);
LocalHostEndpoint ep = new MockLocalHostEndPoint();
ep.setResource(new MockLocalNfsSecondaryStorageResource());
Mockito.when(epSelector.select(Matchers.any(DataStore.class))).thenReturn(ep);
try {
for (SnapshotStrategy strategy : this.snapshotStrategies) {
if (strategy.canHandle(snapshot, SnapshotOperation.DELETE) != StrategyPriority.CANT_HANDLE) {
boolean res = strategy.deleteSnapshot(newSnapshot.getId());
Assert.assertTrue(res);
}
}
} finally {
Mockito.when(epSelector.select(Matchers.any(DataStore.class))).thenReturn(remoteEp);
}
}
use of org.apache.cloudstack.storage.LocalHostEndpoint in project cloudstack by apache.
the class S3TemplateTest method setUp.
@Test(priority = -1)
public void setUp() {
ComponentContext.initComponentsLifeCycle();
// create data center
DataCenterVO dc = new DataCenterVO(UUID.randomUUID().toString(), "test", "8.8.8.8", null, "10.0.0.1", null, "10.0.0.1/24", null, null, NetworkType.Basic, null, null, true, true, null, null);
dc = dcDao.persist(dc);
dcId = dc.getId();
// add s3 image store
Map<String, Object> sParams = new HashMap<String, Object>();
sParams.put("name", "test");
sParams.put("protocol", "http");
sParams.put("providerName", "S3");
sParams.put("scope", ScopeType.REGION);
sParams.put("role", DataStoreRole.Image);
Map<String, String> sDetails = new HashMap<String, String>();
sDetails.put(ApiConstants.S3_ACCESS_KEY, this.getS3AccessKey());
sDetails.put(ApiConstants.S3_SECRET_KEY, this.getS3SecretKey());
sDetails.put(ApiConstants.S3_BUCKET_NAME, this.getS3TemplateBucket());
sDetails.put(ApiConstants.S3_END_POINT, this.getS3EndPoint());
this.imageStoreHelper.createImageStore(sParams, sDetails);
// add nfs cache storage
Map<String, Object> cParams = new HashMap<String, Object>();
cParams.put("name", "testCache");
cParams.put("protocol", "nfs");
cParams.put("providerName", DataStoreProvider.NFS_IMAGE);
cParams.put("scope", ScopeType.ZONE);
cParams.put("role", DataStoreRole.ImageCache);
cParams.put("url", this.getSecondaryStorage());
cParams.put("zoneId", dcId);
this.imageStoreHelper.createImageStore(cParams);
VMTemplateVO image = new VMTemplateVO();
image.setTemplateType(TemplateType.SYSTEM);
image.setUrl(this.getTemplateUrl());
image.setUniqueName(UUID.randomUUID().toString());
image.setName(UUID.randomUUID().toString());
image.setPublicTemplate(false);
image.setFeatured(false);
image.setRequiresHvm(false);
image.setBits(64);
image.setFormat(Storage.ImageFormat.VHD);
image.setEnablePassword(false);
image.setEnableSshKey(false);
image.setGuestOSId(133);
image.setBootable(true);
image.setPrepopulate(true);
image.setCrossZones(true);
image.setExtractable(true);
image.setAccountId(2);
image = templateDao.persist(image);
templateId = image.getId();
// inject mockito
LocalHostEndpoint ep = new LocalHostEndpoint();
ep.setResource(new MockLocalNfsSecondaryStorageResource());
Mockito.when(epSelector.select(Matchers.any(DataObject.class))).thenReturn(ep);
Mockito.when(epSelector.select(Matchers.any(DataStore.class))).thenReturn(ep);
Mockito.when(epSelector.select(Matchers.any(DataObject.class), Matchers.any(DataObject.class))).thenReturn(ep);
}
use of org.apache.cloudstack.storage.LocalHostEndpoint in project cloudstack by apache.
the class SnapshotTest method createTemplateFromSnapshot.
@Test
public void createTemplateFromSnapshot() throws InterruptedException, ExecutionException {
VolumeInfo vol = createCopyBaseImage();
SnapshotVO snapshotVO = createSnapshotInDb(vol);
SnapshotInfo snapshot = this.snapshotFactory.getSnapshot(snapshotVO.getId(), vol.getDataStore());
boolean result = false;
SnapshotStrategy snapshotStrategy = storageStrategyFactory.getSnapshotStrategy(snapshot, SnapshotOperation.TAKE);
if (snapshotStrategy != null) {
snapshot = snapshotStrategy.takeSnapshot(snapshot);
result = true;
}
AssertJUnit.assertTrue(result);
LocalHostEndpoint ep = new LocalHostEndpoint();
ep.setResource(new MockLocalNfsSecondaryStorageResource());
Mockito.when(epSelector.select(Matchers.any(DataObject.class), Matchers.any(DataObject.class))).thenReturn(ep);
try {
VMTemplateVO templateVO = createTemplateInDb();
TemplateInfo tmpl = this.templateFactory.getTemplate(templateVO.getId(), DataStoreRole.Image);
DataStore imageStore = this.dataStoreMgr.getImageStore(this.dcId);
AsyncCallFuture<TemplateApiResult> templateFuture = this.imageService.createTemplateFromSnapshotAsync(snapshot, tmpl, imageStore);
TemplateApiResult apiResult = templateFuture.get();
Assert.assertTrue(apiResult.isSuccess());
} finally {
Mockito.when(epSelector.select(Matchers.any(DataObject.class), Matchers.any(DataObject.class))).thenReturn(remoteEp);
}
}
Aggregations