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