Merge "Adding support for voltha-onos 1.13.10 and 2.2 to BBSim based sanity test"
diff --git a/jjb/cord-test/voltha.yaml b/jjb/cord-test/voltha.yaml
index 557d50c..dabe712 100644
--- a/jjb/cord-test/voltha.yaml
+++ b/jjb/cord-test/voltha.yaml
@@ -84,6 +84,7 @@
           release: 'master'
           branch: 'master'
           released: false
+          onos-version: '2.2'
           test-repo: 'voltha-system-tests'
           Jenkinsfile: 'Jenkinsfile-voltha-bal31-build'
           oltDebVersion: 'openolt_asfvolt16_bal3.2.deb'
diff --git a/jjb/pipeline/omec-fossa-scan.groovy b/jjb/pipeline/omec-fossa-scan.groovy
index 53c19e9..f59f276 100644
--- a/jjb/pipeline/omec-fossa-scan.groovy
+++ b/jjb/pipeline/omec-fossa-scan.groovy
@@ -53,6 +53,8 @@
                         #!/usr/bin/env bash
 
                         git checkout FETCH_HEAD
+                        git show
+
                         echo "Testing project: ${params.project}"
 
                         echo "Run 'fossa init'"
diff --git a/jjb/pipeline/omec-reuse-scan.groovy b/jjb/pipeline/omec-reuse-scan.groovy
index dc2cf1f..f4fcf51 100644
--- a/jjb/pipeline/omec-reuse-scan.groovy
+++ b/jjb/pipeline/omec-reuse-scan.groovy
@@ -52,6 +52,8 @@
                     #!/usr/bin/env bash
 
                     git checkout FETCH_HEAD
+                    git show
+
                     reuse lint
                     """
             }
diff --git a/jjb/pipeline/voltha-bbsim-tests.groovy b/jjb/pipeline/voltha-bbsim-tests.groovy
index 6003e62..0b77619 100644
--- a/jjb/pipeline/voltha-bbsim-tests.groovy
+++ b/jjb/pipeline/voltha-bbsim-tests.groovy
@@ -84,7 +84,14 @@
     stage('Build Images') {
       steps {
         sh """
-           if ! [[ "${gerritProject}" =~ ^(voltha-helm-charts|voltha-system-tests)\$ ]]; then
+           if [ "${gerritProject}" = "pyvoltha" ]; then
+             cd $WORKSPACE/voltha/pyvoltha/
+             make dist
+             cd $WORKSPACE/voltha/voltha-openonu-adapter
+             export LOCAL_PYVOLTHA=$WORKSPACE/voltha/pyvoltha/
+             make local-pyvoltha
+             make DOCKER_REPOSITORY=voltha/ DOCKER_TAG=citest docker-build
+           elif ! [[ "${gerritProject}" =~ ^(voltha-helm-charts|voltha-system-tests)\$ ]]; then
              cd $WORKSPACE/voltha/${gerritProject}/
              make DOCKER_REPOSITORY=voltha/ DOCKER_TAG=citest docker-build
            fi
@@ -124,6 +131,8 @@
              IMAGES="afrouter afrouterd "
            elif [ "${gerritProject}" = "bbsim" ]; then
              IMAGES="bbsim "
+           elif [ "${gerritProject}" = "pyvoltha" ]; then
+             IMAGES="adapter_open_onu "
            else
              echo "No images to push"
            fi
