Merge "SEBA-971 fix problems in groovy scripts; increase unit-test provision to 2c-4g"
diff --git a/jjb/docker-publish.yaml b/jjb/docker-publish.yaml
index f9f878a..d264eb9 100644
--- a/jjb/docker-publish.yaml
+++ b/jjb/docker-publish.yaml
@@ -72,7 +72,13 @@
           default: '{maintainers}'
           description: "The person that sould be notified if this job fails"
 
+      - string:
+          name: extraEnvironmentVars
+          default: '{extraEnvironmentVars}'
+          description: "Provide extra environment variables to the build"
+
     project-type: pipeline
     concurrent: true
+    extraEnvironmentVars: ""
 
     dsl: !include-raw-escape: pipeline/docker-publish.groovy
diff --git a/jjb/pipeline/comac-in-a-box-gerrit.groovy b/jjb/pipeline/comac-in-a-box-gerrit.groovy
index dc2be39..e3f20e9 100644
--- a/jjb/pipeline/comac-in-a-box-gerrit.groovy
+++ b/jjb/pipeline/comac-in-a-box-gerrit.groovy
@@ -66,11 +66,26 @@
 
     stage ("Run COMAC-in-a-box"){
       steps {
-        sh label: 'Run Makefile', script: """
-          cd $HOME/automation-tools/comac-in-a-box/
-          sudo make reset-test
-          sudo make test
-          """
+        script{
+          try{
+            sh label: 'Run Makefile', script: """
+              cd $HOME/automation-tools/comac-in-a-box/
+              sudo make reset-test
+              sudo make test
+              """
+          } finally {
+            sh label: 'Archive Logs', script: '''
+              mkdir logs
+              mkdir logs/pods
+              kubectl get pods -n omec > logs/kubectl_get_pods_omec.log
+              for pod in $(kubectl get pods -n omec | awk '{print $1}' | tail -n +2)
+              do
+                kubectl logs -n omec $pod --all-containers > logs/pods/$pod.log || true
+              done
+            '''
+            archiveArtifacts artifacts: "logs/**/*.log", allowEmptyArchive: true
+          }
+        }
       }
     }
   }
diff --git a/jjb/pipeline/docker-publish.groovy b/jjb/pipeline/docker-publish.groovy
index a21eda9..3b80806 100644
--- a/jjb/pipeline/docker-publish.groovy
+++ b/jjb/pipeline/docker-publish.groovy
@@ -54,7 +54,7 @@
 
           # Build w/branch
           echo "Building image with branch"
-          make DOCKER_TAG="$branchName" docker-build 2>&1 | tee "$WORKSPACE/docker-build.log"
+          $extraEnvironmentVars DOCKER_TAG="$branchName" make docker-build 2>&1 | tee "$WORKSPACE/docker-build.log"
 
           # Build w/tags if they exist
           if [ -n "$git_tags" ]
@@ -67,7 +67,7 @@
               # remove leading 'v' on funky golang tags
               clean_tag=\$(echo \$tag | sed 's/^v//g')
               echo "Building image with tag: \$clean_tag (should reuse cached layers)"
-              make DOCKER_TAG="\$clean_tag" docker-build
+              $extraEnvironmentVars DOCKER_TAG="\$clean_tag" make docker-build
             done
           fi
         """)
@@ -91,7 +91,7 @@
 
               # Push w/branch
               echo "Pushing image with branch"
-              make DOCKER_TAG="$branchName" docker-push 2>&1 | tee "$WORKSPACE/docker-push.log"
+              $extraEnvironmentVars DOCKER_TAG="$branchName" make docker-push 2>&1 | tee "$WORKSPACE/docker-push.log"
 
               # Push w/tags if they exist
               if [ -n "$git_tags" ]
@@ -103,7 +103,7 @@
                   # remove leading 'v' on funky golang tags
                   clean_tag=\$(echo \$tag | sed 's/^v//g')
                   echo "Pushing image with tag: \$clean_tag (should reuse cached layers)"
-                  make DOCKER_TAG="\$clean_tag" docker-push
+                  $extraEnvironmentVars DOCKER_TAG="\$clean_tag" make docker-push
                 done
               fi
             """)
