]> git.sur5r.net Git - bacula/bacula/blobdiff - regress/scripts/functions
Minor tweaks
[bacula/bacula] / regress / scripts / functions
index 3e1c468e179d224d274fda5b75089c757a5c44b3..715f6fb4cb0dd5deed3d08ac8d8543bb77325457 100644 (file)
@@ -2,13 +2,83 @@
 # A set of useful functions to be sourced in each test
 #
 
+
 start_test()
 {
+   # Turn off email
+   outf="tmp/sed_tmp"
+   echo "s%  mail =%# mail = %g" >${outf}
+   echo "s%  operator =%# operator =%g" >>${outf}
+   cp bin/bacula-dir.conf tmp/1
+   sed -f ${outf} tmp/1 > bin/bacula-dir.conf
    echo " "
    echo " "
-   echo " === Starting $JobName at `date +%R:%S` ==="
-   echo " === Starting $JobName at `date +%R:%S` ===" >>working/log
+   echo " === Starting $TestName at `date +%R:%S` ==="
+   echo " === Starting $TestName at `date +%R:%S` ===" >> working/log
    echo " "
+   export zstat
+}
+
+require_root()
+{
+MUID=`/usr/bin/id | awk -F= '{print $2}' | awk -F\( '{print $1}'`
+if [ $MUID != 0 ] ; then
+   echo " "
+   echo "You must be root to run this test."
+   echo "  ===== !!!! $TestName not run at `date +%R:%S` ==="
+   echo "  ===== !!!! $TestName not run at `date +%R:%S` !!!! ===== " >>test.out
+   echo " "
+   exit 1
+fi
+}
+
+require_tape_drive() 
+{
+if test x${TAPE_DRIVE} = x/dev/null ; then
+   echo "$TestName test needs a tape drive, but has none."
+   exit 1
+fi
+}
+
+require_second_drive()
+{ 
+if test x${TAPE_DRIVE1} = x/dev/null ; then
+   echo "$JobName needs second drive, but has none."
+   exit 1
+fi
+}
+
+require_autochanger()
+{
+if test x${AUTOCHANGER} = x/dev/null ; then
+   echo "$TestName needs an autochanger, but has none."
+   exit 1
+fi
+}
+
+require_vtape() 
+{
+if test x${USE_VTAPE} = x ; then
+   echo "$TestName test needs the vtape driver."
+   exit 0
+fi
+}
+
+require_linux()
+{
+os=`uname`
+if [ $os != 'Linux' ]; then
+   echo "This test $TestName runs only on Linux"
+   exit 0
+fi
+}
+
+skip_if_no_autochanger()
+{
+if test x${AUTOCHANGER} = x/dev/null ; then
+   echo "$TestName test skipped. No autochanger."
+   exit
+fi
 }
 
 set_debug()
@@ -21,82 +91,371 @@ set_debug()
    fi
 } 
 
+print_debug()
+{
+   if test "$debug" -eq 1 ; then
+     echo $*
+   fi
+}
+
+check_files_written()
+{
+    LOG=$1
+    NB=$2
+    FILES=`awk '/FD Files Written:/ { last=$4 } END { print last }' $LOG`
+
+    if [ "$NB" != "$FILES" ]; then
+        print_debug "Expect $NB files, get $FILES"
+        bstat=2
+    fi
+}
+
+################################################################
+# Get information from logs
+get_mig_info()
+{
+    # Prev Backup JobId
+    JOBID=$1
+    LOG=$2
+    RET=`awk -F: "BEGIN { jobid=$JOBID } "'/Prev Backup JobId/ { cjid=$2 } /New Backup JobId/  { if (cjid == jobid) { print $2 } }' $LOG`
+}
+
+get_duration()
+{
+   LOG=$1
+   RET=`awk 'BEGIN {t["secs"]=1;t["sec"]=1;t["min"]=60;t["mins"]=60}; /Elapsed time:/ { last=$3*t[$4] } END { print last }' $LOG`
+}
+
+check_duration()
+{
+   LOG=$1
+   TIME=$2
+   OP=${3-gt}
+
+   get_duration $LOG
+   if [ "$RET" -$OP "$TIME" ]; then
+       print_debug "Expect $OP than $TIME sec, get $RET"
+       bstat=2
+   fi
+}
+
 run_bacula()
 {
+   debug_wait
+   zstat=0
    if test "$debug" -eq 1 ; then
-     bin/bacula start
-     cat tmp/bconcmds | bin/bconsole -c bin/bconsole.conf
+     bin/bacula-ctl-sd start
+     bin/bacula-ctl-fd start $1
+     bin/bacula-ctl-dir start
+     cat tmp/bconcmds | $bin/bconsole -c bin/bconsole.conf
+     return $?
    else
-     bin/bacula start 2>&1 >/dev/null
-     cat tmp/bconcmds | bin/bconsole -c bin/bconsole.conf  2>&1 >/dev/null
+     bin/bacula start >/dev/null 2>&1
+     cat tmp/bconcmds | $bin/bconsole -c bin/bconsole.conf >/dev/null 2>&1
+     return $?
    fi
 }
 
 run_bconsole()
