Search in sources :

Example 1 with MockLocalNfsSecondaryStorageResource

use of org.apache.cloudstack.storage.MockLocalNfsSecondaryStorageResource 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);
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) LocalHostEndpoint(org.apache.cloudstack.storage.LocalHostEndpoint) DataObject(org.apache.cloudstack.engine.subsystem.api.storage.DataObject) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) VMTemplateVO(com.cloud.storage.VMTemplateVO) MockLocalNfsSecondaryStorageResource(org.apache.cloudstack.storage.MockLocalNfsSecondaryStorageResource) ImageStoreVO(org.apache.cloudstack.storage.datastore.db.ImageStoreVO) Test(org.testng.annotations.Test)

Example 2 with MockLocalNfsSecondaryStorageResource

use of org.apache.cloudstack.storage.MockLocalNfsSecondaryStorageResource 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);
    }
}
Also used : LocalHostEndpoint(org.apache.cloudstack.storage.LocalHostEndpoint) SnapshotInfo(org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo) SnapshotVO(com.cloud.storage.SnapshotVO) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) MockLocalNfsSecondaryStorageResource(org.apache.cloudstack.storage.MockLocalNfsSecondaryStorageResource) VolumeInfo(org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo) SnapshotStrategy(org.apache.cloudstack.engine.subsystem.api.storage.SnapshotStrategy) Test(org.testng.annotations.Test)

Example 3 with MockLocalNfsSecondaryStorageResource

use of org.apache.cloudstack.storage.MockLocalNfsSecondaryStorageResource 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);
    }
}
Also used : MockLocalNfsSecondaryStorageResource(org.apache.cloudstack.storage.MockLocalNfsSecondaryStorageResource) VMTemplateVO(com.cloud.storage.VMTemplateVO) VolumeInfo(org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo) TemplateApiResult(org.apache.cloudstack.engine.subsystem.api.storage.TemplateService.TemplateApiResult) LocalHostEndpoint(org.apache.cloudstack.storage.LocalHostEndpoint) SnapshotInfo(org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo) TemplateInfo(org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo) SnapshotVO(com.cloud.storage.SnapshotVO) DataObject(org.apache.cloudstack.engine.subsystem.api.storage.DataObject) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) SnapshotStrategy(org.apache.cloudstack.engine.subsystem.api.storage.SnapshotStrategy) Test(org.testng.annotations.Test)

Example 4 with MockLocalNfsSecondaryStorageResource

use of org.apache.cloudstack.storage.MockLocalNfsSecondaryStorageResource 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);
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) LocalHostEndpoint(org.apache.cloudstack.storage.LocalHostEndpoint) DataObject(org.apache.cloudstack.engine.subsystem.api.storage.DataObject) HashMap(java.util.HashMap) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) VMTemplateVO(com.cloud.storage.VMTemplateVO) MockLocalNfsSecondaryStorageResource(org.apache.cloudstack.storage.MockLocalNfsSecondaryStorageResource) DataObject(org.apache.cloudstack.engine.subsystem.api.storage.DataObject) Test(org.testng.annotations.Test)

Aggregations

DataStore (org.apache.cloudstack.engine.subsystem.api.storage.DataStore)4 LocalHostEndpoint (org.apache.cloudstack.storage.LocalHostEndpoint)4 MockLocalNfsSecondaryStorageResource (org.apache.cloudstack.storage.MockLocalNfsSecondaryStorageResource)4 Test (org.testng.annotations.Test)4 VMTemplateVO (com.cloud.storage.VMTemplateVO)3 DataObject (org.apache.cloudstack.engine.subsystem.api.storage.DataObject)3 DataCenterVO (com.cloud.dc.DataCenterVO)2 SnapshotVO (com.cloud.storage.SnapshotVO)2 SnapshotInfo (org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo)2 SnapshotStrategy (org.apache.cloudstack.engine.subsystem.api.storage.SnapshotStrategy)2 VolumeInfo (org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo)2 HashMap (java.util.HashMap)1 TemplateInfo (org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo)1 TemplateApiResult (org.apache.cloudstack.engine.subsystem.api.storage.TemplateService.TemplateApiResult)1 ImageStoreVO (org.apache.cloudstack.storage.datastore.db.ImageStoreVO)1