diff --git a/jjb/pipeline/omec-fossa-scan.groovy b/jjb/pipeline/omec-fossa-scan.groovy
index c70f3eb..c7a3f3f 100644
--- a/jjb/pipeline/omec-fossa-scan.groovy
+++ b/jjb/pipeline/omec-fossa-scan.groovy
@@ -81,6 +81,12 @@
 
                         echo "Testing project: ${params.project}"
 
+                        if [ ! -f ".fossa.yml" ]
+                        then
+                          echo ".fossa.yml not found. This file is mandatory for the test to proceed."
+                          exit 1
+                        fi
+
                         echo "Run 'fossa init'"
                         fossa init --no-ansi --verbose
 
diff --git a/jjb/pipeline/omec-postmerge.groovy b/jjb/pipeline/omec-postmerge.groovy
index 5f23be4..9291f16 100644
--- a/jjb/pipeline/omec-postmerge.groovy
+++ b/jjb/pipeline/omec-postmerge.groovy
@@ -35,13 +35,17 @@
       steps {
         script {
           abbreviated_commit_hash = commitHash.substring(0, 7)
+          tags_to_build = [ "${branchName}-latest",
+                            "${branchName}-${abbreviated_commit_hash}"]
+          tags_to_build.each { tag ->
+            build job: "docker-publish-github_$repoName", parameters: [
+                  string(name: 'gitUrl', value: "${repoUrl}"),
+                  string(name: 'gitRef', value: "${branchName}"),
+                  string(name: 'branchName', value: "${tag}"),
+                  string(name: 'projectName', value: "${repoName}"),
+                ]
+          }
         }
-        build job: "docker-publish-github_$repoName", parameters: [
-              string(name: 'gitUrl', value: "${repoUrl}"),
-              string(name: 'gitRef', value: "${branchName}"),
-              string(name: 'branchName', value: "${branchName}-${abbreviated_commit_hash}"),
-              string(name: 'projectName', value: "${repoName}"),
-            ]
       }
     }
 
diff --git a/jjb/pipeline/voltha-bbsim-tests.groovy b/jjb/pipeline/voltha-bbsim-tests.groovy
index 7dfd54e..485fdbf 100644
--- a/jjb/pipeline/voltha-bbsim-tests.groovy
+++ b/jjb/pipeline/voltha-bbsim-tests.groovy
@@ -30,14 +30,9 @@
     VOLTCONFIG="$HOME/.volt/config-minimal"
     PATH="$WORKSPACE/voltha/kind-voltha/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
     TYPE="minimal"
+    VOLTHA_LOG_LEVEL="DEBUG"
     FANCY=0
     WITH_SIM_ADAPTERS="n"
