diff --git a/CHANGELOG.md b/CHANGELOG.md index 38f2da05..d2f2f103 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -70,6 +70,7 @@ Users may have to change how they access the system ### 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 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) diff --git a/lib/src/clixon_validate.c b/lib/src/clixon_validate.c index 13052cdd..aa4cb6a8 100644 --- a/lib/src/clixon_validate.c +++ b/lib/src/clixon_validate.c @@ -111,7 +111,7 @@ * node is the leaf or leaf-list node in the data tree that * references the typedef. (ie ys) * 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 @@ -162,8 +162,7 @@ validate_leafref(cxobj *xt, } if ((leafrefbody = xml_body(xt)) == NULL) goto ok; - /* See comment^: If path is defined in typedef or not */ - if (xml_nsctx_node(xt, &nsc) < 0) + if (xml_nsctx_yang(ys, &nsc) < 0) goto done; if (xpath_vec(xt, nsc, "%s", &xvec, &xlen, path_arg) < 0) goto done; diff --git a/test/test_leafref_uses_augment.sh b/test/test_leafref_uses_augment.sh new file mode 100755 index 00000000..999b4a9e --- /dev/null +++ b/test/test_leafref_uses_augment.sh @@ -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 < $cfg + + $cfg + a:test + $dir + ${YANG_INSTALLDIR} + $fyang1 + /usr/local/lib/$APPNAME/clispec + /usr/local/lib/$APPNAME/cli + $APPNAME + /usr/local/var/$APPNAME/$APPNAME.sock + /usr/local/var/$APPNAME/$APPNAME.pidfile + /usr/local/lib/$APPNAME/backend + /usr/local/var/$APPNAME + false + ${AUTOCLI} + +EOF + +# This is the lib function with the base container +cat < $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 < $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