Bug 2156: Unsupported augment target 60/11860/2
authorpkajsa <pkajsa@cisco.com>
Tue, 7 Oct 2014 14:56:59 +0000 (16:56 +0200)
committerTony Tkacik <ttkacik@cisco.com>
Thu, 16 Oct 2014 09:34:50 +0000 (09:34 +0000)
Some yang models contain augmentations into unsupported target
(e.g. node in body of extension). This causes maven build failure
(by generation of DTO), even though parsing such models is successful.

Change-Id: I8efff696aa2d3b95c5168ba8e42d49a93d1dff74
Signed-off-by: pkajsa <pkajsa@cisco.com>
(cherry picked from commit 48387f2188ee83a3c8e909df01e109ebd3e7c89c)

yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/api/AugmentationSchemaBuilder.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/impl/AugmentationSchemaBuilderImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/impl/UsesNodeBuilderImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/impl/YangParserImpl.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/AugmentToExtensionTest.java [new file with mode: 0644]
yang/yang-parser-impl/src/test/resources/augment-to-extension-test/correct-augment/augment-module.yang [new file with mode: 0644]
yang/yang-parser-impl/src/test/resources/augment-to-extension-test/correct-augment/extension-module.yang [new file with mode: 0644]
yang/yang-parser-impl/src/test/resources/augment-to-extension-test/correct-path-into-unsupported-target/augment-module.yang [new file with mode: 0644]
yang/yang-parser-impl/src/test/resources/augment-to-extension-test/correct-path-into-unsupported-target/extension-module.yang [new file with mode: 0644]
yang/yang-parser-impl/src/test/resources/augment-to-extension-test/incorrect-path/augment-module.yang [new file with mode: 0644]
yang/yang-parser-impl/src/test/resources/augment-to-extension-test/incorrect-path/extension-module.yang [new file with mode: 0644]

index f7004791e2c1d21da4fd77970c28438bfdd5f588..6ebd25fc4d8efc760c0647b53a420aa28a47b084 100644 (file)
@@ -85,4 +85,16 @@ public interface AugmentationSchemaBuilder extends DataNodeContainerBuilder,Docu
      */
     int getOrder();
 
+    /**
+     *  Set true if target of augment is unsupported (e.g. node in body of extension).
+     *  In such case, augmentation is skipped and AugmentationSchema is not built.
+     */
+    public void setUnsupportedTarget(boolean unsupportedTarget);
+
+    /**
+     *  Return true if target of augment is unsupported (e.g. node in body of extension).
+     *  In such case, augmentation is skipped and AugmentationSchema is not built.
+     */
+    public boolean isUnsupportedTarget();
+
 }
index 5d93a06579bea94c8ead4cea608b422dfab68b78..83dffd946273afa530b4bba08baeb541e866eb60 100644 (file)
@@ -37,6 +37,8 @@ public final class AugmentationSchemaBuilderImpl extends AbstractDocumentedDataN
     private final SchemaPath targetPath;
 
     private boolean resolved;
+    private boolean unsupportedTarget = false;
+
     private AugmentationSchemaBuilder copyOf;
 
     public AugmentationSchemaBuilderImpl(final String moduleName, final int line, final String augmentTargetStr,
@@ -110,6 +112,24 @@ public final class AugmentationSchemaBuilderImpl extends AbstractDocumentedDataN
         this.resolved = resolved;
     }
 
