blob: 6e95a98c100d1f86d672cf19859814060f93c440 [file] [log] [blame]
#!/bin/bash
# -----------------------------------------------------------------------------
# Executes a command on all ONOS instances in a cluster and matches the output
# from each instance to the passed one.
# First argument is the command and it's arguments if needed, then --expect and
# after it the string of what the output should be.
# Example:
# onos-cluster-execute-expect fooCommand fooParamenter --expect fooOutputString
# -----------------------------------------------------------------------------
[ ! -d "$ONOS_ROOT" ] && echo "ONOS_ROOT is not defined" >&2 && exit 1
. $ONOS_ROOT/tools/build/envDefaults
aux=/tmp/stc/stc-$$.log
trap "rm -f $aux 2>/dev/null" EXIT
cmd=""
for a in ${*:1}; do shift; if [ "$a" = "--expect" ]; then break; fi; cmd="$cmd $a"; done
expect="${@: -1}"
echo $cmd
echo "expect ${expect}"
nodes=`onos $OCI nodes | awk -F 'address=' '{print $2}' | cut -d':' -f1`
while read -r line; do
node_var=$line
onos ${node_var} $cmd > $aux
cat $aux
grep -q $expect $aux || exit 1
done <<< "$nodes"
echo "expected value found"
exit 0