diff --git a/jjb/pipeline/voltha-physical-functional-tests.groovy b/jjb/pipeline/voltha-physical-functional-tests.groovy
index 549101f..f4ca083 100644
--- a/jjb/pipeline/voltha-physical-functional-tests.groovy
+++ b/jjb/pipeline/voltha-physical-functional-tests.groovy
@@ -23,7 +23,7 @@
     label "${params.buildNode}"
   }
   options {
-    timeout(time: 60, unit: 'MINUTES')
+    timeout(time: 90, unit: 'MINUTES')
   }
 
   environment {
diff --git a/jjb/pipeline/voltha-scale-measurements.groovy b/jjb/pipeline/voltha-scale-measurements.groovy
index 0239627..d7aad03 100644
--- a/jjb/pipeline/voltha-scale-measurements.groovy
+++ b/jjb/pipeline/voltha-scale-measurements.groovy
@@ -17,6 +17,7 @@
     VOLTHA_LOG_LEVEL="DEBUG"
     CONFIG_SADIS="n"
     ROBOT_MISC_ARGS="-d $WORKSPACE/RobotLogs -v teardown_device:False"
+    SSHPASS="karaf"
   }
 
   stages {
@@ -45,7 +46,6 @@
           '''
       }
     }
-
     stage('deploy-voltha') {
       steps {
         sh '''
@@ -56,10 +56,32 @@
           '''
       }
     }
+    stage('MIB-template') {
+      steps {
+        sh '''
+          if [ "$withMibTemplate" = true ] ; then
+            git clone https://github.com/opencord/voltha-openonu-adapter.git
+            cat voltha-openonu-adapter/templates/BBSM-12345123451234512345-00000000000001-v1.json | kubectl exec -it -n voltha $(kubectl get pods -n voltha | grep etcd-cluster | awk 'NR==1{print $1}') etcdctl put service/voltha/omci_mibs/templates/BBSM/12345123451234512345/00000000000001
+            rm -rf voltha-openonu-adapter
+          fi
+        '''
+      }
+    }
+    stage('disable-ONOS-apps') {
+      steps {
+         sh '''
+          #Check withOnosApps and disable apps accordingly
+          if [ "$withOnosApps" = false ] ; then
+            sshpass -e ssh -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -p 8101 karaf@localhost app deactivate org.opencord.olt
+            sshpass -e ssh -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -p 8101 karaf@localhost app deactivate org.opencord.aaa
+            sshpass -e ssh -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -p 8101 karaf@localhost app deactivate org.opencord.dhcpl2relay
+          fi
+         '''
+      }
+    }
     stage('activate-ONUs') {
       steps {
         sh '''
-          export SSHPASS=karaf
           if [ -z "$onuTarget" ]
           then
             echo -e "You need to set the target ONU number\n"
@@ -75,15 +97,30 @@
           until [ $i -eq $onuTarget ]
           do
             echo "$i ONUs ACTIVE of $onuTarget expected (time: $SECONDS)"
-            sleep 20
+            sleep $pollInterval
             i=$(voltctl device list | grep -v OLT | grep ACTIVE | wc -l)
           done
           echo "$onuTarget ONUs Activated in $SECONDS seconds (time: $SECONDS)"
-          exit 0
+          #exit 0
 
         '''
       }
     }
+    stage('ONOS-ports') {
+      steps {
+        sh '''    
+          # Check ports showed up in ONOS
+          z=$(sshpass -e ssh -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -p 8101 karaf@localhost ports -e | grep BBSM | wc -l)
+          until [ $z -eq "$onuTarget" ]
+          do
+            echo "${z} enabled ports of "$onuTarget" expected (time: $SECONDS)"
+            sleep $pollInterval
+            z=$(sshpass -e ssh -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -p 8101 karaf@localhost ports -e | grep BBSM | wc -l)
+          done
+          echo "$onuTarget ports enabled in $SECONDS seconds (time: $SECONDS)"
+        '''
+      }
+    }
   }
   post {
     cleanup {
diff --git a/jjb/verify/pyvoltha.yaml b/jjb/verify/pyvoltha.yaml
index a16817d..8bc15db 100644
--- a/jjb/verify/pyvoltha.yaml
+++ b/jjb/verify/pyvoltha.yaml
@@ -20,6 +20,8 @@
           dependency-jobs: 'verify_pyvoltha_licensed'
       - 'python-unit-test':
           dependency-jobs: 'verify_pyvoltha_tag-collision'
+      - 'voltha-patch-test':
+          pipeline-script: 'voltha-bbsim-tests.groovy'
 
 - job-group:
     name: 'publish-pyvoltha-jobs'
diff --git a/jjb/voltha-scale.yaml b/jjb/voltha-scale.yaml
index 5ff2018..db8bc45 100644
--- a/jjb/voltha-scale.yaml
+++ b/jjb/voltha-scale.yaml
@@ -53,6 +53,22 @@
           default: 1
           description: 'Expected number of activated ONUs'
 
+      - string:
+          name: pollInterval
+          default: 20
+          description: 'Sleep time between ONU activation checks'
+      
+      - bool:
+          name: withOnosApps
+          default: false
+          description: 'Option to deactivate certain ONOS apps'
+
+      - bool:
+          name: withMibTemplate
+          default: false
+          description: 'Option to trigger MIB template command'
+    
+
     project-type: pipeline
     concurrent: true
 
diff --git a/packer/provision/basebuild.sh b/packer/provision/basebuild.sh
index 19e3876..c433d2d 100644
--- a/packer/provision/basebuild.sh
+++ b/packer/provision/basebuild.sh
@@ -19,9 +19,6 @@
     apt-get update
     apt-get install -y apt-transport-https software-properties-common
 
-    # set up ansible repo
-    apt-add-repository -y ppa:ansible/ansible
-
     # set up git backports repo
     add-apt-repository -y  ppa:git-core/ppa
 
@@ -87,7 +84,6 @@
     apt-get install -y \
         "docker-ce=17.06*" \
         apt-transport-https \
-        ansible \
         build-essential \
         bzip2 \
         curl \
@@ -97,7 +93,6 @@
         git \
         golang-1.12-go \
         graphviz \
-        httpie \
         jq \
         kafkacat \
         "kubeadm=1.12.7-*" \
@@ -110,14 +105,8 @@
         maven \
         nodejs \
         python \
-        python-certifi \
-        python-cryptography \
         python-dev \
-        python-idna \
-        python-netaddr \
-        python-openssl \
         python-pip \
-        python-urllib3 \
         python3-dev \
         ruby \
         screen \
@@ -127,33 +116,57 @@
         zip
         # end of apt-get install list
 
+    # remove apt installed incompatible python tools
+    # NOTE: Python3 versions are not removed, as cloud-init depends on them
+    apt-get -y remove \
+      python-enum34 \
+      python-cryptography \
+      python-openssl \
+      python-ndg-httpsclient \
+      python-requests \
+      python-six \
+      python-urllib3
+
     # install python modules
+    # upgrade pip or other installations may fail in unusual ways
+    pip install --upgrade pip
     pip install \
         Jinja2 \
+        ansible \
         ansible-lint \
         astroid==1.* \
         coverage \
+        certifi \
+        cryptography \
         docker-compose==1.20.1 \
         docker==3.2.1 \
         gitpython \
+        git-review \
         graphviz \
         grpcio-tools \
+        httpie==1.0.3 \
         isort \
         linkchecker \
         more-itertools==5.0.0 \
         mock \
+        netaddr \
+        ndg-httpsclient \
         nose2 \
+        pyopenssl \
         pexpect \
         pylint==1.* \
         pyyaml \
+        requests \
         robotframework \
         robotframework-httplibrary \
         robotframework-kafkalibrary \
         robotframework-lint \
         robotframework-requests \
         robotframework-sshlibrary \
+        six \
         tox \
         twine==1.15.0 \
+        urllib3 \
         virtualenv
         # end of pip install list
 
diff --git a/packer/provision/baseline.sh b/packer/provision/baseline.sh
index ed76c9d..a966a45 100644
--- a/packer/provision/baseline.sh
+++ b/packer/provision/baseline.sh
@@ -341,7 +341,7 @@
     # --- START LFTOOLS DEPS
 
     # Used by various scripts to push patches to Gerrit
-    ensure_ubuntu_install git-review
+    # ensure_ubuntu_install git-review
 
     # Needed to parse OpenStack commands used by opendaylight-infra stack commands
     # to initialize Heat template based systems.