#!/bin/bash # Test7: Yang specifics: leafref # include err() and new() functions . ./lib.sh # For memcheck # clixon_netconf="valgrind --leak-check=full --show-leak-kinds=all clixon_netconf" clixon_netconf=clixon_netconf clixon_cli=clixon_cli cat < /tmp/leafref.yang module example{ import ietf-ip { prefix ip; } 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=eth0]" + "/address/ip"; } } } } EOF # XXX not eth0 path "../../interface[name = current()/../ifname]" # kill old backend (if any) new "kill old backend" sudo clixon_backend -zf $clixon_cf -y /tmp/leafref.yang if [ $? -ne 0 ]; then err fi new "start backend" # start new backend sudo clixon_backend -If $clixon_cf -y /tmp/leafref.yang if [ $? -ne 0 ]; then err fi new "leafref base config" expecteof "$clixon_netconf -qf $clixon_cf -y /tmp/leafref.yang" " eth0 eth
192.0.2.1
192.0.2.2
lolo
127.0.0.1
]]>]]>" "^]]>]]>$" new "leafref get config" expecteof "$clixon_netconf -qf $clixon_cf" ']]>]]>' '^eth0' new "leafref base commit" expecteof "$clixon_netconf -qf $clixon_cf -y /tmp/leafref.yang" "]]>]]>" "^]]>]]>$" new "leafref add wrong ref" expecteof "$clixon_netconf -qf $clixon_cf -y /tmp/leafref.yang" "eth3
10.0.4.6
]]>]]>" "^]]>]]>$" new "leafref validate" expecteof "$clixon_netconf -qf $clixon_cf -y /tmp/leafref.yang" "]]>]]>" "^missing-attribute" new "leafref discard-changes" expecteof "$clixon_netconf -qf $clixon_cf" "]]>]]>" "^]]>]]>$" new "leafref add correct absref" expecteof "$clixon_netconf -qf $clixon_cf -y /tmp/leafref.yang" "eth0]]>]]>" "^]]>]]>$" new "leafref add correct relref" expecteof "$clixon_netconf -qf $clixon_cf -y /tmp/leafref.yang" "eth0]]>]]>" "^]]>]]>$" # XXX add address new "leafref validate (ok)" expecteof "$clixon_netconf -qf $clixon_cf -y /tmp/leafref.yang" "]]>]]>" "^" new "leafref delete leaf" expecteof "$clixon_netconf -qf $clixon_cf -y /tmp/leafref.yang" "eth0]]>]]>" "^" new "leafref validate (should fail)" expecteof "$clixon_netconf -qf $clixon_cf -y /tmp/leafref.yang" "]]>]]>" "^missing-attribute" new "leafref discard-changes" expecteof "$clixon_netconf -qf $clixon_cf" "]]>]]>" "^]]>]]>$" new "cli leafref lo" expectfn "$clixon_cli -1f $clixon_cf -y /tmp/leafref.yang -l o set default-address absname lo" "^$" new "cli leafref validate" expectfn "$clixon_cli -1f $clixon_cf -y /tmp/leafref.yang -l o validate" "^$" new "Kill backend" # Check if still alive pid=`pgrep clixon_backend` if [ -z "$pid" ]; then err "backend already dead" fi # kill backend sudo clixon_backend -zf $clixon_cf if [ $? -ne 0 ]; then err "kill backend" fi