Fix IidCodec broken by new yangtools 91/67191/3
authorVishal Thapar <vishal.thapar@ericsson.com>
Tue, 16 Jan 2018 06:42:09 +0000 (12:12 +0530)
committerStephen Kitt <skitt@redhat.com>
Tue, 16 Jan 2018 10:14:39 +0000 (11:14 +0100)
There are multiple versions of network-topology loaded
and yangtools can't tell which one to use. It has ramifications
beyond just OVSDB, but this fixes functionality issues in
OVSDB.

Root issue is two different files with different versions
bundled together. It may not have been issue earlier but is now.

Change-Id: Ibc7f8387c5b84cb6e1c0e8a69454acb661a4acc4
Signed-off-by: Vishal Thapar <vishal.thapar@ericsson.com>
Signed-off-by: Stephen Kitt <skitt@redhat.com>
southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/InstanceIdentifierCodec.java
southbound/southbound-impl/src/test/java/org/opendaylight/ovsdb/southbound/InstanceIdentifierCodecTest.java

index 6e4d456dbf7250b0e2044b9eed0eec88558840cc..0b2d188133b41fc68678e67fcef35340c37ded7a 100644 (file)
@@ -10,10 +10,10 @@ package org.opendaylight.ovsdb.southbound;
 
 import java.net.URI;
 
-import java.util.Optional;
 import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer;
 import org.opendaylight.mdsal.dom.api.DOMSchemaService;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.common.Revision;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.impl.codec.DeserializationException;
 import org.opendaylight.yangtools.yang.data.util.AbstractModuleStringInstanceIdentifierCodec;
@@ -28,6 +28,7 @@ public class InstanceIdentifierCodec extends AbstractModuleStringInstanceIdentif
     implements SchemaContextListener {
 
     private static final Logger LOG = LoggerFactory.getLogger(InstanceIdentifierCodec.class);
+    private static final Revision REVISION = Revision.of("2013-10-21");
 
     private DataSchemaContextTree dataSchemaContextTree;
     private SchemaContext context;
@@ -46,12 +47,12 @@ public class InstanceIdentifierCodec extends AbstractModuleStringInstanceIdentif
 
     @Override
     protected Module moduleForPrefix(final String prefix) {
-        return context.findModule(prefix, Optional.empty()).orElse(null);
+        return context.findModule(prefix, REVISION).orElse(null);
     }
 
     @Override
     protected String prefixForNamespace(final URI namespace) {
-        return context.findModule(namespace, Optional.empty()).map(Module::getName).orElse(null);
+        return context.findModule(namespace, REVISION).map(Module::getName).orElse(null);
     }
 
     @Override
index f24946e3ecddc304e8dc41f30224910ad9d2e3ae..101a62c9a51c79551973ed698060a9f47d9126ec 100644 (file)
@@ -28,6 +28,7 @@ import org.mockito.stubbing.Answer;
 import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer;
 import org.opendaylight.mdsal.dom.api.DOMSchemaService;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.common.Revision;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.util.AbstractModuleStringInstanceIdentifierCodec;
 import org.opendaylight.yangtools.yang.data.util.DataSchemaContextTree;
@@ -75,7 +76,7 @@ public class InstanceIdentifierCodecTest {
     @Test
     public void testModuleForPrefix() {
         Module module = mock(Module.class);
-        when(context.findModule(anyString(), any(Optional.class))).thenReturn(Optional.of(module));
+        when(context.findModule(anyString(), any(Revision.class))).thenReturn(Optional.of(module));
         assertEquals("Error, did not return correct Module object", module, instanceIdCodec.moduleForPrefix(""));
     }
 
@@ -83,7 +84,7 @@ public class InstanceIdentifierCodecTest {
     public void testPrefixForNamespace() throws URISyntaxException {
         Module module = mock(Module.class);
         URI namespace = new URI("");
-        when(context.findModule(any(URI.class), any(Optional.class))).thenReturn(Optional.empty()).thenReturn(
+        when(context.findModule(any(URI.class), any(Revision.class))).thenReturn(Optional.empty()).thenReturn(
                 Optional.of(module));
         when(module.getName()).thenReturn("");
         assertEquals("Error, null should have been returned", null, instanceIdCodec.prefixForNamespace(namespace));