* Fixed: [Validate error when appending module B grouping to module A item use augment statement #308](https://github.com/clicon/clixon/issues/308)

This commit is contained in:
Olof hagsand 2022-02-23 13:21:10 +01:00
parent 2291275fae
commit add797ed31
3 changed files with 133 additions and 3 deletions

View file

@ -70,6 +70,7 @@ Users may have to change how they access the system
### Corrected Bugs ### Corrected Bugs
* Fixed: [Validate error when appending module B grouping to module A item use augment statement #308](https://github.com/clicon/clixon/issues/308)
* Fixed: [ Restconf PATCH method request failed on item defined by submodule #306](https://github.com/clicon/clixon/issues/306) * Fixed: [ Restconf PATCH method request failed on item defined by submodule #306](https://github.com/clicon/clixon/issues/306)
* Fixed: [restconf GET json response does not encode top level node with namespace as per rfc #303](https://github.com/clicon/clixon/issues/303) * Fixed: [restconf GET json response does not encode top level node with namespace as per rfc #303](https://github.com/clicon/clixon/issues/303)
* Fixed: [statement: require-instance should be true if not present according to rfc7950 Sec 9.9.3](https://github.com/clicon/clixon/issues/302) * Fixed: [statement: require-instance should be true if not present according to rfc7950 Sec 9.9.3](https://github.com/clicon/clixon/issues/302)

View file

@ -111,7 +111,7 @@
* node is the leaf or leaf-list node in the data tree that * node is the leaf or leaf-list node in the data tree that
* references the typedef. (ie ys) * references the typedef. (ie ys)
* o Otherwise, the context node is the node in the data tree for which * o Otherwise, the context node is the node in the data tree for which
* the "path" statement is defined. (ie yc) * the "path" statement is defined. (ie ys)
* *
*/ */
static int static int
@ -162,8 +162,7 @@ validate_leafref(cxobj *xt,
} }
if ((leafrefbody = xml_body(xt)) == NULL) if ((leafrefbody = xml_body(xt)) == NULL)
goto ok; goto ok;
/* See comment^: If path is defined in typedef or not */ if (xml_nsctx_yang(ys, &nsc) < 0)
if (xml_nsctx_node(xt, &nsc) < 0)
goto done; goto done;
if (xpath_vec(xt, nsc, "%s", &xvec, &xlen, path_arg) < 0) if (xpath_vec(xt, nsc, "%s", &xvec, &xlen, path_arg) < 0)
goto done; goto done;

130
test/test_leafref_uses_augment.sh Executable file
View file

@ -0,0 +1,130 @@
#!/usr/bin/env bash
# leafref + augment + grouping, essentially test of default namespaces in augment+uses
# See also https://github.com/clicon/clixon/issues/308
# Magic line must be first in script (see README.md)
s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi
APPNAME=example
cfg=$dir/conf_yang.xml
fyang1=$dir/test1.yang
fyang2=$dir/test2.yang
fyang3=$dir/test3.yang
# Generate autocli for these modules
AUTOCLI=$(autocli_config test\* kw-nokey false)
cat <<EOF > $cfg
<clixon-config xmlns="http://clicon.org/config">
<CLICON_CONFIGFILE>$cfg</CLICON_CONFIGFILE>
<CLICON_FEATURE>a:test</CLICON_FEATURE>
<CLICON_YANG_DIR>$dir</CLICON_YANG_DIR>
<CLICON_YANG_DIR>${YANG_INSTALLDIR}</CLICON_YANG_DIR>
<CLICON_YANG_MAIN_FILE>$fyang1</CLICON_YANG_MAIN_FILE>
<CLICON_CLISPEC_DIR>/usr/local/lib/$APPNAME/clispec</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_BACKEND_DIR>/usr/local/lib/$APPNAME/backend</CLICON_BACKEND_DIR>
<CLICON_XMLDB_DIR>/usr/local/var/$APPNAME</CLICON_XMLDB_DIR>
<CLICON_MODULE_LIBRARY_RFC7895>false</CLICON_MODULE_LIBRARY_RFC7895>
${AUTOCLI}
</clixon-config>
EOF
# This is the lib function with the base container
cat <<EOF > $fyang1
module test1 {
yang-version 1.1;
namespace "http://www.test1.com/test1";
prefix t1;
import test3 { prefix t3; }
grouping t1-group {
container t1-con {
leaf t1-a {
type string;
}
leaf t1-ref-a {
type leafref {
path "../t1-a"; // This should have t1 namespace regardless of augment/uses
}
}
}
}
container t1-con {
}
augment "/t1-con" {
uses t1-group;
}
augment "/t3:t3-con" {
uses t1:t1-group;
}
}
EOF
cat <<EOF > $fyang3
module test3 {
yang-version 1.1;
namespace "http://www.test3.com/test3";
prefix t3;
container t3-con {
}
}
EOF
new "test params: -f $cfg"
if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -zf $cfg
if [ $? -ne 0 ]; then
err
fi
new "start backend -s init -f $cfg"
start_backend -s init -f $cfg
fi
new "waiting"
wait_backend
if true; then
new "cli set t1-con t1-con t1-a 123"
expectpart "$($clixon_cli -1 -f $cfg set t1-con t1-con t1-a 123)" 0 ""
new "cli set t1-con t1-con t1-ref-a 123"
expectpart "$($clixon_cli -1 -f $cfg set t1-con t1-con t1-ref-a 123)" 0 ""
new "cli validate"
expectpart "$($clixon_cli -1 -f $cfg validate)" 0 ""
new "cli discard"
expectpart "$($clixon_cli -1 -f $cfg discard)" 0 ""
fi
new "cli set t3-con t1-con t1-a 123"
expectpart "$($clixon_cli -1 -f $cfg set t3-con t1-con t1-a 123)" 0 ""
new "cli set t3-con t1-con t1-ref-a 123"
expectpart "$($clixon_cli -1 -f $cfg set t3-con t1-con t1-ref-a 123)" 0 ""
new "cli validate"
expectpart "$($clixon_cli -1 -f $cfg validate)" 0 ""
if [ $BE -ne 0 ]; then
new "Kill backend"
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
fi
rm -rf $dir
new "endtest"
endtest