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