Fix SchemaTreeNamespace population via augment 54/100154/2
authorSangwook Ha <sangwook.ha@verizon.com>
Wed, 16 Mar 2022 16:39:14 +0000 (09:39 -0700)
committerRobert Varga <robert.varga@pantheon.tech>
Sat, 19 Mar 2022 15:01:51 +0000 (16:01 +0100)
This change adds 4 test cases to reproduce:
  - Deviation of a case node with case statement
  - Deviation of a case node without case statement
  - Deviation of an augmented case node with case statement
  - Deviation of an augmented case node without case statement

The only test case fails is the last one (deviation of an augmented
case node without case statement). There is another way to depreduce
the root cause, which is to use 'augment' instead of deviate.

The problem is that the implicit case statement does not trigger
onStatementAdded() and hence it does not get registered in the
namespace.

Fixing this issue changes behaviour in testDuplicityInAugmentTarget2(),
i.e. the schema tree overlap previously reported through
SchemaTreeIndexingException (when we are already building effective
view) gets flagged earlier with a SourceException, pointing to both the
place where the conflict occurs and which source statement is causing
it.

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

parser/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/StatementContextBase.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/YT1408Test.java [new file with mode: 0644]
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/YangParserNegativeTest.java
parser/yang-parser-rfc7950/src/test/resources/bugs/YT1408/aug-choice-case-deviate-case/deviate.yang [new file with mode: 0644]
parser/yang-parser-rfc7950/src/test/resources/bugs/YT1408/aug-choice-case-deviate-case/orig.yang [new file with mode: 0644]
parser/yang-parser-rfc7950/src/test/resources/bugs/YT1408/aug-choice-deviate-case/deviate.yang [new file with mode: 0644]
parser/yang-parser-rfc7950/src/test/resources/bugs/YT1408/aug-choice-deviate-case/orig.yang [new file with mode: 0644]
parser/yang-parser-rfc7950/src/test/resources/bugs/YT1408/choice-case-deviate-case/deviate.yang [new file with mode: 0644]
parser/yang-parser-rfc7950/src/test/resources/bugs/YT1408/choice-case-deviate-case/orig.yang [new file with mode: 0644]
parser/yang-parser-rfc7950/src/test/resources/bugs/YT1408/choice-deviate-case/deviate.yang [new file with mode: 0644]
parser/yang-parser-rfc7950/src/test/resources/bugs/YT1408/choice-deviate-case/orig.yang [new file with mode: 0644]

index 4f6ab2363ccba802a92458677f92e7a74db08f5e..2e0a591b8e16746da64eff7029ef3055c0872787 100644 (file)
@@ -848,6 +848,7 @@ public abstract class StatementContextBase<A, D extends DeclaredStatement<A>, E
 
             copy = new InferredStatementContext<>(result, original, childCopyType, type, targetModule);
             result.addEffectiveSubstatement(copy);
+            result.definition.onStatementAdded(result);
         } else {
             result = copy = new InferredStatementContext<>(this, original, type, type, targetModule);
         }
diff --git a/parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/YT1408Test.java b/parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/YT1408Test.java
new file mode 100644 (file)
index 0000000..f147e43
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2022 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.Test;
+
+public class YT1408Test {
+    @Test
+    public void testChoiceCaseDeviateCase() throws Exception {
+        StmtTestUtils.parseYangSources("/bugs/YT1408/choice-case-deviate-case");
+    }
+
+    @Test
+    public void testChoiceDeviateCase() throws Exception {
+        StmtTestUtils.parseYangSources("/bugs/YT1408/choice-deviate-case");
+    }
+
+    @Test
+    public void testAugmentChoiceCaseDeviateCase() throws Exception {
+        StmtTestUtils.parseYangSources("/bugs/YT1408/aug-choice-case-deviate-case");
+    }
+
+    @Test
+    public void testAugmentChoiceDeviateCase() throws Exception {
+        StmtTestUtils.parseYangSources("/bugs/YT1408/aug-choice-deviate-case");
+    }
+}
index 104a4270523bc41b7cbf26355096544ecd99d45d..5d94cda9914842a4fd4cb9b229bc453d39672909 100644 (file)
@@ -7,7 +7,9 @@
  */
 package org.opendaylight.yangtools.yang.stmt;
 
+import static org.hamcrest.CoreMatchers.allOf;
 import static org.hamcrest.CoreMatchers.containsString;
+import static org.hamcrest.CoreMatchers.endsWith;
 import static org.hamcrest.CoreMatchers.startsWith;
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.Matchers.isA;
@@ -15,7 +17,6 @@ import static org.junit.Assert.assertThrows;
 
 import com.google.common.base.Throwables;
 import org.junit.Test;
-import org.opendaylight.yangtools.yang.model.spi.meta.SubstatementIndexingException;
 import org.opendaylight.yangtools.yang.parser.spi.meta.InferenceException;
 import org.opendaylight.yangtools.yang.parser.spi.meta.SomeModifiersUnresolvedException;
 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
@@ -142,9 +143,12 @@ public class YangParserNegativeTest {
             () -> TestUtils.loadModuleResources(getClass(),
                 "/negative-scenario/duplicity/augment0.yang", "/negative-scenario/duplicity/augment2.yang"));
         final Throwable rootCause = Throwables.getRootCause(ex);
