Search in sources :

Example 11 with SnapshotStrategy

use of org.apache.cloudstack.engine.subsystem.api.storage.SnapshotStrategy 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)

Aggregations

SnapshotStrategy (org.apache.cloudstack.engine.subsystem.api.storage.SnapshotStrategy)11 SnapshotVO (com.cloud.storage.SnapshotVO)9 SnapshotInfo (org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo)8 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)6 VolumeInfo (org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo)6 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)5 DataStore (org.apache.cloudstack.engine.subsystem.api.storage.DataStore)5 DataStoreRole (com.cloud.storage.DataStoreRole)4 VolumeVO (com.cloud.storage.VolumeVO)4 Account (com.cloud.user.Account)4 VMSnapshotVO (com.cloud.vm.snapshot.VMSnapshotVO)4 SnapshotDataStoreVO (org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO)4 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)3 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)3 StorageUnavailableException (com.cloud.exception.StorageUnavailableException)3 DB (com.cloud.utils.db.DB)3 ConfigurationException (javax.naming.ConfigurationException)3 Test (org.testng.annotations.Test)3 ActionEvent (com.cloud.event.ActionEvent)2 VMTemplateVO (com.cloud.storage.VMTemplateVO)2