]>
Commit | Line | Data |
---|---|---|
94ace6ff | 1 | AT_BANNER([appctl bashcomp unit tests]) |
08d42548 AW |
2 | |
3 | m4_define([GET_FORMAT], [ | |
4 | echo "$@" | grep -A 1 -- "Command format" | tail -n+2 | |
5 | ]) | |
6 | ||
7 | m4_define([GET_EXPAN], [ | |
8 | echo "$@" | grep -- "available completions for keyword" \ | |
9 | | sed -e 's/^[ ]*//g;s/[ ]*$//g' | |
10 | ]) | |
11 | ||
12 | m4_define([GET_AVAIL], [ | |
13 | echo "$@" | sed -e '1,/Available/d' | tail -n+2 | |
14 | ]) | |
15 | ||
16 | m4_define([GET_COMP_STR], [ | |
17 | echo "available completions for keyword \"$1\": $2" \ | |
18 | | sed -e 's/[ ]*$//g' | |
19 | ]) | |
20 | ||
94ace6ff | 21 | AT_SETUP([appctl-bashcomp - basic verification]) |
08d42548 AW |
22 | AT_SKIP_IF([test -z ${BASH_VERSION+x}]) |
23 | OVS_VSWITCHD_START | |
24 | ||
25 | # complete ovs-appctl [TAB] | |
26 | # complete ovs-dpctl [TAB] | |
27 | # complete ovs-ofctl [TAB] | |
28 | # complete ovsdb-tool [TAB] | |
29 | m4_foreach( | |
30 | [test_command], | |
31 | [[ovs-appctl], | |
32 | [ovs-dpctl], | |
33 | [ovs-ofctl], | |
34 | [ovsdb-tool]], | |
35 | [ | |
94ace6ff | 36 | INPUT="$(bash ovs-appctl-bashcomp.bash debug test_command TAB 2>&1)" |
08d42548 AW |
37 | MATCH="$(test_command --option | sort | sed -n '/^--.*/p' | cut -d '=' -f1) |
38 | $(test_command list-commands | tail -n +2 | cut -c3- | cut -d ' ' -f1 | sort)" | |
39 | AT_CHECK_UNQUOTED([GET_AVAIL(${INPUT})], | |
40 | [0], [dnl | |
41 | ${MATCH} | |
42 | ])]) | |
43 | ||
44 | ||
45 | # complete ovs-appctl --tar[TAB] | |
94ace6ff | 46 | INPUT="$(bash ovs-appctl-bashcomp.bash debug ovs-appctl --tar 2>&1)" |
08d42548 AW |
47 | AT_CHECK_UNQUOTED([GET_AVAIL(${INPUT})], |
48 | [0], [dnl | |
49 | --target | |
50 | ]) | |
51 | ||
52 | ||
53 | # complete ovs-appctl --target [TAB] | |
94ace6ff | 54 | INPUT="$(bash ovs-appctl-bashcomp.bash debug ovs-appctl --target TAB 2>&1)" |
08d42548 AW |
55 | AT_CHECK_UNQUOTED([GET_AVAIL(${INPUT})], |
56 | [0], [dnl | |
57 | ovs-ofctl | |
58 | ovs-vswitchd | |
59 | ovsdb-server | |
60 | ]) | |
61 | ||
62 | ||
63 | # complete ovs-appctl --target ovs-vswitchd [TAB] | |
64 | # complete ovs-appctl --target ovsdb-server [TAB] | |
65 | # complete ovs-appctl --target ovs-ofctl [TAB] | |
66 | AT_CHECK([ovs-ofctl monitor br0 --detach --no-chdir --pidfile]) | |
67 | m4_foreach( | |
68 | [target_daemon], | |
69 | [[ovs-vswitchd], | |
70 | [ovsdb-server], | |
71 | [ovs-ofctl]], | |
72 | [ | |
94ace6ff | 73 | INPUT="$(bash ovs-appctl-bashcomp.bash debug ovs-appctl --target target_daemon TAB 2>&1)" |
08d42548 AW |
74 | MATCH="$(ovs-appctl --option | sort | sed -n '/^--.*/p' | cut -d '=' -f1) |
75 | $(ovs-appctl --target target_daemon list-commands | tail -n +2 | cut -c3- | cut -d ' ' -f1 | sort)" | |
76 | AT_CHECK_UNQUOTED([GET_AVAIL(${INPUT})], | |
77 | [0], [dnl | |
78 | ${MATCH} | |
79 | ])]) | |
80 | AT_CHECK([ovs-appctl --target ovs-ofctl exit]) | |
08d42548 AW |
81 | OVS_VSWITCHD_STOP |
82 | AT_CLEANUP | |
83 | ||
84 | ||
85 | # complex completion check - bfd/set-forwarding | |
86 | # bfd/set-forwarding [interface] normal|false|true | |
87 | # test expansion of 'interface' | |
94ace6ff | 88 | AT_SETUP([appctl-bashcomp - complex completion check 1]) |
08d42548 AW |
89 | AT_SKIP_IF([test -z ${BASH_VERSION+x}]) |
90 | OVS_VSWITCHD_START(add-port br0 p0 -- set Interface p0 type=dummy) | |
91 | ||
92 | # check the top level completion. | |
94ace6ff | 93 | INPUT="$(bash ovs-appctl-bashcomp.bash debug ovs-appctl bfd/set-forwarding TAB 2>&1)" |
08d42548 AW |
94 | MATCH="$(GET_COMP_STR([normal], []) |
95 | GET_COMP_STR([false], []) | |
96 | GET_COMP_STR([true], []) | |
97 | GET_COMP_STR([interface], [p0]))" | |
98 | AT_CHECK_UNQUOTED([GET_EXPAN(${INPUT})], | |
99 | [0], [dnl | |
100 | ${MATCH} | |
101 | ]) | |
102 | # check the available completions. | |
103 | AT_CHECK_UNQUOTED([GET_AVAIL(${INPUT})], | |
104 | [0], [dnl | |
105 | p0 | |
106 | ]) | |
107 | ||
108 | ||
109 | # set argument to 'true', there should be no more completions. | |
94ace6ff | 110 | INPUT="$(bash ovs-appctl-bashcomp.bash debug ovs-appctl bfd/set-forwarding true TAB 2>&1)" |
08d42548 AW |
111 | AT_CHECK_UNQUOTED([echo "$INPUT" | sed -e '/./,$!d'], |
112 | [0], [dnl | |
08d42548 AW |
113 | ]) |
114 | ||
115 | ||
116 | # set argument to 'p1', there should still be the completion for booleans. | |
94ace6ff | 117 | INPUT="$(bash ovs-appctl-bashcomp.bash debug ovs-appctl bfd/set-forwarding p1 TAB 2>&1)" |
08d42548 AW |
118 | MATCH="$(GET_COMP_STR([normal], []) |
119 | GET_COMP_STR([false], []) | |
120 | GET_COMP_STR([true], []))" | |
121 | AT_CHECK_UNQUOTED([GET_EXPAN(${INPUT})], | |
122 | [0], [dnl | |
123 | ${MATCH} | |
124 | ]) | |
125 | # check the available completions. | |
126 | AT_CHECK_UNQUOTED([GET_AVAIL(${INPUT})], [0]) | |
127 | ||
128 | ||
129 | # set argument to 'p1 false', there should still no more completions. | |
94ace6ff | 130 | INPUT="$(bash ovs-appctl-bashcomp.bash debug ovs-appctl bfd/set-forwarding p1 false TAB 2>&1)" |
08d42548 AW |
131 | AT_CHECK_UNQUOTED([echo "$INPUT" | sed -e '/./,$!d'], |
132 | [0], [dnl | |
08d42548 AW |
133 | ]) |
134 | ||
135 | OVS_VSWITCHD_STOP | |
136 | AT_CLEANUP | |
137 | ||
138 | ||
139 | # complex completion check - lacp/show | |
140 | # lacp/show [port] | |
141 | # test expansion on 'port' | |
94ace6ff | 142 | AT_SETUP([appctl-bashcomp - complex completion check 2]) |
08d42548 AW |
143 | AT_SKIP_IF([test -z ${BASH_VERSION+x}]) |
144 | OVS_VSWITCHD_START(add-port br0 p0 -- set Interface p0 type=dummy \ | |
145 | -- add-port br0 p1 -- set Interface p1 type=dummy) | |
146 | ||
147 | # check the top level completion. | |
94ace6ff | 148 | INPUT="$(bash ovs-appctl-bashcomp.bash debug ovs-appctl lacp/show TAB 2>&1)" |
08d42548 AW |
149 | MATCH="$(GET_COMP_STR([port], [br0 p0 p1]))" |
150 | AT_CHECK_UNQUOTED([GET_EXPAN(${INPUT})], | |
151 | [0], [dnl | |
152 | ${MATCH} | |
153 | ]) | |
154 | # check the available completions. | |
155 | AT_CHECK_UNQUOTED([GET_AVAIL(${INPUT})], | |
156 | [0], [dnl | |
157 | br0 | |
158 | p0 | |
159 | p1 | |
160 | ]) | |
161 | ||
162 | ||
163 | # set argument to 'p1', there should be no more completions. | |
94ace6ff | 164 | INPUT="$(bash ovs-appctl-bashcomp.bash debug ovs-appctl lacp/show p1 TAB 2>&1)" |
08d42548 AW |
165 | AT_CHECK_UNQUOTED([echo "$INPUT" | sed -e '/./,$!d'], |
166 | [0], [dnl | |
08d42548 AW |
167 | ]) |
168 | ||
169 | OVS_VSWITCHD_STOP | |
170 | AT_CLEANUP | |
171 | ||
172 | ||
173 | # complex completion check - ofproto/trace | |
174 | # ofproto/trace {[dp_name] odp_flow | bridge br_flow} [-generate|packet] | |
175 | # test expansion on 'dp|dp_name' and 'bridge' | |
94ace6ff | 176 | AT_SETUP([appctl-bashcomp - complex completion check 3]) |
08d42548 AW |
177 | AT_SKIP_IF([test -z ${BASH_VERSION+x}]) |
178 | OVS_VSWITCHD_START(add-port br0 p0 -- set Interface p0 type=dummy \ | |
179 | -- add-port br0 p1 -- set Interface p1 type=dummy) | |
180 | ||
181 | # check the top level completion. | |
94ace6ff | 182 | INPUT="$(bash ovs-appctl-bashcomp.bash debug ovs-appctl ofproto/trace TAB 2>&1)" |
08d42548 AW |
183 | MATCH="$(GET_COMP_STR([bridge], [br0]) |
184 | GET_COMP_STR([odp_flow], []) | |
185 | GET_COMP_STR([dp_name], [ovs-dummy]))" | |
186 | AT_CHECK_UNQUOTED([GET_EXPAN(${INPUT})], | |
187 | [0], [dnl | |
188 | ${MATCH} | |
189 | ]) | |
190 | # check the available completions. | |
191 | AT_CHECK_UNQUOTED([GET_AVAIL(${INPUT})], | |
192 | [0], [dnl | |
193 | br0 | |
194 | ovs-dummy | |
195 | ]) | |
196 | ||
197 | ||
198 | # set argument to 'ovs-dummy', should go to the dp-name path. | |
94ace6ff | 199 | INPUT="$(bash ovs-appctl-bashcomp.bash debug ovs-appctl ofproto/trace ovs-dummy TAB 2>&1)" |
08d42548 AW |
200 | MATCH="$(GET_COMP_STR([odp_flow], []))" |
201 | AT_CHECK_UNQUOTED([GET_EXPAN(${INPUT})], | |
202 | [0], [dnl | |
203 | ${MATCH} | |
204 | ]) | |
205 | # check the available completions. | |
206 | AT_CHECK_UNQUOTED([GET_AVAIL(${INPUT})], [0]) | |
207 | ||
208 | ||
209 | # set odp_flow to some random string, should go to the next level. | |
94ace6ff | 210 | INPUT="$(bash ovs-appctl-bashcomp.bash debug ovs-appctl ofproto/trace ovs-dummy "in_port(123),mac(),ip,tcp" TAB 2>&1)" |
08d42548 AW |
211 | MATCH="$(GET_COMP_STR([-generate], [-generate]) |
212 | GET_COMP_STR([packet], []))" | |
213 | AT_CHECK_UNQUOTED([GET_EXPAN(${INPUT})], | |
214 | [0], [dnl | |
215 | ${MATCH} | |
216 | ]) | |
217 | # check the available completions. | |
218 | AT_CHECK_UNQUOTED([GET_AVAIL(${INPUT})], | |
219 | [0], [dnl | |
220 | -generate | |
221 | ]) | |
222 | ||
223 | ||
224 | # set packet to some random string, there should be no more completions. | |
94ace6ff | 225 | INPUT="$(bash ovs-appctl-bashcomp.bash debug ovs-appctl ofproto/trace ovs-dummy "in_port(123),mac(),ip,tcp" "ABSJDFLSDJFOIWEQR" TAB 2>&1)" |
08d42548 AW |
226 | AT_CHECK_UNQUOTED([echo "$INPUT" | sed -e '/./,$!d'], |
227 | [0], [dnl | |
08d42548 AW |
228 | ]) |
229 | ||
230 | ||
231 | # set argument to 'br0', should go to the bridge path. | |
94ace6ff | 232 | INPUT="$(bash ovs-appctl-bashcomp.bash debug ovs-appctl ofproto/trace br0 TAB 2>&1)" |
08d42548 AW |
233 | MATCH="$(GET_COMP_STR([br_flow], []))" |
234 | AT_CHECK_UNQUOTED([GET_EXPAN(${INPUT})], | |
235 | [0], [dnl | |
236 | ${MATCH} | |
237 | ]) | |
238 | # check the available completions. | |
239 | AT_CHECK_UNQUOTED([GET_AVAIL(${INPUT})], [0]) | |
240 | ||
241 | ||
242 | # set argument to some random string, should go to the odp_flow path. | |
94ace6ff | 243 | INPUT="$(bash ovs-appctl-bashcomp.bash debug ovs-appctl ofproto/trace "in_port(123),mac(),ip,tcp" TAB 2>&1)" |
08d42548 AW |
244 | MATCH="$(GET_COMP_STR([-generate], [-generate]) |
245 | GET_COMP_STR([packet], []))" | |
246 | AT_CHECK_UNQUOTED([GET_EXPAN(${INPUT})], | |
247 | [0], [dnl | |
248 | ${MATCH} | |
249 | ]) | |
250 | # check the available completions. | |
251 | AT_CHECK_UNQUOTED([GET_AVAIL(${INPUT})], | |
252 | [0], [dnl | |
253 | -generate | |
254 | ]) | |
255 | ||
256 | OVS_VSWITCHD_STOP | |
257 | AT_CLEANUP | |
258 | ||
259 | ||
260 | # complex completion check - vlog/set | |
261 | # vlog/set {spec | PATTERN:destination:pattern} | |
262 | # test non expandable arguments | |
94ace6ff | 263 | AT_SETUP([appctl-bashcomp - complex completion check 4]) |
08d42548 AW |
264 | AT_SKIP_IF([test -z ${BASH_VERSION+x}]) |
265 | OVS_VSWITCHD_START | |
266 | ||
267 | # check the top level completion. | |
94ace6ff | 268 | INPUT="$(bash ovs-appctl-bashcomp.bash debug ovs-appctl vlog/set TAB 2>&1)" |
08d42548 AW |
269 | MATCH="$(GET_COMP_STR([PATTERN:destination:pattern], []) |
270 | GET_COMP_STR([spec], []))" | |
271 | AT_CHECK_UNQUOTED([GET_EXPAN(${INPUT})], | |
272 | [0], [dnl | |
273 | ${MATCH} | |
274 | ]) | |
275 | # check the available completions. | |
276 | AT_CHECK_UNQUOTED([GET_AVAIL(${INPUT})], [0]) | |
277 | ||
278 | ||
279 | # set argument to random 'abcd', there should be no more completions. | |
94ace6ff | 280 | INPUT="$(bash ovs-appctl-bashcomp.bash debug ovs-appctl vlog/set abcd TAB 2>&1)" |
08d42548 AW |
281 | AT_CHECK_UNQUOTED([echo "$INPUT" | sed -e '/./,$!d'], |
282 | [0], [dnl | |
08d42548 AW |
283 | ]) |
284 | ||
285 | OVS_VSWITCHD_STOP | |
286 | AT_CLEANUP | |
287 | ||
288 | ||
94ace6ff | 289 | AT_SETUP([appctl-bashcomp - negative test]) |
08d42548 AW |
290 | AT_SKIP_IF([test -z ${BASH_VERSION+x}]) |
291 | OVS_VSWITCHD_START(add-port br0 p0 -- set Interface p0 type=dummy) | |
292 | ||
293 | # negative test - incorrect subcommand | |
94ace6ff | 294 | INPUT="$(bash ovs-appctl-bashcomp.bash debug ovs-appctl ERROR 2>&1)" |
08d42548 | 295 | AT_CHECK_UNQUOTED([echo "$INPUT" | sed -e 's/[ \t]*$//' | sed -e '/./,$!d'], [0]) |
94ace6ff | 296 | INPUT="$(bash ovs-appctl-bashcomp.bash debug ovs-appctl ERROR TAB 2>&1)" |
08d42548 AW |
297 | AT_CHECK_UNQUOTED([echo "$INPUT" | sed -e 's/[ \t]*$//' | sed -e '/./!d'], |
298 | [0], [dnl | |
08d42548 AW |
299 | ]) |
300 | ||
301 | ||
302 | # negative test - no ovs-vswitchd | |
303 | # negative test - no ovsdb-server | |
304 | # negative test - no ovs-ofctl | |
305 | # should not see any error. | |
306 | OVS_VSWITCHD_STOP | |
307 | m4_foreach( | |
308 | [target_daemon], | |
309 | [[ovs-vswitchd], | |
310 | [ovsdb-server], | |
311 | [ovs-ofctl]], | |
312 | [ | |
94ace6ff | 313 | INPUT="$(bash ovs-appctl-bashcomp.bash debug ovs-appctl --target target_daemon TAB 2>&1)" |
08d42548 AW |
314 | MATCH="$(ovs-appctl --option | sort | sed -n '/^--.*/p' | cut -d '=' -f1)" |
315 | AT_CHECK_UNQUOTED([GET_AVAIL(${INPUT})], | |
316 | [0], [dnl | |
317 | ${MATCH} | |
318 | ]) | |
94ace6ff | 319 | INPUT="$(bash ovs-appctl-bashcomp.bash debug ovs-appctl --target target_daemon ERROR SUBCMD TAB 2>&1)" |
08d42548 AW |
320 | AT_CHECK_UNQUOTED([echo "$INPUT" | sed -e 's/[ \t]*$//' | sed -e '/./!d'], |
321 | [0], [dnl | |
08d42548 AW |
322 | ])]) |
323 | ||
324 | ||
325 | # negative test - do not match on nested option | |
94ace6ff | 326 | INPUT="$(bash ovs-appctl-bashcomp.bash debug ovsdb-tool create TAB 2>&1)" |
08d42548 AW |
327 | AT_CHECK_UNQUOTED([GET_AVAIL(${INPUT})], [0]) |
328 | ||
557570fa AW |
329 | AT_CLEANUP |
330 | ||
331 | ||
332 | dnl ---------------------------------------------------------------------- | |
333 | AT_BANNER([vsctl bashcomp unit tests]) | |
334 | ||
335 | m4_define([PREPARE_MATCH_NOSPACE], [ | |
336 | echo "$@" | tr ' ' '\n' | sed -e '/^$/d' | sort -u | |
337 | ]) | |
338 | ||
339 | m4_define([PREPARE_MATCH_SPACE], [ | |
340 | echo "$@" | tr ' ' '\n' | sed -e '/^$/d' | sed -e 's/$/ /g' | sort -u | |
341 | ]) | |
342 | ||
343 | AT_SETUP([vsctl-bashcomp - basic verification]) | |
ce34e37f | 344 | AT_SKIP_IF([test -z ${BASH_VERSION+x} || test ${BASH_VERSINFO[[0]]} -lt 4]) |
557570fa AW |
345 | OVS_VSWITCHD_START |
346 | ||
347 | # complete ovs-vsctl --db=* [TAB] | |
348 | TMP="$(ovs-vsctl --commands | cut -d',' -f1-2 | tr -d ',[[]]' | tr -s ' ' '\n') | |
349 | $(ovs-vsctl --options | grep -- '--' | sed -e 's/=.*$/=/g')" | |
350 | MATCH="$(PREPARE_MATCH_NOSPACE(${TMP}))" | |
351 | AT_CHECK_UNQUOTED([ovs-vsctl-bashcomp.bash test "--db=unix:$OVS_RUNDIR/db.sock "], | |
352 | [0], [dnl | |
353 | ${MATCH} | |
354 | ]) | |
355 | # complete ovs-vsctl [TAB] | |
356 | AT_CHECK_UNQUOTED([ovs-vsctl-bashcomp.bash test ""], | |
357 | [0], [dnl | |
358 | ${MATCH} | |
359 | ]) | |
360 | ||
361 | # complete on global options. | |
362 | AT_CHECK_UNQUOTED([ovs-vsctl-bashcomp.bash test "--dry-run "], | |
363 | [0], [dnl | |
364 | ${MATCH} | |
365 | ]) | |
366 | AT_CHECK_UNQUOTED([ovs-vsctl-bashcomp.bash test "--dry-run --pretty "], | |
367 | [0], [dnl | |
368 | ${MATCH} | |
369 | ]) | |
370 | ||
371 | # complete on local options. | |
372 | TMP="$(ovs-vsctl --commands | grep -- '--may-exist' | cut -d',' -f1-2 | tr -d ',[[]]' | tr -s ' ' '\n' | grep -v -- '--may-exist')" | |
373 | MATCH="$(PREPARE_MATCH_SPACE(${TMP}))" | |
374 | AT_CHECK_UNQUOTED([ovs-vsctl-bashcomp.bash test "--may-exist "], | |
375 | [0], [dnl | |
376 | ${MATCH} | |
377 | ]) | |
378 | ||
379 | # | |
380 | # test !, +, ?, *. | |
381 | # | |
382 | # test !. no following arguments are expanded. | |
383 | TMP="$(ovsdb-client --no-heading list-tables)" | |
384 | MATCH="$(PREPARE_MATCH_SPACE(${TMP}))" | |
385 | AT_CHECK_UNQUOTED([ovs-vsctl-bashcomp.bash test "set "], | |
386 | [0], [dnl | |
387 | ${MATCH} | |
388 | ]) | |
389 | # test ?. will show completions for both current and following arguments. | |
390 | ovs-vsctl br-set-external-id br0 bridge-id br0 | |
391 | MATCH="$(PREPARE_MATCH_SPACE(bridge-id --))" | |
392 | AT_CHECK_UNQUOTED([ovs-vsctl-bashcomp.bash test "br-get-external-id br0 "], | |
393 | [0], [dnl | |
394 | ${MATCH} | |
395 | ]) | |
396 | # test *. argument with this prefix could be completed for zero or more times. | |
397 | TMP="$(ovs-vsctl --no-heading --columns=_uuid,name list Bridge | tr -d '\"')" | |
398 | MATCH="$(PREPARE_MATCH_SPACE(${TMP} --))" | |
399 | AT_CHECK_UNQUOTED([ovs-vsctl-bashcomp.bash test "destroy Bridge "], | |
400 | [0], [dnl | |
401 | ${MATCH} | |
402 | ]) | |
403 | AT_CHECK_UNQUOTED([ovs-vsctl-bashcomp.bash test "destroy Bridge br0 "], | |
404 | [0], [dnl | |
405 | ${MATCH} | |
406 | ]) | |
407 | # test +. the first time, an argument is required, after that, it becomes '*'. | |
408 | TMP="$(ovsdb-client --no-heading list-columns Open_vSwitch Bridge | awk '/key.*value/ { print $1":"; next } { print $1; next }')" | |
409 | MATCH="$(PREPARE_MATCH_NOSPACE(${TMP}))" | |
410 | AT_CHECK_UNQUOTED([ovs-vsctl-bashcomp.bash test "set Bridge br0 "], | |
411 | [0], [dnl | |
412 | ${MATCH} | |
413 | ]) | |
414 | MATCH="$(PREPARE_MATCH_NOSPACE(${TMP} --))" | |
415 | AT_CHECK_UNQUOTED([ovs-vsctl-bashcomp.bash test "set Bridge br0 other_config:random_key=123 "], | |
416 | [0], [dnl | |
417 | ${MATCH} | |
418 | ]) | |
419 | ||
420 | OVS_VSWITCHD_STOP | |
421 | AT_CLEANUP | |
422 | ||
423 | ||
424 | AT_SETUP([vsctl-bashcomp - argument completion]) | |
ce34e37f | 425 | AT_SKIP_IF([test -z ${BASH_VERSION+x} || test ${BASH_VERSINFO[[0]]} -lt 4]) |
557570fa AW |
426 | OVS_VSWITCHD_START( |
427 | [add-br br1 -- \ | |
428 | set bridge br1 datapath-type=dummy -- \ | |
429 | add-br foo -- \ | |
430 | set bridge foo datapath-type=dummy -- \ | |
431 | add-br --weird-br_name -- \ | |
432 | set bridge --weird-br_name datapath-type=dummy -- \ | |
433 | add-port br0 br0p0 -- set Interface br0p0 type=dummy -- \ | |
434 | add-port br0 br0p1 -- set Interface br0p1 type=dummy -- \ | |
435 | add-port br1 br1p0 -- set Interface br1p0 type=dummy -- \ | |
436 | add-port br1 br1p1 -- set Interface br1p1 type=dummy -- \ | |
437 | add-port foo bar -- set Interface bar type=dummy ]) | |
438 | # | |
439 | # test completion functions defined in '_OVS_VSCTL_ARG_COMPLETION_FUNCS'. | |
440 | # therein, the different argument prefixes are also tested at the same time. | |
441 | # | |
442 | # A space is appended to each output if completion is configured without | |
443 | # 'nospace' option. | |
444 | # | |
445 | ||
446 | ||
447 | # | |
448 | # test: _ovs_vsctl_complete_table | |
449 | # | |
450 | TMP="$(ovsdb-client --no-heading list-tables)" | |
451 | MATCH="$(PREPARE_MATCH_SPACE(${TMP}))" | |
452 | AT_CHECK_UNQUOTED([ovs-vsctl-bashcomp.bash test "set "], | |
453 | [0], [dnl | |
454 | ${MATCH} | |
455 | ]) | |
456 | MATCH="$(PREPARE_MATCH_SPACE(Open_vSwitch))" | |
457 | AT_CHECK_UNQUOTED([ovs-vsctl-bashcomp.bash test "set Open"], | |
458 | [0], [dnl | |
459 | ${MATCH} | |
460 | ]) | |
461 | ||
462 | ||
463 | # | |
464 | # test: _ovs_vsctl_complete_record | |
465 | # | |
466 | TMP="$(ovs-vsctl --no-heading --columns=_uuid list Open_vSwitch | tr -d '\"')" | |
467 | MATCH="$(PREPARE_MATCH_SPACE(${TMP}))" | |
468 | AT_CHECK_UNQUOTED([ovs-vsctl-bashcomp.bash test "set Open_vSwitch "], | |
469 | [0], [dnl | |
470 | ${MATCH} | |
471 | ]) | |
472 | TMP="$(ovs-vsctl --no-heading --columns=_uuid,name list Bridge | tr -d '\"')" | |
473 | MATCH="$(PREPARE_MATCH_SPACE(${TMP}))" | |
474 | AT_CHECK_UNQUOTED([ovs-vsctl-bashcomp.bash test "set Bridge "], | |
475 | [0], [dnl | |
476 | ${MATCH} | |
477 | ]) | |
478 | ||
479 | ||
480 | # | |
481 | # test: _ovs_vsctl_complete_bridge | |
482 | # | |
483 | TMP="$(ovs-vsctl list-br)" | |
484 | MATCH="$(PREPARE_MATCH_SPACE(${TMP}))" | |
485 | AT_CHECK_UNQUOTED([ovs-vsctl-bashcomp.bash test "br-to-vlan "], | |
486 | [0], [dnl | |
487 | ${MATCH} | |
488 | ]) | |
489 | # this also helps check the '_ovs_vsctl_check_startswith_string'. | |
490 | MATCH="$(PREPARE_MATCH_SPACE(--weird-br_name))" | |
491 | AT_CHECK_UNQUOTED([ovs-vsctl-bashcomp.bash test "br-to-vlan --"], | |
492 | [0], [dnl | |
493 | ${MATCH} | |
494 | ]) | |
495 | ||
496 | ||
497 | # | |
498 | # test: _ovs_vsctl_complete_port | |
499 | # | |
500 | TMP="$(ovs-vsctl --no-heading --columns=name list Port | tr -d '\"')" | |
501 | MATCH="$(PREPARE_MATCH_SPACE(${TMP}))" | |
502 | AT_CHECK_UNQUOTED([ovs-vsctl-bashcomp.bash test "port-to-br "], | |
503 | [0], [dnl | |
504 | ${MATCH} | |
505 | ]) | |
506 | # complete on ports in particular bridge. | |
507 | TMP="$(ovs-vsctl list-ports br0)" | |
508 | MATCH="$(PREPARE_MATCH_SPACE(${TMP}))" | |
509 | AT_CHECK_UNQUOTED([ovs-vsctl-bashcomp.bash test "del-port br0 "], | |
510 | [0], [dnl | |
511 | ${MATCH} | |
512 | ]) | |
513 | ||
514 | ||
515 | # | |
516 | # test: _ovs_vsctl_complete_iface | |
517 | # | |
518 | for br in `ovs-vsctl list-br`; do | |
519 | TMP="${TMP} $(ovs-vsctl list-ifaces $br)" | |
520 | done | |
521 | MATCH="$(PREPARE_MATCH_SPACE(${TMP}))" | |
522 | AT_CHECK_UNQUOTED([ovs-vsctl-bashcomp.bash test "iface-to-br "], | |
523 | [0], [dnl | |
524 | ${MATCH} | |
525 | ]) | |
526 | ||
527 | ||
528 | # | |
529 | # test: _ovs_vsctl_complete_bridge_fail_mode | |
530 | # | |
531 | MATCH="$(PREPARE_MATCH_SPACE(standalone secure))" | |
532 | AT_CHECK_UNQUOTED([ovs-vsctl-bashcomp.bash test "set-fail-mode br0 "], | |
533 | [0], [dnl | |
534 | ${MATCH} | |
535 | ]) | |
536 | ||
537 | ||
538 | # | |
539 | # test: _ovs_vsctl_complete_key | |
540 | # | |
541 | AT_CHECK_UNQUOTED([ovs-vsctl-bashcomp.bash test "br-set-external-id br0 "], | |
542 | [0], [dnl | |
543 | ||
544 | ]) | |
545 | # since there is no key added yet, we will only get our own input. | |
546 | MATCH="$(PREPARE_MATCH_SPACE(test_key))" | |
547 | AT_CHECK_UNQUOTED([ovs-vsctl-bashcomp.bash test "br-set-external-id br0 test_key"], | |
548 | [0], [dnl | |
549 | ${MATCH} | |
550 | ]) | |
551 | # now add a key, as we should see it. | |
552 | ovs-vsctl br-set-external-id br0 bridge-id br0 | |
553 | MATCH="$(PREPARE_MATCH_SPACE(bridge-id))" | |
554 | AT_CHECK_UNQUOTED([ovs-vsctl-bashcomp.bash test "br-set-external-id br0 "], | |
555 | [0], [dnl | |
556 | ${MATCH} | |
557 | ]) | |
558 | MATCH="$(PREPARE_MATCH_SPACE(bridge-id --))" | |
559 | AT_CHECK_UNQUOTED([ovs-vsctl-bashcomp.bash test "br-get-external-id br0 "], | |
560 | [0], [dnl | |
561 | ${MATCH} | |
562 | ]) | |
563 | ||
564 | ||
565 | # | |
566 | # test: _ovs_vsctl_complete_value | |
567 | # | |
568 | # should just return the user input. | |
569 | MATCH="$(PREPARE_MATCH_SPACE(test_value --))" | |
570 | AT_CHECK_UNQUOTED([ovs-vsctl-bashcomp.bash test "br-set-external-id br0 bridge-id test_value"], | |
571 | [0], [dnl | |
572 | ${MATCH} | |
573 | ]) | |
574 | ||
575 | ||
576 | # | |
577 | # test: _ovs_vsctl_complete_column | |
578 | # | |
579 | TMP="$(ovsdb-client --no-heading list-columns Open_vSwitch Open_vSwitch | tr -d ':' | cut -d' ' -f1)" | |
580 | UUID="$(ovs-vsctl --no-heading --columns=_uuid list Open_vSwitch | tr -d ' ')" | |
581 | MATCH="$(PREPARE_MATCH_SPACE(${TMP}))" | |
582 | AT_CHECK_UNQUOTED([ovs-vsctl-bashcomp.bash test "clear Open_vSwitch $UUID "], | |
583 | [0], [dnl | |
584 | ${MATCH} | |
585 | ]) | |
586 | TMP="$(ovsdb-client --no-heading list-columns Open_vSwitch Bridge | tr -d ':' | cut -d' ' -f1)" | |
587 | MATCH="$(PREPARE_MATCH_SPACE(${TMP}))" | |
588 | AT_CHECK_UNQUOTED([ovs-vsctl-bashcomp.bash test "clear Bridge br0 "], | |
589 | [0], [dnl | |
590 | ${MATCH} | |
591 | ]) | |
592 | # the 'clear' command requires one or more (+) COLUMN. | |
593 | # so, with one specified COLUMN 'other_config', it should still complete on | |
594 | # COLUMNs, plus '--'. | |
595 | MATCH="$(PREPARE_MATCH_SPACE(${TMP} --))" | |
596 | AT_CHECK_UNQUOTED([ovs-vsctl-bashcomp.bash test "clear Bridge br0 other_config "], | |
597 | [0], [dnl | |
598 | ${MATCH} | |
599 | ]) | |
600 | ||
601 | ||
602 | # | |
603 | # test: _ovs_vsctl_complete_key_value | |
604 | # | |
605 | # with no key available, should always get user input. | |
606 | MATCH="$(PREPARE_MATCH_NOSPACE(random_key))" | |
607 | AT_CHECK_UNQUOTED([ovs-vsctl-bashcomp.bash test "add Bridge br0 other_config random_key"], | |
608 | [0], [dnl | |
609 | ${MATCH} | |
610 | ]) | |
611 | MATCH="$(PREPARE_MATCH_NOSPACE(random_key=abc))" | |
612 | AT_CHECK_UNQUOTED([ovs-vsctl-bashcomp.bash test "add Bridge br0 other_config random_key=abc"], | |
613 | [0], [dnl | |
614 | ${MATCH} | |
615 | ]) | |
616 | # now add two random keys. | |
617 | ovs-vsctl set Bridge br0 other_config:random_key1=abc other_config:random_val1=xyz | |
618 | MATCH="$(PREPARE_MATCH_NOSPACE(random_key1= random_val1=))" | |
619 | AT_CHECK_UNQUOTED([ovs-vsctl-bashcomp.bash test "add Bridge br0 other_config ran"], | |
620 | [0], [dnl | |
621 | ${MATCH} | |
622 | ]) | |
623 | ||
624 | ||
625 | # | |
626 | # test: _ovs_vsctl_complete_column_optkey_value | |
627 | # | |
628 | # at first, we should complete on column. | |
629 | TMP="$(ovsdb-client --no-heading list-columns Open_vSwitch Bridge | awk '/key.*value/ { print $1":"; next } { print $1; next }')" | |
630 | MATCH="$(PREPARE_MATCH_NOSPACE(${TMP}))" | |
631 | AT_CHECK_UNQUOTED([ovs-vsctl-bashcomp.bash test "set Bridge br0 "], | |
632 | [0], [dnl | |
633 | ${MATCH} | |
634 | ]) | |
635 | MATCH="$(PREPARE_MATCH_NOSPACE(other_config:))" | |
636 | AT_CHECK_UNQUOTED([ovs-vsctl-bashcomp.bash test "set Bridge br0 other"], | |
637 | [0], [dnl | |
638 | ${MATCH} | |
639 | ]) | |
640 | # then, with the ':' we should complete on key. | |
641 | TMP="$(ovs-vsctl --no-heading --columns=other_config list Bridge br0 | tr -d '{\"}' | tr -s ', ' '\n' | cut -d'=' -f1 | xargs printf "other_config:%s\n")" | |
642 | MATCH="$(PREPARE_MATCH_NOSPACE(${TMP}))" | |
643 | AT_CHECK_UNQUOTED([ovs-vsctl-bashcomp.bash test "set Bridge br0 other_config:"], | |
644 | [0], [dnl | |
645 | ${MATCH} | |
646 | ]) | |
647 | # finally, if user fill in some value, we should just complete on user input. | |
648 | MATCH="$(PREPARE_MATCH_NOSPACE(other_config:random_val1=12345))" | |
649 | AT_CHECK_UNQUOTED([ovs-vsctl-bashcomp.bash test "set Bridge br0 other_config:random_val1=12345"], | |
650 | [0], [dnl | |
651 | ${MATCH} | |
652 | ]) | |
653 | ||
654 | ||
655 | # | |
656 | # test: _ovs_vsctl_complete_filename | |
657 | # | |
658 | touch private_key certificate | |
659 | MATCH="$(PREPARE_MATCH_SPACE(private_key))" | |
660 | AT_CHECK_UNQUOTED([ovs-vsctl-bashcomp.bash test "set-ssl priva"], | |
661 | [0], [dnl | |
662 | ${MATCH} | |
663 | ]) | |
664 | MATCH="$(PREPARE_MATCH_SPACE(certificate))" | |
665 | AT_CHECK_UNQUOTED([ovs-vsctl-bashcomp.bash test "set-ssl private_key cer"], | |
666 | [0], [dnl | |
667 | ${MATCH} | |
668 | ]) | |
669 | ||
670 | ||
671 | # | |
672 | # test: _ovs_vsctl_complete_target | |
673 | # | |
674 | MATCH="$(PREPARE_MATCH_NOSPACE(pssl: ptcp: punix: ssl: tcp: unix:))" | |
675 | AT_CHECK_UNQUOTED([ovs-vsctl-bashcomp.bash test "set-manager "], | |
676 | [0], [dnl | |
677 | ${MATCH} | |
678 | ]) | |
679 | # filename completion on unix, punix. | |
680 | MATCH="$(PREPARE_MATCH_NOSPACE(unix:testsuite.log))" | |
681 | AT_CHECK_UNQUOTED([ovs-vsctl-bashcomp.bash test "set-manager unix:test"], | |
682 | [0], [dnl | |
683 | ${MATCH} | |
684 | ]) | |
685 | # no completion on other type, just return available types. | |
686 | # in real environment, bash will not complete on anything. | |
687 | MATCH="$(PREPARE_MATCH_NOSPACE(pssl: ptcp: punix: ssl: tcp: unix:))" | |
688 | AT_CHECK_UNQUOTED([ovs-vsctl-bashcomp.bash test "set-manager ssl:something"], | |
689 | [0], [dnl | |
690 | ${MATCH} | |
691 | ]) | |
692 | ||
693 | ||
694 | # | |
695 | # test: _ovs_vsctl_complete_new | |
696 | # | |
697 | # test 'add-br' | |
698 | AT_CHECK_UNQUOTED([ovs-vsctl-bashcomp.bash test "add-br "], | |
699 | [0], [dnl | |
700 | --- BEGIN MESSAGE | |
701 | Enter a new bridge: | |
702 | > ovs-vsctl add-br --- END MESSAGE | |
703 | ]) | |
704 | # user input does not change the output. | |
705 | AT_CHECK_UNQUOTED([ovs-vsctl-bashcomp.bash test "add-br new-br"], | |
706 | [0], [dnl | |
707 | --- BEGIN MESSAGE | |
708 | Enter a new bridge: | |
709 | > ovs-vsctl add-br new-br--- END MESSAGE | |
710 | ]) | |
711 | # after specifying the new bridge name, we should complete on parent bridge. | |
712 | TMP="$(ovs-vsctl list-br)" | |
713 | MATCH="$(PREPARE_MATCH_SPACE(${TMP}))" | |
714 | AT_CHECK_UNQUOTED([ovs-vsctl-bashcomp.bash test "add-br new-br "], | |
715 | [0], [dnl | |
716 | ${MATCH} | |
717 | ]) | |
718 | # test 'add-port' | |
719 | # after specifying the new port name, we should complete on the column part | |
720 | # of '*COLUMN?:KEY=VALUE'. | |
721 | TMP="$(ovsdb-client --no-heading list-columns Open_vSwitch Port | awk '/key.*value/ { print $1":"; next } { print $1; next }')" | |
722 | MATCH="$(PREPARE_MATCH_NOSPACE(${TMP} --))" | |
723 | AT_CHECK_UNQUOTED([ovs-vsctl-bashcomp.bash test "add-port br0 new-port "], | |
724 | [0], [dnl | |
725 | ${MATCH} | |
726 | ]) | |
727 | ||
728 | ||
729 | # | |
730 | # test: _ovs_vsctl_complete_dashdash | |
731 | # | |
732 | # after '--', there should be no global options available for completion. | |
733 | TMP="$(ovs-vsctl --commands | cut -d',' -f1-2 | tr -d ',[[]]' | tr -s ' ' '\n')" | |
734 | MATCH="$(PREPARE_MATCH_NOSPACE(${TMP}))" | |
735 | AT_CHECK_UNQUOTED([ovs-vsctl-bashcomp.bash test "init -- "], | |
736 | [0], [dnl | |
737 | ${MATCH} | |
738 | ]) | |
739 | TMP="$(ovs-vsctl --no-heading --columns=name,_uuid list Port | tr -d '\"')" | |
740 | MATCH="$(PREPARE_MATCH_SPACE(${TMP} newp1 newp2))" | |
741 | AT_CHECK_UNQUOTED([ovs-vsctl-bashcomp.bash test "add-port br0 newp1 -- add-port br1 newp2 -- set Port "], | |
742 | [0], [dnl | |
743 | ${MATCH} | |
744 | ]) | |
745 | ||
746 | OVS_VSWITCHD_STOP | |
747 | AT_CLEANUP | |
748 | ||
749 | ||
750 | AT_SETUP([vsctl-bashcomp - negative test]) | |
ce34e37f | 751 | AT_SKIP_IF([test -z ${BASH_VERSION+x} || test ${BASH_VERSINFO[[0]]} -lt 4]) |
557570fa AW |
752 | OVS_VSWITCHD_START |
753 | ||
754 | # complete non-matching command. | |
755 | AT_CHECK_UNQUOTED([ovs-vsctl-bashcomp.bash test "invalid"], | |
756 | [0], [dnl | |
757 | ||
758 | ]) | |
759 | ||
760 | # complete after invalid command. | |
761 | AT_CHECK_UNQUOTED([ovs-vsctl-bashcomp.bash test "invalid argu"], | |
762 | [0], [dnl | |
763 | ||
764 | ]) | |
765 | ||
766 | # complete non-matching end argument. | |
767 | AT_CHECK_UNQUOTED([ovs-vsctl-bashcomp.bash test "set INVALID_"], | |
768 | [0], [dnl | |
769 | ||
770 | ]) | |
771 | ||
772 | # complete after invalid intermediate argument. | |
773 | AT_CHECK_UNQUOTED([ovs-vsctl-bashcomp.bash test "set INVALID_TBL "], | |
774 | [1], [dnl | |
775 | --- BEGIN MESSAGE | |
776 | Cannot complete 'INVALID_TBL' at index 3: | |
777 | > ovs-vsctl set INVALID_TBL --- END MESSAGE]) | |
778 | ||
779 | # complete ovs-vsctl --db=wrongdb [TAB] | |
780 | # should return 1 and show nothing. | |
781 | AT_CHECK_UNQUOTED([ovs-vsctl-bashcomp.bash test "--db=wrongdb"], | |
782 | [1], []) | |
783 | ||
784 | OVS_VSWITCHD_STOP | |
785 | # delete ovsdb-server and try again. | |
786 | AT_CHECK_UNQUOTED([ovs-vsctl-bashcomp.bash test ""], | |
787 | [1], []) | |
788 | ||
08d42548 | 789 | AT_CLEANUP |