summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Srnicek <jsrnicek@cisco.com>2016-12-02 09:37:22 +0100
committerMarek Gradzki <mgradzki@cisco.com>2016-12-02 13:47:21 +0000
commit7088e80deb3384c84cefca8f92e92722b1f19fe9 (patch)
treee64f8ca4c0213d642b0a2f41532b25cf45a9be92
parent14542744e674673847e6f671ee179eeee30b2d5a (diff)
HONEYCOMB-307 - Prevent re-mapping of already mapped names
Prevent invoking addName while initializing data for names that are already in mappings Change-Id: I56063fb28cfb215bbdb1ed745aaa44544ffa77a0 Signed-off-by: Jan Srnicek <jsrnicek@cisco.com>
-rw-r--r--routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/write/RoutingProtocolCustomizer.java9
-rw-r--r--routing/routing-impl/src/test/java/io/fd/hc2vpp/routing/helpers/RoutingRequestTestHelper.java1
-rw-r--r--routing/routing-impl/src/test/java/io/fd/hc2vpp/routing/write/RoutingProtocolCustomizerTest.java30
3 files changed, 36 insertions, 4 deletions
diff --git a/routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/write/RoutingProtocolCustomizer.java b/routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/write/RoutingProtocolCustomizer.java
index 220f07690..69b8e509e 100644
--- a/routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/write/RoutingProtocolCustomizer.java
+++ b/routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/write/RoutingProtocolCustomizer.java
@@ -61,9 +61,12 @@ public class RoutingProtocolCustomizer
// while using ip_add_del_table
routingProtocolContext.addName(tableId, newProtocolName, mappingContext);
} else {
- throw new IllegalStateException(String.format(
- "An attempt to assign protocol %s to table id %s. Table id already assigned to protocol %s",
- newProtocolName, tableId, routingProtocolContext.getName(tableId, mappingContext)));
+ // prevent to fail while restoring data(trying to remap already mapped name)
+ if (!newProtocolName.equals(routingProtocolContext.getName(tableId, mappingContext))) {
+ throw new IllegalStateException(String.format(
+ "An attempt to assign protocol %s to table id %s. Table id already assigned to protocol %s",
+ newProtocolName, tableId, routingProtocolContext.getName(tableId, mappingContext)));
+ }
}
}
}
diff --git a/routing/routing-impl/src/test/java/io/fd/hc2vpp/routing/helpers/RoutingRequestTestHelper.java b/routing/routing-impl/src/test/java/io/fd/hc2vpp/routing/helpers/RoutingRequestTestHelper.java
index bcb8e6800..a13364db8 100644
--- a/routing/routing-impl/src/test/java/io/fd/hc2vpp/routing/helpers/RoutingRequestTestHelper.java
+++ b/routing/routing-impl/src/test/java/io/fd/hc2vpp/routing/helpers/RoutingRequestTestHelper.java
@@ -39,6 +39,7 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.rev
public interface RoutingRequestTestHelper extends ByteDataTranslator, FutureProducer, RouteMapper {
String ROUTE_PROTOCOL_NAME = "tst-protocol";
+ String ROUTE_PROTOCOL_NAME_2 = "tst-protocol-2";
String ROUTE_NAME = "tst-route";
String STATIC_ROUTE_PATH = "/ietf-routing:routing" +
"/ietf-routing:routing-instance[ietf-routing:name='" + ROUTE_PROTOCOL_NAME + "']" +
diff --git a/routing/routing-impl/src/test/java/io/fd/hc2vpp/routing/write/RoutingProtocolCustomizerTest.java b/routing/routing-impl/src/test/java/io/fd/hc2vpp/routing/write/RoutingProtocolCustomizerTest.java
index d734aab66..21a2bdc14 100644
--- a/routing/routing-impl/src/test/java/io/fd/hc2vpp/routing/write/RoutingProtocolCustomizerTest.java
+++ b/routing/routing-impl/src/test/java/io/fd/hc2vpp/routing/write/RoutingProtocolCustomizerTest.java
@@ -17,6 +17,7 @@
package io.fd.hc2vpp.routing.write;
import static io.fd.hc2vpp.routing.helpers.RoutingRequestTestHelper.ROUTE_PROTOCOL_NAME;
+import static io.fd.hc2vpp.routing.helpers.RoutingRequestTestHelper.ROUTE_PROTOCOL_NAME_2;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@@ -39,6 +40,7 @@ public class RoutingProtocolCustomizerTest extends WriterCustomizerTest {
private InstanceIdentifier<RoutingProtocol> validId;
private RoutingProtocol validData;
+ private RoutingProtocol validData2;
private RoutingProtocol invalidData;
private RoutingProtocolCustomizer customizer;
private NamingContext routingProtocolContext;
@@ -56,6 +58,16 @@ public class RoutingProtocolCustomizerTest extends WriterCustomizerTest {
.build())
.build();
+ validData2= new RoutingProtocolBuilder()
+ .setName(ROUTE_PROTOCOL_NAME_2)
+ .setType(Static.class)
+ .addAugmentation(RoutingProtocolVppAttr.class, new RoutingProtocolVppAttrBuilder()
+ .setVppProtocolAttributes(new VppProtocolAttributesBuilder()
+ .setPrimaryVrf(new VniReference(1L))
+ .build())
+ .build())
+ .build();
+
invalidData = new RoutingProtocolBuilder()
.setType(Direct.class)
.build();
@@ -74,12 +86,28 @@ public class RoutingProtocolCustomizerTest extends WriterCustomizerTest {
}
}
+ /**
+ * Should not fail, just ignore re-mapping same name
+ * */
@Test
- public void testWriteIsStaticAllreadyExist() throws WriteFailedException {
+ public void testWriteIsStaticSameAllreadyExist() throws WriteFailedException {
defineMapping(mappingContext, ROUTE_PROTOCOL_NAME, 1, "routing-protocol-context");
try {
customizer.writeCurrentAttributes(validId, validData, writeContext);
} catch (Exception e) {
+ fail("Test should have passed without throwing exception");
+ }
+ }
+
+ /**
+ * Should fail, because of attempt to map different name to same index
+ * */
+ @Test
+ public void testWriteIsStaticOtherAllreadyExist() throws WriteFailedException {
+ defineMapping(mappingContext, ROUTE_PROTOCOL_NAME, 1, "routing-protocol-context");
+ try {
+ customizer.writeCurrentAttributes(validId, validData2, writeContext);
+ } catch (Exception e) {
assertTrue(e instanceof IllegalStateException);
return;
}