Mike Kolesnik has uploaded a new change for review. Change subject: core: Add interfaceBasedOn method (#849971) ......................................................................
core: Add interfaceBasedOn method (#849971) https://bugzilla.redhat.com/849971 This method will be used to identify if a proposed VLAN if in fact a VLAN of the given interface or the interface, or is it an unrelated interface. Change-Id: Ic479acc3179622b60efe921522dcb2115838557f Signed-off-by: Mike Kolesnik <[email protected]> --- M backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/NetworkUtils.java M backend/manager/modules/utils/src/test/java/org/ovirt/engine/core/utils/NetworkUtilsTest.java 2 files changed, 56 insertions(+), 0 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/06/7406/1 diff --git a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/NetworkUtils.java b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/NetworkUtils.java index cff1947..a4e3ace 100644 --- a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/NetworkUtils.java +++ b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/NetworkUtils.java @@ -87,6 +87,22 @@ return retVal; } + /** + * Check if the proposed interface name represents a VLAN of the given interface name or is equal to it.<br> + * If either of the parameters is null, <code>false</code> is returned. + * + * @param proposedIface + * The interface to check if it's a VLAN of the other interface or it is the other interface. + * @param iface + * The interface to check for. + * + * @return <code>true</code> if the proposed interface is a VLAN on the interface or if it is the same name, + * <code>false</code> otherwise. + */ + public static boolean interfaceBasedOn(String proposedIface, String iface) { + return iface != null && proposedIface != null && iface.equals(StripVlan(proposedIface)); + } + public static boolean interfaceHasVlan(VdsNetworkInterface iface, List<VdsNetworkInterface> allIfaces) { for (VdsNetworkInterface i : allIfaces) { if (i.getVlanId() != null && NetworkUtils.StripVlan(i.getName()).equals(iface.getName())) { diff --git a/backend/manager/modules/utils/src/test/java/org/ovirt/engine/core/utils/NetworkUtilsTest.java b/backend/manager/modules/utils/src/test/java/org/ovirt/engine/core/utils/NetworkUtilsTest.java index 247cdc0..24722b8 100644 --- a/backend/manager/modules/utils/src/test/java/org/ovirt/engine/core/utils/NetworkUtilsTest.java +++ b/backend/manager/modules/utils/src/test/java/org/ovirt/engine/core/utils/NetworkUtilsTest.java @@ -1,8 +1,10 @@ package org.ovirt.engine.core.utils; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; import java.util.Collections; import java.util.Map; @@ -119,6 +121,44 @@ iface.getVlanId() + 1); } + @Test + public void interfaceBasedOn() { + String iface = RandomUtils.instance().nextNumericString(RandomUtils.instance().nextInt(1, 10)); + assertTrue(NetworkUtils.interfaceBasedOn(iface + "." + RandomUtils.instance().nextInt(100), iface)); + } + + @Test + public void interfaceBasedOnSameName() { + String iface = RandomUtils.instance().nextNumericString(RandomUtils.instance().nextInt(1, 10)); + assertTrue(NetworkUtils.interfaceBasedOn(iface, iface)); + } + + @Test + public void interfaceBasedOnNotAVlanOfIface() { + String iface1 = RandomUtils.instance().nextNumericString(RandomUtils.instance().nextInt(1, 10)); + String iface2 = RandomUtils.instance().nextNumericString(RandomUtils.instance().nextInt(1, 10)); + assertFalse(NetworkUtils.interfaceBasedOn(iface2 + "." + RandomUtils.instance().nextInt(100), iface1)); + } + + @Test + public void interfaceBasedOnNotAVlanAtAll() { + String iface1 = RandomUtils.instance().nextNumericString(RandomUtils.instance().nextInt(1, 10)); + String iface2 = RandomUtils.instance().nextNumericString(RandomUtils.instance().nextInt(1, 10)); + assertFalse(NetworkUtils.interfaceBasedOn(iface2, iface1)); + } + + @Test + public void interfaceBasedOnNullIface() { + String iface = RandomUtils.instance().nextNumericString(RandomUtils.instance().nextInt(1, 10)); + assertFalse(NetworkUtils.interfaceBasedOn(iface + "." + RandomUtils.instance().nextInt(100), null)); + } + + @Test + public void interfaceBasedOnNullProposedVlan() { + String iface = RandomUtils.instance().nextNumericString(RandomUtils.instance().nextInt(1, 10)); + assertFalse(NetworkUtils.interfaceBasedOn(null, iface)); + } + private void calculateNetworkImplementationDetailsAndAssertManaged(VdsNetworkInterface iface, boolean expectManaged, Map<String, Network> networks) { -- To view, visit http://gerrit.ovirt.org/7406 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ic479acc3179622b60efe921522dcb2115838557f Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Mike Kolesnik <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
