use of com.cloud.storage.Snapshot in project cosmic by MissionCriticalCloud.
the class SnapshotManagerTest method testBackupSnapshotFromVmSnapshotF1.
// vm on Xenserver, expected exception
@Test(expected = InvalidParameterValueException.class)
public void testBackupSnapshotFromVmSnapshotF1() {
when(_vmDao.findById(anyLong())).thenReturn(vmMock);
when(vmMock.getHypervisorType()).thenReturn(Hypervisor.HypervisorType.XenServer);
Snapshot snapshot = _snapshotMgr.backupSnapshotFromVmSnapshot(TEST_SNAPSHOT_ID, TEST_VM_ID, TEST_VOLUME_ID, TEST_VM_SNAPSHOT_ID);
Assert.assertNull(snapshot);
}
use of com.cloud.storage.Snapshot in project cosmic by MissionCriticalCloud.
the class SnapshotManagerTest method testBackupSnapshotFromVmSnapshotF2.
// vm on KVM, first time
@Test
public void testBackupSnapshotFromVmSnapshotF2() {
when(_vmDao.findById(anyLong())).thenReturn(vmMock);
when(vmMock.getHypervisorType()).thenReturn(Hypervisor.HypervisorType.KVM);
when(_vmSnapshotDao.findById(anyLong())).thenReturn(vmSnapshotMock);
when(_snapshotStoreDao.findParent(any(DataStoreRole.class), anyLong(), anyLong())).thenReturn(null);
when(snapshotFactory.getSnapshot(anyLong(), Mockito.any(DataStore.class))).thenReturn(snapshotInfoMock);
when(storeMock.create(snapshotInfoMock)).thenReturn(snapshotInfoMock);
when(_snapshotStoreDao.findBySnapshot(anyLong(), any(DataStoreRole.class))).thenReturn(snapshotStoreMock);
when(_snapshotStoreDao.update(anyLong(), any(SnapshotDataStoreVO.class))).thenReturn(true);
when(_snapshotDao.update(anyLong(), any(SnapshotVO.class))).thenReturn(true);
when(vmMock.getAccountId()).thenReturn(2L);
when(snapshotStrategy.backupSnapshot(any(SnapshotInfo.class))).thenReturn(snapshotInfoMock);
Snapshot snapshot = _snapshotMgr.backupSnapshotFromVmSnapshot(TEST_SNAPSHOT_ID, TEST_VM_ID, TEST_VOLUME_ID, TEST_VM_SNAPSHOT_ID);
Assert.assertNotNull(snapshot);
}
use of com.cloud.storage.Snapshot in project cosmic by MissionCriticalCloud.
the class SnapshotManagerTest method testBackupSnapshotFromVmSnapshotF3.
// vm on KVM, already backed up
@Test(expected = InvalidParameterValueException.class)
public void testBackupSnapshotFromVmSnapshotF3() {
when(_vmDao.findById(anyLong())).thenReturn(vmMock);
when(vmMock.getHypervisorType()).thenReturn(Hypervisor.HypervisorType.KVM);
when(_vmSnapshotDao.findById(anyLong())).thenReturn(vmSnapshotMock);
when(_snapshotStoreDao.findParent(any(DataStoreRole.class), anyLong(), anyLong())).thenReturn(snapshotStoreMock);
when(snapshotStoreMock.getInstallPath()).thenReturn("VM_SNAPSHOT_NAME");
when(vmSnapshotMock.getName()).thenReturn("VM_SNAPSHOT_NAME");
Snapshot snapshot = _snapshotMgr.backupSnapshotFromVmSnapshot(TEST_SNAPSHOT_ID, TEST_VM_ID, TEST_VOLUME_ID, TEST_VM_SNAPSHOT_ID);
Assert.assertNull(snapshot);
}
use of com.cloud.storage.Snapshot in project cosmic by MissionCriticalCloud.
the class CreateSnapshotCmd method execute.
@Override
public void execute() {
s_logger.info("VOLSS: createSnapshotCmd starts:" + System.currentTimeMillis());
CallContext.current().setEventDetails("Volume Id: " + getVolumeUuid());
final Snapshot snapshot;
try {
snapshot = _volumeService.takeSnapshot(getVolumeId(), getPolicyId(), getEntityId(), _accountService.getAccount(getEntityOwnerId()), getQuiescevm());
if (snapshot != null) {
final SnapshotResponse response = _responseGenerator.createSnapshotResponse(snapshot);
response.setResponseName(getCommandName());
setResponseObject(response);
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create snapshot due to an internal error creating snapshot for volume " + volumeId);
}
} catch (final Exception e) {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create snapshot due to an internal error creating snapshot for volume " + volumeId);
}
}
use of com.cloud.storage.Snapshot in project cosmic by MissionCriticalCloud.
the class CreateSnapshotCmd method create.
@Override
public void create() throws ResourceAllocationException {
final Snapshot snapshot = _volumeService.allocSnapshot(getVolumeId(), getPolicyId(), getSnapshotName());
if (snapshot != null) {
setEntityId(snapshot.getId());
setEntityUuid(snapshot.getUuid());
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create snapshot");
}
}
Aggregations