[VOL-2655] Enabling support for multiple OLTs on one agg switch

Change-Id: Ib508433a60c355858db5130ee9810c32fc3e37fb
diff --git a/Jenkinsfile-voltha-build b/Jenkinsfile-voltha-build
index ec366a2..89697a1 100644
--- a/Jenkinsfile-voltha-build
+++ b/Jenkinsfile-voltha-build
@@ -17,10 +17,6 @@
     if (params.withKind != null){
         withKind = params.withKind
     }
-    def tech_prof_directory = "XGS-PON"
-    if (params.oltDebVersion.contains("asgvolt64")){
-        tech_prof_directory = "GPON"
-    }
     timeout (100) {
         try {
             stage ("Parse deployment configuration file") {
@@ -124,21 +120,27 @@
             }
             if ( params.configurePod && params.profile != "Default" ) {
                 stage('Push Tech-Profile') {
-                    timeout(1) {
-                        out_push_tp = sh returnStatus: true, script: """
-                        export KUBECONFIG=$WORKSPACE/${configBaseDir}/${configKubernetesDir}/${configFileName}.conf
-                        etcd_container=\$(kubectl get pods -n voltha | grep voltha-etcd-cluster | awk 'NR==1{print \$1}')
-                        kubectl cp $WORKSPACE/voltha-system-tests/tests/data/TechProfile-${profile}.json voltha/\$etcd_container:/tmp/flexpod.json
-                        put_result=\$(kubectl exec -it \$etcd_container -n voltha -- /bin/sh -c 'cat /tmp/flexpod.json | ETCDCTL_API=3 etcdctl put service/voltha/technology_profiles/${tech_prof_directory}/64')
-                        """
-                        return out_push_tp == 0
-                    }
-                    timeout(1) {
-                        out_get_tp = sh returnStatus: true, script: """
-                        etcd_container=\$(kubectl get pods -n voltha | grep voltha-etcd-cluster | awk 'NR==1{print \$1}')
-                        get_result=\$(kubectl exec -it \$etcd_container -n voltha -- /bin/sh -c 'ETCDCTL_API=3 etcdctl get --prefix service/voltha/technology_profiles/${tech_prof_directory}/64')
-                        """
-                        return out_get_tp == 0
+                    for(int i=0; i < deployment_config.olts.size(); i++) {
+                        def tech_prof_directory = "XGS-PON"
+                        if (deployment_config.olts[i].oltDebVersion.contains("asgvolt64")){
+                            tech_prof_directory = "GPON"
+                        }
+                        timeout(1) {
+                            out_push_tp = sh returnStatus: true, script: """
+                            export KUBECONFIG=$WORKSPACE/${configBaseDir}/${configKubernetesDir}/${configFileName}.conf
+                            etcd_container=\$(kubectl get pods -n voltha | grep voltha-etcd-cluster | awk 'NR==1{print \$1}')
+                            kubectl cp $WORKSPACE/voltha-system-tests/tests/data/TechProfile-${profile}.json voltha/\$etcd_container:/tmp/flexpod.json
+                            put_result=\$(kubectl exec -it \$etcd_container -n voltha -- /bin/sh -c 'cat /tmp/flexpod.json | ETCDCTL_API=3 etcdctl put service/voltha/technology_profiles/${tech_prof_directory}/64')
+                            """
+                            return out_push_tp == 0
+                        }
+                        timeout(1) {
+                            out_get_tp = sh returnStatus: true, script: """
+                            etcd_container=\$(kubectl get pods -n voltha | grep voltha-etcd-cluster | awk 'NR==1{print \$1}')
+                            get_result=\$(kubectl exec -it \$etcd_container -n voltha -- /bin/sh -c 'ETCDCTL_API=3 etcdctl get --prefix service/voltha/technology_profiles/${tech_prof_directory}/64')
+                            """
+                            return out_get_tp == 0
+                        }
                     }
                 }
             }
@@ -158,13 +160,13 @@
                 stage('Reinstall OLT software') {
                     for(int i=0; i < deployment_config.olts.size(); i++) {
                         sh returnStdout: true, script: """
-                        sshpass -p ${deployment_config.olts[i].pass} ssh -l ${deployment_config.olts[i].user} ${deployment_config.olts[i].ip} "dpkg --install ${oltDebVersion}"
+                        sshpass -p ${deployment_config.olts[i].pass} ssh -l ${deployment_config.olts[i].user} ${deployment_config.olts[i].ip} "dpkg --install ${deployment_config.olts[i].oltDebVersion}"
                         sleep 10
                         """
                         timeout(5) {
                             waitUntil {
                                 olt_sw_present = sh returnStdout: true, script: """
-                                if [[ "${oltDebVersion}" == *"asfvolt16"* ]]; then
+                                if [[ "${deployment_config.olts[i].oltDebVersion}" == *"asfvolt16"* ]]; then
                                     sshpass -p ${deployment_config.olts[i].pass} ssh -l ${deployment_config.olts[i].user} ${deployment_config.olts[i].ip} 'dpkg --list | grep asfvolt16 | wc -l'
                                 else
                                     sshpass -p ${deployment_config.olts[i].pass} ssh -l ${deployment_config.olts[i].user} ${deployment_config.olts[i].ip} 'dpkg --list | grep asgvolt64 | wc -l'
@@ -227,16 +229,24 @@
                             return sr_active_out == 0
                         }
                     }
-                    timeout(1) {
-                        // FIXME support multiple OLTs
+                    timeout(5) {
                         for(int i=0; i < deployment_config.hosts.src.size(); i++) {
+                            def aggPort = -1
+                            for(int j=0; j < deployment_config.olts.size(); j++) {
+                                if(deployment_config.olts[j].serial == deployment_config.hosts.src[j].olt){
+                                    aggPort = deployment_config.olts[j].aggPort
+                                }
+                            }
+                            if(aggPort == -1){
+                                throw new Exception("Upstream port for the olt is not configured, field aggPort is empty")
+                            }
                             xconnect_out = sh returnStatus: true, script: """
                             version=\$(sshpass -p karaf ssh -p 30115 karaf@${deployment_config.nodes[0].ip} "summary" | grep version)
                             sleep 10
                             if [[ \$version == *"version=2.2"* ]]; then
-                                curl -X POST --user karaf:karaf --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{"deviceId": "${deployment_config.fabric_switches[0].device_id}", "vlanId": "${deployment_config.hosts.src[i].s_tag}", "endpoints": [${deployment_config.fabric_switches[0].bngPort},${deployment_config.fabric_switches[0].oltPort}]}' 'http://${deployment_config.nodes[0].ip}:30120/onos/segmentrouting/xconnect'
+                                curl -X POST --user karaf:karaf --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{"deviceId": "${deployment_config.fabric_switches[0].device_id}", "vlanId": "${deployment_config.hosts.src[i].s_tag}", "endpoints": [${deployment_config.fabric_switches[0].bngPort},${aggPort}]}' 'http://${deployment_config.nodes[0].ip}:30120/onos/segmentrouting/xconnect'
                             else
-                                curl -X POST --user karaf:karaf --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{"deviceId": "${deployment_config.fabric_switches[0].device_id}", "vlanId": "${deployment_config.hosts.src[i].s_tag}", "ports": [${deployment_config.fabric_switches[0].bngPort},${deployment_config.fabric_switches[0].oltPort}]}' 'http://${deployment_config.nodes[0].ip}:30120/onos/segmentrouting/xconnect'
+                                curl -X POST --user karaf:karaf --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{"deviceId": "${deployment_config.fabric_switches[0].device_id}", "vlanId": "${deployment_config.hosts.src[i].s_tag}", "ports": [${deployment_config.fabric_switches[0].bngPort},${aggPort}]}' 'http://${deployment_config.nodes[0].ip}:30120/onos/segmentrouting/xconnect'
                             fi
                             """
                         }