]> git.sur5r.net Git - bacula/bacula/blob - regress/scripts/functions
ebl fix autochanger option
[bacula/bacula] / regress / scripts / functions
1 #
2 # A set of useful functions to be sourced in each test
3 #
4
5
6 start_test()
7 {
8    # Turn off email
9    outf="tmp/sed_tmp"
10    echo "s%  mail =%# mail = %g" >${outf}
11    echo "s%  operator =%# operator =%g" >>${outf}
12    cp bin/bacula-dir.conf tmp/1
13    sed -f ${outf} tmp/1 >bin/bacula-dir.conf
14    echo " "
15    echo " "
16    echo " === Starting $TestName at `date +%R:%S` ==="
17    echo " === Starting $TestName at `date +%R:%S` ===" >>working/log
18    echo " "
19    export zstat
20 }
21
22 require_root()
23 {
24 MUID=`/usr/bin/id | awk -F= '{print $2}' | awk -F\( '{print $1}'`
25 if [ $MUID != 0 ] ; then
26    echo " "
27    echo "You must be root to run this test."
28    echo "  ===== !!!! $TestName not run at `date +%R:%S` ==="
29    echo "  ===== !!!! $TestName not run at `date +%R:%S` !!!! ===== " >>test.out
30    echo " "
31    exit 1
32 fi
33 }
34
35 require_tape_drive() 
36 {
37 if test x${TAPE_DRIVE} = x/dev/null ; then
38    echo "$TestName test needs a tape drive, but has none."
39    exit 1
40 fi
41 }
42
43 require_second_drive()
44
45 if test x${TAPE_DRIVE1} = x/dev/null ; then
46    echo "$JobName needs second drive, but has none."
47    exit 1
48 fi
49 }
50
51 require_autochanger()
52 {
53 if test x${AUTOCHANGER} = x/dev/null ; then
54    echo "$TestName needs an autochanger, but has none."
55    exit 1
56 fi
57 }
58
59 require_vtape() 
60 {
61 if test x${USE_VTAPE} = x ; then
62    echo "$TestName test needs the vtape driver."
63    exit 0
64 fi
65 }
66
67 require_linux()
68 {
69 os=`uname`
70 if [ $os != 'Linux' ]; then
71    echo "This test $TestName runs only on Linux"
72    exit 0
73 fi
74 }
75
76 skip_if_no_autochanger()
77 {
78 if test x${AUTOCHANGER} = x/dev/null ; then
79    echo "$TestName test skipped. No autochanger."
80    exit
81 fi
82 }
83
84 set_debug()
85 {
86    debug=$1
87    if test "$debug" -eq 1 ; then
88      out="tee"
89    else
90      out="output"
91    fi
92
93
94 print_debug()
95 {
96    if test "$debug" -eq 1 ; then
97      echo $*
98    fi
99 }
100
101 run_bacula()
102 {
103    debug_wait
104    zstat=0
105    if test "$debug" -eq 1 ; then
106      bin/bacula-ctl-sd start
107      bin/bacula-ctl-fd start
108      bin/bacula-ctl-dir start
109      cat tmp/bconcmds | bin/bconsole -c bin/bconsole.conf
110      return $?
111    else
112      bin/bacula start 2>&1 >/dev/null
113      cat tmp/bconcmds | bin/bconsole -c bin/bconsole.conf  2>&1 >/dev/null
114      return $?
115    fi
116 }
117
118 run_bconsole()
119 {
120    if test "$debug" -eq 1 ; then
121      cat tmp/bconcmds | bin/bconsole -c bin/bconsole.conf
122    else
123      cat tmp/bconcmds | bin/bconsole -c bin/bconsole.conf  2>&1 >/dev/null
124    fi
125 }
126
127 run_btape()
128 {
129    if test "$debug" -eq 1 ; then
130      cat tmp/bconcmds | bin/btape -c bin/bacula-sd.conf DDS-4 | tee tmp/log1.out
131    else
132      cat tmp/bconcmds | bin/btape -c bin/bacula-sd.conf DDS-4 2>&1 >tmp/log1.out
133    fi
134 }
135
136 run_bscan()
137 {
138    if test "$debug" -eq 1 ; then
139       bin/bscan $* | tee tmp/log.out
140    else
141       bin/bscan $* 2>&1 >/dev/null
142    fi
143 }
144
145 bscan_libdbi()
146 {   
147    B=`echo $LIBDBI | sed 's/;//' | sed 's/;//g'`
148    B_D=`echo $B | awk '{print $3}'`
149    B_t=`echo $B | awk '{print $6}'`
150    B_p=`echo $B | awk '{print $9}'`
151
152    BSCANLIBDBI="${LIBDBI:+1}"
153                 
154    if test "$BSCANLIBDBI" = "1" ; then
155       BSCANLIBDBI="-D $B_D -h $B_t -t $B_p"
156    else
157       BSCANLIBDBI=" "
158    fi
159 }
160
161 stop_bacula()
162 {
163    bin/bacula stop 2>&1 >/dev/null
164 }
165
166 check_for_zombie_jobs()
167 {
168    scripts/check_for_zombie_jobs $*
169 }
170
171 change_jobname()
172 {
173    if test $# -eq 1; then
174       oldname=NightlySave
175       newname=$1
176    else
177       oldname=$1
178       newname=$2
179    fi
180    rm -f bin/1
181    mv bin/bacula-dir.conf bin/1
182    echo "s%${oldname}%${newname}%g" >tmp/1
183    sed -f tmp/1 bin/1 >bin/bacula-dir.conf
184 #  echo "Job ${oldname} changed to ${newname}"
185 }
186
187 check_two_logs()
188 {
189    grep "^  Termination: *Backup OK" tmp/log1.out 2>&1 >/dev/null
190    bstat=$?
191    grep "^  Termination: .*Backup Error" tmp/log1.out 2>&1 >/dev/null
192    if test $? -eq 0; then
193       bstat=2
194    fi
195    grep "^  Termination: *Restore OK" tmp/log2.out 2>&1 >/dev/null
196    rstat=$?
197    grep "^  Termination: *Restore OK -- warning file count mismatch" tmp/log2.out 2>&1 >/dev/null
198    if test $? -eq 0; then
199       rstat=2
200    fi
201    grep "^  Termination: .*Verify Differences" tmp/log2.out 2>&1 >/dev/null
202    if test $? -eq 0; then
203       rstat=3
204    fi
205 }
206
207 check_restore_diff()
208 {
209    diff -r build tmp/bacula-restores${cwd}/build 2>&1 >/dev/null
210    dstat=$?
211 }
212
213 check_restore_tmp_build_diff()
214 {
215    diff -r tmp/build tmp/bacula-restores${cwd}/tmp/build 2>&1 >/dev/null
216    dstat=$?
217 }
218
219 end_test()
220 {
221    if [ $zstat != 0 ] ; then
222       echo " "
223       echo "  !!!!! $TestName failed!!! `date +%R:%S` !!!!! "
224       echo "  !!!!! $TestName failed!!! `date +%R:%S` !!!!! " >>test.out
225       echo "   Status: zombie=$zstat backup=$bstat restore=$rstat diff=$dstat" >>test.out
226       echo " "
227       exit 1
228    fi
229    if [ $dstat != 0 -o $bstat != 0 -o $rstat != 0 ] ; then
230       echo " "
231       echo " "
232       echo "  !!!!! $TestName failed!!! `date +%R:%S` !!!!! "
233       echo "  !!!!! $TestName failed!!! `date +%R:%S` !!!!! " >>test.out
234       if [ $bstat != 0 -o $rstat != 0 ] ; then
235          echo "  !!!!! Bad termination status       !!!!! "
236          echo "  !!!!! Bad termination status       !!!!! " >>test.out
237       else
238          echo "  !!!!! Restored files differ          !!!!! "
239          echo "  !!!!! Restored files differ          !!!!! " >>test.out
240       fi
241       echo "   Status: backup=$bstat restore=$rstat diff=$dstat"
242       echo "   Status: backup=$bstat restore=$rstat diff=$dstat" >>test.out
243       echo " "
244       exit 1
245    else
246       echo "  ===== $TestName OK `date +%R:%S` ===== "
247       echo "  ===== $TestName OK `date +%R:%S` ===== " >>test.out
248       if test "$debug" -eq 0 ; then
249          scripts/cleanup
250       fi
251    fi
252 }
253
254 copy_tape_confs()
255 {
256    scripts/copy-tape-confs
257    scripts/cleanup-tape
258 }
259
260 copy_test_confs()
261 {
262    scripts/copy-test-confs
263    scripts/cleanup
264 }
265
266 debug_wait()
267 {
268   if test "x${REGRESS_WAIT}" = "x1"; then
269      echo "Start Bacula under debugger and enter anything when ready ..."
270      read a
271   fi
272 }
273
274 init_slot()
275 {
276    DRIVE=$1
277    SLOT=$2
278    if test -n "$DRIVE" -a -n "$SLOT"; then
279       if test ! -c $DRIVE -a ! -b $DRIVE -a x$USE_VTAPE != x ; then
280          dir=`dirname $DRIVE`
281          touch $dir/slot$SLOT
282       fi
283    fi
284 }
285
286 init_drive()
287 {
288   if test a$USE_VTAPE = a; then
289     mt -f $1 rewind
290     mt -f $1 weof
291   else
292     cp /dev/null $1
293   fi
294 }
295
296 # Save current directory
297 cwd=`pwd`
298 if test "x${REGRESS_DEBUG}" = "x1"; then
299    set_debug 1
300 else
301    set_debug 0
302 fi
303
304 # Source the configuration variables
305 . ${cwd}/config
306
307 db_name=${db_name:-"regress"}
308 db_user=${db_user:-"regress"}
309 db_password=${db_password:-""}
310
311 CLIENT=${HOST}-fd
312
313 if [ x$USE_VTAPE = xyes ]; then
314    mkdir -p $cwd/working/ach
315    SLOT1=1
316    SLOT2=2
317    TAPE_DRIVE=$cwd/working/ach/drive1
318    TAPE_DRIVE1=$cwd/working/ach/drive1
319    AUTOCHANGER=$cwd/working/ach/config
320    AUTOCHANGER_SCRIPT=disk-changer
321    DRIVE1=0
322    DRIVE2=1
323    cat > $AUTOCHANGER <<EOF
324 maxdrive=2
325 maxslot=10
326 EOF
327 fi
328
329 AUTOCHANGER_SCRIPT=${AUTOCHANGER_SCRIPT:-mtx-changer}