]> git.sur5r.net Git - bacula/bacula/blob - regress/scripts/functions
regress: tweak the message in the update_win32()
[bacula/bacula] / regress / scripts / functions
1 #
2 # A set of useful functions to be sourced in each test
3 #
4
5
6 check_encoding()
7 {
8    ${bin}/bacula-dir -d50 -t -c ${conf}/bacula-dir.conf 2>&1 | grep 'Wanted SQL_ASCII, got UTF8' >/dev/null
9    if [ $? = 0 ]; then
10        echo "Found database encoding problem, please modify the database encoding (SQL_ASCII)"
11        exit 1
12    fi
13 }
14
15 start_test()
16 {
17    check_encoding
18    # Turn off email
19    outf="${tmp}/sed_tmp"
20    echo "s%  mail =%# mail = %g" >${outf}
21    echo "s%  operator =%# operator =%g" >>${outf}
22    cp ${conf}/bacula-dir.conf ${tmp}/1
23    sed -f ${outf} ${tmp}/1 > ${conf}/bacula-dir.conf
24    echo " "
25    echo " "
26    echo " === Starting $TestName at `date +%R:%S` ==="
27    echo " === Starting $TestName at `date +%R:%S` ===" >> ${working}/log
28    echo " "
29    export TestName
30    export zstat
31    export estat
32    estat=0
33    zstat=0
34    bstat=0
35    rstat=0
36    dstat=0
37 }
38
39 require_root()
40 {
41 MUID=`/usr/bin/id | awk -F= '{print $2}' | awk -F\( '{print $1}'`
42 if [ $MUID != 0 ] ; then
43    echo " "
44    echo "You must be root to run this test."
45    echo "  ===== !!!! $TestName not run at `date +%R:%S` ==="
46    echo "  ===== !!!! $TestName not run at `date +%R:%S` !!!! ===== " >>test.out
47    echo " "
48    exit 1
49 fi
50 }
51
52 require_tape_drive() 
53 {
54 if test x${TAPE_DRIVE} = x/dev/null ; then
55    echo "$TestName test needs a tape drive, but has none."
56    exit 1
57 fi
58 }
59
60 require_second_drive()
61
62 if test x${TAPE_DRIVE1} = x/dev/null ; then
63    echo "$JobName needs second drive, but has none."
64    exit 1
65 fi
66 }
67
68 require_autochanger()
69 {
70 if test x${AUTOCHANGER} = x/dev/null ; then
71    echo "$TestName needs an autochanger, but has none."
72    exit 1
73 fi
74 }
75
76 require_vtape() 
77 {
78 if test x${USE_VTAPE} = x ; then
79    echo "$TestName test needs the vtape driver."
80    exit 0
81 fi
82 }
83
84 require_linux()
85 {
86 os=`uname`
87 if [ $os != 'Linux' ]; then
88    echo "This test $TestName runs only on Linux"
89    exit 0
90 fi
91 }
92
93 skip_if_no_autochanger()
94 {
95 if test x${AUTOCHANGER} = x/dev/null ; then
96    echo "$TestName test skipped. No autochanger."
97    exit
98 fi
99 }
100
101 set_debug()
102 {
103    debug=$1
104    if test "$debug" -eq 1 ; then
105      out="tee"
106    else
107      out="output"
108    fi
109
110
111 print_debug()
112 {
113    echo $* | grep ERROR > /dev/null
114    if test $? -eq 0; then
115      echo $* >> $tmp/err.log
116    fi
117    if test "$debug" -eq 1 ; then
118      echo $*
119    fi
120 }
121
122 check_files_written()
123 {
124     LOG=$1
125     NB=$2
126     FILES=`awk '/FD Files Written:/ { last=$4 } END { print last }' $LOG`
127
128     if [ "$NB" != "$FILES" ]; then
129         print_debug "Expect $NB files, get $FILES"
130         bstat=2
131     fi
132 }
133
134 ################################################################
135 # Get information from logs
136 get_mig_info()
137 {
138     # Prev Backup JobId
139     JOBID=$1
140     LOG=$2
141     RET=`awk -F: "BEGIN { jobid=$JOBID } "'/Prev Backup JobId/ { cjid=$2 } /New Backup JobId/  { if (cjid == jobid) { print $2 } }' $LOG`
142 }
143
144 get_duration()
145 {
146    LOG=$1
147    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`
148 }
149
150 check_duration()
151 {
152    LOG=$1
153    TIME=$2
154    OP=${3-gt}
155
156    get_duration $LOG
157    if [ "$RET" -$OP "$TIME" ]; then
158        print_debug "Expect $OP than $TIME sec, get $RET"
159        bstat=2
160    fi
161 }
162
163 run_bacula()
164 {
165    debug_wait
166    zstat=0
167    estat=0
168    if test "$debug" -eq 1 ; then
169      ${scripts}/bacula-ctl-sd start -m
170      ${scripts}/bacula-ctl-fd start -m $1
171      ${scripts}/bacula-ctl-dir start -m
172      cat ${tmp}/bconcmds | ${bin}/bconsole -c ${conf}/bconsole.conf
173      return $?
174    else
175      ${scripts}/bacula start >/dev/null 2>&1
176      cat ${tmp}/bconcmds | ${bin}/bconsole -c ${conf}/bconsole.conf >/dev/null 2>&1
177      return $?
178    fi
179 }
180
181 run_bconsole()
182 {
183    bconsole_file=${1:-${tmp}/bconcmds}
184    if test "$debug" -eq 1 ; then
185      cat $bconsole_file | ${bin}/bconsole -c ${conf}/bconsole.conf
186    else
187      cat $bconsole_file | ${bin}/bconsole -c ${conf}/bconsole.conf  2>&1 >/dev/null
188    fi
189 }
190
191 run_btape()
192 {
193    if test "$debug" -eq 1 ; then
194      cat ${tmp}/bconcmds | ${bin}/btape -c ${conf}/bacula-sd.conf tape | tee ${tmp}/log1.out
195    else
196      cat ${tmp}/bconcmds | ${bin}/btape -c ${conf}/bacula-sd.conf tape >${tmp}/log1.out 2>&1
197    fi
198 }
199
200 run_bscan()
201 {
202    if test "$debug" -eq 1 ; then
203       ${bin}/bscan $* | tee ${tmp}/log.out
204    else
205       ${bin}/bscan $* 2>&1 >/dev/null
206    fi
207 }
208
209 bscan_libdbi()
210 {   
211    B=`echo $LIBDBI | sed 's/;//' | sed 's/;//g'`
212    B_D=`echo $B | awk '{print $3}'`
213    B_t=`echo $B | awk '{print $6}'`
214    B_p=`echo $B | awk '{print $9}'`
215
216    BSCANLIBDBI="${LIBDBI:+1}"
217                 
218    if test "$BSCANLIBDBI" = "1" ; then
219       BSCANLIBDBI="-D $B_D -h $B_t -t $B_p"
220    else
221       BSCANLIBDBI=" "
222    fi
223 }
224
225 stop_bacula()
226 {
227    if test "$debug" -eq 1 ; then
228       ${scripts}/bacula stop
229    else
230       ${scripts}/bacula stop 2>&1 >/dev/null
231    fi
232 }
233
234 check_for_zombie_jobs()
235 {
236    ${rscripts}/check_for_zombie_jobs $*
237 }
238
239 change_jobname()
240 {
241    if test $# -eq 1; then
242       oldname=NightlySave
243       newname=$1
244    else
245       oldname=$1
246       newname=$2
247    fi
248    rm -f $tmp/1 $tmp/2
249    mv ${conf}/bacula-dir.conf $tmp/1
250    echo "s%${oldname}%${newname}%g" >$tmp/2
251    sed -f $tmp/2 $tmp/1 >$conf/bacula-dir.conf
252 #  echo "Job ${oldname} changed to ${newname}"
253 }
254
255 check_two_logs()
256 {
257    grep "^  Termination: *Backup OK" ${tmp}/log1.out 2>&1 >/dev/null
258    bstat=${bstat:-$?}
259    grep "^  Termination: .*Backup Error" ${tmp}/log1.out 2>&1 >/dev/null
260    if test $? -eq 0; then
261       bstat=2
262    fi
263    grep "^  Termination: *Restore OK" ${tmp}/log2.out 2>&1 >/dev/null
264    rstat=${rstat:-$?}
265    grep "^  Termination: .*Restore Error" ${tmp}/log2.out 2>&1 >/dev/null
266    if test $? -eq 0; then
267       rstat=2
268    fi
269    grep "^  Termination: *Restore OK -- warning file count mismatch" ${tmp}/log2.out 2>&1 >/dev/null
270    if test $? -eq 0; then
271       rstat=3
272    fi
273    grep "^  Termination: .*Verify Differences" ${tmp}/log2.out 2>&1 >/dev/null
274    if test $? -eq 0; then
275       rstat=4
276    fi
277    grep "Encoding error for database" ${tmp}/log1.out > /dev/null
278    if test $? -eq 0; then
279       print_debug "Found database encoding error"
280       bstat=2
281    fi
282 }
283
284 check_restore_diff()
285 {
286    if test "$debug" -eq 1 ; then
287       $rscripts/diff.pl -s ${src} -d ${tmp}/bacula-restores${src}
288       diff -ur ${src} ${tmp}/bacula-restores${src}
289    else 
290       diff -ur ${src} ${tmp}/bacula-restores${src} 2>&1 >/dev/null
291    fi
292    dstat=$?
293 }
294
295 check_restore_bin_diff()
296 {
297    if test "$debug" -eq 1 ; then
298       $rscripts/diff.pl -s ${bin} -d ${tmp}/bacula-restores${bin}
299       diff -ur ${bin} ${tmp}/bacula-restores${bin}
300    else 
301       diff -ur ${bin} ${tmp}/bacula-restores${bin} 2>&1 >/dev/null
302    fi
303    dstat=$?
304 }
305
306
307 check_restore_tmp_build_diff()
308 {
309    if test "$debug" -eq 1 ; then
310       $rscripts/diff.pl -s ${tmpsrc} -d ${tmp}/bacula-restores${tmpsrc}
311       diff -ur ${tmpsrc} ${tmp}/bacula-restores${tmpsrc}
312    else
313       diff -ur ${tmpsrc} ${tmp}/bacula-restores${tmpsrc} 2>&1 >/dev/null
314    fi
315    dstat=$?
316 }
317
318 # bstat is backup error
319 # dstat is diff difference
320 # estat is special error status (shown by print_debug message)
321 # rstat is restore status
322 # zstat is zombie job(s)
323 #
324 end_test()
325 {
326    if [ x$notracedump != xyes ]; then 
327       cat ${working}/bacula.*.traceback 2>/dev/null
328       cp -f  ${working}/bacula.*.traceback ${dumps} 2>/dev/null
329       cat ${working}/*.bactrace 2>/dev/null
330       cp -f ${working}/*.bactrace ${dumps} 2>/dev/null
331    fi
332    if [ -f $tmp/err.log ]; then
333       cat $tmp/err.log
334    fi
335    if [ $estat != 0 ] ; then
336       echo " "
337       echo "  !!!!! $TestName failed!!! `date +%R:%S` !!!!! "
338       echo "   Status: estat=$estat zombie=$zstat backup=$bstat restore=$rstat diff=$dstat"
339       echo "  !!!!! $TestName failed!!! `date +%R:%S` !!!!! " >>test.out
340       echo "   Status: estat=$estat zombie=$zstat backup=$bstat restore=$rstat diff=$dstat" >>test.out
341       echo " "
342       exit 1
343    fi
344    if [ $zstat != 0 ] ; then
345       echo " "
346       echo "  !!!!! $TestName failed!!! `date +%R:%S` !!!!! "
347       echo "   Status: zombie=$zstat backup=$bstat restore=$rstat diff=$dstat"
348       echo "  !!!!! $TestName failed!!! `date +%R:%S` !!!!! " >>test.out
349       echo "   Status: zombie=$zstat backup=$bstat restore=$rstat diff=$dstat" >>test.out
350       echo " "
351       exit 1
352    fi
353    if [ $dstat != 0 -o $bstat != 0 -o $rstat != 0 ] ; then
354       echo " "
355       echo " "
356       echo "  !!!!! $TestName failed!!! `date +%R:%S` !!!!! "
357       echo "   Status: zombie=$zstat backup=$bstat restore=$rstat diff=$dstat"
358       echo "  !!!!! $TestName failed!!! `date +%R:%S` !!!!! " >>test.out
359       echo "   Status: zombie=$zstat backup=$bstat restore=$rstat diff=$dstat" >>test.out
360       if [ $bstat != 0 -o $rstat != 0 ] ; then
361          echo "  !!!!! Bad termination status       !!!!! "
362          echo "  !!!!! Bad termination status       !!!!! " >>test.out
363       else
364          echo "  !!!!! Restored files differ          !!!!! "
365          echo "  !!!!! Restored files differ          !!!!! " >>test.out
366       fi
367       echo "   Status: backup=$bstat restore=$rstat diff=$dstat"
368       echo "   Status: backup=$bstat restore=$rstat diff=$dstat" >>test.out
369       echo "   Test owner of $SITE_NAME is $EMAIL"
370       echo "   Test owner of $SITE_NAME is $EMAIL" >>test.out
371       echo " "
372       exit 1
373    else
374       echo "  ===== $TestName OK `date +%R:%S` ===== "
375       echo "  ===== $TestName OK `date +%R:%S` ===== " >>test.out
376       if test "$debug" -eq 0 ; then
377          ${rscripts}/cleanup
378       fi
379    fi
380 }
381
382 copy_tape_confs()
383 {
384    ${rscripts}/copy-tape-confs
385    ${rscripts}/cleanup-tape
386 }
387
388 copy_test_confs()
389 {
390    ${rscripts}/copy-test-confs
391    ${rscripts}/cleanup
392 }
393
394 disable_pluguins()
395 {
396    for i in ${conf}/bacula-fd.conf; do
397       sed 's/Plugin/#Plugin/' $i > $tmp/1
398       cp -f $tmp/1 $i
399    done
400 }
401
402 update_win32()
403 {
404    if [ -d $cwd/build/src/win32/release32   \
405      -a -d $cwd/build/src/win32/release64 ] \
406    || [ -d $cwd/release32 -a -f $cwd/release64 ]
407    then
408        echo -ne "Try to upgrade the FileDaemon:\t"
409        wget -qO - "$WIN32_ADDR:8091/install"
410    fi
411 }
412
413 debug_wait()
414 {
415   if test "x${REGRESS_WAIT}" = "x1"; then
416      echo "Start Bacula under debugger and enter anything when ready ..."
417      read a
418   fi
419 }
420
421 init_slot()
422 {
423    DRIVE=$1
424    SLOT=$2
425    if test -n "$DRIVE" -a -n "$SLOT"; then
426       if test ! -c $DRIVE -a ! -b $DRIVE -a x$USE_VTAPE != x ; then
427          dir=`dirname $DRIVE`
428          if [ ! -d "$dir" ]; then
429             mkdir -p "$dir"
430          fi
431          touch $dir/slot$SLOT
432       fi
433    fi
434 }
435
436 init_drive()
437 {
438   if test a$USE_VTAPE = a; then
439     mt -f $1 rewind
440     mt -f $1 weof
441   else
442     cp /dev/null $1
443   fi
444 }
445
446 rewind_drive()
447 {
448   if test a$USE_VTAPE = a; then
449     mt -f $1 rewind
450   fi
451 }
452
453 load_slot1() 
454 {
455 # Get a tape from slot1
456 slot=`${scripts}/$MTX ${AUTOCHANGER} loaded 0 ${TAPE_DRIVE} $DRIVE1`
457 case $slot in
458  0)
459     ${scripts}/$MTX ${AUTOCHANGER} load $SLOT1 ${TAPE_DRIVE} $DRIVE1
460     slot=$SLOT1
461     ;;
462  $SLOT1)
463     slot=$SLOT1
464     ;;
465  *)
466     rewind_drive ${TAPE_DRIVE}
467     ${scripts}/$MTX ${AUTOCHANGER} unload $slot  ${TAPE_DRIVE} $DRIVE1
468     ${scripts}/$MTX ${AUTOCHANGER} load   $SLOT1 ${TAPE_DRIVE} $DRIVE1
469     slot=$SLOT1
470     ;;
471 esac
472 }
473
474 #
475 # $1 has currently loaded slot, load the other one i.e. if 1, load 2;
476 #    if 2, load 1; if 0 load 1
477 #
478 load_other_slot()
479 {
480 rewind_drive ${TAPE_DRIVE}
481 case $1 in
482  0)
483     ${scripts}/${AUTOCHANGER_SCRIPT} ${AUTOCHANGER} load $SLOT1 ${TAPE_DRIVE} $DRIVE1
484     slot=1
485     ;;
486  $SLOT1)
487     ${scripts}/${AUTOCHANGER_SCRIPT} ${AUTOCHANGER} unload $1 ${TAPE_DRIVE} $DRIVE1
488     ${scripts}/${AUTOCHANGER_SCRIPT} ${AUTOCHANGER} load $SLOT2 ${TAPE_DRIVE} $DRIVE1
489     slot=2
490     ;;
491  $SLOT2)
492     ${scripts}/${AUTOCHANGER_SCRIPT} ${AUTOCHANGER} unload $1 ${TAPE_DRIVE} $DRIVE1
493     ${scripts}/${AUTOCHANGER_SCRIPT} ${AUTOCHANGER} load $SLOT1 ${TAPE_DRIVE} $DRIVE1
494     slot=1
495     ;;
496  *)
497     echo "Something went wrong. Expected $SLOT1 or $SLOT2, got $1"
498     exit 1
499     ;;
500 esac
501 }
502
503 # Save current directory
504 cwd=`pwd`
505 if test "x${REGRESS_DEBUG}" = "x1"; then
506    set_debug 1
507 else
508    set_debug 0
509 fi
510
511 # Source the configuration variables
512 . ${cwd}/config
513
514 db_name=${db_name:-"regress"}
515 db_user=${db_user:-"regress"}
516 db_password=${db_password:-""}
517 working=${working:-"$cwd/working"}
518 dumps=${dumps:-"$cwd/dumps"}
519 bin=${bin:-"$cwd/bin"}
520
521 # Bacula scripts
522 scripts=${scripts:-"$cwd/bin"}
523
524 # Bacula conf files
525 conf=${conf:-"$cwd/bin"}
526
527 # Regress scripts
528 rscripts=${rscripts:-"$cwd/scripts"}
529
530 tmp=${tmp:-"$cwd/tmp"}
531
532 # Bacula source directory when copied here
533 #  also build directory
534 src=${src:-"$cwd/build"}
535
536 # Temp source directory so we don't mess up $src
537 tmpsrc=${tmpsrc:-"$cwd/tmp/build"}
538
539 export bin
540 export conf
541 export working
542 export dumps
543 export scripts
544 export rscripts
545 export tmp
546 export src
547 export tmpsrc
548
549 bperl="perl -Mscripts::functions"
550 export bperl
551
552 mkdir -p ${tmp}
553 touch ${tmp}/dir.out ${tmp}/fd.out ${tmp}/sd.out
554
555 CLIENT=${HOST}-fd
556
557 if [ x$USE_VTAPE = xyes ]; then
558    mkdir -p $working/ach
559    SLOT1=1
560    SLOT2=2
561    TAPE_DRIVE=$working/ach/drive0
562    TAPE_DRIVE1=$working/ach/drive1
563    AUTOCHANGER=$working/ach/config
564    AUTOCHANGER_SCRIPT=disk-changer
565    DRIVE1=0
566    DRIVE2=1
567    cp /dev/null $working/ach/slot$SLOT1
568    cp /dev/null $working/ach/slot$SLOT2
569    cat > $AUTOCHANGER <<EOF
570 maxdrive=8
571 maxslot=80
572 EOF
573 fi
574
575 AUTOCHANGER_SCRIPT=${AUTOCHANGER_SCRIPT:-mtx-changer}
576 LD_LIBRARY_PATH=$bin:$LD_LIBRARY_PATH
577 export LD_LIBRARY_PATH