]> git.sur5r.net Git - bacula/bacula/blob - regress/tests/cancel-test
0ecfb8969edb9f6751d677c7246e16ff646d532c
[bacula/bacula] / regress / tests / cancel-test
1 #!/bin/sh
2 #
3 # Test different cancel cases
4 # Can be quite long
5
6 #
7 TestName="cancel-test"
8 JobName=backup
9 . scripts/functions
10
11 scripts/cleanup
12 scripts/copy-confs
13
14 #
15 # Zap out any schedule in default conf file so that
16 #  it doesn't start during our test
17 #
18 outf="tmp/sed_tmp"
19 echo "s%  Schedule =%# Schedule =%g" >$outf
20 cp ${cwd}/bin/bacula-dir.conf ${cwd}/tmp/1
21 sed -f ${outf} ${cwd}/tmp/1 >${cwd}/bin/bacula-dir.conf
22
23 touch tmp/log1.out
24
25 # Add some jobs and fileset for this test
26 cat <<EOF >>${cwd}/bin/bacula-dir.conf
27 FileSet {
28   Name = FS_ERR
29   Include {
30     Options {
31       signature = MD5
32     }
33     file = "\\</path/to/nowhere"
34   }
35 }
36 Job {
37   Name = RUN_ERR1
38   ClientRunBeforeJob = "/bin/false"
39   JobDefs = DefaultJob
40 }
41 Job {
42   Name = RUN_ERR2
43   RunScript {
44     Command = "/bin/false"
45     RunsWhen = Before
46   }
47   JobDefs = DefaultJob
48 }
49 Job {
50   Name = RUN_ERR3
51   ClientRunBeforeJob="/bin/sleep 10"
52   RunScript {
53     Command = "/bin/sleep 600"
54     RunsWhen = After
55     RunsOnFailure = Yes
56   }
57   JobDefs = DefaultJob
58 }
59 Job {
60   Name = RUN_ERR4
61   ClientRunBeforeJob="/bin/sleep 10"
62   RunScript {
63     Command = "/bin/sleep 40"
64     RunsWhen = After
65     RunsOnFailure = Yes
66   }
67   JobDefs = DefaultJob
68 }
69 EOF
70
71 change_jobname BackupClient1 $JobName
72 start_test
73
74 when=`perl -MPOSIX -e "print strftime('%F %T', localtime(time+6000))"`
75
76 cat <<END_OF_DATA >${cwd}/tmp/bconcmds
77 @$out /dev/null
78 messages
79 @$out ${cwd}/tmp/logfile1.out
80 @################################################################
81 @# run a first test without volume
82 @# Expect: duration < 60
83 @################################################################
84 run job=$JobName yes
85 @sleep 5
86 messages
87 cancel
88 yes
89 wait
90 messages
91 @$out ${cwd}/tmp/logfile2.out
92 @################################################################
93 @# run test with a small volume
94 @# Expect: duration < 60
95 @################################################################
96 label volume=TestVolume001 storage=File pool=Default
97 update volume=TestVolume001 MaxVolBytes=1MB
98 run job=$JobName yes
99 @sleep 5
100 messages
101 st dir
102 cancel
103 yes
104 wait
105 messages
106 @$out ${cwd}/tmp/logfile3.out
107 @################################################################
108 @# run test with 2 jobs in // (limit 1)
109 @# expect that the second job don't stay in the list
110 @# Expect: Job2 not present at the end
111 @################################################################
112 label volume=TestVolume002 storage=File pool=Default
113 run job=$JobName yes
114 @sleep 1
115 messages
116 run job=$JobName yes
117 @sleep 1
118 messages
119 st dir
120 cancel jobid=4
121 @sleep 1
122 st dir
123 cancel jobid=3
124 @sleep 1
125 st dir
126 wait
127 messages
128 @$out ${cwd}/tmp/logfile4.out
129 @################################################################
130 @# test with a broken fileset
131 @# Expect: duration < 20s
132 @################################################################
133 run job=$JobName fileset=FS_ERR yes
134 @sleep 3
135 messages
136 st dir
137 wait
138 messages
139 @$out ${cwd}/tmp/logfile5.out
140 @################################################################
141 @# test with a broken runscript
142 @# Expect: duration < 20s
143 @################################################################
144 run job=RUN_ERR1 yes
145 @sleep 3
146 messages
147 st dir
148 wait
149 messages
150 @$out ${cwd}/tmp/logfile6.out
151 @################################################################
152 @# test with a broken runscript
153 @# Expect: duration < 20s
154 @################################################################
155 run job=RUN_ERR2 yes
156 @sleep 3
157 messages
158 st dir
159 wait
160 messages
161 @$out ${cwd}/tmp/logfile7.out
162 @################################################################
163 @# test with a broken runscript and a very long AfterJob
164 @# we break the backup during the ClientRunBeforeJob
165 @# Expect: duration > 550
166 @################################################################
167 run job=RUN_ERR3 yes
168 @sleep 5
169 messages
170 st dir
171 cancel
172 yes
173 @sleep 5
174 messages
175 st dir
176 wait
177 messages
178 @$out ${cwd}/tmp/logfile8.out
179 @################################################################
180 @# test with a broken runscript and a very long AfterJob
181 @# we break the backup during the ClientRunAfterJob
182 @# Expect: duration > 550
183 @#         print sleep 600
184 @################################################################
185 run job=RUN_ERR3 yes
186 @sleep 20
187 messages
188 st dir
189 cancel
190 yes
191 @sleep 5
192 messages
193 st dir
194 wait
195 messages
196 @$out ${cwd}/tmp/logfile9.out
197 @################################################################
198 @# test with a broken runscript and a very long AfterJob
199 @# we break the backup during the backup
200 @# Expect: duration > 550
201 @#         print sleep 600
202 @################################################################
203 update volume=TestVolume002 volstatus=Used
204 label volume=TestVolume003 storage=File pool=Default
205 update volume=TestVolume003 MaxVolBytes=1MB
206 run job=RUN_ERR3 yes
207 @sleep 20
208 messages
209 st dir
210 cancel
211 yes
212 @sleep 5
213 messages
214 st dir
215 wait
216 messages
217 @$out ${cwd}/tmp/logfile10.out
218 @################################################################
219 @# test with a broken runscript and a short AfterJob
220 @# we break the backup during the backup
221 @# Expect: print sleep 40
222 @################################################################
223 update volume=TestVolume003 volstatus=Used
224 label volume=TestVolume004 storage=File pool=Default
225 update volume=TestVolume004 MaxVolBytes=1MB
226 run job=RUN_ERR4 yes
227 @sleep 20
228 messages
229 st dir
230 time
231 cancel
232 yes
233 @sleep 5
234 messages
235 st dir
236 wait
237 time
238 messages
239 @$out ${cwd}/tmp/logfile11.out
240 @################################################################
241 @# Test to cancel the job immediately
242 @# Expect: duration < 30
243 @################################################################
244 label volume=TestVolume005 storage=File pool=Default
245 run job=$JobName yes
246 time
247 cancel
248 yes
249 @sleep 5
250 messages
251 st dir
252 wait
253 time
254 messages
255 @$out ${cwd}/tmp/logfile12.out
256 @################################################################
257 @# Test to cancel the job before it starts
258 @# Expect: 
259 @################################################################
260 run job=$JobName when="$when" yes
261 @sleep 5
262 st dir
263 cancel
264 yes
265 time
266 @sleep 5
267 messages
268 st dir
269 wait
270 time
271 messages
272 @$out ${cwd}/tmp/logfile20.out
273 @################################################################
274 @# test with a broken connexion between DIR/FD
275 @# the test will run a job that will stop, and we send
276 @# the STOP signal to the FD process
277 @# Expect: duration < 400
278 @################################################################
279 update volume=TestVolume005 volstatus=Used
280 label volume=TestVolume006 storage=File pool=Default
281 update volume=TestVolume006 MaxVolBytes=1MB
282 run job=$JobName yes
283 @sleep 5
284 messages
285 quit
286 END_OF_DATA
287
288 run_bacula
289
290 print_debug "Stopping FD"
291 # stop the bacula-fd and cancel the job
292 kill -STOP $(pidof bacula-fd)
293
294 cat <<END_OF_DATA >${cwd}/tmp/bconcmds
295 @$out ${cwd}/tmp/logfile20.out
296 @sleep 3
297 messages
298 st dir
299 cancel
300 yes
301 st dir
302 wait
303 messages
304 quit
305 END_OF_DATA
306
307 run_bconsole
308
309 kill -CONT $(pidof bacula-fd)
310
311 check_for_zombie_jobs storage=File
312 stop_bacula
313
314 # A fileset or runscript error goes fast
315 check_duration ${cwd}/tmp/logfile1.out 30
316 check_duration ${cwd}/tmp/logfile3.out 30
317 check_duration ${cwd}/tmp/logfile4.out 30
318 check_duration ${cwd}/tmp/logfile5.out 30
319 check_duration ${cwd}/tmp/logfile6.out 30
320
321 check_duration ${cwd}/tmp/logfile8.out 550 lt
322 grep 'ClientAfterJob "/bin/sleep 600"' tmp/logfile8.out >/dev/null
323 if [ $? -ne 0 ]; then
324     print_debug "Can't find ClientAfterJob"
325     bstat=2
326 fi
327
328 check_duration ${cwd}/tmp/logfile9.out 550 lt
329 grep 'ClientAfterJob "/bin/sleep 600"' tmp/logfile9.out >/dev/null
330 if [ $? -ne 0 ]; then
331     print_debug "Can't find ClientAfterJob"
332     bstat=2
333 fi
334
335 grep 'ClientAfterJob "/bin/sleep 40"' tmp/logfile10.out >/dev/null
336 if [ $? -ne 0 ]; then
337     print_debug "Can't find ClientAfterJob"
338     bstat=2
339 fi
340
341 # Verify the broken connection
342 check_duration ${cwd}/tmp/logfile20.out 400 lt
343
344 end_test