#!/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 ietf-ip{ typedef admin-status{ type string; } list interface { key "name"; leaf name { type string; } leaf admin-status { type admin-status; } list address { key "ip"; leaf ip { type string; } } } container default-address { leaf ifname { type leafref { path "../../interface/name"; } } leaf address { type leafref { path "../../interface[name=eth0]" + "/address/ip"; } } } } EOF # path "../../interface[name = current()/../ifname]" # kill old backend (if any) new "kill old backend" sudo clixon_backend -zf $clixon_cf -y /tmp/leafref if [ $? -ne 0 ]; then err fi new "start backend" # start new backend sudo clixon_backend -If $clixon_cf -y /tmp/leafref if [ $? -ne 0 ]; then err fi new "leafref base config" expecteof "$clixon_netconf -qf $clixon_cf -y /tmp/leafref" "eth0up
192.0.2.1
192.0.2.2
loup
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" "]]>]]>" "^]]>]]>$" new "leafref add wrong ref" expecteof "$clixon_netconf -qf $clixon_cf -y /tmp/leafref" "eth3
10.0.4.6
]]>]]>" "^]]>]]>$" new "leafref validate" expecteof "$clixon_netconf -qf $clixon_cf -y /tmp/leafref" "]]>]]>" "^missing-attribute" new "leafref discard-changes" expecteof "$clixon_netconf -qf $clixon_cf" "]]>]]>" "^]]>]]>$" new "leafref add correct ref" expecteof "$clixon_netconf -qf $clixon_cf -y /tmp/leafref" "eth0
192.0.2.2
]]>]]>" "^]]>]]>$" new "leafref validate (ok)" expecteof "$clixon_netconf -qf $clixon_cf -y /tmp/leafref" "]]>]]>" "^" new "leafref delete leaf" expecteof "$clixon_netconf -qf $clixon_cf -y /tmp/leafref" "eth0]]>]]>" "^" new "leafref validate (should fail)" expecteof "$clixon_netconf -qf $clixon_cf -y /tmp/leafref" "]]>]]>" "^missing-attribute" 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