andrea | 669ada4 | 2015-10-21 09:03:50 -0700 | [diff] [blame] | 1 | #!/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 Hall | fb6009d | 2017-02-15 16:01:17 -0800 | [diff] [blame] | 16 | aux=/tmp/stc/stc-$$.log |
andrea | 669ada4 | 2015-10-21 09:03:50 -0700 | [diff] [blame] | 17 | trap "rm -f $aux 2>/dev/null" EXIT |
| 18 | ip=$1 |
| 19 | cmd="" |
| 20 | for a in ${*:2}; do shift; if [ "$a" = "--expect" ]; then break; fi; cmd="$cmd $a"; done |
| 21 | expect="${@: -1}" |
| 22 | onos $ip $cmd > $aux |
| 23 | cat $aux |
| 24 | grep -q $expect $aux && echo "expected value found" && exit 0 |
| 25 | exit 1 |
| 26 | |
| 27 | |