[VOL-3007] Moving the dev pipeline to use the robot framework scale test

Change-Id: Icd06efd07bd0472ecc0149748078ba68f6e4a31e
diff --git a/jjb/pipeline/voltha-scale-test.groovy b/jjb/pipeline/voltha-scale-test.groovy
new file mode 100644
index 0000000..c97ecd4
--- /dev/null
+++ b/jjb/pipeline/voltha-scale-test.groovy
@@ -0,0 +1,201 @@
+// Copyright 2019-present Open Networking Foundation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+// deploy VOLTHA using kind-voltha and performs a scale test
+
+pipeline {
+
+  /* no label, executor is determined by JJB */
+  agent {
+    label "${params.buildNode}"
+  }
+  options {
+      timeout(time: 30, unit: 'MINUTES')
+  }
+  environment {
+    KUBECONFIG="$HOME/.kube/config"
+    VOLTCONFIG="$HOME/.volt/config"
+    PATH="$WORKSPACE/kind-voltha/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
+    TYPE="minimal"
+    FANCY=0
+    WITH_SIM_ADAPTERS="no"
+    WITH_RADIUS="yes"
+    WITH_BBSIM="yes"
+    LEGACY_BBSIM_INDEX="no"
+    DEPLOY_K8S="no"
+    CONFIG_SADIS="external"
+
+    // install everything in the default namespace
+    VOLTHA_NS="default"
+    ADAPTER_NS="default"
+    INFRA_NS="default"
+    BBSIM_NS="default"
+
+    // TODO make configurable
+    VOLTHA_LOG_LEVEL="${logLevel}"
+    NUM_OF_BBSIM="${olts}"
+    NUM_OF_OPENONU=4
+    NUM_OF_ONOS=1
+    NUM_OF_ATOMIX=0
+
+    // TODO make charts configurable (low priority)
+    VOLTHA_CHART="onf/voltha"
+    VOLTHA_CHART_VERSION="latest"
+    VOLTHA_BBSIM_CHART="onf/bbsim"
+    VOLTHA_BBSIM_CHART_VERSION="latest"
+    VOLTHA_ADAPTER_SIM_CHART="onf/voltha-adapter-simulated"
+    VOLTHA_ADAPTER_SIM_CHART_VERSION="latest"
+    VOLTHA_ADAPTER_OPEN_OLT_CHART="onf/voltha-adapter-openolt"
+    VOLTHA_ADAPTER_OPEN_OLT_CHART_VERSION="latest"
+    VOLTHA_ADAPTER_OPEN_ONU_CHART="onf/voltha-adapter-openonu"
+    VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION="latest"
+  }
+
+  stages {
+    stage ('Cleanup') {
+      // TODO remove plot files
+      steps {
+        sh returnStdout: false, script: """
+        test -e $WORKSPACE/kind-voltha/voltha && cd $WORKSPACE/kind-voltha && ./voltha down
+        cd $WORKSPACE
+        rm -rf $WORKSPACE/*
+        """
+      }
+    }
+    stage('Clone kind-voltha') {
+      steps {
+        checkout([
+          $class: 'GitSCM',
+          userRemoteConfigs: [[ url: "https://gerrit.opencord.org/kind-voltha", ]],
+          branches: [[ name: "master", ]],
+          extensions: [
+            [$class: 'WipeWorkspace'],
+            [$class: 'RelativeTargetDirectory', relativeTargetDir: "kind-voltha"],
+            [$class: 'CloneOption', depth: 0, noTags: false, reference: '', shallow: false],
+          ],
+        ])
+      }
+    }
+    stage('Clone voltha-system-tests') {
+      steps {
+        checkout([
+          $class: 'GitSCM',
+          userRemoteConfigs: [[ url: "https://gerrit.opencord.org/voltha-system-tests", ]],
+          branches: [[ name: "master", ]],
+          extensions: [
+            [$class: 'WipeWorkspace'],
+            [$class: 'RelativeTargetDirectory', relativeTargetDir: "voltha-system-tests"],
+            [$class: 'CloneOption', depth: 0, noTags: false, reference: '', shallow: false],
+          ],
+        ])
+        // TODO use master once the tests are merged
+        script {
+          sh(script:"cd voltha-system-tests; git fetch https://gerrit.opencord.org/voltha-system-tests refs/changes/79/18779/13 && git checkout FETCH_HEAD")
+        }
+      }
+    }
+    // stage('Deploy monitoring infrastructure') {
+    //   steps {
+    //     sh '''
+    //     helm install -n nem-monitoring cord/nem-monitoring --set kpi_exporter.enabled=false,dashboards.xos=false,dashboards.onos=false,dashboards.aaa=false,dashboards.voltha=false
+    //     '''
+    //   }
+    // }
+    stage('Deploy Voltha') {
+      steps {
+        script {
+          // TODO add support for custom images, see voltha-pyshical-build-and-test.groovy
+          // TODO install kafka outside kind-voltha (can't use 3 instances otherwise)
+          // TODO install etcd outside kind-voltha (no need to redeploy the operator everytime)
+          sh returnStdout: false, script: """
+            export EXTRA_HELM_FLAGS+='--set enablePerf=true,pon=${pons},onu=${onus}'
+
+
+            cd $WORKSPACE/kind-voltha/
+
+            ./voltha up
+          """
+        }
+      }
+    }
+    stage('Push MIB template to ETCD') {
+      steps {
+        sh '''
+          if [ ${withMibTemplate} = true ] ; then
+            rm -f BBSM-12345123451234512345-00000000000001-v1.json
+            wget https://raw.githubusercontent.com/opencord/voltha-openonu-adapter/master/templates/BBSM-12345123451234512345-00000000000001-v1.json
+            cat BBSM-12345123451234512345-00000000000001-v1.json | kubectl exec -it $(kubectl get pods | grep etcd-cluster | awk 'NR==1{print $1}') etcdctl put service/voltha/omci_mibs/templates/BBSM/12345123451234512345/00000000000001
+          fi
+        '''
+      }
+    }
+    stage('Run Test') {
+      steps {
+        // TODO use -i/-e in robot to customize runs for:
+        // - runs without flows
+        // - runs without subscriber provisioning
+        sh '''
+          mkdir -p $WORKSPACE/RobotLogs
+          cd voltha-system-tests
+          make vst_venv
+          source ./vst_venv/bin/activate
+          robot -d $WORKSPACE/RobotLogs \
+            -v olt:${olts} \
+            -v pon:${pons} \
+            -v onu:${onus} \
+            -v workflow:att \
+            -e teardown \
+            tests/scale/Voltha_Scale_Tests.robot
+        '''
+      }
+    }
+    stage('Collect results') {
+      steps {
+        sh '''
+          cd voltha-system-tests
+          source ./vst_venv/bin/activate
+          python tests/scale/collect-result.py -r ../RobotLogs/output.xml -p ../plots> execution-time.txt
+        '''
+      }
+    }
+  }
+  post {
+    always {
+      plot([
+        csvFileName: 'scale-test.csv',
+        csvSeries: [
+          [file: 'plots/plot-voltha-onus.txt', displayTableFlag: false, exclusionValues: '', inclusionFlag: 'OFF', url: ''],
+          [file: 'plots/plot-onos-ports.txt', displayTableFlag: false, exclusionValues: '', inclusionFlag: 'OFF', url: ''],
+          [file: 'plots/plot-voltha-flows-before.txt', displayTableFlag: false, exclusionValues: '', inclusionFlag: 'OFF', url: ''],
+          [file: 'plots/plot-onos-flows-before.txt', displayTableFlag: false, exclusionValues: '', inclusionFlag: 'OFF', url: ''],
+          [file: 'plots/plot-onos-auth.txt', displayTableFlag: false, exclusionValues: '', inclusionFlag: 'OFF', url: ''],
+          [file: 'plots/plot-voltha-flows-after.txt', displayTableFlag: false, exclusionValues: '', inclusionFlag: 'OFF', url: ''],
+          [file: 'plots/plot-onos-flows-after.txt', displayTableFlag: false, exclusionValues: '', inclusionFlag: 'OFF', url: ''],
+          [file: 'plots/plot-onos-dhcp.txt', displayTableFlag: false, exclusionValues: '', inclusionFlag: 'OFF', url: ''],
+        ],
+        group: 'Voltha-Scale-Numbers', numBuilds: '20', style: 'line', title: "Scale Test (OLTs: ${olts}, PONs: ${pons}, ONUs: ${onus})", yaxis: 'Time (s)', useDescr: true
+      ])
+      step([$class: 'RobotPublisher',
+        disableArchiveOutput: false,
+        logFileName: 'RobotLogs/log*.html',
+        otherFiles: '',
+        outputFileName: 'RobotLogs/output*.xml',
+        outputPath: '.',
+        passThreshold: 100,
+        reportFileName: 'RobotLogs/report*.html',
+        unstableThreshold: 0]);
+      archiveArtifacts artifacts: 'kind-voltha/install-minimal.log,voltha-system-tests/*.txt'
+    }
+  }
+}
diff --git a/jjb/voltha-scale.yaml b/jjb/voltha-scale.yaml
index 0c03a30..a64a786 100644
--- a/jjb/voltha-scale.yaml
+++ b/jjb/voltha-scale.yaml
@@ -163,13 +163,9 @@
           portsStatInterval: 5
           expectedFlows: 201
           extraHelmFlags: "--set replicas.adapter_open_onu=2"
