VOL-4795 - Researching berlin-community-pod issues.

vars/volthaInfraDeploy.groovy
-----------------------------
   o Wrap call() in a try/catch/finally block for error visibility.
   o Added named function doKubeNamespaces() to capture logic.
   o Display namespace(s) prior to helm update, considering removal for clean install.
   o Problem may be related to special case behavor trying to update a new creation

vars/volthaStackDeploy.groovy
-----------------------------
   o Wrap call() in a try/catch/finally block for error visibility.

vars/waitForAdapter.groovy
--------------------------
   o Fix iam() method name
   o npm-groovy-lint cleanups

Change-Id: Ib9407b9cfefc40f411dbf9ab6e9e25adf9741a58
diff --git a/vars/volthaInfraDeploy.groovy b/vars/volthaInfraDeploy.groovy
index 189b562..e76a93a 100644
--- a/vars/volthaInfraDeploy.groovy
+++ b/vars/volthaInfraDeploy.groovy
@@ -1,5 +1,5 @@
 #!/usr/bin/env groovy
-
+// -----------------------------------------------------------------------
 // usage
 //
 // stage('test stage') {
@@ -9,12 +9,66 @@
 //     ])
 //   }
 // }
+// -----------------------------------------------------------------------
 
-def call(Map config) {
+// -----------------------------------------------------------------------
+// -----------------------------------------------------------------------
+def getIam(String func)
+{
+    // Cannot rely on a stack trace due to jenkins manipulation
+    String src = 'vars/volthaInfraDeploy.groovy'
+    String iam = [src, func].join('::')
+    return iam
+}
 
-    String iam = 'vars/volthaInfraDeploy.groovy'
+// -----------------------------------------------------------------------
+// Intent: Display and interact with kubernetes namespaces.
+// -----------------------------------------------------------------------
+def doKubeNamespaces()
+{
+    String iam = getIam('doKubeNamespaces')
     println("** ${iam}: ENTER")
-    
+
+    /*
+     [joey] - should pre-existing hint the env is tainted (?)
+     05:24:57  + kubectl create namespace infra
+     05:24:57  Error from server (AlreadyExists): namespaces "infra" already exists
+     05:24:57  error: failed to create configmap: configmaps "kube-config" already exists
+
+     [joey] Thinking we should:
+            o A special case exists  (create namespace)
+            o helm upgrade --install (inital update)
+     */
+
+    namespaces = sh(
+	script: 'kubectl get namespaces',
+	returnStdout: true
+    ).trim()
+    print(namespaces)
+
+    // Document prior to removal
+    namespaces.each{namespace ->
+	namespaces = sh("kubectl describe namespaces ${namespace}")
+    }
+
+    /*
+     // [TODO] Remove if safe op: clean state and avoids a special case.
+    namespaces.each{namespace ->
+	namespaces = sh("kubectl delete namespaces ${namespace}")
+    }
+     */
+
+    println("** ${iam}: LEAVE")    
+    return
+}
+
+// -----------------------------------------------------------------------
+// -----------------------------------------------------------------------
+def process(Map config)
+{
+    String iam = getIam('process')
+    println("** ${iam}: ENTER")
+
     // NOTE use params or directule extraHelmFlags??
     def defaultConfig = [
       onosReplica: 1,
@@ -30,10 +84,6 @@
       kubeconfig: null, // location of the kubernetes config file, if null we assume it's stored in the $KUBECONFIG environment variable
     ]
 
-    if (!config) {
-        config = [:]
-    }
-
     def cfg = defaultConfig + config
 
     def volthaInfraChart = "onf/voltha-infra"
@@ -55,12 +105,7 @@
       kubeconfig = env.KUBECONFIG
     }
 
-    /*
-     [joey] - should pre-existing hint the env is tainted (?)
-     05:24:57  + kubectl create namespace infra
-     05:24:57  Error from server (AlreadyExists): namespaces "infra" already exists
-     05:24:57  error: failed to create configmap: configmaps "kube-config" already exists
-     */
+    doKubeNamespaces() // WIP: joey
 
     sh """
     kubectl create namespace ${cfg.infraNamespace} || true
@@ -85,5 +130,34 @@
           -f $WORKSPACE/voltha-helm-charts/examples/${serviceConfigFile}-values.yaml ${cfg.extraHelmFlags}
     """
 
-    println("** ${iam}: LEAVE")    
+    return
 }
