blob: cc81802cec24ec8c185aceff8d2fef32b1276e6a [file] [log] [blame]
Test User01ed0642019-07-03 20:17:06 +00001#!/bin/bash
David K. Bainbridgeb7285432019-07-02 22:05:24 -07002# Copyright 2019 Ciena Corporation
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
David Bainbridged049a612020-03-16 17:22:54 -070015set -f
David Bainbridged18f4942020-04-14 16:46:13 -070016unalias -a
David Bainbridge60ffc0f2020-04-27 22:13:22 -070017shopt -s extglob
David Bainbridged18f4942020-04-14 16:46:13 -070018TOTAL_START_TIME="$(date +%s)"
David Bainbridgeb4bbde12020-06-25 14:46:36 -070019mkdir -p "$(pwd)/bin"
20PATH="$(pwd)/bin:$PATH"; export PATH
21GOPATH="$(pwd)"; export GOPATH
David K. Bainbridgeb7285432019-07-02 22:05:24 -070022
David Bainbridge38dc1e82019-08-12 15:18:45 +000023FANCY=${FANCY:-1}
24if [ "$TERM X" == " X" ]; then
25 FANCY=0
26fi
27
David K. Bainbridgeb7285432019-07-02 22:05:24 -070028# trap ctrl-c and call ctrl_c()
29trap ctrl_c INT
30
31function ctrl_c() {
David Bainbridged18f4942020-04-14 16:46:13 -070032 echo -en "$CNORM"
David K. Bainbridgeb7285432019-07-02 22:05:24 -070033 echo ""
34 echo "ctrl-c trapped"
David Bainbridgec6a6eb62019-10-18 22:50:07 +000035 echo "Thank you for trying 'voltha up'"
David K. Bainbridgeb7285432019-07-02 22:05:24 -070036 exit
37}
38
Andrea Campanella40e48b72020-07-21 20:32:52 +020039HELM_VERSION=${HELM_VERSION:-v3.2.4}
David K. Bainbridgeebf38d92020-02-10 10:46:31 -080040VOLTCTL_VERSION=${VOLTCTL_VERSION:-latest}
David K. Bainbridge88a7a792020-07-27 17:01:14 +000041KIND_VERSION=${KIND_VERSION:-v0.8.1}
David K. Bainbridgeb3a99372020-01-08 14:39:06 -080042VK_RELEASE=${VK_RELEASE:-master}
David Bainbridge60ffc0f2020-04-27 22:13:22 -070043EXTRA_TOOLS=
Test User08ebbd92019-07-03 17:15:39 +000044
David Bainbridge38dc1e82019-08-12 15:18:45 +000045RED=
46GREEN=
47YELLOW=
48BLUE=
David Bainbridge38dc1e82019-08-12 15:18:45 +000049BOLD=
50NORMAL=
51ERROR=
52CEOL=
53CNORM=
54CIVIS=
David Bainbridged18f4942020-04-14 16:46:13 -070055if [ "$FANCY" -eq 1 ]; then
56 RED="$(tput setaf 1)"
57 GREEN="$(tput setaf 2)"
58 YELLOW="$(tput setaf 3)"
59 BLUE="$(tput setaf 4)"
60 BOLD="$(tput bold)"
61 NORMAL="$(tput sgr0)"
David Bainbridge38dc1e82019-08-12 15:18:45 +000062 ERROR="\xe2\x9c\x97\x20"
David Bainbridged18f4942020-04-14 16:46:13 -070063 CEOL="$(tput el)"
64 CNORM="$(tput cnorm)"
65 CIVIS="$(tput civis)"
David Bainbridge38dc1e82019-08-12 15:18:45 +000066fi
Test User7d866122019-07-09 17:52:35 +000067
Matteo Scandolo657e13c2020-07-28 11:41:42 -070068NAME=${NAME:-minimal}
David K. Bainbridge484d80c2020-03-05 21:44:34 -080069
70ENABLE_ONOS_EXTRANEOUS_RULES=${ENABLE_ONOS_EXTRANEOUS_RULES:-no}
David Bainbridge76afd812020-04-06 09:53:52 -070071INFRA_NS=${INFRA_NS:-default}
72VOLTHA_NS=${VOLTHA_NS:-voltha}
73BBSIM_NS=${BBSIM_NS:-voltha}
74ADAPTER_NS=${ADAPTER_NS:-voltha}
David Bainbridgee87067b2019-08-12 22:00:12 +000075WITH_TIMINGS=${WITH_TIMINGS:-no}
Test User7d866122019-07-09 17:52:35 +000076WITH_BBSIM=${WITH_BBSIM:-no}
divyadesai59f987a2020-05-27 12:11:33 +000077WITH_EFK=${WITH_EFK:-no}
David Bainbridge5b7b96b2019-07-25 20:29:13 +000078WITH_RADIUS=${WITH_RADIUS:-no}
Matteo Scandolo78dfee02020-02-13 16:18:03 -080079WITH_EAPOL=${WITH_EAPOL:-yes}
80WITH_DHCP=${WITH_DHCP:-yes}
81WITH_IGMP=${WITH_IGMP:-no}
David Bainbridgeb270c202019-07-26 01:44:42 +000082WITH_ONOS=${WITH_ONOS:-yes}
David Bainbridge60ffc0f2020-04-27 22:13:22 -070083NUM_OF_ONOS=${NUM_OF_ONOS:-1}
84NUM_OF_ATOMIX=${NUM_OF_ATOMIX:-0}
David Bainbridge99ac7a22019-08-31 02:26:43 +000085WITH_CHAOS=${WITH_CHAOS:-no}
David Bainbridge46505fb2019-10-01 21:13:20 +000086WITH_ADAPTERS=${WITH_ADAPTERS:-yes}
David K. Bainbridgeda33d652020-03-06 10:31:23 -080087WITH_SIM_ADAPTERS=${WITH_SIM_ADAPTERS:-no}
David Bainbridge46505fb2019-10-01 21:13:20 +000088WITH_OPEN_ADAPTERS=${WITH_OPEN_ADAPTERS:-yes}
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -080089WITH_PORT_FORWARDS=${WITH_PORT_FORWARDS:-yes}
David Bainbridge696bc632020-04-05 21:49:37 -070090WITH_KAFKA=${WITH_KAFKA:-yes}
91WITH_ETCD=${WITH_ETCD:-yes}
Matteo Scandoloefee0432020-05-05 13:56:20 -070092WITH_PPROF=${WITH_PPROF:-no}
Girish Gowdra4cc5d8b2020-06-11 17:12:00 -070093WITH_INCREMENTAL_EVTO_UPDATE=${WITH_INCREMENTAL_EVTO_UPDATE:-no}
David Bainbridgee4d11ca2020-05-08 10:21:10 -070094SCHEDULE_ON_CONTROL_NODES=${SCHEDULE_ON_CONTROL_NODES:-no}
David Bainbridge309099c2020-05-05 08:47:29 -070095CONFIG_SADIS=${CONFIG_SADIS:-no} # yes | no | file | bbsim | external | URL
Hardik Windlassb3147602020-03-09 16:59:15 +053096SADIS_CFG=${SADIS_CFG:-onos-files/onos-sadis-sample.json}
David Bainbridge27790d62019-08-13 22:43:19 +000097INSTALL_ONOS_APPS=${INSTALL_ONOS_APPS:-no}
Test Userba1e7e72019-07-10 22:27:54 +000098JUST_K8S=${JUST_K8S:-no}
99DEPLOY_K8S=${DEPLOY_K8S:-yes}
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700100INSTALL_KUBECTL=${INSTALL_KUBECTL:-yes}
101INSTALL_HELM=${INSTALL_HELM:-yes}
David Bainbridge7f8bf992020-04-08 21:53:22 -0700102HELM_USE_UPGRADE=${HELM_USE_UPGRADE:-no}
David Bainbridge46505fb2019-10-01 21:13:20 +0000103UPDATE_HELM_REPOS=${UPDATE_HELM_REPOS:-yes}
Matteo Scandolofab98622020-01-28 15:17:20 -0800104WAIT_ON_DOWN=${WAIT_ON_DOWN:-yes}
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700105WAIT_TIMEOUT=${WAIT_TIMEOUT:-30m}
106VOLTHA_DOWN_ON_TIMEOUT=${VOLTHA_DOWN_ON_TIMEOUT:-no}
David Bainbridge5b7b96b2019-07-25 20:29:13 +0000107VOLTHA_LOG_LEVEL=${VOLTHA_LOG_LEVEL:-WARN}
David Bainbridge90fd8e32019-08-21 23:32:47 +0000108VOLTHA_CHART=${VOLTHA_CHART:-onf/voltha}
109VOLTHA_CHART_VERSION=${VOLTHA_CHART_VERSION:-latest}
110VOLTHA_BBSIM_CHART=${VOLTHA_BBSIM_CHART:-onf/bbsim}
Matteo Scandolodcd29f52019-10-07 15:42:42 -0700111VOLTHA_BBSIM_CHART_VERSION=${VOLTHA_BBSIM_CHART_VERSION:-latest}
divyadesai59f987a2020-05-27 12:11:33 +0000112ELASTICSEARCH_CHART=${ELASTICSEARCH_CHART:-elastic/elasticsearch}
113ELASTICSEARCH_CHART_VERSION=${ELASTICSEARCH_CHART_VERSION:-latest}
114KIBANA_CHART=${KIBANA_CHART:-elastic/kibana}
115KIBANA_CHART_VERSION=${KIBANA_CHART_VERSION:-latest}
116FLUENTD_ELASTICSEARCH_CHART=${FLUENTD_ELASTICSEARCH_CHART:-kiwigrid/fluentd-elasticsearch}
117FLUENTD_ELASTICSEARCH_CHART_VERSION=${FLUENTD_ELASTICSEARCH_CHART_VERSION:-latest}
David Bainbridgee10f6d52019-07-25 00:28:13 +0000118VOLTHA_ADAPTER_SIM_CHART=${VOLTHA_ADAPTER_SIM_CHART:-onf/voltha-adapter-simulated}
David Bainbridge90fd8e32019-08-21 23:32:47 +0000119VOLTHA_ADAPTER_SIM_CHART_VERSION=${VOLTHA_ADAPTER_SIM_CHART_VERSION:-latest}
David Bainbridgee10f6d52019-07-25 00:28:13 +0000120VOLTHA_ADAPTER_OPEN_OLT_CHART=${VOLTHA_ADAPTER_OPEN_OLT_CHART:-onf/voltha-adapter-openolt}
David Bainbridge90fd8e32019-08-21 23:32:47 +0000121VOLTHA_ADAPTER_OPEN_OLT_CHART_VERSION=${VOLTHA_ADAPTER_OPEN_OLT_CHART_VERSION:-latest}
David Bainbridgee10f6d52019-07-25 00:28:13 +0000122VOLTHA_ADAPTER_OPEN_ONU_CHART=${VOLTHA_ADAPTER_OPEN_ONU_CHART:-onf/voltha-adapter-openonu}
David Bainbridge90fd8e32019-08-21 23:32:47 +0000123VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION=${VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION:-latest}
David K. Bainbridgeda33d652020-03-06 10:31:23 -0800124ONOS_CHART=${ONOS_CHART:-onf/onos}
Andrea Campanella21323292019-12-18 11:44:19 -0800125ONOS_CHART_VERSION=${ONOS_CHART_VERSION:-latest}
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700126ONOS_CLASSIC_CHART=${ONOS_CLASSIC_CHART:-onos/onos-classic}
Andrea Campanella5b801702020-07-30 10:16:22 +0200127ONOS_CLASSIC_CHART_VERSION=${ONOS_CLASSIC_CHART_VERSION:-latest}
David Bainbridgecf546362020-04-21 23:18:50 -0700128KAFKA_CHART=${KAFKA_CHART:-incubator/kafka}
David Bainbridgeb4bbde12020-06-25 14:46:36 -0700129KAFKA_CHART_VERSION=${KAFKA_CHART_VERSION:=latest}
David Bainbridge309099c2020-05-05 08:47:29 -0700130BBSIM_SADIS_SERVER_CHART=${BBSIM_SADIS_SERVER_CHART:-bbsim-sadis/bbsim-sadis-server}
131BBSIM_SADIS_SERVER_CHART_VERSION=${BBSIM_SADIS_SERVER_CHART_VERSION:-latest}
David Bainbridgeb4bbde12020-06-25 14:46:36 -0700132ETCD_CHART=${ETCD_CHART:-etcd/etcd}
David Bainbridgec7220622020-05-28 12:31:47 -0700133ETCD_CHART_VERSION=${ETCD_CHART_VERSION:-latest}
David Bainbridge879439b2020-06-12 15:59:35 -0700134RADIUS_CHART=${RADIUS_CHART:-onf/freeradius}
135RADIUS_CHART_VERSION=${RADIUS_CHART_VERSION:-latest}
David Bainbridge2eaf2cf2020-03-18 12:54:08 -0700136EXTRA_HELM_INSTALL_ARGS=${EXTRA_HELM_INSTALL_ARGS:-}
137INTERNAL_EXTRA_HELM_INSTALL_ARGS=
uottrembb16d3982020-02-28 08:34:36 +0100138NUM_OF_BBSIM=${NUM_OF_BBSIM:-1}
Matteo Scandolo657e13c2020-07-28 11:41:42 -0700139NUM_OF_WORKER_NODES=${NUM_OF_WORKER_NODES:-2}
140NUM_OF_CONTROLLER_NODES=${NUM_OF_CONTROLLER_NODES:-1}
Matteo Scandolo67335f02020-04-09 11:19:53 -0700141NUM_OF_OPENONU=${NUM_OF_OPENONU:-1}
Matteo Scandolo657e13c2020-07-28 11:41:42 -0700142NUM_OF_KAFKA=${NUM_OF_KAFKA:-1}
143NUM_OF_ETCD=${NUM_OF_ETCD:-1}
uottrembb16d3982020-02-28 08:34:36 +0100144MAX_NUM_OF_BBSIM=10
Matteo Scandolo67335f02020-04-09 11:19:53 -0700145MAX_NUM_OF_OPENONU=10
Matteo Scandoloc2eb0672020-05-01 14:43:15 -0700146LEGACY_BBSIM_INDEX=${LEGACY_BBSIM_INDEX:-no}
David Bainbridgeb4bbde12020-06-25 14:46:36 -0700147PF_ADDRESS=${PF_ADDRESS:-0.0.0.0}
Test Userba1e7e72019-07-10 22:27:54 +0000148
David Bainbridged18f4942020-04-14 16:46:13 -0700149HOSTOS="$(uname -s | tr "[:upper:]" "[:lower:"])"
150HOSTARCH="$(uname -m | tr "[:upper:]" "[:lower:"])"
151if [ "$HOSTARCH" == "x86_64" ]; then
Test Userba1e7e72019-07-10 22:27:54 +0000152 HOSTARCH="amd64"
153fi
David Bainbridge7db44002020-04-09 12:54:29 -0700154BBSIM_LABEL="-l app=bbsim"
David Bainbridged18f4942020-04-14 16:46:13 -0700155NO_LABEL=
Test User7d866122019-07-09 17:52:35 +0000156
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700157# checks to see if a given WORD is in the given LIST of words
158function is_in() {
159 local WORD LIST
160 WORD="$1"; shift
161 LIST="$*"
162 LIST=${LIST//+([[:space:],|])/:}
163
164 [ "$(echo ":$LIST:" | grep -ic ":$WORD:")" -ne 0 ]
165}
166
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700167function parseDuration() {
David Bainbridged18f4942020-04-14 16:46:13 -0700168 local DUR RESULT TERM TERMS VALUE UNIT
169 DUR=$1
170 RESULT=0
171 TERMS="$(echo "$DUR" | sed -Ee 's/([sSmMhHdD])/\1 /g' -e 's/,$//g')"
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700172 for TERM in $TERMS; do
David Bainbridged18f4942020-04-14 16:46:13 -0700173 VALUE="$(echo "$TERM" | sed -Ee 's/([0-9]+)[sSmMhHdD]/\1/')"
174 UNIT="$(echo "$TERM" | sed -Ee 's/[0-9]+([sSmMhHdD])/\1/')"
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700175 case $UNIT in
176 s|S)
David Bainbridged18f4942020-04-14 16:46:13 -0700177 RESULT=$((RESULT + VALUE)) ;;
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700178 m|M)
David Bainbridged18f4942020-04-14 16:46:13 -0700179 RESULT=$((RESULT + (VALUE * 60))) ;;
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700180 h|H)
David Bainbridged18f4942020-04-14 16:46:13 -0700181 RESULT=$((RESULT + (VALUE * 3600))) ;;
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700182 d|D)
David Bainbridged18f4942020-04-14 16:46:13 -0700183 RESULT=$((RESULT + (VALUE * 86400))) ;;
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700184 *) ;;
185 esac
186 done
187 echo $RESULT
188}
189
190function doTimeout() {
191 local MSG=$1
192 2>&1 echo -e "\n${RED}${BOLD}${ERROR}TIMEOUT:${NORMAL}${RED} Operation timed out after '$WAIT_TIMEOUT': $MSG"
193 exit 125
194}
195
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -0800196function get_service_ep() {
197 local NS=$1
198 local NAME=$2
David Bainbridged18f4942020-04-14 16:46:13 -0700199 kubectl -n "$NS" get service "$NAME" -o json | jq -r '.spec.clusterIP + ":" + (.spec.ports[0].port|tostring)'
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -0800200}
201
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000202# Used to verify configuration values are set to "yes" or "no" value or convert
203# equivalents to "yes" or "no"
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700204YES="y,yes,t,true,1"
205NO="n,no,f,false,0"
206YES_OR_NO="$YES,$NO"
207
208# If the given VAR matches a truth value then normalize that
209# value, else return original value
210function normalize_yes_no() {
211 local VAR VAL
212 VAR=$1
213 VAL="$(eval echo "\$$VAR")"
214 if ! is_in "$VAL" "$YES_OR_NO"; then
215 echo "$VAL"
216 return 1
217 fi
218 if is_in "$VAL" "$YES"; then
219 echo "yes"
220 else
221 echo "no"
222 fi
223 return 0
224}
225
226# If the given VAR matches a truth value then normalize that
227# value, else display an error
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000228function verify_yes_no() {
David Bainbridged18f4942020-04-14 16:46:13 -0700229 local VAR VAL
230 VAR=$1
231 VAL="$(eval echo "\$$VAR")"
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700232 if ! is_in "$VAL" "$YES_OR_NO"; then
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000233 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} Invalid '$VAR' value of '$VAL'. Should be 'yes' or 'no'${NORMAL}"
234 echo "INVALID"
235 return 1
236 fi
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700237 if is_in "$VAL" "$YES"; then
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000238 echo "yes"
239 else
240 echo "no"
241 fi
242 return 0
243}
Test User7d866122019-07-09 17:52:35 +0000244
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000245ALL_YES_NO="\
David K. Bainbridge484d80c2020-03-05 21:44:34 -0800246 ENABLE_ONOS_EXTRANEOUS_RULES \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000247 WITH_TIMINGS \
248 WITH_BBSIM \
divyadesai59f987a2020-05-27 12:11:33 +0000249 WITH_EFK \
Matteo Scandolo78dfee02020-02-13 16:18:03 -0800250 WITH_EAPOL \
251 WITH_DHCP \
252 WITH_IGMP \
David Bainbridge99ac7a22019-08-31 02:26:43 +0000253 WITH_CHAOS \
David Bainbridge46505fb2019-10-01 21:13:20 +0000254 WITH_ADAPTERS \
255 WITH_SIM_ADAPTERS \
256 WITH_OPEN_ADAPTERS \
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -0800257 WITH_PORT_FORWARDS \
Matteo Scandoloefee0432020-05-05 13:56:20 -0700258 WITH_PPROF \
Girish Gowdra4cc5d8b2020-06-11 17:12:00 -0700259 WITH_INCREMENTAL_EVTO_UPDATE \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000260 JUST_K8S \
261 DEPLOY_K8S \
262 INSTALL_ONOS_APPS \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000263 INSTALL_KUBECTL \
264 INSTALL_HELM \
David Bainbridge7f8bf992020-04-08 21:53:22 -0700265 HELM_USE_UPGRADE \
David Bainbridge46505fb2019-10-01 21:13:20 +0000266 UPDATE_HELM_REPOS \
David Bainbridge4f1b5562019-08-19 04:46:52 +0000267 WAIT_ON_DOWN \
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700268 VOLTHA_DOWN_ON_TIMEOUT \
Matteo Scandoloc2eb0672020-05-01 14:43:15 -0700269 LEGACY_BBSIM_INDEX \
David Bainbridgee4d11ca2020-05-08 10:21:10 -0700270 SCHEDULE_ON_CONTROL_NODES \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000271 "
David Bainbridge5b7b96b2019-07-25 20:29:13 +0000272
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700273OPT_YES_NO="\
274 CONFIG_SADIS \
275 WITH_KAFKA \
276 WITH_RADIUS \
277 WITH_ETCD \
278 WITH_ONOS \
279 "
280
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000281ALL_OPTIONS="\
282 NAME \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000283 $ALL_YES_NO \
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700284 $OPT_YES_NO \
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700285 WAIT_TIMEOUT \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000286 VOLTHA_LOG_LEVEL \
287 VOLTHA_CHART \
David Bainbridge90fd8e32019-08-21 23:32:47 +0000288 VOLTHA_CHART_VERSION \
289 VOLTHA_BBSIM_CHART \
290 VOLTHA_BBSIM_CHART_VERSION \
David Bainbridge879439b2020-06-12 15:59:35 -0700291 BBSIM_SADIS_SERVER_CHART \
292 BBSIM_SADIS_SERVER_CHART_VERSION \
uottrembd5a20572020-03-06 09:15:01 +0100293 NUM_OF_BBSIM \
Matteo Scandolo657e13c2020-07-28 11:41:42 -0700294 NUM_OF_WORKER_NODES \
295 NUM_OF_CONTROLLER_NODES \
296 NUM_OF_KAFKA \
297 NUM_OF_ETCD \
divyadesai59f987a2020-05-27 12:11:33 +0000298 ELASTICSEARCH_CHART \
299 ELASTICSEARCH_CHART_VERSION \
300 KIBANA_CHART \
301 KIBANA_CHART_VERSION \
302 FLUENTD_ELASTICSEARCH_CHART \
303 FLUENTD_ELASTICSEARCH_CHART_VERSION \
Matteo Scandolo67335f02020-04-09 11:19:53 -0700304 NUM_OF_OPENONU \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000305 VOLTHA_ADAPTER_SIM_CHART \
David Bainbridge90fd8e32019-08-21 23:32:47 +0000306 VOLTHA_ADAPTER_SIM_CHART_VERSION \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000307 VOLTHA_ADAPTER_OPEN_OLT_CHART \
David Bainbridge90fd8e32019-08-21 23:32:47 +0000308 VOLTHA_ADAPTER_OPEN_OLT_CHART_VERSION \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000309 VOLTHA_ADAPTER_OPEN_ONU_CHART \
David Bainbridge90fd8e32019-08-21 23:32:47 +0000310 VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION \
David K. Bainbridgeda33d652020-03-06 10:31:23 -0800311 ONOS_CHART \
Andrea Campanella21323292019-12-18 11:44:19 -0800312 ONOS_CHART_VERSION \
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700313 ONOS_CLASSIC_CHART \
314 ONOS_CLASSIC_CHART_VERSION \
David Bainbridgecf546362020-04-21 23:18:50 -0700315 KAFKA_CHART \
David Bainbridgeb9093522020-04-15 14:32:44 -0700316 KAFKA_CHART_VERSION \
David Bainbridge879439b2020-06-12 15:59:35 -0700317 ETCD_CHART \
318 ETCD_CHART_VERSION \
319 RADIUS_CHART \
320 RADIUS_CHART_VERSION \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000321 ONOS_API_PORT \
322 ONOS_SSH_PORT \
Hardik Windlassb3147602020-03-09 16:59:15 +0530323 SADIS_CFG \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000324 VOLTHA_API_PORT \
325 VOLTHA_SSH_PORT \
326 VOLTHA_ETCD_PORT \
divyadesai59f987a2020-05-27 12:11:33 +0000327 ELASTICSEARCH_PORT \
328 KIBANA_PORT \
David K. Bainbridge00ecd382020-02-28 12:31:58 -0800329 VOLTHA_KAFKA_PORT \
Matteo Scandoloefee0432020-05-05 13:56:20 -0700330 VOLTHA_PPROF_PORT \
331 OPENOLT_PPROF_PORT \
Matteo Scandolo65c35192020-05-13 10:41:21 -0700332 OFAGENT_PPROF_PORT \
David K. Bainbridge8f7f30b2020-01-08 13:06:16 -0800333 VK_RELEASE \
334 KIND_VERSION \
335 VOLTCTL_VERSION \
David Bainbridgea34993d2020-04-01 09:15:42 -0700336 HELM_VERSION \
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700337 NUM_OF_ONOS \
338 NUM_OF_ATOMIX \
David Bainbridge6ca40102020-04-08 11:30:40 -0700339 VOLTHA_NS \
340 ADAPTER_NS \
341 INFRA_NS \
342 BBSIM_NS \
David Bainbridge7db44002020-04-09 12:54:29 -0700343 SADIS_BANDWIDTH_PROFILES \
344 SADIS_SUBSCRIBERS \
David Bainbridgeb4bbde12020-06-25 14:46:36 -0700345 PF_ADDRESS \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000346 "
David Bainbridge01294952019-07-30 19:33:45 +0000347
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000348# Iterate over yes/no configuration options and validate
349for VAR in $ALL_YES_NO; do
David Bainbridged18f4942020-04-14 16:46:13 -0700350 eval "$VAR"="$(verify_yes_no "$VAR")"
351 if [ "$(eval echo "\$$VAR")" == "INVALID" ]; then
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000352 exit 1;
353 fi
354done
David Bainbridgeb270c202019-07-26 01:44:42 +0000355
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700356# Iterate over optional yes/no configuration options and
357# normalize values if they are truth values
358for VAR in $OPT_YES_NO; do
359 eval "$VAR"="$(normalize_yes_no "$VAR")"
360done
David Bainbridge15f6f232020-03-30 09:15:43 -0700361
Matteo Scandolo657e13c2020-07-28 11:41:42 -0700362# check number (range) of bbsim, max bbsim must not exceed 10 instances!
363# note: instances will be numbered from 0 to 9
364if [ "$1" == "up" ]; then
365 if [ "$NUM_OF_BBSIM" -lt 1 ]; then
366 >&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}"
367 exit 1
368 fi
369 if [ "$NUM_OF_BBSIM" -gt "$MAX_NUM_OF_BBSIM" ]; then
370 >&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}"
371 exit 1
372 fi
373
374 if [ "$NUM_OF_OPENONU" -lt 1 ]; then
375 >&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}"
376 exit 1
377 fi
378 if [ "$NUM_OF_OPENONU" -gt "$MAX_NUM_OF_OPENONU" ]; then
379 >&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}"
380 exit 1
381 fi
382
383 # check that NUM_OF_KAFKA, NUM_OF_ONOS, NUM_OF_ATOMIX, NUM_OF_ETCD is:
384 # <= NUM_OF_WORKER_NODES + 1 if SCHEDULE_ON_CONTROL_NODES == y
385 # <= NUM_OF_WORKER_NODES if SCHEDULE_ON_CONTROL_NODES == n
386 SCHEDULABLE_NODES=$NUM_OF_WORKER_NODES
387
388 if [ "$SCHEDULE_ON_CONTROL_NODES" == "yes" ]; then
389 SCHEDULABLE_NODES=$((NUM_OF_CONTROLLER_NODES+NUM_OF_WORKER_NODES))
390 fi
391
392 NODES="SCHEDULE_ON_CONTROL_NODES: $SCHEDULE_ON_CONTROL_NODES, SCHEDULABLE_NODES: $SCHEDULABLE_NODES, NUM_OF_CONTROLLER_NODES: $NUM_OF_CONTROLLER_NODES, NUM_OF_WORKER_NODES: $NUM_OF_WORKER_NODES"
393
394 if [ ! "$NUM_OF_KAFKA" -le "$SCHEDULABLE_NODES" ]; then
395 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} Invalid setting of KAFKA replicas. NUM_OF_KAFKA (${NUM_OF_KAFKA}) is greater than the available nodes ($NODES)${NORMAL}"
396 exit 1
397 fi
398
399 if [ ! "$NUM_OF_ETCD" -le "$SCHEDULABLE_NODES" ]; then
400 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} Invalid setting of ETCD replicas. NUM_OF_ETCD (${NUM_OF_ETCD}) is greater than the available nodes ($NODES)${NORMAL}"
401 exit 1
402 fi
403
404 if [ ! "$NUM_OF_ATOMIX" -le "$SCHEDULABLE_NODES" ]; then
405 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} Invalid setting of ATOMIX replicas. NUM_OF_ATOMIX (${NUM_OF_ATOMIX}) is greater than the available nodes ($NODES)${NORMAL}"
406 exit 1
407 fi
408
409 if [ ! "$NUM_OF_ONOS" -le "$SCHEDULABLE_NODES" ]; then
410 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} Invalid setting of ONOS replicas. NUM_OF_ONOS (${NUM_OF_ONOS}) is greater than the available nodes ($NODES)${NORMAL}"
411 exit 1
412 fi
413fi
414
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700415# normalize non-truth value options
416if is_in "$WITH_KAFKA" "e,external"; then
David Bainbridge76afd812020-04-06 09:53:52 -0700417 WITH_KAFKA="external"
418fi
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700419if is_in "$WITH_ETCD" "e,external"; then
David Bainbridge76afd812020-04-06 09:53:52 -0700420 WITH_ETCD="external"
421fi
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700422if is_in "$WITH_ONOS" "l,legacy"; then
423 WITH_ONOS="legacy"
424elif is_in "$WITH_ONOS" "c,classic"; then
425 WITH_ONOS="classic"
426elif is_in "$WITH_ONOS" "u,m,micro"; then
427 WITH_ONOS="micro"
David Bainbridge29c31cb2020-04-06 09:45:50 -0700428fi
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700429
430if [ "$WITH_ONOS" == "micro" ]; then
431 >&2 echo -e "${YELLOW}${BOLD}${ERROR}WARNING:${NORMAL}${YELLOW} The value specified as WITH_ONOS, '$WITH_ONOS', is not valid.${NORMAL}"
432 exit 1
David Bainbridge29c31cb2020-04-06 09:45:50 -0700433fi
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700434
435if is_in "$WITH_ONOS" "yes,classic"; then
436 # there is an extra utility required if we are using ONOS CLASSIC as
437 # the chart for classic specifies images differently
438 EXTRA_TOOLS+=" yq"
David Bainbridge76afd812020-04-06 09:53:52 -0700439fi
David Bainbridge696bc632020-04-05 21:49:37 -0700440
David Bainbridge22db5dd2020-05-26 12:21:21 -0700441if [ "$LEGACY_BBSIM_INDEX" == "no" ]; then
442 BBSIM_SADIS_SVC="bbsim0"
443else
444 BBSIM_SADIS_SVC="bbsim"
445fi
446
447SADIS_SUBSCRIBERS=${SADIS_SUBSCRIBERS:-http://$BBSIM_SADIS_SVC.$VOLTHA_NS.svc:50074/v2/subscribers/%s}
448SADIS_BANDWIDTH_PROFILES=${SADIS_BANDWIDTH_PROFILES:-http://$BBSIM_SADIS_SVC.$VOLTHA_NS.svc:50074/v2/bandwidthprofiles/%s}
449
David Bainbridged18f4942020-04-14 16:46:13 -0700450if [ "$HELM_USE_UPGRADE" == "yes" ]; then
David Bainbridge7f8bf992020-04-08 21:53:22 -0700451 _HELM_DESC="Upgrade/Install"
452else
453 _HELM_DESC="Install"
454fi
455
David K. Bainbridgeda33d652020-03-06 10:31:23 -0800456# Check for prerequiste tools
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700457TOOLS="curl sed jq $EXTRA_TOOLS"
David Bainbridged18f4942020-04-14 16:46:13 -0700458if [ "$DEPLOY_K8S" == "yes" ]; then
David K. Bainbridgeda33d652020-03-06 10:31:23 -0800459 TOOLS+=" docker"
460fi
461NOT_FOUND=""
462for T in $TOOLS; do
David Bainbridged18f4942020-04-14 16:46:13 -0700463 if [ -z "$(command -v "$T")" ]; then
David K. Bainbridgeda33d652020-03-06 10:31:23 -0800464 NOT_FOUND+=" $T"
465 fi
466done
467
David Bainbridged18f4942020-04-14 16:46:13 -0700468if [ -n "$NOT_FOUND" ]; then
David K. Bainbridgeda33d652020-03-06 10:31:23 -0800469 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} The following required tools where not found, please install them:$NOT_FOUND"
470 exit 1
471fi
472
David Bainbridged18f4942020-04-14 16:46:13 -0700473TIMEOUT_SECONDS="$(parseDuration "$WAIT_TIMEOUT")"
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700474
David Bainbridge0774b232019-08-02 06:37:19 +0000475mkdir -p .voltha
476touch .voltha/ports
David Bainbridged18f4942020-04-14 16:46:13 -0700477HAVE="$(grep "$NAME" .voltha/ports)"
David Bainbridge0774b232019-08-02 06:37:19 +0000478if [ "$HAVE X" == " X" ]; then
479 # Find free port prefix
480 START=81
481 while true; do
David Bainbridged18f4942020-04-14 16:46:13 -0700482 if [ "$(grep -c $START .voltha/ports)" -eq 0 ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000483 break
484 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700485 START="$((START + 1))"
David Bainbridge0774b232019-08-02 06:37:19 +0000486 done
David Bainbridged18f4942020-04-14 16:46:13 -0700487 DELTA="$((START - 81))"
David Bainbridgea2595422019-10-22 03:54:28 +0000488 ONOS_API_PORT=${ONOS_API_PORT:-${START}81}
489 ONOS_SSH_PORT=${ONOS_SSH_PORT:-${START}01}
David Bainbridged18f4942020-04-14 16:46:13 -0700490 VOLTHA_API_PORT=${VOLTHA_API_PORT:-5$((55 + DELTA))55}
491 VOLTHA_SSH_PORT=${VOLTHA_SSH_PORT:-$((50 + DELTA))22}
492 VOLTHA_ETCD_PORT=${VOLTHA_ETCD_PORT:-$((23 + DELTA))79}
493 VOLTHA_KAFKA_PORT=${VOLTHA_KAFKA_PORT:-$((90 + DELTA))92}
Matteo Scandoloefee0432020-05-05 13:56:20 -0700494 VOLTHA_PPROF_PORT=${VOLTHA_PPROF_PORT:-$((60 + DELTA))60}
495 OPENOLT_PPROF_PORT=${OPENOLT_PPROF_PORT:-$((60 + DELTA))61}
Matteo Scandolo65c35192020-05-13 10:41:21 -0700496 OFAGENT_PPROF_PORT=${OFAGENT_PPROF_PORT:-$((60 + DELTA))62}
divyadesai59f987a2020-05-27 12:11:33 +0000497 ELASTICSEARCH_PORT=${ELASTICSEARCH_PORT:-$((92 + DELTA))00}
498 KIBANA_PORT=${KIBANA_PORT:-$((56 + DELTA))01}
Test User01ed0642019-07-03 20:17:06 +0000499else
David Bainbridged18f4942020-04-14 16:46:13 -0700500 VALUES="$(echo "$HAVE" | sed -e 's/\s//g' | cut -d= -f2)"
501 ONOS_API_PORT=${ONOS_API_PORT:-$(echo "$VALUES" | cut -d, -f1)}
502 ONOS_SSH_PORT=${ONOS_SSH_PORT:-$(echo "$VALUES" | cut -d, -f2)}
503 VOLTHA_API_PORT=${VOLTHA_API_PORT:-$(echo "$VALUES" | cut -d, -f3)}
504 VOLTHA_SSH_PORT=${VOLTHA_SSH_PORT:-$(echo "$VALUES" | cut -d, -f4)}
505 VOLTHA_ETCD_PORT=${VOLTHA_ETCD_PORT:-$(echo "$VALUES" | cut -d, -f5)}
506 VOLTHA_KAFKA_PORT=${VOLTHA_KAFKA_PORT:-$(echo "$VALUES" | cut -d, -f6)}
Matteo Scandoloefee0432020-05-05 13:56:20 -0700507 VOLTHA_PPROF_PORT=${VOLTHA_PPROF_PORT:-$(echo "$VALUES" | cut -d, -f7)}
508 OPENOLT_PPROF_PORT=${OPENOLT_PPROF_PORT:-$(echo "$VALUES" | cut -d, -f8)}
Matteo Scandolo65c35192020-05-13 10:41:21 -0700509 OFAGENT_PPROF_PORT=${OFAGENT_PPROF_PORT:-$(echo "$VALUES" | cut -d, -f9)}
divyadesai59f987a2020-05-27 12:11:33 +0000510 ELASTICSEARCH_PORT=${ELASTICSEARCH_PORT:-$(echo "$VALUES" | cut -d, -f10)}
511 KIBANA_PORT=${KIBANA_PORT:-$(echo "$VALUES" | cut -d, -f11)}
David K. Bainbridge00ecd382020-02-28 12:31:58 -0800512
Matteo Scandoloefee0432020-05-05 13:56:20 -0700513 # Some ports were added after the .voltha/ports files was created.
514 # Calculate the original DELTA from the VOLTHA_SSH_PORT so that it can
515 # be used to set up newer port-forwards.
516 DELTA="$((VOLTHA_SSH_PORT/100-50))"
517
David K. Bainbridge00ecd382020-02-28 12:31:58 -0800518 if [ -z "$VOLTHA_KAFKA_PORT" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -0700519 VOLTHA_KAFKA_PORT=${VOLTHA_KAFKA_PORT:-$((90 + DELTA))92}
David K. Bainbridge00ecd382020-02-28 12:31:58 -0800520 fi
Matteo Scandoloefee0432020-05-05 13:56:20 -0700521
522 if [ -z "$VOLTHA_PPROF_PORT" ]; then
divyadesai59f987a2020-05-27 12:11:33 +0000523 VOLTHA_PPROF_PORT=${VOLTHA_PPROF_PORT:-$((60 + DELTA))60}
Matteo Scandoloefee0432020-05-05 13:56:20 -0700524 fi
525 if [ -z "$OPENOLT_PPROF_PORT" ]; then
divyadesai59f987a2020-05-27 12:11:33 +0000526 OPENOLT_PPROF_PORT=${OPENOLT_PPROF_PORT:-$((60 + DELTA))61}
Matteo Scandoloefee0432020-05-05 13:56:20 -0700527 fi
Matteo Scandolo65c35192020-05-13 10:41:21 -0700528 if [ -z "$OFAGENT_PPROF_PORT" ]; then
divyadesai59f987a2020-05-27 12:11:33 +0000529 OFAGENT_PPROF_PORT=${OFAGENT_PPROF_PORT:-$((60 + DELTA))62}
530 fi
531
532 if [ -z "$ELASTICSEARCH_PORT" ]; then
533 ELASTICSEARCH_PORT=${ELASTICSEARCH_PORT:-$((92 + DELTA))00}
534 fi
535
536 if [ -z "$KIBANA_PORT" ]; then
537 KIBANA_PORT=${KIBANA_PORT:-$((56 + DELTA))01}
Matteo Scandolo65c35192020-05-13 10:41:21 -0700538 fi
Test User01ed0642019-07-03 20:17:06 +0000539fi
540
David Bainbridged18f4942020-04-14 16:46:13 -0700541PORTTMP="$(mktemp -u)"
542grep -v "$NAME" .voltha/ports > "$PORTTMP"
divyadesai59f987a2020-05-27 12:11:33 +0000543echo "$NAME=$ONOS_API_PORT,$ONOS_SSH_PORT,$VOLTHA_API_PORT,$VOLTHA_SSH_PORT,$VOLTHA_ETCD_PORT,$VOLTHA_KAFKA_PORT,$VOLTHA_PPROF_PORT,$OPENOLT_PPROF_PORT,$OFAGENT_PPROF_PORT,$ELASTICSEARCH_PORT,$KIBANA_PORT" >> "$PORTTMP"
David Bainbridged18f4942020-04-14 16:46:13 -0700544cp "$PORTTMP" .voltha/ports
545rm -f "$PORTTMP"
David Bainbridge0774b232019-08-02 06:37:19 +0000546
David Bainbridge27790d62019-08-13 22:43:19 +0000547export ONOS_API_PORT ONOS_SSH_PORT
David Bainbridge01294952019-07-30 19:33:45 +0000548
Test Userd87942b2019-07-03 07:20:24 +0000549IDX=1
David Bainbridgee87067b2019-08-12 22:00:12 +0000550CLOCK="TIME:"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000551SPIN_PARTS=
552NOT_VERIFIED=
David Bainbridgef858a022019-08-14 21:25:11 +0000553THEX=
554BUILD=
David Bainbridge38dc1e82019-08-12 15:18:45 +0000555VERIFIED=
556HELM=
557OLD_KEY=
558BIRD=
559HIGH_VOLTAGE=
560PLUG=
David Bainbridge38dc1e82019-08-12 15:18:45 +0000561FORWARD=
David Bainbridge38dc1e82019-08-12 15:18:45 +0000562GO=
563DOWNLOAD=
564GEAR=
565NO_ENTRY=
566LOCK=
567
David Bainbridged18f4942020-04-14 16:46:13 -0700568if [ "$FANCY" -eq 1 ]; then
569 SPIN_PARTS="\xe2\xa2\x8e\xe2\xa1\xb0 \xe2\xa2\x8e\xe2\xa1\xa1 \xe2\xa2\x8e\xe2\xa1\x91 \xe2\xa2\x8e\xe2\xa0\xb1 \xe2\xa0\x8e\xe2\xa1\xb1 \xe2\xa2\x8a\xe2\xa1\xb1 \xe2\xa2\x8c\xe2\xa1\xb1 \xe2\xa2\x86\xe2\xa1\xb1"
David Bainbridgee87067b2019-08-12 22:00:12 +0000570 CLOCK="\xe2\x8f\xb1"
David Bainbridgef858a022019-08-14 21:25:11 +0000571 THEX="${RED}${BOLD}\xe2\x9c\x97\x20${NORMAL}"
David Bainbridgef858a022019-08-14 21:25:11 +0000572 BUILD="${YELLOW}${BOLD}\xf0\x9f\x8f\x97${NORMAL}"
573 NOT_VERIFIED="$BUILD"
574 VERIFIED="${GREEN}${BOLD}\xe2\x9c\x93\x20${NORMAL}"
575 HELM="${BLUE}${BOLD}\xE2\x8E\x88${NORMAL}"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000576 OLD_KEY="\xF0\x9F\x97\x9D"
577 BIRD="\xF0\x9F\x90\xA6"
578 HIGH_VOLTAGE="\xE2\x9A\xA1"
579 PLUG="\xF0\x9F\xa7\xa9"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000580 FORWARD="\xE2\x87\xA8"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000581 GO="\xf0\x9f\x9a\x80"
582 DOWNLOAD="\xf0\x9f\x93\xa5"
583 GEAR="\xe2\x9a\x99"
584 NO_ENTRY="\xe2\x9b\x94"
585 LOCK="\xf0\x9f\x94\x92"
586fi
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700587
David Bainbridge712afb82019-08-14 19:55:58 +0000588duration() {
David Bainbridged18f4942020-04-14 16:46:13 -0700589 local h m s t
590 h="$(($1 / 3600))"
591 m="$(($1 % 3600 / 60))"
592 s="$(($1 % 60))"
593 t=""
David Bainbridgee87067b2019-08-12 22:00:12 +0000594
David Bainbridged18f4942020-04-14 16:46:13 -0700595 if [ "$h" -gt 0 ]; then
David Bainbridgee87067b2019-08-12 22:00:12 +0000596 t="$t${h}h"
597 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700598 if [ "$m" -gt 0 ]; then
David Bainbridgee87067b2019-08-12 22:00:12 +0000599 t="$t${m}m"
600 fi
David Bainbridge712afb82019-08-14 19:55:58 +0000601 echo "$t${s}s"
602}
603
604printtime() {
David Bainbridged18f4942020-04-14 16:46:13 -0700605 local INDENT
David Bainbridge712afb82019-08-14 19:55:58 +0000606 if [ "$1" == "-" ]; then
607 INDENT=" "
608 shift
609 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700610 echo -e "$INDENT $CLOCK $(duration "$1")"
David Bainbridgee87067b2019-08-12 22:00:12 +0000611}
612
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700613bspin() {
Test Userd87942b2019-07-03 07:20:24 +0000614 IDX=1
David Bainbridged18f4942020-04-14 16:46:13 -0700615 local INDENT
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700616 if [ "$1" == "-" ]; then
617 INDENT=" "
618 shift
619 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700620 if [ "$FANCY" -eq 0 ]; then
621 LINE="${*//[[:space:]+-]}"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000622 if [ "$LINE X" == " X" ]; then
623 return
624 fi
625 echo -e "$CIVIS$INDENT$*"
626 else
627 echo -en "$CIVIS$INDENT $*"
628 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700629}
630
631sspin() {
David Bainbridged18f4942020-04-14 16:46:13 -0700632 local INDENT
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700633 if [ "$1" == "-" ]; then
634 INDENT=" "
635 shift
636 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700637 if [ "$FANCY" -eq 0 ]; then
638 LINE="${*//[[:space:]+-]}"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000639 if [ "$LINE X" == " X" ]; then
640 return
641 fi
642 echo -e "$INDENT$*"
643 else
David Bainbridged18f4942020-04-14 16:46:13 -0700644 C="$(echo "$SPIN_PARTS" | cut '-d ' -f "$IDX")"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000645 echo -en "\r$INDENT$C $*"
David Bainbridged18f4942020-04-14 16:46:13 -0700646 IDX="$((IDX + 1))"
647 if [ "$IDX" -gt 8 ]; then
David Bainbridge38dc1e82019-08-12 15:18:45 +0000648 IDX=1
649 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700650 fi
651}
652
653espin() {
David Bainbridged18f4942020-04-14 16:46:13 -0700654 local INDENT
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700655 if [ "$1" == "-" ]; then
656 INDENT=" "
657 shift
658 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700659 if [ "$FANCY" -eq 0 ]; then
660 LINE="${*//[[:space:]+-]}"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000661 if [ "$LINE X" == " X" ]; then
662 return
663 fi
664 echo -e "$INDENT$*"
665 else
666 echo -e "\r$INDENT$*$CNORM"
667 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700668}
669
David Bainbridged18f4942020-04-14 16:46:13 -0700670if [ "$1" == "get" ] && [ "$2" == "voltconfig" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000671 echo "$HOME/.volt/config-$NAME"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000672 exit
673fi
674
David Bainbridgee4d11ca2020-05-08 10:21:10 -0700675if [ $# -ne 1 ] || ! is_in "$1" "up,down,dump,clean"; then
David Bainbridgeac7f8072019-08-01 22:15:33 +0000676 >&2 echo "What wouild you like to do today:"
677 >&2 echo " up - bring up voltha"
678 >&2 echo " down - tear down voltha"
679 >&2 echo " dump - create a debug dump of running system"
680 exit 1
681fi
682
divyadesai59f987a2020-05-27 12:11:33 +0000683do_curl() {
684 local DATA_ARGS CREDS CMD_ECHO CMD_OUTPUT SC_OUTPUT WAIT_START INDENTA EXTRAA NOW
685 local INDENT=$1
686 local OP=$2
687 local USER=$3
688 local PASS=$4
689 local URL=$5
690 local DATA_TYPE=$6
691 local DATA=$7
692 local MSG=$8
693 local VALID_RESULTS=$9
694 local EXTRA=${10}
695 local ICON=${11}
696
697 # Turn into an array for passing
698 INDENTA=()
699 if [ -n "$INDENT" ]; then
700 INDENTA=("$INDENT")
701 fi
702 IFS=' ' read -r -a EXTRAA <<< "$EXTRA"
David Bainbridge4f1b5562019-08-19 04:46:52 +0000703
David K. Bainbridgeb4b163b2020-02-19 15:55:06 -0800704 # Thanks to the latest version of ONOS using the return code 207 this gets a
705 # whole lot nastier. Can't thank them enough for doing this. So in order to
706 # capture the command and the output in the log file as well as capture the
707 # status code to verify it is 200 and not 207 mutltiple files and a bit of
708 # hackery must be used. Thanks again ONOS.
David Bainbridged18f4942020-04-14 16:46:13 -0700709 CMD_ECHO="$(mktemp -u)"
710 CMD_OUTPUT="$(mktemp -u)"
711 SC_OUTPUT="$(mktemp -u)"
712 WAIT_START="$(date +%s)"
David K. Bainbridgeb4b163b2020-02-19 15:55:06 -0800713
divyadesai59f987a2020-05-27 12:11:33 +0000714 CREDS=()
715 if [ -n "$USER" ]; then
716 CREDS=("--user" "$USER:$PASS")
717 fi
718
719 DATA_ARGS=()
720 if [ -n "$DATA" ]; then
721 if [ "$DATA_TYPE" == "file" ]; then
722 DATA_ARGS=("--data" "@$DATA")
723 elif [ "$DATA_TYPE" == "json" ]; then
724 DATA_ARGS=("--data" "$DATA")
725 fi
726 fi
727
728 bspin "${INDENTA[@]}" "$MSG" "$ICON"
David Bainbridge4f1b5562019-08-19 04:46:52 +0000729 while true; do
David Bainbridged18f4942020-04-14 16:46:13 -0700730 NOW="$(date +%s)"
731 if [ "$((NOW - WAIT_START))" -gt "$TIMEOUT_SECONDS" ]; then
divyadesai59f987a2020-05-27 12:11:33 +0000732 espin "${INDENTA[@]}" "$THEX"
David Bainbridged18f4942020-04-14 16:46:13 -0700733 rm -f "$CMD_ECHO" "$CMD_OUTPUT" "$SC_OUTPUT"
divyadesai59f987a2020-05-27 12:11:33 +0000734 doTimeout "$MSG"
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700735 fi
divyadesai59f987a2020-05-27 12:11:33 +0000736 (set -x; curl -sSL "${CREDS[@]}" -w "%{http_code}" -o "$CMD_OUTPUT" -X "$OP" "${EXTRAA[@]}" "$URL" "${DATA_ARGS[@]}" >"$SC_OUTPUT" 2>/dev/null) >>"$CMD_ECHO" 2>&1
737 RESULT=$?
David K. Bainbridgeb4b163b2020-02-19 15:55:06 -0800738 # Dump everything to the log
David Bainbridged18f4942020-04-14 16:46:13 -0700739 cat "$CMD_ECHO" >> "$LOG"
740 test -r "$CMD_OUTPUT" && cat "$CMD_OUTPUT" >> "$LOG"
741 SC="$(cat "$SC_OUTPUT")"
742 echo "RESPONSE CODE: $SC" >> "$LOG"
743 echo "ERROR CODE: $RESULT" >> "$LOG"
David K. Bainbridgeb4b163b2020-02-19 15:55:06 -0800744
745 # clean up temp files
David Bainbridged18f4942020-04-14 16:46:13 -0700746 rm -f "$CMD_ECHO" "$CMD_OUTPUT" "$SC_OUTPUT"
divyadesai59f987a2020-05-27 12:11:33 +0000747 if [ "$RESULT" -eq 0 ] && is_in "$SC" "$VALID_RESULTS"; then
David Bainbridge4f1b5562019-08-19 04:46:52 +0000748 break
749 fi
Matteo Scandolo9a77a732020-01-09 14:24:12 -0800750 sleep 1
divyadesai59f987a2020-05-27 12:11:33 +0000751 sspin "${INDENTA[@]}"
David Bainbridge4f1b5562019-08-19 04:46:52 +0000752 done
divyadesai59f987a2020-05-27 12:11:33 +0000753 espin "${INDENTA[@]}" "$VERIFIED"
754}
755
756push_onos_config() {
757 local DATA_TYPE=$1
758 local MSG=$2
759 local RESOURCE=$3
760 local DATA=$4
761
762 do_curl "-" "POST" "karaf" "karaf" "http://$_ONOS_API_EP/onos/v1/$RESOURCE" "$DATA_TYPE" "$DATA" "$MSG" "200" "--fail -H Content-Type:application/json" "$GEAR"
David Bainbridge4f1b5562019-08-19 04:46:52 +0000763}
764
Matteo Scandolo9a77a732020-01-09 14:24:12 -0800765check_onos_app_active() {
David Bainbridged18f4942020-04-14 16:46:13 -0700766 local APP_ID WAIT_START RESULT NOW
767 APP_ID=$1
768 WAIT_START="$(date +%s)"
Matteo Scandolo9a77a732020-01-09 14:24:12 -0800769
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700770 bspin - "Checking that $APP_ID is active $CLOCK"
771 while true; do
David Bainbridged18f4942020-04-14 16:46:13 -0700772 NOW="$(date +%s)"
773 if [ "$((NOW - WAIT_START))" -gt "$TIMEOUT_SECONDS" ]; then
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700774 espin - "$THEX"
775 doTimeout "waiting for ONOS application activation '$APP_ID'"
776 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700777 if (set -x; curl --fail -sSL --user karaf:karaf -X GET "http://$_ONOS_API_EP/onos/v1/applications/$APP_ID" | grep ACTIVE >>"$LOG" 2>&1) >>"$LOG" 2>&1; then
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700778 break
779 fi
780 sleep 1
781 sspin -
782 done
783 sleep 5 # OSGI components take a little longer that the app to activate
David Bainbridged18f4942020-04-14 16:46:13 -0700784 espin - "$VERIFIED"
Matteo Scandolo9a77a732020-01-09 14:24:12 -0800785}
786
David Bainbridge4f1b5562019-08-19 04:46:52 +0000787override_onos_app() {
David Bainbridged18f4942020-04-14 16:46:13 -0700788 local APP NAME WAIT_START NOW
789 APP=$1
790 NAME="$(basename "$APP" | sed -e 's/^[0-9][0-9]*-//g' -e 's/-.*$//g')"
791 WAIT_START="$(date +%s)"
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700792
David Bainbridge4f1b5562019-08-19 04:46:52 +0000793 while true; do
David Bainbridged18f4942020-04-14 16:46:13 -0700794 NOW="$(date +%s)"
795 if [ "$((NOW - WAIT_START))" -gt "$TIMEOUT_SECONDS" ]; then
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700796 espin - "$THEX"
797 doTimeout "waiting to overwrite ONOS application '$APP'"
798 fi
David Bainbridge4f1b5562019-08-19 04:46:52 +0000799 sspin -
800 # Attempt to delete old version (if it exists)
David Bainbridged18f4942020-04-14 16:46:13 -0700801 (set -x; curl --fail -sSL --user karaf:karaf -X DELETE "http://$_ONOS_API_EP/onos/v1/applications/$NAME" >>"$LOG" 2>&1) >>"$LOG" 2>&1
802 RESULT=$?
David Bainbridge4f1b5562019-08-19 04:46:52 +0000803 sspin -
David Bainbridged18f4942020-04-14 16:46:13 -0700804 if [ $RESULT -ne 0 ]; then
David Bainbridge4f1b5562019-08-19 04:46:52 +0000805 continue
806 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700807 if (set -x; curl --fail -sSL --user karaf:karaf -X POST -H Content-Type:application/octet-stream "http://$_ONOS_API_EP/onos/v1/applications?activate=true" --data-binary "@$APP" >>"$LOG" 2>&1) >>"$LOG" 2>&1; then
David Bainbridge4f1b5562019-08-19 04:46:52 +0000808 break
809 fi
810 sleep .2
811 done
812}
813
814activate_onos_app() {
David Bainbridged18f4942020-04-14 16:46:13 -0700815 local MSG APP WAIT_START NOW
816 MSG="$1"
817 APP=$2
818 WAIT_START="$(date +%s)"
David Bainbridge4f1b5562019-08-19 04:46:52 +0000819
820 bspin - "$MSG $GO"
821 while true; do
David Bainbridged18f4942020-04-14 16:46:13 -0700822 NOW="$(date +%s)"
823 if [ "$((NOW - WAIT_START))" -gt "$TIMEOUT_SECONDS" ]; then
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700824 espin - "$THEX"
825 doTimeout "waiting to activate ONOS application '$APP'"
826 fi
David Bainbridge4f1b5562019-08-19 04:46:52 +0000827 sspin -
David Bainbridged18f4942020-04-14 16:46:13 -0700828 if (set -x; curl --fail -sSL --user karaf:karaf -X POST "http://$_ONOS_API_EP/onos/v1/applications/$APP/active" >>"$LOG" 2>&1) >>"$LOG" 2>&1; then
David Bainbridge4f1b5562019-08-19 04:46:52 +0000829 break
830 fi
831 sleep .2
832 done
833 espin - "$VERIFIED"
834}
835
836count_pods() {
David Bainbridged18f4942020-04-14 16:46:13 -0700837 local NAMESPACE STATES LABELS CMD PODS
838 NAMESPACE=$1; shift
David Bainbridge4f1b5562019-08-19 04:46:52 +0000839 if [ "$NAMESPACE" == "all-namespaces" ]; then
840 NAMESPACE="--all-namespaces"
841 else
842 NAMESPACE="-n $NAMESPACE"
843 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700844 STATES=$1; shift
845 LABELS=$1; shift
846 CMD=("kubectl get $NAMESPACE $LABELS pod")
847 PODS=$(${CMD[*]} -o go-template="{{range .items}}{{.metadata.name}}/{{.status.phase}}/_{{range .status.containerStatuses}}{{.ready}}_{{end}} {{end}}")
David Bainbridge4f1b5562019-08-19 04:46:52 +0000848 local COUNT=0
849 local PATTERNS="$*"
850 for POD in $PODS; do
David Bainbridged18f4942020-04-14 16:46:13 -0700851 local NAME STATE CONTAINERS TOTAL FOUND
852 NAME="$(echo "$POD" | cut -d/ -f 1)"
853 STATE="$(echo "$POD" | cut -d/ -f 2)"
854 CONTAINERS="$(echo "$POD" | cut -d/ -f 3 | sed -e 's/_/ /g')"
855 if [ "$STATES" == "*" ] || [ "$(echo "$STATES" | grep -c ":$STATE:")" -ne 0 ]; then
856 TOTAL="$(echo "$CONTAINERS" | wc -w)"
857 FOUND="$(echo "$CONTAINERS" | grep -o true | wc -l)"
858 if [ "$TOTAL" -eq "$FOUND" ]; then
David Bainbridge4f1b5562019-08-19 04:46:52 +0000859 for PATTERN in $PATTERNS; do
David Bainbridged18f4942020-04-14 16:46:13 -0700860 if [[ "$NAME" =~ $PATTERN ]]; then
861 COUNT="$((COUNT + 1))"
David Bainbridge4f1b5562019-08-19 04:46:52 +0000862 break
863 fi
864 done
865 fi
866 fi
867 done
David Bainbridge4f1b5562019-08-19 04:46:52 +0000868 echo $COUNT
869}
870
871wait_for_pods() {
David Bainbridged18f4942020-04-14 16:46:13 -0700872 local INDENT NAMESPACE EXPECT TYPE MESSAGE LABELS PATTERNS STATES HAVE ALL WAIT_START NOW
David Bainbridge4f1b5562019-08-19 04:46:52 +0000873 if [ "$1" == "-" ]; then
874 INDENT=$1; shift
875 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700876 NAMESPACE=$1; shift
877 EXPECT=$1; shift
878 TYPE=$1; shift
879 MESSAGE=$1; shift
880 LABELS=$1; shift
881 PATTERNS=("$*")
882 STATES=":Running:"
David Bainbridge99ac7a22019-08-31 02:26:43 +0000883 if [ "$TYPE" == "not" ]; then
884 STATES="*"
885 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700886 HAVE="$(count_pods "$NAMESPACE" "$STATES" "$LABELS" "${PATTERNS[@]}")"
887 ALL=$HAVE
David Bainbridge4f1b5562019-08-19 04:46:52 +0000888 if [ "$TYPE" == "only" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -0700889 ALL="$(count_pods "all-namespaces" "*" ".*")"
David Bainbridge4f1b5562019-08-19 04:46:52 +0000890 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700891 COUNT="$((300 / 15))"
892 WAIT_START="$(date +%s)"
893 bspin "$INDENT" "$MESSAGE"
894 sspin "$INDENT"
895 if [ "$HAVE" -ne "$EXPECT" ] || [ "$ALL" -ne "$HAVE" ]; then
896 while [ "$HAVE" -ne "$EXPECT" ] || [ "$ALL" -ne "$HAVE" ]; do
897 NOW="$(date +%s)"
898 if [ "$((NOW - WAIT_START))" -gt "$TIMEOUT_SECONDS" ]; then
899 espin "$INDENT" "$THEX"
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700900 doTimeout "waiting for PODs to start"
901 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700902 sspin "$INDENT"
903 COUNT="$((COUNT - 1))"
904 if [ "$COUNT" -eq 0 ]; then
905 HAVE="$(count_pods "$NAMESPACE" "$STATES" "$LABELS" "${PATTERNS[@]}")"
906 ALL="$HAVE"
David Bainbridge4f1b5562019-08-19 04:46:52 +0000907 if [ "$TYPE" == "only" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -0700908 ALL="$(count_pods "all-namespaces" "*" ".*")"
David Bainbridge4f1b5562019-08-19 04:46:52 +0000909 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700910 COUNT="$((300 / 15))"
David Bainbridge4f1b5562019-08-19 04:46:52 +0000911 fi
912 sleep .15
913 done
914 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700915 espin "$INDENT" "$VERIFIED"
916 if [ "$HAVE" -ne "$EXPECT" ]; then
David Bainbridge4f1b5562019-08-19 04:46:52 +0000917 return 1
918 fi
919 return 0
920}
921
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800922port_forward() {
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700923 local NS=$1; shift
924 local SVC=$1; shift
925 local PORTS="$*"
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800926 local TAG=$SVC-$NAME
927
David Bainbridgeb4bbde12020-06-25 14:46:36 -0700928 (set -x; _TAG="$TAG" bash -c "while true; do kubectl port-forward --address $PF_ADDRESS -n $NS service/$SVC $PORTS; done" >>"$PFLOG" 2>&1 &) >>"$PFLOG" 2>&1
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800929}
930
931kill_port_forward() {
David Bainbridge1d2c5842020-06-03 15:29:07 -0700932 local TAG P_IDS PARENTS KIDS UNKNOWN PP_ID PF
933
934 while [ $# -gt 0 ]; do
935 PF=$1; shift
936 TAG=
937 if [ "$PF" != "__ALL__" ]; then
938 TAG="$PF-$NAME"
939 fi
940 PARENTS=
941 KIDS=
942 UNKNOWN=
943 # shellcheck disable=SC2009
944 P_IDS="$(ps e -ww -A | grep "_TAG=$TAG" | grep -v grep | awk '{print $1}')"
945 if [ -n "$P_IDS" ]; then
946 for P_ID in $P_IDS; do
947 PP_ID="$(ps -o ppid "$P_ID" | tail -n +2)"
948 if [ -n "$PP_ID" ]; then
949 if [ "$PP_ID" -eq 1 ]; then
950 PARENTS="$PARENTS $P_ID"
951 else
952 KIDS="$KIDS $P_ID"
953 fi
David Bainbridgec6871d22019-11-13 17:10:31 +0000954 else
David Bainbridge1d2c5842020-06-03 15:29:07 -0700955 UNKNOWN="$UNKNOWN $P_ID"
David Bainbridgec6871d22019-11-13 17:10:31 +0000956 fi
David Bainbridge1d2c5842020-06-03 15:29:07 -0700957 done
958 if [ -n "$PARENTS" ]; then
959 # shellcheck disable=SC2086
960 while ps -h $PARENTS >/dev/null 2>&1; do
961 (set -x; eval "kill -9 $PARENTS" >>"$LOG" 2>&1) >>"$LOG" 2>&1
962 done
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800963 fi
David Bainbridge1d2c5842020-06-03 15:29:07 -0700964 if [ -n "$KIDS" ]; then
965 # shellcheck disable=SC2086
966 while ps -h $KIDS >/dev/null 2>&1; do
967 (set -x; eval "kill -9 $KIDS" >>"$LOG" 2>&1) >>"$LOG" 2>&1
968 done
969 fi
970 if [ -n "$UNKNOWN" ]; then
971 # shellcheck disable=SC2086
972 while ps -h $UNKNOWN >/dev/null 2>&1; do
973 (set -x; eval "kill -9 $UNKNOWN" >>"$LOG" 2>&1) >>"$LOG" 2>&1
974 done
975 fi
976 fi
977 done
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800978}
979
David Bainbridgecf546362020-04-21 23:18:50 -0700980resolve_chart_version() {
981 [ "$2" != "latest" ] && echo "$2" && return
982 helm inspect chart "$1" | grep "^version:" | awk '{print $2}'
983}
984
Jonathan Hart6a91e6c2020-04-16 14:28:33 -0700985# Compares two semver-formatted version strings (e.g. 2.4.3)
986# Returns 0 if $1 == $2, returns 1 if $1 > $2 and returns 2 if $1 < $2
987compare_versions() {
988 [ "$1" == "$2" ] && return 0
Jonathan Hart6a91e6c2020-04-16 14:28:33 -0700989 local lowest
990 lowest=$(echo -e "$1\n$2" | sort -V | head -1)
991 [ "$lowest" == "$1" ] && return 2
992 return 1
993}
994
David Bainbridgeac7f8072019-08-01 22:15:33 +0000995if [ "$1" == "down" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000996 echo "Tearing down voltha cluster $NAME"
997 LOG="down-$NAME.log"
David Bainbridged18f4942020-04-14 16:46:13 -0700998 date -u +"%Y%m%dT%H%M%SZ" >"$LOG"
David Bainbridgeb4bbde12020-06-25 14:46:36 -0700999 HELM_MAJOR=$(helm version --client --short | sed -E -e 's/^.*v([0-9]+)\.[0-9]+\.[0-9]+.*$/\1/')
David Bainbridge60ffc0f2020-04-27 22:13:22 -07001000 if is_in "$WITH_ONOS" "yes,legacy,classic"; then
David Bainbridge696bc632020-04-05 21:49:37 -07001001 bspin "Remove port-forwards: onos-ui-$NAME"
1002 kill_port_forward onos-ui
1003 sspin "Remove port-forwards: onos-ssh-$NAME$CEOL"
1004 kill_port_forward onos-ssh
David Bainbridge60ffc0f2020-04-27 22:13:22 -07001005 bspin "Remove port-forwards: onos-onos-classic-hs-$NAME$CEOL"
1006 kill_port_forward onos-onos-classic-hs
David Bainbridge696bc632020-04-05 21:49:37 -07001007 fi
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -08001008 sspin "Remove port-forwards: voltha-api-$NAME$CEOL"
David Bainbridge1d2c5842020-06-03 15:29:07 -07001009 kill_port_forward voltha-api voltha-voltha-api
David Bainbridgec7220622020-05-28 12:31:47 -07001010 if is_in "$WITH_ETCD" "yes,external"; then
1011 sspin "Remove port-forwards: etcd-$NAME$CEOL"
1012 kill_port_forward "etcd"
David Bainbridge696bc632020-04-05 21:49:37 -07001013 fi
David Bainbridgec7220622020-05-28 12:31:47 -07001014 if is_in "$WITH_KAFKA" "yes,external"; then
1015 sspin "Remove port-forwards: kafka-$NAME$CEOL"
1016 kill_port_forward "kafka"
David Bainbridge696bc632020-04-05 21:49:37 -07001017 fi
Matteo Scandoloefee0432020-05-05 13:56:20 -07001018
1019 if [ "$WITH_PPROF" == "yes" ]; then
David Bainbridgec7220622020-05-28 12:31:47 -07001020 sspin "Remove port-forwards: *-profiler$CEOL"
David Bainbridge1d2c5842020-06-03 15:29:07 -07001021 kill_port_forward voltha-rw-core-profiler voltha-voltha-rw-core-profiler
1022 kill_port_forward voltha-of-agent-profiler voltha-voltha-of-agent-profiler
David Bainbridgec7220622020-05-28 12:31:47 -07001023 if [ "$WITH_OPEN_ADAPTERS" == "yes" ]; then
David Bainbridge1d2c5842020-06-03 15:29:07 -07001024 kill_port_forward adapter-open-olt-profiler open-olt-adapter-open-olt-profiler
David Bainbridgec7220622020-05-28 12:31:47 -07001025 fi
Matteo Scandoloefee0432020-05-05 13:56:20 -07001026 fi
1027
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -08001028 espin "$VERIFIED Remove port-forwards$CEOL"
David Bainbridged18f4942020-04-14 16:46:13 -07001029 if [ "$DEPLOY_K8S" == "yes" ]; then
David Bainbridgeac7f8072019-08-01 22:15:33 +00001030 if [ -x ./bin/kind ]; then
David Bainbridge0774b232019-08-02 06:37:19 +00001031 bspin "Delete Kubernetes Kind Cluster"
David Bainbridged18f4942020-04-14 16:46:13 -07001032 (set -x; ./bin/kind delete cluster --name "voltha-$NAME" >>"$LOG" 2>&1) >>"$LOG" 2>&1
1033 espin "$VERIFIED"
David Bainbridgeac7f8072019-08-01 22:15:33 +00001034 else
David Bainbridge0774b232019-08-02 06:37:19 +00001035 espin "$NO_ENTRY Delete Kubernetes Kind Cluster: kind command not found"
David Bainbridgeac7f8072019-08-01 22:15:33 +00001036 fi
1037 else
David Bainbridge309099c2020-05-05 08:47:29 -07001038 if [ "$CONFIG_SADIS" == "external" ]; then
1039 bspin "Remove configmap for BBSIM SADIS server"
1040 (set -x; kubectl -n "$BBSIM_NS" delete --ignore-not-found configmap kube-config >>"$LOG" 2>&1) >>"$LOG" 2>&1
1041 espin "$VERIFIED"
1042 fi
David Bainbridgeb4bbde12020-06-25 14:46:36 -07001043
1044 if [ "$HELM_MAJOR" -le 2 ]; then
1045 EXISTS=$(helm list --output json 2>/dev/null | jq -r '.Releases | .[] | .Name + "," + .Namespace')
1046 else
1047 EXISTS=$(helm list --all-namespaces --output json 2>/dev/null | jq -r '.[] | .name + "," + .namespace')
1048 fi
David Bainbridge76afd812020-04-06 09:53:52 -07001049 EXPECT="voltha"
David Bainbridge60ffc0f2020-04-27 22:13:22 -07001050 if is_in "$WITH_ONOS" "yes,legacy,classic"; then
David Bainbridge696bc632020-04-05 21:49:37 -07001051 EXPECT+=" onos"
1052 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001053 if [ "$WITH_RADIUS" == "yes" ]; then
David Bainbridge696bc632020-04-05 21:49:37 -07001054 EXPECT+=" radius"
1055 fi
David Bainbridge309099c2020-05-05 08:47:29 -07001056 if [ "$CONFIG_SADIS" == "external" ]; then
1057 EXPECT+=" bbsim-sadis-server"
1058 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001059 if [ "$WITH_BBSIM" == "yes" ]; then
David Bainbridge696bc632020-04-05 21:49:37 -07001060 EXPECT+=" bbsim"
1061 fi
divyadesai59f987a2020-05-27 12:11:33 +00001062 if [ "$WITH_EFK" == "yes" ]; then
1063 EXPECT+=" elasticsearch kibana fluentd"
1064 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001065 if [ "$WITH_OPEN_ADAPTERS" == "yes" ]; then
David Bainbridge696bc632020-04-05 21:49:37 -07001066 EXPECT+=" open-olt open-onu"
1067 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001068 if [ "$WITH_SIM_ADAPTERS" == "yes" ]; then
David Bainbridge696bc632020-04-05 21:49:37 -07001069 EXPECT+=" sim"
1070 fi
David Bainbridgec7220622020-05-28 12:31:47 -07001071 if is_in "$WITH_ETCD" "yes,external"; then
1072 EXPECT+=" etcd"
David Bainbridge76afd812020-04-06 09:53:52 -07001073 fi
David Bainbridgec7220622020-05-28 12:31:47 -07001074 if is_in "$WITH_KAFKA" "yes,external"; then
David Bainbridge76afd812020-04-06 09:53:52 -07001075 EXPECT+=" kafka"
1076 fi
David Bainbridge0774b232019-08-02 06:37:19 +00001077 bspin "Remove Helm Deployments"
David Bainbridgeac7f8072019-08-01 22:15:33 +00001078 for i in $EXISTS; do
David K. Bainbridge43422402020-03-06 07:41:22 -08001079 for j in $EXPECT; do
David Bainbridged18f4942020-04-14 16:46:13 -07001080 if [[ "$i" =~ $j ]]; then
David Bainbridgeb4bbde12020-06-25 14:46:36 -07001081 __NAME=$(echo "$i" | cut -d, -f1)
1082 __NS=$(echo "$i" | cut -d, -f2)
1083 sspin "Remove Helm Deployments: $__NS:$__NAME$CEOL"
1084 if [ "$HELM_MAJOR" -le 2 ]; then
1085 (set -x; helm delete --no-hooks --purge "$__NAME" >>"$LOG" 2>&1) >>"$LOG" 2>&1
1086 else
1087 (set -x; helm uninstall --no-hooks --namespace "$__NS" "$__NAME" >>"$LOG" 2>&1) >>"$LOG" 2>&1
1088 fi
David K. Bainbridge43422402020-03-06 07:41:22 -08001089 fi
1090 done
uottrembb16d3982020-02-28 08:34:36 +01001091 done
David Bainbridge0774b232019-08-02 06:37:19 +00001092 espin "$VERIFIED Remove Helm Deployments$CEOL"
David Bainbridge4f1b5562019-08-19 04:46:52 +00001093 if [ "$WAIT_ON_DOWN" == "yes" ]; then
Matteo Scandoloe93c9eb2020-06-03 12:08:51 -07001094 PODS="voltha-ofagent.* voltha-rw-core.*"
David Bainbridge76afd812020-04-06 09:53:52 -07001095 INFRA_PODS=
1096 ADAPT_PODS=
1097 SIM_PODS=
divyadesai59f987a2020-05-27 12:11:33 +00001098 EFK_PODS=
David Bainbridged18f4942020-04-14 16:46:13 -07001099 if [ "$WITH_RADIUS" == "yes" ]; then
David Bainbridge696bc632020-04-05 21:49:37 -07001100 PODS+=" radius.*"
1101 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001102 if [ "$WITH_BBSIM" == "yes" ]; then
David Bainbridge76afd812020-04-06 09:53:52 -07001103 SIM_PODS+=" bbsim.*"
David Bainbridge696bc632020-04-05 21:49:37 -07001104 fi
divyadesai59f987a2020-05-27 12:11:33 +00001105 if [ "$WITH_EFK" == "yes" ]; then
1106 EFK_PODS+=" kibana-* elasticsearch-* fluentd-*"
1107 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001108 if [ "$WITH_OPEN_ADAPTERS" ] || [ "$WITH_SIM_ADAPTERS" ]; then
David Bainbridge76afd812020-04-06 09:53:52 -07001109 ADAPT_PODS+=" adapter-*"
David Bainbridge696bc632020-04-05 21:49:37 -07001110 fi
David Bainbridge60ffc0f2020-04-27 22:13:22 -07001111 if is_in "$WITH_ONOS" "yes,legacy,classic"; then
David Bainbridge76afd812020-04-06 09:53:52 -07001112 INFRA_PODS+=" onos-.*"
1113 fi
David Bainbridgec7220622020-05-28 12:31:47 -07001114 if is_in "$WITH_ETCD" "yes,external"; then
1115 INFRA_PODS+=" etcd.*"
David Bainbridge76afd812020-04-06 09:53:52 -07001116 fi
David Bainbridgec7220622020-05-28 12:31:47 -07001117 if is_in "$WITH_KAFKA" "yes,external"; then
David Bainbridge76afd812020-04-06 09:53:52 -07001118 INFRA_PODS+=" kafka.*"
1119 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001120 if [ -n "$SIM_PODS" ]; then
1121 wait_for_pods "$BBSIM_NS" 0 "not" "Waiting for BBSIM PODs to terminate" "$BBSIM_LABEL" "$SIM_PODS"
David Bainbridge76afd812020-04-06 09:53:52 -07001122 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001123 if [ -n "$INFRA_PODS" ]; then
1124 wait_for_pods "$INFRA_NS" 0 "not" "Waiting for infrastructure PODs to terminate" "$NO_LABEL" "$INFRA_PODS"
David Bainbridge76afd812020-04-06 09:53:52 -07001125 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001126 if [ -n "$ADAPT_PODS" ]; then
1127 wait_for_pods "$ADAPTER_NS" 0 "not" "Waiting for adapter PODs to terminate" "$NO_LABEL" "$ADAPT_PODS"
David Bainbridge76afd812020-04-06 09:53:52 -07001128 fi
divyadesai59f987a2020-05-27 12:11:33 +00001129 if [ -n "$EFK_PODS" ]; then
1130 wait_for_pods "$INFRA_NS" 0 "not" "Waiting for EFK PODs to terminate" "$NO_LABEL" "$EFK_PODS"
1131 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001132 wait_for_pods "$VOLTHA_NS" 0 "not" "Waiting for VOLTHA PODs to terminate" "$NO_LABEL" "$PODS"
David Bainbridge4f1b5562019-08-19 04:46:52 +00001133 fi
David Bainbridgeac7f8072019-08-01 22:15:33 +00001134 fi
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001135 exit
David Bainbridgeac7f8072019-08-01 22:15:33 +00001136fi
1137
1138if [ "$1" == "dump" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +00001139 LOG="dump-$NAME.log"
David Bainbridged18f4942020-04-14 16:46:13 -07001140 TS="$(date -u +"%Y%m%dT%H%M%SZ")"
1141 if [ -n "$DUMP_FROM" ]; then
1142 TS=${DUMP_FROM//[:-]}
David Bainbridge76514a02019-10-08 01:50:35 +00001143 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001144 WORK="$(mktemp -u -d)"
David Bainbridge0774b232019-08-02 06:37:19 +00001145 DATA=$WORK/voltha-debug-dump-$NAME-$TS
David Bainbridged18f4942020-04-14 16:46:13 -07001146 mkdir -p "$DATA"
1147 echo "$TS" > "$LOG"
David Bainbridge0774b232019-08-02 06:37:19 +00001148 echo -e "Capturing debug dump to voltha-debug-dump-$NAME-$TS.tgz"
David Bainbridgeac7f8072019-08-01 22:15:33 +00001149 bspin - "Copy install log"
David Bainbridged18f4942020-04-14 16:46:13 -07001150 if [ -f "install-$NAME.log" ]; then
1151 (set -x; cp "install-$NAME.log" "$DATA/install-$NAME.log") >>"$LOG" 2>&1
1152 espin - "$VERIFIED"
David Bainbridgeac7f8072019-08-01 22:15:33 +00001153 else
David Bainbridge0774b232019-08-02 06:37:19 +00001154 espin - "$NO_ENTRY Copy install log: install-$NAME.log not found"
David Bainbridgeac7f8072019-08-01 22:15:33 +00001155 fi
1156 bspin - "Dumping Kubernetes PODs"
David Bainbridged18f4942020-04-14 16:46:13 -07001157 (set -x; kubectl get --all-namespaces pods >> "$DATA/all-pods.txt" 2>&1) >>"$LOG" 2>&1
1158 espin - "$VERIFIED"
David Bainbridgeac7f8072019-08-01 22:15:33 +00001159 bspin - "Dumping Kubernetes SERVICEs"
David Bainbridged18f4942020-04-14 16:46:13 -07001160 (set -x; kubectl get --all-namespaces svc >> "$DATA/all-services.txt" 2>&1) >>"$LOG" 2>&1
1161 espin - "$VERIFIED"
David Bainbridgeac7f8072019-08-01 22:15:33 +00001162 bspin - "Dumping Kubernetes EVENTs"
David Bainbridged18f4942020-04-14 16:46:13 -07001163 (set -x; kubectl get --all-namespaces events >> "$DATA/all-events.txt" 2>&1) >>"$LOG" 2>&1
1164 espin - "$VERIFIED"
David Bainbridgeac7f8072019-08-01 22:15:33 +00001165 bspin - "Dumping VOLTHA POD details"
David Bainbridged18f4942020-04-14 16:46:13 -07001166 PODS="$(kubectl -n "$INFRA_NS" get pod -o name | grep onos | sed -e "s/^/$INFRA_NS:/g") $(kubectl get -n "$VOLTHA_NS" pod -o name | sed -e "s/^/$VOLTHA_NS:/g")"
David Bainbridgecfd7ca12019-10-06 03:31:41 +00001167 SINCE=
David Bainbridged18f4942020-04-14 16:46:13 -07001168 if [ -n "$DUMP_FROM" ]; then
David Bainbridgecfd7ca12019-10-06 03:31:41 +00001169 SINCE="--since-time=$DUMP_FROM"
1170 fi
David Bainbridgeac7f8072019-08-01 22:15:33 +00001171 for POD in $PODS; do
David Bainbridged18f4942020-04-14 16:46:13 -07001172 NS="$(echo "$POD" | cut -d: -f1)"
1173 POD="$(echo "$POD" | cut -d: -f2)"
David Bainbridgeac7f8072019-08-01 22:15:33 +00001174 sspin - "Dumping VOLTHA POD details: $POD$CEOL"
David Bainbridged18f4942020-04-14 16:46:13 -07001175 mkdir -p "$DATA/$POD"
1176 (set -x; kubectl describe -n "$NS" "$POD" >> "$DATA/$POD/describe.txt" 2>&1) >>"$LOG" 2>&1
David Bainbridgeac7f8072019-08-01 22:15:33 +00001177 sspin - "Dumping VOLTHA POD details: $POD"
David Bainbridged18f4942020-04-14 16:46:13 -07001178 (set -x; kubectl logs -n "$NS" --all-containers "$SINCE" --previous "$LOG_ARGS" "$POD" >> "$DATA/$POD/logs-previous.txt" 2>&1) >>"$LOG" 2>&1
David Bainbridgeac7f8072019-08-01 22:15:33 +00001179 sspin - "Dumping VOLTHA POD details: $POD"
David Bainbridged18f4942020-04-14 16:46:13 -07001180 (set -x; kubectl logs -n "$NS" --all-containers "$SINCE" "$LOG_ARGS" "$POD" >> "$DATA/$POD/logs-current.txt" 2>&1) >>"$LOG" 2>&1
David Bainbridgeac7f8072019-08-01 22:15:33 +00001181 sspin - "Dumping VOLTHA POD details: $POD"
1182 done
1183 espin - "$VERIFIED Dumping VOLTHA POD details$CEOL"
1184 bspin - "Dumping ETCD"
David Bainbridged18f4942020-04-14 16:46:13 -07001185 if [ -n "$(command -v etcdctl)" ]; then
1186 (set -x; ETCDCTL_API=3 etcdctl --endpoints "localhost:$VOLTHA_ETCD_PORT" get --prefix service/voltha | hexdump -C >> "$DATA/etcd.hex" 2>&1) >>"$LOG" 2>&1
1187 espin - "$VERIFIED"
David Bainbridgeac7f8072019-08-01 22:15:33 +00001188 else
1189 espin - "$NO_ENTRY Dumping ETCD: etcdctl command not available"
1190 fi
David Bainbridge0774b232019-08-02 06:37:19 +00001191 bspin - "Creating compressed TAR: voltha-debug-dump-$NAME-$TS.tgz"
David Bainbridged18f4942020-04-14 16:46:13 -07001192 (set -x; tar -C "$WORK" -zcf "voltha-debug-dump-$NAME-$TS.tgz" "./voltha-debug-dump-$NAME-$TS") >>"$LOG" 2>&1
1193 espin - "$VERIFIED"
David Bainbridgeac7f8072019-08-01 22:15:33 +00001194 bspin - "Cleanup"
David Bainbridged18f4942020-04-14 16:46:13 -07001195 (set -x; rm -rf "$WORK") >>"$LOG" 2>&1
1196 espin - "$VERIFIED"
1197 bspin - "$(ls -l "voltha-debug-dump-$NAME-$TS.tgz")"
1198 espin - "$VERIFIED"
David Bainbridgeac7f8072019-08-01 22:15:33 +00001199 exit
1200fi
1201
David Bainbridge0774b232019-08-02 06:37:19 +00001202LOG="install-$NAME.log"
David Bainbridge1d2c5842020-06-03 15:29:07 -07001203PFLOG="port-forward-$NAME.log"
David Bainbridged18f4942020-04-14 16:46:13 -07001204date > "$LOG"
divyadesai59f987a2020-05-27 12:11:33 +00001205echo "PORTS=$ONOS_API_PORT,$ONOS_SSH_PORT,$VOLTHA_API_PORT,$VOLTHA_SSH_PORT,$VOLTHA_ETCD_PORT,$ELASTICSEARCH_PORT,$KIBANA_PORT" >> "$LOG"
David Bainbridgeac7f8072019-08-01 22:15:33 +00001206
1207# Output install options to log
David Bainbridged18f4942020-04-14 16:46:13 -07001208echo "OPTIONS" >> "$LOG"
David Bainbridgeac7f8072019-08-01 22:15:33 +00001209for O in $ALL_OPTIONS; do
David Bainbridged18f4942020-04-14 16:46:13 -07001210 VAL="$(eval echo "\$$O")"
1211 if [ -n "$VAL" ]; then
1212 printf " %-30s = %s\n" "$O" "$VAL" >> "$LOG"
David Bainbridgeac7f8072019-08-01 22:15:33 +00001213 fi
1214done
1215
David Bainbridgee4d11ca2020-05-08 10:21:10 -07001216# Force remove any existing k8s port-forward processes. This will
1217# remove them for all kind clusters.
David Bainbridgee4d11ca2020-05-08 10:21:10 -07001218if [ "$1" == "clean" ]; then
1219 kill_port_forward __ALL__
1220 exit
1221fi
1222
David Bainbridgefad50732020-05-01 17:00:12 -07001223helm_values() {
1224 local NAMESPACE=$1; shift
1225 local INAME=$1; shift
1226 local CHART=$1; shift
1227 local CHART_VERSION=$1; shift
1228
1229 if [ "$CHART_VERSION X" != " X" ] && [ "$CHART_VERSION" != "latest" ]; then
1230 CHART_VERSION="--version $CHART_VERSION"
1231 else
1232 CHART_VERSION=
1233 fi
1234
1235 local CHART_ARGS=
1236 if [ -r "${INAME}-values.yaml" ]; then
1237 CHART_ARGS="-f ${INAME}-values.yaml"
1238 fi
1239
1240 if [ "$HELM_USE_UPGRADE" == "yes" ]; then
1241 _HELM_COMMAND="upgrade --install"
1242 _HELM_ARGS="xxxdryrunxxx"
1243 else
1244 _HELM_COMMAND="install"
Matteo Scandolof2d080b2020-07-23 13:59:29 -07001245 if [ "$HELM_MAJOR" -le 2 ]; then
1246 _HELM_NAME_ARG="--name xxxdryrunxxx"
1247 _HELM_ARGS=
1248 else
1249 _HELM_NAME_ARG="xxxdryrunxxx"
1250 _HELM_ARGS="--create-namespace"
1251 fi
David Bainbridgefad50732020-05-01 17:00:12 -07001252 fi
Matteo Scandolo657e13c2020-07-28 11:41:42 -07001253 CMD=("helm $_HELM_COMMAND --debug --dry-run -f values.yaml $CHART_ARGS $INTERNAL_EXTRA_HELM_INSTALL_ARGS $EXTRA_HELM_INSTALL_ARGS --set defaults.log_level=$VOLTHA_LOG_LEVEL --namespace $NAMESPACE $_HELM_ARGS $CHART_VERSION $EXTRA_HELM_FLAGS $_HELM_NAME_ARG $CHART")
David Bainbridgefad50732020-05-01 17:00:12 -07001254 ${CMD[*]} 2>/dev/null | awk 'PRINT==1 {print}; /^USER-SUPPLIED VALUES:/ {PRINT = 1}; /^$/ {PRINT = 0}'
1255}
1256
David Bainbridgeb4bbde12020-06-25 14:46:36 -07001257helm_is_deployed() {
1258 local NAMESPACE=$1; shift
1259 local NAME=$1; shift
1260
1261 if [ "$HELM_MAJOR" -le 2 ]; then
1262 helm list --deployed --short --namespace "$NAMESPACE" "$NAME" 2>/dev/null | wc -l
1263 else
1264 helm list --deployed --short --namespace "$NAMESPACE" --filter "$NAME" 2>/dev/null | wc -l
1265 fi
1266}
1267
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001268helm_install() {
David Bainbridgec7220622020-05-28 12:31:47 -07001269 local INDENT NOW VALUES_FILE PPROF_ARG
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001270 if [ "$1" == "-" ]; then
1271 INDENT=$1; shift
1272 fi
1273 local NAMESPACE=$1; shift
David Bainbridge0774b232019-08-02 06:37:19 +00001274 local INAME=$1; shift
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001275 local CHART=$1; shift
David Bainbridge90fd8e32019-08-21 23:32:47 +00001276 local CHART_VERSION=$1; shift
David Bainbridgec7220622020-05-28 12:31:47 -07001277 local FILTER=$1; shift
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001278 local MESSAGE=$*
1279
David Bainbridged18f4942020-04-14 16:46:13 -07001280 if [ "$CHART_VERSION X" != " X" ] && [ "$CHART_VERSION" != "latest" ]; then
David Bainbridge90fd8e32019-08-21 23:32:47 +00001281 CHART_VERSION="--version $CHART_VERSION"
1282 else
1283 CHART_VERSION=
1284 fi
1285
David Bainbridge99ac7a22019-08-31 02:26:43 +00001286 local CHART_ARGS=
1287 if [ -r "${INAME}-values.yaml" ]; then
1288 CHART_ARGS="-f ${INAME}-values.yaml"
1289 fi
1290
David Bainbridged18f4942020-04-14 16:46:13 -07001291 local WAIT_START CMD
1292 WAIT_START="$(date +%s)"
1293 COUNT="$((300 / 15))"
1294 bspin "$INDENT" "$MESSAGE"
1295 if [ "$HELM_USE_UPGRADE" == "yes" ]; then
David Bainbridge7f8bf992020-04-08 21:53:22 -07001296 _HELM_COMMAND="upgrade --install"
David Bainbridgeb4bbde12020-06-25 14:46:36 -07001297 _HELM_NAME_ARG="$INAME"
David Bainbridge7f8bf992020-04-08 21:53:22 -07001298 else
1299 _HELM_COMMAND="install"
David Bainbridgeb4bbde12020-06-25 14:46:36 -07001300 if [ "$HELM_MAJOR" -le 2 ]; then
1301 _HELM_NAME_ARG="--name $INAME"
1302 _HELM_ARGS=
1303 else
1304 _HELM_NAME_ARG="$INAME"
1305 _HELM_ARGS="--create-namespace"
1306 fi
David Bainbridge7f8bf992020-04-08 21:53:22 -07001307 fi
David Bainbridgec7220622020-05-28 12:31:47 -07001308
1309 VALUES_FILE="$(mktemp)"
1310 if [ "$FILTER" == "-" ]; then
Matteo Scandolo657e13c2020-07-28 11:41:42 -07001311 cp "values.yaml" "$VALUES_FILE"
David Bainbridgea965ca22020-06-09 17:45:04 -07001312 elif [ "${FILTER:0:1}" == "+" ]; then
Matteo Scandolo657e13c2020-07-28 11:41:42 -07001313 cp "values.yaml" "$VALUES_FILE"
1314 yq r - "${FILTER:1}" <"values.yaml" >>"$VALUES_FILE"
David Bainbridge33e56c72020-06-11 11:39:56 -07001315 cat "$VALUES_FILE" >>"$LOG"
David Bainbridgec7220622020-05-28 12:31:47 -07001316 else
Matteo Scandolo657e13c2020-07-28 11:41:42 -07001317 yq r - "$FILTER" <"values.yaml" >"$VALUES_FILE"
David Bainbridgec7220622020-05-28 12:31:47 -07001318 fi
1319 if [ "$WITH_PPROF" == "yes" ]; then
1320 PPROF_ARG="--set profiler.enabled=true"
1321 fi
David Bainbridgeb4bbde12020-06-25 14:46:36 -07001322 CMD=("helm $_HELM_COMMAND -f $VALUES_FILE $_HELM_ARGS $CHART_ARGS $PPROF_ARG $INTERNAL_EXTRA_HELM_INSTALL_ARGS $EXTRA_HELM_INSTALL_ARGS --set defaults.log_level=$VOLTHA_LOG_LEVEL --namespace $NAMESPACE $CHART_VERSION $EXTRA_HELM_FLAGS $_HELM_NAME_ARG $CHART")
David Bainbridged18f4942020-04-14 16:46:13 -07001323 (set -x; ${CMD[*]} >>"$LOG" 2>&1) >>"$LOG" 2>&1
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001324 SUCCESS=$?
David Bainbridged18f4942020-04-14 16:46:13 -07001325 while [ "$SUCCESS" -ne 0 ]; do
1326 NOW="$(date +%s)"
1327 if [ "$((NOW - WAIT_START))" -gt "$TIMEOUT_SECONDS" ]; then
David Bainbridge52e6e9d2020-03-23 13:48:27 -07001328 espin "$THEX"
David Bainbridgec7220622020-05-28 12:31:47 -07001329 rm -f "$VALUES_FILE"
David Bainbridge52e6e9d2020-03-23 13:48:27 -07001330 doTimeout "waiting for helm install $CHART"
1331 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001332 sspin "$INDENT"
1333 COUNT="$((COUNT - 1))"
1334 if [ "$COUNT" -eq 0 ]; then
1335 if [ "$HELM_USE_UPGRADE" == "no" ]; then
David Bainbridgeb4bbde12020-06-25 14:46:36 -07001336 if [ "$HELM_MAJOR" -le 2 ]; then
1337 (set -x; helm delete --purge "$INAME" >>"$LOG" 2>&1) >>"$LOG" 2>&1
1338 else
1339 (set -x; helm uninstall "$INAME" >>"$LOG" 2>&1) >>"$LOG" 2>&1
1340 fi
David Bainbridge7f8bf992020-04-08 21:53:22 -07001341 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001342 (set -x; ${CMD[*]} >>"$LOG" 2>&1) >>"$LOG" 2>&1
Andy Baviere22ff252019-12-19 11:40:31 -07001343 SUCCESS=$?
David Bainbridged18f4942020-04-14 16:46:13 -07001344 COUNT="$((300 / 15))"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001345 fi
1346 sleep .15
1347 done
David Bainbridgec7220622020-05-28 12:31:47 -07001348 rm -f "$VALUES_FILE"
David Bainbridged18f4942020-04-14 16:46:13 -07001349 espin "$INDENT" "$VERIFIED"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001350}
1351
Matteo Scandolo657e13c2020-07-28 11:41:42 -07001352echo "INSTALL NAME: $NAME" >> "$LOG"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001353
David Bainbridged18f4942020-04-14 16:46:13 -07001354STIME="$(date +%s)"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001355if [ "$INSTALL_KUBECTL" == "no" ]; then
1356 bspin "Skip kubectl install"
1357 espin $NO_ENTRY
Test Userc13bdc92019-07-03 20:57:49 +00001358else
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001359 bspin "Verify kubectl $HELM"
David Bainbridged18f4942020-04-14 16:46:13 -07001360 if [ -x "$GOPATH/bin/kubectl" ]; then
1361 espin "$VERIFIED"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001362 else
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001363 ERR_OUT="$(mktemp)"
David Bainbridged18f4942020-04-14 16:46:13 -07001364 espin "$NOT_VERIFIED"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001365 bspin - "Download and install Kubernetes/kubectl $DOWNLOAD"
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001366 (set -x; curl --fail -o "$GOPATH/bin/kubectl" -sSL "https://storage.googleapis.com/kubernetes-release/release/$(curl --fail -sSL https://storage.googleapis.com/kubernetes-release/release/stable.txt 2>>"$ERR_OUT")/bin/$HOSTOS/$HOSTARCH/kubectl" >>"$LOG" 2>>"$ERR_OUT") >>"$LOG" 2>&1
1367 RESULT=$?
1368 if [ "$RESULT" -ne 0 ]; then
1369 espin - "$THEX"
David Bainbridgee3fc0c32020-04-21 15:34:04 -07001370 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR: unable to download kubectl: $(tail "$ERR_OUT")${NORMAL}"
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001371 cat "$ERR_OUT" >> "$LOG"
Zack Williamsded60cb2020-04-13 10:02:20 -07001372 rm -rf "$ERR_OUT" "$GOPATH/bin/kubectl"
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001373 exit 1
1374 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001375 (set -x; chmod 755 "$GOPATH/bin/kubectl" >>"$LOG" 2>&1) >>"$LOG" 2>&1
1376 espin - "$VERIFIED"
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001377 rm -rf "$ERR_OUT"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001378 fi
Test Userc13bdc92019-07-03 20:57:49 +00001379fi
David Bainbridgee87067b2019-08-12 22:00:12 +00001380if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001381 NOW="$(date +%s)"
1382 printtime $((NOW - STIME))
David Bainbridgee87067b2019-08-12 22:00:12 +00001383fi
Test Userc13bdc92019-07-03 20:57:49 +00001384
David Bainbridged18f4942020-04-14 16:46:13 -07001385STIME="$(date +%s)"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001386if [ "$DEPLOY_K8S" == "no" ]; then
1387 bspin "Skip Kubernetes/Kind Deployment"
1388 espin $NO_ENTRY
1389else
Test Userba1e7e72019-07-10 22:27:54 +00001390 bspin "Verify Kubernetes/Kind $HELM"
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -08001391 IS_INSTALLED=0
1392 OP_TYPE="install"
David Bainbridged18f4942020-04-14 16:46:13 -07001393 if [ -x "$GOPATH/bin/kind" ]; then
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -08001394 OP_TYPE="upgrade"
David Bainbridgeb4bbde12020-06-25 14:46:36 -07001395 if [ "$("$GOPATH/bin/kind" version | grep -c "$KIND_VERSION")" -eq 1 ]; then
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -08001396 IS_INSTALLED=1
David Bainbridged18f4942020-04-14 16:46:13 -07001397 espin "$VERIFIED"
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -08001398 fi
1399 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001400 if [ "$IS_INSTALLED" -eq 0 ]; then
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001401 ERR_OUT="$(mktemp)"
David Bainbridged18f4942020-04-14 16:46:13 -07001402 espin "$NOT_VERIFIED"
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -08001403 bspin - "Download and $OP_TYPE Kubernetes/kind $DOWNLOAD"
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001404 (set -x; curl -o "$GOPATH/bin/kind" --fail -sSL "https://github.com/kubernetes-sigs/kind/releases/download/$KIND_VERSION/kind-$HOSTOS-$HOSTARCH" >>"$LOG" 2>"$ERR_OUT") >>"$LOG" 2>&1
1405 RESULT=$?
1406 if [ $RESULT -ne 0 ]; then
1407 espin - "$THEX"
David Bainbridgee3fc0c32020-04-21 15:34:04 -07001408 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR: unable to download kind: $(tail "$ERR_OUT")${NORMAL}"
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001409 cat "$ERR_OUT" >> "$LOG"
Zack Williamsded60cb2020-04-13 10:02:20 -07001410 rm -rf "$ERR_OUT" "$GOPATH/bin/kind"
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001411 exit 1
1412 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001413 (set -x; chmod 755 "$GOPATH/bin/kind" >>"$LOG" 2>&1) >>"$LOG" 2>&1
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001414 rm -rf "$ERR_OUT"
David Bainbridged18f4942020-04-14 16:46:13 -07001415 espin - "$VERIFIED"
Test Userba1e7e72019-07-10 22:27:54 +00001416 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001417fi
1418
David Bainbridgee87067b2019-08-12 22:00:12 +00001419if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001420 NOW="$(date +%s)"
1421 printtime $((NOW - STIME))
David Bainbridgee87067b2019-08-12 22:00:12 +00001422fi
1423
David Bainbridged18f4942020-04-14 16:46:13 -07001424STIME="$(date +%s)"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001425if [ "$INSTALL_HELM" == "no" ]; then
1426 bspin "Skip Helm Install"
1427 espin $NO_ENTRY
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001428else
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001429 bspin "Verify Helm $HELM"
David Bainbridgea34993d2020-04-01 09:15:42 -07001430 HELM_UPGRADE=0
1431 HELM_UPGRADE_DESC="install"
David Bainbridged18f4942020-04-14 16:46:13 -07001432 if [ -x "$GOPATH/bin/helm" ]; then
David Bainbridgeb4bbde12020-06-25 14:46:36 -07001433 HAVE_VER=$(helm version --client --short | sed -E -e 's/^.*(v[0-9]+\.[0-9]+\.[0-9]+).*$/\1/')
David Bainbridged18f4942020-04-14 16:46:13 -07001434 HELM_UP_DOWN="$(echo -e "$HAVE_VER\n$HELM_VERSION" | sort -V | head -1)"
1435 if [ "$HAVE_VER" != "$HELM_VERSION" ]; then
1436 if [ "$HELM_UP_DOWN" == "$HELM_VERSION" ]; then
David Bainbridgea34993d2020-04-01 09:15:42 -07001437 HELM_UPGRADE_DESC="downgrade"
1438 else
1439 HELM_UPGRADE_DESC="upgrade"
1440 fi
1441 HELM_UPGRADE=1
1442 else
David Bainbridged18f4942020-04-14 16:46:13 -07001443 espin "$VERIFIED"
David Bainbridgea34993d2020-04-01 09:15:42 -07001444 fi
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001445 else
David Bainbridgea34993d2020-04-01 09:15:42 -07001446 HELM_UPGRADE=1
1447 fi
1448
David Bainbridged18f4942020-04-14 16:46:13 -07001449 if [ "$HELM_UPGRADE" -ne 0 ]; then
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001450 ERR_OUT="$(mktemp)"
1451 INSTALL_HELM_BIN=$(mktemp)
David Bainbridged18f4942020-04-14 16:46:13 -07001452 espin "$NOT_VERIFIED"
David Bainbridgea34993d2020-04-01 09:15:42 -07001453 bspin - "Download and $HELM_UPGRADE_DESC Helm $DOWNLOAD"
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001454 (set -x; curl -o "$INSTALL_HELM_BIN" --fail -sSL https://git.io/get_helm.sh >>"$LOG" 2>"$ERR_OUT") >>"$LOG" 2>&1
1455 RESULT=$?
1456 if [ $RESULT -ne 0 ]; then
1457 espin - "$THEX"
David Bainbridgee3fc0c32020-04-21 15:34:04 -07001458 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR: unable to download helm installer: $(tail "$ERR_OUT")${NORMAL}"
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001459 cat "$ERR_OUT" >> "$LOG"
1460 rm -rf "$INSTALL_HELM_BIN" "$ERR_OUT" "$GOPATH/bin/helm" "$GOPATH/bin/tiller"
1461 exit 1
1462 fi
1463 rm -rf "$ERR_OUT"
1464 chmod +x "$INSTALL_HELM_BIN"
1465 (set -x; PATH="$GOPATH/bin:$PATH" DESIRED_VERSION=$HELM_VERSION USE_SUDO=false HELM_INSTALL_DIR=$GOPATH/bin "$INSTALL_HELM_BIN" >>"$LOG" 2>&1) >>"$LOG" 2>&1
1466 RESULT=$?
1467 if [ $RESULT -ne 0 ]; then
1468 espin - "$THEX"
1469 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR: unable to install helm, see install log for details${NORMAL}"
1470 rm -rf "$INSTALL_HELM_BIN" "$ERR_OUT" "$GOPATH/bin/helm" "$GOPATH/bin/tiller"
1471 exit 1
1472 fi
1473 rm -rf "$INSTALL_HELM_BIN" "$ERR_OUT"
David Bainbridged18f4942020-04-14 16:46:13 -07001474 espin - "$VERIFIED"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001475 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001476fi
David Bainbridgee87067b2019-08-12 22:00:12 +00001477if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001478 NOW="$(date +%s)"
1479 printtime $((NOW - STIME))
David Bainbridgee87067b2019-08-12 22:00:12 +00001480fi
David Bainbridgeb4bbde12020-06-25 14:46:36 -07001481HELM_MAJOR=$(helm version --client --short 2>/dev/null| sed -E -e 's/^.*v([0-9]+)\.[0-9]+\.[0-9]+.*$/\1/')
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001482
David Bainbridged18f4942020-04-14 16:46:13 -07001483STIME="$(date +%s)"
Test Userb5712372019-07-03 21:52:17 +00001484bspin "Verify voltctl $HIGH_VOLTAGE"
David Bainbridged2811972019-12-14 01:14:09 +00001485VOK=0
1486VMESSAGE="install"
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001487ERR_OUT=$(mktemp)
David K. Bainbridgeebf38d92020-02-10 10:46:31 -08001488export VC_VERSION="$VOLTCTL_VERSION"
1489if [ "$VC_VERSION" == "latest" ]; then
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001490 set -o pipefail # TODO: would be nice to run all in pipefail mode
1491 VC_VERSION="$(curl --fail -sSL https://api.github.com/repos/opencord/voltctl/releases/latest 2>"$ERR_OUT" | jq -r .tag_name | sed -e 's/^v//g')"
1492 RESULT=$?
1493 set +o pipefail
1494 if [ "$RESULT" -ne 0 ]; then
1495 espin - "$THEX"
1496 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR: unable to determine released version of voltctl: $(cat "$ERR_OUT")${NORMAL}"
1497 rm -rf "$ERR_OUT" "$GOPATH/bin/voltctl"
1498 exit 1
1499 fi
1500 export VC_VERSION
David K. Bainbridgeebf38d92020-02-10 10:46:31 -08001501fi
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001502
David Bainbridged18f4942020-04-14 16:46:13 -07001503if [ -x "$GOPATH/bin/voltctl" ]; then
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001504 VHAVE="$("$GOPATH/bin/voltctl" version --clientonly -o json 2>/dev/null | jq -r .version)"
David Bainbridged18f4942020-04-14 16:46:13 -07001505 RESULT=$?
1506 if [ $RESULT -eq 0 ] && [ "$VHAVE" == "$VC_VERSION" ]; then
David Bainbridged2811972019-12-14 01:14:09 +00001507 VOK=1
David Bainbridged18f4942020-04-14 16:46:13 -07001508 espin "$VERIFIED"
David Bainbridge1ba64f12019-12-18 00:40:13 +00001509 else
David Bainbridged18f4942020-04-14 16:46:13 -07001510 VCHECK="$(echo -e "$VHAVE\n$VC_VERSION" | sort -V | head -1)"
David K. Bainbridgeebf38d92020-02-10 10:46:31 -08001511 if [ "$VCHECK" == "$VHAVE" ]; then
1512 VMESSAGE="upgrade"
1513 else
1514 VMESSAGE="downgrade"
1515 fi
David Bainbridged2811972019-12-14 01:14:09 +00001516 fi
1517fi
1518
David Bainbridged18f4942020-04-14 16:46:13 -07001519if [ "$VOK" -eq 0 ]; then
1520 espin "$NOT_VERIFIED"
David Bainbridged2811972019-12-14 01:14:09 +00001521 bspin - "Download and $VMESSAGE voltctl $DOWNLOAD"
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001522 (set -x; curl --fail -o "$GOPATH/bin/voltctl" -sSL "https://github.com/opencord/voltctl/releases/download/v$VC_VERSION/voltctl-$VC_VERSION-$HOSTOS-$HOSTARCH" >>"$LOG" 2>"$ERR_OUT") >>"$LOG" 2>&1
1523 RESULT=$?
1524 if [ $RESULT -ne 0 ]; then
1525 espin - "$THEX"
1526 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR: unable to download voltctl (version $VC_VERSION): $(cat "$ERR_OUT")${NORMAL}"
1527 rm -rf "$ERR_OUT" "$GOPATH/bin/voltctl"
1528 exit 1
1529 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001530 (set -x; chmod 755 "$GOPATH/bin/voltctl" >>"$LOG" 2>&1) >>"$LOG" 2>&1
1531 espin - "$VERIFIED"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001532fi
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001533rm -rf "$ERR_OUT"
David Bainbridgee87067b2019-08-12 22:00:12 +00001534if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001535 NOW="$(date +%s)"
1536 printtime $((NOW - STIME))
David Bainbridgee87067b2019-08-12 22:00:12 +00001537fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001538
1539bspin "Verify command PATH"
David Bainbridged18f4942020-04-14 16:46:13 -07001540espin "$VERIFIED"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001541
David Bainbridged18f4942020-04-14 16:46:13 -07001542STIME="$(date +%s)"
Test Userba1e7e72019-07-10 22:27:54 +00001543if [ "$DEPLOY_K8S" == "yes" ]; then
David Bainbridgeb4bbde12020-06-25 14:46:36 -07001544 HAVE="$(kind get clusters 2>/dev/null | grep -c "voltha-$NAME")"
Test Userba1e7e72019-07-10 22:27:54 +00001545 bspin "Verify Kubernetes/Kind Cluster"
1546 sspin
David Bainbridged18f4942020-04-14 16:46:13 -07001547 if [ "$HAVE" -eq 0 ]; then
1548 espin "$NOT_VERIFIED"
Matteo Scandolo657e13c2020-07-28 11:41:42 -07001549 bspin - "Generating cluster configuration"
1550
1551 touch "$NAME-cluster.cfg"
1552
1553 yq w -i "$NAME-cluster.cfg" kind Cluster
1554 yq w -i "$NAME-cluster.cfg" apiVersion "kind.sigs.k8s.io/v1alpha3"
1555
1556 if [ ! "$NUM_OF_CONTROLLER_NODES" -eq 0 ]; then
1557 for instance in $(seq 1 "$NUM_OF_CONTROLLER_NODES"); do
1558 yq w -i "$NAME-cluster.cfg" "nodes[+].role" "control-plane"
1559 done
David K. Bainbridgea00736b2020-01-08 14:33:17 -08001560 fi
Matteo Scandolo657e13c2020-07-28 11:41:42 -07001561
1562 if [ ! "$NUM_OF_WORKER_NODES" -eq 0 ]; then
1563 for instance in $(seq 1 "$NUM_OF_WORKER_NODES"); do
1564 yq w -i "$NAME-cluster.cfg" "nodes[+].role" worker
1565 done
1566 fi
1567 espin - "$VERIFIED"
1568
1569 cat "$NAME-cluster.cfg" >> "$LOG" 2>&1
1570
David Bainbridged18f4942020-04-14 16:46:13 -07001571 kind create cluster --name "voltha-$NAME" --config "$NAME-cluster.cfg"
David Bainbridge491b1bd2019-07-11 17:53:11 +00001572 else
David Bainbridged18f4942020-04-14 16:46:13 -07001573 espin "$VERIFIED"
Test Userba1e7e72019-07-10 22:27:54 +00001574 fi
1575
David K. Bainbridgec0ec6492020-07-21 17:34:23 +00001576 KUBECONFIG_TMP=$(mktemp)
1577 kind get kubeconfig --name="voltha-$NAME" >"$KUBECONFIG_TMP"
1578 mkdir -p "$HOME/.kube"
1579 KUBECONFIG="$HOME/.kube/kind-config-voltha-$NAME"; export KUBECONFIG
1580 cp "$KUBECONFIG_TMP" "$KUBECONFIG"
1581 rm -rf "$KUBECONFIG_TMP"
David Bainbridge1d2c5842020-06-03 15:29:07 -07001582
Test Userba1e7e72019-07-10 22:27:54 +00001583 P="coredns-.* \
David Bainbridge0774b232019-08-02 06:37:19 +00001584 etcd-voltha-$NAME-control-plane \
Test Userba1e7e72019-07-10 22:27:54 +00001585 kindnet-.* \
David Bainbridge0774b232019-08-02 06:37:19 +00001586 kube-apiserver-voltha-$NAME-control-plane \
1587 kube-controller-manager-voltha-$NAME-control-plane \
Test Userba1e7e72019-07-10 22:27:54 +00001588 kube-proxy-.* \
David Bainbridge0774b232019-08-02 06:37:19 +00001589 kube-scheduler-voltha-$NAME-control-plane"
Test Userba1e7e72019-07-10 22:27:54 +00001590
Matteo Scandolo657e13c2020-07-28 11:41:42 -07001591 EXPECT="8"
1592 if [ ! "$NUM_OF_WORKER_NODES" -eq 0 ]; then
1593 NUM=$((2*NUM_OF_WORKER_NODES)) # kindnet and kube-proxy are deployed on each node
1594 EXPECT=$((EXPECT+NUM))
1595 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001596 wait_for_pods - "kube-system" "$EXPECT" "includes" "Waiting for system PODs to start" "$NO_LABEL" "$P"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001597fi
Matteo Scandolo657e13c2020-07-28 11:41:42 -07001598
David Bainbridgee87067b2019-08-12 22:00:12 +00001599if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001600 NOW="$(date +%s)"
1601 printtime $((NOW - STIME))
David Bainbridgee87067b2019-08-12 22:00:12 +00001602fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001603
David Bainbridgee4d11ca2020-05-08 10:21:10 -07001604if [ "$SCHEDULE_ON_CONTROL_NODES" == "yes" ]; then
1605 bspin "Untaint control nodes to allow scheduling $LOCK"
1606 for MNODE in $(kubectl get node --selector='node-role.kubernetes.io/master' -o json | jq -r '.items[].metadata.name'); do
1607 (set -x; kubectl taint node "$MNODE" node-role.kubernetes.io/master:NoSchedule- >>"$LOG" 2>&1) >>"$LOG" 2>&1
1608 sspin
1609 done
1610 espin "$VERIFIED"
1611fi
1612
David Bainbridgeb4bbde12020-06-25 14:46:36 -07001613if [ "$HELM_MAJOR" -le 2 ]; then
1614 STIME="$(date +%s)"
1615 COUNT="$(count_pods "kube-system" ":Running:" "$NO_LABEL" "tiller-deploy-.*")"
1616 bspin "Verify Helm"
1617 if [ "$COUNT" -ne 1 ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001618 espin "$NOT_VERIFIED"
David Bainbridgeb4bbde12020-06-25 14:46:36 -07001619 echo -e "Configuring Helm $GEAR"
1620 if [ "$INSTALL_HELM" == "no" ]; then
1621 bspin - "Skip Helm Initialization"
1622 espin - $NO_ENTRY
1623 else
1624 bspin - "Initialize Helm"
1625 (set -x; helm init --upgrade >>"$LOG" 2>&1) >>"$LOG" 2>&1
1626 espin - "$VERIFIED"
1627 wait_for_pods - "kube-system" 1 "includes" "Waiting for Tiller POD to start" "$NO_LABEL" "tiller-deploy-.*"
1628 fi
1629
1630 # HACK (sort-of) - the config for tiller is about to be patched, which will
1631 # cause the tiller pod to be recreated. This can sometimes cause a timing
1632 # issue with the "wait_for_pods" call on tiller as it may incorrectly
1633 # identify the running/ready tiller pod that is soon to be terminated as
1634 # what it is waiting for. To avoid this issue we do a clean scale down and
1635 # scale up of the pod so the script controlls when it should be expecting
1636 # things
1637 (set -x; kubectl -n kube-system scale deploy tiller-deploy --replicas=0 >>"$LOG" 2>&1) >>"$LOG" 2>&1
1638 wait_for_pods - "kube-system" 0 "not" "Waiting for Tiller POD to shutdown" "$NO_LABEL" "tiller-deploy-.*"
1639
1640 # Create and k8s service account so that Helm can create pods
1641 bspin - "Create Tiller ServiceAccount"
1642 (set -x; kubectl create serviceaccount --namespace kube-system tiller >>"$LOG" 2>&1) >>"$LOG" 2>&1
1643 espin - "$VERIFIED"
1644 bspin - "Create Tiller ClusterRoleBinding"
1645 (set -x; kubectl create clusterrolebinding tiller-cluster-rule --clusterrole=cluster-admin --serviceaccount=kube-system:tiller >>"$LOG" 2>&1) >>"$LOG" 2>&1
1646 espin - "$VERIFIED"
1647 bspin - "Update Tiller Manifest"
1648 (set -x; kubectl patch deploy --namespace kube-system tiller-deploy -p '{"spec":{"template":{"spec":{"serviceAccount":"tiller"}}}}' >>"$LOG" 2>&1) >>"$LOG" 2>&1
1649
1650 # HACK (sort-of) - part to, spin it back up
1651 (set -x; kubectl -n kube-system scale deploy tiller-deploy --replicas=1 >>"$LOG" 2>&1) >>"$LOG" 2>&1
David Bainbridged18f4942020-04-14 16:46:13 -07001652 espin - "$VERIFIED"
David Bainbridgea34993d2020-04-01 09:15:42 -07001653 else
David Bainbridgeb4bbde12020-06-25 14:46:36 -07001654 if [ "$(helm version -s --template '{{.Server.SemVer}}')" != "$HELM_VERSION" ]; then
1655 espin "$NOT_VERIFIED"
1656 bspin - "Sync Tiller server version with helm client"
1657 (set -x; helm init --upgrade --force-upgrade --wait >>"$LOG" 2>&1) >>"$LOG" 2>&1
1658 espin - "$VERIFIED"
1659 else
1660 espin "$VERIFIED"
1661 fi
1662
David Bainbridgea34993d2020-04-01 09:15:42 -07001663 fi
David Bainbridgeb4bbde12020-06-25 14:46:36 -07001664 wait_for_pods - "kube-system" 1 "includes" "Waiting for Tiller POD to start" "$NO_LABEL" "tiller-deploy-.*"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001665fi
David Bainbridgeddeab482020-06-24 12:43:40 -07001666
David Bainbridgeb4bbde12020-06-25 14:46:36 -07001667# The `etcd` repo is temporary until `http://github.com/helm/charts/pull/22955` is
1668# merged into the incubator charts
David Bainbridgeddeab482020-06-24 12:43:40 -07001669REPOS="onf|https://charts.opencord.org|ONF_VOLTHA \
1670 stable|https://kubernetes-charts.storage.googleapis.com|Google_Stable \
Ubuntubaab12f2020-06-30 01:08:19 +00001671 incubator|https://kubernetes-charts-incubator.storage.googleapis.com|Google_Incubator \
1672 onos|https://charts.onosproject.org|ONF_ONOS \
1673 atomix|https://charts.atomix.io|ONF_Atomix \
1674 bbsim-sadis|https://ciena.github.io/bbsim-sadis-server/charts|Custom_BBSIM_SADIS_Server \
1675 elastic|https://helm.elastic.co|Elastic \
David Bainbridgeb4bbde12020-06-25 14:46:36 -07001676 kiwigrid|https://kiwigrid.github.io|Fluentd-ElasticSearch \
1677 etcd|https://dbainbri-ciena.github.io/etcd-helm-chart"
David Bainbridgeddeab482020-06-24 12:43:40 -07001678
David Bainbridgeb4bbde12020-06-25 14:46:36 -07001679REPO_UPDATE_REQ="no"
David Bainbridgeddeab482020-06-24 12:43:40 -07001680bspin - "Verify Helm Repository"
1681for REPO in $REPOS; do
1682 REPO_NAME="$(echo "$REPO" | cut -d\| -f1)"
1683 REPO_URL="$(echo "$REPO" | cut -d\| -f2)"
1684 REPO_LABEL="$(echo "$REPO" | cut -d\| -f3 | sed -e 's/_/ /g')"
1685
1686 sspin - "Verify Helm Repository: $REPO_LABEL$CEOL"
1687 if [ "$(helm repo list 2>/dev/null | grep -c "$REPO_NAME" 2>/dev/null)" -eq 0 ]; then
1688 sspin - "Add Helm Repository: $REPO_LABEL$CEOL"
1689 (set -x; helm repo add "$REPO_NAME" "$REPO_URL" >>"$LOG" 2>&1) >>"$LOG" 2>&1
1690 REPO_UPDATE_REQ="yes"
1691 fi
1692done
1693sspin - "Verify Helm Repositories$CEOL"
1694espin - "$VERIFIED"
1695
1696if [ "$REPO_UPDATE_REQ" == "yes" ] || [ "$UPDATE_HELM_REPOS" == "yes" ]; then
1697 bspin - "Update Helm repository cache"
1698 (set -x; helm repo update >>"$LOG" 2>&1) >>"$LOG" 2>&1
1699 espin - "$VERIFIED"
1700fi
1701
David Bainbridgee87067b2019-08-12 22:00:12 +00001702if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001703 NOW="$(date +%s)"
1704 printtime $((NOW - STIME))
David Bainbridgee87067b2019-08-12 22:00:12 +00001705fi
David Bainbridgecf546362020-04-21 23:18:50 -07001706# Resolve chart versions and log them for debug/support
1707RESOLVED_VOLTHA_CHART_VERSION=$(resolve_chart_version "$VOLTHA_CHART" "$VOLTHA_CHART_VERSION")
1708RESOLVED_VOLTHA_BBSIM_CHART_VERSION=$(resolve_chart_version "$VOLTHA_BBSIM_CHART" "$VOLTHA_BBSIM_CHART_VERSION")
1709RESOLVED_VOLTHA_ADAPTER_SIM_CHART_VERSION=$(resolve_chart_version "$VOLTHA_ADAPTER_SIM_CHART" "$VOLTHA_ADAPTER_SIM_CHART_VERSION")
1710RESOLVED_VOLTHA_ADAPTER_OPEN_OLT_CHART_VERSION=$(resolve_chart_version "$VOLTHA_ADAPTER_OPEN_OLT_CHART" "$VOLTHA_ADAPTER_OPEN_OLT_CHART_VERSION")
1711RESOLVED_VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION=$(resolve_chart_version "$VOLTHA_ADAPTER_OPEN_ONU_CHART" "$VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION")
1712RESOLVED_ONOS_CHART_VERSION=$(resolve_chart_version "$ONOS_CHART" "$ONOS_CHART_VERSION")
David Bainbridge60ffc0f2020-04-27 22:13:22 -07001713RESOLVED_ONOS_CLASSIC_CHART_VERSION=$(resolve_chart_version "$ONOS_CLASSIC_CHART" "$ONOS_CLASSIC_CHART_VERSION")
David Bainbridgecf546362020-04-21 23:18:50 -07001714RESOLVED_KAFKA_CHART_VERSION=$(resolve_chart_version "$KAFKA_CHART" "$KAFKA_CHART_VERSION")
divyadesai59f987a2020-05-27 12:11:33 +00001715RESOLVED_ELASTICSEARCH_CHART_VERSION=$(resolve_chart_version "$ELASTICSEARCH_CHART" "$ELASTICSEARCH_CHART_VERSION")
1716RESOLVED_KIBANA_CHART_VERSION=$(resolve_chart_version "$KIBANA_CHART" "$KIBANA_CHART_VERSION")
1717RESOLVED_FLUENTD_ELASTICSEARCH_CHART_VERSION=$(resolve_chart_version "$FLUENTD_ELASTICSEARCH_CHART" "$FLUENTD_ELASTICSEARCH_CHART_VERSION")
David K. Bainbridge450c15c2020-06-29 10:12:06 -07001718RESOLVED_BBSIM_SADIS_SERVER_CHART_VERSION=$(resolve_chart_version "$BBSIM_SADIS_SERVER_CHART" "$BBSIM_SADIS_SERVER_CHART_VERSION")
1719RESOLVED_RADIUS_CHART_VERSION=$(resolve_chart_version "$RADIUS_CHART" "$RADIUS_CHART_VERSION")
David Bainbridgecf546362020-04-21 23:18:50 -07001720cat <<EOV >>"$LOG"
1721Resolved helm charts and versions:
1722 $VOLTHA_CHART:$RESOLVED_VOLTHA_CHART_VERSION
1723 $VOLTHA_BBSIM_CHART:$RESOLVED_VOLTHA_BBSIM_CHART_VERSION
1724 $VOLTHA_ADAPTER_SIM_CHART:$RESOLVED_VOLTHA_ADAPTER_SIM_CHART_VERSION
1725 $VOLTHA_ADAPTER_OPEN_OLT_CHART:$RESOLVED_VOLTHA_ADAPTER_OPEN_OLT_CHART_VERSION
1726 $VOLTHA_ADAPTER_OPEN_ONU_CHART:$RESOLVED_VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION
1727 $ONOS_CHART:$RESOLVED_ONOS_CHART_VERSION
David Bainbridge60ffc0f2020-04-27 22:13:22 -07001728 $ONOS_CLASSIC_CHART:$RESOLVED_ONOS_CLASSIC_CHART_VERSION
David Bainbridgecf546362020-04-21 23:18:50 -07001729 $KAFKA_CHART:$RESOLVED_KAFKA_CHART_VERSION
divyadesai59f987a2020-05-27 12:11:33 +00001730 $ELASTICSEARCH_CHART:$RESOLVED_ELASTICSEARCH_CHART_VERSION
1731 $KIBANA_CHART:$RESOLVED_KIBANA_CHART_VERSION
1732 $FLUENTD_ELASTICSEARCH_CHART:$RESOLVED_FLUENTD_ELASTICSEARCH_CHART_VERSION
David K. Bainbridge450c15c2020-06-29 10:12:06 -07001733 $BBSIM_SADIS_SERVER_CHART:$RESOLVED_BBSIM_SADIS_SERVER_CHART_VERSION
1734 $RADIUS_CHART:$RESOLVED_RADIUS_CHART_VERSION
David Bainbridgecf546362020-04-21 23:18:50 -07001735EOV
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001736
David Bainbridged18f4942020-04-14 16:46:13 -07001737STIME="$(date +%s)"
Matteo Scandolo657e13c2020-07-28 11:41:42 -07001738bspin "Verify Helm values file: values.yaml"
1739if [ ! -r "./values.yaml" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001740 espin "$NOT_VERIFIED"
Matteo Scandolo657e13c2020-07-28 11:41:42 -07001741 bspin - "Download Helm values file: values.yaml to values.yaml $DOWNLOAD"
David Bainbridged18f4942020-04-14 16:46:13 -07001742 ERR_OUT="$(mktemp)"
Matteo Scandolo657e13c2020-07-28 11:41:42 -07001743 if ! (set -x; curl --fail -o "./values.yaml" -sSL "https://raw.githubusercontent.com/opencord/kind-voltha/$VK_RELEASE/values.yaml" >>"$LOG" 2>"$ERR_OUT") >>"$LOG" 2>&1; then
David Bainbridged18f4942020-04-14 16:46:13 -07001744 espin - "$THEX"
Matteo Scandolo657e13c2020-07-28 11:41:42 -07001745 echo -e "${RED}${BOLD}${ERROR}ERROR: values.yaml${NORMAL}${RED} - $(cat "$ERR_OUT")${NORMAL}"
David Bainbridged18f4942020-04-14 16:46:13 -07001746 echo "ERROR: $(cat "$ERR_OUT")" >>"$LOG"
Matteo Scandolo657e13c2020-07-28 11:41:42 -07001747 rm -rf "$ERR_OUT" "./values.yaml"
David K. Bainbridgea00736b2020-01-08 14:33:17 -08001748 exit 1
1749 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001750 rm -rf "$ERR_OUT"
1751 espin - "$VERIFIED"
Test Userba1e7e72019-07-10 22:27:54 +00001752else
David Bainbridged18f4942020-04-14 16:46:13 -07001753 espin "$VERIFIED"
Test Userba1e7e72019-07-10 22:27:54 +00001754fi
David Bainbridgee87067b2019-08-12 22:00:12 +00001755if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001756 NOW="$(date +%s)"
1757 printtime $((NOW - STIME))
David Bainbridgee87067b2019-08-12 22:00:12 +00001758fi
Test Userba1e7e72019-07-10 22:27:54 +00001759
David Bainbridged18f4942020-04-14 16:46:13 -07001760STIME="$(date +%s)"
David Bainbridge99ac7a22019-08-31 02:26:43 +00001761bspin "Verify or download chart specific values files $DOWNLOAD"
1762VALUES_FILES="monkey-values.yaml"
David Bainbridged18f4942020-04-14 16:46:13 -07001763ERR_OUT="$(mktemp)"
David Bainbridge99ac7a22019-08-31 02:26:43 +00001764for i in $VALUES_FILES; do
1765 if [ ! -r ./$i ]; then
serkant.uluderya4d315132020-04-15 16:25:54 -07001766 if ! (set -x; curl --fail -o "./$i" -sSL "https://raw.githubusercontent.com/opencord/kind-voltha/$VK_RELEASE/$i" >>"$LOG" 2>"$ERR_OUT") >>"$LOG" 2>&1; then
David Bainbridged18f4942020-04-14 16:46:13 -07001767 espin "$THEX"
1768 echo -e "${RED}${BOLD}${ERROR}ERROR: $i${NORMAL}${RED} - $(cat "$ERR_OUT")${NORMAL}"
1769 echo "ERROR: $i - $(cat "$ERR_OUT")" >>"$LOG"
1770 rm -rf "$ERR_OUT" "./$i"
David K. Bainbridgea00736b2020-01-08 14:33:17 -08001771 exit 1
1772 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001773 rm -rf "$ERR_OUT"
David Bainbridge99ac7a22019-08-31 02:26:43 +00001774 fi
1775done
David Bainbridged18f4942020-04-14 16:46:13 -07001776rm -rf "$ERR_OUT"
1777espin "$VERIFIED"
David Bainbridge99ac7a22019-08-31 02:26:43 +00001778if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001779 NOW="$(date +%s)"
1780 printtime $((NOW - STIME))
David Bainbridge99ac7a22019-08-31 02:26:43 +00001781fi
1782
1783if [ "$WITH_CHAOS" == "yes" ]; then
1784 bspin "Verify or clone kube-monkey helm chart $DOWNLOAD"
1785 if [ -r ./kube-monkey ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001786 espin "$VERIFIED"
David Bainbridge99ac7a22019-08-31 02:26:43 +00001787 else
David Bainbridged18f4942020-04-14 16:46:13 -07001788 espin "$NOT_VERIFIED"
David Bainbridge99ac7a22019-08-31 02:26:43 +00001789 bspin - "GIT clone kube-monkey"
David Bainbridged18f4942020-04-14 16:46:13 -07001790 (set -x; git clone https://github.com/asobti/kube-monkey kube-monkey >>"$LOG" 2>&1) >>"$LOG" 2>&1
1791 espin - "$VERIFIED"
David Bainbridge99ac7a22019-08-31 02:26:43 +00001792 fi
1793fi
1794
Test Userba1e7e72019-07-10 22:27:54 +00001795if [ "$JUST_K8S" == "yes" ]; then
1796 echo "Environment deployed, not deploying VOLTHA artifacts as requested. Good bye."
1797 echo ""
David Bainbridged18f4942020-04-14 16:46:13 -07001798 echo "Please issue the following commands in your terminal to ensure that you" | tee -a "$LOG"
1799 echo "are accessing the correct Kubernetes/Kind cluster as well as have the " | tee -a "$LOG"
1800 echo "tools required by VOLTHA in your command path. " | tee -a "$LOG"
1801 echo "" | tee -a "$LOG"
1802 echo -en "$BOLD"
1803 if [ "$DEPLOY_K8S" == "yes" ]; then
David K. Bainbridge02ae1f32020-07-21 13:25:13 -07001804 KUBECONFIG_TMP=$(mktemp)
1805 kind get kubeconfig --name="voltha-$NAME" >"$KUBECONFIG_TMP"
1806 mkdir -p "$HOME/.kube"
1807 KUBECONFIG="$HOME/.kube/kind-config-voltha-$NAME"; export KUBECONFIG
1808 cp "$KUBECONFIG_TMP" "$KUBECONFIG"
1809 rm -rf "$KUBECONFIG_TMP"
David Bainbridgeb4bbde12020-06-25 14:46:36 -07001810 echo "export KUBECONFIG=\"$KUBECONFIG\"" | tee -a "$LOG"
Test Userba1e7e72019-07-10 22:27:54 +00001811 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001812 echo "export PATH=$GOPATH/bin:\$PATH" | tee -a "$LOG"
1813 echo -en "$NORMAL"
1814 echo "" | tee -a "$LOG"
1815 echo "Thank you for choosing kind-voltha for you quick cluster needs." | tee -a "$LOG"
Test Userba1e7e72019-07-10 22:27:54 +00001816 exit 0
1817fi
1818
David Bainbridged18f4942020-04-14 16:46:13 -07001819STIME="$(date +%s)"
David Bainbridge60ffc0f2020-04-27 22:13:22 -07001820if is_in "$WITH_ONOS" "yes,legacy,classic"; then
1821 if is_in "$WITH_ONOS" "legacy"; then
1822 bspin "Verify ONOS LEGACY installed $BIRD"
David Bainbridgeb4bbde12020-06-25 14:46:36 -07001823 if [ "$HELM_USE_UPGRADE" == "yes" ] || [ "$(helm_is_deployed "$INFRA_NS" "^onos\$")" -ne 1 ]; then
David Bainbridge60ffc0f2020-04-27 22:13:22 -07001824 espin "$NOT_VERIFIED"
David Bainbridge33e56c72020-06-11 11:39:56 -07001825 INTERNAL_EXTRA_HELM_INSTALL_ARGS="$SET_TAG $EXTRA_HELM_FLAGS" helm_install - "$INFRA_NS" onos "$ONOS_CHART" "$ONOS_CHART_VERSION" "+onos" "$_HELM_DESC ONOS LEGACY"
David Bainbridge60ffc0f2020-04-27 22:13:22 -07001826 INTERNAL_EXTRA_HELM_INSTALL_ARGS=
1827 else
1828 espin "$VERIFIED"
1829 fi
1830 wait_for_pods - "$INFRA_NS" 1 "includes" "Waiting for ONOS to start" "$NO_LABEL" "onos-.*"
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001831
David Bainbridge60ffc0f2020-04-27 22:13:22 -07001832 if [ "$WITH_PORT_FORWARDS" == "yes" ]; then
1833 bspin - "Forward ONOS API port $FORWARD"
1834 kill_port_forward onos-ui
1835 port_forward "$INFRA_NS" onos-ui "$ONOS_API_PORT:8181"
1836 espin - "$VERIFIED"
1837 bspin - "Forward ONOS SSH port $FORWARD"
1838 kill_port_forward onos-ssh
1839 port_forward "$INFRA_NS" onos-ssh "$ONOS_SSH_PORT:8101"
1840 espin - "$VERIFIED"
1841 _ONOS_API_EP="127.0.0.1:$ONOS_API_PORT"
1842 else
1843 _ONOS_API_EP="$(get_service_ep "$INFRA_NS" onos-ui)"
1844 fi
1845 elif is_in "$WITH_ONOS" "yes,classic"; then
1846 bspin "Verify ONOS CLASSIC installed $BIRD"
David Bainbridgeb4bbde12020-06-25 14:46:36 -07001847 if [ "$HELM_USE_UPGRADE" == "yes" ] || [ "$(helm_is_deployed "$INFRA_NS" "^onos\$")" -ne 1 ]; then
David Bainbridge60ffc0f2020-04-27 22:13:22 -07001848 espin "$NOT_VERIFIED"
Matteo Scandoloe0829b52020-05-08 14:23:56 -07001849 # ONOS CLASSIC identifies its image repo/tag/pullPolicy differently, so yq is used to grab the values from the
David Bainbridge60ffc0f2020-04-27 22:13:22 -07001850 # values value
David Bainbridgefad50732020-05-01 17:00:12 -07001851 YAML_VALUES=$(INTERNAL_EXTRA_HELM_INSTALL_ARGS="--set replicas=$NUM_OF_ONOS --set atomix.replicas=$NUM_OF_ATOMIX" \
1852 helm_values "$INFRA_NS" onos "$ONOS_CLASSIC_CHART" "$ONOS_CLASSIC_CHART_VERSION")
1853 _ONOS_REPO="$(echo "$YAML_VALUES" | yq read - images.onos.repository)"
David Bainbridgedee3f022020-06-05 07:45:13 -07001854 if [ -z "$_ONOS_REPO" ]; then
1855 _ONOS_REPO="voltha/voltha-onos"
1856 fi
David Bainbridgefad50732020-05-01 17:00:12 -07001857 _ONOS_TAG="$(echo "$YAML_VALUES" | yq read - images.onos.tag)"
David Bainbridge60ffc0f2020-04-27 22:13:22 -07001858 if [ -z "$_ONOS_TAG" ]; then
David Bainbridgedee3f022020-06-05 07:45:13 -07001859 _ONOS_TAG="$(echo "$YAML_VALUES" | yq read - defaults.image_tag)"
1860 fi
1861 if [ -z "$_ONOS_TAG" ]; then
1862 _ONOS_TAG="master"
1863 fi
1864 _ONOS_PULL_POLICY="$(echo "$YAML_VALUES" | yq read - images.onos.pullPolicy)"
1865 if [ -z "$_ONOS_PULL_POLICY" ]; then
1866 _ONOS_PULL_POLICY="$(echo "$YAML_VALUES" | yq read - defaults.image_pullPolicy)"
1867 fi
1868 if [ -z "$_ONOS_PULL_POLICY" ]; then
1869 _ONOS_PULL_POLICY="Always"
David Bainbridge60ffc0f2020-04-27 22:13:22 -07001870 fi
David Bainbridgefad50732020-05-01 17:00:12 -07001871
Matteo Scandoloe0829b52020-05-08 14:23:56 -07001872 INTERNAL_EXTRA_HELM_INSTALL_ARGS="--set image.pullPolicy=$_ONOS_PULL_POLICY,image.repository=$_ONOS_REPO,image.tag=$_ONOS_TAG,replicas=$NUM_OF_ONOS,atomix.replicas=$NUM_OF_ATOMIX" \
David Bainbridge33e56c72020-06-11 11:39:56 -07001873 helm_install - "$INFRA_NS" onos "$ONOS_CLASSIC_CHART" "$ONOS_CLASSIC_CHART_VERSION" "+onos" "$_HELM_DESC ONOS CLASSIC"
David Bainbridge60ffc0f2020-04-27 22:13:22 -07001874 INTERNAL_EXTRA_HELM_INSTALL_ARGS=
1875 else
1876 espin "$VERIFIED"
1877 fi
1878 wait_for_pods - "$INFRA_NS" $((NUM_OF_ONOS + NUM_OF_ATOMIX)) "includes" "Waiting for ONOS CLASSIC to start" "$NO_LABEL" "onos-.*"
1879 if [ "$WITH_PORT_FORWARDS" == "yes" ]; then
1880 bspin - "Forward ONOS API port $FORWARD"
1881 kill_port_forward onos-onos-classic-hs
1882 port_forward "$INFRA_NS" onos-onos-classic-hs "$ONOS_API_PORT:8181" "$ONOS_SSH_PORT:8101"
1883 espin - "$VERIFIED"
1884 _ONOS_API_EP="127.0.0.1:$ONOS_API_PORT"
1885 else
1886 _ONOS_API_EP="$(get_service_ep "$INFRA_NS" onos-onos-classic-hs)"
1887 fi
1888 elif [ "$WITH_ONOS" == "micro" ]; then
1889 bspin "Verify micro-ONOS installed $BIRD"
1890 # We should never get here
1891 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} Micro ONOS not currently supported${NORMAL}"
1892 exit 1
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -08001893 fi
David Bainbridged31d6122019-08-13 19:37:59 +00001894 bspin - "Verify or download ONOS configuration support files $DOWNLOAD"
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001895 ONOS_FILES="olt-onos-enableExtraneousRules.json onos-aaa.json \
David Bainbridge696bc632020-04-05 21:49:37 -07001896 onos-dhcpl2relay.json onos-sadis-sample.json"
David Bainbridged18f4942020-04-14 16:46:13 -07001897 (set -x; mkdir -p ./onos-files >>"$LOG" 2>&1) >>"$LOG" 2>&1
1898 ERR_OUT="$(mktemp)"
David Bainbridge2b19e832019-08-16 02:40:53 +00001899 for i in $ONOS_FILES; do
David Bainbridged18f4942020-04-14 16:46:13 -07001900 if [ ! -r "./onos-files/$i" ]; then
serkant.uluderya4d315132020-04-15 16:25:54 -07001901 if ! (set -x; curl --fail -o "./onos-files/$i" -sSL "https://raw.githubusercontent.com/opencord/kind-voltha/$VK_RELEASE/onos-files/$i" >>"$LOG" 2>"$ERR_OUT") >>"$LOG" 2>&1; then
David Bainbridged18f4942020-04-14 16:46:13 -07001902 espin - "$THEX"
1903 echo -e "${RED}${BOLD}${ERROR}ERROR: $i${NORMAL}${RED} - $(cat "$ERR_OUT")${NORMAL}"
1904 echo "ERROR: $(cat "$ERR_OUT")" >>"$LOG"
1905 rm -rf "$ERR_OUT" "./onos-files/$i"
David K. Bainbridgea00736b2020-01-08 14:33:17 -08001906 exit 1
1907 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001908 rm -rf "$ERR_OUT"
David Bainbridged31d6122019-08-13 19:37:59 +00001909 fi
1910 done
David Bainbridged18f4942020-04-14 16:46:13 -07001911 rm -rf "$ERR_OUT"
1912 espin - "$VERIFIED"
David Bainbridge27790d62019-08-13 22:43:19 +00001913
David Bainbridged18f4942020-04-14 16:46:13 -07001914 if [ "$INSTALL_ONOS_APPS" == "yes" ]; then
David Bainbridge27790d62019-08-13 22:43:19 +00001915 bspin - "Installing custom ONOS applications"
David Bainbridged18f4942020-04-14 16:46:13 -07001916 if [ -x onos-files/onos-apps ] && [ "$(find onos-files/onos-apps -name "*.oar" 2>/dev/null | wc -l)" -gt 0 ]; then
1917 for OAR in onos-files/onos-apps/*.oar; do
David Bainbridge27790d62019-08-13 22:43:19 +00001918 sspin - "Installing custom ONOS applications - $OAR$CEOL"
David Bainbridged18f4942020-04-14 16:46:13 -07001919 override_onos_app "$OAR"
David Bainbridge27790d62019-08-13 22:43:19 +00001920 done
1921 espin - "$VERIFIED Installing custom ONOS applications$CEOL"
1922 else
1923 espin - "$NOT_VERIFIED Installing custom ONOS applications - None Found"
1924 fi
1925 fi
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001926
David Bainbridged18f4942020-04-14 16:46:13 -07001927 if [ "$WITH_KAFKA" != "no" ]; then
David Bainbridge837e8bd2020-04-06 13:17:14 -07001928 check_onos_app_active org.opencord.kafka
David Bainbridge879439b2020-06-12 15:59:35 -07001929 if is_in "$WITH_KAFKA" "yes,external"; then
David Bainbridgec7220622020-05-28 12:31:47 -07001930 _HOST=kafka.$INFRA_NS.svc
David Bainbridge76afd812020-04-06 09:53:52 -07001931 _PORT=9092
David Bainbridge879439b2020-06-12 15:59:35 -07001932 elif [ "$WITH_KAFKA" != "no" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001933 _HOST="$(echo "$WITH_KAFKA" | cut -d: -f1)"
1934 _PORT="$(echo "$WITH_KAFKA" | cut -s -d: -f2)"
David Bainbridge837e8bd2020-04-06 13:17:14 -07001935 _PORT=${_PORT:-9092}
1936 fi
1937 push_onos_config "json" "Push ONOS Kafka Configuration" "network/configuration/apps/org.opencord.kafka" \
David Bainbridged18f4942020-04-14 16:46:13 -07001938 "$(cat <<EOJ | tr -d '[:space:]'
David Bainbridge696bc632020-04-05 21:49:37 -07001939{
1940 "kafka": {
1941 "bootstrapServers": "$_HOST:$_PORT"
1942 }
1943}
1944EOJ
David Bainbridged18f4942020-04-14 16:46:13 -07001945)"
David Bainbridge837e8bd2020-04-06 13:17:14 -07001946 fi
Matteo Scandolo9a77a732020-01-09 14:24:12 -08001947 check_onos_app_active org.opencord.dhcpl2relay
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001948 push_onos_config "file" "Push ONOS DHCP L2 Relay Configuration" "network/configuration/apps/org.opencord.dhcpl2relay" "onos-files/onos-dhcpl2relay.json"
Matteo Scandolo9a77a732020-01-09 14:24:12 -08001949 check_onos_app_active org.opencord.olt
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001950 # FIXME use WITH_DHCP and WITH_EAPOL flags to configre OLT App
Hardik Windlassa7501fb2020-02-17 14:28:20 +00001951 # Default value for "enableEapol" is true in OLT App
David Bainbridged18f4942020-04-14 16:46:13 -07001952 if [ "$WITH_EAPOL" == "yes" ]; then
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001953 push_onos_config "json" "Enable VOLTHA ONOS EAPOL provisioning" "configuration/org.opencord.olt.impl.OltFlowService" '{"enableEapol":true}'
David Bainbridged18f4942020-04-14 16:46:13 -07001954 elif [ "$WITH_EAPOL" == "no" ]; then
Hardik Windlassa7501fb2020-02-17 14:28:20 +00001955 push_onos_config "json" "Disable VOLTHA ONOS EAPOL provisioning" "configuration/org.opencord.olt.impl.OltFlowService" '{"enableEapol":false}'
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001956 fi
Hardik Windlassa7501fb2020-02-17 14:28:20 +00001957 # Default value for "enableDhcpOnProvisioning" is false and for "enableDhcpV4" is true in OLT App
David Bainbridged18f4942020-04-14 16:46:13 -07001958 if [ "$WITH_DHCP" == "yes" ]; then
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001959 push_onos_config "json" "Enable VOLTHA ONOS DHCP provisioning" "configuration/org.opencord.olt.impl.OltFlowService" '{"enableDhcpOnProvisioning":true,"enableDhcpV4":true}'
David Bainbridged18f4942020-04-14 16:46:13 -07001960 elif [ "$WITH_DHCP" == "no" ]; then
Hardik Windlassa7501fb2020-02-17 14:28:20 +00001961 push_onos_config "json" "Disable VOLTHA ONOS DHCP provisioning" "configuration/org.opencord.olt.impl.OltFlowService" '{"enableDhcpOnProvisioning":false,"enableDhcpV4":false}'
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001962 fi
Hardik Windlassa7501fb2020-02-17 14:28:20 +00001963 # Default value for "enableIgmpOnProvisioning" is false in OLT App
David Bainbridged18f4942020-04-14 16:46:13 -07001964 if [ "$WITH_IGMP" == "yes" ]; then
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001965 push_onos_config "json" "Enable VOLTHA ONOS IGMP provisioning" "configuration/org.opencord.olt.impl.OltFlowService" '{"enableIgmpOnProvisioning":true}'
David Bainbridged18f4942020-04-14 16:46:13 -07001966 elif [ "$WITH_IGMP" == "no" ]; then
Hardik Windlassa7501fb2020-02-17 14:28:20 +00001967 push_onos_config "json" "Disable VOLTHA ONOS IGMP provisioning" "configuration/org.opencord.olt.impl.OltFlowService" '{"enableIgmpOnProvisioning":false}'
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001968 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001969 if [ "$ENABLE_ONOS_EXTRANEOUS_RULES" == "yes" ]; then
David K. Bainbridge484d80c2020-03-05 21:44:34 -08001970 push_onos_config "file" "Enabling extraneous rules for ONOS" "configuration/org.onosproject.net.flow.impl.FlowRuleManager" "onos-files/olt-onos-enableExtraneousRules.json"
1971 fi
David Bainbridge60ffc0f2020-04-27 22:13:22 -07001972 if is_in "$CONFIG_SADIS" "yes,file"; then
Matteo Scandolo9a77a732020-01-09 14:24:12 -08001973 check_onos_app_active org.opencord.sadis
Hardik Windlassb3147602020-03-09 16:59:15 +05301974 push_onos_config "file" "[optional] Push ONOS SADIS Configuration: $SADIS_CFG" "network/configuration/apps/org.opencord.sadis" "$SADIS_CFG"
David K. Bainbridgeb859e912020-03-13 14:07:52 -07001975 elif [ "$CONFIG_SADIS" == "bbsim" ]; then
1976 push_onos_config "json" \
1977 "[optional] Push ONOS configuration for BBSIM SADIS servers" \
1978 "network/configuration/apps/org.opencord.sadis" \
David Bainbridged18f4942020-04-14 16:46:13 -07001979 "$(cat <<EOJ | tr -d '[:space:]'
David K. Bainbridgeb859e912020-03-13 14:07:52 -07001980{
1981 "sadis": {
1982 "integration": {
David Bainbridgec7220622020-05-28 12:31:47 -07001983 "url": "http://$BBSIM_SADIS_SVC.$BBSIM_NS.svc:50074/v2/subscribers/%s",
David K. Bainbridgeb859e912020-03-13 14:07:52 -07001984 "cache": {
1985 "enabled": true,
1986 "maxsize": 50,
1987 "ttl": "PT1m"
1988 }
1989 }
1990 },
1991 "bandwidthprofile": {
1992 "integration": {
David Bainbridgec7220622020-05-28 12:31:47 -07001993 "url": "http://$BBSIM_SADIS_SVC.$BBSIM_NS.svc:50074/v2/bandwidthprofiles/%s",
David K. Bainbridgeb859e912020-03-13 14:07:52 -07001994 "cache": {
1995 "enabled": true,
1996 "maxsize": 50,
1997 "ttl": "PT1m"
1998 }
1999 }
2000 }
2001}
2002EOJ
David Bainbridged18f4942020-04-14 16:46:13 -07002003)"
David K. Bainbridgeb859e912020-03-13 14:07:52 -07002004 elif [ "$CONFIG_SADIS" == "url" ]; then
2005 push_onos_config "json" \
2006 "[optional] Push ONOS configuration for custom SADIS and Bandwidth Profile servers" \
2007 "network/configuration/apps/org.opencord.sadis" \
David Bainbridged18f4942020-04-14 16:46:13 -07002008 "$(cat <<EOJ | tr -d '[:space:]'
David K. Bainbridgeb859e912020-03-13 14:07:52 -07002009{
2010 "sadis": {
2011 "integration": {
2012 "url": "$SADIS_SUBSCRIBERS",
2013 "cache": {
2014 "enabled": true,
2015 "maxsize": 50,
2016 "ttl": "PT1m"
2017 }
2018 }
2019 },
2020 "bandwidthprofile": {
2021 "integration": {
2022 "url": "$SADIS_BANDWIDTH_PROFILES",
2023 "cache": {
2024 "enabled": true,
2025 "maxsize": 50,
2026 "ttl": "PT1m"
2027 }
2028 }
2029 }
2030}
2031EOJ
David Bainbridged18f4942020-04-14 16:46:13 -07002032)"
David Bainbridge2b19e832019-08-16 02:40:53 +00002033 fi
Test Userba1e7e72019-07-10 22:27:54 +00002034fi
David Bainbridgee87067b2019-08-12 22:00:12 +00002035if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07002036 NOW="$(date +%s)"
2037 printtime $((NOW - STIME))
David Bainbridgee87067b2019-08-12 22:00:12 +00002038fi
Test Userba1e7e72019-07-10 22:27:54 +00002039
David Bainbridgec7220622020-05-28 12:31:47 -07002040if is_in "$WITH_ETCD" "yes,external"; then
David Bainbridged18f4942020-04-14 16:46:13 -07002041 STIME="$(date +%s)"
David Bainbridge76afd812020-04-06 09:53:52 -07002042 bspin "Verify external ETCD cluster $OLD_KEY"
Matteo Scandolo657e13c2020-07-28 11:41:42 -07002043 EXPECT=$NUM_OF_ETCD
David Bainbridgeb4bbde12020-06-25 14:46:36 -07002044 if [ "$HELM_USE_UPGRADE" == "yes" ] || [ "$(helm_is_deployed "$INFRA_NS" "^etcd\$")" -ne 1 ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07002045 espin "$NOT_VERIFIED"
Matteo Scandolo657e13c2020-07-28 11:41:42 -07002046 INTERNAL_EXTRA_HELM_INSTALL_ARGS="--set replicas=$NUM_OF_ETCD" helm_install - "$INFRA_NS" etcd "$ETCD_CHART" "$ETCD_CHART_VERSION" etcd "$_HELM_DESC external ETCD cluster"
2047 INTERNAL_EXTRA_HELM_INSTALL_ARGS=
David Bainbridge76afd812020-04-06 09:53:52 -07002048 else
David Bainbridged18f4942020-04-14 16:46:13 -07002049 espin "$VERIFIED"
David Bainbridge76afd812020-04-06 09:53:52 -07002050 fi
David Bainbridgec7220622020-05-28 12:31:47 -07002051 wait_for_pods - "$INFRA_NS" "$EXPECT" "includes" "Waiting for ETCD cluster to start" "$NO_LABEL" "etcd-.*"
David Bainbridge76afd812020-04-06 09:53:52 -07002052 if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07002053 NOW="$(date +%s)"
2054 printtime $((NOW - STIME))
David Bainbridge76afd812020-04-06 09:53:52 -07002055 fi
2056fi
2057
David Bainbridgec7220622020-05-28 12:31:47 -07002058if is_in "$WITH_KAFKA" "yes,external"; then
David Bainbridged18f4942020-04-14 16:46:13 -07002059 _TMP="$(mktemp -u)"
David Bainbridged18f4942020-04-14 16:46:13 -07002060 cat << EOC > "$_TMP"
David Bainbridge76afd812020-04-06 09:53:52 -07002061configurationOverrides:
Matteo Scandolo657e13c2020-07-28 11:41:42 -07002062 "default.replication.factor": $NUM_OF_KAFKA
2063 "offsets.topic.replication.factor": $NUM_OF_KAFKA
David Bainbridge76afd812020-04-06 09:53:52 -07002064 "log.retention.hours": 4
2065 "log.message.timestamp.type": "LogAppendTime"
2066persistence:
2067 enabled: false
2068zookeeper:
Matteo Scandolo657e13c2020-07-28 11:41:42 -07002069 replicaCount: $NUM_OF_KAFKA
David Bainbridge76afd812020-04-06 09:53:52 -07002070 persistence:
2071 enabled: false
Matteo Scandolo657e13c2020-07-28 11:41:42 -07002072replicas: $NUM_OF_KAFKA
David Bainbridge76afd812020-04-06 09:53:52 -07002073EOC
David Bainbridged18f4942020-04-14 16:46:13 -07002074 STIME="$(date +%s)"
David Bainbridge76afd812020-04-06 09:53:52 -07002075 bspin "Verify external Kafka cluster $OLD_KEY"
Matteo Scandolo657e13c2020-07-28 11:41:42 -07002076 EXPECT=$((NUM_OF_KAFKA*2))
David Bainbridgeb4bbde12020-06-25 14:46:36 -07002077 if [ "$HELM_USE_UPGRADE" == "yes" ] || [ "$(helm_is_deployed "$INFRA_NS" "^kafka\$")" -ne 1 ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07002078 espin "$NOT_VERIFIED"
David Bainbridge76afd812020-04-06 09:53:52 -07002079 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" -f $_TMP"
David Bainbridgec7220622020-05-28 12:31:47 -07002080 helm_install - "$INFRA_NS" kafka "$KAFKA_CHART" "$KAFKA_CHART_VERSION" kafka "$_HELM_DESC external Kafka cluster"
David Bainbridge76afd812020-04-06 09:53:52 -07002081 else
David Bainbridged18f4942020-04-14 16:46:13 -07002082 espin "$VERIFIED"
David Bainbridge76afd812020-04-06 09:53:52 -07002083 fi
David Bainbridged18f4942020-04-14 16:46:13 -07002084 wait_for_pods - "$INFRA_NS" "$EXPECT" "includes" "Waiting for Kafka cluster to start" "$NO_LABEL" "kafka-.*"
David Bainbridge76afd812020-04-06 09:53:52 -07002085 if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07002086 NOW="$(date +%s)"
2087 printtime $((NOW - STIME))
David Bainbridge76afd812020-04-06 09:53:52 -07002088 fi
David Bainbridged18f4942020-04-14 16:46:13 -07002089 rm -rf "$_TMP"
David Bainbridge76afd812020-04-06 09:53:52 -07002090fi
2091
David Bainbridged18f4942020-04-14 16:46:13 -07002092STIME="$(date +%s)"
David Bainbridgeed476572020-06-02 14:05:45 -07002093EXPECT=2
2094# therecanbeonlyone set hardcoded to true for backward compatibility
2095INTERNAL_EXTRA_HELM_INSTALL_ARGS="--set therecanbeonlyone=true"
Matteo Scandolo67335f02020-04-09 11:19:53 -07002096case $WITH_ETCD in
David Bainbridge76afd812020-04-06 09:53:52 -07002097 no)
David Bainbridge76afd812020-04-06 09:53:52 -07002098 ;;
David Bainbridgec7220622020-05-28 12:31:47 -07002099 yes|external)
2100 _HOST="etcd.$INFRA_NS.svc"
David Bainbridge76afd812020-04-06 09:53:52 -07002101 _PORT=2379
David K. Bainbridgeec1cdf32020-07-23 15:51:07 +00002102 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set services.etcd.service=$_HOST --set services.etcd.port=$_PORT"
Neha Sharmaa1c92ca2020-06-24 11:50:33 +00002103 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set services.etcd.address=$_HOST:$_PORT"
David Bainbridge76afd812020-04-06 09:53:52 -07002104 ;;
2105 *)
David Bainbridged18f4942020-04-14 16:46:13 -07002106 _HOST="$(echo "$WITH_ETCD" | cut -d: -f1)"
2107 _PORT="$(echo "$WITH_ETCD" | cut -s -d: -f2)"
David Bainbridge696bc632020-04-05 21:49:37 -07002108 _PORT=${_PORT:-2379}
David K. Bainbridgeec1cdf32020-07-23 15:51:07 +00002109 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set services.etcd.service=$_HOST --set services.etcd.port=$_PORT"
Neha Sharmaa1c92ca2020-06-24 11:50:33 +00002110 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set services.etcd.address=$_HOST:$_PORT"
David Bainbridge76afd812020-04-06 09:53:52 -07002111 ;;
2112esac
2113case $WITH_KAFKA in
2114 no)
David Bainbridge76afd812020-04-06 09:53:52 -07002115 ;;
David Bainbridgec7220622020-05-28 12:31:47 -07002116 yes|external)
2117 _HOST=kafka.$INFRA_NS.svc
David Bainbridge76afd812020-04-06 09:53:52 -07002118 _PORT=9092
David K. Bainbridgeec1cdf32020-07-23 15:51:07 +00002119 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set kafka_broker=$_HOST:$_PORT --set services.kafka.adapter.service=$_HOST --set services.kafka.adapter.port=$_PORT --set services.kafka.cluster.service=$_HOST --set services.kafka.cluster.port=$_PORT"
2120 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set services.kafka.adapter.address=$_HOST:$_PORT --set services.kafka.cluster.address=$_HOST:$_PORT"
David Bainbridge76afd812020-04-06 09:53:52 -07002121 ;;
2122 *)
David Bainbridged18f4942020-04-14 16:46:13 -07002123 _HOST="$(echo "$WITH_KAFKA" | cut -d: -f1)"
2124 _PORT="$(echo "$WITH_KAFKA" | cut -s -d: -f2)"
David Bainbridge696bc632020-04-05 21:49:37 -07002125 _PORT=${_PORT:-9092}
David K. Bainbridgeec1cdf32020-07-23 15:51:07 +00002126 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set kafka_broker=$_HOST:$_PORT --set services.kafka.adapter.service=$_HOST --set services.kafka.adapter.port=$_PORT --set services.kafka.cluster.service=$_HOST --set services.kafka.cluster.port=$_PORT"
2127 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set services.kafka.adapter.address=$_HOST:$_PORT --set services.kafka.cluster.address=$_HOST:$_PORT"
David Bainbridge76afd812020-04-06 09:53:52 -07002128 ;;
2129esac
2130
David Bainbridge60ffc0f2020-04-27 22:13:22 -07002131if is_in "$WITH_ONOS" "legacy"; then
David Bainbridgec7220622020-05-28 12:31:47 -07002132 _HOST=onos-openflow.$INFRA_NS.svc
David Bainbridge76afd812020-04-06 09:53:52 -07002133 _PORT=6653
David Bainbridge60ffc0f2020-04-27 22:13:22 -07002134elif is_in "$WITH_ONOS" "yes,classic"; then
David Bainbridgec7220622020-05-28 12:31:47 -07002135 _HOST=onos-onos-classic-hs.$INFRA_NS.svc
David Bainbridge60ffc0f2020-04-27 22:13:22 -07002136 _PORT=6653
David Bainbridged18f4942020-04-14 16:46:13 -07002137elif [ "$WITH_ONOS" != "no" ]; then
2138 _HOST="$(echo "$WITH_ONOS" | cut -d: -f1)"
2139 _PORT="$(echo "$WITH_ONOS" | cut -s -d: -f2)"
David Bainbridge76afd812020-04-06 09:53:52 -07002140 _PORT=${_PORT:-6653}
Jonathan Hart6a91e6c2020-04-16 14:28:33 -07002141fi
David Bainbridge60ffc0f2020-04-27 22:13:22 -07002142
David Bainbridgecf546362020-04-21 23:18:50 -07002143compare_versions "$RESOLVED_VOLTHA_CHART_VERSION" 2.4.2
Jonathan Hart6a91e6c2020-04-16 14:28:33 -07002144if [ "$?" == "1" ]; then
2145 # voltha chart > 2.4.2 uses list of controllers
David Bainbridgee4d11ca2020-05-08 10:21:10 -07002146 for NUM in $(seq 0 $((NUM_OF_ONOS-1))); do
David K. Bainbridgeec1cdf32020-07-23 15:51:07 +00002147 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set services.controller[$NUM].service=onos-onos-classic-$NUM.onos-onos-classic-hs.$INFRA_NS.svc --set services.controller[$NUM].port=6653"
Neha Sharmaa1c92ca2020-06-24 11:50:33 +00002148 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set services.controller[$NUM].address=onos-onos-classic-$NUM.onos-onos-classic-hs.$INFRA_NS.svc:6653"
David Bainbridgee4d11ca2020-05-08 10:21:10 -07002149 done
Jonathan Hart6a91e6c2020-04-16 14:28:33 -07002150else
2151 # voltha chart <= 2.4.2 uses single controller
David K. Bainbridgeec1cdf32020-07-23 15:51:07 +00002152 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set services.controller.service=$_HOST --set services.controller.port=$_PORT"
Neha Sharmaa1c92ca2020-06-24 11:50:33 +00002153 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set services.controller.address=$_HOST:$_PORT"
David Bainbridge696bc632020-04-05 21:49:37 -07002154fi
Jonathan Hart6a91e6c2020-04-16 14:28:33 -07002155
Test Userb5712372019-07-03 21:52:17 +00002156bspin "Verify VOLTHA installed $HIGH_VOLTAGE"
David Bainbridgeb4bbde12020-06-25 14:46:36 -07002157if [ "$HELM_USE_UPGRADE" == "yes" ] || [ "$(helm_is_deployed "$VOLTHA_NS" "^voltha\$")" -ne 1 ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07002158 espin "$NOT_VERIFIED"
David Bainbridgea965ca22020-06-09 17:45:04 -07002159 helm_install - "$VOLTHA_NS" voltha "$VOLTHA_CHART" "$VOLTHA_CHART_VERSION" "+voltha" "$_HELM_DESC VOLTHA Core"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07002160else
David Bainbridged18f4942020-04-14 16:46:13 -07002161 espin "$VERIFIED"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07002162fi
David Bainbridge696bc632020-04-05 21:49:37 -07002163INTERNAL_EXTRA_HELM_INSTALL_ARGS=
Test Userba1e7e72019-07-10 22:27:54 +00002164
David Bainbridge90fd8e32019-08-21 23:32:47 +00002165VOLTHA="voltha-ofagent-.* \
David K. Bainbridgeb7285432019-07-02 22:05:24 -07002166 rw-core.* \
David K. Bainbridgeb7285432019-07-02 22:05:24 -07002167 voltha-zookeeper-.*"
David Bainbridged18f4942020-04-14 16:46:13 -07002168wait_for_pods - "$VOLTHA_NS" "$EXPECT" "includes" "Waiting for VOLTHA Core to start" "$NO_LABEL" "$VOLTHA"
David Bainbridgee87067b2019-08-12 22:00:12 +00002169if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07002170 NOW="$(date +%s)"
2171 printtime $((NOW - STIME))
David Bainbridgee87067b2019-08-12 22:00:12 +00002172fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07002173
David Bainbridge46505fb2019-10-01 21:13:20 +00002174if [ "$WITH_ADAPTERS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07002175 STIME="$(date +%s)"
David Bainbridge46505fb2019-10-01 21:13:20 +00002176 EXPECT=0
David Bainbridgec7220622020-05-28 12:31:47 -07002177 if is_in "$WITH_ETCD" "yes,external"; then
2178 _HOST=etcd.$INFRA_NS.svc
David Bainbridge3517f6c2020-04-08 12:14:08 -07002179 _PORT=2379
David K. Bainbridgeec1cdf32020-07-23 15:51:07 +00002180 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set services.etcd.service=$_HOST --set services.etcd.port=$_PORT"
2181 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set services.etcd.address=$_HOST:$_PORT"
David Bainbridged18f4942020-04-14 16:46:13 -07002182 elif [ "$WITH_ETCD" != "no" ]; then
2183 _HOST="$(echo "$WITH_ETCD" | cut -d: -f1)"
2184 _PORT="$(echo "$WITH_ETCD" | cut -s -d: -f2)"
David Bainbridge3517f6c2020-04-08 12:14:08 -07002185 _PORT=${_PORT:-2379}
David K. Bainbridgeec1cdf32020-07-23 15:51:07 +00002186 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set services.etcd.service=$_HOST --set services.etcd.port=$_PORT"
2187 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set services.etcd.address=$_HOST:$_PORT"
David Bainbridge696bc632020-04-05 21:49:37 -07002188 fi
David Bainbridgec7220622020-05-28 12:31:47 -07002189 if is_in "$WITH_KAFKA" "yes,external"; then
2190 _HOST=kafka.$INFRA_NS.svc
David Bainbridge3517f6c2020-04-08 12:14:08 -07002191 _PORT=9092
David K. Bainbridgeec1cdf32020-07-23 15:51:07 +00002192 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set kafka_broker=$_HOST:$_PORT --set services.kafka.adapter.service=$_HOST --set services.kafka.adapter.port=$_PORT --set services.kafka.cluster.service=$_HOST --set services.kafka.cluster.port=$_PORT"
2193 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set services.kafka.adapter.address=$_HOST:$_PORT --set services.kafka.cluster.address=$_HOST:$_PORT"
David Bainbridged18f4942020-04-14 16:46:13 -07002194 elif [ "$WITH_KAFKA" != "no" ]; then
2195 _HOST="$(echo "$WITH_KAFKA" | cut -d: -f1)"
2196 _PORT="$(echo "$WITH_KAFKA" | cut -s -d: -f2)"
David Bainbridge3517f6c2020-04-08 12:14:08 -07002197 _PORT=${_PORT:-9092}
David K. Bainbridgeec1cdf32020-07-23 15:51:07 +00002198 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set kafka_broker=$_HOST:$_PORT --set services.kafka.adapter.service=$_HOST --set services.kafka.adapter.port=$_PORT --set services.kafka.cluster.service=$_HOST --set services.kafka.cluster.port=$_PORT"
2199 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set services.kafka.adapter.address=$_HOST:$_PORT --set services.kafka.cluster.address=$_HOST:$_PORT"
David Bainbridge696bc632020-04-05 21:49:37 -07002200 fi
David Bainbridge46505fb2019-10-01 21:13:20 +00002201 echo -e "Verify Adapters $PLUG"
2202 if [ "$WITH_SIM_ADAPTERS" == "yes" ]; then
2203 bspin - "Verify Simulated Adapters installed"
David Bainbridgeb4bbde12020-06-25 14:46:36 -07002204 if [ "$HELM_USE_UPGRADE" == "yes" ] || [ "$(helm_is_deployed "$ADAPTER_NS" "^sim\$")" -ne 1 ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07002205 espin - "$NOT_VERIFIED"
David Bainbridgec7220622020-05-28 12:31:47 -07002206 helm_install - "$ADAPTER_NS" sim "$VOLTHA_ADAPTER_SIM_CHART" "$VOLTHA_ADAPTER_SIM_CHART_VERSION" - "$_HELM_DESC Simulated Adapters"
David Bainbridge46505fb2019-10-01 21:13:20 +00002207 else
David Bainbridged18f4942020-04-14 16:46:13 -07002208 espin - "$VERIFIED"
David Bainbridge46505fb2019-10-01 21:13:20 +00002209 fi
David Bainbridged18f4942020-04-14 16:46:13 -07002210 EXPECT="$((EXPECT + 2))"
David Bainbridge46505fb2019-10-01 21:13:20 +00002211 fi
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07002212
David Bainbridge46505fb2019-10-01 21:13:20 +00002213 if [ "$WITH_OPEN_ADAPTERS" == "yes" ]; then
2214 bspin - "Verify OpenOLT Adapter installed"
David Bainbridgeb4bbde12020-06-25 14:46:36 -07002215 if [ "$HELM_USE_UPGRADE" == "yes" ] || [ "$(helm_is_deployed "$ADAPTER_NS" "^open-olt\$")" -ne 1 ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07002216 espin - "$NOT_VERIFIED"
David Bainbridgea965ca22020-06-09 17:45:04 -07002217 helm_install - "$ADAPTER_NS" open-olt "$VOLTHA_ADAPTER_OPEN_OLT_CHART" "$VOLTHA_ADAPTER_OPEN_OLT_CHART_VERSION" "+open-olt" "$_HELM_DESC OpenOLT Adapter"
David Bainbridge46505fb2019-10-01 21:13:20 +00002218 else
David Bainbridged18f4942020-04-14 16:46:13 -07002219 espin - "$VERIFIED"
David Bainbridge46505fb2019-10-01 21:13:20 +00002220 fi
Matteo Scandolo67335f02020-04-09 11:19:53 -07002221 EXPECT="$((EXPECT + 1))"
David Bainbridge46505fb2019-10-01 21:13:20 +00002222 bspin - "Verify OpenONU Adapter installed"
David Bainbridgeb4bbde12020-06-25 14:46:36 -07002223 if [ "$HELM_USE_UPGRADE" == "yes" ] || [ "$(helm_is_deployed "$ADAPTER_NS" "^open-onu\$")" -ne 1 ]; then
Matteo Scandolo67335f02020-04-09 11:19:53 -07002224 _ORIGINAL_EXTRA_HELM_INSTALL_ARGS="$INTERNAL_EXTRA_HELM_INSTALL_ARGS"
2225 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set replicas.adapter_open_onu=$NUM_OF_OPENONU"
Girish Gowdra4cc5d8b2020-06-11 17:12:00 -07002226 if [ "$WITH_INCREMENTAL_EVTO_UPDATE" == "yes" ]; then
Girish Gowdra1c7ad4c2020-06-26 13:35:16 -07002227 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set defaults.incremental_evto_update=true"
Girish Gowdra4cc5d8b2020-06-11 17:12:00 -07002228 fi
David Bainbridged18f4942020-04-14 16:46:13 -07002229 espin - "$NOT_VERIFIED"
David Bainbridgea965ca22020-06-09 17:45:04 -07002230 helm_install - "$ADAPTER_NS" open-onu "$VOLTHA_ADAPTER_OPEN_ONU_CHART" "$VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION" "+open-onu" "$_HELM_DESC OpenONU Adapter"
Matteo Scandolo67335f02020-04-09 11:19:53 -07002231 INTERNAL_EXTRA_HELM_INSTALL_ARGS="$_ORIGINAL_EXTRA_HELM_INSTALL_ARGS"
David Bainbridge46505fb2019-10-01 21:13:20 +00002232 else
David Bainbridged18f4942020-04-14 16:46:13 -07002233 espin - "$VERIFIED"
David Bainbridge46505fb2019-10-01 21:13:20 +00002234 fi
Matteo Scandolo67335f02020-04-09 11:19:53 -07002235 EXPECT=$((EXPECT + NUM_OF_OPENONU))
David Bainbridge46505fb2019-10-01 21:13:20 +00002236 fi
David Bainbridge696bc632020-04-05 21:49:37 -07002237 INTERNAL_EXTRA_HELM_INSTALL_ARGS=
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07002238
David Bainbridge46505fb2019-10-01 21:13:20 +00002239 ADAPTERS="adapter-.*"
David Bainbridged18f4942020-04-14 16:46:13 -07002240 wait_for_pods - "$ADAPTER_NS" "$EXPECT" "includes" "Waiting for adapters to start" "$NO_LABEL" "$ADAPTERS"
David Bainbridge46505fb2019-10-01 21:13:20 +00002241 if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07002242 NOW="$(date +%s)"
2243 printtime $((NOW - STIME))
David Bainbridge46505fb2019-10-01 21:13:20 +00002244 fi
David Bainbridgee87067b2019-08-12 22:00:12 +00002245fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07002246
David Bainbridged18f4942020-04-14 16:46:13 -07002247if [ "$WITH_BBSIM" == "yes" ]; then
2248 STIME="$(date +%s)"
Test User7d866122019-07-09 17:52:35 +00002249 echo -e "Verify BBSIM $PLUG"
David Bainbridge5b7b96b2019-07-25 20:29:13 +00002250 bspin - "Verify BBSIM Installed"
David Bainbridged18f4942020-04-14 16:46:13 -07002251 for instance in $(seq 0 $((NUM_OF_BBSIM-1))); do
Matteo Scandoloc2eb0672020-05-01 14:43:15 -07002252
2253 if [ "$LEGACY_BBSIM_INDEX" == "yes" ]; then
2254 if [ "$instance" -eq 0 ]; then
2255 instance_num=""
2256 else
2257 instance_num=$instance
2258 fi
David K. Bainbridge43422402020-03-06 07:41:22 -08002259 else
2260 instance_num=$instance
2261 fi
Matteo Scandoloc2eb0672020-05-01 14:43:15 -07002262
2263
David Bainbridgeb4bbde12020-06-25 14:46:36 -07002264 if [ "$HELM_USE_UPGRADE" == "yes" ] || [ "$(helm_is_deployed "$BBSIM_NS" "^bbsim${instance_num}\$")" -ne 1 ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07002265 espin - "$NOT_VERIFIED"
2266 S_TAG="$((900+instance))"
Matteo Scandolo5a149572020-04-01 10:14:57 -07002267 INTERNAL_EXTRA_HELM_INSTALL_ARGS="--set olt_id=$instance,s_tag=$S_TAG"
David Bainbridged9329af2020-05-01 11:58:52 -07002268 if [ "$WITH_EAPOL" == "yes" ]; then
2269 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set auth=true"
2270 else
2271 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set auth=false"
2272 fi
2273 if [ "$WITH_DHCP" == "yes" ]; then
2274 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set dhcp=true"
2275 else
2276 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set dhcp=false"
2277 fi
David Bainbridge33e56c72020-06-11 11:39:56 -07002278 if is_in "$WITH_KAFKA" "yes,external"; then
2279 _HOST=kafka.$INFRA_NS.svc
2280 _PORT=9092
2281 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set kafkaAddress=$_HOST:$_PORT"
2282 elif [ "$WITH_KAFKA" != "no" ]; then
2283 _HOST="$(echo "$WITH_KAFKA" | cut -d: -f1)"
2284 _PORT="$(echo "$WITH_KAFKA" | cut -s -d: -f2)"
2285 _PORT=${_PORT:-9092}
2286 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set kafkaAddress=$_HOST:$_PORT"
2287 fi
2288 helm_install - "$BBSIM_NS" "bbsim${instance_num}" "$VOLTHA_BBSIM_CHART" "$VOLTHA_BBSIM_CHART_VERSION" "+bbsim" "$_HELM_DESC BBSIM${instance_num}"
David Bainbridge2eaf2cf2020-03-18 12:54:08 -07002289 INTERNAL_EXTRA_HELM_INSTALL_ARGS=
David K. Bainbridge43422402020-03-06 07:41:22 -08002290 else
David Bainbridged18f4942020-04-14 16:46:13 -07002291 espin - "$VERIFIED"
David K. Bainbridge43422402020-03-06 07:41:22 -08002292 fi
2293 done
David Bainbridged18f4942020-04-14 16:46:13 -07002294 wait_for_pods - "$BBSIM_NS" "$NUM_OF_BBSIM" "includes" "Waiting for BBSIM to start" "$BBSIM_LABEL" "bbsim*"
David Bainbridgee87067b2019-08-12 22:00:12 +00002295 if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07002296 NOW="$(date +%s)"
2297 printtime $((NOW - STIME))
David Bainbridgee87067b2019-08-12 22:00:12 +00002298 fi
Test User7d866122019-07-09 17:52:35 +00002299fi
2300
divyadesai59f987a2020-05-27 12:11:33 +00002301if [ "$WITH_EFK" == "yes" ]; then
2302 STIME="$(date +%s)"
2303 echo -e "Verify EFK $PLUG"
2304 bspin - "Verify EFK Installed"
David Bainbridgeb4bbde12020-06-25 14:46:36 -07002305 if [ "$HELM_USE_UPGRADE" == "yes" ] || [ "$(helm_is_deployed "$INFRA_NS" "^elasticsearch\$")" -ne 1 ] || [ "$(helm_is_deployed "$INFRA_NS" "^kibana\$")" -ne 1 ] || [ "$(helm_is_deployed "$INFRA_NS" "^fluentd\$")" -ne 1 ]; then
divyadesai59f987a2020-05-27 12:11:33 +00002306 espin - "$NOT_VERIFIED"
David Bainbridgeb4bbde12020-06-25 14:46:36 -07002307 if [ "$HELM_USE_UPGRADE" == "yes" ] || [ "$(helm_is_deployed "$INFRA_NS" "^elasticsearch\$")" -ne 1 ]; then
divyadesai59f987a2020-05-27 12:11:33 +00002308 helm_install - "$INFRA_NS" elasticsearch "$ELASTICSEARCH_CHART" "$ELASTICSEARCH_CHART_VERSION" elasticsearch "$_HELM_DESC elasticsearch"
2309 fi
David Bainbridgeb4bbde12020-06-25 14:46:36 -07002310 if [ "$HELM_USE_UPGRADE" == "yes" ] || [ "$(helm_is_deployed "$INFRA_NS" "^kibana\$")" -ne 1 ]; then
divyadesai59f987a2020-05-27 12:11:33 +00002311 helm_install - "$INFRA_NS" kibana "$KIBANA_CHART" "$KIBANA_CHART_VERSION" kibana "$_HELM_DESC kibana"
2312 fi
David Bainbridgeb4bbde12020-06-25 14:46:36 -07002313 if [ "$HELM_USE_UPGRADE" == "yes" ] || [ "$(helm_is_deployed "$INFRA_NS" "^fluentd\$")" -ne 1 ]; then
divyadesai59f987a2020-05-27 12:11:33 +00002314 helm_install - "$INFRA_NS" fluentd "$FLUENTD_ELASTICSEARCH_CHART" "$FLUENTD_ELASTICSEARCH_CHART_VERSION" fluentd-elasticsearch "$_HELM_DESC fluentd-elasticsearch"
2315 fi
2316 else
2317 espin - "$VERIFIED"
2318 fi
2319 EXPECT=2 # for elastic and kibana
2320 if [ "$TYPE" == "minimal" ]; then
2321 EXPECT=$((EXPECT + 2)) # for fluentd on worker 2 worker nodes
2322 else
2323 EXPECT=$((EXPECT + 3)) # for fluentd on worker 3 worker nodes
2324 fi
2325 if [ "$SCHEDULE_ON_CONTROL_NODES" == "yes" ]; then
2326 EXPECT=$((EXPECT + 1)) # for fluentd on the control plan node
2327 fi
2328
2329 wait_for_pods - "$INFRA_NS" "$EXPECT" "includes" "Waiting for EFK to start" "$NO_LABEL" "fluentd-* elasticsearch-* kibana-*"
2330 if [ "$WITH_TIMINGS" == "yes" ]; then
2331 NOW="$(date +%s)"
2332 printtime $((NOW - STIME))
2333 fi
2334fi
2335
David Bainbridge309099c2020-05-05 08:47:29 -07002336if [ "$CONFIG_SADIS" == "external" ]; then
2337 STIME="$(date +%s)"
2338 echo -e "Verify BBSIM SADIS Service $PLUG"
2339 bspin - "Verify required configmap"
2340 (set -x; kubectl -n "$BBSIM_NS" delete --ignore-not-found configmap kube-config >>"$LOG" 2>&1) >>"$LOG" 2>&1
2341 (set -x; kubectl -n "$BBSIM_NS" create configmap kube-config "--from-file=kube_config=$KUBECONFIG" >>"$LOG" 2>&1) >>"$LOG" 2>&1
2342 espin - "$VERIFIED"
2343 bspin - "Verify BBSIM SADIS Service Installed"
David Bainbridgeb4bbde12020-06-25 14:46:36 -07002344 if [ "$HELM_USE_UPGRADE" == "yes" ] || [ "$(helm_is_deployed "$BBSIM_NS" "^bbsim-sadis-server\$")" -ne 1 ]; then
David Bainbridge309099c2020-05-05 08:47:29 -07002345 espin - "$NOT_VERIFIED"
Matteo Scandolo871fd982020-07-23 11:46:51 -07002346 INTERNAL_EXTRA_HELM_INSTALL_ARGS="$EXTRA_HELM_FLAGS" helm_install - "$BBSIM_NS" bbsim-sadis-server "$BBSIM_SADIS_SERVER_CHART" "$BBSIM_SADIS_SERVER_CHART_VERSION" "+sadis" "$_HELM_DESC BBSIM SADIS Server"
2347 INTERNAL_EXTRA_HELM_INSTALL_ARGS=
David Bainbridge309099c2020-05-05 08:47:29 -07002348 else
2349 espin - "$VERIFIED"
2350 fi
2351 wait_for_pods - "$BBSIM_NS" 1 "includes" "Waiting for BBSIM SADIS Server to start" "$NO_LABEL" "bbsim-sadis-server-.*"
Ubuntu7135e6a2020-06-30 01:46:08 +00002352
Matteo Scandolo21660442020-07-17 11:05:21 -07002353 if is_in "$WITH_ONOS" "yes,classic,legacy"; then
Ubuntu7135e6a2020-06-30 01:46:08 +00002354 if kubectl get -n "$BBSIM_NS" svc/bbsim-sadis-server-bbsim-sadis-server >/dev/null 2>&1; then
2355 BBSIM_SADIS_SVC="bbsim-sadis-server-bbsim-sadis-server"
2356 else
2357 BBSIM_SADIS_SVC="bbsim-sadis-server"
2358 fi
2359 push_onos_config "json" \
2360 "[optional] Push ONOS configuration for custom SADIS and Bandwidth Profile servers" \
2361 "network/configuration/apps/org.opencord.sadis" \
2362 "$(cat <<EOJ | tr -d '[:space:]'
2363{
2364 "sadis": {
2365 "integration": {
2366 "url": "http://$BBSIM_SADIS_SVC.$BBSIM_NS.svc:58080/subscribers/%s",
2367 "cache": {
2368 "enabled": true,
2369 "maxsize": 50,
2370 "ttl": "PT1m"
2371 }
2372 }
2373 },
2374 "bandwidthprofile": {
2375 "integration": {
2376 "url": "http://$BBSIM_SADIS_SVC.$BBSIM_NS.svc:58080/profiles/%s",
2377 "cache": {
2378 "enabled": true,
2379 "maxsize": 50,
2380 "ttl": "PT1m"
2381 }
2382 }
2383 }
2384}
2385EOJ
2386)"
2387 fi
David Bainbridge309099c2020-05-05 08:47:29 -07002388 if [ "$WITH_TIMINGS" == "yes" ]; then
2389 NOW="$(date +%s)"
2390 printtime $((NOW - STIME))
2391 fi
2392fi
2393
David Bainbridged18f4942020-04-14 16:46:13 -07002394if [ "$WITH_RADIUS" == "yes" ]; then
2395 STIME="$(date +%s)"
David Bainbridge5b7b96b2019-07-25 20:29:13 +00002396 echo -e "Verify RADIUS $LOCK"
2397 bspin - "Verify RADIUS Installed"
David Bainbridgeb4bbde12020-06-25 14:46:36 -07002398 if [ "$HELM_USE_UPGRADE" == "yes" ] || [ "$(helm_is_deployed "$INFRA_NS" "^radius\$")" -ne 1 ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07002399 espin - "$NOT_VERIFIED"
David Bainbridge879439b2020-06-12 15:59:35 -07002400 helm_install - "$INFRA_NS" radius "$RADIUS_CHART" "$RADIUS_CHART_VERSION" "+radius" "$_HELM_DESC RADIUS"
David Bainbridge5b7b96b2019-07-25 20:29:13 +00002401 else
David Bainbridged18f4942020-04-14 16:46:13 -07002402 espin - "$VERIFIED"
David Bainbridge5b7b96b2019-07-25 20:29:13 +00002403 fi
David Bainbridged18f4942020-04-14 16:46:13 -07002404 wait_for_pods - "$INFRA_NS" 1 "includes" "Waiting for RADIUS to start" "$NO_LABEL" "radius-.*"
David Bainbridgee87067b2019-08-12 22:00:12 +00002405 if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07002406 NOW="$(date +%s)"
2407 printtime $((NOW - STIME))
David Bainbridgee87067b2019-08-12 22:00:12 +00002408 fi
David Bainbridge5b7b96b2019-07-25 20:29:13 +00002409fi
2410
David Bainbridged18f4942020-04-14 16:46:13 -07002411if [ "$WITH_PORT_FORWARDS" == "yes" ]; then
2412 STIME="$(date +%s)"
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -08002413 bspin - "Forward VOLTHA API port $FORWARD"
David Bainbridge1d2c5842020-06-03 15:29:07 -07002414 kill_port_forward voltha-api voltha-voltha-api
2415 VOLTHA_PREFIX=
2416 if kubectl get -n "$VOLTHA_NS" "svc/voltha-voltha-api" >/dev/null 2>&1; then
2417 VOLTHA_PREFIX="voltha-"
2418 fi
Matteo Scandolo21660442020-07-17 11:05:21 -07002419
David Bainbridge1d2c5842020-06-03 15:29:07 -07002420 port_forward "$VOLTHA_NS" "${VOLTHA_PREFIX}voltha-api" "$VOLTHA_API_PORT:55555"
David Bainbridged18f4942020-04-14 16:46:13 -07002421 espin - "$VERIFIED"
David Bainbridgec7220622020-05-28 12:31:47 -07002422 if is_in "$WITH_ETCD" "yes,external"; then
David Bainbridge696bc632020-04-05 21:49:37 -07002423 bspin - "Forward VOLTHA ETCD port $FORWARD"
David Bainbridgec7220622020-05-28 12:31:47 -07002424 kill_port_forward "etcd"
2425 port_forward "$INFRA_NS" "etcd" "$VOLTHA_ETCD_PORT:2379"
David Bainbridged18f4942020-04-14 16:46:13 -07002426 espin - "$VERIFIED"
David Bainbridge696bc632020-04-05 21:49:37 -07002427 fi
David Bainbridgec7220622020-05-28 12:31:47 -07002428 if is_in "$WITH_KAFKA" "yes,external"; then
David Bainbridge696bc632020-04-05 21:49:37 -07002429 bspin - "Forward VOLTHA Kafka port $FORWARD"
David Bainbridgec7220622020-05-28 12:31:47 -07002430 kill_port_forward "kafka"
2431 port_forward "$INFRA_NS" kafka "$VOLTHA_KAFKA_PORT:9092"
David Bainbridged18f4942020-04-14 16:46:13 -07002432 espin - "$VERIFIED"
David Bainbridge696bc632020-04-05 21:49:37 -07002433 fi
divyadesai59f987a2020-05-27 12:11:33 +00002434 if [ "$WITH_EFK" == "yes" ]; then
2435 bspin - "Forward EFK port $FORWARD"
2436 kill_port_forward elasticsearch-master
2437 kill_port_forward kibana-kibana
2438 port_forward "$INFRA_NS" elasticsearch-master "$ELASTICSEARCH_PORT:9200"
2439 port_forward "$INFRA_NS" kibana-kibana "$KIBANA_PORT:5601"
2440 espin - "$VERIFIED"
2441 fi
Matteo Scandoloefee0432020-05-05 13:56:20 -07002442 if [ "$WITH_PPROF" == "yes" ]; then
David Bainbridge1d2c5842020-06-03 15:29:07 -07002443 VOLTHA_OPENOLT_PREFIX=
2444 if kubectl get -n "$ADAPTER_NS" "svc/open-olt-adapter-open-olt-profiler" >/dev/null 2>&1; then
2445 VOLTHA_OPENOLT_PREFIX="open-olt-"
2446 fi
David Bainbridge879439b2020-06-12 15:59:35 -07002447 bspin - "Forward PProf ports port $FORWARD"
2448 kill_port_forward voltha-rw-core-profiler voltha-voltha-rw-core-profiler
2449 kill_port_forward adapter-open-olt-profiler open-olt-adapter-open-olt-profiler
2450 kill_port_forward voltha-of-agent-profiler voltha-voltha-of-agent-profiler
2451 port_forward "$VOLTHA_NS" "${VOLTHA_PREFIX}voltha-rw-core-profiler" "$VOLTHA_PPROF_PORT:6060"
2452 port_forward "$ADAPTER_NS" "${VOLTHA_OPENOLT_PREFIX}adapter-open-olt-profiler" "$OPENOLT_PPROF_PORT:6060"
2453 port_forward "$VOLTHA_NS" "${VOLTHA_PREFIX}voltha-of-agent-profiler" "$OFAGENT_PPROF_PORT:6060"
2454 espin - "$VERIFIED"
Matteo Scandoloefee0432020-05-05 13:56:20 -07002455 fi
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -08002456 if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07002457 NOW="$(date +%s)"
2458 printtime $((NOW - STIME))
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -08002459 fi
David Bainbridgee87067b2019-08-12 22:00:12 +00002460fi
Test User3d7ad8e2019-07-03 06:15:44 +00002461
David Bainbridge60ffc0f2020-04-27 22:13:22 -07002462if is_in "$WITH_ONOS" "yes,legacy,classic" && [ "$WITH_RADIUS" != "no" ]; then
David Bainbridge879439b2020-06-12 15:59:35 -07002463 SVC_NAME=radius
2464 if kubectl get -n "$INFRA_NS" "svc/radius-freeradius" >/dev/null 2>&1; then
2465 SVC_NAME="radius-freeradius"
2466 fi
2467 _HOST="$SVC_NAME.$INFRA_NS.svc"
David Bainbridge696bc632020-04-05 21:49:37 -07002468 _PORT=1812
David Bainbridged18f4942020-04-14 16:46:13 -07002469 if [ "$WITH_RADIUS" != "yes" ]; then
2470 _HOST="$(echo "$WITH_RADIUS" | cut -d: -f1)"
2471 _PORT="$(echo "$WITH_RADIUS" | cut -s -d: -f2)"
David Bainbridge696bc632020-04-05 21:49:37 -07002472 _PORT=${_PORT:-1812}
2473 fi
David Bainbridge5b7b96b2019-07-25 20:29:13 +00002474 bspin "Configure ONOS RADIUS Connection $GEAR"
David Bainbridged18f4942020-04-14 16:46:13 -07002475 (set -x; sed -e "s/:RADIUS_SVC:/$_HOST/g" -e "s/:RADIUS_PORT:/$_PORT/" onos-files/onos-aaa.json | curl --fail -sSL --user karaf:karaf -X POST "http://$_ONOS_API_EP/onos/v1/network/configuration/apps/org.opencord.aaa" -H Content-type:application/json -d@- >>"$LOG" 2>&1) >>"$LOG" 2>&1
2476 espin "$VERIFIED"
David Bainbridge5b7b96b2019-07-25 20:29:13 +00002477fi
2478
divyadesai59f987a2020-05-27 12:11:33 +00002479if [ "$WITH_EFK" == "yes" ]; then
2480 do_curl "" "POST" "" "" "http://localhost:$KIBANA_PORT/api/saved_objects/index-pattern/logst*" "json" '{"attributes":{"title":"logst*","timeFieldName":"@timestamp"}}' "Verify logging index in EFK" "409,200" "-H Content-type:application/json -H kbn-xsrf:true" "$GEAR"
2481# fi
2482fi
2483
David Bainbridge99ac7a22019-08-31 02:26:43 +00002484if [ "$WITH_CHAOS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07002485 STIME="$(date +%s)"
David Bainbridge99ac7a22019-08-31 02:26:43 +00002486 echo -e "Verify kube-monkey $LOCK"
2487 bspin - "Verify kube-monkey Installed"
David Bainbridgeb4bbde12020-06-25 14:46:36 -07002488 if [ "$HELM_USE_UPGRADE" == "yes" ] || [ "$(helm_is_deployed kube-monkey "^monkey\$")" -ne 1 ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07002489 espin - "$NOT_VERIFIED"
David Bainbridgec7220622020-05-28 12:31:47 -07002490 helm_install - kube-monkey monkey ./kube-monkey/helm/kubemonkey latest - "$_HELM_DESC Chaos Monkey"
David Bainbridge99ac7a22019-08-31 02:26:43 +00002491 else
David Bainbridged18f4942020-04-14 16:46:13 -07002492 espin - "$VERIFIED"
David Bainbridge99ac7a22019-08-31 02:26:43 +00002493 fi
David Bainbridged18f4942020-04-14 16:46:13 -07002494 wait_for_pods - "kube-monkey" 1 "includes" "Waiting for Chaos to start" "$NO_LABEL" "monkey-.*"
David Bainbridge99ac7a22019-08-31 02:26:43 +00002495 if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07002496 NOW="$(date +%s)"
2497 printtime $((NOW - STIME))
David Bainbridge99ac7a22019-08-31 02:26:43 +00002498 fi
2499fi
2500
David Bainbridge5b7b96b2019-07-25 20:29:13 +00002501bspin "Create voltctl configuration file"
David Bainbridged18f4942020-04-14 16:46:13 -07002502(set -x; mkdir -p "$HOME/.volt" >>"$LOG" 2>&1) >>"$LOG" 2>&1
2503MIN_VC_VERSION="$(echo -e "1.0.15\n$VC_VERSION" | sort -V | head -1)"
2504if [ "$WITH_PORT_FORWARDS" == "yes" ]; then
David K. Bainbridgeb859e912020-03-13 14:07:52 -07002505 KAFKA_FLAG="-k localhost:$VOLTHA_KAFKA_PORT"
2506 SERVER_FLAG="-s localhost:$VOLTHA_API_PORT"
2507 ETCD_FLAG=
2508 if [ "$MIN_VC_VERSION" == "1.0.15" ]; then
2509 ETCD_FLAG="-e localhost:$VOLTHA_ETCD_PORT"
2510 fi
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -08002511else
David Bainbridgec7220622020-05-28 12:31:47 -07002512 KAFKA_FLAG="-k $(get_service_ep "$INFRA_NS" kafka)"
David Bainbridged18f4942020-04-14 16:46:13 -07002513 SERVER_FLAG="-s $(get_service_ep "$VOLTHA_NS" voltha-api)"
David K. Bainbridgeb859e912020-03-13 14:07:52 -07002514 ETCD_FLAG=
2515 if [ "$MIN_VC_VERSION" == "1.0.15" ]; then
David Bainbridgec7220622020-05-28 12:31:47 -07002516 ETCD_FLAG="-e $(get_service_ep "$INFRA_NS" etcd)"
David K. Bainbridgeb859e912020-03-13 14:07:52 -07002517 fi
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -08002518fi
David Bainbridgea965ca22020-06-09 17:45:04 -07002519CMD=("voltctl $KAFKA_FLAG $SERVER_FLAG $ETCD_FLAG config")
David Bainbridged18f4942020-04-14 16:46:13 -07002520(set -x; ${CMD[*]} > "$HOME/.volt/config-$NAME" 2>>"$LOG") >>"$LOG" 2>&1
David Bainbridgea965ca22020-06-09 17:45:04 -07002521#(set -x; voltctl "$KAFKA_FLAG" "$SERVER_FLAG" "$ETCD_FLAG" config > "$HOME/.volt/config-$NAME" 2>>"$LOG") >>"$LOG" 2>&1
David Bainbridged18f4942020-04-14 16:46:13 -07002522espin "$VERIFIED"
Test User08ebbd92019-07-03 17:15:39 +00002523
David Bainbridge0774b232019-08-02 06:37:19 +00002524if [ ! -f "$NAME-env.sh" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07002525 touch "$NAME-env.sh"
David Bainbridgeb07fdf72019-07-29 22:51:40 +00002526fi
2527
David Bainbridge596f30d2019-07-30 17:07:59 +00002528for O in $ALL_OPTIONS; do
David Bainbridged18f4942020-04-14 16:46:13 -07002529 VAL="$(eval echo "\$$O")"
2530 if [ -n "$VAL" ] && [ "$(grep -c "^export $O=" "$NAME-env.sh")" -eq 0 ]; then
2531 echo "export $O=\"$(eval echo "\$$O")\"" >> "$NAME-env.sh"
David Bainbridgeb07fdf72019-07-29 22:51:40 +00002532 fi
2533done
2534
David Bainbridged18f4942020-04-14 16:46:13 -07002535if [ "$DEPLOY_K8S" == "yes" ] && [ "$(grep -c "^export KUBECONFIG=" "$NAME-env.sh")" -eq 0 ]; then
David Bainbridgeb4bbde12020-06-25 14:46:36 -07002536 echo "export KUBECONFIG=\"$HOME/.kube/kind-config-voltha-$NAME\"" >> "$NAME-env.sh"
David Bainbridgeb07fdf72019-07-29 22:51:40 +00002537fi
2538
David Bainbridged18f4942020-04-14 16:46:13 -07002539if [ "$(grep -c "^export VOLTCONFIG=" "$NAME-env.sh")" -eq 0 ]; then
2540 echo "export VOLTCONFIG=\"$HOME/.volt/config-$NAME\"" >> "$NAME-env.sh"
David Bainbridgeb07fdf72019-07-29 22:51:40 +00002541fi
2542
David Bainbridged18f4942020-04-14 16:46:13 -07002543if [ "$(grep -c "^export PATH=" "$NAME-env.sh")" -eq 0 ]; then
2544 echo "export PATH=\"$GOPATH/bin:\$PATH\"" >> "$NAME-env.sh"
David Bainbridgeb07fdf72019-07-29 22:51:40 +00002545fi
2546
Test User7d866122019-07-09 17:52:35 +00002547echo ""
David Bainbridged18f4942020-04-14 16:46:13 -07002548echo "Please issue the following commands in your terminal to ensure that you" | tee -a "$LOG"
2549echo "are accessing the correct Kubernetes/Kind cluster as well as have the " | tee -a "$LOG"
2550echo "tools required by VOLTHA in your command path. " | tee -a "$LOG"
2551echo "" | tee -a "$LOG"
2552echo -en "$BOLD"
2553if [ "$DEPLOY_K8S" == "yes" ]; then
David Bainbridgeb4bbde12020-06-25 14:46:36 -07002554 echo "export KUBECONFIG=\"$HOME/.kube/kind-config-voltha-$NAME\"" | tee -a "$LOG"
Test Userba1e7e72019-07-10 22:27:54 +00002555fi
David Bainbridged18f4942020-04-14 16:46:13 -07002556echo "export VOLTCONFIG=\"$HOME/.volt/config-$NAME\"" | tee -a "$LOG"
2557echo "export PATH=$GOPATH/bin:\$PATH" | tee -a "$LOG"
2558echo -en "$NORMAL"
2559echo "" | tee -a "$LOG"
2560echo "Thank you for choosing kind-voltha for you quick cluster needs." | tee -a "$LOG"
Test User08ebbd92019-07-03 17:15:39 +00002561
David Bainbridge712afb82019-08-14 19:55:58 +00002562if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07002563 NOW="$(date +%s)"
2564 echo -e "$CLOCK ${BOLD}TOTAL: $(duration $((NOW - TOTAL_START_TIME)))${NORMAL}"
David Bainbridge712afb82019-08-14 19:55:58 +00002565fi