-        assertThat(rootCause, isA(SubstatementIndexingException.class));
-        assertThat(rootCause.getMessage(), containsString("Cannot add schema tree child with name "
-            + "(urn:simple.augment2.demo?revision=2014-06-02)delta, a conflicting child already exists"));
+        assertThat(rootCause, isA(SourceException.class));
+        assertThat(rootCause.getMessage(), allOf(
+            startsWith("Error in module 'augment0': cannot add "
+                + "'(urn:simple.augment2.demo?revision=2014-06-02)delta'. Node name collision: "
+                + "'(urn:simple.augment2.demo?revision=2014-06-02)delta' already declared at "),
+            endsWith("duplicity/augment2.yang:17:9]")));
     }
 
     @Test
diff --git a/parser/yang-parser-rfc7950/src/test/resources/bugs/YT1408/aug-choice-case-deviate-case/deviate.yang b/parser/yang-parser-rfc7950/src/test/resources/bugs/YT1408/aug-choice-case-deviate-case/deviate.yang
new file mode 100644 (file)
index 0000000..a8fd026
--- /dev/null
@@ -0,0 +1,12 @@
+module deviate {
+    namespace "urn:deviate";
+    prefix dev;
+
+    import orig {
+        prefix orig;
+    }
+
+    deviation /orig:foo/orig:bar/orig:bar2 {
+        deviate not-supported;
+    }
+}
diff --git a/parser/yang-parser-rfc7950/src/test/resources/bugs/YT1408/aug-choice-case-deviate-case/orig.yang b/parser/yang-parser-rfc7950/src/test/resources/bugs/YT1408/aug-choice-case-deviate-case/orig.yang
new file mode 100644 (file)
index 0000000..77c2a90
--- /dev/null
@@ -0,0 +1,22 @@
+module orig {
+    namespace "urn:orig";
+    prefix orig;
+
+    container foo {
+        choice bar {
+            case bar1 {
+                leaf bar1 {
+                    type string;
+                }
+            }
+        }
+    }
+
+    augment /foo/bar {
+        case bar2 {
+            leaf bar2 {
+                type string;
+            }
+        }
+    }
+}
diff --git a/parser/yang-parser-rfc7950/src/test/resources/bugs/YT1408/aug-choice-deviate-case/deviate.yang b/parser/yang-parser-rfc7950/src/test/resources/bugs/YT1408/aug-choice-deviate-case/deviate.yang
new file mode 100644 (file)
index 0000000..a8fd026
--- /dev/null
@@ -0,0 +1,12 @@
+module deviate {
+    namespace "urn:deviate";
+    prefix dev;
+
+    import orig {
+        prefix orig;
+    }
+
+    deviation /orig:foo/orig:bar/orig:bar2 {
+        deviate not-supported;
+    }
+}
diff --git a/parser/yang-parser-rfc7950/src/test/resources/bugs/YT1408/aug-choice-deviate-case/orig.yang b/parser/yang-parser-rfc7950/src/test/resources/bugs/YT1408/aug-choice-deviate-case/orig.yang
new file mode 100644 (file)
index 0000000..b0596cb
--- /dev/null
@@ -0,0 +1,18 @@
+module orig {
+    namespace "urn:orig";
+    prefix orig;
+
+    container foo {
+        choice bar {
+            leaf bar1 {
+                type string;
+            }
+        }
+    }
+
+    augment /foo/bar {
+        leaf bar2 {
+            type string;
+        }
+    }
+}
diff --git a/parser/yang-parser-rfc7950/src/test/resources/bugs/YT1408/choice-case-deviate-case/deviate.yang b/parser/yang-parser-rfc7950/src/test/resources/bugs/YT1408/choice-case-deviate-case/deviate.yang
new file mode 100644 (file)
index 0000000..a8fd026
--- /dev/null
@@ -0,0 +1,12 @@
+module deviate {
+    namespace "urn:deviate";
+    prefix dev;
+
+    import orig {
+        prefix orig;
+    }
+
+    deviation /orig:foo/orig:bar/orig:bar2 {
+        deviate not-supported;
+    }
+}
diff --git a/parser/yang-parser-rfc7950/src/test/resources/bugs/YT1408/choice-case-deviate-case/orig.yang b/parser/yang-parser-rfc7950/src/test/resources/bugs/YT1408/choice-case-deviate-case/orig.yang
new file mode 100644 (file)
index 0000000..1c3b873
--- /dev/null
@@ -0,0 +1,19 @@
+module orig {
+    namespace "urn:orig";
+    prefix orig;
+
+    container foo {
+        choice bar {
+            case bar1 {
+                leaf bar1 {
+                    type string;
+                }
+            }
+            case bar2 {
+                leaf bar2 {
+                    type string;
+                }
+            }
+        }
+    }
+}
diff --git a/parser/yang-parser-rfc7950/src/test/resources/bugs/YT1408/choice-deviate-case/deviate.yang b/parser/yang-parser-rfc7950/src/test/resources/bugs/YT1408/choice-deviate-case/deviate.yang
new file mode 100644 (file)
index 0000000..a8fd026
--- /dev/null
@@ -0,0 +1,12 @@
+module deviate {
+    namespace "urn:deviate";
+    prefix dev;
+
+    import orig {
+        prefix orig;
+    }
+
+    deviation /orig:foo/orig:bar/orig:bar2 {
+        deviate not-supported;
+    }
+}
diff --git a/parser/yang-parser-rfc7950/src/test/resources/bugs/YT1408/choice-deviate-case/orig.yang b/parser/yang-parser-rfc7950/src/test/resources/bugs/YT1408/choice-deviate-case/orig.yang
new file mode 100644 (file)
index 0000000..cd7fccf
--- /dev/null
@@ -0,0 +1,15 @@
+module orig {
+    namespace "urn:orig";
+    prefix orig;
+
+    container foo {
+        choice bar {
+            leaf bar1 {
+                type string;
+            }
+            leaf bar2 {
+                type string;
+            }
+        }
+    }
+}