1# #-- dnstap_reconnect.test --# 2# source the master var file when it's there 3[ -f ../.tpkg.var.master ] && source ../.tpkg.var.master 4# use .tpkg.var.test for in test variable passing 5[ -f .tpkg.var.test ] && source .tpkg.var.test 6 7. ../common.sh 8PRE="../.." 9 10# test if the server is up. 11echo "> dig www.example.com." 12dig @127.0.0.1 -p $UNBOUND_PORT www.example.com. | tee outfile 13echo "> check answer" 14if grep "10.20.30.40" outfile; then 15 echo "OK" 16else 17 echo "> cat logfiles" 18 cat tap.log 19 cat tap.errlog 20 cat fwd.log 21 cat unbound.log 22 echo "Not OK" 23 exit 1 24fi 25 26echo "> check tap.log for dnstap info" 27# see if it logged the information in tap.log 28# wait for a moment for filesystem to catch up. 29if grep "www.example.com" tap.log >/dev/null; then :; else sleep 1; fi 30if grep "www.example.com" tap.log >/dev/null; then :; else sleep 1; fi 31if grep "www.example.com" tap.log >/dev/null; then :; else sleep 1; fi 32if grep "www.example.com" tap.log >/dev/null; then :; else sleep 10; fi 33if grep "www.example.com" tap.log; then echo "yes it is in tap.log"; 34else 35 echo "information not in tap.log" 36 echo "failed" 37 echo "> cat logfiles" 38 cat tap.log 39 cat tap.errlog 40 cat fwd.log 41 cat unbound.log 42 echo "Not OK" 43 exit 1 44fi 45 46echo "" 47echo "> test disconnect from the upstream server" 48 49kill_pid $DNSTAP_SOCKET_PID 50dig @127.0.0.1 -p $UNBOUND_PORT down.example.net. 51 52# bring log socket back up 53$PRE/unbound-dnstap-socket -u dnstap.socket -l -vvvv 2>tap2.errlog >tap2.log & 54if test $? -ne 0; then 55 echo "could not start (again) unbound-dnstap-socket server" 56 exit 1 57fi 58DNSTAP_SOCKET_PID=$! 59echo "DNSTAP_SOCKET_PID=$DNSTAP_SOCKET_PID" >> .tpkg.var.test 60# wait for the server to go up and make the dnstap.socket file 61wait_server_up "tap2.errlog" "creating unix socket" 62 63dig @127.0.0.1 -p $UNBOUND_PORT up.example.net. 64sleep 2 65dig @127.0.0.1 -p $UNBOUND_PORT up2.example.net. 66 67for x in down up up2; do 68 if grep "$x.example.net" tap2.log >/dev/null; then :; else sleep 1; fi 69 if grep "$x.example.net" tap2.log >/dev/null; then :; else sleep 1; fi 70 if grep "$x.example.net" tap2.log >/dev/null; then :; else sleep 1; fi 71 if grep "$x.example.net" tap2.log >/dev/null; then :; else sleep 10; fi 72 if grep "$x.example.net" tap2.log; then echo "yes it is in tap2.log"; 73 else 74 echo "$x.example.net. information not in tap2.log" 75 echo "failed" 76 echo "> cat logfiles" 77 cat tap.log 78 cat tap.errlog 79 echo "> tap2 logfiles" 80 cat tap2.log 81 cat tap2.errlog 82 cat fwd.log 83 cat unbound.log 84 echo "Not OK" 85 exit 1 86 fi 87done 88 89echo "> cat logfiles" 90cat tap.log 91cat tap.errlog 92echo "> tap2 logfiles" 93cat tap2.log 94cat tap2.errlog 95cat fwd.log 96echo "> OK" 97exit 0 98