blob: 067320e158be2f117ae055c3494a811ea4dd7688 [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
15aux=/tmp/stc-$$.log
16trap "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
21echo $expect
22node_count=`onos $OC1 nodes | wc -l`
23for i in `seq 1 $node_count`; do
24 node_var="OC$i"
25 onos ${!node_var} $cmd > $aux
26 cat $aux
27 grep -q $expect $aux || exit 1
28done
29echo "expected value found"
30exit 0