#!/usr/bin/env bash # Yang leafref test # 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 fyang=$dir/leafref.yang cat < $cfg $cfg $dir /usr/local/share/clixon $IETFRFC $fyang /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 cat < $fyang module example{ yang-version 1.1; namespace "urn:example:clixon"; prefix ex; import ietf-interfaces { prefix if; } import ietf-ip { prefix ip; } identity eth { base if:interface-type; } identity lo { base if:interface-type; } container default-address { leaf absname { description "Absolute references existing interfaces in if module"; type leafref { path "/if:interfaces/if:interface/if:name"; } } leaf relname { type leafref { path "../../if:interfaces/if:interface/if:name"; } } leaf address { description "From RFC7950 9.9.6"; type leafref { path "../../if:interfaces/if:interface[if:name = current()/../relname]" + "/ip:ipv4/ip:address/ip:ip"; } } leaf wrong { description "References leading nowhere in yang"; type leafref { path "/ip:interfaces/ip:interface/ip:name"; } } } list sender{ key name; leaf name{ type string; } leaf template{ type leafref{ path "/sender/name"; } } } } EOF BASEXML=$(cat < eth0 ex:eth 192.0.2.1 24 192.0.2.2 24 lo ex:lo 127.0.0.1 32 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 new "leafref base config" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO$BASEXML]]>]]>" "^]]>]]>$" new "leafref get config" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^$BASEXML]]>]]>" new "leafref base commit" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^]]>]]>$" new "leafref add non-existing ref" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLOeth3
10.0.4.6
]]>]]>" "^]]>]]>$" new "leafref validate" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^applicationbad-elementeth3errorLeafref validation failed: No leaf eth3 matching path /if:interfaces/if:interface/if:name]]>]]>$" #new "leafref wrong ref" #expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLOeth3
10.0.4.6
]]>]]>" "^]]>]]>$" new "leafref discard-changes" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^]]>]]>$" new "leafref add correct absref" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLOeth0]]>]]>" "^]]>]]>$" new "leafref validate (ok)" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^" new "leafref add correct relref" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLOeth0]]>]]>" "^]]>]]>$" new "leafref validate (ok)" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^" new "leafref add correct address" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO
192.0.2.1
]]>]]>" "^]]>]]>$" new "leafref validate (ok)" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^" new "leafref delete leaf" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLOeth0]]>]]>" "^" new "leafref validate (should fail)" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^applicationbad-elementeth0errorLeafref validation failed: No leaf eth0 matching path /if:interfaces/if:interface/if:name]]>]]>$" new "leafref discard-changes" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^]]>]]>$" new "cli leafref lo" expectpart "$($clixon_cli -1f $cfg -l o set default-address absname lo)" 0 "^$" new "cli leafref validate" expectpart "$($clixon_cli -1f $cfg -l o validate)" 0 "^$" new "cli sender" expectpart "$($clixon_cli -1f $cfg -l o set sender a)" 0 "^$" new "cli sender template" expectpart "$($clixon_cli -1f $cfg -l o set sender b template a)" 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