Adding support to deploy multiple openonu adapters

Change-Id: I38ba60533333d845f5c5d8606f0c21b0d3c9ebfc
diff --git a/README.md b/README.md
index ec737d7..0ce5cda 100644
--- a/README.md
+++ b/README.md
@@ -1,5 +1,5 @@
 #  VOLTHA DEPLOYMENT TOOL
-Thie repository describes how to the the `voltha` script to install a 
+Thie repository describes how to the the `voltha` script to install a
 VOLTHA deployment. `voltha` can be used to deploy an instance into an existing
 Kubernetes cluster (physical or virtual) or can be start up a local
 docker-in-docker KinD Kuberentes cluster in which to deploy VOLTHA.
@@ -14,7 +14,7 @@
 using the script. The script checks for the presence of these tools before
 it deployes VOLTHA and will exit with an error if the tools are not present.
 
-_NOTE: If you are deploying a KinD Kubernetes cluster using the `voltha` 
+_NOTE: If you are deploying a KinD Kubernetes cluster using the `voltha`
 script, you must also also have Docker installed_
 
 ## INSTALL TYPE
@@ -42,7 +42,7 @@
 ## TL;DR
 OK, if you really don't care how it starts and you just want it started. After
 cloning the repository and making sure you have the prerequisites installed,
-just execute 
+just execute
 ```bash
 DEPLOY_K8S=y WITH_BBSIM=y WITH_RADIUS=y CONFIG_SADIS=y  ./voltha up
 ```
