#!/bin/bash # Yang when and must conditional xpath specification # Testing of validation phase. APPNAME=example # include err() and new() functions and creates $dir . ./lib.sh cfg=$dir/conf_yang.xml fyang=$dir/test.yang cat < $cfg $cfg /usr/local/share/$APPNAME/yang $APPNAME /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 $APPNAME{ prefix ex; identity routing-protocol { description "Base identity from which routing protocol identities are derived."; } identity direct { base routing-protocol; description "Routing pseudo-protocol which provides routes to directly connected networks."; } identity static { base routing-protocol; description "Static routing pseudo-protocol."; } list whenex { key "type name"; leaf type { type identityref { base routing-protocol; } } leaf name { type string; } leaf route-preference { type uint32; } container static-routes { when "../type='static'" { description "This container is only valid for the 'static' routing protocol."; } presence true; } } container interface { leaf ifType { type enumeration { enum ethernet; enum atm; } } leaf ifMTU { type uint32; } must 'ifType != "ethernet" or ifMTU = 1500' { error-message "An Ethernet MTU must be 1500"; } must 'ifType != "atm" or' + ' (ifMTU <= 17966 and ifMTU >= 64)' { error-message "An ATM MTU must be 64 .. 17966"; } } } EOF # kill old backend (if any) new "kill old backend" sudo clixon_backend -zf $cfg -y $fyang if [ $? -ne 0 ]; then err fi new "start backend -s init -f $cfg -y $fyang" # start new backend sudo $clixon_backend -s init -f $cfg -y $fyang if [ $? -ne 0 ]; then err fi new "when: add static route" expecteof "$clixon_netconf -qf $cfg -y $fyang" 0 "staticr1]]>]]>" "^]]>]]>$" new "when: validate ok" expecteof "$clixon_netconf -qf $cfg -y $fyang" 0 "]]>]]>" "^]]>]]>$" new "when: add direct route" expecteof "$clixon_netconf -qf $cfg -y $fyang" 0 "directr2]]>]]>" "^]]>]]>$" new "when get config" expecteof "$clixon_netconf -qf $cfg -y $fyang" 0 "]]>]]>" "^directr2staticr1]]>]]>$" new "when: validate fail" expecteof "$clixon_netconf -qf $cfg -y $fyang" 0 "]]>]]>" "^operation-failedapplicationerrorxpath static-routes validation failed]]>]]>$" new "when: discard-changes" expecteof "$clixon_netconf -qf $cfg -y $fyang" 0 "]]>]]>" "^]]>]]>$" new "must: add interface" expecteof "$clixon_netconf -qf $cfg -y $fyang" 0 "ethernet1500]]>]]>" "^]]>]]>$" new "must: validate ok" expecteof "$clixon_netconf -qf $cfg -y $fyang" 0 "]]>]]>" "^]]>]]>$" new "must: add atm interface" expecteof "$clixon_netconf -qf $cfg -y $fyang" 0 "atm32]]>]]>" "^]]>]]>$" new "must: atm validate fail" expecteof "$clixon_netconf -qf $cfg -y $fyang" 0 "]]>]]>" "^operation-failedapplicationerrorAn ATM MTU must be 64 .. 17966]]>]]>$" new "must: add eth interface" expecteof "$clixon_netconf -qf $cfg -y $fyang" 0 "ethernet989]]>]]>" "^]]>]]>$" new "must: eth validate fail" expecteof "$clixon_netconf -qf $cfg -y $fyang" 0 "]]>]]>" "^operation-failedapplicationerrorAn Ethernet MTU must be 1500]]>]]>" # Check if still alive pid=`pgrep clixon_backend` if [ -z "$pid" ]; then err "backend already dead" fi # kill backend sudo clixon_backend -zf $cfg if [ $? -ne 0 ]; then err "kill backend" fi rm -rf $dir