summaryrefslogtreecommitdiffstats
path: root/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/InterfaceRoutingCustomizerTest.java
diff options
context:
space:
mode:
authorJan Srnicek <jsrnicek@cisco.com>2017-05-15 14:41:25 +0200
committerMarek Gradzki <mgradzki@cisco.com>2017-05-15 13:12:49 +0000
commit400acf46ddab06a23a703f7d5b67cc4f5deeafe4 (patch)
tree5297889eafee26d3b3018f4461b10ed6bfaf9da4 /v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/InterfaceRoutingCustomizerTest.java
parent8e0b7b8b35c2efba5e48219318e6c5a8e48a6d4f (diff)
HC2VPP-151 - ip table reconfiguration while address present prevention
- fixed ordering - addresses must be written after vrf's - added check to prevent such scenario in multi-request scenario Change-Id: Idc233a8ac36fabef306339bfeec57bdc19b0f082 Signed-off-by: Jan Srnicek <jsrnicek@cisco.com>
Diffstat (limited to 'v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/InterfaceRoutingCustomizerTest.java')
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/InterfaceRoutingCustomizerTest.java60
1 files changed, 60 insertions, 0 deletions
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/InterfaceRoutingCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/InterfaceRoutingCustomizerTest.java
index 89c4cd1eb..4f7b4a659 100644
--- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/InterfaceRoutingCustomizerTest.java
+++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/InterfaceRoutingCustomizerTest.java
@@ -20,15 +20,24 @@ import static org.mockito.Matchers.any;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import com.google.common.base.Optional;
import io.fd.hc2vpp.common.test.write.WriterCustomizerTest;
import io.fd.hc2vpp.common.translate.util.NamingContext;
+import io.fd.honeycomb.translate.util.RWUtils;
import io.fd.honeycomb.translate.write.WriteFailedException;
import io.fd.vpp.jvpp.core.dto.SwInterfaceSetTable;
import io.fd.vpp.jvpp.core.dto.SwInterfaceSetTableReply;
+import java.util.Collections;
import org.junit.Test;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceBuilder;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceKey;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.Interface1;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.Interface1Builder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.Ipv4Builder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.Ipv6Builder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.AddressBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170315.VppInterfaceAugmentation;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170315.interfaces._interface.Routing;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170315.interfaces._interface.RoutingBuilder;
@@ -52,6 +61,7 @@ public class InterfaceRoutingCustomizerTest extends WriterCustomizerTest {
@Test
public void testWrite() throws WriteFailedException {
+ when(writeContext.readBefore(any(InstanceIdentifier.class))).thenReturn(Optional.absent());
final int vrfId = 123;
when(api.swInterfaceSetTable(any())).thenReturn(future(new SwInterfaceSetTableReply()));
customizer.writeCurrentAttributes(IID, routing(vrfId), writeContext);
@@ -60,18 +70,67 @@ public class InterfaceRoutingCustomizerTest extends WriterCustomizerTest {
@Test(expected = WriteFailedException.class)
public void testWriteFailed() throws WriteFailedException {
+ when(writeContext.readBefore(any(InstanceIdentifier.class))).thenReturn(Optional.absent());
when(api.swInterfaceSetTable(any())).thenReturn(failedFuture());
customizer.writeCurrentAttributes(IID, routing(213), writeContext);
}
+ @Test(expected = IllegalStateException.class)
+ public void testWriteFailedIpv4Present() throws WriteFailedException {
+ when(writeContext.readBefore(RWUtils.cutId(IID, Interface.class)))
+ .thenReturn(Optional.of(ifaceWithV4Address()));
+ customizer.writeCurrentAttributes(IID, routing(213), writeContext);
+ }
+
+ @Test(expected = IllegalStateException.class)
+ public void testWriteFailedIpv6Present() throws WriteFailedException {
+ when(writeContext.readBefore(RWUtils.cutId(IID, Interface.class)))
+ .thenReturn(Optional.of(ifaceWithV6Address()));
+ customizer.writeCurrentAttributes(IID, routing(213), writeContext);
+ }
+
+ @Test
+ public void testWriteEmptyIfaceData() throws WriteFailedException {
+ when(writeContext.readBefore(any(InstanceIdentifier.class))).thenReturn(Optional.of(new InterfaceBuilder().build()));
+ final int vrfId = 123;
+ when(api.swInterfaceSetTable(any())).thenReturn(future(new SwInterfaceSetTableReply()));
+ customizer.writeCurrentAttributes(IID, routing(vrfId), writeContext);
+ verify(api).swInterfaceSetTable(expectedRequest(vrfId));
+ }
+
+ private static Interface ifaceWithV4Address() {
+ return new InterfaceBuilder()
+ .addAugmentation(Interface1.class, new Interface1Builder()
+ .setIpv4(new Ipv4Builder()
+ .setAddress(Collections.singletonList(new AddressBuilder().build()))
+ .build())
+ .build())
+ .build();
+ }
+
+
+ private static Interface ifaceWithV6Address() {
+ return new InterfaceBuilder()
+ .addAugmentation(Interface1.class, new Interface1Builder()
+ .setIpv6(new Ipv6Builder()
+ .setAddress(Collections.singletonList(
+ new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv6.AddressBuilder()
+ .build()))
+ .build())
+ .build())
+ .build();
+ }
+
@Test(expected = WriteFailedException.class)
public void testUpdateFailed() throws WriteFailedException {
+ when(writeContext.readBefore(any(InstanceIdentifier.class))).thenReturn(Optional.absent());
when(api.swInterfaceSetTable(any())).thenReturn(failedFuture());
customizer.updateCurrentAttributes(IID, routing(123L), routing(321L), writeContext);
}
@Test
public void testDelete() throws WriteFailedException {
+ when(writeContext.readAfter(any(InstanceIdentifier.class))).thenReturn(Optional.absent());
when(api.swInterfaceSetTable(any())).thenReturn(future(new SwInterfaceSetTableReply()));
customizer.deleteCurrentAttributes(IID, routing(123), writeContext);
verify(api).swInterfaceSetTable(expectedRequest(0));
@@ -79,6 +138,7 @@ public class InterfaceRoutingCustomizerTest extends WriterCustomizerTest {
@Test(expected = WriteFailedException.DeleteFailedException.class)
public void testDeleteFailed() throws WriteFailedException {
+ when(writeContext.readAfter(any(InstanceIdentifier.class))).thenReturn(Optional.absent());
when(api.swInterfaceSetTable(any())).thenReturn(failedFuture());
customizer.deleteCurrentAttributes(IID, routing(123), writeContext);
}