public static Response setTicket(BackendResource resource, Action action, Guid vmId, org.ovirt.engine.core.common.businessentities.GraphicsType graphicsType) { final Response response = resource.performAction(ActionType.SetVmTicket, new SetVmTicketParameters(vmId, getTicketValue(action), getTicketExpiry(action), graphicsType), action); final Action actionResponse = (Action) response.getEntity(); if (CreationStatus.FAILED.value().equals(actionResponse.getStatus())) { actionResponse.getTicket().setValue(null); actionResponse.getTicket().setExpiry(null); } return response; }
protected void verifyActionResponse(Response r, String baseUri, boolean async, String reason) { assertEquals(async ? 202 : 200, r.getStatus(), "unexpected status"); Object entity = r.getEntity(); assertTrue(entity instanceof Action, "expect Action response entity"); Action action = (Action)entity; if (async) { assertTrue(action.isAsync()); assertNotNull(action.getHref()); assertNotNull(action.getId()); assertNotNull(action.getLinks()); assertEquals(2, action.getLinks().size()); assertEquals("parent", action.getLinks().get(0).getRel(), "expected parent link"); assertNotNull(action.getLinks().get(0).getHref()); assertTrue(action.getLinks().get(0).getHref().startsWith(BASE_PATH + "/" + baseUri)); assertNotNull(action.getLinks().get(1).getHref()); assertEquals("replay", action.getLinks().get(1).getRel(), "expected replay link"); assertTrue(action.getLinks().get(1).getHref().startsWith(BASE_PATH + "/" + baseUri)); } else { assertTrue(!(action.isSetAsync() && action.isAsync())); } assertTrue(async ? action.getStatus().equals(CreationStatus.PENDING.value()) || action.getStatus().equals(CreationStatus.IN_PROGRESS.value()) || action.getStatus().equals(CreationStatus.COMPLETE.value()) : reason == null ? action.getStatus().equals(CreationStatus.COMPLETE.value()) : action.getStatus().equals(CreationStatus.FAILED.value()), "unexpected status"); }
@Test public void testUndoSnapshot() { setUriInfo(setUpActionExpectations(ActionType.RestoreAllSnapshots, RestoreAllSnapshotsParameters.class, new String[] { "VmId", "SnapshotAction" }, new Object[] { GUIDS[0], SnapshotActionEnum.UNDO })); Response response = resource.undoSnapshot(new Action()); verifyActionResponse(response); Action action = (Action)response.getEntity(); assertTrue(action.isSetStatus()); assertEquals(CreationStatus.COMPLETE.value(), action.getStatus()); }
@Test public void testCommitSnapshot() { setUriInfo(setUpActionExpectations(ActionType.RestoreAllSnapshots, RestoreAllSnapshotsParameters.class, new String[] { "VmId", "SnapshotAction" }, new Object[] { GUIDS[0], SnapshotActionEnum.COMMIT })); Response response = resource.commitSnapshot(new Action()); verifyActionResponse(response); Action action = (Action)response.getEntity(); assertTrue(action.isSetStatus()); assertEquals(CreationStatus.COMPLETE.value(), action.getStatus()); }
private void doTestSuspendAsync(AsyncTaskStatusEnum asyncStatus, CreationStatus actionStatus) { setUriInfo(setUpActionExpectations(ActionType.HibernateVm, VmOperationParameterBase.class, new String[] { "VmId" }, new Object[] { GUIDS[0] }, asList(GUIDS[1]), asList(new AsyncTaskStatus(asyncStatus)))); Response response = resource.suspend(new Action()); verifyActionResponse(response, "vms/" + GUIDS[0], true, null); Action action = (Action)response.getEntity(); assertTrue(action.isSetStatus()); assertEquals(actionStatus.value(), action.getStatus()); }
private void doTestActivateAsync(AsyncTaskStatusEnum asyncStatus, CreationStatus actionStatus) { setUriInfo(setUpActionExpectations(ActionType.ActivateVds, VdsActionParameters.class, new String[] { "VdsId" }, new Object[] { GUIDS[0] }, asList(GUIDS[1]), asList(new AsyncTaskStatus(asyncStatus)))); Response response = resource.activate(new Action()); verifyActionResponse(response, "hosts/" + GUIDS[0], true, null); Action action = (Action)response.getEntity(); assertTrue(action.isSetStatus()); assertEquals(actionStatus.value(), action.getStatus()); }
private void doTestActivateAsync(AsyncTaskStatusEnum asyncStatus, CreationStatus actionStatus) { setUriInfo( setUpActionExpectations( ActionType.ActivateStorageDomain, StorageDomainPoolParametersBase.class, new String[] { "StorageDomainId", "StoragePoolId" }, new Object[] { STORAGE_DOMAIN_ID, DATA_CENTER_ID }, asList(GUIDS[1]), asList(new AsyncTaskStatus(asyncStatus)) ) ); Response response = resource.activate(new Action()); verifyActionResponse( response, "datacenters/" + DATA_CENTER_ID + "/storagedomains/" + STORAGE_DOMAIN_ID, true, null ); Action action = (Action) response.getEntity(); assertTrue(action.isSetStatus()); assertEquals(actionStatus.value(), action.getStatus()); }
@Test public void testPreviewSnapshot() { setUriInfo(setUpActionExpectations(ActionType.TryBackToAllSnapshotsOfVm, TryBackToAllSnapshotsOfVmParameters.class, new String[] { "VmId", "DstSnapshotId" }, new Object[] { GUIDS[0], GUIDS[1] })); Action action = new Action(); Snapshot snapshot = new Snapshot(); snapshot.setId(GUIDS[1].toString()); action.setSnapshot(snapshot); Response response = resource.previewSnapshot(action); verifyActionResponse(response); Action actionResponse = (Action)response.getEntity(); assertTrue(actionResponse.isSetStatus()); assertEquals(CreationStatus.COMPLETE.value(), actionResponse.getStatus()); }
@Test public void testFenceStatusFailure() { FenceOperationResult retVal = new FenceOperationResult(FenceOperationResult.Status.ERROR, PowerStatus.UNKNOWN, "some_error"); setUpEntityQueryExpectations(QueryType.GetVdsFenceStatus, IdQueryParameters.class, new String[] { "Id" }, new Object[] { GUIDS[0] }, retVal); Action action = new Action(); action.setFenceType(FenceType.STATUS.value()); Response response = resource.fence(action); Action actionReturned = (Action)response.getEntity(); assertEquals(actionReturned.getStatus(), CreationStatus.FAILED.value()); assertNotNull(actionReturned.getFault()); assertEquals("some_error", actionReturned.getFault().getReason()); }
private void doTestExportAsync(AsyncTaskStatusEnum asyncStatus, CreationStatus actionStatus) { setUriInfo(setUpActionExpectations(ActionType.ExportVmTemplate, MoveOrCopyParameters.class, new String[] { "ContainerId", "StorageDomainId", "ForceOverride" }, new Object[] { GUIDS[0], GUIDS[2], false }, asList(GUIDS[1]), asList(new AsyncTaskStatus(asyncStatus)))); Action action = new Action(); StorageDomain storageDomain = new StorageDomain(); storageDomain.setId(GUIDS[2].toString()); action.setStorageDomain(storageDomain); Response response = resource.export(action); verifyActionResponse(response, "templates/" + GUIDS[0], true, null); action = (Action)response.getEntity(); assertTrue(action.isSetStatus()); assertEquals(actionStatus.value(), action.getStatus()); }
private void doTestImportAsync(AsyncTaskStatusEnum asyncStatus, CreationStatus actionStatus) { setUpGetEntityExpectations(1, StorageDomainType.ImportExport, GUIDS[2]); setUpGetDataCenterByStorageDomainExpectations(GUIDS[3]); setUriInfo(setUpActionExpectations( ActionType.ImportVm, ImportVmParameters.class, new String[] { "ContainerId", "StorageDomainId", "SourceDomainId", "DestDomainId", "StoragePoolId", "ClusterId" }, new Object[] { VM_ID, GUIDS[2], STORAGE_DOMAIN_ID, GUIDS[2], DATA_CENTER_ID, GUIDS[1] }, asList(GUIDS[1]), asList(new AsyncTaskStatus(asyncStatus)))); StorageDomain storageDomain = new StorageDomain(); storageDomain.setId(GUIDS[2].toString()); org.ovirt.engine.api.model.Cluster cluster = new org.ovirt.engine.api.model.Cluster(); cluster.setId(GUIDS[1].toString()); Action action = new Action(); action.setStorageDomain(storageDomain); action.setCluster(cluster); Response response = resource.doImport(action); verifyActionResponse(response, URL_BASE, true, null); action = (Action)response.getEntity(); assertTrue(action.isSetStatus()); assertEquals(actionStatus.value(), action.getStatus()); }
private void doTestImportAsync(AsyncTaskStatusEnum asyncStatus, CreationStatus actionStatus) { setUpGetEntityExpectations(1, StorageDomainType.ImportExport, GUIDS[2]); setUpGetDataCenterByStorageDomainExpectations(GUIDS[3]); setUriInfo(setUpActionExpectations( ActionType.ImportVmTemplate, ImportVmTemplateParameters.class, new String[] { "ContainerId", "StorageDomainId", "SourceDomainId", "DestDomainId", "StoragePoolId", "ClusterId" }, new Object[] { TEMPLATE_ID, GUIDS[2], STORAGE_DOMAIN_ID, GUIDS[2], DATA_CENTER_ID, GUIDS[1] }, asList(GUIDS[1]), asList(new AsyncTaskStatus(asyncStatus)))); StorageDomain storageDomain = new StorageDomain(); storageDomain.setId(GUIDS[2].toString()); org.ovirt.engine.api.model.Cluster cluster = new org.ovirt.engine.api.model.Cluster(); cluster.setId(GUIDS[1].toString()); Action action = new Action(); action.setStorageDomain(storageDomain); action.setCluster(cluster); Response response = resource.doImport(action); verifyActionResponse(response, URL_BASE, true, null); action = (Action)response.getEntity(); assertTrue(action.isSetStatus()); assertEquals(actionStatus.value(), action.getStatus()); }
status.setState(from.getStatus()); to.setStatus(status);