[NETCONF-1215] Mandatory attributes in RPC input are not honoured Created: 27/Mar/17  Updated: 03/Jan/24

Status: Confirmed
Project: netconf
Component/s: restconf-nb
Affects Version/s: None
Fix Version/s: 7.0.0

Type: Bug Priority: Highest
Reporter: Vikram Darsi Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: pick-next, pt
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Operating System: All
Platform: All


Attachments: PNG File RPCInvocation.png    
Issue Links:
Blocks
is blocked by YANGTOOLS-1259 Split out immutable NormalizedNode im... Resolved
External issue ID: 8088

 Description   

We are using ODL Boron.

Mandatory attributes inside RPC input are not honoured , therefore RPC’s can be invoked without passing mandatory attributes.

 

rpc say-hello {
  input {
    leaf name {
      type string;
      mandatory true;
    }
  }
}

 

Whereas with RESTCONF url’s the mandatory attributes validation is happening

RESTCONF ERROR:
There is no Error to the North Bound(In the APIDOCS page), but in the server side, below logs are printed, CDS is not updated with the values as the validation is failed.

 

Caused by: java.lang.IllegalArgumentException: Node (urn:opendaylight:params:xml:ns:yang:normalizednodedemo?revision=2015-01-05)emp-list[
{(urn:opendaylight:params:xml:ns:yang:normalizednodedemo?revision=2015-01-05)name=vikram}
] is missing mandatory descendant /(urn:opendaylight:params:xml:ns:yang:normalizednodedemo?revision=2015-01-05)age
 at com.google.common.base.Preconditions.checkArgument(Preconditions.java:145)[58:com.google.guava:18.0.0]
 at org.opendaylight.yangtools.yang.data.impl.schema.tree.MandatoryLeafEnforcer$Strict.enforceOnTreeNode(MandatoryLeafEnforcer.java:60)[74:org.opendaylight.yangtools.yang-data-impl:1.0.0.Boron]
 at org.opendaylight.yangtools.yang.data.impl.schema.tree.MandatoryLeafEnforcer$Strict.enforceOnTreeNode(MandatoryLeafEnforcer.java:53)[74:org.opendaylight.yangtools.yang-data-impl:1.0.0.Boron]
 at org.opendaylight.yangtools.yang.data.impl.schema.tree.ListEntryModificationStrategy.applyWrite(ListEntryModificationStrategy.java:41)[74:org.opendaylight.yangtools.yang-data-impl:1.0.0.Boron]
 at org.opendaylight.yangtools.yang.data.impl.schema.tree.SchemaAwareApplyOperation.apply(SchemaAwareApplyOperation.java:216)[74:org.opendaylight.yangtools.yang-data-impl:1.0.0.Boron]
 at org.opendaylight.yangtools.yang.data.impl.schema.tree.AbstractNodeContainerModificationStrategy.mutateChildren(AbstractNodeContainerModificationStrategy.java:139)[74:org.opendaylight.yangtools.yang-data-impl:1.0.0.Boron]
 at org.opendaylight.yangtools.yang.data.impl.schema.tree.AbstractNodeContainerModificationStrategy.applyTouch(AbstractNodeContainerModificationStrategy.java:252)[74:org.opendaylight.yangtools.yang-data-impl:1.0.0.Boron]
 at org.opendaylight.yangtools.yang.data.impl.schema.tree.AbstractNodeContainerModificationStrategy.applyMerge(AbstractNodeContainerModificationStrategy.java:170)[74:org.opendaylight.yangtools.yang-data-impl:1.0.0.Boron]
 at org.opendaylight.yangtools.yang.data.impl.schema.tree.SchemaAwareApplyOperation.apply(SchemaAwareApplyOperation.java:207)[74:org.opendaylight.yangtools.yang-data-impl:1.0.0.Boron]
 at org.opendaylight.yangtools.yang.data.impl.schema.tree.MinMaxElementsValidation.checkMinMaxElements(MinMaxElementsValidation.java:76)[74:org.opendaylight.yangtools.yang-data-impl:1.0.0.Boron]
 at org.opendaylight.yangtools.yang.data.impl.schema.tree.MinMaxElementsValidation.checkMergeApplicable(MinMaxElementsValidation.java:114)[74:org.opendaylight.yangtools.yang-data-impl:1.0.0.Boron]
 at org.opendaylight.yangtools.yang.data.impl.schema.tree.SchemaAwareApplyOperation.checkApplicable(SchemaAwareApplyOperation.java:131)[74:org.opendaylight.yangtools.yang-data-impl:1.0.0.Boron]
 at org.opendaylight.yangtools.yang.data.impl.schema.tree.AbstractNodeContainerModificationStrategy.checkChildPreconditions(AbstractNodeContainerModificationStrategy.java:305)[74:org.opendaylight.yangtools.yang-data-impl:1.0.0.Boron]
 at org.opendaylight.yangtools.yang.data.impl.schema.tree.AbstractNodeContainerModificationStrategy.checkMergeApplicable(AbstractNodeContainerModificationStrategy.java:313)[74:org.opendaylight.yangtools.yang-data-impl:1.0.0.Boron]
 at org.opendaylight.yangtools.yang.data.impl.schema.tree.SchemaAwareApplyOperation.checkApplicable(SchemaAwareApplyOperation.java:131)[74:org.opendaylight.yangtools.yang-data-impl:1.0.0.Boron]
 at org.opendaylight.yangtools.yang.data.impl.schema.tree.StructuralContainerModificationStrategy.checkApplicable(StructuralContainerModificationStrategy.java:99)[74:org.opendaylight.yangtools.yang-data-impl:1.0.0.Boron]
 at org.opendaylight.yangtools.yang.data.impl.schema.tree.AbstractNodeContainerModificationStrategy.checkChildPreconditions(AbstractNodeContainerModificationStrategy.java:305)[74:org.opendaylight.yangtools.yang-data-impl:1.0.0.Boron]
 at org.opendaylight.yangtools.yang.data.impl.schema.tree.AbstractNodeContainerModificationStrategy.checkTouchApplicable(AbstractNodeContainerModificationStrategy.java:288)[74:org.opendaylight.yangtools.yang-data-impl:1.0.0.Boron]
 at org.opendaylight.yangtools.yang.data.impl.schema.tree.SchemaAwareApplyOperation.checkApplicable(SchemaAwareApplyOperation.java:125)[74:org.opendaylight.yangtools.yang-data-impl:1.0.0.Boron]
 at org.opendaylight.yangtools.yang.data.impl.schema.tree.RootModificationApplyOperation.checkApplicable(RootModificationApplyOperation.java:72)[74:org.opendaylight.yangtools.yang-data-impl:1.0.0.Boron]
 at org.opendaylight.yangtools.yang.data.impl.schema.tree.AbstractDataTreeTip.validate(AbstractDataTreeTip.java:37)[74:org.opendaylight.yangtools.yang-data-impl:1.0.0.Boron]

 

