From 14841c1a9091015db2393bc8d1dc76e3cfcde520 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Wed, 24 Nov 2021 11:43:31 +0100 Subject: [PATCH] Augments should get disabled if target is unsupported AugmentInferenceAction should pay attention to unavailable target nodes, so we disable the augmentation. JIRA: YANGTOOLS-1370 Change-Id: Ib1f0bde83a90e4bb45a7c4fa1fc62af205f4ea6c Signed-off-by: Robert Varga (cherry picked from commit 43fb7cd8d8bd9330988c02566ef376d00eb7b461) (cherry picked from commit 6f56510d0c0706a7b4a3e02c893e9e2eaccd09be) --- .../AbstractAugmentStatementSupport.java | 14 +++++++++++++ .../yangtools/yang/stmt/YT1370Test.java | 21 +++++++++++++++++++ .../src/test/resources/bugs/YT1370/foo.yang | 14 +++++++++++++ 3 files changed, 49 insertions(+) create mode 100644 yang/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/YT1370Test.java create mode 100644 yang/yang-parser-rfc7950/src/test/resources/bugs/YT1370/foo.yang diff --git a/yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/augment/AbstractAugmentStatementSupport.java b/yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/augment/AbstractAugmentStatementSupport.java index 5c85334c3c..36ea6f506d 100644 --- a/yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/augment/AbstractAugmentStatementSupport.java +++ b/yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/augment/AbstractAugmentStatementSupport.java @@ -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 index 0000000000..debf3eb2ec --- /dev/null +++ b/yang/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/YT1370Test.java @@ -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 index 0000000000..20446ae023 --- /dev/null +++ b/yang/yang-parser-rfc7950/src/test/resources/bugs/YT1370/foo.yang @@ -0,0 +1,14 @@ +module foo { + prefix foo; + namespace foo; + + feature foo; + + container foo { + if-feature foo; + } + + augment /foo { + container bar; + } +} -- 2.36.6