-      - 'voltha-scale-measurements':
+      - 'voltha-scale-measurements-dev':
           name: 'voltha-scale-measurements-dev'
           build-node: 'voltha-scale'
-          onuPerPon: 16
-          ponPorts: 1
-          expectedOnus: 16
-          BBSIMdelay: 200
 
 - job-template:
     id: 'voltha-scale-measurements-periodic'
@@ -367,9 +363,9 @@
                  {time-trigger}
 
 - job-template:
-    id: 'voltha-scale-measurements'
+    id: 'voltha-scale-measurements-dev'
     name: '{name}'
-    pipeline-script: 'voltha-scale-measurements.groovy'
+    pipeline-script: 'voltha-scale-test.groovy'
 
     description: |
       <!-- Managed by Jenkins Job Builder -->
@@ -387,29 +383,6 @@
           build-timeout: '{build-timeout}'
           jenkins-ssh-credential: '{jenkins-ssh-credential}'
 
-    # default parameters
-    bbsimImg: "voltha/bbsim:master"
-    bbsimChart: "onf/bbsim"
-    volthaImg: "voltha/voltha-rw-core:master"
-    ofAgentImg: "voltha/voltha-ofagent-go:master"
-    volthaChart: "onf/voltha"
-    openoltAdapterImg: "voltha/voltha-openolt-adapter:master"
-    openoltAdapterChart: "onf/voltha-adapter-openolt"
-    openonuAdapterImg: "voltha/voltha-openonu-adapter:master"
-    openonuAdapterChart: "onf/voltha-adapter-openonu"
-    onosImg: "voltha/voltha-onos:master"
-    extraHelmFlags: ''
-    withMibTemplate: true
-    numOfBbsim: 1
-    numOfKafka: 3
-    withOnosApps: true
-    setLinkDiscovery: false
-    flowStatInterval: 600
-    portsStatInterval: 600
-    expectedFlows: 17 # one EAPOL per ONU + 1 LLDP on the NNI
-    bbsimAuth: true
-    bbsimDhcp: true
-
     parameters:
       - string:
           name: buildNode
