]> git.sur5r.net Git - bacula/bacula/blob - regress/scripts/functions
Delete unwanted subdirectory
[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 }
113
114 check_restore_diff()
115 {
116    diff -r build tmp/bacula-restores${cwd}/build 2>&1 >/dev/null
117    dstat=$?
118 }
119
120 check_restore_tmp_build_diff()
121 {
122    diff -r tmp/build tmp/bacula-restores${cwd}/tmp/build 2>&1 >/dev/null
123    dstat=$?
124 }
125
126 end_test()
127 {
128    if [ $dstat != 0 -o $bstat != 0 -o $rstat != 0 ] ; then
129       echo " "
130       echo " "
131       echo "  !!!!! $TestName failed!!! !!!!! "
132       echo "  !!!!! $TestName failed!!! !!!!! " >>test.out
133       if [ $bstat != 0 -o $rstat != 0 ] ; then
134          echo "  !!!!! Bad Job termination status     !!!!! "
135          echo "  !!!!! Bad Job termination status     !!!!! " >>test.out
136          echo "        bstat=$bstat rstat=$rstat dstat=$dstat"
137       else
138          echo "  !!!!! Restored files differ          !!!!! "
139          echo "  !!!!! Restored files differ          !!!!! " >>test.out
140          echo "        bstat=$bstat rstat=$rstat dstat=$dstat"
141       fi
142       echo " "
143    else
144       echo "  ===== $TestName OK `date +%R:%S` ===== "
145       echo "  ===== $TestName OK `date +%R:%S` ===== " >>test.out
146       if test "$debug" -eq 0 ; then
147          scripts/cleanup
148       fi
149    fi
150 }
151
152 copy_tape_confs()
153 {
154    scripts/copy-tape-confs
155    scripts/cleanup-tape
156 }
157
158 copy_test_confs()
159 {
160    scripts/copy-test-confs
161    scripts/cleanup
162 }
163
164 debug_wait()
165 {
166   if test "x${REGRESS_WAIT}" = "x1"; then
167      echo "Start Bacula under debugger and enter anything when ready ..."
168      read a
169   fi
170 }
171
172 # Save current directory
173 cwd=`pwd`
174 if test "x${REGRESS_DEBUG}" = "x1"; then
175    set_debug 1
176 else
177    set_debug 0
178 fi
179
180 # Source the configuration variables
181 . ${cwd}/config