]> 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 skip_if_no_autochanger()
29 {
30 if test x${AUTOCHANGER} = x/dev/null ; then
31    echo "$TestName test skipped. No autochanger."
32    exit
33 fi
34
35 }
36
37 set_debug()
38 {
39    debug=$1
40    if test "$debug" -eq 1 ; then
41      out="tee"
42    else
43      out="output"
44    fi
45
46
47 run_bacula()
48 {
49    debug_wait
50    zstat=0
51    if test "$debug" -eq 1 ; then
52      bin/bacula-ctl-sd start
53      bin/bacula-ctl-fd start
54      bin/bacula-ctl-dir start
55      cat tmp/bconcmds | bin/bconsole -c bin/bconsole.conf
56    else
57      bin/bacula start 2>&1 >/dev/null
58      cat tmp/bconcmds | bin/bconsole -c bin/bconsole.conf  2>&1 >/dev/null
59    fi
60 }
61
62 run_bconsole()
63 {
64    if test "$debug" -eq 1 ; then
65      cat tmp/bconcmds | bin/bconsole -c bin/bconsole.conf
66    else
67      cat tmp/bconcmds | bin/bconsole -c bin/bconsole.conf  2>&1 >/dev/null
68    fi
69 }
70
71 run_btape()
72 {
73    if test "$debug" -eq 1 ; then
74      cat tmp/bconcmds | bin/btape -c bin/bacula-sd.conf DDS-4 | tee tmp/log1.out
75    else
76      cat tmp/bconcmds | bin/btape -c bin/bacula-sd.conf DDS-4 2>&1 >tmp/log1.out
77    fi
78 }
79
80 run_bscan()
81 {
82    if test "$debug" -eq 1 ; then
83       bin/bscan $* | tee tmp/log.out
84    else
85       bin/bscan $* 2>&1 >/dev/null
86    fi
87 }
88
89
90 stop_bacula()
91 {
92    bin/bacula stop 2>&1 >/dev/null
93 }
94
95 check_for_zombie_jobs()
96 {
97    scripts/check_for_zombie_jobs $*
98 }
99
100 change_jobname()
101 {
102    if test $# -eq 1; then
103       oldname=NightlySave
104       newname=$1
105    else
106       oldname=$1
107       newname=$2
108    fi
109    rm -f bin/1
110    mv bin/bacula-dir.conf bin/1
111    echo "s%${oldname}%${newname}%g" >tmp/1
112    sed -f tmp/1 bin/1 >bin/bacula-dir.conf
113 #  echo "Job ${oldname} changed to ${newname}"
114 }
115
116 check_two_logs()
117 {
118    grep "^  Termination: *Backup OK" tmp/log1.out 2>&1 >/dev/null
119    bstat=$?
120    grep "^  Termination: .*Backup Error" tmp/log1.out 2>&1 >/dev/null
121    if test $? -eq 0; then
122       bstat=2
123    fi
124    grep "^  Termination: *Restore OK" tmp/log2.out 2>&1 >/dev/null
125    rstat=$?
126    grep "^  Termination: *Restore OK -- warning file count mismatch" tmp/log2.out 2>&1 >/dev/null
127    if test $? -eq 0; then
128       rstat=2
129    fi
130    grep "^  Termination: .*Verify Differences" tmp/log2.out 2>&1 >/dev/null
131    if test $? -eq 0; then
132       rstat=3
133    fi
134 }
135
136 check_restore_diff()
137 {
138    diff -r build tmp/bacula-restores${cwd}/build 2>&1 >/dev/null
139    dstat=$?
140 }
141
142 check_restore_tmp_build_diff()
143 {
144    diff -r tmp/build tmp/bacula-restores${cwd}/tmp/build 2>&1 >/dev/null
145    dstat=$?
146 }
147
148 end_test()
149 {
150    if [ $zstat != 0 ] ; then
151       echo " "
152       echo "  !!!!! $TestName failed!!! `date +%R:%S` !!!!! "
153       echo "  !!!!! $TestName failed!!! `date +%R:%S` !!!!! " >>test.out
154       echo "   Status: zombie=$zstat backup=$bstat restore=$rstat diff=$dstat" >>test.out
155       echo " "
156       exit 1
157    fi
158    if [ $dstat != 0 -o $bstat != 0 -o $rstat != 0 ] ; then
159       echo " "
160       echo " "
161       echo "  !!!!! $TestName failed!!! `date +%R:%S` !!!!! "
162       echo "  !!!!! $TestName failed!!! `date +%R:%S` !!!!! " >>test.out
163       if [ $bstat != 0 -o $rstat != 0 ] ; then
164          echo "  !!!!! Bad termination status       !!!!! "
165          echo "  !!!!! Bad termination status       !!!!! " >>test.out
166       else
167          echo "  !!!!! Restored files differ          !!!!! "
168          echo "  !!!!! Restored files differ          !!!!! " >>test.out
169       fi
170       echo "   Status: backup=$bstat restore=$rstat diff=$dstat"
171       echo "   Status: backup=$bstat restore=$rstat diff=$dstat" >>test.out
172       echo " "
173       exit 1
174    else
175       echo "  ===== $TestName OK `date +%R:%S` ===== "
176       echo "  ===== $TestName OK `date +%R:%S` ===== " >>test.out
177       if test "$debug" -eq 0 ; then
178          scripts/cleanup
179       fi
180    fi
181 }
182
183 copy_tape_confs()
184 {
185    scripts/copy-tape-confs
186    scripts/cleanup-tape
187 }
188
189 copy_test_confs()
190 {
191    scripts/copy-test-confs
192    scripts/cleanup
193 }
194
195 debug_wait()
196 {
197   if test "x${REGRESS_WAIT}" = "x1"; then
198      echo "Start Bacula under debugger and enter anything when ready ..."
199      read a
200   fi
201 }
202
203 # Save current directory
204 cwd=`pwd`
205 if test "x${REGRESS_DEBUG}" = "x1"; then
206    set_debug 1
207 else
208    set_debug 0
209 fi
210
211 # Source the configuration variables
212 . ${cwd}/config