| # ----------------------------------------------------------------------------- |
| # 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 |
| trap "rm -f $aux 2>/dev/null" EXIT |
| echo onos-check-intent: $* |
| # $4: number of expected intents |
| [[ $4 =~ $re ]] && numIntentsExpected=$4 # silently ignore if not positive |
| onos $target "onos:intents" | tee $aux |
| if [ -z "$numIntentsExpected" ]; then |
| ( cat $aux | egrep "Key.*$2" && cat $aux | egrep "State.*$3" ) && cat $aux && exit 0 |
| # 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=`egrep "Key.*$2" $aux | wc -l` |
| [ $numIntentsExpected -gt 0 ] && numIntentsOfState=`egrep "Key.*$2" $aux | egrep "State.*$3" | wc -l` |
| [ $numIntents -eq $numIntentsOfState ] \ |
| && [ $numIntents -eq $numIntentsExpected ] \ |