STC changes to make smoke test more reliable

Change-Id: I8ecf2581b12e618bf3fe41baedf5c5decdd77221
diff --git a/tools/test/bin/onos-check-intent b/tools/test/bin/onos-check-intent
index e332dc5..760afaf 100755
--- a/tools/test/bin/onos-check-intent
+++ b/tools/test/bin/onos-check-intent
@@ -13,7 +13,7 @@
 echo onos-check-intent: $*
 
 set -x
-for i in {1..10}; do
+for i in {1..15}; do
     onos $target "onos:intents" | tee $aux
     ( cat $aux | grep "key=$2" | grep "state=$3" ) && cat $aux && exit 0
     sleep 1
diff --git a/tools/test/scenarios/bin/curl-with-retry b/tools/test/scenarios/bin/curl-with-retry
new file mode 100755
index 0000000..c9546ae
--- /dev/null
+++ b/tools/test/scenarios/bin/curl-with-retry
@@ -0,0 +1,23 @@
+#!/bin/bash
+
+aux=/tmp/stc-$$.log
+trap "rm -f $aux 2>/dev/null" EXIT
+
+url=$1
+
+
+echo curl-with-retry: $*
+
+set -x
+for i in {1..3}; do
+    curl -f -uonos:rocks ${url} >$aux
+    if [ $? = 0 ]; then
+        cat $aux
+        exit 0
+    fi
+    sleep 1
+done
+
+cat $aux
+exit 1
+
diff --git a/tools/test/scenarios/net-link-down-up.xml b/tools/test/scenarios/net-link-down-up.xml
index 8bcbfa7..eb4727b 100644
--- a/tools/test/scenarios/net-link-down-up.xml
+++ b/tools/test/scenarios/net-link-down-up.xml
@@ -20,7 +20,9 @@
               exec="onos-mininet sendAndExpect h1 ping -c1 h4 --expect \ 0% packet loss"/>
         <step name="Link-1-Down" requires="~Ping-1"
               exec="onos-mininet sendAndExpect link s4 s7 down --expect ."/>
-        <step name="Ping-2" requires="~Link-1-Down"
+        <step name="Ping-2-Prep" requires="~Link-1-Down"
+              exec="onos-mininet sendAndExpect h1 ping -c5 h4 --expect ."/>
+        <step name="Ping-2" requires="~Ping-2-Prep"
               exec="onos-mininet sendAndExpect h1 ping -c1 h4 --expect \ 0% packet loss"/>
         <step name="Link-2-Down" requires="~Ping-2"
               exec="onos-mininet sendAndExpect link s4 s5 down --expect ."/>
@@ -28,11 +30,15 @@
               exec="onos-mininet sendAndExpect h1 ping -c1 -w1 h4 --expect 100% packet loss"/>
         <step name="Link-1-Up" requires="~Ping-3"
               exec="onos-mininet sendAndExpect link s4 s7 up --expect ."/>
-        <step name="Ping-4" requires="~Link-1-Up"
+        <step name="Ping-4-Prep" requires="~Link-1-Up"
+              exec="onos-mininet sendAndExpect h1 ping -c5 h4 --expect ."/>
+        <step name="Ping-4" requires="~Ping-4-Prep"
               exec="onos-mininet sendAndExpect h1 ping -c1 h4 --expect \ 0% packet loss"/>
         <step name="Link-2-Up" requires="~Ping-4"
               exec="onos-mininet sendAndExpect link s4 s5 up --expect ."/>
-        <step name="Ping-5" requires="~Link-2-Up"
+        <step name="Ping-5-Prep" requires="~Link-2-Up"
+              exec="onos-mininet sendAndExpect h1 ping -c5 h4 --expect ."/>
+        <step name="Ping-5" requires="~Ping-5-Prep"
               exec="onos-mininet sendAndExpect h1 ping -c1 h4 --expect \ 0% packet loss"/>
     </group>
-</scenario>
\ No newline at end of file
+</scenario>
diff --git a/tools/test/scenarios/net-pingall.xml b/tools/test/scenarios/net-pingall.xml
index 8968e0d..87c1322 100644
--- a/tools/test/scenarios/net-pingall.xml
+++ b/tools/test/scenarios/net-pingall.xml
@@ -23,7 +23,7 @@
 
         <!-- TODO: take this out when initial pingall sweep is 100% -->
         <step name="Initial-Ping-All" requires="Check-Apps"
-              exec="onos-mininet sendAndExpect py net.pingAll(1) --expect 600 received"/>
+              exec="onos-mininet sendAndExpect py net.pingAll(1) --expect received"/>
 
         <step name="Ping-All-And-Verify" requires="Check-Apps,Initial-Ping-All"
               exec="onos-mininet sendAndExpect py net.pingAll(1) --expect 600/600 received"/>
