#!/bin/bash # Test7: Yang specifics: leafref APPNAME=example # include err() and new() functions and creates $dir . ./lib.sh 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 1 /usr/local/var/$APPNAME /usr/local/lib/xmldb/text.so 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 { type leafref { path "/ip:interfaces/ip:interface/ip:name"; } } leaf relname { type leafref { path "../../interfaces/interface/name"; } } leaf address { type leafref { path "../../interfaces/interface[name = current()/../relname]" + "/ipv4/address/ip"; } } } list sender{ key name; leaf name{ type string; } leaf template{ type leafref{ path "/sender/name"; } } } } 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" sudo $clixon_backend -s init -f $cfg -D $DBG if [ $? -ne 0 ]; then err fi fi new "leafref base config" expecteof "$clixon_netconf -qf $cfg" 0 'eth0ex:eth
192.0.2.124
192.0.2.224
loex:lo
127.0.0.132
]]>]]>' '^]]>]]>$' new "leafref get config" expecteof "$clixon_netconf -qf $cfg" 0 ']]>]]>' '^eth0' new "leafref base commit" expecteof "$clixon_netconf -qf $cfg" 0 "]]>]]>" "^]]>]]>$" new "leafref get config" expecteof "$clixon_netconf -qf $cfg" 0 ']]>]]>' '^eth0' new "leafref add wrong ref" expecteof "$clixon_netconf -qf $cfg" 0 'eth3
10.0.4.6
]]>]]>' '^]]>]]>$' new "leafref validate" expecteof "$clixon_netconf -qf $cfg" 0 "]]>]]>" '^applicationbad-elementeth3errorLeafref validation failed: No such leaf]]>]]>$' new "leafref discard-changes" expecteof "$clixon_netconf -qf $cfg" 0 "]]>]]>" "^]]>]]>$" new "leafref add correct absref" expecteof "$clixon_netconf -qf $cfg" 0 'eth0]]>]]>' '^]]>]]>$' new "leafref add correct relref" expecteof "$clixon_netconf -qf $cfg" 0 'eth0]]>]]>' '^]]>]]>$' # XXX add address new "leafref validate (ok)" expecteof "$clixon_netconf -qf $cfg" 0 "]]>]]>" "^" new "leafref delete leaf" expecteof "$clixon_netconf -qf $cfg" 0 'eth0]]>]]>' '^' new "leafref validate (should fail)" expecteof "$clixon_netconf -qf $cfg" 0 "]]>]]>" '^applicationbad-elementeth0errorLeafref validation failed: No such leaf]]>]]>$' new "leafref discard-changes" expecteof "$clixon_netconf -qf $cfg" 0 "]]>]]>" "^]]>]]>$" new "cli leafref lo" expectfn "$clixon_cli -1f $cfg -l o set default-address absname lo" 0 "^$" new "cli leafref validate" expectfn "$clixon_cli -1f $cfg -l o validate" 0 "^$" new "cli sender" expectfn "$clixon_cli -1f $cfg -l o set sender a" 0 "^$" new "cli sender template" expectfn "$clixon_cli -1f $cfg -l o set sender b template a" 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 sudo clixon_backend -z -f $cfg if [ $? -ne 0 ]; then err "kill backend" fi rm -rf $dir