+{
+   bconsole_file=${1:-tmp/bconcmds}
+   if test "$debug" -eq 1 ; then
+     cat $bconsole_file | $bin/bconsole -c bin/bconsole.conf
+   else
+     cat $bconsole_file | $bin/bconsole -c bin/bconsole.conf  2>&1 >/dev/null
+   fi
+}
+
+run_btape()
 {
    if test "$debug" -eq 1 ; then
-     cat tmp/bconcmds | bin/bconsole -c bin/bconsole.conf
+     cat tmp/bconcmds | $bin/btape -c bin/bacula-sd.conf DDS-4 | tee tmp/log1.out
    else
-     cat tmp/bconcmds | bin/bconsole -c bin/bconsole.conf  2>&1 >/dev/null
+     cat tmp/bconcmds | $bin/btape -c bin/bacula-sd.conf DDS-4 >tmp/log1.out 2>&1
+   fi
+}
+
+run_bscan()
+{
+   if test "$debug" -eq 1 ; then
+      $bin/bscan $* | tee tmp/log.out
+   else
+      $bin/bscan $* 2>&1 >/dev/null
+   fi
+}
+
+bscan_libdbi()
+{   
+   B=`echo $LIBDBI | sed 's/;//' | sed 's/;//g'`
+   B_D=`echo $B | awk '{print $3}'`
+   B_t=`echo $B | awk '{print $6}'`
+   B_p=`echo $B | awk '{print $9}'`
+
+   BSCANLIBDBI="${LIBDBI:+1}"
+                
+   if test "$BSCANLIBDBI" = "1" ; then
+      BSCANLIBDBI="-D $B_D -h $B_t -t $B_p"
+   else
+      BSCANLIBDBI=" "
    fi
 }
 
 stop_bacula()
 {
    bin/bacula stop 2>&1 >/dev/null
+   zstat=0
+   bstat=0
+   rstat=0
+   dstat=0
 }
 
 check_for_zombie_jobs()
 {
-   scripts/check_for_zombie_jobs $1
+   scripts/check_for_zombie_jobs $*
 }
 
 change_jobname()
 {
+   if test $# -eq 1; then
+      oldname=NightlySave
+      newname=$1
+   else
+      oldname=$1
+      newname=$2
+   fi
    rm -f bin/1
    mv bin/bacula-dir.conf bin/1
-   echo "s%NightlySave%$1%g" >/tmp/1
-   sed -f /tmp/1 bin/1 >bin/bacula-dir.conf
+   echo "s%${oldname}%${newname}%g" >tmp/1
+   sed -f tmp/1 bin/1 >bin/bacula-dir.conf
+#  echo "Job ${oldname} changed to ${newname}"
 }
 
 check_two_logs()
 {
    grep "^  Termination: *Backup OK" tmp/log1.out 2>&1 >/dev/null
-   bstat=$?
+   bstat=${bstat:-$?}
+   grep "^  Termination: .*Backup Error" tmp/log1.out 2>&1 >/dev/null
+   if test $? -eq 0; then
+      bstat=2
+   fi
    grep "^  Termination: *Restore OK" tmp/log2.out 2>&1 >/dev/null
-   rstat=$?
+   rstat=${rstat:-$?}
+   grep "^  Termination: .*Restore Error" tmp/log2.out 2>&1 >/dev/null
+   if test $? -eq 0; then
+      rstat=2
+   fi
+   grep "^  Termination: *Restore OK -- warning file count mismatch" tmp/log2.out 2>&1 >/dev/null
+   if test $? -eq 0; then
+      rstat=3
+   fi
+   grep "^  Termination: .*Verify Differences" tmp/log2.out 2>&1 >/dev/null
+   if test $? -eq 0; then
+      rstat=4
+   fi
+   grep "Encoding error for database" tmp/log1.out > /dev/null
+   if test $? -eq 0; then
+      print_debug "Found database encoding error"
+      bstat=2
+   fi
 }
 
 check_restore_diff()
 {
-   diff -r build tmp/bacula-restores${cwd}/build 2>&1 >/dev/null
+   if test "$debug" -eq 1 ; then
+      diff -ur build tmp/bacula-restores${cwd}/build
+   else 
+      diff -ur build tmp/bacula-restores${cwd}/build 2>&1 >/dev/null
+   fi
    dstat=$?
 }
 
 check_restore_tmp_build_diff()
 {
-   diff -r tmp/build tmp/bacula-restores${cwd}/tmp/build 2>&1 >/dev/null
+   if test "$debug" -eq 1 ; then
+      diff -ur tmp/build tmp/bacula-restores${cwd}/tmp/build
+   else
+      diff -ur tmp/build tmp/bacula-restores${cwd}/tmp/build 2>&1 >/dev/null
+   fi
    dstat=$?
 }
 
 end_test()
 {
+   if [ $zstat != 0 ] ; then
+      echo " "
+      echo "  !!!!! $TestName failed!!! `date +%R:%S` !!!!! "
+      echo "   Status: zombie=$zstat backup=$bstat restore=$rstat diff=$dstat"
+      echo "  !!!!! $TestName failed!!! `date +%R:%S` !!!!! " >>test.out
+      echo "   Status: zombie=$zstat backup=$bstat restore=$rstat diff=$dstat" >>test.out
+      echo " "
+      exit 1
+   fi
    if [ $dstat != 0 -o $bstat != 0 -o $rstat != 0 ] ; then
       echo " "
       echo " "
-      echo "  !!!!! $TestName Bacula source failed!!! !!!!! "
-      echo "  !!!!! $TestName failed!!! !!!!! " >>test.out
+      echo "  !!!!! $TestName failed!!! `date +%R:%S` !!!!! "
+      echo "   Status: zombie=$zstat backup=$bstat restore=$rstat diff=$dstat"
+      echo "  !!!!! $TestName failed!!! `date +%R:%S` !!!!! " >>test.out
+      echo "   Status: zombie=$zstat backup=$bstat restore=$rstat diff=$dstat" >>test.out
       if [ $bstat != 0 -o $rstat != 0 ] ; then
-         echo "  !!!!! Bad Job termination status     !!!!! "
-         echo "  !!!!! Bad Job termination status     !!!!! " >>test.out
+         echo "  !!!!! Bad termination status       !!!!! "
+         echo "  !!!!! Bad termination status       !!!!! " >>test.out
       else
          echo "  !!!!! Restored files differ          !!!!! "
          echo "  !!!!! Restored files differ          !!!!! " >>test.out
       fi
+      echo "   Status: backup=$bstat restore=$rstat diff=$dstat"
+      echo "   Status: backup=$bstat restore=$rstat diff=$dstat" >>test.out
       echo " "
+      exit 1
    else
-      echo "  ===== $TestName Bacula source OK `date +%R:%S` ===== "
+      echo "  ===== $TestName OK `date +%R:%S` ===== "
       echo "  ===== $TestName OK `date +%R:%S` ===== " >>test.out
-      scripts/cleanup
+      if test "$debug" -eq 0 ; then
+         scripts/cleanup
+      fi
    fi
 }
