]> git.sur5r.net Git - bacula/bacula/blob - regress/scripts/functions
Ensure correct client specified when checking for zombies
[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_faketape() 
60 {
61 if test x${USE_FAKETAPE} = x ; then
62    echo "$TestName test needs the faketape driver."
63    exit 1
64 fi
65 }
66
67 skip_if_no_autochanger()
68 {
69 if test x${AUTOCHANGER} = x/dev/null ; then
70    echo "$TestName test skipped. No autochanger."
71    exit
72 fi
73 }
74
75 set_debug()
76 {
77    debug=$1
78    if test "$debug" -eq 1 ; then
79      out="tee"
80    else
81      out="output"
82    fi
83
84
85 print_debug()
86 {
87    if test "$debug" -eq 1 ; then
88      echo $*
89    fi
90 }
91
92 run_bacula()
93 {
94    debug_wait
95    zstat=0
96    if test "$debug" -eq 1 ; then
97      bin/bacula-ctl-sd start
98      bin/bacula-ctl-fd start
99      bin/bacula-ctl-dir start
100      cat tmp/bconcmds | bin/bconsole -c bin/bconsole.conf
101    else
102      bin/bacula start 2>&1 >/dev/null
103      cat tmp/bconcmds | bin/bconsole -c bin/bconsole.conf  2>&1 >/dev/null
104    fi
105 }
106
107 run_bconsole()
108 {
109    if test "$debug" -eq 1 ; then
110      cat tmp/bconcmds | bin/bconsole -c bin/bconsole.conf
111    else
112      cat tmp/bconcmds | bin/bconsole -c bin/bconsole.conf  2>&1 >/dev/null
113    fi
114 }
115
116 run_btape()
117 {
118    if test "$debug" -eq 1 ; then
119      cat tmp/bconcmds | bin/btape -c bin/bacula-sd.conf DDS-4 | tee tmp/log1.out
120    else
121      cat tmp/bconcmds | bin/btape -c bin/bacula-sd.conf DDS-4 2>&1 >tmp/log1.out
122    fi
123 }
124
125 run_bscan()
126 {
127    if test "$debug" -eq 1 ; then
128       bin/bscan $* | tee tmp/log.out
129    else
130       bin/bscan $* 2>&1 >/dev/null
131    fi
132 }
133
134 bscan_libdbi()
135 {   
136    B=`echo $LIBDBI | sed 's/;//' | sed 's/;//g'`
137    B_D=`echo $B | awk '{print $3}'`
138    B_t=`echo $B | awk '{print $6}'`
139    B_p=`echo $B | awk '{print $9}'`
140
141    BSCANLIBDBI="${LIBDBI:+1}"
142                 
143    if test "$BSCANLIBDBI" = "1" ; then
144       BSCANLIBDBI="-D $B_D -h $B_t -t $B_p"
145    else
146       BSCANLIBDBI=" "
147    fi
148 }
149
150 stop_bacula()
151 {
152    bin/bacula stop 2>&1 >/dev/null
153 }
154
155 check_for_zombie_jobs()
156 {
157    scripts/check_for_zombie_jobs $*
158 }
159
160 change_jobname()
161 {
162    if test $# -eq 1; then
163       oldname=NightlySave
164       newname=$1
165    else
166       oldname=$1
167       newname=$2
168    fi
169    rm -f bin/1
170    mv bin/bacula-dir.conf bin/1
171    echo "s%${oldname}%${newname}%g" >tmp/1
172    sed -f tmp/1 bin/1 >bin/bacula-dir.conf
173 #  echo "Job ${oldname} changed to ${newname}"
174 }
175
176 check_two_logs()
177 {
178    grep "^  Termination: *Backup OK" tmp/log1.out 2>&1 >/dev/null
179    bstat=$?
180    grep "^  Termination: .*Backup Error" tmp/log1.out 2>&1 >/dev/null
181    if test $? -eq 0; then
182       bstat=2
183    fi
184    grep "^  Termination: *Restore OK" tmp/log2.out 2>&1 >/dev/null
185    rstat=$?
186    grep "^  Termination: *Restore OK -- warning file count mismatch" tmp/log2.out 2>&1 >/dev/null
187    if test $? -eq 0; then
188       rstat=2
189    fi
190    grep "^  Termination: .*Verify Differences" tmp/log2.out 2>&1 >/dev/null
191    if test $? -eq 0; then
192       rstat=3
193    fi
194 }
195
196 check_restore_diff()
197 {
198    diff -r build tmp/bacula-restores${cwd}/build 2>&1 >/dev/null
199    dstat=$?
200 }
201
202 check_restore_tmp_build_diff()
203 {
204    diff -r tmp/build tmp/bacula-restores${cwd}/tmp/build 2>&1 >/dev/null
205    dstat=$?
206 }
207
208 end_test()
209 {
210    if [ $zstat != 0 ] ; then
211       echo " "
212       echo "  !!!!! $TestName failed!!! `date +%R:%S` !!!!! "
213       echo "  !!!!! $TestName failed!!! `date +%R:%S` !!!!! " >>test.out
214       echo "   Status: zombie=$zstat backup=$bstat restore=$rstat diff=$dstat" >>test.out
215       echo " "
216       exit 1
217    fi
218    if [ $dstat != 0 -o $bstat != 0 -o $rstat != 0 ] ; then
219       echo " "
220       echo " "
221       echo "  !!!!! $TestName failed!!! `date +%R:%S` !!!!! "
222       echo "  !!!!! $TestName failed!!! `date +%R:%S` !!!!! " >>test.out
223       if [ $bstat != 0 -o $rstat != 0 ] ; then
224          echo "  !!!!! Bad termination status       !!!!! "
225          echo "  !!!!! Bad termination status       !!!!! " >>test.out
226       else
227          echo "  !!!!! Restored files differ          !!!!! "
228          echo "  !!!!! Restored files differ          !!!!! " >>test.out
229       fi
230       echo "   Status: backup=$bstat restore=$rstat diff=$dstat"
231       echo "   Status: backup=$bstat restore=$rstat diff=$dstat" >>test.out
232       echo " "
233       exit 1
234    else
235       echo "  ===== $TestName OK `date +%R:%S` ===== "
236       echo "  ===== $TestName OK `date +%R:%S` ===== " >>test.out
237       if test "$debug" -eq 0 ; then
238          scripts/cleanup
239       fi
240    fi
241 }
242
243 copy_tape_confs()
244 {
245    scripts/copy-tape-confs
246    scripts/cleanup-tape
247 }
248
249 copy_test_confs()
250 {
251    scripts/copy-test-confs
252    scripts/cleanup
253 }
254
255 debug_wait()
256 {
257   if test "x${REGRESS_WAIT}" = "x1"; then
258      echo "Start Bacula under debugger and enter anything when ready ..."
259      read a
260   fi
261 }
262
263 init_drive()
264 {
265   if test a$USE_FAKETAPE = a; then
266     mt -f $1 rewind
267     mt -f $1 weof
268   else
269     cp /dev/null $1
270   fi
271 }
272
273 # Save current directory
274 cwd=`pwd`
275 if test "x${REGRESS_DEBUG}" = "x1"; then
276    set_debug 1
277 else
278    set_debug 0
279 fi
280
281 # Source the configuration variables
282 . ${cwd}/config
283