Moti Asayag has uploaded a new change for review. Change subject: restapi: Preserve labels when setup networks is sent ......................................................................
restapi: Preserve labels when setup networks is sent The setup networks api doesn't use the patch mechanism to preserve any interface's properties that wasn't sent by the user. Instead, it creates a new interface entity and set only the provided nic attributes. Since labels are maintained as a sub-collection on the nic entity, it should not be deleted for each setup networks request. This logic cannot reside on the engine side, since there will be no distinction between setup networks sent by the UI, in which the labels can be provided or removed, to the rest in which labels cannot be provided and should be preserved. Change-Id: Ic2b728a4797d03d6718e6c9b0b6adec6dcf3bbff Bug-Url: https://bugzilla.redhat.com/1055441 Signed-off-by: Moti Asayag <[email protected]> --- M backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendHostNicsResource.java M backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendHostNicsResourceTest.java 2 files changed, 14 insertions(+), 0 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/24/23524/1 diff --git a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendHostNicsResource.java b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendHostNicsResource.java index 8b4ba84..ea301f4 100644 --- a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendHostNicsResource.java +++ b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendHostNicsResource.java @@ -30,6 +30,7 @@ import org.ovirt.engine.core.common.action.RemoveBondParameters; import org.ovirt.engine.core.common.action.SetupNetworksParameters; import org.ovirt.engine.core.common.action.VdcActionType; +import org.ovirt.engine.core.common.businessentities.Entities; import org.ovirt.engine.core.common.businessentities.VDS; import org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface; import org.ovirt.engine.core.common.queries.IdQueryParameters; @@ -374,6 +375,10 @@ private List<VdsNetworkInterface> nicsToInterfaces(List<HostNIC> hostNics) { List<VdsNetworkInterface> ifaces = new ArrayList<VdsNetworkInterface>(hostNics.size()); + List<VdsNetworkInterface> existingNics = getCollection(); + Map<String, VdsNetworkInterface> nicsByName = Entities.entitiesByName(existingNics); + Map<Guid, VdsNetworkInterface> nicsById = Entities.businessEntitiesById(existingNics); + for (HostNIC nic : hostNics) { VdsNetworkInterface iface = map(nic, null); ifaces.add(iface); @@ -385,6 +390,13 @@ ifaces.add(slaveIface); } } + + if (nic.isSetName() && nicsByName.containsKey(nic.getName())) { + iface.setLabels(nicsByName.get(nic.getName()).getLabels()); + } else if (nic.isSetId() && nicsById.containsKey(nic.getId())) { + iface.setLabels(nicsById.get(nic.getId()).getLabels()); + } + } return ifaces; } diff --git a/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendHostNicsResourceTest.java b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendHostNicsResourceTest.java index 1062b99..14af092 100644 --- a/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendHostNicsResourceTest.java +++ b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendHostNicsResourceTest.java @@ -233,6 +233,7 @@ @Test public void testSetupNetworksNotSyncsNetwork() throws Exception { setUpNetworkQueryExpectations(1); + setUpEntityQueryExpectations(1); doTestSetupNetworksSyncsNetwork(false, Collections.<String> emptyList()); } @@ -240,6 +241,7 @@ @Test public void testSetupNetworksSyncsNetwork() throws Exception { setUpNetworkQueryExpectations(2); + setUpEntityQueryExpectations(1); doTestSetupNetworksSyncsNetwork(true, Collections.singletonList(NETWORK_NAME)); } -- To view, visit http://gerrit.ovirt.org/23524 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ic2b728a4797d03d6718e6c9b0b6adec6dcf3bbff Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: ovirt-engine-3.4 Gerrit-Owner: Moti Asayag <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