+
+copy_tape_confs()
+{
+   scripts/copy-tape-confs
+   scripts/cleanup-tape
+}
+
+copy_test_confs()
+{
+   scripts/copy-test-confs
+   scripts/cleanup
+}
+
+debug_wait()
+{
+  if test "x${REGRESS_WAIT}" = "x1"; then
+     echo "Start Bacula under debugger and enter anything when ready ..."
+     read a
+  fi
+}
+
+init_slot()
+{
+   DRIVE=$1
+   SLOT=$2
+   if test -n "$DRIVE" -a -n "$SLOT"; then
+      if test ! -c $DRIVE -a ! -b $DRIVE -a x$USE_VTAPE != x ; then
+         dir=`dirname $DRIVE`
+         touch $dir/slot$SLOT
+      fi
+   fi
+}
+
+init_drive()
+{
+  if test a$USE_VTAPE = a; then
+    mt -f $1 rewind
+    mt -f $1 weof
+  else
+    cp /dev/null $1
+  fi
+}
+
+rewind_drive()
+{
+  if test a$USE_VTAPE = a; then
+    mt -f $1 rewind
+  fi
+}
+
+load_slot1() 
+{
+# Get a tape from slot1
+slot=`$scripts/$MTX ${AUTOCHANGER} loaded 0 ${TAPE_DRIVE} $DRIVE1`
+case $slot in
+ 0)
+    $scripts/$MTX ${AUTOCHANGER} load $SLOT1 ${TAPE_DRIVE} $DRIVE1
+    slot=$SLOT1
+    ;;
+ $SLOT1)
+    slot=$SLOT1
+    ;;
+ *)
+    rewind_drive ${TAPE_DRIVE}
+    $scripts/$MTX ${AUTOCHANGER} unload $slot  ${TAPE_DRIVE} $DRIVE1
+    $scripts/$MTX ${AUTOCHANGER} load   $SLOT1 ${TAPE_DRIVE} $DRIVE1
+    slot=$SLOT1
+    ;;
+esac
+}
+
+#
+# $1 has currently loaded slot, load the other one i.e. if 1, load 2;
+#    if 2, load 1; if 0 load 1
+#
+load_other_slot()
+{
+rewind_drive ${TAPE_DRIVE}
+case $1 in
+ 0)
+    $scripts/${AUTOCHANGER_SCRIPT} ${AUTOCHANGER} load $SLOT1 ${TAPE_DRIVE} $DRIVE1
+    slot=1
+    ;;
+ $SLOT1)
+    $scripts/${AUTOCHANGER_SCRIPT} ${AUTOCHANGER} unload $1 ${TAPE_DRIVE} $DRIVE1
+    $scripts/${AUTOCHANGER_SCRIPT} ${AUTOCHANGER} load $SLOT2 ${TAPE_DRIVE} $DRIVE1
+    slot=2
+    ;;
+ $SLOT2)
+    $scripts/${AUTOCHANGER_SCRIPT} ${AUTOCHANGER} unload $1 ${TAPE_DRIVE} $DRIVE1
+    $scripts/${AUTOCHANGER_SCRIPT} ${AUTOCHANGER} load $SLOT1 ${TAPE_DRIVE} $DRIVE1
+    slot=1
+    ;;
+ *)
+    echo "Something went wrong. Expected $SLOT1 or $SLOT2, got $1"
+    exit 1
+    ;;
+esac
+}
+
+# Save current directory
+cwd=`pwd`
+if test "x${REGRESS_DEBUG}" = "x1"; then
+   set_debug 1
+else
+   set_debug 0
+fi
+
+# Source the configuration variables
+. ${cwd}/config
+
+db_name=${db_name:-"regress"}
+db_user=${db_user:-"regress"}
+db_password=${db_password:-""}
+working=${working:-"$cwd/working"}
+bin=${bin:-"$cwd/bin"}
+scripts=${scripts:-"$bin"}
+
+export bin
+export working
+export scripts
+
+CLIENT=${HOST}-fd
+
+if [ x$USE_VTAPE = xyes ]; then
+   mkdir -p $working/ach
+   SLOT1=1
+   SLOT2=2
+   TAPE_DRIVE=$working/ach/drive1
+   TAPE_DRIVE1=$working/ach/drive1
+   AUTOCHANGER=$working/ach/config
+   AUTOCHANGER_SCRIPT=disk-changer
+   DRIVE1=0
+   DRIVE2=1
+   cat > $AUTOCHANGER <<EOF
+maxdrive=2
+maxslot=10
+EOF
+fi
+
+AUTOCHANGER_SCRIPT=${AUTOCHANGER_SCRIPT:-mtx-changer}
+LD_LIBRARY_PATH=$bin:$LD_LIBRARY_PATH
+export LD_LIBRARY_PATH