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 | fb6009d | 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" |
Yuta HIGUCHI | af0a4c2 | 2017-05-15 12:23:40 -0700 | [diff] [blame] | 26 | onos $target date |
| 27 | onos $target "onos:intents --filter $2" | tee $aux |
Claudine Chiu | b0d0ada | 2016-06-06 18:03:09 -0400 | [diff] [blame] | 28 | if [ -z "$numIntentsExpected" ]; then |
Ray Milkey | b40e945 | 2017-01-27 14:21:25 -0800 | [diff] [blame] | 29 | ( 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] | 30 | else |
Claudine Chiu | b0d0ada | 2016-06-06 18:03:09 -0400 | [diff] [blame] | 31 | # exit 0 only if expected number of intents (with required key) |
| 32 | # 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] | 33 | numIntents=`egrep "Key.*$2" $aux | wc -l` |
Claudine Chiu | b0d0ada | 2016-06-06 18:03:09 -0400 | [diff] [blame] | 34 | numIntentsOfState=0 |
Ray Milkey | b40e945 | 2017-01-27 14:21:25 -0800 | [diff] [blame] | 35 | [ $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] | 36 | [ $numIntents -eq $numIntentsOfState ] \ |
| 37 | && [ $numIntents -eq $numIntentsExpected ] \ |
| 38 | && cat $aux && exit 0 |
Ray Milkey | bb1ac3f | 2016-09-09 13:15:45 -0700 | [diff] [blame] | 39 | fi |
Yuta HIGUCHI | f76f6d5 | 2017-05-15 18:02:09 -0700 | [diff] [blame] | 40 | onos $target "onos:flows -s -n" |
Ray Milkey | bb1ac3f | 2016-09-09 13:15:45 -0700 | [diff] [blame] | 41 | sleep 2 |
Ray Milkey | c345663 | 2015-08-24 17:06:29 -0700 | [diff] [blame] | 42 | done |
| 43 | |
Yuta HIGUCHI | af0a4c2 | 2017-05-15 12:23:40 -0700 | [diff] [blame] | 44 | # failed. print informations |
| 45 | echo "Failed print information for debugging" |
Yuta HIGUCHI | f76f6d5 | 2017-05-15 18:02:09 -0700 | [diff] [blame] | 46 | onos $target date |
Yuta HIGUCHI | af0a4c2 | 2017-05-15 12:23:40 -0700 | [diff] [blame] | 47 | onos $target "onos:intents" |
| 48 | onos $target "onos:intent-details" |
| 49 | onos $target "onos:flows -s -n" |
| 50 | |
Ray Milkey | c345663 | 2015-08-24 17:06:29 -0700 | [diff] [blame] | 51 | cat $aux |
| 52 | exit 1 |