summaryrefslogtreecommitdiffstats
path: root/v3po/v3po2vpp/src/test/java
diff options
context:
space:
mode:
Diffstat (limited to 'v3po/v3po2vpp/src/test/java')
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/DisabledInterfacesManagerTest.java106
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/VxlanCustomizerTest.java24
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/VxlanGpeCustomizerTest.java5
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/InterfaceCustomizerTest.java30
4 files changed, 161 insertions, 4 deletions
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/DisabledInterfacesManagerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/DisabledInterfacesManagerTest.java
new file mode 100644
index 000000000..7381533e5
--- /dev/null
+++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/DisabledInterfacesManagerTest.java
@@ -0,0 +1,106 @@
+/*
+ * Copyright (c) 2016 Cisco and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.honeycomb.translate.v3po;
+
+import static org.hamcrest.CoreMatchers.hasItems;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.verify;
+
+import com.google.common.base.Optional;
+import io.fd.honeycomb.translate.MappingContext;
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.Collectors;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.context.rev160909.DisabledInterfaces;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.context.rev160909.DisabledInterfacesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.context.rev160909.disabled.interfaces.DisabledInterfaceIndex;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.context.rev160909.disabled.interfaces.DisabledInterfaceIndexBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.context.rev160909.disabled.interfaces.DisabledInterfaceIndexKey;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
+
+public class DisabledInterfacesManagerTest {
+
+ private static final InstanceIdentifier<DisabledInterfaces>
+ ROOT_ID = InstanceIdentifier.create(DisabledInterfaces.class);
+ private static final KeyedInstanceIdentifier<DisabledInterfaceIndex, DisabledInterfaceIndexKey> SPECIFIC_ID_1 =
+ ROOT_ID.child(DisabledInterfaceIndex.class, new DisabledInterfaceIndexKey(1));
+ private static final KeyedInstanceIdentifier<DisabledInterfaceIndex, DisabledInterfaceIndexKey> SPECIFIC_ID_4 =
+ ROOT_ID.child(DisabledInterfaceIndex.class, new DisabledInterfaceIndexKey(4));
+
+ @Mock
+ private MappingContext mappingContext;
+ private DisabledInterfacesManager manager;
+
+ @Before
+ public void setUp() throws Exception {
+ MockitoAnnotations.initMocks(this);
+ manager = new DisabledInterfacesManager();
+ doReturn(Optional.of(new DisabledInterfacesBuilder().setDisabledInterfaceIndex(toIndices(1, 2, 3)).build()))
+ .when(mappingContext)
+ .read(ROOT_ID);
+ doReturn(Optional.of(toIndex(1)))
+ .when(mappingContext)
+ .read(SPECIFIC_ID_1);
+ doReturn(Optional.absent())
+ .when(mappingContext)
+ .read(SPECIFIC_ID_4);
+ }
+
+ @Test
+ public void testGetAll() throws Exception {
+ final List<Integer> disabledInterfaces = manager.getDisabledInterfaces(mappingContext);
+ assertThat(disabledInterfaces, hasItems(1, 2, 3));
+ }
+
+ @Test
+ public void testCheckOne() throws Exception {
+ assertTrue(manager.isInterfaceDisabled(1, mappingContext));
+ assertFalse(manager.isInterfaceDisabled(4, mappingContext));
+ }
+
+ @Test
+ public void testDisable() throws Exception {
+ manager.disableInterface(1, mappingContext);
+ verify(mappingContext).put(SPECIFIC_ID_1, toIndex(1));
+ }
+
+ @Test
+ public void testRemoveDisability() throws Exception {
+ manager.removeDisabledInterface(1, mappingContext);
+ verify(mappingContext).delete(SPECIFIC_ID_1);
+ }
+
+ private List<DisabledInterfaceIndex> toIndices(final int... indices) {
+ return Arrays.stream(indices)
+ .mapToObj(this::toIndex)
+ .collect(Collectors.toList());
+ }
+
+ private DisabledInterfaceIndex toIndex(final int idx) {
+ return new DisabledInterfaceIndexBuilder()
+ .setIndex(idx)
+ .build();
+ }
+} \ No newline at end of file
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/VxlanCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/VxlanCustomizerTest.java
index 40a6b53bd..0d954deaa 100644
--- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/VxlanCustomizerTest.java
+++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/VxlanCustomizerTest.java
@@ -35,11 +35,12 @@ import static org.mockito.MockitoAnnotations.initMocks;
import com.google.common.base.Optional;
import com.google.common.net.InetAddresses;
-import io.fd.honeycomb.translate.write.WriteContext;
import io.fd.honeycomb.translate.MappingContext;
import io.fd.honeycomb.translate.ModificationCache;
+import io.fd.honeycomb.translate.v3po.DisabledInterfacesManager;
import io.fd.honeycomb.translate.v3po.test.TestHelperUtils;
import io.fd.honeycomb.translate.v3po.util.NamingContext;
+import io.fd.honeycomb.translate.write.WriteContext;
import io.fd.honeycomb.translate.write.WriteFailedException;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
@@ -80,6 +81,8 @@ public class VxlanCustomizerTest {
private WriteContext writeContext;
@Mock
private MappingContext mappingContext;
+ @Mock
+ private DisabledInterfacesManager disableContext;
private VxlanCustomizer customizer;
private String ifaceName;
@@ -96,7 +99,7 @@ public class VxlanCustomizerTest {
doReturn(toBeReturned).when(writeContext).getModificationCache();
doReturn(mappingContext).when(writeContext).getMappingContext();
- customizer = new VxlanCustomizer(api, namingContext);
+ customizer = new VxlanCustomizer(api, namingContext, disableContext);
ifaceName = "eth0";
id = InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(ifaceName))
@@ -175,6 +178,22 @@ public class VxlanCustomizerTest {
}
@Test
+ public void testWriteCurrentAttributesWithExistingVxlanPlaceholder() throws Exception {
+ final Vxlan vxlan = generateVxlan();
+
+ whenVxlanAddDelTunnelThenSuccess();
+
+ doReturn(Optional.absent())
+ .when(mappingContext).read(getMappingIid(ifaceName, "test-instance").firstIdentifierOf(Mappings.class));
+ doReturn(true).when(disableContext).isInterfaceDisabled(0, mappingContext);
+
+ customizer.writeCurrentAttributes(id, vxlan, writeContext);
+ verifyVxlanAddWasInvoked(vxlan);
+ verify(mappingContext).put(eq(getMappingIid(ifaceName, "test-instance")), eq(getMapping(ifaceName, 0).get()));
+ verify(disableContext).removeDisabledInterface(0, mappingContext);
+ }
+
+ @Test
public void testWriteCurrentAttributesMappingAlreadyPresent() throws Exception {
final Vxlan vxlan = generateVxlan();
@@ -231,6 +250,7 @@ public class VxlanCustomizerTest {
customizer.deleteCurrentAttributes(id, vxlan, writeContext);
verifyVxlanDeleteWasInvoked(vxlan);
verify(mappingContext).delete(eq(getMappingIid(ifaceName, "test-instance")));
+ verify(disableContext).disableInterface(1, mappingContext);
}
@Test
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/VxlanGpeCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/VxlanGpeCustomizerTest.java
index 09e32ffe9..35dacab56 100644
--- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/VxlanGpeCustomizerTest.java
+++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/VxlanGpeCustomizerTest.java
@@ -34,6 +34,7 @@ import static org.mockito.MockitoAnnotations.initMocks;
import com.google.common.base.Optional;
import com.google.common.net.InetAddresses;
import io.fd.honeycomb.translate.ModificationCache;
+import io.fd.honeycomb.translate.v3po.DisabledInterfacesManager;
import io.fd.honeycomb.translate.v3po.test.ContextTestUtils;
import io.fd.honeycomb.translate.v3po.test.TestHelperUtils;
import io.fd.honeycomb.translate.v3po.util.NamingContext;
@@ -80,6 +81,8 @@ public class VxlanGpeCustomizerTest {
private WriteContext writeContext;
@Mock
private MappingContext mappingContext;
+ @Mock
+ private DisabledInterfacesManager interfaceDisableContext;
private VxlanGpeCustomizer customizer;
private String ifaceName;
@@ -96,7 +99,7 @@ public class VxlanGpeCustomizerTest {
doReturn(toBeReturned).when(writeContext).getModificationCache();
doReturn(mappingContext).when(writeContext).getMappingContext();
- customizer = new VxlanGpeCustomizer(api, namingContext);
+ customizer = new VxlanGpeCustomizer(api, namingContext, interfaceDisableContext);
ifaceName = "eth0";
id = InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(ifaceName))
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/InterfaceCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/InterfaceCustomizerTest.java
index a9a2a3c74..f64d750fa 100644
--- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/InterfaceCustomizerTest.java
+++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/InterfaceCustomizerTest.java
@@ -28,6 +28,7 @@ import static org.mockito.Mockito.verifyZeroInteractions;
import com.google.common.base.Optional;
import com.google.common.collect.Lists;
import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
+import io.fd.honeycomb.translate.v3po.DisabledInterfacesManager;
import io.fd.honeycomb.translate.v3po.test.ContextTestUtils;
import io.fd.honeycomb.translate.v3po.test.InterfaceTestUtils;
import io.fd.honeycomb.translate.v3po.test.ListReaderCustomizerTest;
@@ -38,6 +39,7 @@ import java.util.List;
import org.junit.Assert;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
+import org.mockito.Mock;
import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.contexts.naming.context.Mappings;
import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.contexts.naming.context.MappingsBuilder;
import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.contexts.naming.context.mappings.Mapping;
@@ -57,6 +59,8 @@ public class InterfaceCustomizerTest extends
ListReaderCustomizerTest<Interface, InterfaceKey, InterfaceBuilder> {
private NamingContext interfacesContext;
+ @Mock
+ private DisabledInterfacesManager interfaceDisableContext;
public InterfaceCustomizerTest() {
super(Interface.class);
@@ -89,7 +93,7 @@ public class InterfaceCustomizerTest extends
doReturn(eth1).when(mappingContext).read(eth1Id);
doReturn(subEth1).when(mappingContext).read(subEth1Id);
- return new InterfaceCustomizer(api, interfacesContext);
+ return new InterfaceCustomizer(api, interfacesContext, interfaceDisableContext);
}
@Test
@@ -208,4 +212,28 @@ public class InterfaceCustomizerTest extends
// sub-interface should not be on the list
assertEquals(expectedIds, actualIds);
}
+
+ @Test
+ public void testGetAllIdsWithDisabled() throws Exception {
+ final InstanceIdentifier<Interface> id = InstanceIdentifier.create(InterfacesState.class)
+ .child(Interface.class);
+
+ doReturn(true).when(interfaceDisableContext).isInterfaceDisabled(1, mappingContext);
+
+ final String swIf0Name = "eth0";
+ final SwInterfaceDetails swIf0 = new SwInterfaceDetails();
+ swIf0.swIfIndex = 0;
+ swIf0.interfaceName = swIf0Name.getBytes();
+ final String swIf1Name = "eth1";
+ final SwInterfaceDetails swIf1 = new SwInterfaceDetails();
+ swIf1.swIfIndex = 1;
+ swIf1.interfaceName = swIf1Name.getBytes();
+ InterfaceTestUtils.whenSwInterfaceDumpThenReturn(api, Arrays.asList(swIf0, swIf1));
+
+ final List<InterfaceKey> expectedIds = Arrays.asList(new InterfaceKey(swIf0Name));
+ final List<InterfaceKey> actualIds = getCustomizer().getAllIds(id, ctx);
+
+ // disabled interface should not be on the list
+ assertEquals(expectedIds, actualIds);
+ }
}