Do not enforce augments in unsupported nodes 75/99575/3
authorRobert Varga <robert.varga@pantheon.tech>
Tue, 1 Feb 2022 12:28:53 +0000 (13:28 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Tue, 8 Feb 2022 09:10:21 +0000 (10:10 +0100)
If our parent uses node is not supported by features, we should not be
trying to enforce the augmentation dependency, as it will not be
present.

JIRA: YANGTOOLS-1393
Change-Id: I4b9cff536f4bbd33314f8befb1d70151a5f4f5de
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
parser/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/augment/AugmentInferenceAction.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/YT1393Test.java
parser/yang-parser-rfc7950/src/test/resources/bugs/YT1393/xyzzy.yang [new file with mode: 0644]

index 985b5e9855c8e03925af8daf12de3adc6d06a259..80f4e7e5db8f1d55fd28e45e1a208b74fa0bcc7e 100644 (file)
@@ -90,6 +90,11 @@ final class AugmentInferenceAction implements InferenceAction {
          * Do not fail, if it is an uses-augment to an unknown node.
          */
         if (YangStmtMapping.USES == augmentNode.coerceParentContext().publicDefinition()) {
+            if (!augmentNode.isSupportedToBuildEffective()) {
+                // We are not supported, hence the uses is not effective and we should bail
+                return;
+            }
+
             final SchemaNodeIdentifier augmentArg = augmentNode.getArgument();
             final Optional<StmtContext<?, ?, ?>> targetNode = SchemaTreeNamespace.findNode(
                 AbstractAugmentStatementSupport.getSearchRoot(augmentNode), augmentArg);
index 1e3976209d3fd73d75e39eefc2cbca46a373f004..ffe8d8b3b20d198c51c6dfa89ebcc1e4d79fcdae 100644 (file)
@@ -37,4 +37,12 @@ public class YT1393Test {
             .orElseThrow();
         assertEquals(5, module.effectiveSubstatements().size());
     }
+
+    @Test
+    public void testUsesAugmentInUnsupportedByFeatures() throws Exception {
+        final var module = StmtTestUtils.parseYangSource("/bugs/YT1393/xyzzy.yang", Set.of())
+            .findModuleStatement(QName.create("xyzzy", "xyzzy"))
+            .orElseThrow();
+        assertEquals(3, module.effectiveSubstatements().size());
+    }
 }
diff --git a/parser/yang-parser-rfc7950/src/test/resources/bugs/YT1393/xyzzy.yang b/parser/yang-parser-rfc7950/src/test/resources/bugs/YT1393/xyzzy.yang
new file mode 100644 (file)
index 0000000..7420d69
--- /dev/null
@@ -0,0 +1,22 @@
+module xyzzy {
+  namespace xyzzy;
+  prefix xyzzy;
+
+  feature bar;
+
+  grouping foo {
+    container foo;
+  }
+
+  container bar {
+    if-feature bar;
+
+    uses foo {
+      augment foo {
+        leaf foo {
+          type string;
+        }
+      }
+    }
+  }
+}