Ray Milkey | c345663 | 2015-08-24 17:06:29 -0700 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # ----------------------------------------------------------------------------- |
| 3 | # Checks that all intents in the system have a given state. |
| 4 | # ----------------------------------------------------------------------------- |
| 5 | |
| 6 | [ ! -d "$ONOS_ROOT" ] && echo "ONOS_ROOT is not defined" >&2 && exit 1 |
| 7 | . $ONOS_ROOT/tools/build/envDefaults |
| 8 | |
| 9 | aux=/tmp/stc-$$.log |
| 10 | trap "rm -f $aux 2>/dev/null" EXIT |
| 11 | target=${1:-$OCI} |
| 12 | |
Ray Milkey | bba7138 | 2015-08-26 13:09:23 -0700 | [diff] [blame] | 13 | echo onos-check-intent: $* |
| 14 | |
Ray Milkey | c345663 | 2015-08-24 17:06:29 -0700 | [diff] [blame] | 15 | set -x |
Claudine Chiu | b0d0ada | 2016-06-06 18:03:09 -0400 | [diff] [blame] | 16 | |
| 17 | # $1: target host |
| 18 | # $2: intent key |
| 19 | # $3: intent state |
| 20 | # $4: number of expected intents |
| 21 | re='^[0-9]+$' |
| 22 | [[ $4 =~ $re ]] && numIntentsExpected=$4 # silently ignore if not positive |
| 23 | |
Ray Milkey | 6e968e1 | 2015-09-18 09:55:07 -0700 | [diff] [blame] | 24 | for i in {1..15}; do |
Claudine Chiu | b0d0ada | 2016-06-06 18:03:09 -0400 | [diff] [blame] | 25 | echo "Attempt #$i" |
Thomas Vachuska | 1c15287 | 2015-08-26 18:41:10 -0700 | [diff] [blame] | 26 | onos $target "onos:intents" | tee $aux |
Claudine Chiu | b0d0ada | 2016-06-06 18:03:09 -0400 | [diff] [blame] | 27 | if [ -z "$numIntentsExpected" ]; then |
| 28 | ( cat $aux | grep "key=$2" | grep "state=$3" ) && cat $aux && exit 0 |
Ray Milkey | bb1ac3f | 2016-09-09 13:15:45 -0700 | [diff] [blame^] | 29 | else |
Claudine Chiu | b0d0ada | 2016-06-06 18:03:09 -0400 | [diff] [blame] | 30 | # exit 0 only if expected number of intents (with required key) |
| 31 | # are present and all intents match state (if expected no. of intents > 0) |
| 32 | numIntents=`grep "key=$2" $aux | wc -l` |
| 33 | numIntentsOfState=0 |
| 34 | [ $numIntentsExpected -gt 0 ] && numIntentsOfState=`grep "key=$2" $aux | grep "state=$3" | wc -l` |
| 35 | [ $numIntents -eq $numIntentsOfState ] \ |
| 36 | && [ $numIntents -eq $numIntentsExpected ] \ |
| 37 | && cat $aux && exit 0 |
Ray Milkey | bb1ac3f | 2016-09-09 13:15:45 -0700 | [diff] [blame^] | 38 | fi |
| 39 | sleep 2 |
Ray Milkey | c345663 | 2015-08-24 17:06:29 -0700 | [diff] [blame] | 40 | done |
| 41 | |
| 42 | cat $aux |
| 43 | exit 1 |
| 44 | |