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