From 53691dee703bd6ef58ff28bc1e2d7dbb961f77fa Mon Sep 17 00:00:00 2001 From: Stephan Duehr Date: Thu, 23 Mar 2017 11:44:46 +0100 Subject: [PATCH] Added test scripts for LAN Address feature --- tests/lan-addr-test | 122 +++++++++++++++++++++++++++++++++++ tests/lan-addr-test-passive | 124 ++++++++++++++++++++++++++++++++++++ 2 files changed, 246 insertions(+) create mode 100755 tests/lan-addr-test create mode 100755 tests/lan-addr-test-passive diff --git a/tests/lan-addr-test b/tests/lan-addr-test new file mode 100755 index 0000000..a748dff --- /dev/null +++ b/tests/lan-addr-test @@ -0,0 +1,122 @@ +#!/bin/sh +# +# Run a simple backup of the Bareos build directory +# then restore it. +# + +unset LANG +TestName="lan-addr-test" +JobName=backup +. scripts/functions + +scripts/cleanup +scripts/copy-confs + +# +# Zap out any schedule in default conf file so that +# it doesn't start during our test +# +outf="tmp/sed_tmp" +echo "s% Schedule =%# Schedule =%g" >${outf} +echo "s%Name = \"BackupClient1\"%Name = \"backup\"; client run after job = \"netstat -tan\"%g" >>${outf} +cp $scripts/bareos-dir.conf $tmp/1 +sed -f ${outf} $tmp/1 >$scripts/bareos-dir.conf + +PATH=$PATH:/sbin:/usr/sbin +# +# Deduce a primary IP address by examining +# the interface defined by INTERFACE= +# +os=`uname` +if [ $os = 'FreeBSD' ]; then + INTERFACE=bge0 + IP=`ifconfig ${INTERFACE} | perl -ne '/inet (.+?) / && print $1'` +elif [ $os = 'Linux' ]; then + INTERFACE=eth0 + IP=`ifconfig ${INTERFACE} | perl -ne '/inet addr:(.+?) / && print $1'` +fi + +if [ "$IP" = '' ]; then + # ifconfig output may be like this (RHEL/CentOS 7, Fedora, ...?) + # eth0: flags=4163 mtu 1500 + # inet 192.168.121.195 netmask 255.255.255.0 broadcast 192.168.121.255 + IP=`ifconfig ${INTERFACE} | perl -ne '/inet (.+?) / && print $1'` + if [ "$IP" = '' ]; then + echo "Can't detect ip address" + exit 0 + fi +fi + +outf="tmp/sed_tmp" +echo "s/Address =/Address = 127.0.0.1\n LAN Address = $IP\n #/g" > $outf +cp $scripts/bareos-dir.conf $tmp/1 +sed -f ${outf} ${cwd}/tmp/1 > $scripts/bareos-dir.conf + +DIRPORT=$BASEPORT +FDPORT=$(($BASEPORT + 1)) +SDPORT=$(($BASEPORT + 2)) + +change_jobname BackupClient1 $JobName +start_test + +cat <${cwd}/tmp/bconcmds +@$out /dev/null +messages +@$out ${cwd}/tmp/log1.out +@#label volume=TestVolume001 storage=File pool=Full +@#setdebug level=100 storage=File +run job=$JobName yes +@#sleep 3 +messages +quit +END_OF_DATA + +run_bareos +cat <${cwd}/tmp/bconcmds +@$out /dev/null +messages +@$out ${cwd}/tmp/log1.out +label volume=TestVolume001 storage=File pool=Full +@#setdebug level=100 storage=File +wait +messages +@# +@# now do a restore +@# +@$out ${cwd}/tmp/log2.out +restore where=${cwd}/tmp/bareos-restores select all done +yes +wait +messages +quit +END_OF_DATA + +run_bconsole +check_for_zombie_jobs storage=File +stop_bareos + +print_debug "Detecting connections to SD with source and target ${IP}" +grep -E "${IP}(.|:)$SDPORT .* ${IP}" $tmp/log1.out > $tmp/log3.out +if [ $? -ne 0 ]; then + stat=2 + print_debug "Couldn't detect a connection to the SD with source and target ${IP}" +fi + +if [ "$stat" = 2 ] ; then + netstat -tan +fi + +if [ "$debug" = 1 ] ; then + cat $tmp/log3.out +fi + + +check_two_logs +check_restore_diff + +if [ "$stat" = 2 ]; then + print_debug `cat $tmp/log3.out` + bstat=$stat +fi + +end_test diff --git a/tests/lan-addr-test-passive b/tests/lan-addr-test-passive new file mode 100755 index 0000000..c7934a5 --- /dev/null +++ b/tests/lan-addr-test-passive @@ -0,0 +1,124 @@ +#!/bin/sh +# +# Run a simple backup of the Bareos build directory +# then restore it. +# + +unset LANG +TestName="lan-addr-test-passive" +JobName=backup +. scripts/functions + +scripts/cleanup +scripts/copy-confs + +# +# Zap out any schedule in default conf file so that +# it doesn't start during our test +# +outf="tmp/sed_tmp" +echo "s% Schedule =%# Schedule =%g" >${outf} +echo "s%Name = \"BackupClient1\"%Name = \"backup\"; client run after job = \"netstat -tan\"%g" >>${outf} +cp $scripts/bareos-dir.conf $tmp/1 +sed -f ${outf} $tmp/1 >$scripts/bareos-dir.conf + +PATH=$PATH:/sbin:/usr/sbin +# +# Deduce a primary IP address by examining +# the interface defined by INTERFACE= +# +os=`uname` +if [ $os = 'FreeBSD' ]; then + INTERFACE=bge0 + IP=`ifconfig ${INTERFACE} | perl -ne '/inet (.+?) / && print $1'` +elif [ $os = 'Linux' ]; then + INTERFACE=eth0 + IP=`ifconfig ${INTERFACE} | perl -ne '/inet addr:(.+?) / && print $1'` +fi + +if [ "$IP" = '' ]; then + # ifconfig output may be like this (RHEL/CentOS 7, Fedora, ...?) + # eth0: flags=4163 mtu 1500 + # inet 192.168.121.195 netmask 255.255.255.0 broadcast 192.168.121.255 + IP=`ifconfig ${INTERFACE} | perl -ne '/inet (.+?) / && print $1'` + if [ "$IP" = '' ]; then + echo "Can't detect ip address" + exit 0 + fi +fi + +outf="tmp/sed_tmp" +echo "s/Address =/Address = 127.0.0.1\n LAN Address = $IP\n #/g" > $outf +echo 's/\(Password = "@fd_password@"\)/\1\n Passive=yes/g' >> $outf +cp $scripts/bareos-dir.conf $tmp/1 +sed -f ${outf} ${cwd}/tmp/1 > $scripts/bareos-dir.conf + +DIRPORT=$BASEPORT +FDPORT=$(($BASEPORT + 1)) +SDPORT=$(($BASEPORT + 2)) + +change_jobname BackupClient1 $JobName +start_test + +cat <${cwd}/tmp/bconcmds +@$out /dev/null +messages +@$out ${cwd}/tmp/log1.out +@#label volume=TestVolume001 storage=File pool=Full +@#setdebug level=100 storage=File +run job=$JobName yes +@#sleep 3 +messages +quit +END_OF_DATA + +run_bareos +cat <${cwd}/tmp/bconcmds +@$out /dev/null +messages +@$out ${cwd}/tmp/log1.out +label volume=TestVolume001 storage=File pool=Full +@#setdebug level=100 storage=File +wait +messages +@# +@# now do a restore +@# +@$out ${cwd}/tmp/log2.out +restore where=${cwd}/tmp/bareos-restores select all done +yes +wait +messages +quit +END_OF_DATA + +run_bconsole +check_for_zombie_jobs storage=File +stop_bareos + + +print_debug "and connections to FD with source and target ${IP}" +grep -E "${IP}(.|:)$FDPORT .* ${IP}" $tmp/log1.out >> $tmp/log3.out +if [ $? -ne 0 ]; then + stat=2 + print_debug "Couldn't detect a connection to the FD with source and target ${IP}" +fi + +if [ "$stat" = 2 ] ; then + netstat -tan +fi + +if [ "$debug" = 1 ] ; then + cat $tmp/log3.out +fi + + +check_two_logs +check_restore_diff + +if [ "$stat" = 2 ]; then + print_debug `cat $tmp/log3.out` + bstat=$stat +fi + +end_test