]> git.sur5r.net Git - bacula/bacula/blob - regress/tests/plugin-test
Attempt to fix timing problem with console-dotcmd-test on FreeBSD
[bacula/bacula] / regress / tests / plugin-test
1 #!/bin/sh
2 #
3 # Copyright (C) 2000-2015 Kern Sibbald
4 # License: BSD 2-Clause; see file LICENSE-FOSS
5 #
6
7 #
8 # Attempt to backup and restore a file with the bpipe plugin
9 #
10 TestName="plugin-test"
11 JobName=pluginTest
12 . scripts/functions
13
14 scripts/cleanup
15 scripts/copy-plugin-confs
16 make -C $src/src/plugins/fd install-test-plugin
17
18 file=encrypt-bug.jpg
19 rm -rf ${cwd}/tmp/*
20 echo "${cwd}/README" >${cwd}/tmp/file-list
21
22 start_test
23
24 cat <<END_OF_DATA >${cwd}/tmp/bconcmds
25 @output /dev/null
26 messages
27 @$out ${cwd}/tmp/log1.out
28 label storage=File1 volume=TestVolume001
29 setdebug level=150 client=$CLIENT
30 estimate job=$JobName level=Full
31 setdebug level=50 client=$CLIENT
32 run job=$JobName storage=File1 yes
33 wait
34 status client=$CLIENT
35 messages
36 setdebug level=50 trace=1 client=$CLIENT
37 run job=TestPluginTest storage=File1 yes
38 wait
39 run job=$JobName fileset=TestPluginSetAcceptFile1 storage=File1 yes
40 wait
41 status client=$CLIENT
42 messages
43 setdebug level=50 trace=0 client=$CLIENT
44 quit
45 END_OF_DATA
46
47
48 run_bacula
49
50 cat <<END_OF_DATA >${cwd}/tmp/bconcmds
51 @$out $tmp/list
52 llist pluginrestoreconf jobid=2
53 @$out $tmp/conf
54 llist pluginrestoreconf jobid=2 id=2
55 END_OF_DATA
56
57 run_bconsole
58
59 grep string1 $tmp/conf
60
61 cat <<EOF >$tmp/obj
62 string1="My string"
63 string2="My other string"
64 ok=no
65 EOF
66
67 cat <<END_OF_DATA >${cwd}/tmp/bconcmds
68 messages
69 @# 
70 @# now do a restore
71 @#
72 @$out ${cwd}/tmp/log2.out
73 setdebug level=50 client=$CLIENT
74 restore fileset=pluginSet where=${cwd}/tmp  select all storage=File1 done
75 yes
76 wait
77 setdebug level=0 client=$CLIENT
78 messages
79 quit
80 END_OF_DATA
81
82 run_bconsole
83
84 stop_bacula
85
86 # ****FIXME**** test if the restore of the two files is OK
87
88 #
89 # Remove plugin so we can try the restore without the plugin
90 #
91 mv -f ${cwd}/bin/plugins/bpipe-fd.so ${cwd}/bin/plugins/bpipe-fd.sox
92
93 cat <<END_OF_DATA >${cwd}/tmp/bconcmds
94 @$out ${cwd}/tmp/log2.out
95 @# remove plugin
96 @exec "sh -c 'rm -f ${cwd}/bin/plugins/bpipe-fd.so'"
97 @# 
98 @# now do a restore without the plugin
99 @#
100 @$out ${cwd}/tmp/log2.out
101 @#setdebug level=50 client=$CLIENT
102 restore fileset=pluginSet where=${cwd}/tmp  select all storage=File1 done
103 yes
104 wait
105 messages
106 quit
107 END_OF_DATA
108
109 run_bacula -d50
110 run_bconsole
111
112 cat <<END_OF_DATA >${cwd}/tmp/bconcmds
113 messages
114 @# 
115 @# now do a restore
116 @#
117 @$out ${cwd}/tmp/log3.out
118 setdebug level=50 client=$CLIENT trace=1
119 @putfile obj1 $tmp/obj
120 restore pluginrestoreconf="2:obj1" fileset=TestPluginSet where=${cwd}/tmp  select all storage=File1 done
121 yes
122 wait
123 setdebug level=0 client=$CLIENT trace=0
124 messages
125 quit
126 END_OF_DATA
127
128 run_bconsole
129
130 grep "My other string" $working/*trace > /dev/null
131 if [ $? != 0 ]; then
132     print_debug "ERROR: Should find plugin restore conf"
133     estat=1
134 fi
135
136 cat <<END_OF_DATA >${cwd}/tmp/bconcmds
137 messages
138 @# 
139 @# now do a restore
140 @#
141 @$out ${cwd}/tmp/log3.out
142 setdebug level=50 client=$CLIENT trace=1
143 restore fileset=TestPluginSet where=${cwd}/tmp  select all storage=File1 done
144 mod
145 13
146 mod
147 1
148 My new string
149 yes
150 yes
151 wait
152 setdebug level=0 client=$CLIENT trace=0
153 messages
154 quit
155 END_OF_DATA
156
157 run_bconsole
158
159 grep "My new string" $working/*trace > /dev/null
160 if [ $? != 0 ]; then
161     print_debug "ERROR: Should find second plugin restore conf"
162     estat=1
163 fi
164
165 check_for_zombie_jobs storage=File1
166 stop_bacula
167 #
168 # Restore plugin
169 #
170 mv -f ${cwd}/bin/plugins/bpipe-fd.sox ${cwd}/bin/plugins/bpipe-fd.so
171
172 check_two_logs
173 #
174 # ****FIXME**** test that all three files are restored correctly
175 #
176 diff ${cwd}/${file} ${cwd}/tmp/${file}
177 dstat=$?
178
179 diff $working/restore.0 $working/torestore.0
180 if [ $? != 0 ]; then
181     print_debug "ERROR: Restore object difference found"
182     dstat=$?
183 fi
184
185 # Look if bRC_OK = 0, bRC_Skip = 7
186 grep "AcceptFile=takeme.h = 0" $working/*trace > /dev/null
187 if [ $? != 0 ]; then
188     print_debug "ERROR: AcceptFile API problem, look at takeme.h"
189     estat=1
190 fi
191
192 grep "excludeme.o = 7" $working/*trace > /dev/null
193 if [ $? != 0 ]; then
194     print_debug "ERROR: AcceptFile API problem, look at excludeme.o"
195     estat=1
196 fi
197
198 grep "excludeme.c = 7" $working/*trace > /dev/null
199 if [ $? != 0 ]; then
200     print_debug "ERROR: AcceptFile API problem, look at excludeme.c"
201     estat=1
202 fi
203
204
205 # the test-plugin should create a RestoreObject, just check 
206 # compare restore object before/after
207 perl -ne '
208  chomp();
209  if (/Creating RestoreObject/) {
210    @elt = split(/\s/, $_, 7);
211    $ro{$elt[5]}{clen} = $elt[4];
212    $ro{$elt[5]}{cdata} = $elt[6];
213  } elsif (/Get RestoreObject/) {
214    @elt = split(/\s/, $_, 9);
215    $ro{$elt[6]}{glen} = $elt[4];
216    $ro{$elt[6]}{gdata} = $elt[8];
217  }
218  END {
219    $err=0;
220    delete $ro{"oname=RestoreOptions"};
221    if (scalar(keys %ro) == 0) {
222      $err = 1;
223      print "ERROR: No restore object found\n";
224    }
225    foreach my $k (keys %ro) {
226       if ($ro{$k}{clen} ne $ro{$k}{glen}) {
227         print "ERROR: $k $ro{$k}{clen} != $ro{$k}{glen}\n";
228         $err++;
229       } else {
230         print "OK: $k $ro{$k}{clen} == $ro{$k}{glen}\n";
231       }
232       if ($ro{$k}{cdata} ne $ro{$k}{gdata}) {
233         print "ERROR: $k <$ro{$k}{cdata}> != <$ro{$k}{gdata}>\n";
234         $err++;
235       } else {
236         print "OK: $k $ro{$k}{gdata} == $ro{$k}{gdata}\n";
237       }
238    }
239    exit $err;
240  }
241 ' working/*.trace
242
243 estat=$?
244
245 end_test