@@ -77,18 +77,19 @@
 ```
 Please check the `releases` folder to see the available ones and pick the correct tag associatet do that release.
 
-| OPTION                                | DEFAULT                                               | DESCRIPTION |
-| ------------------------------------- | ----------------------------------------------------- | ------------------------------------------------------------------------------------ |
+| OPTION                                  | DEFAULT                                               | DESCRIPTION |
+| --------------------------------------- | ----------------------------------------------------- | ------------------------------------------------------------------------------------ |
 | `TYPE`                                  | minimal                                               | `minimal` or `full` and determines number of cluster nodes and etcd cluster members |
 | `NAME`                                  | TYPE                                                  | Name of the KinD Cluster to be created |
 | `DEPLOY_K8S`                            | yes                                                   | Should the KinD Kubernetes cluster be deployed? |
 | `JUST_K8S`                              | no                                                    | Should just the KinD Kubernetes cluster be depoyed? (i.e. no VOLTHA) |
-| `VOLTHA_NS`                             | `voltha`                                                | K8s namespace into which to deploy voltha PODs |
-| `INFRA_NS`                              | `default`                                               | K8s namespace into which to deploy infrastructure PODs |
-| `BBSIM_NS`                              | `voltha`                                                | K8s namespace into which to deploy BBSIM PODs |
-| `ADAPTER_NS`                            | `voltha`                                                | K8s namespace into which to deploy VOLTHA adapters |
+| `VOLTHA_NS`                             | `voltha`                                              | K8s namespace into which to deploy voltha PODs |
+| `INFRA_NS`                              | `default`                                             | K8s namespace into which to deploy infrastructure PODs |
+| `BBSIM_NS`                              | `voltha`                                              | K8s namespace into which to deploy BBSIM PODs |
+| `ADAPTER_NS`                            | `voltha`                                              | K8s namespace into which to deploy VOLTHA adapters |
 | `WITH_BBSIM`                            | no                                                    | Should the BBSIM POD be deployed? |
 | `NUM_OF_BBSIM`                          | 1                                                     | number of BBSIM POD to start (minimum = 1, maximum = 10) |
+| `NUM_OF_OPENONU`                        | 1                                                     | number of OpenONU POD to start (minimum = 1, maximum = 10) |
 | `WITH_ONOS`                             | yes                                                   | Deploy ONOS (yes/no) or service:port of external ONOS |
 | `WITH_KAFKA`                            | yes                                                   | Deploy private Kafka (yes/no) or k8s servce:port of external Kafka |
 | `WITH_ETCD`                             | yes                                                   | Deploy private etcd (yes/no) or k8s service:port of external etcd |
diff --git a/voltha b/voltha
index a887742..ba85f84 100755
--- a/voltha
+++ b/voltha
@@ -113,7 +113,9 @@
 EXTRA_HELM_INSTALL_ARGS=${EXTRA_HELM_INSTALL_ARGS:-}
 INTERNAL_EXTRA_HELM_INSTALL_ARGS=
 NUM_OF_BBSIM=${NUM_OF_BBSIM:-1}
+NUM_OF_OPENONU=${NUM_OF_OPENONU:-1}
 MAX_NUM_OF_BBSIM=10
+MAX_NUM_OF_OPENONU=10
 
 HOSTOS="$(uname -s | tr "[:upper:]" "[:lower:"])"
 HOSTARCH="$(uname -m | tr "[:upper:]" "[:lower:"])"
@@ -127,11 +129,20 @@
 # note: instances will be numbered from 0 to 9
 if [ "$1" == "up" ]; then
     if [ "$NUM_OF_BBSIM" -lt 1 ]; then
-        >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} Invalid setting of BBSIM instances. NUM_OF_BBSIM is less than 1${NORMAL}"
+        >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} Invalid setting of BBSIM instances. NUM_OF_BBSIM (${NUM_OF_BBSIM}) is less than 1${NORMAL}"
         exit 1
     fi
     if [ "$NUM_OF_BBSIM" -gt "$MAX_NUM_OF_BBSIM" ]; then
-        >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} Invalid setting of BBSIM instances. NUM_OF_BBSIM is greater than $MAX_NUM_OF_BBSIM${NORMAL}"
+        >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} Invalid setting of BBSIM instances. NUM_OF_BBSIM (${NUM_OF_BBSIM}) is greater than $MAX_NUM_OF_BBSIM${NORMAL}"
+        exit 1
+    fi
+
+    if [ "$NUM_OF_OPENONU" -lt 1 ]; then
+        >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} Invalid setting of OPENONU instances. NUM_OF_OPENONU (${NUM_OF_OPENONU}) is less than 1${NORMAL}"
+        exit 1
+    fi
+    if [ "$NUM_OF_OPENONU" -gt "$MAX_NUM_OF_OPENONU" ]; then
+        >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} Invalid setting of OPENONU instances. NUM_OF_OPENONU (${NUM_OF_OPENONU}) is greater than $MAX_NUM_OF_OPENONU${NORMAL}"
         exit 1
     fi
 fi
@@ -230,6 +241,7 @@
     VOLTHA_BBSIM_CHART \
     VOLTHA_BBSIM_CHART_VERSION \
     NUM_OF_BBSIM \
+    NUM_OF_OPENONU \
     VOLTHA_ADAPTER_SIM_CHART \
     VOLTHA_ADAPTER_SIM_CHART_VERSION \
     VOLTHA_ADAPTER_OPEN_OLT_CHART \
@@ -1593,7 +1605,7 @@
 else
     EXPECT="$((EXPECT+2))"
 fi
-case $WITH_ETCD in 
+case $WITH_ETCD in
     no)
         INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set private_etcd_cluster=false"
         ;;
@@ -1719,14 +1731,18 @@
         else
             espin - "$VERIFIED"
         fi
+        EXPECT="$((EXPECT + 1))"
         bspin - "Verify OpenONU Adapter installed"
         if [ "$HELM_USE_UPGRADE" == "yes" ] || [ "$(helm list --deployed --short --namespace "$ADAPTER_NS"  "^open-onu\$" | wc -l)" -ne 1 ]; then
+            _ORIGINAL_EXTRA_HELM_INSTALL_ARGS="$INTERNAL_EXTRA_HELM_INSTALL_ARGS"
+            INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set replicas.adapter_open_onu=$NUM_OF_OPENONU"
             espin - "$NOT_VERIFIED"
-            helm_install - "$ADAPTER_NS" open-onu "$VOLTHA_ADAPTER_OPEN_ONU_CHART" "$VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION" "$_HELM_DESC OpenONU Adapter"
+            helm_install - "$ADAPTER_NS"  open-onu "$VOLTHA_ADAPTER_OPEN_ONU_CHART" "$VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION" "$_HELM_DESC OpenONU Adapter"
+            INTERNAL_EXTRA_HELM_INSTALL_ARGS="$_ORIGINAL_EXTRA_HELM_INSTALL_ARGS"
         else
             espin - "$VERIFIED"
         fi
-        EXPECT="$((EXPECT + 2))"
+        EXPECT=$((EXPECT + NUM_OF_OPENONU))
     fi
     INTERNAL_EXTRA_HELM_INSTALL_ARGS=