use of com.cloud.storage.Snapshot in project cloudstack by apache.
the class SnapshotManagerTest method testRevertSnapshotF2.
// vm on Xenserver, return null
@Test
public void testRevertSnapshotF2() {
when(_vmDao.findById(anyLong())).thenReturn(vmMock);
when(vmMock.getState()).thenReturn(State.Stopped);
when(vmMock.getHypervisorType()).thenReturn(Hypervisor.HypervisorType.XenServer);
when(volumeMock.getFormat()).thenReturn(ImageFormat.VHD);
Snapshot snapshot = _snapshotMgr.revertSnapshot(TEST_SNAPSHOT_ID);
Assert.assertNull(snapshot);
}
use of com.cloud.storage.Snapshot in project cloudstack by apache.
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 cloudstack by apache.
the class SnapshotManagerTest method testRevertSnapshotF3.
// vm on KVM, successful
@Test
public void testRevertSnapshotF3() {
when(_vmDao.findById(anyLong())).thenReturn(vmMock);
when(vmMock.getState()).thenReturn(State.Stopped);
when(vmMock.getHypervisorType()).thenReturn(Hypervisor.HypervisorType.KVM);
when(volumeMock.getFormat()).thenReturn(ImageFormat.QCOW2);
when(snapshotStrategy.revertSnapshot(Mockito.any(SnapshotInfo.class))).thenReturn(true);
when(_volumeDao.update(anyLong(), any(VolumeVO.class))).thenReturn(true);
Snapshot snapshot = _snapshotMgr.revertSnapshot(TEST_SNAPSHOT_ID);
Assert.assertNotNull(snapshot);
}
use of com.cloud.storage.Snapshot in project cosmic by MissionCriticalCloud.
the class CreateTemplateCmd method getEntityOwnerId.
@Override
public long getEntityOwnerId() {
final Long volumeId = getVolumeId();
final Long snapshotId = getSnapshotId();
final Account callingAccount = CallContext.current().getCallingAccount();
if (volumeId != null) {
final Volume volume = _entityMgr.findById(Volume.class, volumeId);
if (volume != null) {
_accountService.checkAccess(callingAccount, SecurityChecker.AccessType.UseEntry, false, volume);
} else {
throw new InvalidParameterValueException("Unable to find volume by id=" + volumeId);
}
} else {
final Snapshot snapshot = _entityMgr.findById(Snapshot.class, snapshotId);
if (snapshot != null) {
_accountService.checkAccess(callingAccount, SecurityChecker.AccessType.UseEntry, false, snapshot);
} else {
throw new InvalidParameterValueException("Unable to find snapshot by id=" + snapshotId);
}
}
if (projectId != null) {
final Project project = _projectService.getProject(projectId);
if (project != null) {
if (project.getState() == Project.State.Active) {
final Account projectAccount = _accountService.getAccount(project.getProjectAccountId());
_accountService.checkAccess(callingAccount, SecurityChecker.AccessType.UseEntry, false, projectAccount);
return project.getProjectAccountId();
} else {
final PermissionDeniedException ex = new PermissionDeniedException("Can't add resources to the project with specified projectId in state=" + project.getState() + " as it's no longer active");
ex.addProxyObject(project.getUuid(), "projectId");
throw ex;
}
} else {
throw new InvalidParameterValueException("Unable to find project by id");
}
}
return callingAccount.getId();
}
use of com.cloud.storage.Snapshot in project cosmic by MissionCriticalCloud.
the class CreateSnapshotFromVMSnapshotCmd method create.
@Override
public void create() throws ResourceAllocationException {
final Snapshot snapshot = this._volumeService.allocSnapshotForVm(getVmId(), getVolumeId(), getSnapshotName());
if (snapshot != null) {
this.setEntityId(snapshot.getId());
this.setEntityUuid(snapshot.getUuid());
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create snapshot from vm snapshot");
}
}
Aggregations