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