Move pgrep_proc and pkill_proc into vars/*.groovy for reuse

Change-Id: I78cc51448d8132207aa9c7db3cc3ee1381a62f02
diff --git a/jjb/pipeline/voltha/voltha-2.12/bbsim-tests.groovy b/jjb/pipeline/voltha/voltha-2.12/bbsim-tests.groovy
index f66b29d..1f82010 100644
--- a/jjb/pipeline/voltha/voltha-2.12/bbsim-tests.groovy
+++ b/jjb/pipeline/voltha/voltha-2.12/bbsim-tests.groovy
@@ -70,52 +70,6 @@
 // -----------------------------------------------------------------------
 // Intent:
 // -----------------------------------------------------------------------
-void pgrep_proc(String proc) {
-
-    println("** RAW PROCESS OUTPUT:")
-    def stream = sh(returnStdout: true, script: 'ps faaux')
-    println(stream)
-    
-    String cmd = [
-	'pgrep',
-	// '--older', 5, // switch not supported, nodes using older version
-	'--list-full',
-	"\"${proc}\"",
-	';',
-	'echo', 'DONE',
-	';',
-	'true',
-    ].join(' ')
-
-    println("** Running: ${cmd}")
-    sh(
-        returnStdout: true,
-	"set +euo pipefail && ${cmd}"
-    )
-    return
-}
-
-// -----------------------------------------------------------------------
-// -----------------------------------------------------------------------
-void pkill_proc(String proc) {
-    String cmd = [
-	'pkill',
-	// switch not supported, nodes using older version
-	// NOTE: pkill should not kill it-self
-	// good old kill (ps | grep -v -e grep -e '$$-me') }
-	// '--older', 5,
-	'--echo',
-	"\"${proc}\"",
-    ].join(' ')
-
-    println("** Running: ${cmd}")
-    sh(""" if [[ \$(pgrep --count "${proc}") -gt 0 ]]; then "$cmd"; fi" """)
-    return
-}
-
-// -----------------------------------------------------------------------
-// Intent:
-// -----------------------------------------------------------------------
 void execute_test(testTarget, workflow, testLogging, teardown, testSpecificHelmFlags='') {
     String infraNamespace  = 'default'
     String volthaNamespace = 'voltha'
diff --git a/jjb/pipeline/voltha/voltha-2.12/software-upgrades.groovy b/jjb/pipeline/voltha/voltha-2.12/software-upgrades.groovy
index 7cfa54b..d7427bb 100755
--- a/jjb/pipeline/voltha/voltha-2.12/software-upgrades.groovy
+++ b/jjb/pipeline/voltha/voltha-2.12/software-upgrades.groovy
@@ -144,7 +144,9 @@
       // Currently only testing with ATT workflow
       // TODO: Support for other workflows
       volthaDeploy([bbsimReplica: olts.toInteger(), workflow: 'att', extraHelmFlags: extraHelmFlags, localCharts: localCharts])
-      // stop logging
+
+        // [TODO] pkill_proc("_TAG=kail-${name}")
+        // stop logging
       sh """
         P_IDS="\$(ps e -ww -A | grep "_TAG=kail-${name}" | grep -v grep | awk '{print \$1}')"
         if [ -n "\$P_IDS" ]; then
@@ -231,11 +233,16 @@
         # Run the specified tests
         make -C $WORKSPACE/voltha-system-tests \$TARGET || true
       """
-      // remove port-forwarding
+
+        pkill_proc('port-forw')
+	    // remove port-forwarding
+	    /*
       sh """
         # 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
       """
+	     */
+
       // collect pod details
       get_pods_info("$WORKSPACE/${name}")
       sh """
@@ -307,37 +314,21 @@
     // -----------------------------------------------------------------------
     // -----------------------------------------------------------------------
     stage('Cleanup') {
-        steps {
-
-	script {
-            println('''
-** -----------------------------------------------------------------------
-** Raw process listing
-** -----------------------------------------------------------------------
-''')
-        sh(''' ps faaux ''')
-
-            println('''
-** -----------------------------------------------------------------------
-** pgrep --list-full port
-** -----------------------------------------------------------------------
-''')
-        sh(''' set +euo pipefail && pgrep --list-full 'port' ''')
-		}
-
-        // remove port-forwarding
-        sh """
-          # 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
-        """
-        helmTeardown(['infra', 'voltha'])
-      }
-    }
+        steps        {
+            script   {
+                pgrep_proc('port-forw')
+                pkill_proc('port-forw')
+            } // script
+            helmTeardown(['infra', 'voltha'])
+        } // steps
+    } // stage
+	
     stage('Create K8s Cluster') {
-      steps {
-        createKubernetesCluster([nodes: 3])
-      }
+        steps {
+            createKubernetesCluster([nodes: 3])
+        }
     }
+	
     stage('Run Test') {
       steps {
         test_software_upgrade("onos-app-upgrade")
@@ -371,3 +362,5 @@
     }
   }
 }
+
+// [EOF]