-    WITH_RADIUS="y"
-    WITH_BBSIM="y"
-    DEPLOY_K8S="y"
-    VOLTHA_LOG_LEVEL="DEBUG"
-    CONFIG_SADIS="n"
-    ROBOT_MISC_ARGS="-d $WORKSPACE/RobotLogs"
   }
 
   stages {
@@ -144,7 +139,11 @@
            '''
       }
     }
-    stage('Deploy Voltha') {
+
+    stage('ATT workflow') {
+      environment {
+        ROBOT_LOGS_DIR="$WORKSPACE/RobotLogs/ATTWorkflow"
+      }
       steps {
         sh '''
            if [ "${branch}" != "master" ]; then
@@ -154,6 +153,12 @@
              echo "on master, using default settings for kind-voltha"
            fi
 
+           # Workflow-specific flags
+           export WITH_RADIUS=yes
+           export WITH_BBSIM=yes
+           export DEPLOY_K8S=yes
+           export CONFIG_SADIS=no
+
            export EXTRA_HELM_FLAGS+="--set log_agent.enabled=False ${extraHelmFlags} "
 
            IMAGES=""
@@ -205,32 +210,71 @@
              md5sum $WORKSPACE/voltha/kind-voltha/bin/voltctl
            fi
 
-           cd $WORKSPACE/voltha/kind-voltha/
-           echo \$EXTRA_HELM_FLAGS
+           printenv
            kail -n voltha -n default > $WORKSPACE/onos-voltha-combined.log &
-           ./voltha up
-           '''
-      }
-    }
 
-    stage('Run E2E Tests') {
-      steps {
-        sh '''
-           mkdir -p $WORKSPACE/RobotLogs
+           cd $WORKSPACE/voltha/kind-voltha/
+           ./voltha up
+
+           # minimal-env.sh contains the environment we used
+           # Save value of EXTRA_HELM_FLAGS there to use in subsequent stages
+           echo export EXTRA_HELM_FLAGS=\\"\$EXTRA_HELM_FLAGS\\" >> minimal-env.sh
+
+           mkdir -p $ROBOT_LOGS_DIR
+           export ROBOT_MISC_ARGS="-d $ROBOT_LOGS_DIR"
 
            # By default, all tests tagged 'sanity' are run.  This covers basic functionality
            # like running through the ATT workflow for a single subscriber.
-           export TEST_TAGS=sanity
+           export TARGET=sanity-single-kind
 
            # If the Gerrit comment contains a line with "functional tests" then run the full
            # functional test suite.  This covers tests tagged either 'sanity' or 'functional'.
            # Note: Gerrit comment text will be prefixed by "Patch set n:" and a blank line
            REGEX="functional tests"
            if [[ "$GERRIT_EVENT_COMMENT_TEXT" =~ \$REGEX ]]; then
-             TEST_TAGS=sanityORfunctional
+             TARGET=functional-single-kind
            fi
 
-           make -C $WORKSPACE/voltha/voltha-system-tests single-kind || true
+           make -C $WORKSPACE/voltha/voltha-system-tests \$TARGET || true
+           '''
+      }
+    }
+
+    stage('DT workflow') {
+      environment {
+        ROBOT_LOGS_DIR="$WORKSPACE/RobotLogs/DTWorkflow"
+      }
+      steps {
+        sh '''
+           cd $WORKSPACE/voltha/kind-voltha/
+           source minimal-env.sh
+           WAIT_ON_DOWN=y DEPLOY_K8S=n ./voltha down
+
+           # Workflow-specific flags
+           export WITH_RADIUS=no
+           export WITH_EAPOL=no
+           export WITH_DHCP=no
+           export WITH_IGMP=no
+           export CONFIG_SADIS=no
+
+           DEPLOY_K8S=n ./voltha up
+
+           mkdir -p $ROBOT_LOGS_DIR
+           export ROBOT_MISC_ARGS="-d $ROBOT_LOGS_DIR"
+
+           # By default, all tests tagged 'sanityDt' are run.  This covers basic functionality
+           # like running through the DT workflow for a single subscriber.
+           export TARGET=sanity-kind-dt
+
+           # If the Gerrit comment contains a line with "functional tests" then run the full
+           # functional test suite.  This covers tests tagged either 'sanityDt' or 'functionalDt'.
+           # Note: Gerrit comment text will be prefixed by "Patch set n:" and a blank line
+           REGEX="functional tests"
+           if [[ "$GERRIT_EVENT_COMMENT_TEXT" =~ \$REGEX ]]; then
+             TARGET=functional-single-kind-dt
+           fi
+
+           make -C $WORKSPACE/voltha/voltha-system-tests \$TARGET || true
            '''
       }
     }
@@ -272,27 +316,15 @@
          extract_errors_python voltha-ofagent >> $WORKSPACE/error-report.log
 
          gzip $WORKSPACE/onos-voltha-combined.log
-
-
-         ## shut down kind-voltha
-         if [ "${branch}" != "master" ]; then
-           echo "on branch: ${branch}, sourcing kind-voltha/releases/${branch}"
-           source "$WORKSPACE/voltha/kind-voltha/releases/${branch}"
-         else
-           echo "on master, using default settings for kind-voltha"
-         fi
-
-         cd $WORKSPACE/voltha/kind-voltha
-	       WAIT_ON_DOWN=y ./voltha down
          '''
          step([$class: 'RobotPublisher',
             disableArchiveOutput: false,
-            logFileName: 'RobotLogs/log*.html',
+            logFileName: 'RobotLogs/*/log*.html',
             otherFiles: '',
-            outputFileName: 'RobotLogs/output*.xml',
+            outputFileName: 'RobotLogs/*/output*.xml',
             outputPath: '.',
-            passThreshold: 80,
-            reportFileName: 'RobotLogs/report*.html',
+            passThreshold: 100,
+            reportFileName: 'RobotLogs/*/report*.html',
             unstableThreshold: 0]);
          archiveArtifacts artifacts: '*.log,*.gz'
     }
