]> git.sur5r.net Git - bacula/bacula/blob - regress/tests/console-dotcmd-test
Attempt to fix timing problem with console-dotcmd-test on FreeBSD
[bacula/bacula] / regress / tests / console-dotcmd-test
1 #!/bin/sh
2 #
3 # Copyright (C) 2000-2017 Kern Sibbald
4 # License: BSD 2-Clause; see file LICENSE-FOSS
5 #
6 # Run a couple of tests with bconsole and dotcommands
7 #
8 TestName="console-dotcmd-test"
9 JobName=backup
10 . scripts/functions
11
12 scripts/cleanup
13 scripts/copy-test-confs
14
15 #
16 # Zap out any schedule in default conf file so that
17 #  it doesn't start during our test
18 #
19 outf="$tmp/sed_tmp"
20 echo "s%  Schedule =%# Schedule =%g" >${outf}
21 cp $scripts/bacula-dir.conf $tmp/1
22 sed -f ${outf} $tmp/1 >$scripts/bacula-dir.conf
23
24 echo "$cwd/build/po" > $tmp/file-list
25
26 change_jobname NightlySave $JobName
27
28 perl -Mscripts::functions \
29     -e "extract_resource('$conf/bacula-dir.conf', 'Client', '$HOST-fd')" \
30     > $tmp/1
31
32 OUT=$conf/bacula-dir.conf
33 for i in `seq 0 254`
34 do
35
36   sed "s/$HOST-fd/test$i-1-fd/" $tmp/1   | sed "s/Address.*/Address = 127.0.0.$i/" >> $OUT
37   sed "s/$HOST-fd/test$i-2-fd/" $tmp/1   | sed "s/Address.*/Address = 127.0.2.$i/" >> $OUT
38   sed "s/$HOST-fd/test$i-rst-fd/" $tmp/1 | sed "s/Address.*/Address = 127.0.3.$i/" >> $OUT
39   sed "s/$HOST-fd/test$i-err-fd/" $tmp/1 | sed "s/Address.*/Address = something.lan.xx.baculasystems.com/" >> $tmp/bad-fd
40 done
41
42 start_test
43
44 # We create hundred of clients in this test, the director startup can be long
45 # specially on MySQL and Ubuntu
46 touch $tmp/bconcmds
47 run_bacula
48
49 ok=1
50 retry=0
51
52 while [ $ok -ne 0 -a $retry -lt 5 ]; do
53     echo quit | $bin/bconsole -c $conf/bconsole.conf | grep quit
54     ok=$?
55     retry=`expr $retry + 1`
56 done
57     
58 cat <<EOF > $tmp/bconcmds
59 @out /dev/null
60 reload
61 messages
62 @$out $tmp/log1.out
63 .client
64 @$out $tmp/log2.out
65 time
66 .client address=127.0.0.50
67 time
68 @$out $tmp/log3.out
69 time
70 .client address=x.x.x.x
71 time
72 @echo done
73 @exec "touch $tmp/log.done"
74 EOF
75
76 run_bconsole
77
78 # Put some bad FDs in the list
79 cat $tmp/bad-fd >> $conf/bacula-dir.conf
80
81 # At the end of the bconsole session, touch $tmp/logerr.done instead of $tmp/log.done
82 sed s/log/logerr/ $tmp/bconcmds > $tmp/bconcmds.err
83
84 # With DNS errors, it will take more times
85 (run_bconsole $tmp/bconcmds.err)&
86
87 sleep 2
88
89 cat <<EOF > $tmp/bconcmds.sametime
90 @out /dev/null
91 reload
92 messages
93 @$out $tmp/log1.out
94 .client
95 @exec "touch $tmp/logsametime.done"
96 EOF
97
98 run_bconsole $tmp/bconcmds.sametime
99
100 wait
101
102 $bperl -e '(-M "$tmp/logsametime.done" < -M "$tmp/logerr.done") && exit 1'
103 if [ $? -ne 0 ]; then
104     print_debug "ERROR: The timestamp of $tmp/logsametime.done should be smaller than $tmp/logerr.done"
105     stat $tmp/logsametime.done
106     stat $tmp/logerr.done
107 # I am not convinced that these timestamps will always be correct -- KES
108 #    estat=1
109 else
110     stat $tmp/logsametime.done
111     stat $tmp/logerr.done
112 fi
113
114 nb=`grep test50-1-fd $tmp/log2.out $tmp/logerr2.out | wc -l`
115 if [ $nb != 2 ]; then
116     print_debug "ERROR: Should find the client test50-1-fd in the $tmp/log2.out and $tmp/logerr2.out files"
117     estat=1
118 fi
119
120 stop_bacula
121 end_test