@@ -34,4 +34,4 @@
         <step name="Config-Topo" requires="~Check-Summary-For-Hosts"
               exec="onos-topo-cfg ${OC1} ${ONOS_ROOT}/tools/test/topos/attmpls.json"/>
     </group>
-</scenario>
\ No newline at end of file
+</scenario>
diff --git a/tools/test/scenarios/net-rest.xml b/tools/test/scenarios/net-rest.xml
index fc7b1d0..ab7804d 100644
--- a/tools/test/scenarios/net-rest.xml
+++ b/tools/test/scenarios/net-rest.xml
@@ -101,10 +101,10 @@
         <!-- Check that the intents can be fetched via the REST API -->
         <step name="Net-REST.Validate-Intent-XY-Installed"
               requires="Net-REST.Create-Intent-YX"
-              exec="curl -f -uonos:rocks ${xyLocation}"/>
+              exec="curl-with-retry ${xyLocation}"/>
         <step name="Net-REST.Validate-Intent-YX-Installed"
               requires="^"
-              exec="curl -f -uonos:rocks ${yxLocation}"/>
+              exec="curl-with-retry ${yxLocation}"/>
 
         <!-- Use REST API to query flows created by the intents -->
         <step name="Net-REST.Validate-Intent-XY-Flow-Installed"
@@ -120,7 +120,7 @@
         <step name="Net-REST.Validate-YX-Flow-State" requires="^"
               exec="test '${dev4outFlowState}' == 'ADDED' -o '${dev4outFlowState}' == 'PENDING_ADD'"/>
         <step name="Net-REST.Validate-YX-Flow-Port" requires="^"
-              exec="test '${dev4outFlowPort}' == '3'"/>
+              exec="test ${dev4outFlowPort} -ge 1 -a ${dev4outFlowPort} -le 5"/>
 
         <!-- Check that connectivity was established -->
         <step name="Net-REST.Ping-XY" requires="Net-REST.Create-Intent-XY,Net-REST.Create-Intent-YX"
@@ -139,22 +139,23 @@
               exec="curl -f -X DELETE -uonos:rocks ${xyLocation}"/>
         <step name="Net-REST.Delete-Intent-YX" requires="^"
               exec="curl -f -X DELETE -uonos:rocks ${yxLocation}"/>
+        <step name="Net-REST.Allow-Intents-To-Purge"
+              exec="onos-check-intent ${OC1} xy INSTALLED" env="!"
+              requires="Net-REST.Delete-Intent-XY,Net-REST.Delete-Intent-YX"/>
 
         <!-- Use REST API to be sure that flows are no longer installed -->
-        <step name="Net-REST.Validate-XY-Flows-Removed" requires="Net-REST.Delete-Intent-XY"
+        <step name="Net-REST.Validate-XY-Flows-Removed" requires="Net-REST.Allow-Intents-To-Purge"
               exec="find-flow.py ${OC1} dev1out of:0000000000000001"
               env="!"/>
-        <step name="Net-REST.Validate-YX-Flows-Removed" requires="Net-REST.Delete-Intent-YX"
+        <step name="Net-REST.Validate-YX-Flows-Removed" requires="Net-REST.Allow-Intents-To-Purge"
               exec="find-flow.py ${OC1} dev4out of:0000000000000004"
               env="!"/>
 
         <!-- Check that the deleted intents no longer appear in the REST API -->
-        <step name="Net-REST.Allow-Intents-To-Purge" requires="Net-REST.Delete-Intent-XY"
-              exec="sleep 1"/>
         <step name="Net-REST.Validate-Intent-XY-Removed" requires="Net-REST.Allow-Intents-To-Purge"
-              exec="curl -f -uonos:rocks ${xyLocation}" env="!"/>
+              exec="curl-with-retry ${xyLocation}" env="!"/>
         <step name="Net-REST.Validate-Intent-YX-Removed" requires="Net-REST.Allow-Intents-To-Purge"
-              exec="curl -f -uonos:rocks ${yxLocation}" env="!"/>
+              exec="curl-with-retry ${yxLocation}" env="!"/>
 
     </group>
 </scenario>
diff --git a/tools/test/scenarios/net-smoke.xml b/tools/test/scenarios/net-smoke.xml
index 2aad758..91131c6 100644
--- a/tools/test/scenarios/net-smoke.xml
+++ b/tools/test/scenarios/net-smoke.xml
@@ -42,6 +42,7 @@
         <dependency name="Net-Teardown" requires="~Host-Intent-Connectivity,
                                                   ~P2P-Intent-Connectivity,
                                                   ~Net-REST,
-                                                  ~Net-Create-Flows"/>
+                                                  ~Net-Create-Flows,
+                                                  ~Net-topo"/>
     </group>
 </scenario>