[YANG error when poking on EOS configuration](https://github.com/clicon/clixon-controller/issues/26)

This commit is contained in:
Olof hagsand 2023-08-21 10:54:48 +02:00
parent d1b8dcdf1f
commit 0e81e8137b
6 changed files with 151 additions and 319 deletions

View file

@ -57,6 +57,7 @@ Developers may need to change their code
### Corrected Bugs
* [YANG error when poking on EOS configuration](https://github.com/clicon/clixon-controller/issues/26)
* [CLICON_CONFIGDIR with external subsystems causes endless looping](https://github.com/clicon/clixon/issues/439)
* Fixed: ["show configuration devices" and "show configuration devices | display cli" differs](https://github.com/clicon/clixon-controller/issues/24)
* Fixed: [Configuring Juniper PTX produces CLI errors](https://github.com/clicon/clixon-controller/issues/19)

View file

@ -1202,7 +1202,7 @@ yang2cli_stmt(clicon_handle h,
int retval = -1;
yang_stmt *yc;
int treeref_state = 0;
int grouping_treeref;
int grouping_treeref = 0;
if (ys == NULL){
clicon_err(OE_YANG, EINVAL, "No yang spec");

View file

@ -1,233 +0,0 @@
module clixon-example {
yang-version 1.1;
namespace "urn:example:clixon";
prefix ex;
import ietf-interfaces {
/* is in yang/optional which means clixon must be installed using --opt-yang-installdir */
prefix if;
}
import ietf-ip {
prefix ip;
}
import iana-if-type {
prefix ianaift;
}
import ietf-datastores {
prefix ds;
}
import clixon-autocli{
prefix autocli;
}
description
"Clixon example used as a part of the Clixon test suite.
It can be used as a basis for making new Clixon applications.
Note, may change without updating revision, just for testing current master.
";
revision 2020-12-01 {
description "Added table/parameter/value as the primary data example";
}
revision 2020-03-11 {
description "Added container around translation list. Released in Clixon 4.4.0";
}
revision 2019-11-05 {
description "Augment interface. Released in Clixon 4.3.0";
}
revision 2019-07-23 {
description "Extension e4. Released in Clixon 4.1.0";
}
revision 2019-01-13 {
description "Released in Clixon 3.9";
}
/* Example interface type for tests, local callbacks, etc */
identity eth {
base if:interface-type;
}
identity loopback {
base if:interface-type;
}
/* Generic config data */
container table{
list parameter{
key name;
leaf name{
type string;
}
leaf value{
type string;
}
leaf hidden{
type string;
autocli:hide;
}
leaf stat{
description "Inline state data for example application";
config false;
type int32;
}
}
}
/* State data (not config) for the example application*/
container state {
config false;
description "state data for the example application (must be here for example get operation)";
leaf-list op {
type string;
}
}
augment "/if:interfaces/if:interface" {
container my-status {
config false;
description "For testing augment+state";
leaf int {
type int32;
}
leaf str {
type string;
}
}
}
/* yang extension implemented by the example backend code. */
extension e4 {
description
"The first child of the ex:e4 (unknown) statement is inserted into
the module as a regular data statement. This means that 'uses bar;'
in the ex:e4 statement below is a valid data node";
argument arg;
}
grouping bar {
leaf bar{
type string;
}
}
ex:e4 arg1{
uses bar;
}
/* Example notification as used in RFC 5277 and RFC 8040 */
notification event {
description "Example notification event.";
leaf event-class {
type string;
description "Event class identifier.";
}
container reportingEntity {
description "Event specific information.";
leaf card {
type string;
description "Line card identifier.";
}
}
leaf severity {
type string;
description "Event severity description.";
}
}
rpc client-rpc {
description "Example local client-side RPC that is processed by the
the netconf/restconf and not sent to the backend.
This is a clixon implementation detail: some rpc:s
are better processed by the client for API or perf reasons";
input {
leaf x {
type string;
}
}
output {
leaf x {
type string;
}
}
}
rpc empty {
description "Smallest possible RPC with no input or output sections";
}
rpc optional {
description "Small RPC with optional input and output";
input {
leaf x {
type string;
}
}
output {
leaf x {
type string;
}
}
}
rpc example {
description "Some example input/output for testing RFC7950 7.14.
RPC simply echoes the input for debugging.";
input {
leaf x {
description
"If a leaf in the input tree has a 'mandatory' statement with
the value 'true', the leaf MUST be present in an RPC invocation.";
type string;
mandatory true;
}
leaf y {
description
"If a leaf in the input tree has a 'mandatory' statement with the
value 'true', the leaf MUST be present in an RPC invocation.";
type string;
default "42";
}
leaf-list z {
description
"If a leaf-list in the input tree has one or more default
values, the server MUST use these values (XXX not supported)";
type string;
}
leaf w {
description
"If any node has a 'when' statement that would evaluate to
'false',then this node MUST NOT be present in the input tree.
(XXX not supported)";
type string;
}
list u0 {
description "list without key";
leaf uk{
type string;
}
}
list u1 {
description "list with key";
key uk;
leaf uk{
type string;
}
leaf val{
type string;
}
}
}
output {
leaf x {
type string;
}
leaf y {
type string;
}
leaf z {
type string;
}
leaf w {
type string;
}
list u0 {
leaf uk{
type string;
}
}
list u1 {
key uk;
leaf uk{
type string;
}
leaf val{
type string;
}
}
}
}
}

View file

@ -119,11 +119,11 @@ xp_yang_op_eq(xp_yang_ctx *xy1,
if ((xy = xy_dup(xy1)) == NULL)
goto done;
if (xy1 == NULL || xy2 == NULL || xy1->xy_node == NULL || xy2->xy_node == NULL){
clicon_err(OE_YANG, EINVAL, "Invalid path-arg (Error in xy1 or xy2) ");
goto done;
xy->xy_bool = 0;
}
xy->xy_type = XT_BOOL;
else
xy->xy_bool = 1;
xy->xy_type = XT_BOOL;
xy->xy_node = NULL;
*xyr = xy;
retval = 0;
@ -251,7 +251,7 @@ xp_yang_eval_predicate(xp_yang_ctx *xy,
if (xp_yang_eval(xy0, xptree->xs_c1, &xy1) < 0)
goto done;
/* Check xrc: if "true" then xyr=xy0? */
if (xy1->xy_type == XT_BOOL && xy1->xy_bool)
if (xy1 && xy1->xy_type == XT_BOOL && xy1->xy_bool)
;
else
xy0->xy_node = NULL;

View file

@ -7,16 +7,19 @@ s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi
APPNAME=example
cfg=$dir/conf_yang.xml
cfd=$dir/conf_yang.d
if [ ! -d $cfd ]; then
mkdir $cfd
fi
fyang=$dir/example.yang
fyang2=$dir/example-external.yang
fyang3=$dir/example-external3.yang
# Whether grouping treeref is enabled
grouping_treeref=true
# XXX try -E?
cat <<EOF > $cfg
<clixon-config xmlns="http://clicon.org/config">
<CLICON_CONFIGFILE>$cfg</CLICON_CONFIGFILE>
<CLICON_CONFIGDIR>$cfd</CLICON_CONFIGDIR>
<CLICON_FEATURE>ietf-netconf:startup</CLICON_FEATURE>
<CLICON_YANG_DIR>${YANG_INSTALLDIR}</CLICON_YANG_DIR>
<CLICON_YANG_DIR>$dir</CLICON_YANG_DIR>
@ -29,16 +32,6 @@ cat <<EOF > $cfg
<CLICON_BACKEND_PIDFILE>/usr/local/var/$APPNAME/$APPNAME.pidfile</CLICON_BACKEND_PIDFILE>
<CLICON_XMLDB_DIR>$dir</CLICON_XMLDB_DIR>
<CLICON_YANG_LIBRARY>false</CLICON_YANG_LIBRARY>
<autocli>
<module-default>false</module-default>
<list-keyword-default>kw-nokey</list-keyword-default>
<grouping-treeref>${grouping_treeref}</grouping-treeref>
<rule>
<name>include ${APPNAME}</name>
<operation>enable</operation>
<module-name>${APPNAME}*</module-name>
</rule>
</autocli>
</clixon-config>
EOF
@ -54,6 +47,7 @@ set @datamodel, cli_auto_set();
merge @datamodel, cli_auto_merge();
create @datamodel, cli_auto_create();
commit("Commit the changes"), cli_commit();
validate("Validate changes"), cli_validate();
delete("Delete a configuration item") {
@datamodel, cli_auto_del();
all("Delete whole candidate configuration"), delete_all("candidate");
@ -91,6 +85,20 @@ module example {
description "a value";
type string;
}
/* See https://github.com/clicon/clixon-controller/issues/26
* reference that goes beyond the scope of this grouping
*/
leaf-list scope {
type leafref {
path "../../value0";
}
}
/* leaf-list inscope {
type leafref {
path "../iv";
}
}
*/
}
}
container table{
@ -143,6 +151,43 @@ module example-external3 {
}
}
}
EOF
# Args:
# 1: grouping_treeref
function testrun()
{
# Whether grouping treeref is enabled
grouping_treeref=$1
echo "grouping_treeref=$1"
# cat <<EOF > $cfd/autocli.xml # XXX
cat <<EOF > $cfg
<clixon-config xmlns="http://clicon.org/config">
<CLICON_CONFIGFILE>$cfg</CLICON_CONFIGFILE>
<CLICON_CONFIGDIR>$cfd</CLICON_CONFIGDIR>
<CLICON_FEATURE>ietf-netconf:startup</CLICON_FEATURE>
<CLICON_YANG_DIR>${YANG_INSTALLDIR}</CLICON_YANG_DIR>
<CLICON_YANG_DIR>$dir</CLICON_YANG_DIR>
<CLICON_YANG_MAIN_DIR>$dir</CLICON_YANG_MAIN_DIR>
<CLICON_BACKEND_DIR>/usr/local/lib/$APPNAME/backend</CLICON_BACKEND_DIR>
<CLICON_CLISPEC_DIR>$dir</CLICON_CLISPEC_DIR>
<CLICON_CLI_DIR>/usr/local/lib/$APPNAME/cli</CLICON_CLI_DIR>
<CLICON_CLI_MODE>$APPNAME</CLICON_CLI_MODE>
<CLICON_SOCK>/usr/local/var/$APPNAME/$APPNAME.sock</CLICON_SOCK>
<CLICON_BACKEND_PIDFILE>/usr/local/var/$APPNAME/$APPNAME.pidfile</CLICON_BACKEND_PIDFILE>
<CLICON_XMLDB_DIR>$dir</CLICON_XMLDB_DIR>
<CLICON_YANG_LIBRARY>false</CLICON_YANG_LIBRARY>
<autocli>
<module-default>false</module-default>
<list-keyword-default>kw-nokey</list-keyword-default>
<grouping-treeref>${grouping_treeref}</grouping-treeref>
<rule>
<name>include ${APPNAME}</name>
<operation>enable</operation>
<module-name>${APPNAME}*</module-name>
</rule>
</autocli>
</clixon-config>
EOF
new "test params: -f $cfg"
@ -194,6 +239,18 @@ expectpart "$($clixon_cli -f $cfg -1 commit)" 0 ""
new "show config"
expectpart "$($clixon_cli -f $cfg -1 show config)" 0 "<table xmlns=\"urn:example:clixon\"><parameter><name>x</name><value0>40</value0><value1>41</value1><index1><i>a</i><iv>foo</iv></index1><value2>42</value2><c2><value3>43</value3></c2></parameter></table>" "<value1 xmlns=\"urn:example:clixon\">39</value1>"
new "set leafref lack origin"
expectpart "$($clixon_cli -f $cfg -1 set table parameter x index1 a scope 43)" 0 ""
new "validate expect fail"
expectpart "$($clixon_cli -f $cfg -1 validate 2>&1)" 255 "bad-element Leafref validation failed: No leaf 43 matching path"
new "set leafref expect fail"
expectpart "$($clixon_cli -f $cfg -1 set table parameter x value0 43)" 0 ""
new "validate ok"
expectpart "$($clixon_cli -f $cfg -1 validate)" 0 "^$" --not-- "bad-element Leafref validation failed: No leaf 43 matching path"
if [ $BE -ne 0 ]; then
new "Kill backend"
# Check if premature kill
@ -204,6 +261,13 @@ if [ $BE -ne 0 ]; then
# kill backend
stop_backend -f $cfg
fi
}
new "autocli grouping=true"
testrun true
new "autocli grouping=false"
testrun false
rm -rf $dir

View file

@ -147,6 +147,7 @@ fi
# for some reason valgrind tests fail below?
if [ ${valgrindtest} -eq 0 ]; then # Error dont cleanup mem OK
# XXX there may be inconsistent YANGs in this dir
YANGDIR=$YANG_INSTALLDIR
if [ $BE -ne 0 ]; then
@ -157,7 +158,6 @@ new "wait backend"
wait_backend
new "Loop over all yangs in $YANGDIR"
for f in ${YANGDIR}/*.yang; do
b=$(basename $f)
id=$(echo "$b" | sed 's/.yang//' | sed 's/@.*//')