[VOL-5177] - verify_voltha-openolt-adapter_sanity-test failure

jjb/*
---------------------------------------------------------
  o Added function enter/leave for log mesage consistency
  o Update more sh """ calls to sh(label:foo, script:bar) for logfile context.
  o minor npm-groovy-lint cleanups to shorten the warning report.

vars/volthaDeploy.groovy
vars/volthaInfraDeploy.groovy
-----------------------------
  o re-indent buffer so npm-groovy-lint is usable.
  o Log more progression messages to help debugging.

Change-Id: I5824164dbb8f9c516691672219d6d7476212ccd1
diff --git a/jjb/pipeline/voltha/voltha-2.12/bbsim-tests.groovy b/jjb/pipeline/voltha/voltha-2.12/bbsim-tests.groovy
index 825db07..0adf32b 100644
--- a/jjb/pipeline/voltha/voltha-2.12/bbsim-tests.groovy
+++ b/jjb/pipeline/voltha/voltha-2.12/bbsim-tests.groovy
@@ -445,30 +445,29 @@
 void collectArtifacts(exitStatus) {
     script {
         String iam = getIam('collectArtifacts')
-        println("${iam}: ENTER (exitStatus=${exitStatus})")
-    }
+        enter("exitStatus=${exitStatus}")
 
-    echo '''
+        println("""
 
 ** -----------------------------------------------------------------------
+** IAM: $iam
 ** collectArtifacts
 ** -----------------------------------------------------------------------
-'''
+""")
+    }
 
     getPodsInfo("$WORKSPACE/${exitStatus}")
 
-    sh """
-  kubectl logs -n voltha -l app.kubernetes.io/part-of=voltha > $WORKSPACE/${exitStatus}/voltha.log
-  """
+    sh(label  : 'kubectl logs > voltha.log',
+       script : """
+kubectl logs -n voltha -l app.kubernetes.io/part-of=voltha \
+    > $WORKSPACE/${exitStatus}/voltha.log
+""")
 
     archiveArtifacts artifacts: '**/*.log,**/*.gz,**/*.txt,**/*.html,**/voltha-pods-mem-consumption-att/*,**/voltha-pods-mem-consumption-dt/*,**/voltha-pods-mem-consumption-tt/*'
 
     script {
-        println("${iam}: ENTER")
-        /*
-         pgrep_proc('kail-startup')
-         pkill_proc('kail')
-         */
+        enter('pkill _TAG=kail-startup')
         sh(label  : 'pgrep_proc - kill-pre',
            script : """
 pgrep --uid "\$(id -u)" --list-full --full 'kail-startup' || true
@@ -479,10 +478,10 @@
     pkill --uid "\$(id -u)" --echo --full 'kail'
 fi
 """)
-        println("${iam}: LEAVE")
+        leave('pkill _TAG=kail-startup')
     }
 
-    println("${iam}: ENTER RobotPublisher")
+    enter('RobotPublisher')
     step([$class: 'RobotPublisher',
           disableArchiveOutput: false,
           logFileName: '**/*/log*.html',
@@ -493,9 +492,9 @@
           reportFileName: '**/*/report*.html',
           unstableThreshold: 0,
           onlyCritical: true])
-    println("${iam}: LEAVE RobotPublisher")
+    leave('RobotPublisher')
 
-    println("${iam}: LEAVE (exitStatus=${exitStatus})")
+    leave("exitStatus=${exitStatus}")
     return
 }
 
@@ -701,15 +700,15 @@
     {
         aborted {
             collectArtifacts('aborted')
-            script{ cleanupPortForward() }
+            script { cleanupPortForward() }
         }
         failure {
             collectArtifacts('failed')
-            script{ cleanupPortForward() }
+            script { cleanupPortForward() }
         }
         always {
             collectArtifacts('always')
-            script{ cleanupPortForward() }
+            script { cleanupPortForward() }
         }
     }
 } // pipeline
diff --git a/vars/pkill_port_forward.groovy b/vars/pkill_port_forward.groovy
index d935701..286e341 100644
--- a/vars/pkill_port_forward.groovy
+++ b/vars/pkill_port_forward.groovy
@@ -123,11 +123,12 @@
     }
     catch (Exception err) {  // groovylint-disable-line CatchException
         ans = false
+        String iam = getIam(name)
         println("** ${iam}: EXCEPTION ${err}")
         throw err
     }
     finally {
-        enter('main')
+        leave('main')
     }
 
     return(ans)
