Check requested schema tree statement namespace 92/104892/2
authorSangwook Ha <sangwook.ha@verizon.com>
Fri, 27 Jan 2023 22:24:14 +0000 (14:24 -0800)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 15 Mar 2023 17:56:15 +0000 (18:56 +0100)
When we have a reactor when two children of an InferredStatementContext
differ only in namespace, we cannot blindly service
requestSchemaTreeChild().

Check whether the namespaces match, as we can only materialize
statements that match our targetModule.

JIRA: YANGTOOLS-1480
Change-Id: I4d9c6e6361fe2d5383e6de43e3c1bb54bac4e935
Signed-off-by: Sangwook Ha <sangwook.ha@verizon.com>
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
(cherry picked from commit a9bdd9337094457150a89f630dedd21d70177a90)

parser/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/InferredStatementContext.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/YT1480Test.java [new file with mode: 0644]
parser/yang-parser-rfc7950/src/test/resources/bugs/YT1480/bar.yang [new file with mode: 0644]
parser/yang-parser-rfc7950/src/test/resources/bugs/YT1480/baz.yang [new file with mode: 0644]
parser/yang-parser-rfc7950/src/test/resources/bugs/YT1480/foo.yang [new file with mode: 0644]
parser/yang-parser-rfc7950/src/test/resources/bugs/YT1480/qux.yang [new file with mode: 0644]

index ba888efc4b9131916ed9486c2da2d14481d1d154..011603fc1905234afd46bf4190203d4d4385b316 100644 (file)
@@ -426,7 +426,22 @@ final class InferredStatementContext<A, D extends DeclaredStatement<A>, E extend
             return null;
         }
 
-        final QName templateQName = qname.bindTo(StmtContextUtils.getRootModuleQName(prototype));
+        // Determine if the requested QName can be satisfied from the prototype: for that to happen it has to match
+        // our transformation implied by targetModule.
+        final var requestedNamespace = qname.getModule();
+        final QName templateQName;
+        if (targetModule != null) {
+            if (!targetModule.equals(requestedNamespace)) {
+                return null;
+            }
+            templateQName = qname.bindTo(StmtContextUtils.getRootModuleQName(prototype));
+        } else {
+            if (!StmtContextUtils.getRootModuleQName(prototype).equals(requestedNamespace)) {
+                return null;
+            }
+            templateQName = qname;
+        }
+
         LOG.debug("Materializing child {} from {}", qname, templateQName);
 
         final StmtContext<?, ?, ?> template;
diff --git a/parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/YT1480Test.java b/parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/YT1480Test.java
new file mode 100644 (file)
index 0000000..5dc0b88
--- /dev/null
@@ -0,0 +1,17 @@
+/*
+ * Copyright (c) 2023 Verizon and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.yang.stmt;
+
+import org.junit.jupiter.api.Test;
+
+public class YT1480Test extends AbstractYangTest {
+    @Test
+    public void testReplaceAndDeviateNode() {
+        assertEffectiveModelDir("/bugs/YT1480");
+    }
+}
diff --git a/parser/yang-parser-rfc7950/src/test/resources/bugs/YT1480/bar.yang b/parser/yang-parser-rfc7950/src/test/resources/bugs/YT1480/bar.yang
new file mode 100644 (file)
index 0000000..59aff9a
--- /dev/null
@@ -0,0 +1,12 @@
+module bar {
+  namespace "urn:bar";
+  prefix "bar";
+
+  import foo {
+    prefix foo;
+  }
+
+  deviation /foo:foo/foo:cntr {
+    deviate not-supported;
+  }
+}
diff --git a/parser/yang-parser-rfc7950/src/test/resources/bugs/YT1480/baz.yang b/parser/yang-parser-rfc7950/src/test/resources/bugs/YT1480/baz.yang
new file mode 100644 (file)
index 0000000..4214c4b
--- /dev/null
@@ -0,0 +1,16 @@
+module baz {
+  namespace "urn:baz";
+  prefix "baz";
+
+  import foo {
+    prefix foo;
+  }
+
+  augment /foo:foo {
+    container cntr {
+      leaf baz-leaf {
+        type string;
+      }
+    }
+  }
+}
diff --git a/parser/yang-parser-rfc7950/src/test/resources/bugs/YT1480/foo.yang b/parser/yang-parser-rfc7950/src/test/resources/bugs/YT1480/foo.yang
new file mode 100644 (file)
index 0000000..bfc4861
--- /dev/null
@@ -0,0 +1,12 @@
+module foo {
+  namespace "urn:foo";
+  prefix "foo";
+
+  grouping foo-group {
+    container foo {
+      container cntr;
+    }
+  }
+
+  uses foo-group;
+}
diff --git a/parser/yang-parser-rfc7950/src/test/resources/bugs/YT1480/qux.yang b/parser/yang-parser-rfc7950/src/test/resources/bugs/YT1480/qux.yang
new file mode 100644 (file)
index 0000000..906823f
--- /dev/null
@@ -0,0 +1,18 @@
+module qux {
+  namespace "urn:qux";
+  prefix "qux";
+
+  import foo {
+    prefix foo;
+  }
+
+  import baz {
+    prefix baz;
+  }
+
+  deviation /foo:foo/baz:cntr/baz:baz-leaf {
+    deviate add {
+      default "baz";
+    }
+  }
+}