Merge "SEBA-971 fix problems in groovy scripts; increase unit-test provision to 2c-4g"
diff --git a/jjb/pipeline/device-management-mock-tests.groovy b/jjb/pipeline/device-management-mock-tests.groovy
index b3bd20d..fafff45 100644
--- a/jjb/pipeline/device-management-mock-tests.groovy
+++ b/jjb/pipeline/device-management-mock-tests.groovy
@@ -28,7 +28,7 @@
   environment {
     KUBECONFIG="$HOME/.kube/kind-config-voltha-minimal"
     VOLTCONFIG="$HOME/.volt/config-minimal"
-    PATH="$WORKSPACE/kind-voltha/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
+    PATH="$WORKSPACE/voltha/kind-voltha/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
     TYPE="minimal"
     FANCY=0
     WITH_SIM_ADAPTERS="n"
@@ -63,8 +63,12 @@
     stage('Patch') {
       steps {
         sh """
-           pushd voltha
-           repo download "${gerritProject}" "${gerritChangeNumber}/${gerritPatchsetNumber}"
+           pushd $WORKSPACE/
+           echo "${gerritProject}" "${gerritChangeNumber}" "${gerritPatchsetNumber}"
+           echo "${GERRIT_REFSPEC}"
+           git clone https://gerrit.opencord.org/${gerritProject}
+           cd "${gerritProject}"
+           git fetch https://gerrit.opencord.org/${gerritProject} "${GERRIT_REFSPEC}" && git checkout FETCH_HEAD
            popd
            """
       }
@@ -72,20 +76,33 @@
     stage('Create K8s Cluster') {
       steps {
         sh """
-           git clone https://github.com/ciena/kind-voltha.git
-           cd kind-voltha/
+           cd $WORKSPACE/voltha/kind-voltha/
            JUST_K8S=y ./voltha up
-           bash <( curl -sfL https://raw.githubusercontent.com/boz/kail/master/godownloader.sh) -b "$WORKSPACE/kind-voltha/bin"
+           bash <( curl -sfL https://raw.githubusercontent.com/boz/kail/master/godownloader.sh) -b "$WORKSPACE/voltha/kind-voltha/bin"
            """
       }
     }
 
-    stage('Build Images') {
+    stage('Build Redfish Importer Image') {
       steps {
         sh """
-           make-local () {
-             make -C $WORKSPACE/voltha/\$1 DOCKER_REPOSITORY=voltha/ DOCKER_TAG=citest docker-build
-           }
+           make -C $WORKSPACE/device-management/\$1 DOCKER_REPOSITORY=opencord/ DOCKER_TAG=citest docker-build-importer
+           """
+      }
+    }
+
+    stage('Build demo_test Image') {
+      steps {
+        sh """
+           make -C $WORKSPACE/device-management/\$1/demo_test DOCKER_REPOSITORY=opencord/ DOCKER_TAG=citest docker-build
+           """
+      }
+    }
+
+    stage('Build mock-redfish-server  Image') {
+      steps {
+        sh """
+           make -C $WORKSPACE/device-management/\$1/mock-redfish-server DOCKER_REPOSITORY=opencord/ DOCKER_TAG=citest docker-build
            """
       }
     }
@@ -93,8 +110,6 @@
     stage('Push Images') {
       steps {
         sh '''
-             export GOROOT=/usr/local/go
-             export GOPATH=\$(pwd)
              docker images | grep citest
              for image in \$(docker images -f "reference=*/*citest" --format "{{.Repository}}"); do echo "Pushing \$image to nodes"; kind load docker-image \$image:citest --name voltha-\$TYPE --nodes voltha-\$TYPE-worker,voltha-\$TYPE-worker2; done
            '''
@@ -105,7 +120,7 @@
         sh '''
            export EXTRA_HELM_FLAGS="--set log_agent.enabled=False ${extraHelmFlags} "
 
-           cd $WORKSPACE/kind-voltha/
+           cd $WORKSPACE/voltha/kind-voltha/
            echo \$EXTRA_HELM_FLAGS
            kail -n voltha -n default > $WORKSPACE/onos-voltha-combined.log &
            ./voltha up
@@ -119,9 +134,9 @@
            mkdir -p $WORKSPACE/RobotLogs
 
            # tell the kubernetes script to use images tagged citest and pullPolicy:Never
-           sed -i 's/master/citest/g' $WORKSPACE/voltha/device-management/kubernetes/deploy-redfish-importer.yaml
-           sed -i 's/imagePullPolicy: Always/imagePullPolicy: Never/g' $WORKSPACE/voltha/device-management/kubernetes/deploy-redfish-importer.yaml
-           make -C $WORKSPACE/voltha/device-management functional-mock-test || true
+           sed -i 's/master/citest/g' $WORKSPACE/device-management/kubernetes/deploy-redfish-importer.yaml
+           sed -i 's/imagePullPolicy: Always/imagePullPolicy: Never/g' $WORKSPACE/device-management/kubernetes/deploy-redfish-importer.yaml
+           make -C $WORKSPACE/device-management functional-mock-test || true
            '''
       }
     }
@@ -131,14 +146,16 @@
     always {
       sh '''
          set +e
-         cp $WORKSPACE/kind-voltha/install-minimal.log $WORKSPACE/
-         kubectl get pods --all-namespaces -o jsonpath="{range .items[*].status.containerStatuses[*]}{.image}{'\\t'}{.imageID}{'\\n'}" | sort | uniq -c
+         cp $WORKSPACE/voltha/kind-voltha/install-minimal.log $WORKSPACE/
+         kubectl get pods --all-namespaces -o jsonpath="{range .items[*].status.containerStatuses[*]}{.image}{'\\n'}" | sort | uniq
+         kubectl get pods --all-namespaces -o jsonpath="{range .items[*].status.containerStatuses[*]}{.imageID}{'\\n'}" | sort | uniq
          kubectl get nodes -o wide
          kubectl get pods -o wide
          kubectl get pods -n voltha -o wide
 
          sync
          pkill kail || true
+         md5sum $WORKSPACE/voltha/kind-voltha/bin/voltctl
 
          ## Pull out errors from log files
          extract_errors_go() {
@@ -163,7 +180,7 @@
          gzip $WORKSPACE/onos-voltha-combined.log
 
          ## shut down kind-voltha
-         cd $WORKSPACE/kind-voltha
+         cd $WORKSPACE/voltha/kind-voltha
 	       WAIT_ON_DOWN=y ./voltha down
          '''
          step([$class: 'RobotPublisher',
diff --git a/jjb/verify/device-management.yaml b/jjb/verify/device-management.yaml
index 10cfec2..3921ad9 100644
--- a/jjb/verify/device-management.yaml
+++ b/jjb/verify/device-management.yaml
@@ -19,6 +19,7 @@
           dependency-jobs: 'verify_device-management_licensed'
       - 'make-unit-test':
           junit-allow-empty-results: true
+          build-node: 'ubuntu16.04-basebuild-2c-4g'
       - 'device-management-patch-test':
           pipeline-script: 'device-management-mock-tests.groovy'