Fix preparing action with path containing augment 76/82176/1
authorAnna Bencurova <Anna.Bencurova@pantheon.tech>
Mon, 20 May 2019 15:08:41 +0000 (17:08 +0200)
committerRobert Varga <nite@hq.sk>
Mon, 20 May 2019 16:33:18 +0000 (16:33 +0000)
- Augment does not have QName, so call getNodeType causes exception.

JIRA: NETCONF-620

Change-Id: Ib5f64eb1980784ad8df617a1ad9676cad9c2111c
Signed-off-by: Anna Bencurova <Anna.Bencurova@pantheon.tech>
(cherry picked from commit 45550671df11ff4df23dbd4072561b20919df1a2)

netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/util/NetconfMessageTransformUtil.java
netconf/sal-netconf-connector/src/test/java/org/opendaylight/netconf/sal/connect/netconf/schema/mapping/NetconfMessageTransformerTest.java
netconf/sal-netconf-connector/src/test/resources/schemas/example-server-farm-2.yang [new file with mode: 0644]

index bec32307d02254028b58c4203e48445c531a3bf8..a0c8ca7ef941993cc944075017a62c4574f703d3 100644 (file)
@@ -452,7 +452,6 @@ public final class NetconfMessageTransformUtil {
             final Element actionNS, final Iterator<PathArgument> iterator, final Document document) {
         if (iterator.hasNext()) {
             final PathArgument next = iterator.next();
-            final QName actualNS = next.getNodeType();
 
             DataSchemaContextNode<?> current = currentParentSchemaNode.getChild(next);
             Preconditions.checkArgument(current != null, "Invalid input: schema for argument %s not found", next);
@@ -461,6 +460,7 @@ public final class NetconfMessageTransformUtil {
                 return prepareActionData(current, actionNS, iterator, document);
             }
 
+            final QName actualNS = next.getNodeType();
             final Element actualElement = document.createElementNS(actualNS.getNamespace().toString(),
                     actualNS.getLocalName());
             if (next instanceof NodeWithValue) {
index 02d8ddc3b40b0ba0dbfcbd2d4ba8b7325751da77..0d94ef51d71dc9e1d1d19adad6aa1f684f4d4eb9 100644 (file)
@@ -90,6 +90,9 @@ public class NetconfMessageTransformerTest {
     private static final String REVISION_EXAMPLE_SERVER_FARM = "2018-08-07";
     private static final String URN_EXAMPLE_SERVER_FARM = "urn:example:server-farm";
 
+    private static final String REVISION_EXAMPLE_SERVER_FARM_2 = "2019-05-20";
+    private static final String URN_EXAMPLE_SERVER_FARM_2 = "urn:example:server-farm-2";
+
     private NetconfMessageTransformer actionNetconfMessageTransformer;
     private NetconfMessageTransformer netconfMessageTransformer;
     private SchemaContext schema;
@@ -401,7 +404,8 @@ public class NetconfMessageTransformerTest {
         QName start = QName.create(reset, "start");
         QName open = QName.create(start, "open");
         QName enable = QName.create(open, "enable");
-        Set<QName> qnames = new HashSet<>(Arrays.asList(reset, start, open, enable));
+        QName kill = QName.create(URN_EXAMPLE_SERVER_FARM_2, REVISION_EXAMPLE_SERVER_FARM_2, "kill");
+        Set<QName> qnames = new HashSet<>(Arrays.asList(reset, start, open, enable, kill));
         Set<ActionDefinition> actions = actionNetconfMessageTransformer.getActions();
         assertTrue(!actions.isEmpty());
         for (ActionDefinition actionDefinition : actions) {
@@ -524,6 +528,61 @@ public class NetconfMessageTransformerTest {
         checkNode(action, null, actionEnableQName.getLocalName(), null);
     }
 
+    @Test
+    public void toActionRequestListInContainerAugmentedIntoListTest() {
+        QName qnameServer = QName.create(URN_EXAMPLE_SERVER_FARM, REVISION_EXAMPLE_SERVER_FARM, "server");
+        QName serverNameQname = QName.create(qnameServer, "name");
+        QName qnameAppliactions = QName.create(URN_EXAMPLE_SERVER_FARM_2,
+                REVISION_EXAMPLE_SERVER_FARM_2, "applications");
+        QName qnameAppliaction = QName.create(URN_EXAMPLE_SERVER_FARM_2,
+                REVISION_EXAMPLE_SERVER_FARM_2, "application");
+        QName applicationNameQname = QName.create(qnameAppliaction, "name");
+        QName actionKillQName = QName.create(qnameAppliaction, "kill");
+
+        List<PathArgument> nodeIdentifiers = new ArrayList<>();
+        nodeIdentifiers.add(NodeIdentifier.create(qnameServer));
+        nodeIdentifiers.add(new NodeIdentifierWithPredicates(qnameServer, serverNameQname, "testServer"));
+        nodeIdentifiers.add(new YangInstanceIdentifier
+                .AugmentationIdentifier(Collections.singleton(qnameAppliactions)));
+        nodeIdentifiers.add(NodeIdentifier.create(qnameAppliactions));
+        nodeIdentifiers.add(NodeIdentifier.create(qnameAppliaction));
+        nodeIdentifiers.add(new NodeIdentifierWithPredicates(qnameAppliaction,
+                applicationNameQname, "testApplication"));
+
+        DOMDataTreeIdentifier domDataTreeIdentifier = prepareDataTreeId(nodeIdentifiers);
+
+        NormalizedNode<?, ?> payload = initEmptyInputAction(qnameAppliaction);
+        NetconfMessage actionRequest = actionNetconfMessageTransformer.toActionRequest(
+                SchemaPath.create(true, actionKillQName), domDataTreeIdentifier, payload);
+
+        Node childAction = checkBasePartOfActionRequest(actionRequest);
+
+        Node childServer = childAction.getFirstChild();
+        checkNode(childServer, "server", "server", qnameServer.getNamespace().toString());
+
+        Node childServerName = childServer.getFirstChild();
+        checkNode(childServerName, "name", "name", serverNameQname.getNamespace().toString());
+
+        Node childServerNameTest = childServerName.getFirstChild();
+        assertEquals(childServerNameTest.getNodeValue(), "testServer");
+
+        Node childApplications = childServer.getLastChild();
+        checkNode(childApplications, "applications", "applications", qnameAppliactions.getNamespace().toString());
+
+        Node childApplication = childApplications.getFirstChild();
+        checkNode(childApplication, "application", "application", qnameAppliaction.getNamespace().toString());
+
+        Node childApplicationName = childApplication.getFirstChild();
+        checkNode(childApplicationName, "name", "name", applicationNameQname.getNamespace().toString());
+
+        Node childApplicationNameTest = childApplicationName.getFirstChild();
+        assertEquals(childApplicationNameTest.getNodeValue(), "testApplication");
+
+        Node childKillAction = childApplication.getLastChild();
+        checkNode(childApplication, "application", "application", qnameAppliaction.getNamespace().toString());
+        checkNode(childKillAction, null, actionKillQName.getLocalName(), null);
+    }
+
     @SuppressWarnings({ "rawtypes", "unchecked" })
     @Test
     public void toActionResultTest() throws Exception {
@@ -602,7 +661,8 @@ public class NetconfMessageTransformerTest {
     }
 
     private static SchemaContext getActionSchema() {
-        return YangParserTestUtils.parseYangResource("/schemas/example-server-farm.yang");
+        return YangParserTestUtils.parseYangResources(NetconfMessageTransformerTest.class,
+                "/schemas/example-server-farm.yang","/schemas/example-server-farm-2.yang");
     }
 
     private static NetconfMessageTransformer getActionMessageTransformer() {
diff --git a/netconf/sal-netconf-connector/src/test/resources/schemas/example-server-farm-2.yang b/netconf/sal-netconf-connector/src/test/resources/schemas/example-server-farm-2.yang
new file mode 100644 (file)
index 0000000..065a500
--- /dev/null
@@ -0,0 +1,22 @@
+module example-server-farm-2 {
+  yang-version 1.1;
+  namespace "urn:example:server-farm-2";
+  prefix "sfarm2";
+  revision 2019-05-20;
+
+  import example-server-farm { prefix sfarm; revision-date 2018-08-07; }
+
+  augment "/sfarm:server" {
+    container applications {
+      list application {
+        key "name";
+        leaf name {
+          type string;
+        }
+
+        action kill {
+        }
+      }
+    }
+  }
+}
\ No newline at end of file