From: Marek Gradzki Date: Mon, 5 Jun 2017 14:28:44 +0000 (+0200) Subject: BUG-8085: create missing parent augmentation node X-Git-Tag: release/carbon-sr1~8 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=6c78a97edc32dd92365caa5b6f4363bed9dc4df7;p=netconf.git BUG-8085: create missing parent augmentation node Augmentation nodes do not exist in serialized form (e.g. in edit-config message), but are required by DataTree-based DOMDataBroker implementations, so should be created if data from augment is present. This patch creates missing augment nodes by issuing merge on augmentation before put operation (based on current behaviour for ListSchemaNodes). Change-Id: If657ae96e914fc46617099042a833c7d4d5883b7 Signed-off-by: Marek Gradzki --- diff --git a/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/EditConfig.java b/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/EditConfig.java index e3bb3cd100..563fc2e27c 100644 --- a/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/EditConfig.java +++ b/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/EditConfig.java @@ -36,6 +36,7 @@ import org.opendaylight.netconf.util.mapping.AbstractSingletonNetconfOperation; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.data.api.ModifyAction; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; +import org.opendaylight.yangtools.yang.data.api.schema.AugmentationNode; import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode; import org.opendaylight.yangtools.yang.data.api.schema.MapNode; import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; @@ -121,7 +122,7 @@ public class EditConfig extends AbstractSingletonNetconfOperation { case NONE: return; case MERGE: - mergeParentMap(rwtx, path, changeData); + mergeParentMixin(rwtx, path, changeData); rwtx.merge(LogicalDatastoreType.CONFIGURATION, path, changeData); break; case CREATE: @@ -131,14 +132,14 @@ public class EditConfig extends AbstractSingletonNetconfOperation { throw new DocumentedException("Data already exists, cannot execute CREATE operation", ErrorType.PROTOCOL, ErrorTag.DATA_EXISTS, ErrorSeverity.ERROR); } - mergeParentMap(rwtx, path, changeData); + mergeParentMixin(rwtx, path, changeData); rwtx.put(LogicalDatastoreType.CONFIGURATION, path, changeData); } catch (final ReadFailedException e) { LOG.warn("Read from datastore failed when trying to read data for create operation", change, e); } break; case REPLACE: - mergeParentMap(rwtx, path, changeData); + mergeParentMixin(rwtx, path, changeData); rwtx.put(LogicalDatastoreType.CONFIGURATION, path, changeData); break; case DELETE: @@ -161,14 +162,13 @@ public class EditConfig extends AbstractSingletonNetconfOperation { } } - private void mergeParentMap(final DOMDataReadWriteTransaction rwtx, final YangInstanceIdentifier path, - final NormalizedNode change) { + private void mergeParentMixin(final DOMDataReadWriteTransaction rwtx, final YangInstanceIdentifier path, + final NormalizedNode change) { + final YangInstanceIdentifier parentNodeYid = path.getParent(); if (change instanceof MapEntryNode) { - final YangInstanceIdentifier mapNodeYid = path.getParent(); - final SchemaNode schemaNode = SchemaContextUtil.findNodeInSchemaContext( schemaContext.getCurrentContext(), - mapNodeYid.getPathArguments().stream() + parentNodeYid.getPathArguments().stream() // filter out identifiers not present in the schema tree .filter(arg -> !(arg instanceof YangInstanceIdentifier.NodeIdentifierWithPredicates)) .filter(arg -> !(arg instanceof YangInstanceIdentifier.AugmentationIdentifier)) @@ -180,16 +180,23 @@ public class EditConfig extends AbstractSingletonNetconfOperation { //merge empty ordered or unordered map if (((ListSchemaNode) schemaNode).isUserOrdered()) { final MapNode mixinNode = Builders.orderedMapBuilder() - .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(mapNodeYid.getLastPathArgument().getNodeType())) + .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(parentNodeYid.getLastPathArgument().getNodeType())) .build(); - rwtx.merge(LogicalDatastoreType.CONFIGURATION, mapNodeYid, mixinNode); + rwtx.merge(LogicalDatastoreType.CONFIGURATION, parentNodeYid, mixinNode); return; } final MapNode mixinNode = Builders.mapBuilder() - .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(mapNodeYid.getLastPathArgument().getNodeType())) + .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(parentNodeYid.getLastPathArgument().getNodeType())) .build(); - rwtx.merge(LogicalDatastoreType.CONFIGURATION, mapNodeYid, mixinNode); + rwtx.merge(LogicalDatastoreType.CONFIGURATION, parentNodeYid, mixinNode); + } else if (parentNodeYid.getLastPathArgument() instanceof YangInstanceIdentifier.AugmentationIdentifier) { + // merge empty augmentation node + final YangInstanceIdentifier.AugmentationIdentifier augmentationYid = + (YangInstanceIdentifier.AugmentationIdentifier) parentNodeYid.getLastPathArgument(); + final AugmentationNode augmentationNode = Builders.augmentationBuilder() + .withNodeIdentifier(augmentationYid).build(); + rwtx.merge(LogicalDatastoreType.CONFIGURATION, parentNodeYid, augmentationNode); } } diff --git a/netconf/mdsal-netconf-connector/src/test/java/org/opendaylight/netconf/mdsal/connector/ops/NetconfMDSalMappingTest.java b/netconf/mdsal-netconf-connector/src/test/java/org/opendaylight/netconf/mdsal/connector/ops/NetconfMDSalMappingTest.java index 2d5e971dc3..7fe00acd36 100644 --- a/netconf/mdsal-netconf-connector/src/test/java/org/opendaylight/netconf/mdsal/connector/ops/NetconfMDSalMappingTest.java +++ b/netconf/mdsal-netconf-connector/src/test/java/org/opendaylight/netconf/mdsal/connector/ops/NetconfMDSalMappingTest.java @@ -327,6 +327,32 @@ public class NetconfMDSalMappingTest { } + @Test + public void testAugmentedContainerReplace() throws Exception { + verifyResponse(edit("messages/mapping/editConfigs/editConfig_empty_modules_create.xml"), + RPC_REPLY_OK); + verifyResponse(commit(), RPC_REPLY_OK); + + verifyResponse(edit("messages/mapping/editConfigs/editConfig_augmented_container_replace.xml"), + RPC_REPLY_OK); + verifyResponse(commit(), RPC_REPLY_OK); + + deleteDatastore(); + } + + @Test + public void testLeafFromAugmentReplace() throws Exception { + verifyResponse(edit("messages/mapping/editConfigs/editConfig_empty_modules_create.xml"), + RPC_REPLY_OK); + verifyResponse(commit(), RPC_REPLY_OK); + + verifyResponse(edit("messages/mapping/editConfigs/editConfig_leaf_from_augment_replace.xml"), + RPC_REPLY_OK); + verifyResponse(commit(), RPC_REPLY_OK); + + deleteDatastore(); + } + @Test public void testLock() throws Exception { diff --git a/netconf/mdsal-netconf-connector/src/test/resources/messages/mapping/editConfigs/editConfig_augmented_container_replace.xml b/netconf/mdsal-netconf-connector/src/test/resources/messages/mapping/editConfigs/editConfig_augmented_container_replace.xml new file mode 100644 index 0000000000..184b3a0786 --- /dev/null +++ b/netconf/mdsal-netconf-connector/src/test/resources/messages/mapping/editConfigs/editConfig_augmented_container_replace.xml @@ -0,0 +1,28 @@ + + + + + + + + + set + + none + + + + + some id + + + + + + \ No newline at end of file diff --git a/netconf/mdsal-netconf-connector/src/test/resources/messages/mapping/editConfigs/editConfig_empty_modules_create.xml b/netconf/mdsal-netconf-connector/src/test/resources/messages/mapping/editConfigs/editConfig_empty_modules_create.xml new file mode 100644 index 0000000000..7478bfdf82 --- /dev/null +++ b/netconf/mdsal-netconf-connector/src/test/resources/messages/mapping/editConfigs/editConfig_empty_modules_create.xml @@ -0,0 +1,25 @@ + + + + + + + + + set + + none + + + + + + + + \ No newline at end of file diff --git a/netconf/mdsal-netconf-connector/src/test/resources/messages/mapping/editConfigs/editConfig_leaf_from_augment_replace.xml b/netconf/mdsal-netconf-connector/src/test/resources/messages/mapping/editConfigs/editConfig_leaf_from_augment_replace.xml new file mode 100644 index 0000000000..3f825222dd --- /dev/null +++ b/netconf/mdsal-netconf-connector/src/test/resources/messages/mapping/editConfigs/editConfig_leaf_from_augment_replace.xml @@ -0,0 +1,26 @@ + + + + + + + + + set + + none + + + + some value + + + + + \ No newline at end of file diff --git a/netconf/mdsal-netconf-connector/src/test/resources/yang/mdsal-netconf-mapping-test.yang b/netconf/mdsal-netconf-connector/src/test/resources/yang/mdsal-netconf-mapping-test.yang index bf363b321b..2557dbcc86 100644 --- a/netconf/mdsal-netconf-connector/src/test/resources/yang/mdsal-netconf-mapping-test.yang +++ b/netconf/mdsal-netconf-connector/src/test/resources/yang/mdsal-netconf-mapping-test.yang @@ -181,13 +181,19 @@ module config { } augment "/map:top/map:modules/" { - container augmented-container{ + container augmented-container { leaf identifier { type string; } } } + augment "/map:top/map:modules/" { + leaf leaf-from-augment { + type string; + } + } + augment "/map:top" { container mid-level { container low-level {