use of org.apache.cloudstack.engine.subsystem.api.storage.DataStore in project cloudstack by apache.
the class SnapshotTestWithFakeData method createDataStore.
private DataStore createDataStore() throws URISyntaxException {
StoragePoolVO pool = new StoragePoolVO();
pool.setClusterId(clusterId);
pool.setDataCenterId(dcId);
URI uri = new URI("nfs://jfkdkf/fjdkfj");
pool.setHostAddress(uri.getHost());
pool.setPath(uri.getPath());
pool.setPort(0);
pool.setName(UUID.randomUUID().toString());
pool.setUuid(UUID.randomUUID().toString());
pool.setStatus(StoragePoolStatus.Up);
pool.setPoolType(Storage.StoragePoolType.NetworkFilesystem);
pool.setPodId(podId);
pool.setScope(ScopeType.CLUSTER);
pool.setStorageProviderName(DataStoreProvider.DEFAULT_PRIMARY);
pool = primaryDataStoreDao.persist(pool);
DataStore store = dataStoreManager.getPrimaryDataStore(pool.getId());
return store;
}
use of org.apache.cloudstack.engine.subsystem.api.storage.DataStore in project cloudstack by apache.
the class SnapshotTestWithFakeData method testTakeSnapshotWithFailed.
// @Test
public void testTakeSnapshotWithFailed() throws URISyntaxException {
SnapshotVO snapshotVO = createSnapshotInDb();
DataStore store = null;
try {
store = createDataStore();
FakePrimaryDataStoreDriver dataStoreDriver = (FakePrimaryDataStoreDriver) store.getDriver();
dataStoreDriver.makeTakeSnapshotSucceed(false);
SnapshotInfo snapshotInfo = snapshotDataFactory.getSnapshot(snapshotVO.getId(), store);
SnapshotResult result = snapshotService.takeSnapshot(snapshotInfo);
Assert.assertFalse(result.isSuccess());
SnapshotDataStoreVO storeRef = snapshotDataStoreDao.findByStoreSnapshot(store.getRole(), store.getId(), snapshotVO.getId());
Assert.assertTrue(storeRef == null);
} finally {
snapshotDao.expunge(snapshotVO.getId());
if (store != null) {
primaryDataStoreDao.remove(store.getId());
}
}
}
use of org.apache.cloudstack.engine.subsystem.api.storage.DataStore in project cloudstack by apache.
the class SnapshotTestWithFakeData method testTakeSnapshot.
// @Test
public void testTakeSnapshot() throws URISyntaxException {
SnapshotVO snapshotVO = createSnapshotInDb();
DataStore store = createDataStore();
try {
SnapshotInfo snapshotInfo = snapshotDataFactory.getSnapshot(snapshotVO.getId(), store);
SnapshotResult result = snapshotService.takeSnapshot(snapshotInfo);
Assert.assertTrue(result.isSuccess());
SnapshotDataStoreVO storeRef = snapshotDataStoreDao.findByStoreSnapshot(store.getRole(), store.getId(), snapshotVO.getId());
Assert.assertTrue(storeRef != null);
Assert.assertTrue(storeRef.getState() == ObjectInDataStoreStateMachine.State.Ready);
snapshotInfo = result.getSnapshot();
boolean deletResult = snapshotService.deleteSnapshot(snapshotInfo);
Assert.assertTrue(deletResult);
snapshotDataStoreDao.expunge(storeRef.getId());
} finally {
snapshotDao.expunge(snapshotVO.getId());
primaryDataStoreDao.remove(store.getId());
}
}
use of org.apache.cloudstack.engine.subsystem.api.storage.DataStore in project cloudstack by apache.
the class EndpointSelectorTest method testMixZonePrimaryStorages.
@Test
public void testMixZonePrimaryStorages() {
Long srcStoreId = null;
Long destStoreId = imageStore.getId();
DataStore store = createPrimaryDataStore(ScopeType.ZONE);
srcStoreId = store.getId();
HostVO host = createHost(Hypervisor.HypervisorType.VMware);
addStorageToHost(store, host);
store = createPrimaryDataStore(ScopeType.ZONE);
host = createHost(Hypervisor.HypervisorType.VMware);
addStorageToHost(store, host);
Long xenStoreId = null;
store = createPrimaryDataStore(ScopeType.CLUSTER);
xenStoreId = store.getId();
host = createHost(Hypervisor.HypervisorType.XenServer);
addStorageToHost(store, host);
store = createPrimaryDataStore(ScopeType.CLUSTER);
host = createHost(Hypervisor.HypervisorType.XenServer);
addStorageToHost(store, host);
ZoneScope srcScope = new ZoneScope(dcId);
DataStore srcStore = mock(DataStore.class);
DataStore destStore = mock(DataStore.class);
when(srcStore.getScope()).thenReturn(srcScope);
when(srcStore.getRole()).thenReturn(DataStoreRole.Primary);
when(srcStore.getId()).thenReturn(srcStoreId);
when(destStore.getScope()).thenReturn(srcScope);
when(destStore.getRole()).thenReturn(DataStoreRole.Image);
when(destStore.getId()).thenReturn(destStoreId);
DataObject srcObj = mock(DataObject.class);
DataObject destObj = mock(DataObject.class);
when(srcObj.getDataStore()).thenReturn(srcStore);
when(destObj.getDataStore()).thenReturn(destStore);
EndPoint ep = endPointSelector.select(srcObj, destObj);
Assert.assertTrue(ep != null);
Long hostId = ep.getId();
HostVO newHost = hostDao.findById(hostId);
Assert.assertTrue(newHost.getHypervisorType() == Hypervisor.HypervisorType.VMware);
when(srcStore.getRole()).thenReturn(DataStoreRole.Image);
when(srcStore.getId()).thenReturn(destStoreId);
when(destStore.getId()).thenReturn(srcStoreId);
when(destStore.getRole()).thenReturn(DataStoreRole.Primary);
ep = endPointSelector.select(srcObj, destObj);
Assert.assertTrue(ep != null);
hostId = ep.getId();
newHost = hostDao.findById(hostId);
Assert.assertTrue(newHost.getHypervisorType() == Hypervisor.HypervisorType.VMware);
ClusterScope clusterScope = new ClusterScope(clusterId, podId, dcId);
when(srcStore.getRole()).thenReturn(DataStoreRole.Primary);
when(srcStore.getScope()).thenReturn(clusterScope);
when(srcStore.getId()).thenReturn(xenStoreId);
ep = endPointSelector.select(srcStore);
Assert.assertTrue(ep != null);
newHost = hostDao.findById(ep.getId());
Assert.assertTrue(newHost.getHypervisorType() == Hypervisor.HypervisorType.XenServer);
}
use of org.apache.cloudstack.engine.subsystem.api.storage.DataStore in project cloudstack by apache.
the class EndpointSelectorTest method createPrimaryDataStore.
public DataStore createPrimaryDataStore(ScopeType scope) {
String uuid = UUID.randomUUID().toString();
List<StoragePoolVO> pools = primaryDataStoreDao.findPoolByName(uuid);
if (pools.size() > 0) {
return dataStoreManager.getPrimaryDataStore(pools.get(0).getId());
}
StoragePoolVO pool = new StoragePoolVO();
if (scope != ScopeType.ZONE) {
pool.setClusterId(clusterId);
}
pool.setDataCenterId(dcId);
pool.setHostAddress(uuid);
pool.setPath(uuid);
pool.setPort(0);
pool.setName(uuid);
pool.setUuid(uuid);
pool.setStatus(StoragePoolStatus.Up);
pool.setPoolType(Storage.StoragePoolType.NetworkFilesystem);
pool.setPodId(podId);
pool.setScope(scope);
pool.setStorageProviderName(DataStoreProvider.DEFAULT_PRIMARY);
pool = primaryDataStoreDao.persist(pool);
DataStore store = dataStoreManager.getPrimaryDataStore(pool.getId());
return store;
}
Aggregations