]> git.sur5r.net Git - bacula/bacula/blob - regress/scripts/functions
ebl fix warning
[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    else
111      bin/bacula start 2>&1 >/dev/null
112      cat tmp/bconcmds | bin/bconsole -c bin/bconsole.conf  2>&1 >/dev/null
113    fi
114 }
115
116 run_bconsole()
117 {
118    if test "$debug" -eq 1 ; then
119      cat tmp/bconcmds | bin/bconsole -c bin/bconsole.conf
120    else
121      cat tmp/bconcmds | bin/bconsole -c bin/bconsole.conf  2>&1 >/dev/null
122    fi
123 }
124
125 run_btape()
126 {
127    if test "$debug" -eq 1 ; then
128      cat tmp/bconcmds | bin/btape -c bin/bacula-sd.conf DDS-4 | tee tmp/log1.out
129    else
130      cat tmp/bconcmds | bin/btape -c bin/bacula-sd.conf DDS-4 2>&1 >tmp/log1.out
131    fi
132 }
133
134 run_bscan()
135 {
136    if test "$debug" -eq 1 ; then
137       bin/bscan $* | tee tmp/log.out
138    else
139       bin/bscan $* 2>&1 >/dev/null
140    fi
141 }
142
143 bscan_libdbi()
144 {   
145    B=`echo $LIBDBI | sed 's/;//' | sed 's/;//g'`
146    B_D=`echo $B | awk '{print $3}'`
147    B_t=`echo $B | awk '{print $6}'`
148    B_p=`echo $B | awk '{print $9}'`
149
150    BSCANLIBDBI="${LIBDBI:+1}"
151                 
152    if test "$BSCANLIBDBI" = "1" ; then
153       BSCANLIBDBI="-D $B_D -h $B_t -t $B_p"
154    else
155       BSCANLIBDBI=" "
156    fi
157 }
158
159 stop_bacula()
160 {
161    bin/bacula stop 2>&1 >/dev/null
162 }
163
164 check_for_zombie_jobs()
165 {
166    scripts/check_for_zombie_jobs $*
167 }
168
169 change_jobname()
170 {
171    if test $# -eq 1; then
172       oldname=NightlySave
173       newname=$1
174    else
175       oldname=$1
176       newname=$2
177    fi
178    rm -f bin/1
179    mv bin/bacula-dir.conf bin/1
180    echo "s%${oldname}%${newname}%g" >tmp/1
181    sed -f tmp/1 bin/1 >bin/bacula-dir.conf
182 #  echo "Job ${oldname} changed to ${newname}"
183 }
184
185 check_two_logs()
186 {
187    grep "^  Termination: *Backup OK" tmp/log1.out 2>&1 >/dev/null
188    bstat=$?
189    grep "^  Termination: .*Backup Error" tmp/log1.out 2>&1 >/dev/null
190    if test $? -eq 0; then
191       bstat=2
192    fi
193    grep "^  Termination: *Restore OK" tmp/log2.out 2>&1 >/dev/null
194    rstat=$?
195    grep "^  Termination: *Restore OK -- warning file count mismatch" tmp/log2.out 2>&1 >/dev/null
196    if test $? -eq 0; then
197       rstat=2
198    fi
199    grep "^  Termination: .*Verify Differences" tmp/log2.out 2>&1 >/dev/null
200    if test $? -eq 0; then
201       rstat=3
202    fi
203 }
204
205 check_restore_diff()
206 {
207    diff -r build tmp/bacula-restores${cwd}/build 2>&1 >/dev/null
208    dstat=$?
209 }
210
211 check_restore_tmp_build_diff()
212 {
213    diff -r tmp/build tmp/bacula-restores${cwd}/tmp/build 2>&1 >/dev/null
214    dstat=$?
215 }
216
217 end_test()
218 {
219    if [ $zstat != 0 ] ; then
220       echo " "
221       echo "  !!!!! $TestName failed!!! `date +%R:%S` !!!!! "
222       echo "  !!!!! $TestName failed!!! `date +%R:%S` !!!!! " >>test.out
223       echo "   Status: zombie=$zstat backup=$bstat restore=$rstat diff=$dstat" >>test.out
224       echo " "
225       exit 1
226    fi
227    if [ $dstat != 0 -o $bstat != 0 -o $rstat != 0 ] ; then
228       echo " "
229       echo " "
230       echo "  !!!!! $TestName failed!!! `date +%R:%S` !!!!! "
231       echo "  !!!!! $TestName failed!!! `date +%R:%S` !!!!! " >>test.out
232       if [ $bstat != 0 -o $rstat != 0 ] ; then
233          echo "  !!!!! Bad termination status       !!!!! "
234          echo "  !!!!! Bad termination status       !!!!! " >>test.out
235       else
236          echo "  !!!!! Restored files differ          !!!!! "
237          echo "  !!!!! Restored files differ          !!!!! " >>test.out
238       fi
239       echo "   Status: backup=$bstat restore=$rstat diff=$dstat"
240       echo "   Status: backup=$bstat restore=$rstat diff=$dstat" >>test.out
241       echo " "
242       exit 1
243    else
244       echo "  ===== $TestName OK `date +%R:%S` ===== "
245       echo "  ===== $TestName OK `date +%R:%S` ===== " >>test.out
246       if test "$debug" -eq 0 ; then
247          scripts/cleanup
248       fi
249    fi
250 }
251
252 copy_tape_confs()
253 {
254    scripts/copy-tape-confs
255    scripts/cleanup-tape
256 }
257
258 copy_test_confs()
259 {
260    scripts/copy-test-confs
261    scripts/cleanup
262 }
263
264 debug_wait()
265 {
266   if test "x${REGRESS_WAIT}" = "x1"; then
267      echo "Start Bacula under debugger and enter anything when ready ..."
268      read a
269   fi
270 }
271
272 init_slot()
273 {
274    DRIVE=$1
275    SLOT=$2
276    if test -n "$DRIVE" -a -n "$SLOT"; then
277       if test ! -c $DRIVE -a ! -b $DRIVE -a x$USE_VTAPE != x ; then
278          dir=`dirname $DRIVE`
279          touch $dir/slot$SLOT
280       fi
281    fi
282 }
283
284 init_drive()
285 {
286   if test a$USE_VTAPE = a; then
287     mt -f $1 rewind
288     mt -f $1 weof
289   else
290     cp /dev/null $1
291   fi
292 }
293
294 # Save current directory
295 cwd=`pwd`
296 if test "x${REGRESS_DEBUG}" = "x1"; then
297    set_debug 1
298 else
299    set_debug 0
300 fi
301
302 # Source the configuration variables
303 . ${cwd}/config
304
305 CLIENT=${HOST}-fd
306 AUTOCHANGER_SCRIPT=${AUTOCHANGER_SCRIPT:-mtx-changer}