RPC ERROR:
Since there is no validation, it is returning the SUCCESSFUL RPC result to the North Bound



 Comments   
Comment by Igor Foltin [ 28/Mar/17 ]

Hi Vikram,

well, looking at the stack trace, mandatory node validation in yangtools part works the way it should.

The mandatory node "age" is not present in the "emp-list" list entry and that is the reason why the exception is thrown.

Comment by Vikram Darsi [ 28/Mar/17 ]

Hi Igor Foltin

Yes, with RESTCONF the mandatory attributes presence is validated. Bug descriptions says, the same validation is not performed while invoking RPC's (when its input does not have mandatory attributes)

Comment by Igor Foltin [ 28/Mar/17 ]

Could you please provide the exact steps you took to reproduce this behaviour?

Thanks

Comment by Vikram Darsi [ 28/Mar/17 ]

Please find the steps followed:

1. Created sample project using the below command

mvn archetype:generate -DarchetypeGroupId=org.opendaylight.controller -DarchetypeArtifactId=opendaylight-startup-archetype -DarchetypeRepository=http://nexus.opendaylight.org/content/repositories/opendaylight.release/ -DarchetypeCatalog=http://nexus.opendaylight.org/content/repositories/opendaylight.release/archetype-catalog.xml -DarchetypeVersion=1.2.0-Boron

2. api/src/main/yang/normalizednodedemo.yang

module normalizednodedemo {
yang-version 1;
namespace "urn:opendaylight:params:xml:ns:yang:normalizednodedemo";
prefix "normalizednodedemo";

revision "2015-01-05"

{ description "Initial revision of normalizednodedemo model"; }

rpc say-hello {
input{
leaf name

{ type string; mandatory true; }

}
}
}

3. impl/src/main/resources/impl-blueprint.xml

<?xml version="1.0" encoding="UTF-8"?>
<!-- vi: set et smarttab sw=4 tabstop=4: -->
<!--
Copyright © 2016 AdvaOptical.com and others. All rights reserved.

This program and the accompanying materials are made available under the
terms of the Eclipse Public License v1.0 which accompanies this distribution,
and is available at http://www.eclipse.org/legal/epl-v10.html
-->
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:odl="http://opendaylight.org/xmlns/blueprint/v1.0.0"
odl:use-default-for-reference-types="true">

<reference id="dataBroker"
interface="org.opendaylight.controller.md.sal.binding.api.DataBroker"
odl:type="default" />

<bean id="provider"
class="com.adva.ensemble.controller.impl.NormalizedNodeDemoProvider"
init-method="init" destroy-method="close">
<argument ref="dataBroker" />
</bean>

<bean id="rpcDemo"
class="com.adva.ensemble.controller.impl.NNRpcDemo">
</bean>

<odl:rpc-implementation ref="rpcDemo" />
</blueprint>

4. impl/src/main/java
com.adva.ensemble.controller.impl.NNRpcDemo

package com.adva.ensemble.controller.impl;

import java.util.concurrent.Future;

import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.normalizednodedemo.rev150105.NormalizednodedemoService;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.normalizednodedemo.rev150105.SayHelloInput;
import org.opendaylight.yangtools.yang.common.RpcResult;
import org.opendaylight.yangtools.yang.common.RpcResultBuilder;

public class NNRpcDemo implements NormalizednodedemoService{

@Override
public Future<RpcResult<Void>> sayHello(SayHelloInput input)

{ return RpcResultBuilder.<Void>success().buildFuture(); }

}

5. mvn clean install -Pq

6. karaf/target/assembly> bin/karaf debug

7. Launch APIDocs page: http://localhost:8181/apidoc/explorer/index.html

Invoke RPC : http://localhost:8181/restconf/operations/normalizednodedemo:say-hello

JSON : {
"input":{

}
}

RESPONSE : 200
RESPONSE CODE : No Content

NOTE: Mandatory attributes are not passed in the input.

Thanks
Vikram

Comment by Vikram Darsi [ 28/Mar/17 ]

screenshot is attached which shows RPC invocation success when mandatory attributes are not passed

Comment by Vikram Darsi [ 28/Mar/17 ]

Attachment RPCInvocation.png has been added with description: RPCInvocation Image that is showing success when mandatory attrs are not passed

Comment by Robert Varga [ 01/Jan/19 ]

We will need to extract MandatoryLeafEnforcer – and probably some other portions of org.opendaylight.yangtools.yang.data.impl.schema.tree into yang-data-util where it would be usable by codecs.

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