diff --git a/test/lib.sh b/test/lib.sh index 467fccd8..00eec2d7 100755 --- a/test/lib.sh +++ b/test/lib.sh @@ -1,7 +1,16 @@ #!/bin/bash +# Define test functions. +# Create working dir as variable "dir" testnr=0 testname= + +dir=/var/tmp/$0 +if [ ! -d $dir ]; then + mkdir $dir +fi +rm -rf $dir/* + # error and exit, arg is optional extra errmsg err(){ echo "Error in Test$testnr [$testname]:" diff --git a/test/test_cli.sh b/test/test_cli.sh index a77329ca..75f596eb 100755 --- a/test/test_cli.sh +++ b/test/test_cli.sh @@ -1,4 +1,5 @@ #!/bin/bash + # Test1: backend and cli basic functionality # Start backend server # Add an ethernet interface and an address @@ -7,9 +8,25 @@ # Set the mandatory type # Commit -# include err() and new() functions +# include err() and new() functions and creates $dir . ./lib.sh -cfg=/usr/local/etc/routing.xml +cfg=$dir/conf_yang.xml + +cat < $cfg + + $cfg + /usr/local/share/routing/yang + example + /usr/local/lib/routing/clispec + /usr/local/lib/routing/cli + routing + /usr/local/var/routing/routing.sock + /usr/local/var/routing/routing.pidfile + 1 + /usr/local/var/routing + /usr/local/lib/xmldb/text.so + +EOF # For memcheck #clixon_cli="valgrind --leak-check=full --show-leak-kinds=all clixon_cli" @@ -104,3 +121,4 @@ if [ $? -ne 0 ]; then err "kill backend" fi +rm -rf $dir diff --git a/test/test_datastore.sh b/test/test_datastore.sh index acf6af59..6f7ae875 100755 --- a/test/test_datastore.sh +++ b/test/test_datastore.sh @@ -2,12 +2,13 @@ # Test5: datastore tests. # Just run a binary direct to datastore. No clixon. -# include err() and new() functions +# include err() and new() functions and creates $dir . ./lib.sh +fyang=$dir/ietf-ip.yang datastore=datastore_client -cat < /tmp/ietf-ip.yang +cat < $fyang module ietf-ip{ container x { list y { @@ -46,14 +47,14 @@ db='12first-entry13se run(){ name=$1 - dir=/tmp/$name + mydir=$dir/$name - if [ ! -d $dir ]; then - mkdir $dir + if [ ! -d $mydir ]; then + mkdir $mydir fi - rm -rf $dir/* + rm -rf $mydir/* - conf="-d candidate -b $dir -p ../datastore/$name/$name.so -y /tmp -m ietf-ip" + conf="-d candidate -b $mydir -p ../datastore/$name/$name.so -y $dir -m ietf-ip" echo "conf:$conf" new "datastore $name init" expectfn "$datastore $conf init" "" @@ -140,21 +141,23 @@ run(){ expectfn "$datastore $conf put create 13newentry" new "datastore other db init" - expectfn "$datastore -d kalle -b $dir -p ../datastore/$name/$name.so -y /tmp -m ietf-ip init" + expectfn "$datastore -d kalle -b $mydir -p ../datastore/$name/$name.so -y $dir -m ietf-ip init" new "datastore other db copy" expectfn "$datastore $conf copy kalle" "" - diff $dir/kalle_db $dir/candidate_db + diff $mydir/kalle_db $mydir/candidate_db new "datastore lock" expectfn "$datastore $conf lock 756" "" #leaf-list - rm -rf $dir + rm -rf $mydir } #run keyvalue # cant get the put to work run text +rm -rf $dir + diff --git a/test/test_install.sh b/test/test_install.sh index 171b14b7..5e88336b 100755 --- a/test/test_install.sh +++ b/test/test_install.sh @@ -1,64 +1,60 @@ #!/bin/bash # Install test -# include err() and new() functions +# include err() and new() functions and creates $dir . ./lib.sh -DIR=/tmp/clixoninstall - -new "Set up installdir $DIR" -rm -rf $DIR -mkdir $DIR +new "Set up installdir $dir" new "Make DESTDIR install" -(cd ..; make DESTDIR=$DIR install) +(cd ..; make DESTDIR=$dir install) if [ $? -ne 0 ]; then err fi new "Check installed files" -if [ ! -d $DIR/usr ]; then - err $DIR/usr +if [ ! -d $dir/usr ]; then + err $dir/usr fi -if [ ! -d $DIR/www-data ]; then - err $DIR/www-data +if [ ! -d $dir/www-data ]; then + err $dir/www-data fi -if [ ! -f $DIR/usr/local/share/clixon/clixon.mk ]; then - err $DIR/usr/local/share/clixon/clixon.mk +if [ ! -f $dir/usr/local/share/clixon/clixon.mk ]; then + err $dir/usr/local/share/clixon/clixon.mk fi -if [ ! -f $DIR/usr/local/share/clixon/clixon-config* ]; then - err $DIR/usr/local/share/clixon/clixon-config* +if [ ! -f $dir/usr/local/share/clixon/clixon-config* ]; then + err $dir/usr/local/share/clixon/clixon-config* fi -if [ ! -h $DIR/usr/local/lib/libclixon.so ]; then - err $DIR/usr/local/lib/libclixon.so +if [ ! -h $dir/usr/local/lib/libclixon.so ]; then + err $dir/usr/local/lib/libclixon.so fi -if [ ! -h $DIR/usr/local/lib/libclixon_backend.so ]; then - err $DIR/usr/local/lib/libclixon_backend.so +if [ ! -h $dir/usr/local/lib/libclixon_backend.so ]; then + err $dir/usr/local/lib/libclixon_backend.so fi new "Make DESTDIR install include" -(cd ..; make DESTDIR=$DIR install-include) +(cd ..; make DESTDIR=$dir install-include) if [ $? -ne 0 ]; then err fi new "Check installed includes" -if [ ! -f $DIR/usr/local/include/clixon/clixon.h ]; then - err $DIR/usr/local/include/clixon/clixon.h +if [ ! -f $dir/usr/local/include/clixon/clixon.h ]; then + err $dir/usr/local/include/clixon/clixon.h fi new "Make DESTDIR uninstall" -(cd ..; make DESTDIR=$DIR uninstall) +(cd ..; make DESTDIR=$dir uninstall) if [ $? -ne 0 ]; then err fi new "Check remaining files" -f=$(find $DIR -type f) +f=$(find $dir -type f) if [ -n "$f" ]; then err "$f" fi new "Check remaining symlinks" -l=$(find $DIR -type l) +l=$(find $dir -type l) if [ -n "$l" ]; then err "$l" fi diff --git a/test/test_leafref.sh b/test/test_leafref.sh index 715bb89b..f31893af 100755 --- a/test/test_leafref.sh +++ b/test/test_leafref.sh @@ -1,10 +1,26 @@ #!/bin/bash # Test7: Yang specifics: leafref -# include err() and new() functions +# include err() and new() functions and creates $dir . ./lib.sh -cfg=/usr/local/etc/routing.xml -fyang=/tmp/leafref.yang +cfg=$dir/conf_yang.xml +fyang=$dir/leafref.yang + +cat < $cfg + + $cfg + /usr/local/share/routing/yang + example + /usr/local/lib/routing/clispec + /usr/local/lib/routing/cli + routing + /usr/local/var/routing/routing.sock + /usr/local/var/routing/routing.pidfile + 1 + /usr/local/var/routing + /usr/local/lib/xmldb/text.so + +EOF # For memcheck # clixon_netconf="valgrind --leak-check=full --show-leak-kinds=all clixon_netconf" @@ -126,3 +142,5 @@ sudo clixon_backend -zf $cfg if [ $? -ne 0 ]; then err "kill backend" fi + +rm -rf $dir diff --git a/test/test_netconf.sh b/test/test_netconf.sh index 828464db..5b6798ec 100755 --- a/test/test_netconf.sh +++ b/test/test_netconf.sh @@ -1,9 +1,30 @@ #!/bin/bash # Test2: backend and netconf basic functionality -# include err() and new() functions +# include err() and new() functions and creates $dir . ./lib.sh -cfg=/usr/local/etc/routing.xml + +cfg=$dir/conf_yang.xml + +cat < $cfg + + $cfg + /usr/local/share/routing/yang + example + /usr/local/lib/routing/clispec + /usr/local/lib/routing/backend + /usr/local/lib/routing/netconf + /usr/local/lib/routing/restconf + /usr/local/lib/routing/cli + routing + /usr/local/var/routing/routing.sock + /usr/local/var/routing/routing.pidfile + 1 + /usr/local/var/routing + /usr/local/lib/xmldb/text.so + +EOF + # For memcheck #clixon_netconf="valgrind --leak-check=full --show-leak-kinds=all clixon_netconf" @@ -146,3 +167,5 @@ sudo clixon_backend -zf $cfg if [ $? -ne 0 ]; then err "kill backend" fi + +rm -rf $dir diff --git a/test/test_order.sh b/test/test_order.sh index 16ea036f..433ee9bd 100755 --- a/test/test_order.sh +++ b/test/test_order.sh @@ -6,20 +6,22 @@ # No test of ordered-by system is done yet # (we may want to sort them alphabetically for better performance). -# include err() and new() functions +# include err() and new() functions and creates $dir . ./lib.sh -cfg=/tmp/conf_yang.xml -fyang=/tmp/order.yang +cfg=$dir/conf_yang.xml +fyang=$dir/order.yang # For memcheck # clixon_netconf="valgrind --leak-check=full --show-leak-kinds=all clixon_netconf" clixon_netconf=clixon_netconf clixon_cli=clixon_cli -dbdir=/tmp/order +dbdir=$dir/order new "Set up $dbdir" rm -rf $dbdir -mkdir $dbdir +if [ ! -d $dbdir ]; then + mkdir $dbdir +fi cat < $cfg @@ -175,3 +177,5 @@ sudo clixon_backend -zf $cfg if [ $? -ne 0 ]; then err "kill backend" fi + +rm -rf $dir diff --git a/test/test_perf.sh b/test/test_perf.sh index 483dace7..a91e6bb4 100755 --- a/test/test_perf.sh +++ b/test/test_perf.sh @@ -14,13 +14,14 @@ else echo "Usage: $0 [ []]" exit 1 fi -cfg=/tmp/scaling-conf.xml -fyang=/tmp/scaling.yang -fconfig=/tmp/config -# include err() and new() functions +# include err() and new() functions and creates $dir . ./lib.sh +cfg=$dir/scaling-conf.xml +fyang=$dir/scaling.yang +fconfig=$dir/config + # For memcheck # clixon_netconf="valgrind --leak-check=full --show-leak-kinds=all clixon_netconf" @@ -153,3 +154,5 @@ sudo clixon_backend -zf $cfg if [ $? -ne 0 ]; then err "kill backend" fi + +rm -rf $dir diff --git a/test/test_restconf.sh b/test/test_restconf.sh index eccd4035..395e2827 100755 --- a/test/test_restconf.sh +++ b/test/test_restconf.sh @@ -2,11 +2,46 @@ # Restconf basic functionality # Assume http server setup, such as nginx described in apps/restconf/README.md -# include err() and new() functions +# include err() and new() functions and creates $dir . ./lib.sh -cfg=/usr/local/etc/routing.xml +cfg=$dir/conf.xml +fyang=$dir/restconf.yang -# This is a fixed 'state' implemented in routing_backend. It is always there +cat < $cfg + + $cfg + /usr/local/share/routing/yang + example + /usr/local/lib/routing/clispec + /usr/local/lib/routing/backend + /usr/local/lib/routing/restconf + false + /usr/local/lib/routing/cli + routing + /usr/local/var/routing/routing.sock + /usr/local/var/routing/routing.pidfile + 1 + /usr/local/var/routing + /usr/local/lib/xmldb/text.so + +EOF + +cat < $fyang +module example{ + import ietf-ip { + prefix ip; + } + import ietf-routing { + prefix rt; + } + import ietf-inet-types { + prefix "inet"; + revision-date "2013-07-15"; + } +} +EOF + +# This is a fixed 'state' implemented in routing_backend. It is assumed to be always there state='{"interfaces-state": {"interface": {"name": "eth0","type": "eth","if-index": "42"}}}' # kill old backend (if any) @@ -15,8 +50,8 @@ sudo clixon_backend -zf $cfg if [ $? -ne 0 ]; then err fi -new "start backend -s init -f $cfg" -sudo clixon_backend -s init -f $cfg +new "start backend -s init -f $cfg -y $fyang" +sudo clixon_backend -s init -f $cfg -y $fyang if [ $? -ne 0 ]; then err fi @@ -25,7 +60,7 @@ new "kill old restconf daemon" sudo pkill -u www-data clixon_restconf new "start restconf daemon" -sudo start-stop-daemon -S -q -o -b -x /www-data/clixon_restconf -d /www-data -c www-data -- -Df /usr/local/etc/routing.xml # -D +sudo start-stop-daemon -S -q -o -b -x /www-data/clixon_restconf -d /www-data -c www-data -- -Df $cfg # -D sleep 1 @@ -38,11 +73,51 @@ new "restconf head" expectfn "curl -sS -I http://localhost/restconf/data" "HTTP/1.1 200 OK" #Content-Type: application/yang-data+json" -new "restconf get empty config + state" -expectfn "curl -sSG http://localhost/restconf/data" $state +new "restconf root discovery" +expectfn "curl -sS -X GET http://localhost/.well-known/host-meta" "" -new "restconf get state operation" -expectfn "curl -sS -G http://localhost/restconf/data/interfaces-state" $state +#new "restconf get restconf json XXX" +#expectfn "curl -sSG http://localhost/restconf" "{\"restconf\" : $state }" + +#new "restconf get restconf/yang-library-version json XXX" +#expectfn "curl -sSG http://localhost/restconf/yang-library-version" "{\"restconf\" : $state }" + + +new "restconf get empty config + state json" +expectfn "curl -sSG http://localhost/restconf/data" "{\"data\": $state}" + +new "restconf get empty config + state xml" +ret=$(curl -sS -H "Accept: application/yang-data+xml" -G http://localhost/restconf/data) +expect="eth0eth42" +match=`echo $ret | grep -EZo "$expect"` +if [ -z "$match" ]; then + err "$expect" "$ret" +fi + +new "restconf get data/interfaces-state/interface=eth0 json" +expectfn "curl -sS -G http://localhost/restconf/data/interfaces-state/interface=eth0" '{"interface": {"name": "eth0","type": "eth","if-index": "42"}}' + +new "restconf get state operation eth0 xml" +# Cant get shell macros to work, inline matching from lib.sh +ret=$(curl -sS -H "Accept: application/yang-data+xml" -G http://localhost/restconf/data/interfaces-state/interface=eth0) +expect="eth0eth42" +match=`echo $ret | grep -EZo "$expect"` +if [ -z "$match" ]; then + err "$expect" "$ret" +fi + +new "restconf get state operation eth0 type json" +expectfn "curl -sS -G http://localhost/restconf/data/interfaces-state/interface=eth0/type" '{"type": "eth"} +$' + +new "restconf get state operation eth0 type xml" +# Cant get shell macros to work, inline matching from lib.sh +ret=$(curl -sS -H "Accept: application/yang-data+xml" -G http://localhost/restconf/data/interfaces-state/interface=eth0/type) +expect="eth" +match=`echo $ret | grep -EZo "$expect"` +if [ -z "$match" ]; then + err "$expect" "$ret" +fi new "restconf Add subtree to datastore using POST" expectfn 'curl -sS -X POST -d {"interfaces":{"interface":{"name":"eth/0/0","type":"eth","enabled":"true"}}} http://localhost/restconf/data' "" @@ -93,12 +168,16 @@ $' new "restconf operation rpc using POST json" expectfn 'curl -sS -X POST -d {"input":{"routing-instance-name":"ipv4"}} http://localhost/restconf/operations/rt:fib-route' '{ "output": { "route": { "address-family": "ipv4", "next-hop": { "next-hop-list": "2.3.4.5" } } } } ' +exit # XXX + new "restconf rpc using POST xml" +# Cant get shell macros to work, inline matching from lib.sh ret=$(curl -sS -X POST -H "Accept: application/yang-data+xml" -d '{"input":{"routing-instance-name":"ipv4"}}' http://localhost/restconf/operations/rt:fib-route) expect=" ipv4 2.3.4.5 " match=`echo $ret | grep -EZo "$expect"` -echo -n "ret: " -echo $ret +if [ -z "$match" ]; then + err "$expect" "$ret" +fi new "Kill restconf daemon" sudo pkill -u www-data clixon_restconf @@ -114,3 +193,5 @@ sudo clixon_backend -zf $cfg if [ $? -ne 0 ]; then err "kill backend" fi + +rm -rf $dir diff --git a/test/test_startup.sh b/test/test_startup.sh index 93541b2a..53f7c257 100755 --- a/test/test_startup.sh +++ b/test/test_startup.sh @@ -6,9 +6,9 @@ # - running db starts with a "run" interface # - startup db starts with a "start" interface -# include err() and new() functions +# include err() and new() functions and creates $dir . ./lib.sh -cfg=/tmp/conf_startup.xml +cfg=$dir/conf_startup.xml # For memcheck # clixon_netconf="valgrind --leak-check=full --show-leak-kinds=all clixon_netconf" @@ -42,7 +42,8 @@ run(){ mode=$1 expect=$2 - cat < /tmp/db + dbdir=$dir/db + cat < $dbdir @@ -52,9 +53,9 @@ run(){ EOF - sudo mv /tmp/db /usr/local/var/routing/running_db + sudo mv $dbdir /usr/local/var/routing/running_db - cat < /tmp/db + cat < $dbdir @@ -64,9 +65,9 @@ EOF EOF - sudo mv /tmp/db /usr/local/var/routing/startup_db + sudo mv $dbdir /usr/local/var/routing/startup_db - cat < /tmp/config + cat < $dir/config @@ -84,8 +85,8 @@ EOF err fi - new "start backend -f $cfg -s $mode -c /tmp/config" - sudo clixon_backend -f $cfg -s $mode -c /tmp/config + new "start backend -f $cfg -s $mode -c $dir/config" + sudo clixon_backend -f $cfg -s $mode -c $dir/config if [ $? -ne 0 ]; then err fi @@ -111,3 +112,4 @@ run none 'runethextraethtruelolocaltruerunethtrue' run startup 'extraethtruelolocaltruestartupethtrue' +rm -rf $dir diff --git a/test/test_type.sh b/test/test_type.sh index 0c6afbef..432d30cb 100755 --- a/test/test_type.sh +++ b/test/test_type.sh @@ -2,10 +2,27 @@ # Advanced union types and generated code # and enum w values -# include err() and new() functions +# include err() and new() functions and creates $dir . ./lib.sh -cfg=/usr/local/etc/routing.xml -fyang=/tmp/type.yang +fyang=$dir/type.yang +cfg=$dir/conf_yang.xml + +cat < $cfg + + $cfg + /usr/local/share/routing/yang + example + /usr/local/lib/routing/clispec + /usr/local/lib/routing/cli + routing + /usr/local/var/routing/routing.sock + /usr/local/var/routing/routing.pidfile + 1 + /usr/local/var/routing + /usr/local/lib/xmldb/text.so + +EOF + # For memcheck #clixon_cli="valgrind --leak-check=full --show-leak-kinds=all clixon_cli" @@ -126,3 +143,4 @@ if [ $? -ne 0 ]; then err "kill backend" fi +rm -rf $dir diff --git a/test/test_yang.sh b/test/test_yang.sh index 506109b3..c2cdead5 100755 --- a/test/test_yang.sh +++ b/test/test_yang.sh @@ -1,10 +1,11 @@ #!/bin/bash # Test4: Yang specifics: multi-keys and empty type -# include err() and new() functions +# include err() and new() functions and creates $dir . ./lib.sh -cfg=/tmp/conf_yang.xml -fyang=/tmp/test.yang + +cfg=$dir/conf_yang.xml +fyang=$dir/test.yang # For memcheck # clixon_netconf="valgrind --leak-check=full --show-leak-kinds=all clixon_netconf" @@ -151,3 +152,5 @@ sudo clixon_backend -zf $cfg if [ $? -ne 0 ]; then err "kill backend" fi + +rm -rf $dir