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}" |
Madan Jampani | 145623d | 2016-07-22 14:55:57 -0700 | [diff] [blame] | 22 | node_count=`onos $OC1 nodes | wc -l` |
Jon Hall | fb6009d | 2017-02-15 16:01:17 -0800 | [diff] [blame^] | 23 | # FIMXE: This only works if nodes are sequential |
| 24 | # For dynamic clustering we could grab the IPs from 'nodes' |
Madan Jampani | 145623d | 2016-07-22 14:55:57 -0700 | [diff] [blame] | 25 | for i in `seq 1 $node_count`; do |
| 26 | node_var="OC$i" |
| 27 | onos ${!node_var} $cmd > $aux |
| 28 | cat $aux |
| 29 | grep -q $expect $aux || exit 1 |
| 30 | done |
| 31 | echo "expected value found" |
| 32 | exit 0 |