Deviations should get disabled if target is unsupported 60/99060/2
authorRobert Varga <robert.varga@pantheon.tech>
Fri, 17 Dec 2021 07:16:25 +0000 (08:16 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Fri, 17 Dec 2021 12:43:10 +0000 (13:43 +0100)
Deviate's InferenceAction should pay attention to unavailable target
nodes, so we disable the deviation.

JIRA: YANGTOOLS-1370
Change-Id: Id0d8c3a64f91060cb21e807402742341ea98f492
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
(cherry picked from commit 70a13e29e0bec19bd48bd3fe48102a465294caf2)
(cherry picked from commit 298e7fb20a7b4c08598e2d59c5a30ae28b484ba1)

yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/deviate/AbstractDeviateStatementSupport.java
yang/yang-parser-rfc7950/src/test/resources/rfc7950/YT1370/dev.yang [new file with mode: 0644]

index 0ce5325f848f971f04407e14e38b9785717a435a..f50df45df4b38e5de9f145dc7da37720e65658ba 100644 (file)
@@ -16,6 +16,7 @@ import com.google.common.collect.SetMultimap;
 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
 import java.util.Arrays;
 import java.util.Collection;
+import java.util.List;
 import java.util.Objects;
 import java.util.Set;
 import org.opendaylight.yangtools.yang.common.QNameModule;
@@ -135,6 +136,11 @@ abstract class AbstractDeviateStatementSupport
         deviateAction.apply(new InferenceAction() {
             @Override
             public void apply(final InferenceContext ctx) {
+                if (!deviateStmtCtx.isSupportedToBuildEffective()) {
+                    // We are not building effective model, hence we should not be performing any effects
+                    return;
+                }
+
                 // FIXME once BUG-7760 gets fixed, there will be no need for these dirty casts
                 final StatementContextBase<?, ?, ?> sourceNodeStmtCtx =
                         (StatementContextBase<?, ?, ?>) sourceCtxPrerequisite.resolve(ctx);
@@ -164,6 +170,15 @@ abstract class AbstractDeviateStatementSupport
                 throw new InferenceException(deviateStmtCtx.coerceParentContext().getStatementSourceReference(),
                     "Deviation target '%s' not found.", deviationTarget);
             }
+
+            @Override
+            public void prerequisiteUnavailable(final Prerequisite<?> unavail) {
+                if (targetCtxPrerequisite.equals(unavail)) {
+                    deviateStmtCtx.setIsSupportedToBuildEffective(false);
+                } else {
+                    prerequisiteFailed(List.of(unavail));
+                }
+            }
         });
     }
 
diff --git a/yang/yang-parser-rfc7950/src/test/resources/rfc7950/YT1370/dev.yang b/yang/yang-parser-rfc7950/src/test/resources/rfc7950/YT1370/dev.yang
new file mode 100644 (file)
index 0000000..d079e58
--- /dev/null
@@ -0,0 +1,12 @@
+module dev {
+  prefix dev;
+  namespace dev;
+
+  import foo {
+    prefix foo;
+  }
+
+  deviation /foo:foo/foo:bar {
+    deviate not-supported;
+  }
+}