diff --git a/vars/volthaDeploy.groovy b/vars/volthaDeploy.groovy
index 42c482a..a545da1 100644
--- a/vars/volthaDeploy.groovy
+++ b/vars/volthaDeploy.groovy
@@ -18,32 +18,64 @@
 // If you need to deploy different configurations you can use the volthaInfraDeploy and volthaStackDeploy keywords
 // -----------------------------------------------------------------------
 
+// -----------------------------------------------------------------------
+// -----------------------------------------------------------------------
+String getIam(String func) {
+    // Cannot rely on a stack trace due to jenkins manipulation
+    String src = 'vars/volthaDeploy.groovy'
+    String iam = [src, func].join('::')
+    return iam
+}
+
+// -----------------------------------------------------------------------
+// Intent: Log progress message
+// -----------------------------------------------------------------------
+void enter(String name) {
+    // Announce ourselves for log usability
+    String iam = getIam(name)
+    println("${iam}: ENTER")
+    return
+}
+
+// -----------------------------------------------------------------------
+// Intent: Log progress message
+// -----------------------------------------------------------------------
+void leave(String name) {
+    // Announce ourselves for log usability
+    String iam = getIam(name)
+    println("${iam}: LEAVE")
+    return
+}
+
+// -----------------------------------------------------------------------
+// Intent: Perform volthaDeploy stuff
+// -----------------------------------------------------------------------
 def call(Map config) {
 
-    String iam = 'vars/volthaDeploy.groovy'
-    println("** ${iam}: ENTER")
+    // String iam = 'vars/volthaDeploy.groovy'
+    enter('main')
 
     // note that I can't define this outside the function as there's no global scope in Groovy
     // [joey] A class method or library call can be used in place of globals, fqdn needed.
     def defaultConfig = [
-      onosReplica: 1,
-      atomixReplica: 1,
-      kafkaReplica: 1,
-      etcdReplica: 1,
-      bbsimReplica: 1,
-      infraNamespace: "infra",
-      volthaNamespace: "voltha",
-      stackName: "voltha",
-      stackId: 1,
-      workflow: "att",
-      withMacLearning: false,
-      withFttb: false,
-      extraHelmFlags: "",
-      localCharts: false, // wether to use locally cloned charts or upstream one (for local we assume they are stored in $WORKSPACE/voltha-helm-charts)
-      dockerRegistry: "", // use a different docker registry for all images, eg: "mirror.registry.opennetworking.org"
-      kubeconfig: null, // location of the kubernetes config file, if null we assume it's stored in the $KUBECONFIG environment variable
-      withVolthaInfra: true,
-      withVolthaStack: true,
+        onosReplica: 1,
+        atomixReplica: 1,
+        kafkaReplica: 1,
+        etcdReplica: 1,
+        bbsimReplica: 1,
+        infraNamespace: "infra",
+        volthaNamespace: "voltha",
+        stackName: "voltha",
+        stackId: 1,
+        workflow: "att",
+        withMacLearning: false,
+        withFttb: false,
+        extraHelmFlags: "",
+        localCharts: false, // wether to use locally cloned charts or upstream one (for local we assume they are stored in $WORKSPACE/voltha-helm-charts)
+        dockerRegistry: "", // use a different docker registry for all images, eg: "mirror.registry.opennetworking.org"
+        kubeconfig: null, // location of the kubernetes config file, if null we assume it's stored in the $KUBECONFIG environment variable
+        withVolthaInfra: true,
+        withVolthaStack: true,
     ]
 
     if (!config) {
@@ -53,37 +85,38 @@
     def cfg = defaultConfig + config
 
     if (cfg.dockerRegistry != "") {
-      def registryFlags = " --set global.image_registry=${cfg.dockerRegistry}/ "
-      registryFlags += " --set etcd.image.registry=${cfg.dockerRegistry} "
-      registryFlags += " --set kafka.image.registry=${cfg.dockerRegistry} "
-      registryFlags += " --set kafka.zookeper.image.registry=${cfg.dockerRegistry} "
-      registryFlags += " --set onos-classic.image.repository=${cfg.dockerRegistry}/voltha/voltha-onos "
-      registryFlags += " --set onos-classic.atomix.image.repository=${cfg.dockerRegistry}/atomix/atomix "
-      registryFlags += " --set freeradius.images.radius.registry=${cfg.dockerRegistry}/ "
+        def registryFlags = " --set global.image_registry=${cfg.dockerRegistry}/ "
+        registryFlags += " --set etcd.image.registry=${cfg.dockerRegistry} "
+        registryFlags += " --set kafka.image.registry=${cfg.dockerRegistry} "
+        registryFlags += " --set kafka.zookeper.image.registry=${cfg.dockerRegistry} "
+        registryFlags += " --set onos-classic.image.repository=${cfg.dockerRegistry}/voltha/voltha-onos "
+        registryFlags += " --set onos-classic.atomix.image.repository=${cfg.dockerRegistry}/atomix/atomix "
+        registryFlags += " --set freeradius.images.radius.registry=${cfg.dockerRegistry}/ "
 
-      // we want to always leave the user provided flags at the end, to override changes
-      cfg.extraHelmFlags = registryFlags + " " + cfg.extraHelmFlags
+        // we want to always leave the user provided flags at the end, to override changes
+        cfg.extraHelmFlags = registryFlags + " " + cfg.extraHelmFlags
     }
 
     // Add helm repositories
     println "Updating helm repos"
 
-    sh """
-      helm repo add onf https://charts.opencord.org
-      helm repo update
-    """
+    sh(label  : 'Configure helm repo',
+       script : """
+helm repo add onf https://charts.opencord.org
+helm repo update
+""")
 
     println "Deploying VOLTHA with the following parameters: ${cfg}."
 
     if (cfg.withVolthaInfra) {
-      volthaInfraDeploy(cfg)
+        volthaInfraDeploy(cfg)
     }
 
     if (cfg.withVolthaStack) {
-      volthaStackDeploy(cfg)
+        volthaStackDeploy(cfg)
     }
 
-    println("** ${iam}: LEAVE")
+    leave('main')
 }
 
 // [EOF]
diff --git a/vars/volthaInfraDeploy.groovy b/vars/volthaInfraDeploy.groovy
index c476fd5..db17b42 100644
--- a/vars/volthaInfraDeploy.groovy
+++ b/vars/volthaInfraDeploy.groovy
@@ -35,13 +35,33 @@
     return iam
 }
 