+    /**
+     *  Set true if target of augment is unsupported (e.g. node in body of extension).
+     *  In such case, augmentation is skipped and AugmentationSchema is not built.
+     */
+    @Override
+    public void setUnsupportedTarget(boolean unsupportedTarget) {
+        this.unsupportedTarget = unsupportedTarget;
+    }
+
+    /**
+     *  Return true if target of augment is unsupported (e.g. node in body of extension).
+     *  In such case, augmentation is skipped and AugmentationSchema is not built.
+     */
+    @Override
+    public boolean isUnsupportedTarget() {
+        return unsupportedTarget;
+    }
+
     @Override
     public String getWhenCondition() {
         return whenCondition;
index 4cc591f4c43568391d166bcfb353ab082b0dc4a3..f31909725ca829b6e56d38d6009de4f2e5e967d9 100644 (file)
@@ -65,7 +65,8 @@ public final class UsesNodeBuilderImpl extends AbstractBuilder implements UsesNo
         // AUGMENTATIONS
         final Set<AugmentationSchema> augments = new HashSet<>();
         for (AugmentationSchemaBuilder builder : augmentationBuilders) {
-            augments.add(builder.build());
+            if (!builder.isUnsupportedTarget())
+                augments.add(builder.build());
         }
         instance.augmentations = ImmutableSet.copyOf(augments);
 
index 48d96bf36f2fe1e07b5bb990eec8175dec172b5b..3842edb2c296aaabae896df024cfbaf054c27768 100644 (file)
@@ -967,6 +967,7 @@ public final class YangParserImpl implements YangContextParser {
                         "Error in module {} at line {}: Unsupported augment target: {}. Augmentation process skipped.",
                         module.getName(), augment.getLine(), potentialTargetNode);
                 augment.setResolved(true);
+                augment.setUnsupportedTarget(true);
                 return true;
             }
         } else {
diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/AugmentToExtensionTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/AugmentToExtensionTest.java
new file mode 100644 (file)
index 0000000..d8e2789
--- /dev/null
@@ -0,0 +1,70 @@
+/**
+ * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ */
+package org.opendaylight.yangtools.yang.parser.impl;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.util.Set;
+
+import org.junit.Test;
+import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
+import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.Module;
+import org.opendaylight.yangtools.yang.model.api.UsesNode;
+import org.opendaylight.yangtools.yang.parser.util.YangParseException;
+
+public class AugmentToExtensionTest {
+    private Set<Module> modules;
+
+    @Test(expected = YangParseException.class)
+    public void testIncorrectPath() throws IOException, URISyntaxException {
+        modules = TestUtils.loadModules(getClass().getResource("/augment-to-extension-test/incorrect-path").toURI());
+
+    }
+
+    @Test
+    public void testCorrectPathIntoUnsupportedTarget() throws IOException, URISyntaxException {
+        modules = TestUtils.loadModules(getClass().getResource(
+                "/augment-to-extension-test/correct-path-into-unsupported-target").toURI());
+
+        Module devicesModul = TestUtils.findModule(modules, "augment-module");
+
+        ContainerSchemaNode devicesContainer = (ContainerSchemaNode) devicesModul.getDataChildByName("my-container");
+        Set<UsesNode> uses = devicesContainer.getUses();
+
+        boolean augmentationIsInContainer = false;
+        for (UsesNode usesNode : uses) {
+            Set<AugmentationSchema> augmentations = usesNode.getAugmentations();
+            for (AugmentationSchema augmentationSchema : augmentations) {
+                augmentationIsInContainer = true;
+            }
+        }
+
+        assertFalse(augmentationIsInContainer);
+    }
+
+    @Test
+    public void testCorrectAugment() throws IOException, URISyntaxException {
+        modules = TestUtils.loadModules(getClass().getResource("/augment-to-extension-test/correct-augment").toURI());
+
+        Module devicesModul = TestUtils.findModule(modules, "augment-module");
+
+        ContainerSchemaNode devicesContainer = (ContainerSchemaNode) devicesModul.getDataChildByName("my-container");
+        Set<UsesNode> uses = devicesContainer.getUses();
+
+        boolean augmentationIsInContainer = false;
+        for (UsesNode usesNode : uses) {
+            Set<AugmentationSchema> augmentations = usesNode.getAugmentations();
+            for (AugmentationSchema augmentationSchema : augmentations) {
+                augmentationIsInContainer = true;
+            }
+        }
+
+        assertTrue(augmentationIsInContainer);
+    }
+
+}
diff --git a/yang/yang-parser-impl/src/test/resources/augment-to-extension-test/correct-augment/augment-module.yang b/yang/yang-parser-impl/src/test/resources/augment-to-extension-test/correct-augment/augment-module.yang
new file mode 100644 (file)
index 0000000..05ec41b
--- /dev/null
@@ -0,0 +1,39 @@
+module augment-module {
+    yang-version 1;
+    namespace "uri:augment-module";
+    prefix aug;
+
+    import extension-module { prefix ext; }
+
+    revision 2014-10-07 {
+        description
+                "Yang model with augment into extension";
+    }
+
+    grouping my-grouping {
+        ext:my-extension my-extension-name {
+            description
+                        "Extension.";
+            input {
+                leaf my-leaf {
+                    type string;
+                    description
+                                        "my-leaf in extension body.";
+                }
+            }
+        }
+        container my-container-in-gruping {
+        }
+    }
+
+    container my-container {
+        uses my-grouping {
+            augment "my-container-in-gruping" {
+                leaf-list my-leaf-list {
+                    type string;
+                }
+            }
+        }
+    }
+}
+
diff --git a/yang/yang-parser-impl/src/test/resources/augment-to-extension-test/correct-augment/extension-module.yang b/yang/yang-parser-impl/src/test/resources/augment-to-extension-test/correct-augment/extension-module.yang
new file mode 100644 (file)
index 0000000..d2046d1
--- /dev/null
@@ -0,0 +1,15 @@
+module extension-module {
+    yang-version 1;
+    namespace "uri:extension-module";
+    prefix ext;
+
+    revision 2014-10-07 {
+        description
+                "Yang model with extension definition";
+    }
+
+    extension my-extension {
+        argument name {
+        }
+    }
+}
diff --git a/yang/yang-parser-impl/src/test/resources/augment-to-extension-test/correct-path-into-unsupported-target/augment-module.yang b/yang/yang-parser-impl/src/test/resources/augment-to-extension-test/correct-path-into-unsupported-target/augment-module.yang
new file mode 100644 (file)
index 0000000..814004e
--- /dev/null
@@ -0,0 +1,39 @@
+module augment-module {
+    yang-version 1;
+    namespace "uri:augment-module";
+    prefix aug;
+
+    import extension-module { prefix ext; }
+
+    revision 2014-10-07 {
+        description
+                "Yang model with augment into extension";
+    }
+
+    grouping my-grouping {
+        ext:my-extension my-extension-name {
+            description
+                        "Extension.";
+            input {
+                leaf my-leaf {
+                    type string;
+                    description
+                                        "my-leaf in extension body.";
+                }
+            }
+        }
+        container my-container-in-gruping {
+        }
+    }
+
+    container my-container {
+        uses my-grouping {
+            augment "my-extension-name/input" {
+                leaf-list my-leaf-list {
+                    type string;
+                }
+            }
+        }
+    }
+}
+
diff --git a/yang/yang-parser-impl/src/test/resources/augment-to-extension-test/correct-path-into-unsupported-target/extension-module.yang b/yang/yang-parser-impl/src/test/resources/augment-to-extension-test/correct-path-into-unsupported-target/extension-module.yang
new file mode 100644 (file)
index 0000000..d2046d1
--- /dev/null
@@ -0,0 +1,15 @@
+module extension-module {
+    yang-version 1;
+    namespace "uri:extension-module";
+    prefix ext;
+
+    revision 2014-10-07 {
+        description
+                "Yang model with extension definition";
+    }
+
+    extension my-extension {
+        argument name {
+        }
+    }
+}
diff --git a/yang/yang-parser-impl/src/test/resources/augment-to-extension-test/incorrect-path/augment-module.yang b/yang/yang-parser-impl/src/test/resources/augment-to-extension-test/incorrect-path/augment-module.yang
new file mode 100644 (file)
index 0000000..17b3b4c
--- /dev/null
@@ -0,0 +1,39 @@
+module augment-module {
+    yang-version 1;
+    namespace "uri:augment-module";
+    prefix aug;
+
+    import extension-module { prefix ext; }
+
+    revision 2014-10-07 {
+        description
+                "Yang model with augment into extension";
+    }
+
+    grouping my-grouping {
+        ext:my-extension my-extension-name {
+            description
+                        "Extension.";
+            input {
+                leaf my-leaf {
+                    type string;
+                    description
+                                        "my-leaf in extension body.";
+                }
+            }
+        }
+        container my-container-in-gruping {
+        }
+    }
+
+    container my-container {
+        uses my-grouping {
+            augment "my-extension-name/input/a" {
+                leaf-list my-leaf-list {
+                    type string;
+                }
+            }
+        }
+    }
+}
+
diff --git a/yang/yang-parser-impl/src/test/resources/augment-to-extension-test/incorrect-path/extension-module.yang b/yang/yang-parser-impl/src/test/resources/augment-to-extension-test/incorrect-path/extension-module.yang
new file mode 100644 (file)
index 0000000..d2046d1
--- /dev/null
@@ -0,0 +1,15 @@
+module extension-module {
+    yang-version 1;
+    namespace "uri:extension-module";
+    prefix ext;
+
+    revision 2014-10-07 {
+        description
+                "Yang model with extension definition";
+    }
+
+    extension my-extension {
+        argument name {
+        }
+    }
+}