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