Removing ONOS before tearing down BBSim in the scale test

Change-Id: Ifbdad143680a5c7d503ab845906a66ccc828ca13
diff --git a/jjb/pipeline/voltha/master/voltha-scale-test.groovy b/jjb/pipeline/voltha/master/voltha-scale-test.groovy
index f0021c6..a7cb4ee 100644
--- a/jjb/pipeline/voltha/master/voltha-scale-test.groovy
+++ b/jjb/pipeline/voltha/master/voltha-scale-test.groovy
@@ -58,6 +58,23 @@
     stage ('Cleanup') {
       steps {
         timeout(time: 11, unit: 'MINUTES') {
+          sh returnStdout: false, script: '''
+          cd $WORKSPACE
+          rm -rf $WORKSPACE/*
+          '''
+          // removing the voltha-infra chart first
+          // if we don't ONOS might get stuck because of all the events when BBSim goes down
+          sh returnStdout: false, script: '''
+          set +x
+          helm del voltha-infra || true
+          echo -ne "\nWaiting for ONOS to be removed..."
+          onos=$(kubectl get pod -n default -l app=onos-classic --no-headers | wc -l)
+          while [[ $onos != 0 ]]; do
+            onos=$(kubectl get pod -n default -l app=onos-classic --no-headers | wc -l)
+            sleep 5
+            echo -ne "."
+          done
+          '''
           script {
             helmTeardown(["default"])
           }
@@ -75,9 +92,6 @@
 
             # remove orphaned port-forward from different namespaces
             ps aux | grep port-forw | grep -v grep | awk '{print $2}' | xargs --no-run-if-empty kill -9 || true
-
-            cd $WORKSPACE
-            rm -rf $WORKSPACE/*
           '''
         }
       }
diff --git a/jjb/pipeline/voltha/voltha-2.8/voltha-scale-test.groovy b/jjb/pipeline/voltha/voltha-2.8/voltha-scale-test.groovy
index 0f010c4..dc94736 100644
--- a/jjb/pipeline/voltha/voltha-2.8/voltha-scale-test.groovy
+++ b/jjb/pipeline/voltha/voltha-2.8/voltha-scale-test.groovy
@@ -61,6 +61,23 @@
     stage ('Cleanup') {
       steps {
         timeout(time: 11, unit: 'MINUTES') {
+          sh returnStdout: false, script: '''
+          cd $WORKSPACE
+          rm -rf $WORKSPACE/*
+          '''
+          // removing the voltha-infra chart first
+          // if we don't ONOS might get stuck because of all the events when BBSim goes down
+          sh returnStdout: false, script: '''
+          set +x
+          helm del voltha-infra || true
+          echo -ne "\nWaiting for ONOS to be removed..."
+          onos=$(kubectl get pod -n default -l app=onos-classic --no-headers | wc -l)
+          while [[ $onos != 0 ]]; do
+            onos=$(kubectl get pod -n default -l app=onos-classic --no-headers | wc -l)
+            sleep 5
+            echo -ne "."
+          done
+          '''
           script {
             helmTeardown(["default"])
           }
@@ -78,9 +95,6 @@
 
             # remove orphaned port-forward from different namespaces
             ps aux | grep port-forw | grep -v grep | awk '{print $2}' | xargs --no-run-if-empty kill -9 || true
-
-            cd $WORKSPACE
-            rm -rf $WORKSPACE/*
           '''
         }
       }