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