Alona Kaplan has uploaded a new change for review. Change subject: restapi: Vnic's network update when portMirroring is set behaves wrong ......................................................................
restapi: Vnic's network update when portMirroring is set behaves wrong If port mirroring is set, the port mirroring network should be equal to the vnic's network. Otherwise, an exception should be thrown. There was a bug, the equlity was checked just if the port mirroring was updated. So, in case that the network was updated and the port mirroring wasn't- an exception wasn't thrown although it should be. Change-Id: Icbb346805f91bd3964550a19b18b3d0a0c40e12c Signed-off-by: Alona Kaplan <alkap...@redhat.com> --- M backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendVmNicResource.java 1 file changed, 41 insertions(+), 16 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/41/10441/1 diff --git a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendVmNicResource.java b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendVmNicResource.java index fae39a3..82e838f 100644 --- a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendVmNicResource.java +++ b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendVmNicResource.java @@ -6,7 +6,10 @@ import org.ovirt.engine.api.model.Action; import org.ovirt.engine.api.model.Fault; import org.ovirt.engine.api.model.NIC; +import org.ovirt.engine.api.model.Network; +import org.ovirt.engine.api.model.Networks; import org.ovirt.engine.api.model.Nics; +import org.ovirt.engine.api.model.PortMirroring; import org.ovirt.engine.api.resource.ActionResource; import org.ovirt.engine.api.resource.VmNicResource; import org.ovirt.engine.core.common.action.ActivateDeactivateVmNicParameters; @@ -14,9 +17,6 @@ import org.ovirt.engine.core.common.action.VdcActionType; import org.ovirt.engine.core.common.businessentities.VmNetworkInterface; import org.ovirt.engine.core.compat.Guid; -import org.ovirt.engine.api.model.Network; -import org.ovirt.engine.api.model.Networks; -import org.ovirt.engine.api.model.PortMirroring; public class BackendVmNicResource extends BackendNicResource implements VmNicResource { @@ -55,23 +55,49 @@ //TODO: this is temporary mapping between engine boolean port mirroring parameter, and REST // port mirroring network collection, next engine version will support the network collection // in port mirroring + if (device.isSetPortMirroring() || device.isSetNetwork()) { + validatePortMirroring(device); + } + + return super.update(device); + } + + private void validatePortMirroring(NIC device) { + NIC nic = null; validateEnums(NIC.class, device); boolean fault = false; String faultString = "The port mirroring network must match the Network set on the NIC"; - boolean isPortMirroring = device.isSetPortMirroring() && device.getPortMirroring().isSetNetworks(); - boolean isPortMirroringExceeded = - isPortMirroring && device.getPortMirroring().getNetworks().getNetworks().size() > 1; - isPortMirroring = isPortMirroring && device.getPortMirroring().getNetworks().getNetworks().size() == 1; - if (isPortMirroringExceeded) { - fault = true; - faultString = "Cannot set more than one network in port mirroring mode"; + Network pmNetwork = null; + + boolean isPortMirroring = false; + if (device.isSetPortMirroring()) { + if (device.getPortMirroring().isSetNetworks()) { + boolean isPortMirroringExceeded = + device.getPortMirroring().getNetworks().getNetworks().size() > 1; + if (isPortMirroringExceeded) { + fault = true; + faultString = "Cannot set more than one network in port mirroring mode"; + } + if (device.getPortMirroring().getNetworks().getNetworks().size() == 1) { + isPortMirroring = true; + pmNetwork = device.getPortMirroring().getNetworks().getNetworks().get(0); + } + } + } else { + nic = get(); + isPortMirroring = + nic.isSetPortMirroring() && nic.getPortMirroring().isSetNetworks() + && nic.getPortMirroring().getNetworks().isSetNetworks(); + if (isPortMirroring) { + pmNetwork = nic.getPortMirroring().getNetworks().getNetworks().get(0); + } } - String networkId = - (device.isSetNetwork() && device.getNetwork().isSetId()) ? device.getNetwork().getId() : null; - String networkName = - (device.isSetNetwork() && device.getNetwork().isSetName()) ? device.getNetwork().getName() : null; + if (!fault && isPortMirroring) { - Network pmNetwork = device.getPortMirroring().getNetworks().getNetworks().get(0); + String networkId = + (device.isSetNetwork() && device.getNetwork().isSetId()) ? device.getNetwork().getId() : null; + String networkName = + (device.isSetNetwork() && device.getNetwork().isSetName()) ? device.getNetwork().getName() : null; String pmNetworkId = (pmNetwork.isSetId() ? pmNetwork.getId() : null); String pmNetworkName = (pmNetwork.isSetName() ? pmNetwork.getName() : null); if (pmNetworkId != null) { @@ -99,7 +125,6 @@ Response response = Response.status(Response.Status.BAD_REQUEST).entity(f).build(); throw new WebApplicationException(response); } - return super.update(device); } private String getNetworkId(String networkName) { -- To view, visit http://gerrit.ovirt.org/10441 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Icbb346805f91bd3964550a19b18b3d0a0c40e12c Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Alona Kaplan <alkap...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches