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