Augments should get disabled if target is unsupported 58/99058/3
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 24 Nov 2021 10:43:31 +0000 (11:43 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Fri, 17 Dec 2021 12:42:53 +0000 (13:42 +0100)
AugmentInferenceAction should pay attention to unavailable target
nodes, so we disable the augmentation.

JIRA: YANGTOOLS-1370
Change-Id: Ib1f0bde83a90e4bb45a7c4fa1fc62af205f4ea6c
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
(cherry picked from commit 43fb7cd8d8bd9330988c02566ef376d00eb7b461)
(cherry picked from commit 6f56510d0c0706a7b4a3e02c893e9e2eaccd09be)

yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/augment/AbstractAugmentStatementSupport.java
yang/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/YT1370Test.java [new file with mode: 0644]
yang/yang-parser-rfc7950/src/test/resources/bugs/YT1370/foo.yang [new file with mode: 0644]

index 5c85334c3cdaf196a7fe16bf0e9df12f60de89f7..36ea6f506ddbc9e6bfa9c97535ad5fbc4f0108c5 100644 (file)
@@ -97,6 +97,11 @@ abstract class AbstractAugmentStatementSupport
         augmentAction.apply(new InferenceAction() {
             @Override
             public void apply(final InferenceContext ctx) {
+                if (!augmentNode.isSupportedToBuildEffective()) {
+                    // We are not building effective model, hence we should not be performing any effects
+                    return;
+                }
+
                 final StatementContextBase<?, ?, ?> augmentTargetCtx =
                         (StatementContextBase<?, ?, ?>) target.resolve(ctx);
                 if (!isSupportedAugmentTarget(augmentTargetCtx)
@@ -144,6 +149,15 @@ abstract class AbstractAugmentStatementSupport
                 throw new InferenceException(augmentNode.getStatementSourceReference(),
                         "Augment target '%s' not found", augmentNode.getStatementArgument());
             }
+
+            @Override
+            public void prerequisiteUnavailable(final Prerequisite<?> unavail) {
+                if (target.equals(unavail)) {
+                    augmentNode.setIsSupportedToBuildEffective(false);
+                } else {
+                    prerequisiteFailed(List.of(unavail));
+                }
+            }
         });
     }
 
diff --git a/yang/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/YT1370Test.java b/yang/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/YT1370Test.java
new file mode 100644 (file)
index 0000000..debf3eb
--- /dev/null
@@ -0,0 +1,21 @@
+/*
+ * Copyright (c) 2021 PANTHEON.tech, s.r.o. 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 static org.junit.Assert.assertNotNull;
+
+import java.util.Set;
+import org.junit.Test;
+import org.opendaylight.yangtools.yang.model.repo.api.StatementParserMode;
+
+public class YT1370Test {
+    @Test
+    public void testAugmentUnsupportedByFeatures() throws Exception {
+        assertNotNull(StmtTestUtils.parseYangSources("/bugs/YT1370", Set.of(), StatementParserMode.DEFAULT_MODE));
+    }
+}
diff --git a/yang/yang-parser-rfc7950/src/test/resources/bugs/YT1370/foo.yang b/yang/yang-parser-rfc7950/src/test/resources/bugs/YT1370/foo.yang
new file mode 100644 (file)
index 0000000..20446ae
--- /dev/null
@@ -0,0 +1,14 @@
+module foo {
+  prefix foo;
+  namespace foo;
+
+  feature foo;
+
+  container foo {
+    if-feature foo;
+  }
+
+  augment /foo {
+    container bar;
+  }
+}