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 | |
Jon Hall | a67dc45 | 2017-02-15 16:01:17 -0800 | [diff] [blame] | 9 | aux=/tmp/stc/stc-$$.log |
Ray Milkey | c345663 | 2015-08-24 17:06:29 -0700 | [diff] [blame] | 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 |
Ray Milkey | b40e945 | 2017-01-27 14:21:25 -0800 | [diff] [blame] | 28 | ( cat $aux | egrep "Key.*$2" && cat $aux | egrep "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) |
Ray Milkey | b40e945 | 2017-01-27 14:21:25 -0800 | [diff] [blame] | 32 | numIntents=`egrep "Key.*$2" $aux | wc -l` |
Claudine Chiu | b0d0ada | 2016-06-06 18:03:09 -0400 | [diff] [blame] | 33 | numIntentsOfState=0 |
Ray Milkey | b40e945 | 2017-01-27 14:21:25 -0800 | [diff] [blame] | 34 | [ $numIntentsExpected -gt 0 ] && numIntentsOfState=`egrep "Key.*$2" $aux | egrep "State.*$3" | wc -l` |
Claudine Chiu | b0d0ada | 2016-06-06 18:03:09 -0400 | [diff] [blame] | 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 | |