blob: 4b9270ee9b142f7d234ee4bf2956d3416fafde2b [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
4# to the passed one.
5# 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
7# after it the string of what the output should be.
8# Example:
9# onos-execute-expect 1.1.1.1 fooCommand fooParamenter --expect fooOutputString
10# -----------------------------------------------------------------------------
11
12[ ! -d "$ONOS_ROOT" ] && echo "ONOS_ROOT is not defined" >&2 && exit 1
13. $ONOS_ROOT/tools/build/envDefaults
14
15
Jon Halla67dc452017-02-15 16:01:17 -080016aux=/tmp/stc/stc-$$.log
andrea669ada42015-10-21 09:03:50 -070017trap "rm -f $aux 2>/dev/null" EXIT
18ip=$1
19cmd=""
20for a in ${*:2}; do shift; if [ "$a" = "--expect" ]; then break; fi; cmd="$cmd $a"; done
21expect="${@: -1}"
22onos $ip $cmd > $aux
23cat $aux
24grep -q $expect $aux && echo "expected value found" && exit 0
25exit 1
26
27