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