#!/usr/bin/env bash # Yang leafref + augment + grouping taking from a more complex netgate errorcase # A main yang spec: leafref # and a secondary yang spec: augment # module leafref has a primary construct (sender) and a leafref typedef # module augment has an augment and a grouping from where it uses the leafref typedef # Which means that you should first have xml such as: # # x # # and you can then track it via for example (extra levels for debugging): # # y # # original # # augment # # grouping # # x <---- # # # # # # # There is also test for using prefixes or not, as well as swithcing prefix between the main module and # it import statement. # 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/leafref.yang fyang2=$dir/augment.yang cat < $cfg $cfg $dir /usr/local/share/clixon $fyang2 /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/var/$APPNAME EOF # NOTE prefix "example" used in module different from "ex" used in mport of that module cat < $fyang1 module leafref{ yang-version 1.1; namespace "urn:example:example"; prefix example; typedef sender-ref { description "For testing leafref across augment and grouping"; type leafref { path "/ex:sender/ex:name"; } } typedef sender-ref-local { description "For testing leafref local"; type leafref { path "/example:sender/example:name"; } } list sender{ key name; leaf name{ type string; } container stub{ description "Here is where augmentation is done"; } leaf ref{ description "top-level ref (wrong prefix)"; type sender-ref; } leaf ref-local{ description "top-level ref (right prefix)"; type sender-ref-local; } } } EOF cat < $fyang2 module augment{ yang-version 1.1; namespace "urn:example:augment"; prefix aug; import leafref { description "Note different from canonical (leafref module own prefix is 'example'"; prefix "ex"; } grouping attributes { container track{ description "replicates original structure but only references original"; list sender{ description "reference using path in typedef"; key name; leaf name{ type ex:sender-ref; } } list senderdata{ description "reference using path inline in data (not typedef)"; key name; leaf name{ type leafref { path "/ex:sender/ex:name"; } } } } } augment "/ex:sender/ex:stub" { description "Main leafref/sender stub."; container extra{ presence "ensuring it is there"; uses attributes; } } } 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 new "waiting" wait_backend fi # Test top-level, default prefix, wring leafref prefix and typedef path XML=$(cat < x y x EOF ) new "leafref augment+leafref config top-level" expecteof "$clixon_netconf -qf $cfg" 0 "$XML]]>]]>" "^]]>]]>$" new "leafref augment+leafref validate top-level wrong prefix" expecteof "$clixon_netconf -qf $cfg" 0 "]]>]]>" "^applicationbad-elementxerrorLeafref validation failed: No leaf x matching path /ex:sender/ex:name]]>]]>$" new "netconf discard-changes" expecteof "$clixon_netconf -qf $cfg" 0 "]]>]]>" "^]]>]]>$" # Test top-level, default prefix, correct leafref and typedef path XML=$(cat < x y x EOF ) # Use augment + explicit prefixes, correct leafref and typedef path XML=$(cat < x y x EOF ) new "leafref augment+leafref config" expecteof "$clixon_netconf -qf $cfg" 0 "$XML]]>]]>" "^]]>]]>$" new "leafref augment+leafref validate" expecteof "$clixon_netconf -qf $cfg" 0 "]]>]]>" "^]]>]]>$" new "netconf discard-changes" expecteof "$clixon_netconf -qf $cfg" 0 "]]>]]>" "^]]>]]>$" # Use augment, default prefixes, wrong leafref and typedef path XML=$(cat < x y xxx EOF ) new "leafref augment+leafref config wrong ref" expecteof "$clixon_netconf -qf $cfg" 0 "$XML]]>]]>" "^]]>]]>$" new "leafref augment+leafref validate wrong ref" expecteof "$clixon_netconf -qf $cfg" 0 "]]>]]>" "^applicationbad-elementxxxerrorLeafref validation failed: No leaf xxx matching path /ex:sender/ex:name]]>]]>$" new "netconf discard-changes" expecteof "$clixon_netconf -qf $cfg" 0 "]]>]]>" "^]]>]]>$" # Use augment, default prefixes, correct leafref and in-data path XML=$(cat < x y x EOF ) new "leafref augment+leafref config in-data" expecteof "$clixon_netconf -qf $cfg" 0 "$XML]]>]]>" "^]]>]]>$" new "leafref augment+leafref validate in-data" expecteof "$clixon_netconf -qf $cfg" 0 "]]>]]>" "^]]>]]>$" new "netconf discard-changes" expecteof "$clixon_netconf -qf $cfg" 0 "]]>]]>" "^]]>]]>$" if [ $BE -eq 0 ]; then exit # BE fi 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 rm -rf $dir