1#!/bin/sh
2#
3# Run a couple of tests with bconsole
4#
5TestName="bconsole-test"
6JobName=backup
7. scripts/functions
8
9scripts/cleanup
10scripts/copy-test-confs
11
12#
13# Zap out any schedule in default conf file so that
14#  it doesn't start during our test
15#
16outf="$tmp/sed_tmp"
17echo "s%  Schedule =%# Schedule =%g" >${outf}
18cp $conf/bareos-dir.conf $tmp/1
19sed -f ${outf} $tmp/1 >$conf/bareos-dir.conf
20
21change_jobname BackupClient1 $JobName
22start_test
23
24# start the director
25touch $tmp/bconcmds
26run_bareos
27
28print_debug "Test bconsole -l and -D with a single director definition"
29
30$bin/bconsole -c $conf/bconsole.conf -l > $tmp/1
31if [ $? -ne 0 ]; then
32    print_debug "Bconsole doesn't support -l option"
33    estat=1
34fi
35
36nb=`cat $tmp/1 | wc -l`
37if [ "$nb" -ne 1 ]; then
38    print_debug "Found more than one director in bconsole -l output"
39    estat=2
40fi
41
42grep "$HOST-dir" $tmp/1 > /dev/null
43if [ $? -ne 0 ]; then
44    print_debug "bconsole -l option doesn't display $HOST-dir"
45    estat=3
46fi
47
48echo quit | $bin/bconsole -c $conf/bconsole.conf -D "this is a test" > $tmp/1
49if [ $? -eq 0 ]; then
50    print_debug "Bconsole should abort if selected directors isn't defined"
51    estat=4
52fi
53
54echo quit | $bin/bconsole -c $conf/bconsole.conf -D "$HOST-dir" > $tmp/1
55if [ $? -ne 0 ]; then
56    print_debug "bconsole doesn't connect to $HOST-dir"
57    estat=5
58fi
59
60perl -Mscripts::functions \
61    -e "extract_resource('$conf/bconsole.conf', 'Director', '$HOST-dir')" \
62    > $tmp/1
63
64sed "s/$HOST-dir/bconsole-test-dir/" $tmp/1 >> $conf/bconsole.conf
65
66$bin/bconsole -t -c $conf/bconsole.conf > $tmp/1
67if [ $? -ne 0 ]; then
68    print_debug "configuration tweak failed"
69    estat=6
70fi
71
72$bin/bconsole -c $conf/bconsole.conf -l > $tmp/1
73if [ $? -ne 0 ]; then
74    print_debug "Bconsole doesn't support -l option"
75    estat=7
76fi
77
78nb=`cat $tmp/1 | wc -l`
79if [ "$nb" -ne 2 ]; then
80    print_debug "Found more than one director in bconsole -l output"
81    estat=8
82fi
83
84grep "$HOST-dir" $tmp/1 > /dev/null
85if [ $? -ne 0 ]; then
86    print_debug "bconsole -l option doesn't display $HOST-dir"
87    estat=9
88fi
89
90grep "bconsole-test-dir" $tmp/1 > /dev/null
91if [ $? -ne 0 ]; then
92    print_debug "bconsole -l option doesn't display bconsole-test-dir"
93    estat=10
94fi
95
96echo quit | $bin/bconsole -c $conf/bconsole.conf -D "this is a test" > $tmp/1
97if [ $? -eq 0 ]; then
98    print_debug "Bconsole should abort if selected directors isn't defined"
99    estat=11
100fi
101
102echo quit | $bin/bconsole -c $conf/bconsole.conf -D "$HOST-dir" > $tmp/1
103if [ $? -ne 0 ]; then
104    print_debug "bconsole doesn't connect to $HOST-dir"
105    estat=12
106fi
107
108echo quit | $bin/bconsole -c $conf/bconsole.conf -D "bconsole-test-dir" > $tmp/1
109if [ $? -ne 0 ]; then
110    print_debug "bconsole doesn't connect to bconsole-test-dir"
111    estat=13
112fi
113
114
115stop_bareos
116end_test
117