blob: 615bf5209bab14a614a90fd4c7f3d2b76e5c6c4e [file] [log] [blame]
Ray Milkeyc3456632015-08-24 17:06:29 -07001#!/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 Halla67dc452017-02-15 16:01:17 -08009aux=/tmp/stc/stc-$$.log
Ray Milkeyc3456632015-08-24 17:06:29 -070010trap "rm -f $aux 2>/dev/null" EXIT
11target=${1:-$OCI}
12
Ray Milkeybba71382015-08-26 13:09:23 -070013echo onos-check-intent: $*
14
Ray Milkeyc3456632015-08-24 17:06:29 -070015set -x
Claudine Chiub0d0ada2016-06-06 18:03:09 -040016
17# $1: target host
18# $2: intent key
19# $3: intent state
20# $4: number of expected intents
21re='^[0-9]+$'
22[[ $4 =~ $re ]] && numIntentsExpected=$4 # silently ignore if not positive
23
Ray Milkey6e968e12015-09-18 09:55:07 -070024for i in {1..15}; do
Claudine Chiub0d0ada2016-06-06 18:03:09 -040025 echo "Attempt #$i"
Thomas Vachuska1c152872015-08-26 18:41:10 -070026 onos $target "onos:intents" | tee $aux
Claudine Chiub0d0ada2016-06-06 18:03:09 -040027 if [ -z "$numIntentsExpected" ]; then
Ray Milkeyb40e9452017-01-27 14:21:25 -080028 ( cat $aux | egrep "Key.*$2" && cat $aux | egrep "State.*$3" ) && cat $aux && exit 0
Ray Milkeybb1ac3f2016-09-09 13:15:45 -070029 else
Claudine Chiub0d0ada2016-06-06 18:03:09 -040030 # 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 Milkeyb40e9452017-01-27 14:21:25 -080032 numIntents=`egrep "Key.*$2" $aux | wc -l`
Claudine Chiub0d0ada2016-06-06 18:03:09 -040033 numIntentsOfState=0
Ray Milkeyb40e9452017-01-27 14:21:25 -080034 [ $numIntentsExpected -gt 0 ] && numIntentsOfState=`egrep "Key.*$2" $aux | egrep "State.*$3" | wc -l`
Claudine Chiub0d0ada2016-06-06 18:03:09 -040035 [ $numIntents -eq $numIntentsOfState ] \
36 && [ $numIntents -eq $numIntentsExpected ] \
37 && cat $aux && exit 0
Ray Milkeybb1ac3f2016-09-09 13:15:45 -070038 fi
39 sleep 2
Ray Milkeyc3456632015-08-24 17:06:29 -070040done
41
42cat $aux
43exit 1
44