Martin Betak has uploaded a new change for review. Change subject: restapi: Start VM not as RunOnce ......................................................................
restapi: Start VM not as RunOnce The BackendVmResource.start issued RunVmOnce command even if none additional parameters were provided. Now we check if a Vm is passed in the Action and if not, we issue regular RunVmCommand. Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=1005562 Change-Id: I40be200c8742d8b31b7881926c59deaf345992ec Signed-off-by: Martin Betak <[email protected]> --- M backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendVmResource.java M backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendVmResourceTest.java 2 files changed, 28 insertions(+), 8 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/96/19996/1 diff --git a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendVmResource.java b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendVmResource.java index 72f019b..fcf06ff 100644 --- a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendVmResource.java +++ b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendVmResource.java @@ -39,6 +39,7 @@ import org.ovirt.engine.core.common.action.MoveVmParameters; import org.ovirt.engine.core.common.action.RemoveVmFromPoolParameters; import org.ovirt.engine.core.common.action.RunVmOnceParams; +import org.ovirt.engine.core.common.action.RunVmParams; import org.ovirt.engine.core.common.action.SetVmTicketParameters; import org.ovirt.engine.core.common.action.ShutdownVmParameters; import org.ovirt.engine.core.common.action.StopVmParameters; @@ -221,23 +222,26 @@ @Override public Response start(Action action) { - RunVmOnceParams params = - map(map(getEntity(entityType, VdcQueryType.GetVmByVmId, new IdQueryParameters(guid), id, true), - new VM()), - new RunVmOnceParams(guid)); + RunVmParams params; + VdcActionType actionType; if (action.isSetVm()) { - validateEnums(VM.class, action.getVm()); VM vm = action.getVm(); - params = map(vm, params); + validateEnums(VM.class, vm); + actionType = VdcActionType.RunVmOnce; + params = map(vm, map(map(getEntity(entityType, VdcQueryType.GetVmByVmId, new IdQueryParameters(guid), id, true), new VM()), + new RunVmOnceParams(guid))); if (vm.isSetPlacementPolicy() && vm.getPlacementPolicy().isSetHost()) { validateParameters(vm.getPlacementPolicy(), "host.id|name"); params.setDestinationVdsId(getHostId(vm.getPlacementPolicy().getHost())); } + } else { + actionType = VdcActionType.RunVm; + params = new RunVmParams(guid); } if (action.isSetPause() && action.isPause()) { params.setRunAndPause(true); } - return doAction(VdcActionType.RunVmOnce, params, action); + return doAction(actionType, params, action); } @Override diff --git a/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendVmResourceTest.java b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendVmResourceTest.java index cf0d526..2ed3aea 100644 --- a/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendVmResourceTest.java +++ b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendVmResourceTest.java @@ -44,6 +44,7 @@ import org.ovirt.engine.core.common.action.MoveVmParameters; import org.ovirt.engine.core.common.action.RemoveVmFromPoolParameters; import org.ovirt.engine.core.common.action.RunVmOnceParams; +import org.ovirt.engine.core.common.action.RunVmParams; import org.ovirt.engine.core.common.action.SetVmTicketParameters; import org.ovirt.engine.core.common.action.ShutdownVmParameters; import org.ovirt.engine.core.common.action.StopVmParameters; @@ -384,13 +385,28 @@ @Test public void testStart() throws Exception { + setUriInfo(setUpActionExpectations(VdcActionType.RunVm, + RunVmParams.class, + new String[] { "VmId" }, + new Object[] { GUIDS[0] })); + + Response response = resource.start(new Action()); + verifyActionResponse(response); + verifyActionModel(((Action) response.getEntity()).getVm(), 0); + } + + @Test + public void testStartWithVm() throws Exception { setUpWindowsGetEntityExpectations(1, false); + setUriInfo(setUpActionExpectations(VdcActionType.RunVmOnce, RunVmOnceParams.class, new String[] { "VmId" }, new Object[] { GUIDS[0] })); - Response response = resource.start(new Action()); + Action action = new Action(); + action.setVm(new VM()); + Response response = resource.start(action); verifyActionResponse(response); verifyActionModel(((Action) response.getEntity()).getVm(), 0); } -- To view, visit http://gerrit.ovirt.org/19996 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I40be200c8742d8b31b7881926c59deaf345992ec Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: ovirt-engine-3.3 Gerrit-Owner: Martin Betak <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
