From: Anna Bencurova Date: Mon, 20 May 2019 15:08:41 +0000 (+0200) Subject: Fix preparing action with path containing augment X-Git-Tag: release/neon-sr2~18 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=netconf.git;a=commitdiff_plain;h=4b451950fe051f7b46979fba0d03f28dcf07bd25 Fix preparing action with path containing augment - Augment does not have QName, so call getNodeType causes exception. JIRA: NETCONF-620 Change-Id: Ib5f64eb1980784ad8df617a1ad9676cad9c2111c Signed-off-by: Anna Bencurova (cherry picked from commit 45550671df11ff4df23dbd4072561b20919df1a2) --- diff --git a/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/util/NetconfMessageTransformUtil.java b/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/util/NetconfMessageTransformUtil.java index bec32307d0..a0c8ca7ef9 100644 --- a/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/util/NetconfMessageTransformUtil.java +++ b/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/util/NetconfMessageTransformUtil.java @@ -452,7 +452,6 @@ public final class NetconfMessageTransformUtil { final Element actionNS, final Iterator 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) { diff --git a/netconf/sal-netconf-connector/src/test/java/org/opendaylight/netconf/sal/connect/netconf/schema/mapping/NetconfMessageTransformerTest.java b/netconf/sal-netconf-connector/src/test/java/org/opendaylight/netconf/sal/connect/netconf/schema/mapping/NetconfMessageTransformerTest.java index 02d8ddc3b4..0d94ef51d7 100644 --- a/netconf/sal-netconf-connector/src/test/java/org/opendaylight/netconf/sal/connect/netconf/schema/mapping/NetconfMessageTransformerTest.java +++ b/netconf/sal-netconf-connector/src/test/java/org/opendaylight/netconf/sal/connect/netconf/schema/mapping/NetconfMessageTransformerTest.java @@ -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 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 qnames = new HashSet<>(Arrays.asList(reset, start, open, enable, kill)); Set 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 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 index 0000000000..065a500104 --- /dev/null +++ b/netconf/sal-netconf-connector/src/test/resources/schemas/example-server-farm-2.yang @@ -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