#!/usr/bin/env bash # Transaction functionality: Start from startup and ensure # first transaction is OK including diff # See eg https://github.com/clicon/clixon/issues/596 # Magic line must be first in script (see README.md) s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi APPNAME=example cfg=$dir/conf_yang.xml fyang=$dir/trans.yang flog=$dir/backend.log touch $flog # Used as a trigger for user-validation errors, eg $errnr = 42 is invalid errnr=42 cat < $fyang module trans{ yang-version 1.1; namespace "urn:example:clixon"; prefix ex; container x { leaf y { type string; default "abc"; } leaf z { type string; } } } EOF cat < $cfg $cfg ietf-netconf:startup ${YANG_INSTALLDIR} $fyang /usr/local/lib/$APPNAME/clispec /usr/local/lib/$APPNAME/backend /usr/local/lib/$APPNAME/netconf /usr/local/lib/$APPNAME/restconf /usr/local/lib/$APPNAME/cli $APPNAME $dir/$APPNAME.sock /usr/local/var/run/$APPNAME.pidfile $dir EOF # Create startup db revision from 2014-05-08 to be upgraded to 2018-02-20 # This is 2014 syntax cat < $dir/startup_db <${DATASTORE_TOP}> efg EOF # Check statements in log # arg1: a statement to look for # arg2: expected line number function checklog(){ s=$1 # statement l0=$2 # linenr new "Check $s in log" echo "grep \"transaction_log $s line:$l0\" $flog" t=$(grep -n "transaction_log $s" $flog) if [ -z "$t" ]; then echo -e "\e[31m\nError in Test$testnr [$testname]:" if [ $# -gt 0 ]; then echo "Not found \"$s\" on line $l0" echo fi echo -e "\e[0m" exit -1 fi l1=$(echo "$t" | awk -F ":" '{print $1}') if [ $l1 -ne $l0 ]; then echo -e "\e[31m\nError in Test$testnr [$testname]:" if [ $# -gt 0 ]; then echo "Expected match on line $l0, found on $l1" 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 startup -f $cfg -l f$flog -- -t # -t means transaction logging fi new "wait backend" wait_backend let line=0 # Skipping basic transaction let line++ checklog "0 main_begin add: abcefg" $line if [ $BE -ne 0 ]; then 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 fi rm -rf $dir new "endtest" endtest