Navigation Menu

Skip to content
This repository has been archived by the owner on Mar 19, 2021. It is now read-only.

Commit

Permalink
Added test scripts for LAN Address feature
Browse files Browse the repository at this point in the history
  • Loading branch information
sduehr committed Mar 23, 2017
1 parent 251b7da commit 53691de
Show file tree
Hide file tree
Showing 2 changed files with 246 additions and 0 deletions.
122 changes: 122 additions & 0 deletions 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<UP,BROADCAST,RUNNING,MULTICAST> 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 <<END_OF_DATA >${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 <<END_OF_DATA >${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
124 changes: 124 additions & 0 deletions 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<UP,BROADCAST,RUNNING,MULTICAST> 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 <<END_OF_DATA >${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 <<END_OF_DATA >${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

0 comments on commit 53691de

Please sign in to comment.