]> git.sur5r.net Git - bacula/bacula/blob - regress/scripts/functions
Turn off regression emails
[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
127 stop_bacula()
128 {
129    bin/bacula stop 2>&1 >/dev/null
130 }
131
132 check_for_zombie_jobs()
133 {
134    scripts/check_for_zombie_jobs $*
135 }
136
137 change_jobname()
138 {
139    if test $# -eq 1; then
140       oldname=NightlySave
141       newname=$1
142    else
143       oldname=$1
144       newname=$2
145    fi
146    rm -f bin/1
147    mv bin/bacula-dir.conf bin/1
148    echo "s%${oldname}%${newname}%g" >tmp/1
149    sed -f tmp/1 bin/1 >bin/bacula-dir.conf
150 #  echo "Job ${oldname} changed to ${newname}"
151 }
152
153 check_two_logs()
154 {
155    grep "^  Termination: *Backup OK" tmp/log1.out 2>&1 >/dev/null
156    bstat=$?
157    grep "^  Termination: .*Backup Error" tmp/log1.out 2>&1 >/dev/null
158    if test $? -eq 0; then
159       bstat=2
160    fi
161    grep "^  Termination: *Restore OK" tmp/log2.out 2>&1 >/dev/null
162    rstat=$?
163    grep "^  Termination: *Restore OK -- warning file count mismatch" tmp/log2.out 2>&1 >/dev/null
164    if test $? -eq 0; then
165       rstat=2
166    fi
167    grep "^  Termination: .*Verify Differences" tmp/log2.out 2>&1 >/dev/null
168    if test $? -eq 0; then
169       rstat=3
170    fi
171 }
172
173 check_restore_diff()
174 {
175    diff -r build tmp/bacula-restores${cwd}/build 2>&1 >/dev/null
176    dstat=$?
177 }
178
179 check_restore_tmp_build_diff()
180 {
181    diff -r tmp/build tmp/bacula-restores${cwd}/tmp/build 2>&1 >/dev/null
182    dstat=$?
183 }
184
185 end_test()
186 {
187    if [ $zstat != 0 ] ; then
188       echo " "
189       echo "  !!!!! $TestName failed!!! `date +%R:%S` !!!!! "
190       echo "  !!!!! $TestName failed!!! `date +%R:%S` !!!!! " >>test.out
191       echo "   Status: zombie=$zstat backup=$bstat restore=$rstat diff=$dstat" >>test.out
192       echo " "
193       exit 1
194    fi
195    if [ $dstat != 0 -o $bstat != 0 -o $rstat != 0 ] ; then
196       echo " "
197       echo " "
198       echo "  !!!!! $TestName failed!!! `date +%R:%S` !!!!! "
199       echo "  !!!!! $TestName failed!!! `date +%R:%S` !!!!! " >>test.out
200       if [ $bstat != 0 -o $rstat != 0 ] ; then
201          echo "  !!!!! Bad termination status       !!!!! "
202          echo "  !!!!! Bad termination status       !!!!! " >>test.out
203       else
204          echo "  !!!!! Restored files differ          !!!!! "
205          echo "  !!!!! Restored files differ          !!!!! " >>test.out
206       fi
207       echo "   Status: backup=$bstat restore=$rstat diff=$dstat"
208       echo "   Status: backup=$bstat restore=$rstat diff=$dstat" >>test.out
209       echo " "
210       exit 1
211    else
212       echo "  ===== $TestName OK `date +%R:%S` ===== "
213       echo "  ===== $TestName OK `date +%R:%S` ===== " >>test.out
214       if test "$debug" -eq 0 ; then
215          scripts/cleanup
216       fi
217    fi
218 }
219
220 copy_tape_confs()
221 {
222    scripts/copy-tape-confs
223    scripts/cleanup-tape
224 }
225
226 copy_test_confs()
227 {
228    scripts/copy-test-confs
229    scripts/cleanup
230 }
231
232 debug_wait()
233 {
234   if test "x${REGRESS_WAIT}" = "x1"; then
235      echo "Start Bacula under debugger and enter anything when ready ..."
236      read a
237   fi
238 }
239
240 # Save current directory
241 cwd=`pwd`
242 if test "x${REGRESS_DEBUG}" = "x1"; then
243    set_debug 1
244 else
245    set_debug 0
246 fi
247
248 # Source the configuration variables
249 . ${cwd}/config