diff --git a/jjb/verify/voltha-go.yaml b/jjb/verify/voltha-go.yaml
index c40242d..089eaa5 100644
--- a/jjb/verify/voltha-go.yaml
+++ b/jjb/verify/voltha-go.yaml
@@ -41,3 +41,4 @@
           build-timeout: 30
           docker-repo: 'voltha'
           dependency-jobs: 'version-tag'
+          extraEnvironmentVars: BUILD_PROFILED=true
diff --git a/jjb/verify/voltha-openolt-adapter.yaml b/jjb/verify/voltha-openolt-adapter.yaml
index 893ec19..6f9c4c8 100644
--- a/jjb/verify/voltha-openolt-adapter.yaml
+++ b/jjb/verify/voltha-openolt-adapter.yaml
@@ -41,3 +41,4 @@
           build-timeout: 30
           docker-repo: 'voltha'
           dependency-jobs: 'version-tag'
+          extraEnvironmentVars: BUILD_PROFILED=true
diff --git a/jjb/voltha-scale.yaml b/jjb/voltha-scale.yaml
index a1a37ef..0c03a30 100644
--- a/jjb/voltha-scale.yaml
+++ b/jjb/voltha-scale.yaml
@@ -50,6 +50,16 @@
           # multi-adapter
           extraHelmFlags: "--set replicas.adapter_open_onu=8"
       - 'voltha-scale-measurements-periodic':
+          name: 'voltha-scale-measurements-periodic-16-32-20s'
+          build-node: 'onf-pod1-head-node'
+          time-trigger: "H H/4 * * *"
+          onuPerPon: 32
+          ponPorts: 16
+          expectedOnus: 512
+          BBSIMdelay: 20000
+          # multi-adapter
+          extraHelmFlags: "--set replicas.adapter_open_onu=8"
+      - 'voltha-scale-measurements-periodic':
           name: 'voltha-scale-measurements-periodic-16-64-200ms'
           build-node: 'onf-pod1-head-node'
           time-trigger: "H H/4 * * *"
@@ -60,6 +70,16 @@
           # multi-adapter
           extraHelmFlags: "--set replicas.adapter_open_onu=8"
       - 'voltha-scale-measurements-periodic':
+          name: 'voltha-scale-measurements-periodic-16-64-20s'
+          build-node: 'onf-pod1-head-node'
+          time-trigger: "H H/4 * * *"
+          onuPerPon: 64
+          ponPorts: 16
+          expectedOnus: 1024
+          BBSIMdelay: 20000
+          # multi-adapter
+          extraHelmFlags: "--set replicas.adapter_open_onu=8"
+      - 'voltha-scale-measurements-periodic':
           name: 'voltha-scale-measurements-periodic-4-64-200ms'
           build-node: 'onf-pod1-head-node'
           time-trigger: "H H/4 * * *"
@@ -142,6 +162,7 @@
           flowStatInterval: 5
           portsStatInterval: 5
           expectedFlows: 201
+          extraHelmFlags: "--set replicas.adapter_open_onu=2"
       - 'voltha-scale-measurements':
           name: 'voltha-scale-measurements-dev'
           build-node: 'voltha-scale'