VOL-3026 - add support for bbsim-sadis-server

Change-Id: I67e1f447996bca9d0664bec54d8b6b2cf83610a3
diff --git a/README.md b/README.md
index 91e6711..9d592b4 100644
--- a/README.md
+++ b/README.md
@@ -103,7 +103,7 @@
 | `WITH_SIM_ADAPTERS`                     | no                                                    | Should simulated device adapters be deployed (simulated adpaters deprecated) |
 | `WITH_OPEN_ADAPTERS`                    | yes                                                   | Should open OLT and ONU adapters be deployed |
 | `WITH_PORT_FORWARDS`                    | yes                                                   | Forwards ports for some services from localhost into the K8s cluster |
-| `CONFIG_SADIS`                          | no                                                    | Configure SADIS entries into ONOS. Values: `yes`, `no`, `file`, `url`, or `bbsim` |
+| `CONFIG_SADIS`                          | no                                                    | Configure SADIS entries into ONOS. Values: `yes`, `no`, `file`, `url`, `bbsim`, or `external` |
 | `SADIS_SUBSCRIBERS`                     | http://bbsim.voltha.svc:50074/v2/subscribers/%s       | URL for ONOS to use to query subsriber information if `CONFIG_SADIS` is set to `url` |
 | `SADIS_BANDWIDTH_PROFILES`              | http://bbsim.voltha.svc:50074/v2/bandwidthprofiles/%s | URL for ONOS to use to query bandwidth profiles if `CONFIG_SADIS` is set to `url` |
 | `SADIS_CFG`                             | onos-files/onos-sadis-sample.json                     | SADIS Configuration File to push, if CONFIG_SADIS set |
@@ -176,6 +176,7 @@
 | `no`             | do not configure ONOS for SADIS usage |
 | `url`            | configure ONOS to use SADIS via a URL. The URL used for subscriber information<br> is specified in the variable `SADIS_SUBSCRIBERS` and the URL used for bandwidth<br> profiles is specified in the variable `SADIS_BANDWIDTH_PROFILES` |
 | `bbsim`          | configure ONOS use use the SADIS servers that are part of BBSIM |
+| `external`       | an additional helm chart will be installed (`bbsim-sadis-server`) and ONOS will be configured to use that service for SADIS queries |
 
 ### Controlling volthawith and ONOS cluster
 
diff --git a/voltha b/voltha
index c88108b..cdc559d 100755
--- a/voltha
+++ b/voltha
@@ -87,7 +87,7 @@
 WITH_KAFKA=${WITH_KAFKA:-yes}
 WITH_ETCD=${WITH_ETCD:-yes}
 ONLY_ONE=${ONLY_ONE:-yes}
