blob: 041352259783a40f67f008535770b59c660ec16b [file] [log] [blame]
andrea669ada42015-10-21 09:03:50 -07001#!/bin/bash
2# -----------------------------------------------------------------------------
3# Executes a command on the given ONOS instance and matches the output
Dimitrios Mavrommatis30675ca2017-11-13 18:26:53 -08004# to the passed after X retries.
andrea669ada42015-10-21 09:03:50 -07005# First argument is the IP address of the machine to run the command on,
6# then you pass the command and it's arguments if needed, then --expect and
Dimitrios Mavrommatis30675ca2017-11-13 18:26:53 -08007# after it the string of what the output should be or --retry and the maximum
8# retries with 5 seconds delay between them
andrea669ada42015-10-21 09:03:50 -07009# Example:
Dimitrios Mavrommatis30675ca2017-11-13 18:26:53 -080010# onos-execute-expect 1.1.1.1 fooCommand fooParamenter --retry 5 --expect fooOutputString
andrea669ada42015-10-21 09:03:50 -070011# -----------------------------------------------------------------------------
12
13[ ! -d "$ONOS_ROOT" ] && echo "ONOS_ROOT is not defined" >&2 && exit 1
14. $ONOS_ROOT/tools/build/envDefaults
15
Jon Hallfb6009d2017-02-15 16:01:17 -080016aux=/tmp/stc/stc-$$.log
andrea669ada42015-10-21 09:03:50 -070017trap "rm -f $aux 2>/dev/null" EXIT
Dimitrios Mavrommatis30675ca2017-11-13 18:26:53 -080018
19retry=0
andrea669ada42015-10-21 09:03:50 -070020cmd=""
Dimitrios Mavrommatis30675ca2017-11-13 18:26:53 -080021expct=""
22
23for ((i=1; i<=$#; i++))
24do
25 if [ "${!i}" = "--expect" ]; then
26 next=$((i+1))
27 expct="${!next}"
28 i=$i+1
29 elif [ "${!i}" = "--retry" ]; then
30 next=$((i+1))
31 retry="${!next}"
32 i=$i+1
33 else
34 cmd="$cmd ${!i}";
35 fi
36done
37
38until [ $retry -eq -1 ]
39do
40 onos $cmd > $aux
41 cat $aux
42 grep -q $expct $aux && echo "expected value found" && exit 0
43 retry=$[$retry-1]
44 sleep 5
45done
andrea669ada42015-10-21 09:03:50 -070046exit 1