Added onos-cluster-execute-expect as a cluster version of onos-execute-expect + updated stc scenarios for dist primitives to use this for verification

Change-Id: Ife3bde21118ebd21e8abf807070a72ac58341120
diff --git a/tools/test/bin/onos-cluster-execute-expect b/tools/test/bin/onos-cluster-execute-expect
new file mode 100755
index 0000000..067320e
--- /dev/null
+++ b/tools/test/bin/onos-cluster-execute-expect
@@ -0,0 +1,30 @@
+#!/bin/bash
+# -----------------------------------------------------------------------------
+# Executes a command on all ONOS instances in a cluster and matches the output
+# from each instance to the passed one.
+# First argument is the command and it's arguments if needed, then --expect and
+# after it the string of what the output should be.
+# Example:
+# onos-cluster-execute-expect fooCommand fooParamenter --expect fooOutputString
+# -----------------------------------------------------------------------------
+
+[ ! -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
+cmd=""
+for a in ${*:1}; do shift; if [ "$a" = "--expect" ]; then break; fi; cmd="$cmd $a"; done
+expect="${@: -1}"
+echo $cmd
+echo $expect
+node_count=`onos $OC1 nodes | wc -l`
+for i in `seq 1 $node_count`; do
+    node_var="OC$i"
+    onos ${!node_var} $cmd > $aux
+    cat $aux
+    grep -q $expect $aux || exit 1
+done
+echo "expected value found"
+exit 0
diff --git a/tools/test/scenarios/dist-counter.xml b/tools/test/scenarios/dist-counter.xml
index aae33b5..83c2742 100644
--- a/tools/test/scenarios/dist-counter.xml
+++ b/tools/test/scenarios/dist-counter.xml
@@ -25,13 +25,13 @@
             exec="onos ${OCI} app activate org.onosproject.distributedprimitives"/>
 
         <step name="Test-Counter-Initial-Value" requires="^"
-              exec="onos-execute-expect ${OCI} counter-test test-counter get --expect 0"/>
+              exec="onos-cluster-execute-expect counter-test test-counter get --expect 0"/>
 
         <step name="Test-Counter-Set" requires="^"
               exec="onos ${OCI} counter-test test-counter set 1"/>
 
         <step name="Test-Counter-Get" requires="^"
-              exec="onos-execute-expect ${OCI} counter-test test-counter get --expect 1"/>
+              exec="onos-cluster-execute-expect counter-test test-counter get --expect 1"/>
 
         <step name="Test-Counter-IncrementAndGet" requires="^"
               exec="onos-execute-expect ${OCI} counter-test test-counter incrementAndGet --expect 2"/>
@@ -40,7 +40,7 @@
               exec="onos-execute-expect ${OCI} counter-test test-counter getAndIncrement --expect 2"/>
 
         <step name="Test-Counter-Incremented" requires="^"
-              exec="onos-execute-expect ${OCI} counter-test test-counter get --expect 3"/>
+              exec="onos-cluster-execute-expect counter-test test-counter get --expect 3"/>
 
         <step name="Test-Counter-AddAndGet" requires="^"
               exec="onos-execute-expect ${OCI} counter-test test-counter addAndGet 10 --expect 13"/>
@@ -49,19 +49,25 @@
               exec="onos-execute-expect ${OCI} counter-test test-counter getAndAdd 10 --expect 13"/>
 
         <step name="Test-Counter-Updated-After-GetAndAdd" requires="^"
-              exec="onos-execute-expect ${OCI} counter-test test-counter get --expect 23"/>
+              exec="onos-cluster-execute-expect counter-test test-counter get --expect 23"/>
 
         <step name="Test-Counter-CompareAndSet-False" requires="^"
               exec="onos-execute-expect ${OCI} counter-test test-counter compareAndSet 1 2 --expect false"/>
 
         <step name="Test-Counter-Not-Updated-After-CAS" requires="^"
-              exec="onos-execute-expect ${OCI} counter-test test-counter get --expect 23"/>
+              exec="onos-cluster-execute-expect counter-test test-counter get --expect 23"/>
 
         <step name="Test-Counter-CompareAndSet-True" requires="^"
               exec="onos-execute-expect ${OCI} counter-test test-counter compareAndSet 23 25 --expect true"/>
 
         <step name="Test-Counter-Updated-After-CAS" requires="^"
-              exec="onos-execute-expect ${OCI} counter-test test-counter get --expect 25"/>
+              exec="onos-cluster-execute-expect counter-test test-counter get --expect 25"/>
+
+        <step name="Test-Counter-Reset" requires="^"
+              exec="onos ${OCI} counter-test test-counter set 0"/>
+
+        <step name="Test-Counter-Get-After-Reset" requires="^"
+              exec="onos-cluster-execute-expect counter-test test-counter get --expect 0"/>
 
         <!--Check with check logs-->
         <step name="Check-Log-Exceptions" requires="^"
diff --git a/tools/test/scenarios/dist-leader.xml b/tools/test/scenarios/dist-leader.xml
index ec774af..3173721 100644
--- a/tools/test/scenarios/dist-leader.xml
+++ b/tools/test/scenarios/dist-leader.xml
@@ -25,7 +25,7 @@
             exec="onos ${OCI} app activate org.onosproject.distributedprimitives"/>
 
         <step name="Test-Initial-No-Leader" requires="^"
-              exec="onos-execute-expect ${OCI} leader-test test-elector show foo --expect leader=none#candidates=none"/>
+              exec="onos-cluster-execute-expect leader-test test-elector show foo --expect leader=none#candidates=none"/>
 
         <step name="Test-Leader-Run" requires="^"
               exec="onos-execute-expect ${OCI} leader-test test-elector run foo --expect leader=${OCI}#term=1#candidates=${OCI}"/>
@@ -34,7 +34,7 @@
               exec="onos ${OCI} leader-test test-elector withdraw foo"/>
 
         <step name="Test-No-Leader-After-Withdraw" requires="^"
-              exec="onos-execute-expect ${OCI} leader-test test-elector show foo --expect leader=none#candidates=none"/>
+              exec="onos-cluster-execute-expect leader-test test-elector show foo --expect leader=none#candidates=none"/>
 
         <!--Check with check logs-->
         <step name="Check-Log-Exceptions" requires="^"
diff --git a/tools/test/scenarios/dist-map.xml b/tools/test/scenarios/dist-map.xml
index 576aae0..a94b8bb 100644
--- a/tools/test/scenarios/dist-map.xml
+++ b/tools/test/scenarios/dist-map.xml
@@ -25,13 +25,13 @@
             exec="onos ${OCI} app activate org.onosproject.distributedprimitives"/>
 
         <step name="Test-Map-Get" requires="^"
-              exec="onos-execute-expect ${OCI} map-test foo get a --expect null"/>
+              exec="onos-cluster-execute-expect map-test foo get a --expect null"/>
 
         <step name="Test-Map-Put" requires="^"
               exec="onos-execute-expect ${OCI} map-test foo put a b --expect null"/>
 
         <step name="Test-Map-Updated-After-Put" requires="^"
-              exec="onos-execute-expect ${OCI} map-test foo get a --expect b"/>
+              exec="onos-cluster-execute-expect map-test foo get a --expect b"/>
 
         <step name="Test-Map-PutIfAbsent-When-Key-Present" requires="^"
               exec="onos-execute-expect ${OCI} map-test foo putIfAbsent a c --expect b"/>
@@ -40,7 +40,7 @@
               exec="onos-execute-expect ${OCI} map-test foo putIfAbsent b c --expect null"/>
 
         <step name="Test-Map-Updated-After-PutIfAbsent" requires="^"
-              exec="onos-execute-expect ${OCI} map-test foo get b --expect c"/>
+              exec="onos-cluster-execute-expect map-test foo get b --expect c"/>
 
         <step name="Test-Map-Updated-After-PutAndGet" requires="^"
               exec="onos-execute-expect ${OCI} map-test foo putAndGet b d --expect d"/>
@@ -58,16 +58,16 @@
               exec="onos-execute-expect ${OCI} map-test foo replace b e f --expect true"/>
 
         <step name="Test-Map-ContainsValue-False-Case" requires="^"
-              exec="onos-execute-expect ${OCI} map-test foo containsValue x --expect false"/>
+              exec="onos-cluster-execute-expect map-test foo containsValue x --expect false"/>
 
         <step name="Test-Map-ContainsValue-True-Case" requires="^"
-              exec="onos-execute-expect ${OCI} map-test foo containsValue f --expect true"/>
+              exec="onos-cluster-execute-expect map-test foo containsValue f --expect true"/>
 
         <step name="Test-Map-Size" requires="^"
-              exec="onos-execute-expect ${OCI} map-test foo size --expect 2"/>
+              exec="onos-cluster-execute-expect map-test foo size --expect 2"/>
 
         <step name="Test-Map-IsEmpty" requires="^"
-              exec="onos-execute-expect ${OCI} map-test foo isEmpty --expect false"/>
+              exec="onos-cluster-execute-expect map-test foo isEmpty --expect false"/>
 
         <step name="Test-Map-Remove" requires="^"
               exec="onos-execute-expect ${OCI} map-test foo remove b --expect f"/>
diff --git a/tools/test/scenarios/dist-test-seq.xml b/tools/test/scenarios/dist-test-seq.xml
index 97d0480..4b6a162 100644
--- a/tools/test/scenarios/dist-test-seq.xml
+++ b/tools/test/scenarios/dist-test-seq.xml
@@ -64,4 +64,4 @@
                   requires="Sleep-${#}"/>
         </sequential>
     </group>
-</scenario>
\ No newline at end of file
+</scenario>
diff --git a/tools/test/scenarios/dist-value.xml b/tools/test/scenarios/dist-value.xml
index f14eb9f..c49e171 100644
--- a/tools/test/scenarios/dist-value.xml
+++ b/tools/test/scenarios/dist-value.xml
@@ -25,25 +25,25 @@
             exec="onos ${OCI} app activate org.onosproject.distributedprimitives"/>
 
         <step name="Test-Value-Initial-Value" requires="^"
-              exec="onos-execute-expect ${OCI} value-test test-value get --expect null"/>
+              exec="onos-cluster-execute-expect value-test test-value get --expect null"/>
 
         <step name="Test-Value-Set" requires="^"
               exec="onos ${OCI} value-test test-value set v0"/>
 
         <step name="Test-Value-Get" requires="^"
-              exec="onos-execute-expect ${OCI} value-test test-value get --expect v0"/>
+              exec="onos-cluster-execute-expect value-test test-value get --expect v0"/>
 
         <step name="Test-Value-CompareAndSet-False" requires="^"
               exec="onos-execute-expect ${OCI} value-test test-value compareAndSet v1 v2 --expect false"/>
 
         <step name="Test-Value-Not-Updated-After-CAS" requires="^"
-              exec="onos-execute-expect ${OCI} value-test test-value get --expect v0"/>
+              exec="onos-cluster-execute-expect value-test test-value get --expect v0"/>
 
         <step name="Test-Value-CompareAndSet-True" requires="^"
               exec="onos-execute-expect ${OCI} value-test test-value compareAndSet v0 v1 --expect true"/>
 
         <step name="Test-Value-Updated-After-CAS" requires="^"
-              exec="onos-execute-expect ${OCI} value-test test-value get --expect v1"/>
+              exec="onos-cluster-execute-expect value-test test-value get --expect v1"/>
 
         <!--Check with check logs-->
         <step name="Check-Log-Exceptions" requires="^"