blob: a53e639df1b9e5e5d225faee44466dd9f073e039 [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 Hallfb6009d2017-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"
Yuta HIGUCHIaf0a4c22017-05-15 12:23:40 -070026 onos $target date
27 onos $target "onos:intents --filter $2" | tee $aux
Claudine Chiub0d0ada2016-06-06 18:03:09 -040028 if [ -z "$numIntentsExpected" ]; then
Ray Milkeyb40e9452017-01-27 14:21:25 -080029 ( cat $aux | egrep "Key.*$2" && cat $aux | egrep "State.*$3" ) && cat $aux && exit 0
Ray Milkeybb1ac3f2016-09-09 13:15:45 -070030 else
Claudine Chiub0d0ada2016-06-06 18:03:09 -040031 # 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 Milkeyb40e9452017-01-27 14:21:25 -080033 numIntents=`egrep "Key.*$2" $aux | wc -l`
Claudine Chiub0d0ada2016-06-06 18:03:09 -040034 numIntentsOfState=0
Ray Milkeyb40e9452017-01-27 14:21:25 -080035 [ $numIntentsExpected -gt 0 ] && numIntentsOfState=`egrep "Key.*$2" $aux | egrep "State.*$3" | wc -l`
Claudine Chiub0d0ada2016-06-06 18:03:09 -040036 [ $numIntents -eq $numIntentsOfState ] \
37 && [ $numIntents -eq $numIntentsExpected ] \
38 && cat $aux && exit 0
Ray Milkeybb1ac3f2016-09-09 13:15:45 -070039 fi
40 sleep 2
Ray Milkeyc3456632015-08-24 17:06:29 -070041done
42
Yuta HIGUCHIaf0a4c22017-05-15 12:23:40 -070043# failed. print informations
44echo "Failed print information for debugging"
45onos $target "onos:intents"
46onos $target "onos:intent-details"
47onos $target "onos:flows -s -n"
48
Ray Milkeyc3456632015-08-24 17:06:29 -070049cat $aux
50exit 1