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