blob: 6e95a98c100d1f86d672cf19859814060f93c440 [file] [log] [blame]
Madan Jampani145623d2016-07-22 14:55:57 -07001#!/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 Hallfb6009d2017-02-15 16:01:17 -080015aux=/tmp/stc/stc-$$.log
Madan Jampani145623d2016-07-22 14:55:57 -070016trap "rm -f $aux 2>/dev/null" EXIT
17cmd=""
18for a in ${*:1}; do shift; if [ "$a" = "--expect" ]; then break; fi; cmd="$cmd $a"; done
19expect="${@: -1}"
20echo $cmd
Jon Hallfb6009d2017-02-15 16:01:17 -080021echo "expect ${expect}"
slowrb2335db2017-10-26 17:56:29 -070022nodes=`onos $OCI nodes | awk -F 'address=' '{print $2}' | cut -d':' -f1`
23while read -r line; do
24 node_var=$line
25 onos ${node_var} $cmd > $aux
Madan Jampani145623d2016-07-22 14:55:57 -070026 cat $aux
27 grep -q $expect $aux || exit 1
slowrb2335db2017-10-26 17:56:29 -070028done <<< "$nodes"
29
Madan Jampani145623d2016-07-22 14:55:57 -070030echo "expected value found"
31exit 0