onos-check-intent
1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/bin/bash
# -----------------------------------------------------------------------------
# Checks that all intents in the system have a given state.
# -----------------------------------------------------------------------------
[ ! -d "$ONOS_ROOT" ] && echo "ONOS_ROOT is not defined" >&2 && exit 1
. $ONOS_ROOT/tools/build/envDefaults
aux=/tmp/stc-$$.log
trap "rm -f $aux 2>/dev/null" EXIT
target=${1:-$OCI}
echo onos-check-intent: $*
set -x
# $1: target host
# $2: intent key
# $3: intent state
# $4: number of expected intents
re='^[0-9]+$'
[[ $4 =~ $re ]] && numIntentsExpected=$4 # silently ignore if not positive
for i in {1..15}; do
echo "Attempt #$i"
onos $target "onos:intents" | tee $aux
if [ -z "$numIntentsExpected" ]; then
( cat $aux | grep "key=$2" | grep "state=$3" ) && cat $aux && exit 0
else
# exit 0 only if expected number of intents (with required key)
# are present and all intents match state (if expected no. of intents > 0)
numIntents=`grep "key=$2" $aux | wc -l`
numIntentsOfState=0
[ $numIntentsExpected -gt 0 ] && numIntentsOfState=`grep "key=$2" $aux | grep "state=$3" | wc -l`
[ $numIntents -eq $numIntentsOfState ] \
&& [ $numIntents -eq $numIntentsExpected ] \
&& cat $aux && exit 0
fi
sleep 2
done
cat $aux
exit 1