+
+// -----------------------------------------------------------------------
+// Intent: Log progress message
+// -----------------------------------------------------------------------
+void enter(String name) {
+    // Announce ourselves for log usability
+    String iam = getIam(name)
+    println("${iam}: ENTER")
+    return
+}
+
+// -----------------------------------------------------------------------
+// Intent: Log progress message
+// -----------------------------------------------------------------------
+void leave(String name) {
+    // Announce ourselves for log usability
+    String iam = getIam(name)
+    println("${iam}: LEAVE")
+    return
+}
+
 // -----------------------------------------------------------------------
 // Intent: Display and interact with kubernetes namespaces.
 // -----------------------------------------------------------------------
 def doKubeNamespaces()
 {
-    String iam = getIam('doKubeNamespaces')
-    println("** ${iam}: ENTER")
+    enter('doKubeNamespaces')
 
     /*
      [joey] - should pre-existing hint the env is tainted (?)
@@ -50,13 +70,13 @@
      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)
+     o A special case exists  (create namespace)
+     o helm upgrade --install (inital update)
      */
 
     sh('kubectl get namespaces || true')
 
-    println("** ${iam}: LEAVE")    
+    leave('doKubeNamespaces')
     return
 }
 
@@ -64,22 +84,21 @@
 // -----------------------------------------------------------------------
 def process(Map config)
 {
-    String iam = getIam('process')
-    println("** ${iam}: ENTER")
+    enter('process')
 
     // NOTE use params or directule extraHelmFlags??
     def defaultConfig = [
-      onosReplica: 1,
-      atomixReplica: 1,
-      kafkaReplica: 1,
-      etcdReplica: 1,
-      infraNamespace: "infra",
-      workflow: "att",
-      withMacLearning: false,
-      withFttb: false,
-      extraHelmFlags: "",
-      localCharts: false,
-      kubeconfig: null, // location of the kubernetes config file, if null we assume it's stored in the $KUBECONFIG environment variable
+        onosReplica: 1,
+        atomixReplica: 1,
+        kafkaReplica: 1,
+        etcdReplica: 1,
+        infraNamespace: "infra",
+        workflow: "att",
+        withMacLearning: false,
+        withFttb: false,
+        extraHelmFlags: "",
+        localCharts: false,
+        kubeconfig: null, // location of the kubernetes config file, if null we assume it's stored in the $KUBECONFIG environment variable
     ]
 
     def cfg = defaultConfig + config
@@ -87,47 +106,51 @@
     def volthaInfraChart = "onf/voltha-infra"
 
     if (cfg.localCharts) {
-      volthaInfraChart = "$WORKSPACE/voltha-helm-charts/voltha-infra"
+        volthaInfraChart = "$WORKSPACE/voltha-helm-charts/voltha-infra"
 
-      sh """
-      pushd $WORKSPACE/voltha-helm-charts/voltha-infra
-      helm dep update
-      popd
-      """
+        sh(label  : 'HELM: Update deps',
+           script : """
+pushd $WORKSPACE/voltha-helm-charts/voltha-infra
+helm dep update
+popd
+""")
     }
 
     println "Deploying VOLTHA Infra with the following parameters: ${cfg}."
 
     def kubeconfig = cfg.kubeconfig
     if (kubeconfig == null) {
-      kubeconfig = env.KUBECONFIG
+        kubeconfig = env.KUBECONFIG
     }
 
     doKubeNamespaces() // WIP: joey
 
-    sh """
-    kubectl create namespace ${cfg.infraNamespace} || true
-    kubectl create configmap -n ${cfg.infraNamespace} kube-config "--from-file=kube_config=${kubeconfig}"  || true
-    """
+    sh(label  : 'KUBE: Create namespace',
+       script : """
+kubectl create namespace ${cfg.infraNamespace} || true
+kubectl create configmap -n ${cfg.infraNamespace} kube-config "--from-file=kube_config=${kubeconfig}"  || true
+""")
 
     def serviceConfigFile = cfg.workflow
     if (cfg.withMacLearning && cfg.workflow == 'tt') {
-      serviceConfigFile = "tt-maclearner"
+        serviceConfigFile = "tt-maclearner"
     } else if (cfg.withFttb && cfg.workflow == 'dt') {
-      serviceConfigFile = "dt-fttb"
+        serviceConfigFile = "dt-fttb"
     }
 
     // bitnamic/etch has change the replica format between the currently used 5.4.2 and the latest 6.2.5
     // for now put both values in the extra helm chart flags
-    sh """
+    sh(label  : 'HELM: upgrade --install',
+       script : """
     helm upgrade --install --create-namespace -n ${cfg.infraNamespace} voltha-infra ${volthaInfraChart} \
           --set onos-classic.replicas=${cfg.onosReplica},onos-classic.atomix.replicas=${cfg.atomixReplica} \
           --set kafka.replicaCount=${cfg.kafkaReplica},kafka.zookeeper.replicaCount=${cfg.kafkaReplica} \
           --set etcd.statefulset.replicaCount=${cfg.etcdReplica} \
           --set etcd.replicaCount=${cfg.etcdReplica} \
           -f $WORKSPACE/voltha-helm-charts/examples/${serviceConfigFile}-values.yaml ${cfg.extraHelmFlags}
-    """
+""")
 
+    leave('process')
     return
 }
 
@@ -135,8 +158,7 @@
 // -----------------------------------------------------------------------
 def call(Map config)
 {
-    String iam = getIam('main')
-    println("** ${iam}: ENTER")
+    enter('main')
 
     if (!config) {
         config = [:]
@@ -144,18 +166,19 @@
 
     try
     {
-	process(config)
+	    process(config)
     }
     catch (Exception err)
     {
-	println("** ${iam}: EXCEPTION ${err}")
-	// Cannot re-throw ATM: too many potential shell errors.
-	// throw err
+        String iam = getIam(name)
+	    println("** ${iam}: EXCEPTION ${err}")
+	    throw err
     }
     finally
     {
-	println("** ${iam}: LEAVE")
+	    leave('main')
     }
+
     return
 }