3 # Copyright (C) 2000-2017 Kern Sibbald
4 # License: BSD 2-Clause; see file LICENSE-FOSS
6 # Test different cancel cases
10 TestName="cancel-test"
18 # Zap out any schedule in default conf file so that
19 # it doesn't start during our test
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
26 if [ "$FORCE_DEDUP" = yes ]; then
34 # Add some jobs and fileset for this test
35 cat <<EOF >>${cwd}/bin/bacula-dir.conf
42 file = "\\</path/to/nowhere"
47 ClientRunBeforeJob = "/bin/false"
53 Command = "/bin/false"
60 ClientRunBeforeJob="/bin/sleep 10"
62 Command = "/bin/sleep 600"
63 Command = "touch $tmp/RUN_ERR3.after.%i"
71 ClientRunBeforeJob="/bin/sleep 10"
73 Command = "touch $tmp/RUN_ERR4.after"
74 Command = "/bin/sleep 40"
82 change_jobname BackupClient1 $JobName
85 when=`perl -MPOSIX -e "print strftime('%F %T', localtime(time+6000))"`
87 cat <<END_OF_DATA >${cwd}/tmp/bconcmds
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 @################################################################
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
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
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
151 @$out ${cwd}/tmp/logfile5.out
152 @################################################################
153 @# test with a broken runscript
154 @# Expect: duration < 20s
155 @################################################################
162 @$out ${cwd}/tmp/logfile6.out
163 @################################################################
164 @# test with a broken runscript
165 @# Expect: duration < 20s
166 @################################################################
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 @################################################################
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
196 @################################################################
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
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
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
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
267 @$out ${cwd}/tmp/logfile12.out
268 @################################################################
269 @# Test to cancel the job before it starts
271 @################################################################
272 run job=$JobName when="$when" yes
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
302 print_debug "Stopping FD"
303 # stop the bacula-fd and cancel the job
304 pid=`cat $working/bacula-fd.*.pid`
307 cat <<END_OF_DATA >${cwd}/tmp/bconcmds
308 @$out ${cwd}/tmp/logfile20.out
324 check_for_zombie_jobs storage=File1
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
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"
341 print_debug "ERROR: No log found, AND the $tmp/RUN_ERR3.after.9 was not created"
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"
353 print_debug "ERROR: No log found, AND the $tmp/RUN_ERR3.after.10 was not created"
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"
364 print_debug "ERROR: No log found, AND the $tmp/RUN_ERR4.after was not created..."
369 # Verify the broken connection
370 check_duration $tmp/logfile20.out 400 lt