blob: 37558ccb6071ffd922c8845f46a55811709145f0 [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
9aux=/tmp/stc-$$.log
10trap "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
28 ( cat $aux | grep "key=$2" | grep "state=$3" ) && cat $aux && exit 0
29 else
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
38 fi
Ray Milkeyc3456632015-08-24 17:06:29 -070039 sleep 1
40done
41
42cat $aux
43exit 1
44