@@ -422,135 +395,25 @@
           description: 'Log level for all the components'
 
       - string:
-          name: onuPerPon
-          default: 1
+          name: onus
+          default: 2
           description: 'Number of ONUs to provision'
 
       - string:
-          name: ponPorts
+          name: pons
           default: 1
           description: 'Number of PONs to provision'
 
-      - string:
-          name: expectedOnus
-          default: 1
-          description: 'Expected number of activated ONUs'
-
-      - string:
-          name: expectedFlows
-          default: '{expectedFlows}'
-          description: 'Expected number of flows in ONOS'
-
-      - string:
-          name: pollInterval
-          default: 5
-          description: 'Sleep time between ONU activation checks'
-
-      - bool:
-          name: withOnosApps
-          default: '{withOnosApps}'
-          description: 'Option to deactivate certain ONOS apps'
-
       - bool:
           name: withMibTemplate
-          default: '{withMibTemplate}'
+          default: true
           description: 'Option to trigger MIB template command'
 
-      - bool:
-          name: setLinkDiscovery
-          default: '{setLinkDiscovery}'
-          description: 'Option to toggle Link Discovery'
-
       - string:
-          name: BBSIMdelay
-          default: 200
-          description: 'BBSIM Delay, milliseconds'
-
-      - string:
-          name: flowStatInterval
-          default: '{flowStatInterval}'
-          description: 'Flow Stats Collection Interval, milliseconds'
-
-      - string:
-          name: portsStatInterval
-          default: {portsStatInterval}
-          description: 'Ports Stats Collection Interval, milliseconds'
-
-      - bool:
-          name: bbsimAuth
-          default: '{bbsimAuth}'
-          description: 'Option to toggle BBSIM EAPOL true/false'
-
-      - bool:
-          name: bbsimDhcp
-          default: '{bbsimDhcp}'
-          description: 'Option to toggle BBSIM DHCP true/false'
-
-      - string:
-          name: bbsimImg
-          default: '{bbsimImg}'
-          description: 'Custom image selection for BBSIM (repo:tag)'
-
-      - string:
-          name: bbsimChart
-          default: '{bbsimChart}'
-          description: 'BBSim chart name (or location on file system)'
-
-      - string:
-          name: volthaImg
-          default: '{volthaImg}'
-          description: 'Custom image selection for VOLTHA (repo:tag)'
-
-      - string:
-          name: ofAgentImg
-          default: '{ofAgentImg}'
-          description: 'Custom image selection for OfAgent (repo:tag), only supports the go version'
-
-      - string:
-          name: volthaChart
-          default: '{volthaChart}'
-          description: 'VOLTHA chart name (or location on file system)'
-
-      - string:
-          name: openoltAdapterImg
-          default: '{openoltAdapterImg}'
-          description: 'Custom image selection for Openolt Adapter (repo:tag)'
-
-      - string:
-          name: openoltAdapterChart
-          default: '{openoltAdapterChart}'
-          description: 'OpenOLT chart name (or location on file system)'
-
-      - string:
-          name: openonuAdapterImg
-          default: '{openonuAdapterImg}'
-          description: 'Custom image selection for Openonu Adapter (repo:tag)'
-
-      - string:
-          name: openonuAdapterChart
-          default: '{openonuAdapterChart}'
-          description: 'OpenONU chart name (or location on file system)'
-
-      - string:
-          name: onosImg
-          default: '{onosImg}'
-          description: 'Custom image selection for Openonu Adapter (repo:tag)'
-
-      - string:
-          name: extraHelmFlags
-          default: '{extraHelmFlags}'
-          description: 'Any extra helm parameters you want (passed to every helm install command)'
-
-      - string:
-          name: numOfBbsim
-          default: '{numOfBbsim}'
+          name: olts
+          default: 2
           description: 'How many BBSim instances to run'
 
-      - string:
-          name: numOfKafka
-          default: '{numOfKafka}'
-          description: 'How many Kafka instances to run'
-
     project-type: pipeline
     concurrent: false