[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
                             """
                         }
diff --git a/tests/data/dt-berlin-pod-multi-olt-sadis.json b/tests/data/dt-berlin-pod-multi-olt-sadis.json
new file mode 100644
index 0000000..3ebcabf
--- /dev/null
+++ b/tests/data/dt-berlin-pod-multi-olt-sadis.json
@@ -0,0 +1,148 @@
+{
+  "apps": {
+    "org.opencord.sadis": {
+      "sadis": {
+        "integration": {
+          "cache": {
+            "enabled": false,
+            "maxsize": 50,
+            "ttl": "PT0m"
+          }
+        },
+        "entries": [
+          {
+            "id": "EC1912001814",
+            "hardwareIdentifier": "80:a2:35:4d:24:c0",
+            "nasId": "EC1912001814",
+            "uplinkPort": 1048576
+          },
+          {
+            "id": "EC1729003539",
+            "hardwareIdentifier": "a8:2b:b5:6d:1a:95",
+            "nasId": "EC1729003539",
+            "uplinkPort": 1048576
+          },
+          {
+            "id": "SCOM00001c82-1",
+            "nasPortId": "SCOM00001c82-1",
+            "circuitId": "SCOM00001c82-1",
+            "remoteId": "EC1912001814",
+            "uniTagList": [{
+              "uniTagMatch": 4096,
+              "ponCTag": 4096,
+              "ponSTag": 31,
+              "technologyProfileId": 64,
+              "upstreamBandwidthProfile": "Default",
+              "downstreamBandwidthProfile": "Default",
+              "isDhcpRequired": false
+            }]
+          },
+          {
+            "id": "SCOM00001c89-1",
+            "nasPortId": "SCOM00001c89-1",
+            "circuitId": "SCOM00001c89-1",
+            "remoteId": "EC1912001814",
+            "uniTagList": [
+              {
+                "uniTagMatch": 4096,
+                "ponCTag": 4096,
+                "ponSTag": 32,
+                "technologyProfileId": 64,
+                "upstreamBandwidthProfile": "Default",
+                "downstreamBandwidthProfile": "Default",
+                "isDhcpRequired": false
+              }]
+          },
+          {
+            "id": "SCOM00001c96-1",
+            "nasPortId": "SCOM00001c96-1",
+            "circuitId": "SCOM00001c96-1",
+            "remoteId": "EC1912001814",
+            "uniTagList": [
+              {
+                "uniTagMatch": 4096,
+                "ponCTag": 4096,
+                "ponSTag": 33,
+                "technologyProfileId": 64,
+                "upstreamBandwidthProfile": "Default",
+                "downstreamBandwidthProfile": "Default",
+                "isDhcpRequired": false
+              }]
+          },
+          {
+            "id": "ALPHe3d1cf5c-1",
+            "nasPortId": "ALPHe3d1cf5c-1",
+            "circuitId": "ALPHe3d1cf5c-1",
+            "remoteId": "EC1729003539",
+            "uniTagList": [{
+              "ponCTag": 11,
+              "ponSTag": 11,
+              "technologyProfileId": 64,
+              "upstreamBandwidthProfile": "Default",
+              "downstreamBandwidthProfile": "Default",
+              "isDhcpRequired": true
+            }]
+          },
+          {
+            "id": "ALPHe3a69d03-1",
+            "nasPortId": "ALPHe3a69d03-1",
+            "circuitId": "ALPHe3a69d03-1",
+            "remoteId": "EC1729003539",
+            "uniTagList": [
+              {
+                "ponCTag": 7,
+                "ponSTag": 11,
+                "technologyProfileId": 64,
+                "upstreamBandwidthProfile": "Default",
+                "downstreamBandwidthProfile": "Default",
+                "isDhcpRequired": true
+              }]
+          }]
+      },
+      "bandwidthprofile":{
+          "integration":{
+              "cache":{
+                  "enabled":true,
+                  "maxsize":40,
+                  "ttl":"PT1m"
+              }
+          },
+          "entries":[
+              {
+                  "id": "Default",
+                  "air": 100000,
+                  "cbs": 30,
+                  "cir": 16000,
+                  "ebs": 30,
+                  "eir": 16000
+              },
+              {
+                  "id": "User_Bandwidth1",
+                  "air": 100000,
+                  "cbs": 10000,
+                  "cir": 30000,
+                  "ebs": 1000,
+                  "eir": 20000
+              },
+              {
+                  "id": "User_Bandwidth2",
+                  "air": 100000,
+                  "cbs": 5000,
+                  "cir": 100000,
+                  "ebs": 5000,
+                  "eir": 100000
+              },
+              {
+                  "id": "User_Bandwidth3",
+                  "air": 100000,
+                  "cbs": 5000,
+                  "cir": 1000000,
+                  "ebs": 5000,
+                  "eir": 1000000
+              }
+
+          ]
+      }
+    }
+  }
+}