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