Debug silent exception source.

jjb/pipeline/voltha/bbsim-tests.grooy
-------------------------------------
  o Wrap function calls with enter()/leave() pairs to show progress.

vars/getVolthaCode.groovy
-------------------------
  o Apply automatic editor formatting, indentation jumbled at some point.
  o Added debug functions enter() & leave().
  o Wrap checkouts / function calls with enter()/leave() pairs to
    log script progress.

Change-Id: I7816583072403d20c7c89b119f84835f886a9bdb
diff --git a/vars/getVolthaCode.groovy b/vars/getVolthaCode.groovy
index fc4c722..a6a40fb 100644
--- a/vars/getVolthaCode.groovy
+++ b/vars/getVolthaCode.groovy
@@ -1,6 +1,6 @@
 #!/usr/bin/env groovy
 // -----------------------------------------------------------------------
-// Copyright 2021-2023 Open Networking Foundation (ONF) and the ONF Contributors
+// Copyright 2021-2024 Open Networking Foundation (ONF) and the ONF Contributors
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
@@ -24,125 +24,176 @@
     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
+}
+
 // TODO the 3 stages are very similar, most of the code can be shared
 
+// -----------------------------------------------------------------------
+// -----------------------------------------------------------------------
 def wrapped(Map config)
 {
     def defaultConfig = [
-	branch: "master",
-	gerritProject: "",
-	gerritRefspec: "",
-	volthaSystemTestsChange: "",
-	volthaHelmChartsChange: "",
+        branch: "master",
+        gerritProject: "",
+        gerritRefspec: "",
+        volthaSystemTestsChange: "",
+        volthaHelmChartsChange: "",
     ]
-    
+
     def cfg = defaultConfig + config
 
-    println "Downloading VOLTHA code with the following parameters: ${cfg}."
+    println("""
+
+** -----------------------------------------------------------------------
+** Downloading VOLTHA code with the following parameters:
+**   ${cfg}
+** -----------------------------------------------------------------------
+""")
 
     stage('Download Patch')
     {
-	frequent_repos = [
-	    '',
-	    'voltha-system-tests',
-	    'voltha-helm-charts',
-	]
+        frequent_repos = [
+            '',
+            'voltha-system-tests',
+            'voltha-helm-charts',
+        ]
 
-	// We are always downloading those repos, if the patch under test is in one of those
-	// just checkout the patch, no need to clone it again
-	if (cfg.gerritProject == '')
-	{
-	    // Revisit:
-	    // gerritProject should be defined.  Ignore when empty was likely
-	    // added to support manually re-running a job when repo values
-	    // may not be defined.
-	    // Unfortunately the conditional can also inadvertently bypass
-	    // checkout during an error condition.
-	    // Case: when cfg= is invalid due to a jenkins hiccup.
-	}
-	else if (!(cfg.gerritProject in frequent_repos))
-	{
-	    repo_project = "https://gerrit.opencord.org/${cfg.gerritProject}"
-		
-	    checkout([
-		$class: 'GitSCM',
-		userRemoteConfigs: [[ url:repo_project ]],
-		branches: [[ name: "${cfg.branch}", ]],
-		extensions: [
-		    [$class: 'WipeWorkspace'],
-		    [$class: 'RelativeTargetDirectory', relativeTargetDir: "${cfg.gerritProject}"],
-		    [$class: 'CloneOption', depth: 0, noTags: false, reference: '', shallow: false],
-		],
-	    ])
+        // We are always downloading those repos, if the patch under test is in one of those
+        // just checkout the patch, no need to clone it again
+        if (cfg.gerritProject == '')
+        {
+            // Revisit:
+            // gerritProject should be defined.  Ignore when empty was likely
+            // added to support manually re-running a job when repo values
+            // may not be defined.
+            // Unfortunately the conditional can also inadvertently bypass
+            // checkout during an error condition.
+            // Case: when cfg= is invalid due to a jenkins hiccup.
+        }
+        else if (!(cfg.gerritProject in frequent_repos))
+        {
+            repo_project = "https://gerrit.opencord.org/${cfg.gerritProject}"
 
-	    sh """
+            checkout([
+                $class: 'GitSCM',
+                userRemoteConfigs: [[ url:repo_project ]],
+                branches: [[ name: "${cfg.branch}", ]],
+                extensions: [
+                    [$class: 'WipeWorkspace'],
+                    [$class: 'RelativeTargetDirectory', relativeTargetDir: "${cfg.gerritProject}"],
+                    [$class: 'CloneOption', depth: 0, noTags: false, reference: '', shallow: false],
+                ],
+            ])
+
+            sh("""
         pushd $WORKSPACE/${cfg.gerritProject}
         git fetch "$repo_project" ${cfg.gerritRefspec} && git checkout FETCH_HEAD
 
         echo "Currently on commit: \n"
         git log -1 --oneline
         popd
-      """
-	}
+      """)
+        }
     }
 
+    // -----------------------------------------------------------------------
+    // -----------------------------------------------------------------------
     stage('Clone voltha-system-tests')
-    {	
-	repo_vst = 'https://gerrit.opencord.org/voltha-system-tests'
+    {
+        enter('Clone voltha-system-tests')
+        println("""
 
-	checkout([
-	    $class: 'GitSCM',
-	    userRemoteConfigs: [[ url:repo_vst ]],
-	    branches: [[ name: "${cfg.branch}", ]],
-	    extensions: [
-		[$class: 'WipeWorkspace'],
-		[$class: 'RelativeTargetDirectory', relativeTargetDir: "voltha-system-tests"],
-		[$class: 'CloneOption', depth: 0, noTags: false, reference: '', shallow: false],
-	    ],
-	])
+** -----------------------------------------------------------------------
+** Clone voltha-system-tests
+** -----------------------------------------------------------------------
+""")
+        repo_vst = 'https://gerrit.opencord.org/voltha-system-tests'
 
-	if (cfg.volthaSystemTestsChange != '' && cfg.gerritProject != 'voltha-system-tests')
-	{
-	    sh """
+        checkout([
+            $class: 'GitSCM',
+            userRemoteConfigs: [[ url:repo_vst ]],
+            branches: [[ name: "${cfg.branch}", ]],
+            extensions: [
+                [$class: 'WipeWorkspace'],
+                [$class: 'RelativeTargetDirectory', relativeTargetDir: "voltha-system-tests"],
+                [$class: 'CloneOption', depth: 0, noTags: false, reference: '', shallow: false],
+            ],
+        ])
+
+        if (cfg.volthaSystemTestsChange != '' && cfg.gerritProject != 'voltha-system-tests')
+            {
+            enter("git fetch repo_vst=[${repo_vst}]")
+
+            sh """
         cd "$WORKSPACE/voltha-system-tests"
         git fetch "${repo_vst}" ${cfg.volthaSystemTestsChange} && git checkout FETCH_HEAD
       """
-	}
-	else if (cfg.gerritProject == 'voltha-system-tests') {
-	    sh """
+            leave("git fetch repo_vst=[${repo_vst}]")
+        }
+        else if (cfg.gerritProject == 'voltha-system-tests') {
+            enter("git fetch https://${cfg.gerritProject}")
+
+            sh("""
         pushd "$WORKSPACE/${cfg.gerritProject}"
         git fetch https://gerrit.opencord.org/${cfg.gerritProject} ${cfg.gerritRefspec} && git checkout FETCH_HEAD
 
         echo "Currently on commit: \n"
         git log -1 --oneline
         popd
-      """
-	}
+      """)
+            leave("git fetch https://${cfg.gerritProject}")
+        }
+
+        leave('Clone voltha-system-tests')
     }
 
+    // -----------------------------------------------------------------------
+    // -----------------------------------------------------------------------
     stage('Clone voltha-helm-charts')
     {
-	repo_vhc = 'https://gerrit.opencord.org/voltha-helm-charts'
+        enter('Clone voltha-helm-charts')
+        repo_vhc = 'https://gerrit.opencord.org/voltha-helm-charts'
 
-	checkout([
-	    $class: 'GitSCM',
-	    userRemoteConfigs: [[ url:repo_vhc ]],
-	    branches: [[ name: "${cfg.branch}", ]],
-	    extensions: [
-		[$class: 'WipeWorkspace'],
-		[$class: 'RelativeTargetDirectory', relativeTargetDir: "voltha-helm-charts"],
-		[$class: 'CloneOption', depth: 0, noTags: false, reference: '', shallow: false],
-	    ],
-	])
+        checkout([
+            $class: 'GitSCM',
+            userRemoteConfigs: [[ url:repo_vhc ]],
+            branches: [[ name: "${cfg.branch}", ]],
+            extensions: [
+                [$class: 'WipeWorkspace'],
+                [$class: 'RelativeTargetDirectory', relativeTargetDir: "voltha-helm-charts"],
+                [$class: 'CloneOption', depth: 0, noTags: false, reference: '', shallow: false],
+            ],
+        ])
 
-	if (cfg.volthaHelmChartsChange != '' && cfg.gerritProject != 'voltha-helm-charts') {
-	    sh """
+        if (cfg.volthaHelmChartsChange != '' && cfg.gerritProject != 'voltha-helm-charts') {
+            enter("git fetch repo_vhc=[$repo_vhc]")
+            sh """
         cd "$WORKSPACE/voltha-helm-charts"
         git fetch "$repo_vhc" ${cfg.volthaHelmChartsChange} && git checkout FETCH_HEAD
-      """
-	}
-	else if (cfg.gerritProject == 'voltha-helm-charts') {
-	    sh """
+      """ 
+            leave("git fetch repo_vhc=[$repo_vhc]")
+        }
+        else if (cfg.gerritProject == 'voltha-helm-charts') {
+            enter('cfg.gerritProject == voltha-helm-charts')
+            sh """
         pushd "$WORKSPACE/${cfg.gerritProject}"
         git fetch "https://gerrit.opencord.org/${cfg.gerritProject}" ${cfg.gerritRefspec} && git checkout FETCH_HEAD
 
@@ -150,7 +201,10 @@
         git log -1 --oneline
         popd
       """
-	}
+            leave('cfg.gerritProject == voltha-helm-charts')
+        }
+
+        leave('Clone voltha-helm-charts')
     }
 }
 
@@ -159,32 +213,29 @@
 def call(Map config)
 {
     String iam = getIam('main')
-    Boolean debug = false
+    Boolean debug = true
 
-    if (debug)
-    {
-	println("** ${iam}: ENTER")
+    if (debug) {
+        println("** ${iam}: ENTER")
     }
 
-    if (!config) {
-        config = [:]
-    }
+    config ?: [:]
 
     try
     {
-	wrapped(config)
+        wrapped(config)
     }
     catch (Exception err)
     {
-	println("** ${iam}: EXCEPTION ${err}")
-	throw err
+        println("** ${iam}: EXCEPTION ${err}")
+        throw err
     }
     finally
     {
-	if (debug)
-	{
-	    println("** ${iam}: LEAVE")
-	}
+        if (debug)
+            {
+            println("** ${iam}: LEAVE")
+        }
     }
 
     return