+
+// -----------------------------------------------------------------------
+// -----------------------------------------------------------------------
+def call(Map config)
+{
+    String iam = getIam('main')
+    println("** ${iam}: ENTER")
+
+    if (!config) {
+        config = [:]
+    }
+
+    try
+    {
+	process(config)
+    }
+    catch (Exception err)
+    {
+	println("** ${iam}: EXCEPTION ${err}")
+	throw err
+    }
+    finally
+    {
+	println("** ${iam}: LEAVE")
+    }
+    return
+}
+
+// [EOF]
diff --git a/vars/volthaStackDeploy.groovy b/vars/volthaStackDeploy.groovy
index eb6ab0b..5e511d0 100644
--- a/vars/volthaStackDeploy.groovy
+++ b/vars/volthaStackDeploy.groovy
@@ -1,10 +1,18 @@
 #!/usr/bin/env groovy
+// -----------------------------------------------------------------------
+// -----------------------------------------------------------------------
+def getIam(String func)
+{
+    // Cannot rely on a stack trace due to jenkins manipulation
+    String src = 'vars/volthaStackDeploy.groovy'
+    String iam = [src, func].join('::')
+    return iam
+}
 
-def call(Map config) {
-
-    String iam = 'vars/volthaStackDeploy.groovy'
-    println("** ${iam}: ENTER")
-
+// -----------------------------------------------------------------------
+// -----------------------------------------------------------------------
+def process(Map config)
+{
     // note that I can't define this outside the function as there's no global scope in Groovy
     def defaultConfig = [
       bbsimReplica: 1,
@@ -21,10 +29,6 @@
       adaptersToWait: 2,
     ]
 
-    if (!config) {
-        config = [:]
-    }
-
     def cfg = defaultConfig + config
 
     def volthaStackChart = "onf/voltha-stack"
@@ -126,5 +130,34 @@
         done
     """
 
-    println("** ${iam}: LEAVE")
+    return
 }
+
+// -----------------------------------------------------------------------
+// -----------------------------------------------------------------------
+def call(Map config)
+{
+    String iam = getIam('main')
+    println("** ${iam}: ENTER")
+
+    if (!config) {
+        config = [:]
+    }
+
+    try
+    {
+	process(config)
+    }
+    catch (Exception err)
+    {
+	println("** ${iam}: EXCEPTION ${err}")
+	throw err
+    }
+    finally
+    {
+	println("** ${iam}: LEAVE")
+    }
+    return
+}
+
+// [EOF]
diff --git a/vars/waitForAdapters.groovy b/vars/waitForAdapters.groovy
index ecd1f10..3c441da 100644
--- a/vars/waitForAdapters.groovy
+++ b/vars/waitForAdapters.groovy
@@ -6,6 +6,7 @@
 // -----------------------------------------------------------------------
 def getIam(String func)
 {
+    // Cannot rely on a stack trace due to jenkins manipulation
     String src = 'vars/waitForAdapters.groovy'
     String iam = [src, func].join('::')
     return iam
@@ -69,7 +70,9 @@
     {
 	String elapsed = adapters[i]
 	if (debug)
+	{
 	    println("** ${iam} Checking elapsed[$i]: $elapsed")
+	}
 
 	if (! elapsed) // empty string or null
 	{
@@ -127,7 +130,9 @@
     }
 
     if (debug)
+    {
 	println("** ${iam} return: [$ans]")
+    }
     return ans
 } // getAdaptersState
 
@@ -193,7 +198,9 @@
 	// ----------------------------------------------------------
 	countdown -= 1
 	if (1 > countdown)
+	{
 	    throw new Exception("ERROR: Timed out waiting on adapter startup")
+	}
     }
 
     println("** ${iam}: Tearing down port forwarding")
@@ -213,7 +220,7 @@
 // -----------------------------------------------------------------------
 def call(Map config)
 {
-    String iam = getIam('process')
+    String iam = getIam('main')
     println("** ${iam}: ENTER")
 
     if (!config) {