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