Madan Jampani | 145623d | 2016-07-22 14:55:57 -0700 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # ----------------------------------------------------------------------------- |
| 3 | # Executes a command on all ONOS instances in a cluster and matches the output |
| 4 | # from each instance to the passed one. |
| 5 | # First argument is the command and it's arguments if needed, then --expect and |
| 6 | # after it the string of what the output should be. |
| 7 | # Example: |
| 8 | # onos-cluster-execute-expect fooCommand fooParamenter --expect fooOutputString |
| 9 | # ----------------------------------------------------------------------------- |
| 10 | |
| 11 | [ ! -d "$ONOS_ROOT" ] && echo "ONOS_ROOT is not defined" >&2 && exit 1 |
| 12 | . $ONOS_ROOT/tools/build/envDefaults |
| 13 | |
| 14 | |
Jon Hall | fb6009d | 2017-02-15 16:01:17 -0800 | [diff] [blame] | 15 | aux=/tmp/stc/stc-$$.log |
Madan Jampani | 145623d | 2016-07-22 14:55:57 -0700 | [diff] [blame] | 16 | trap "rm -f $aux 2>/dev/null" EXIT |
| 17 | cmd="" |
| 18 | for a in ${*:1}; do shift; if [ "$a" = "--expect" ]; then break; fi; cmd="$cmd $a"; done |
| 19 | expect="${@: -1}" |
| 20 | echo $cmd |
Jon Hall | fb6009d | 2017-02-15 16:01:17 -0800 | [diff] [blame] | 21 | echo "expect ${expect}" |
slowr | b2335db | 2017-10-26 17:56:29 -0700 | [diff] [blame] | 22 | nodes=`onos $OCI nodes | awk -F 'address=' '{print $2}' | cut -d':' -f1` |
| 23 | while read -r line; do |
| 24 | node_var=$line |
| 25 | onos ${node_var} $cmd > $aux |
Madan Jampani | 145623d | 2016-07-22 14:55:57 -0700 | [diff] [blame] | 26 | cat $aux |
| 27 | grep -q $expect $aux || exit 1 |
slowr | b2335db | 2017-10-26 17:56:29 -0700 | [diff] [blame] | 28 | done <<< "$nodes" |
| 29 | |
Madan Jampani | 145623d | 2016-07-22 14:55:57 -0700 | [diff] [blame] | 30 | echo "expected value found" |
| 31 | exit 0 |