Stc scenario for testing distributed primitives and onos-execute-expect command
Change-Id: Iac949099bf072b71aedd85dbc2ee8cf613b01807
diff --git a/tools/test/bin/onos-execute-expect b/tools/test/bin/onos-execute-expect
new file mode 100755
index 0000000..6ad9569
--- /dev/null
+++ b/tools/test/bin/onos-execute-expect
@@ -0,0 +1,27 @@
+#!/bin/bash
+# -----------------------------------------------------------------------------
+# Executes a command on the given ONOS instance and matches the output
+# to the passed one.
+# First argument is the IP address of the machine to run the command on,
+# then you pass the command and it's arguments if needed, then --expect and
+# after it the string of what the output should be.
+# Example:
+# onos-execute-expect 1.1.1.1 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
+ip=$1
+cmd=""
+for a in ${*:2}; do shift; if [ "$a" = "--expect" ]; then break; fi; cmd="$cmd $a"; done
+expect="${@: -1}"
+onos $ip $cmd > $aux
+cat $aux
+grep -q $expect $aux && echo "expected value found" && exit 0
+exit 1
+
+
diff --git a/tools/test/scenarios/dist-test-seq.xml b/tools/test/scenarios/dist-test-seq.xml
new file mode 100644
index 0000000..2e99fa2
--- /dev/null
+++ b/tools/test/scenarios/dist-test-seq.xml
@@ -0,0 +1,67 @@
+<!--
+ ~ Copyright 20${OCI}5 Open Networking Laboratory
+ ~
+ ~ Licensed under the Apache License, Version 2.0 (the "License");
+ ~ you may not use this file except in compliance with the License.
+ ~ You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ -->
+
+<scenario name="dist-test"
+ description="ONOS distributed primitives setup">
+ <group name="Distributed-Primitives">
+ <!--<import file="${ONOS_SCENARIOS}/prerequisites.xml"/>-->
+
+ <!--<import file="${ONOS_SCENARIOS}/setup.xml"/>
+ <dependency name="Setup" requires="Prerequisites"/>-->
+
+ <sequential var="${OC#}" starts="Distributed-App-${#}" ends="Check-Distributed-Exceptions-${#-1}">
+ <step name="Distributed-App-${#}"
+ requires="Setup"
+ exec="onos ${OC#} app activate org.onosproject.distributedprimitives"/>
+
+ <step name="Test-Counter-Increment-${#}"
+ requires="Distributed-App-${#}"
+ exec="onos-execute-expect ${OC#} counter-test-increment fooCounter 5 --expect updated"/>
+
+ <step name="Test-Add-${#}"
+ requires="Distributed-App-${#}"
+ exec="onos-execute-expect ${OC#} set-test-add fooSet foo --expect added"/>
+
+ <step name="Test-Get-${#}"
+ requires="Test-Add-${#}"
+ exec="onos-execute-expect ${OC#} set-test-get fooSet foo --expect contains"/>
+
+ <step name="Test-Remove-${#}"
+ requires="Test-Get-${#}"
+ exec="onos-execute-expect ${OC#} set-test-remove fooSet foo --expect removed"/>
+
+ <step name="Test-Add-Multiple-${#}"
+ requires="Test-Remove-${#}"
+ exec="onos-execute-expect ${OC#} set-test-add fooSet foo foo2 foo3 --expect added"/>
+
+ <step name="Test-Get-Multiple-${#}"
+ requires="Test-Add-Multiple-${#}"
+ exec="onos-execute-expect ${OC#} set-test-get fooSet foo foo2 foo3 --expect contains"/>
+
+ <step name="Test-Remove-Multiple-${#}"
+ requires="Test-Get-Multiple-${#}"
+ exec="onos-execute-expect ${OC#} set-test-remove fooSet foo foo2 foo3 --expect removed"/>
+
+ <step name="Sleep-${#}"
+ exec="sleep 2"
+ requires="Test-Remove-Multiple-${#}"/>
+ <!--Check with check logs-->
+ <step name="Check-Distributed-Exceptions-${#}"
+ exec="onos-check-logs ${OC#}"
+ requires="Sleep-${#}"/>
+ </sequential>
+ </group>
+</scenario>
\ No newline at end of file
diff --git a/tools/test/scenarios/dist-test.xml b/tools/test/scenarios/dist-test.xml
new file mode 100644
index 0000000..5e7dab0
--- /dev/null
+++ b/tools/test/scenarios/dist-test.xml
@@ -0,0 +1,70 @@
+<!--
+ ~ Copyright 2015 Open Networking Laboratory
+ ~
+ ~ Licensed under the Apache License, Version 2.0 (the "License");
+ ~ you may not use this file except in compliance with the License.
+ ~ You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+-->
+
+<scenario name="dist-test"
+ description="ONOS distributed primitives setup">
+ <group name="Distributed-Primitives">
+
+ <!--<import file="${ONOS_SCENARIOS}/setup.xml"/>
+ <dependency name="Setup" requires="Prerequisites"/>-->
+
+ <step name="Distributed-App"
+ requires="Setup"
+ exec="onos ${OCI} app activate org.onosproject.distributedprimitives"/>
+
+ <step name="Test-Counter-Increment"
+ requires="Distributed-App"
+ exec="onos-execute-expect ${OCI} counter-test-increment fooCounter 5 --expect updated"/>
+
+ <step name="Test-Add"
+ requires="Distributed-App"
+ exec="onos-execute-expect ${OCI} set-test-add fooSet foo --expect added"/>
+
+ <step name="Test-Get"
+ requires="Test-Add"
+ exec="onos-execute-expect ${OCI} set-test-get fooSet foo --expect contains"/>
+
+ <step name="Test-Remove"
+ requires="Test-Get"
+ exec="onos-execute-expect ${OCI} set-test-remove fooSet foo --expect removed"/>
+
+ <step name="Test-Add-Multiple"
+ requires="Test-Remove"
+ exec="onos-execute-expect ${OCI} set-test-add fooSet foo foo2 foo3 --expect added"/>
+
+ <step name="Test-Get-Multiple"
+ requires="Test-Add-Multiple"
+ exec="onos-execute-expect ${OCI} set-test-get fooSet foo foo2 foo3 --expect contains"/>
+
+ <step name="Test-Remove-Multiple"
+ requires="Test-Get-Multiple"
+ exec="onos-execute-expect ${OCI} set-test-remove fooSet foo foo2 foo3 --expect removed"/>
+
+ <step name="Test-Map-Put"
+ requires="Distributed-App"
+ exec="onos-execute-expect ${OCI} transactional-map-test-put 1 foo --expect Created"/>
+
+ <step name="Test-Map-Get"
+ requires="Test-Map-Put"
+ exec="onos-execute-expect ${OCI} transactional-map-test-get Key1 --expect Key-value"/>
+
+ <!--Check with check logs-->
+ <step name="Check-Distributed-Exceptions"
+ exec="onos-check-logs ${OCI}"
+ requires="Test-Map-Get"/>
+ </group>
+</scenario>
+