Committed by
Yuta Higuchi
Initial cut of `onos-group` script for running a subset of commands
against multiple ONOS instances: - onos-install - onos-push-keys - onos-kill - onos-patch-vm - onos-uninstall onos-group is simply a wrapper that does minimal sanity checks. New commands are added by adding them to the GOPTS list in ogroup-opts. Reference: ONOS-536 Change-Id: Ib3055491fec80e8759e87594e81a88285546deaf
Showing
3 changed files
with
109 additions
and
3 deletions
... | @@ -146,11 +146,13 @@ function vicell() { | ... | @@ -146,11 +146,13 @@ function vicell() { |
146 | printf "${cdf} : no such cell\n" && return 1 | 146 | printf "${cdf} : no such cell\n" && return 1 |
147 | fi | 147 | fi |
148 | 148 | ||
149 | - if [ -z "$EDITOR" ]; then | 149 | + if [ -z "${EDITOR}" ] || [ -x "$(which ${EDITOR})" ]; then |
150 | - vi ${cpath}${cdf} | 150 | + unset EDITOR && vi ${cpath}${cdf} |
151 | else | 151 | else |
152 | $EDITOR ${cpath}${cdf} | 152 | $EDITOR ${cpath}${cdf} |
153 | fi | 153 | fi |
154 | ($apply) && cell ${cdf} | 154 | ($apply) && cell ${cdf} |
155 | - | ||
156 | } | 155 | } |
156 | + | ||
157 | +# autocomplete for certain utilities | ||
158 | +. ${ONOS_ROOT}/tools/test/bin/ogroup-opts | ... | ... |
tools/test/bin/ogroup-opts
0 → 100644
1 | +# tab completion settings for onos-group. | ||
2 | + | ||
3 | +# options available to onos-group | ||
4 | +GOPTS='install kill patch-vm push-keys uninstall' | ||
5 | + | ||
6 | +function _ogroup-opts () { | ||
7 | + local cur=${COMP_WORDS[COMP_CWORD]} | ||
8 | + | ||
9 | + if [ $COMP_CWORD -eq 1 ]; then | ||
10 | + COMPREPLY=( $( compgen -W "$GOPTS help" -- $cur ) ) | ||
11 | + fi | ||
12 | +} | ||
13 | + | ||
14 | +complete -F _ogroup-opts onos-group |
tools/test/bin/onos-group
0 → 100755
1 | +#!/bin/bash | ||
2 | +# ----------------------------------------------------------------------------- | ||
3 | +# Allows a select group of commands to be sent to all ONOS instances in a cell. | ||
4 | +# ----------------------------------------------------------------------------- | ||
5 | + | ||
6 | +set -o pipefail | ||
7 | +IFS=$'\n' | ||
8 | + | ||
9 | +source ogroup-opts | ||
10 | + | ||
11 | +function err() { | ||
12 | + printf '%s: %s: %s\n' "$(basename $0)" "$1" "$2" >&2 | ||
13 | + usage >&2 | ||
14 | + exit 1 | ||
15 | +} | ||
16 | + | ||
17 | +function usage() { | ||
18 | +cat << EOF | ||
19 | + | ||
20 | +usage: $(basename $0) <help|[command]> | ||
21 | + | ||
22 | +Sends a command to all ONOS instances in the current cell. Currently supported | ||
23 | +commands are: $GOPTS | ||
24 | + | ||
25 | +options: | ||
26 | + [command] : A command to send to the instances. | ||
27 | + help : Displays this message and exits. | ||
28 | + | ||
29 | +notes: | ||
30 | + Hitting <TAB> will display the options for $(basename $0). | ||
31 | + | ||
32 | +EOF | ||
33 | +} | ||
34 | + | ||
35 | +# gets the utility name | ||
36 | +function getcmd() { | ||
37 | + # check that utility can be run in "batch-mode" | ||
38 | + local isgopt=false | ||
39 | + for c in $(printf '%s' "$GOPTS" | tr ' ' $'\n'); do | ||
40 | + [ "$c" = "$1" ] && isgopt=true && break | ||
41 | + done | ||
42 | + if $isgopt ; then | ||
43 | + printf 'onos-%s' "$1" | ||
44 | + else | ||
45 | + err 'unsupported command' "$1" | ||
46 | + fi | ||
47 | +} | ||
48 | + | ||
49 | +# early sanity check for instances/arguments | ||
50 | +[ -z "$1" ] && usage && exit 0 | ||
51 | + | ||
52 | +OCIS=( $(env | sed -ne 's:OC[0-9]=\(.*\):\1 :g p' | sort -k1) ) | ||
53 | +if [ -z "$OCIS" ]; then | ||
54 | + printf "no controller instances, quitting early" >&2 && exit 0 | ||
55 | +fi | ||
56 | + | ||
57 | +CMD_HELP=false | ||
58 | +while [ $# -gt 0 ]; do | ||
59 | + case "$1" in | ||
60 | + 'help') | ||
61 | + usage && exit 0 | ||
62 | + ;; | ||
63 | + '-'?) | ||
64 | + err 'invalid flag' "$1" && exit 1 | ||
65 | + ;; | ||
66 | + *) | ||
67 | + cmd=$(getcmd $1) || exit 1 | ||
68 | + shift | ||
69 | + # grab flags aimed at the utility being called. | ||
70 | + argv=( $@ ) | ||
71 | + args=() | ||
72 | + for i in "${!argv[@]}"; do | ||
73 | + # 'help' is a parameter for us; '-h' is for the command | ||
74 | + [ "${argv[$i]}" = 'help' ] && break | ||
75 | + [ "${argv[$i]}" = '-h' ] && CMD_HELP=true | ||
76 | + args[$i]="${argv[$i]}" | ||
77 | + shift | ||
78 | + done | ||
79 | + continue | ||
80 | + ;; | ||
81 | + esac | ||
82 | + shift | ||
83 | +done | ||
84 | + | ||
85 | +( $CMD_HELP ) && $cmd '-h' && exit 0 | ||
86 | + | ||
87 | +# TODO: verbose-mode and cleanup | ||
88 | +for i in ${OCIS[@]}; do | ||
89 | + ${cmd} $(echo ${args[@]}) "$i" 2>/dev/null & | ||
90 | +done |
-
Please register or login to post a comment