-CONFIG_SADIS=${CONFIG_SADIS:-no} # yes | no | file | bbsim | URL
+CONFIG_SADIS=${CONFIG_SADIS:-no} # yes | no | file | bbsim | external | URL
 SADIS_SUBSCRIBERS=${SADIS_SUBSCRIBERS:-http://bbsim.$VOLTHA_NS.svc:50074/v2/subscribers/%s}
 SADIS_BANDWIDTH_PROFILES=${SADIS_BANDWIDTH_PROFILES:-http://bbsim.$VOLTHA_NS.svc:50074/v2/bandwidthprofiles/%s}
 SADIS_CFG=${SADIS_CFG:-onos-files/onos-sadis-sample.json}
@@ -118,6 +118,8 @@
 ONOS_CLASSIC_CHART_VERSION=${ONOS_CHART_VERSION:-latest}
 KAFKA_CHART=${KAFKA_CHART:-incubator/kafka}
 KAFKA_CHART_VERSION=${KAFKA_CHART_VERSION:=0.15.3}
+BBSIM_SADIS_SERVER_CHART=${BBSIM_SADIS_SERVER_CHART:-bbsim-sadis/bbsim-sadis-server}
+BBSIM_SADIS_SERVER_CHART_VERSION=${BBSIM_SADIS_SERVER_CHART_VERSION:-latest}
 EXTRA_HELM_INSTALL_ARGS=${EXTRA_HELM_INSTALL_ARGS:-}
 INTERNAL_EXTRA_HELM_INSTALL_ARGS=
 NUM_OF_BBSIM=${NUM_OF_BBSIM:-1}
@@ -858,7 +860,6 @@
         sspin "Remove port-forwards: ${KAFKA_PREFIX}kafka-$NAME$CEOL"
         kill_port_forward "${KAFKA_PREFIX}kafka"
     fi
-
     espin "$VERIFIED Remove port-forwards$CEOL"
     if [ "$DEPLOY_K8S" == "yes" ]; then
         if [ -x ./bin/kind ]; then
@@ -869,6 +870,11 @@
             espin "$NO_ENTRY Delete Kubernetes Kind Cluster: kind command not found"
         fi
     else
+        if [ "$CONFIG_SADIS" == "external" ]; then
+            bspin "Remove configmap for BBSIM SADIS server"
+            (set -x; kubectl -n "$BBSIM_NS" delete --ignore-not-found configmap kube-config >>"$LOG" 2>&1) >>"$LOG" 2>&1
+            espin "$VERIFIED"
+        fi
         EXISTS="$(helm list -q)"
         EXPECT="voltha"
         if is_in "$WITH_ONOS" "yes,legacy,classic"; then
@@ -877,6 +883,9 @@
         if [ "$WITH_RADIUS" == "yes" ]; then
             EXPECT+=" radius"
         fi
+        if [ "$CONFIG_SADIS" == "external" ]; then
+            EXPECT+=" bbsim-sadis-server"
+        fi
         if [ "$WITH_BBSIM" == "yes" ]; then
             EXPECT+=" bbsim"
         fi
@@ -1386,6 +1395,9 @@
     bspin - "Add ONF Atomix repository to Helm"
     (set -x; helm repo add atomix https://charts.atomix.io >>"$LOG" 2>&1) >>"$LOG" 2>&1
     espin - "$VERIFIED"
+    bspin - "Add Custom BBSIM SADIS Server repository to Helm"
+    (set -x; helm repo add bbsim-sadis https://ciena.github.io/bbsim-sadis-server/charts >>"$LOG" 2>&1) >>"$LOG" 2>&1
+    espin - "$VERIFIED"
     bspin - "Update Helm repository cache"
     (set -x; helm repo update >>"$LOG" 2>&1) >>"$LOG" 2>&1
     espin - "$VERIFIED"
@@ -1723,6 +1735,35 @@
 }
 EOJ
 )"
+    elif [ "$CONFIG_SADIS" == "external" ]; then
+        push_onos_config "json" \
+            "[optional] Push ONOS configuration for custom SADIS and Bandwidth Profile servers" \
+            "network/configuration/apps/org.opencord.sadis" \
+            "$(cat <<EOJ | tr -d '[:space:]'
+{
+    "sadis": {
+        "integration": {
+            "url": "http://bbsim-sadis-server.$BBSIM_NS.svc:58080/subscribers/%s",
+            "cache": {
+                "enabled": true,
+                "maxsize": 50,
+                "ttl": "PT1m"
+            }
+        }
+    },
+    "bandwidthprofile": {
+        "integration": {
+            "url": "http://bbsim-sadis-server.$BBSIM_NS.svc:58080/profiles/%s",
+            "cache": {
+                "enabled": true,
+                "maxsize": 50,
+                "ttl": "PT1m"
+            }
+        }
+    }
+}
+EOJ
+)"
     elif [ "$CONFIG_SADIS" == "url" ]; then
         push_onos_config "json" \
             "[optional] Push ONOS configuration for custom SADIS and Bandwidth Profile servers" \
@@ -2024,6 +2065,27 @@
     fi
 fi
 
+if [ "$CONFIG_SADIS" == "external" ]; then
+    STIME="$(date +%s)"
+    echo -e "Verify BBSIM SADIS Service $PLUG"
+    bspin - "Verify required configmap"
+    (set -x; kubectl -n "$BBSIM_NS" delete --ignore-not-found configmap kube-config >>"$LOG" 2>&1) >>"$LOG" 2>&1
+    (set -x; kubectl -n "$BBSIM_NS" create configmap kube-config "--from-file=kube_config=$KUBECONFIG" >>"$LOG" 2>&1) >>"$LOG" 2>&1
+    espin - "$VERIFIED"
+    bspin - "Verify BBSIM SADIS Service Installed"
+    if [ "$HELM_USE_UPGRADE" == "yes" ] || [ "$(helm list --deployed --short --namespace "$BBSIM_NS" "^bbsim-sadis-servier\$" | wc -l)" -ne 1 ]; then
+        espin - "$NOT_VERIFIED"
+        helm_install - "$BBSIM_NS" bbsim-sadis-server "$BBSIM_SADIS_SERVER_CHART" "$BBSIM_SADIS_SERVER_CHART_VERSION"  "$_HELM_DESC BBSIM SADIS Server"
+    else
+        espin - "$VERIFIED"
+    fi
+    wait_for_pods - "$BBSIM_NS" 1 "includes" "Waiting for BBSIM SADIS Server to start" "$NO_LABEL" "bbsim-sadis-server-.*"
+    if [ "$WITH_TIMINGS" == "yes" ]; then
+        NOW="$(date +%s)"
+        printtime $((NOW - STIME))
+    fi
+fi
+
 if [ "$WITH_RADIUS" == "yes" ]; then
     STIME="$(date +%s)"
     echo -e "Verify RADIUS $LOCK"