3 # Copyright (C) 2000-2015 Kern Sibbald
4 # License: BSD 2-Clause; see file LICENSE-FOSS
8 # Test different cancel cases
12 TestName="cancel-test"
20 # Zap out any schedule in default conf file so that
21 # it doesn't start during our test
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
32 # Add some jobs and fileset for this test
33 cat <<EOF >>${cwd}/bin/bacula-dir.conf
40 file = "\\</path/to/nowhere"
45 ClientRunBeforeJob = "/bin/false"
51 Command = "/bin/false"
58 ClientRunBeforeJob="/bin/sleep 10"
60 Command = "/bin/sleep 600"
61 Command = "touch $tmp/RUN_ERR3.after.%i"
69 ClientRunBeforeJob="/bin/sleep 10"
71 Command = "touch $tmp/RUN_ERR4.after"
72 Command = "/bin/sleep 40"
80 change_jobname BackupClient1 $JobName
83 when=`perl -MPOSIX -e "print strftime('%F %T', localtime(time+6000))"`
85 cat <<END_OF_DATA >${cwd}/tmp/bconcmds
88 setbandwidth limit=500 client
89 @$out ${cwd}/tmp/logfile1.out
90 @################################################################
91 @# run a first test without volume
92 @# Expect: duration < 60
93 @################################################################
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
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
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
149 @$out ${cwd}/tmp/logfile5.out
150 @################################################################
151 @# test with a broken runscript
152 @# Expect: duration < 20s
153 @################################################################
160 @$out ${cwd}/tmp/logfile6.out
161 @################################################################
162 @# test with a broken runscript
163 @# Expect: duration < 20s
164 @################################################################
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 @################################################################
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
194 @################################################################
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
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
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
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
265 @$out ${cwd}/tmp/logfile12.out
266 @################################################################
267 @# Test to cancel the job before it starts
269 @################################################################
270 run job=$JobName when="$when" yes
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
300 print_debug "Stopping FD"
301 # stop the bacula-fd and cancel the job
302 pid=`cat $working/bacula-fd.*.pid`
305 cat <<END_OF_DATA >${cwd}/tmp/bconcmds
306 @$out ${cwd}/tmp/logfile20.out
322 check_for_zombie_jobs storage=File1
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
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"
339 print_debug "ERROR: No log found, AND the $tmp/RUN_ERR3.after.9 was not created"
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"
351 print_debug "ERROR: No log found, AND the $tmp/RUN_ERR3.after.10 was not created"
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"
362 print_debug "ERROR: No log found, AND the $tmp/RUN_ERR4.after was not created..."
367 # Verify the broken connection
368 check_duration $tmp/logfile20.out 400 lt