#!/bin/bash # Transaction functionality # The test uses a backend that logs to a file and a netconf client to push # changes. The main example backend plugin logs to the file, and the test # verifies the logs. # The yang is a list with three members, so that you can do add/delete/change # in a single go. # Magic line must be first in script (see README.md) s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi # Which format to use as datastore format internally : ${format:=xml} APPNAME=example cfg=$dir/conf_yang.xml fyang=$dir/trans.yang flog=$dir/backend.log touch $flog cat < $fyang module trans{ yang-version 1.1; namespace "urn:example:clixon"; prefix ex; container x { list y { key "a"; leaf a { type int32; } leaf b { description "change this"; type int32; } leaf c { description "del this"; type int32; } leaf d { description "add this"; type int32; } } } } EOF cat < $cfg $cfg /usr/local/share/clixon $fyang /usr/local/lib/$APPNAME/clispec /usr/local/lib/$APPNAME/backend example_backend.so$ /usr/local/lib/$APPNAME/netconf /usr/local/lib/$APPNAME/restconf /usr/local/lib/$APPNAME/cli $APPNAME $dir/$APPNAME.sock /usr/local/var/$APPNAME/$APPNAME.pidfile 1 /usr/local/var/$APPNAME $format EOF # Check statements in log checklog(){ s=$1 # statement new "Check $s in log" t=$(grep "$s" $flog) if [ -z "$t" ]; then echo -e "\e[31m\nError in Test$testnr [$testname]:" if [ $# -gt 0 ]; then echo "Not found in log" echo fi echo -e "\e[0m" exit -1 fi } new "test params: -f $cfg -l f$flog -- -t" # Bring your own backend if [ $BE -ne 0 ]; then # kill old backend (if any) new "kill old backend" sudo clixon_backend -zf $cfg if [ $? -ne 0 ]; then err fi new "start backend -s init -f $cfg -l f$flog -- -t" start_backend -s init -f $cfg -l f$flog -- -t # -t means transaction logging new "waiting" sleep $RCWAIT fi new "netconf base config (0) a,b,c" expecteof "$clixon_netconf -qf $cfg" 0 '000]]>]]>' '^]]>]]>$' new "netconf commit base" expecteof "$clixon_netconf -qf $cfg" 0 ']]>]]>' '^]]>]]>$' #Ignore new "netconf mixed change: change b, del c, add d" expecteof "$clixon_netconf -qf $cfg" 0 '0420]]>]]>' '^]]>]]>$' new "netconf commit change" expecteof "$clixon_netconf -qf $cfg" 0 ']]>]]>' '^]]>]]>$' # Check complete transaction 2: for op in begin validate complete commit; do checklog "transaction_log 2 $op add: 0" checklog "transaction_log 2 $op change: 042" done # End is special checklog "transaction_log 2 end add: 0" checklog "transaction_log 2 end change: 42" new "netconf config (1) end-points a,d " expecteof "$clixon_netconf -qf $cfg" 0 '11]]>]]>' '^]]>]]>$' new "netconf commit base" expecteof "$clixon_netconf -qf $cfg" 0 ']]>]]>' '^]]>]]>$' new "netconf insert b,c between end-points" expecteof "$clixon_netconf -qf $cfg" 0 '111]]>]]>' '^]]>]]>$' new "netconf commit base" expecteof "$clixon_netconf -qf $cfg" 0 ']]>]]>' '^]]>]]>$' checklog "transaction_log 4 validate add: 11" 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 stop_backend -f $cfg #rm -rf $dir