Moti Asayag has uploaded a new change for review. Change subject: engine: Prevent networks with different MTU (#852052) ......................................................................
engine: Prevent networks with different MTU (#852052) https://bugzilla.redhat.com/852052 The patch prevents attaching a network to an interface if one of the following cases occur: * A non-VM network is already attached to the interface with MTU other than default and the user attempt to attach a Vlan which its MTU is other than the non-VM network. * A Vlan with non-default MTU is attached to an interface and the user attempt to attach a non-VM network to it with MTU other than the Vlan. Attaching several Vlans (VM network) with different MTU will not be blocked, as VDSM should support MTU configuration for the underlying interface. Change-Id: I69f5c5f515d782c0311fd7fe458408ed634c1c83 Signed-off-by: Moti Asayag <[email protected]> --- M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/SetupNetworksHelper.java M backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/SetupNetworksHelperTest.java M backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/VdcBllMessages.java M backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties M frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java M frontend/webadmin/modules/userportal-gwtp/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties M frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties 7 files changed, 101 insertions(+), 0 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/61/7661/1 diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/SetupNetworksHelper.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/SetupNetworksHelper.java index fb67d7c..1391077 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/SetupNetworksHelper.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/SetupNetworksHelper.java @@ -91,10 +91,65 @@ extractRemovedNetworks(); extractRemovedBonds(); detectSlaveChanges(); + validateMTU(); return translateViolations(); } + /** + * Validates there is no differences on MTU value between non-VM network to Vlans over the same interface/bond + */ + private void validateMTU() { + Map<String, VdsNetworkInterface> ifacesByNetworkName = + Entities.interfacesByNetworkName(params.getInterfaces()); + Set<String> checkedNetworks = new HashSet<String>(getNetworks().size()); + + for (Network network : getNetworks()) { + if (!checkedNetworks.contains(network.getName())) { + List<Network> networksOnInterface = findNetworksOnInterface(ifacesByNetworkName.get(network.getName())); + boolean mtuDifferenceExists = false; + for (Network net : networksOnInterface) { + checkedNetworks.add(net.getName()); + if (net.getMtu() != network.getMtu() && (!network.isVmNetwork() || !net.isVmNetwork())) { + mtuDifferenceExists = true; + } + } + if (mtuDifferenceExists) { + reportMTUDifferences(networksOnInterface); + } + } + } + } + + private void reportMTUDifferences(List<Network> ifaceNetworks) { + List<String> mtuDiffNetworks = new ArrayList<String>(); + for (Network net : ifaceNetworks) { + mtuDiffNetworks.add(String.format("%s(%d)", net.getName(), net.getMtu())); + } + addViolation(VdcBllMessages.NETWORK_MTU_DIFFERENCES, + String.format("[%s]", StringUtils.join(mtuDiffNetworks, ", "))); + } + + /** + * Finds all the networks on a specific network interface, directly on the interface or over a vlan. + * + * @param iface + * the underlying interface + * @return a list of attached networks to the given underlying interface + */ + private List<Network> findNetworksOnInterface(VdsNetworkInterface iface) { + String nameWithoutVlanId = NetworkUtils.StripVlan(iface.getName()); + List<Network> networks = new ArrayList<Network>(); + for (VdsNetworkInterface tmp : params.getInterfaces()) { + if (NetworkUtils.StripVlan(tmp.getName()).equals(nameWithoutVlanId) && tmp.getNetworkName() != null) { + if (existingClusterNetworks.containsKey(tmp.getNetworkName())) { + networks.add(existingClusterNetworks.get(tmp.getNetworkName())); + } + } + } + return networks; + } + private void addViolation(VdcBllMessages violation, String violatingEntity) { List<String> violatingEntities = violations.get(violation); if (violatingEntities == null) { diff --git a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/SetupNetworksHelperTest.java b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/SetupNetworksHelperTest.java index 66e9ce8..b48e2d7 100644 --- a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/SetupNetworksHelperTest.java +++ b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/SetupNetworksHelperTest.java @@ -654,6 +654,45 @@ validateAndExpectViolation(helper, VdcBllMessages.NETWORKS_DONT_EXIST_IN_CLUSTER, networkName); } + @Test + public void networkWithTheSameMTUAddedToNic() { + Network net = createNetwork("nonVmMtu9000"); + net.setVmNetwork(false); + net.setMtu(9000); + Network newNet = createNetwork("vLanVmMtu9000"); + newNet.setMtu(9000); + mockExistingNetworks(net, newNet); + + VdsNetworkInterface nic = createNic("nic0", net.getName()); + nic.setBridged(false); + mockExistingIfaces(nic); + + SetupNetworksHelper helper = createHelper( + createParametersForNics(nic, createVlan(nic.getName(), 100, newNet.getName()))); + + validateAndExpectNoViolations(helper); + } + + @Test + public void networkWithDifferentMTUAddedToNic() { + Network net = createNetwork("nonVmMtu5000"); + net.setVmNetwork(false); + net.setMtu(5000); + Network newNet = createNetwork("vLanVmMtu9000"); + newNet.setMtu(9000); + mockExistingNetworks(net, newNet); + + VdsNetworkInterface nic = createNic("nic0", net.getName()); + nic.setBridged(false); + mockExistingIfaces(nic); + + SetupNetworksHelper helper = createHelper( + createParametersForNics(nic, createVlan(nic.getName(), 100, newNet.getName()))); + + validateAndExpectViolation(helper, VdcBllMessages.NETWORK_MTU_DIFFERENCES, + String.format("[%s(%d), %s(%d)]", net.getName(), net.getMtu(), newNet.getName(), newNet.getMtu())); + } + /* --- Tests for General Violations --- */ @Test diff --git a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/VdcBllMessages.java b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/VdcBllMessages.java index edca168..e92a0ff 100644 --- a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/VdcBllMessages.java +++ b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/VdcBllMessages.java @@ -402,6 +402,7 @@ NETWORK_BONDS_INVALID_SLAVE_COUNT, NETWORK_CANNOT_DETACH_NETWORK_USED_BY_VMS, NON_VM_NETWORK_CANNOT_SUPPORT_STP, + NETWORK_MTU_DIFFERENCES, ACTION_TYPE_FAILED_STORAGE_DOMAIN_NOT_IN_STORAGE_POOL, ACTION_TYPE_FAILED_STORAGE_POOL_NOT_EXIST, ACTION_TYPE_FAILED_STORAGE_DOMAIN_NOT_EXIST, diff --git a/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties b/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties index 420261c..0a447b1 100644 --- a/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties +++ b/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties @@ -432,6 +432,7 @@ NETWORK_BONDS_INVALID_SLAVE_COUNT=Cannot ${action} ${type}. The following Bonds consist of less than two Network Interfaces: ${NETWORK_BONDS_INVALID_SLAVE_COUNT_LIST}. NETWORK_CANNOT_DETACH_NETWORK_USED_BY_VMS=Cannot ${action} ${type}. The following VMs are actively using the Logical Network: ${NETWORK_CANNOT_DETACH_NETWORK_USED_BY_VMS_LIST}. Please stop the VMs and try again. NON_VM_NETWORK_CANNOT_SUPPORT_STP=Cannot ${action} ${type}. STP can only be enabled on VM Networks. +NETWORK_MTU_DIFFERENCES=Cannot ${action} ${type}. The following Logical Networks don't have the same MTU value: ${NETWORK_MTU_DIFFERENCES_LIST}. CANNOT_PREIEW_CURRENT_IMAGE=The currently used VM Snapshot Image cannot be used in Preview command. CONFIG_UNKNOWN_KEY=Illegal configuration entry.\n\ -Please check configuration entry name. diff --git a/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java b/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java index c84dadf..bba3597 100644 --- a/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java +++ b/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java @@ -1135,6 +1135,9 @@ @DefaultStringValue("Cannot ${action} ${type}. STP can only be enabled on VM Networks.") String NON_VM_NETWORK_CANNOT_SUPPORT_STP(); + @DefaultStringValue("Cannot ${action} ${type}. The following Logical Networks don't have the same MTU value: ${NETWORK_MTU_DIFFERENCES_LIST}.") + String NETWORK_MTU_DIFFERENCES(); + @DefaultStringValue("The currently used VM Snapshot Image cannot be used in Preview command.") String CANNOT_PREIEW_CURRENT_IMAGE(); diff --git a/frontend/webadmin/modules/userportal-gwtp/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties b/frontend/webadmin/modules/userportal-gwtp/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties index 24bc75d..590a460 100644 --- a/frontend/webadmin/modules/userportal-gwtp/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties +++ b/frontend/webadmin/modules/userportal-gwtp/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties @@ -430,6 +430,7 @@ NETWORK_BONDS_INVALID_SLAVE_COUNT=Cannot ${action} ${type}. The following Bonds consist of less than two Network Interfaces: ${NETWORK_BONDS_INVALID_SLAVE_COUNT_LIST}. NETWORK_CANNOT_DETACH_NETWORK_USED_BY_VMS=Cannot ${action} ${type}. The following VMs are actively using the Logical Network: ${NETWORK_CANNOT_DETACH_NETWORK_USED_BY_VMS_LIST}. Please stop the VMs and try again. NON_VM_NETWORK_CANNOT_SUPPORT_STP=Cannot ${action} ${type}. STP can only be enabled on VM Networks. +NETWORK_MTU_DIFFERENCES=Cannot ${action} ${type}. The following Logical Networks don't have the same MTU value: ${NETWORK_MTU_DIFFERENCES_LIST}. CANNOT_PREIEW_CURRENT_IMAGE=The currently used VM Snapshot Image cannot be used in Preview command. CONFIG_UNKNOWN_KEY=Illegal configuration entry.\n\ -Please check configuration entry name. diff --git a/frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties b/frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties index c47ec24..169ae55 100644 --- a/frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties +++ b/frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties @@ -428,6 +428,7 @@ NETWORK_BONDS_INVALID_SLAVE_COUNT=Cannot ${action} ${type}. The following Bonds consist of less than two Network Interfaces: ${NETWORK_BONDS_INVALID_SLAVE_COUNT_LIST}. NETWORK_CANNOT_DETACH_NETWORK_USED_BY_VMS=Cannot ${action} ${type}. The following VMs are actively using the Logical Network: ${NETWORK_CANNOT_DETACH_NETWORK_USED_BY_VMS_LIST}. Please stop the VMs and try again. NON_VM_NETWORK_CANNOT_SUPPORT_STP=Cannot ${action} ${type}. STP can only be enabled on VM Networks. +NETWORK_MTU_DIFFERENCES=Cannot ${action} ${type}. The following Logical Networks don't have the same MTU value: ${NETWORK_MTU_DIFFERENCES_LIST}. CANNOT_PREIEW_CURRENT_IMAGE=The currently used VM Snapshot Image cannot be used in Preview command. CONFIG_UNKNOWN_KEY=Illegal configuration entry.\n\ -Please check configuration entry name. -- To view, visit http://gerrit.ovirt.org/7661 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I69f5c5f515d782c0311fd7fe458408ed634c1c83 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Moti Asayag <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
