[NETCONF-1174] Leaf-list creation fails on min-element violation Created: 02/Oct/23  Updated: 05/Oct/23

Status: Open
Project: netconf
Component/s: None
Affects Version/s: 7.0.0
Fix Version/s: None

Type: Bug Priority: Medium
Reporter: Peter Suna Assignee: Ivan Hrasko
Resolution: Unresolved Votes: 0
Labels: pt
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: Text File karaf.log     Text File testtool.log    

 Description   

Leaf-list resource creation fails due to min-element condition violation, even when the number of leaf-list elements is correct.

Steps to reproduce:
1) Add "test-container-childs" model to netconf-testtool

module test-container-childs {
    namespace "http://example.com/test/container/child";
    prefix "tcc";
    revision 2023-09-28;
    
    container root-leaf-list-container {
        container nested-leaf-list-container {
            leaf-list leaf-list-with-min-elements {
                min-elements 1;
                max-elements 3;
                type string;
            }
        }    
    }
} 

2) Send a request to populate "leaf-list-with-min-elements"

POST URI: 
rests/data/network-topology:network-topology/topology=topology-netconf/node=36001-sim-device/yang-ext:mount/test-container-childs:root-leaf-list-container/nested-leaf-list-container

Payload:
{
    "leaf-list-with-min-elements": [
      "data1",
      "data2"
    ]
}

3) Response from device:

{
    "errors": {
        "error": [
            {
                "error-tag": "operation-failed",
                "error-info": "TransactionCommitFailedException{message=Netconf transaction commit failed, errorList=[RpcError [message=Netconf transaction commit failed, severity=ERROR, errorType=APPLICATION, tag=operation-failed, applicationTag=null, info=null, cause=NetconfDocumentedException{error-type=APPLICATION, error-tag=operation-failed, error-severity=ERROR, error-info={}, message=RPC during tx failed. Transaction commit failed on TransactionCommitFailedException{message=preCommit execution failed, errorList=[RpcError [message=preCommit execution failed, severity=ERROR, errorType=APPLICATION, tag=operation-failed, applicationTag=null, info=null, cause=org.opendaylight.yangtools.yang.data.tree.impl.MinMaxElementsValidationFailedException: (http://example.com/test/container/child?revision=2023-09-28)leaf-list-with-min-elements does not have enough elements (0), needs at least 1]]} 1 Cause: preCommit execution failed }]]}",
                "error-message": "Transaction(POST) not committed correctly",
                "error-type": "application"
            }
        ]
    }
}

 

 



 Comments   
Comment by Peter Suna [ 03/Oct/23 ]

The request for MapNode and LeafSetNode is split into separate RPCs, which are sent one by one to the device.
https://github.com/opendaylight/netconf/blob/7ddbcbbe9fcc2c1c2e9693807457ba339d813f19/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/transactions/NetconfRestconfTransaction.java#L102
The first request is responsible for creating an empty resource and afterward, separate RPCs are sent for each leaf-node child to device.

    for (var child : ((NormalizedNodeContainer<?>) data).body()) {
        final var childPath = path.node(child.name());
        enqueueOperation(() -> netconfService.create(CONFIGURATION, childPath, child, Optional.empty()));
    }

 

Device receive RPC for creating resource for first child:

<rpc xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="m-23">
    <edit-config>
        <target>
            <candidate/>
        </target>
        <config>
            <root-leaf-list-container xmlns="http://example.com/test/container/child">
                <nested-leaf-list-container>
                    <leaf-list-with-min-elements xmlns:op="urn:ietf:params:xml:ns:netconf:base:1.0" op:operation="create">data2</leaf-list-with-min-elements>
                </nested-leaf-list-container>
            </root-leaf-list-container>
        </config>
    </edit-config>
</rpc>
 

this RPC will fails due to check if data already exist on YangInstanceIdentifier path:
"/(http://example.com/test/container/child?revision=2023-09-28)root-leaf-list-container/nested-leaf-list-container/leaf-list-with-min-elements/leaf-list-with-min-elements[data2]"

if (rwtx.exists(LogicalDatastoreType.CONFIGURATION, path).get()) { 

-> 
https://github.com/opendaylight/netconf/blob/7ddbcbbe9fcc2c1c2e9693807457ba339d813f19/plugins/netconf-server-mdsal/src/main/java/org/opendaylight/netconf/server/mdsal/operations/EditConfig.java#L98
This line attempts to invoke validation for` MinMaxElementsValidation#enforceOnData` on the `leaf-list-with-min-elements`, which currently fails at this point. It should only be called after the `commit` RPC is sent.

 

Comment by Ivan Hrasko [ 05/Oct/23 ]

The error can be that, in fact, with POST we are creating nested-leaf-list-container resource. It can be its created "empty" or what by default regardless of payload. Can you try with PUT? PeterSuna 

Comment by Ivan Hrasko [ 05/Oct/23 ]

The error condition probably happens because the logic tries to ensure all parents exist, so first node created is empty root-leaf-list-container which fails to validate:

  • please try to make POST directly to root element
  • use PUT
  • see if we can modify the logic in a way that when we create parent structure parent are not created empty, but instead, with desired content

 

Comment by Peter Suna [ 05/Oct/23 ]

PUT creates a 'REPLACE' operation that does not include a check to verify if the data exists.
https://github.com/opendaylight/netconf/blob/7ddbcbbe9fcc2c1c2e9693807457ba339d813f19/plugins/netconf-server-mdsal/src/main/java/org/opendaylight/netconf/server/mdsal/operations/EditConfig.java#L98

Creating empty "nested-leaf-list-container" container with RPC is also successful because validation check is made after "commit" RPC.

Generated at Wed Feb 07 20:16:51 UTC 2024 using Jira 8.20.10#820010-sha1:ace47f9899e9ee25d7157d59aa17ab06aee30d3d.