blob: 0754045dfbefeefc60b68cecc0960b5a57f2b61e [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}"
Madan Jampani145623d2016-07-22 14:55:57 -070022node_count=`onos $OC1 nodes | wc -l`
Jon Hallfb6009d2017-02-15 16:01:17 -080023# FIMXE: This only works if nodes are sequential
24# For dynamic clustering we could grab the IPs from 'nodes'
Madan Jampani145623d2016-07-22 14:55:57 -070025for 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
30done
31echo "expected value found"
32exit 0