blob: cfd59069c89d6f79d8b749d74dc9028ab8d20638 [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 K. Bainbridgeb7285432019-07-02 22:05:24 -070019
David Bainbridge38dc1e82019-08-12 15:18:45 +000020FANCY=${FANCY:-1}
21if [ "$TERM X" == " X" ]; then
22 FANCY=0
23fi
24
David K. Bainbridgeb7285432019-07-02 22:05:24 -070025# trap ctrl-c and call ctrl_c()
26trap ctrl_c INT
27
28function ctrl_c() {
David Bainbridged18f4942020-04-14 16:46:13 -070029 echo -en "$CNORM"
David K. Bainbridgeb7285432019-07-02 22:05:24 -070030 echo ""
31 echo "ctrl-c trapped"
David Bainbridgec6a6eb62019-10-18 22:50:07 +000032 echo "Thank you for trying 'voltha up'"
David K. Bainbridgeb7285432019-07-02 22:05:24 -070033 exit
34}
35
David Bainbridgea34993d2020-04-01 09:15:42 -070036HELM_VERSION=${HELM_VERSION:-v2.14.3}
David K. Bainbridgeebf38d92020-02-10 10:46:31 -080037VOLTCTL_VERSION=${VOLTCTL_VERSION:-latest}
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -080038KIND_VERSION=${KIND_VERSION:-v0.5.1}
David K. Bainbridgeb3a99372020-01-08 14:39:06 -080039VK_RELEASE=${VK_RELEASE:-master}
David Bainbridge60ffc0f2020-04-27 22:13:22 -070040EXTRA_TOOLS=
Test User08ebbd92019-07-03 17:15:39 +000041
David Bainbridge38dc1e82019-08-12 15:18:45 +000042RED=
43GREEN=
44YELLOW=
45BLUE=
David Bainbridge38dc1e82019-08-12 15:18:45 +000046BOLD=
47NORMAL=
48ERROR=
49CEOL=
50CNORM=
51CIVIS=
David Bainbridged18f4942020-04-14 16:46:13 -070052if [ "$FANCY" -eq 1 ]; then
53 RED="$(tput setaf 1)"
54 GREEN="$(tput setaf 2)"
55 YELLOW="$(tput setaf 3)"
56 BLUE="$(tput setaf 4)"
57 BOLD="$(tput bold)"
58 NORMAL="$(tput sgr0)"
David Bainbridge38dc1e82019-08-12 15:18:45 +000059 ERROR="\xe2\x9c\x97\x20"
David Bainbridged18f4942020-04-14 16:46:13 -070060 CEOL="$(tput el)"
61 CNORM="$(tput cnorm)"
62 CIVIS="$(tput civis)"
David Bainbridge38dc1e82019-08-12 15:18:45 +000063fi
Test User7d866122019-07-09 17:52:35 +000064
Test User3d7ad8e2019-07-03 06:15:44 +000065TYPE=${TYPE:-minimal}
David Bainbridge0774b232019-08-02 06:37:19 +000066NAME=${NAME:-$TYPE}
David K. Bainbridge484d80c2020-03-05 21:44:34 -080067
68ENABLE_ONOS_EXTRANEOUS_RULES=${ENABLE_ONOS_EXTRANEOUS_RULES:-no}
David Bainbridge76afd812020-04-06 09:53:52 -070069INFRA_NS=${INFRA_NS:-default}
70VOLTHA_NS=${VOLTHA_NS:-voltha}
71BBSIM_NS=${BBSIM_NS:-voltha}
72ADAPTER_NS=${ADAPTER_NS:-voltha}
David Bainbridgee87067b2019-08-12 22:00:12 +000073WITH_TIMINGS=${WITH_TIMINGS:-no}
Test User7d866122019-07-09 17:52:35 +000074WITH_BBSIM=${WITH_BBSIM:-no}
divyadesai59f987a2020-05-27 12:11:33 +000075WITH_EFK=${WITH_EFK:-no}
David Bainbridge5b7b96b2019-07-25 20:29:13 +000076WITH_RADIUS=${WITH_RADIUS:-no}
Matteo Scandolo78dfee02020-02-13 16:18:03 -080077WITH_EAPOL=${WITH_EAPOL:-yes}
78WITH_DHCP=${WITH_DHCP:-yes}
79WITH_IGMP=${WITH_IGMP:-no}
David Bainbridgeb270c202019-07-26 01:44:42 +000080WITH_ONOS=${WITH_ONOS:-yes}
David Bainbridge60ffc0f2020-04-27 22:13:22 -070081NUM_OF_ONOS=${NUM_OF_ONOS:-1}
82NUM_OF_ATOMIX=${NUM_OF_ATOMIX:-0}
David Bainbridge99ac7a22019-08-31 02:26:43 +000083WITH_CHAOS=${WITH_CHAOS:-no}
David Bainbridge46505fb2019-10-01 21:13:20 +000084WITH_ADAPTERS=${WITH_ADAPTERS:-yes}
David K. Bainbridgeda33d652020-03-06 10:31:23 -080085WITH_SIM_ADAPTERS=${WITH_SIM_ADAPTERS:-no}
David Bainbridge46505fb2019-10-01 21:13:20 +000086WITH_OPEN_ADAPTERS=${WITH_OPEN_ADAPTERS:-yes}
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -080087WITH_PORT_FORWARDS=${WITH_PORT_FORWARDS:-yes}
David Bainbridge696bc632020-04-05 21:49:37 -070088WITH_KAFKA=${WITH_KAFKA:-yes}
89WITH_ETCD=${WITH_ETCD:-yes}
Matteo Scandoloefee0432020-05-05 13:56:20 -070090WITH_PPROF=${WITH_PPROF:-no}
Girish Gowdra4cc5d8b2020-06-11 17:12:00 -070091WITH_INCREMENTAL_EVTO_UPDATE=${WITH_INCREMENTAL_EVTO_UPDATE:-no}
David Bainbridgee4d11ca2020-05-08 10:21:10 -070092SCHEDULE_ON_CONTROL_NODES=${SCHEDULE_ON_CONTROL_NODES:-no}
David Bainbridge309099c2020-05-05 08:47:29 -070093CONFIG_SADIS=${CONFIG_SADIS:-no} # yes | no | file | bbsim | external | URL
Hardik Windlassb3147602020-03-09 16:59:15 +053094SADIS_CFG=${SADIS_CFG:-onos-files/onos-sadis-sample.json}
David Bainbridge27790d62019-08-13 22:43:19 +000095INSTALL_ONOS_APPS=${INSTALL_ONOS_APPS:-no}
Test Userba1e7e72019-07-10 22:27:54 +000096JUST_K8S=${JUST_K8S:-no}
97DEPLOY_K8S=${DEPLOY_K8S:-yes}
David K. Bainbridge0e89cb92019-07-17 11:30:10 -070098INSTALL_KUBECTL=${INSTALL_KUBECTL:-yes}
99INSTALL_HELM=${INSTALL_HELM:-yes}
David Bainbridge7f8bf992020-04-08 21:53:22 -0700100HELM_USE_UPGRADE=${HELM_USE_UPGRADE:-no}
David Bainbridge46505fb2019-10-01 21:13:20 +0000101UPDATE_HELM_REPOS=${UPDATE_HELM_REPOS:-yes}
Matteo Scandolofab98622020-01-28 15:17:20 -0800102WAIT_ON_DOWN=${WAIT_ON_DOWN:-yes}
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700103WAIT_TIMEOUT=${WAIT_TIMEOUT:-30m}
104VOLTHA_DOWN_ON_TIMEOUT=${VOLTHA_DOWN_ON_TIMEOUT:-no}
David Bainbridge5b7b96b2019-07-25 20:29:13 +0000105VOLTHA_LOG_LEVEL=${VOLTHA_LOG_LEVEL:-WARN}
David Bainbridge90fd8e32019-08-21 23:32:47 +0000106VOLTHA_CHART=${VOLTHA_CHART:-onf/voltha}
107VOLTHA_CHART_VERSION=${VOLTHA_CHART_VERSION:-latest}
108VOLTHA_BBSIM_CHART=${VOLTHA_BBSIM_CHART:-onf/bbsim}
Matteo Scandolodcd29f52019-10-07 15:42:42 -0700109VOLTHA_BBSIM_CHART_VERSION=${VOLTHA_BBSIM_CHART_VERSION:-latest}
divyadesai59f987a2020-05-27 12:11:33 +0000110ELASTICSEARCH_CHART=${ELASTICSEARCH_CHART:-elastic/elasticsearch}
111ELASTICSEARCH_CHART_VERSION=${ELASTICSEARCH_CHART_VERSION:-latest}
112KIBANA_CHART=${KIBANA_CHART:-elastic/kibana}
113KIBANA_CHART_VERSION=${KIBANA_CHART_VERSION:-latest}
114FLUENTD_ELASTICSEARCH_CHART=${FLUENTD_ELASTICSEARCH_CHART:-kiwigrid/fluentd-elasticsearch}
115FLUENTD_ELASTICSEARCH_CHART_VERSION=${FLUENTD_ELASTICSEARCH_CHART_VERSION:-latest}
David Bainbridgee10f6d52019-07-25 00:28:13 +0000116VOLTHA_ADAPTER_SIM_CHART=${VOLTHA_ADAPTER_SIM_CHART:-onf/voltha-adapter-simulated}
David Bainbridge90fd8e32019-08-21 23:32:47 +0000117VOLTHA_ADAPTER_SIM_CHART_VERSION=${VOLTHA_ADAPTER_SIM_CHART_VERSION:-latest}
David Bainbridgee10f6d52019-07-25 00:28:13 +0000118VOLTHA_ADAPTER_OPEN_OLT_CHART=${VOLTHA_ADAPTER_OPEN_OLT_CHART:-onf/voltha-adapter-openolt}
David Bainbridge90fd8e32019-08-21 23:32:47 +0000119VOLTHA_ADAPTER_OPEN_OLT_CHART_VERSION=${VOLTHA_ADAPTER_OPEN_OLT_CHART_VERSION:-latest}
David Bainbridgee10f6d52019-07-25 00:28:13 +0000120VOLTHA_ADAPTER_OPEN_ONU_CHART=${VOLTHA_ADAPTER_OPEN_ONU_CHART:-onf/voltha-adapter-openonu}
David Bainbridge90fd8e32019-08-21 23:32:47 +0000121VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION=${VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION:-latest}
David K. Bainbridgeda33d652020-03-06 10:31:23 -0800122ONOS_CHART=${ONOS_CHART:-onf/onos}
Andrea Campanella21323292019-12-18 11:44:19 -0800123ONOS_CHART_VERSION=${ONOS_CHART_VERSION:-latest}
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700124ONOS_CLASSIC_CHART=${ONOS_CLASSIC_CHART:-onos/onos-classic}
Andy Bavier8b9d4092020-07-01 13:28:08 -0700125ONOS_CLASSIC_CHART_VERSION=${ONOS_CLASSIC_CHART_VERSION:-latest}
David Bainbridgecf546362020-04-21 23:18:50 -0700126KAFKA_CHART=${KAFKA_CHART:-incubator/kafka}
David Bainbridgeb9093522020-04-15 14:32:44 -0700127KAFKA_CHART_VERSION=${KAFKA_CHART_VERSION:=0.15.3}
David Bainbridge309099c2020-05-05 08:47:29 -0700128BBSIM_SADIS_SERVER_CHART=${BBSIM_SADIS_SERVER_CHART:-bbsim-sadis/bbsim-sadis-server}
129BBSIM_SADIS_SERVER_CHART_VERSION=${BBSIM_SADIS_SERVER_CHART_VERSION:-latest}
David Bainbridgec7220622020-05-28 12:31:47 -0700130ETCD_CHART=${ETCD_CHART:-incubator/etcd}
131ETCD_CHART_VERSION=${ETCD_CHART_VERSION:-latest}
David Bainbridge879439b2020-06-12 15:59:35 -0700132RADIUS_CHART=${RADIUS_CHART:-onf/freeradius}
133RADIUS_CHART_VERSION=${RADIUS_CHART_VERSION:-latest}
David Bainbridge2eaf2cf2020-03-18 12:54:08 -0700134EXTRA_HELM_INSTALL_ARGS=${EXTRA_HELM_INSTALL_ARGS:-}
135INTERNAL_EXTRA_HELM_INSTALL_ARGS=
uottrembb16d3982020-02-28 08:34:36 +0100136NUM_OF_BBSIM=${NUM_OF_BBSIM:-1}
Matteo Scandolo67335f02020-04-09 11:19:53 -0700137NUM_OF_OPENONU=${NUM_OF_OPENONU:-1}
uottrembb16d3982020-02-28 08:34:36 +0100138MAX_NUM_OF_BBSIM=10
Matteo Scandolo67335f02020-04-09 11:19:53 -0700139MAX_NUM_OF_OPENONU=10
Matteo Scandoloc2eb0672020-05-01 14:43:15 -0700140LEGACY_BBSIM_INDEX=${LEGACY_BBSIM_INDEX:-no}
Test Userba1e7e72019-07-10 22:27:54 +0000141
David Bainbridged18f4942020-04-14 16:46:13 -0700142HOSTOS="$(uname -s | tr "[:upper:]" "[:lower:"])"
143HOSTARCH="$(uname -m | tr "[:upper:]" "[:lower:"])"
144if [ "$HOSTARCH" == "x86_64" ]; then
Test Userba1e7e72019-07-10 22:27:54 +0000145 HOSTARCH="amd64"
146fi
David Bainbridge7db44002020-04-09 12:54:29 -0700147BBSIM_LABEL="-l app=bbsim"
David Bainbridged18f4942020-04-14 16:46:13 -0700148NO_LABEL=
Test User7d866122019-07-09 17:52:35 +0000149
uottrembb16d3982020-02-28 08:34:36 +0100150# check number (range) of bbsim, max bbsim must not exceed 10 instances!
151# note: instances will be numbered from 0 to 9
152if [ "$1" == "up" ]; then
David K. Bainbridge43422402020-03-06 07:41:22 -0800153 if [ "$NUM_OF_BBSIM" -lt 1 ]; then
Matteo Scandolo67335f02020-04-09 11:19:53 -0700154 >&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}"
David K. Bainbridge43422402020-03-06 07:41:22 -0800155 exit 1
156 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700157 if [ "$NUM_OF_BBSIM" -gt "$MAX_NUM_OF_BBSIM" ]; then
Matteo Scandolo67335f02020-04-09 11:19:53 -0700158 >&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}"
159 exit 1
160 fi
161
162 if [ "$NUM_OF_OPENONU" -lt 1 ]; then
163 >&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}"
164 exit 1
165 fi
166 if [ "$NUM_OF_OPENONU" -gt "$MAX_NUM_OF_OPENONU" ]; then
167 >&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}"
David K. Bainbridge43422402020-03-06 07:41:22 -0800168 exit 1
169 fi
uottrembb16d3982020-02-28 08:34:36 +0100170fi
Test User7d866122019-07-09 17:52:35 +0000171# Verify TYPE setting
David Bainbridged18f4942020-04-14 16:46:13 -0700172if [ "$(echo ":minimal:full:" | grep -ic ":$TYPE:")" -eq 0 ]; then
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700173 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} Invalid \$TYPE value of '$TYPE'. Should be 'minimal' or 'full'${NORMAL}"
Test User7d866122019-07-09 17:52:35 +0000174 exit 1
175fi
176
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700177# checks to see if a given WORD is in the given LIST of words
178function is_in() {
179 local WORD LIST
180 WORD="$1"; shift
181 LIST="$*"
182 LIST=${LIST//+([[:space:],|])/:}
183
184 [ "$(echo ":$LIST:" | grep -ic ":$WORD:")" -ne 0 ]
185}
186
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700187function parseDuration() {
David Bainbridged18f4942020-04-14 16:46:13 -0700188 local DUR RESULT TERM TERMS VALUE UNIT
189 DUR=$1
190 RESULT=0
191 TERMS="$(echo "$DUR" | sed -Ee 's/([sSmMhHdD])/\1 /g' -e 's/,$//g')"
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700192 for TERM in $TERMS; do
David Bainbridged18f4942020-04-14 16:46:13 -0700193 VALUE="$(echo "$TERM" | sed -Ee 's/([0-9]+)[sSmMhHdD]/\1/')"
194 UNIT="$(echo "$TERM" | sed -Ee 's/[0-9]+([sSmMhHdD])/\1/')"
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700195 case $UNIT in
196 s|S)
David Bainbridged18f4942020-04-14 16:46:13 -0700197 RESULT=$((RESULT + VALUE)) ;;
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700198 m|M)
David Bainbridged18f4942020-04-14 16:46:13 -0700199 RESULT=$((RESULT + (VALUE * 60))) ;;
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700200 h|H)
David Bainbridged18f4942020-04-14 16:46:13 -0700201 RESULT=$((RESULT + (VALUE * 3600))) ;;
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700202 d|D)
David Bainbridged18f4942020-04-14 16:46:13 -0700203 RESULT=$((RESULT + (VALUE * 86400))) ;;
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700204 *) ;;
205 esac
206 done
207 echo $RESULT
208}
209
210function doTimeout() {
211 local MSG=$1
212 2>&1 echo -e "\n${RED}${BOLD}${ERROR}TIMEOUT:${NORMAL}${RED} Operation timed out after '$WAIT_TIMEOUT': $MSG"
213 exit 125
214}
215
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -0800216function get_service_ep() {
217 local NS=$1
218 local NAME=$2
David Bainbridged18f4942020-04-14 16:46:13 -0700219 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 -0800220}
221
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000222# Used to verify configuration values are set to "yes" or "no" value or convert
223# equivalents to "yes" or "no"
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700224YES="y,yes,t,true,1"
225NO="n,no,f,false,0"
226YES_OR_NO="$YES,$NO"
227
228# If the given VAR matches a truth value then normalize that
229# value, else return original value
230function normalize_yes_no() {
231 local VAR VAL
232 VAR=$1
233 VAL="$(eval echo "\$$VAR")"
234 if ! is_in "$VAL" "$YES_OR_NO"; then
235 echo "$VAL"
236 return 1
237 fi
238 if is_in "$VAL" "$YES"; then
239 echo "yes"
240 else
241 echo "no"
242 fi
243 return 0
244}
245
246# If the given VAR matches a truth value then normalize that
247# value, else display an error
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000248function verify_yes_no() {
David Bainbridged18f4942020-04-14 16:46:13 -0700249 local VAR VAL
250 VAR=$1
251 VAL="$(eval echo "\$$VAR")"
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700252 if ! is_in "$VAL" "$YES_OR_NO"; then
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000253 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} Invalid '$VAR' value of '$VAL'. Should be 'yes' or 'no'${NORMAL}"
254 echo "INVALID"
255 return 1
256 fi
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700257 if is_in "$VAL" "$YES"; then
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000258 echo "yes"
259 else
260 echo "no"
261 fi
262 return 0
263}
Test User7d866122019-07-09 17:52:35 +0000264
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000265ALL_YES_NO="\
David K. Bainbridge484d80c2020-03-05 21:44:34 -0800266 ENABLE_ONOS_EXTRANEOUS_RULES \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000267 WITH_TIMINGS \
268 WITH_BBSIM \
divyadesai59f987a2020-05-27 12:11:33 +0000269 WITH_EFK \
Matteo Scandolo78dfee02020-02-13 16:18:03 -0800270 WITH_EAPOL \
271 WITH_DHCP \
272 WITH_IGMP \
David Bainbridge99ac7a22019-08-31 02:26:43 +0000273 WITH_CHAOS \
David Bainbridge46505fb2019-10-01 21:13:20 +0000274 WITH_ADAPTERS \
275 WITH_SIM_ADAPTERS \
276 WITH_OPEN_ADAPTERS \
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -0800277 WITH_PORT_FORWARDS \
Matteo Scandoloefee0432020-05-05 13:56:20 -0700278 WITH_PPROF \
Girish Gowdra4cc5d8b2020-06-11 17:12:00 -0700279 WITH_INCREMENTAL_EVTO_UPDATE \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000280 JUST_K8S \
281 DEPLOY_K8S \
282 INSTALL_ONOS_APPS \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000283 INSTALL_KUBECTL \
284 INSTALL_HELM \
David Bainbridge7f8bf992020-04-08 21:53:22 -0700285 HELM_USE_UPGRADE \
David Bainbridge46505fb2019-10-01 21:13:20 +0000286 UPDATE_HELM_REPOS \
David Bainbridge4f1b5562019-08-19 04:46:52 +0000287 WAIT_ON_DOWN \
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700288 VOLTHA_DOWN_ON_TIMEOUT \
Matteo Scandoloc2eb0672020-05-01 14:43:15 -0700289 LEGACY_BBSIM_INDEX \
David Bainbridgee4d11ca2020-05-08 10:21:10 -0700290 SCHEDULE_ON_CONTROL_NODES \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000291 "
David Bainbridge5b7b96b2019-07-25 20:29:13 +0000292
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700293OPT_YES_NO="\
294 CONFIG_SADIS \
295 WITH_KAFKA \
296 WITH_RADIUS \
297 WITH_ETCD \
298 WITH_ONOS \
299 "
300
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000301ALL_OPTIONS="\
302 NAME \
303 TYPE \
304 $ALL_YES_NO \
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700305 $OPT_YES_NO \
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700306 WAIT_TIMEOUT \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000307 VOLTHA_LOG_LEVEL \
308 VOLTHA_CHART \
David Bainbridge90fd8e32019-08-21 23:32:47 +0000309 VOLTHA_CHART_VERSION \
310 VOLTHA_BBSIM_CHART \
311 VOLTHA_BBSIM_CHART_VERSION \
David Bainbridge879439b2020-06-12 15:59:35 -0700312 BBSIM_SADIS_SERVER_CHART \
313 BBSIM_SADIS_SERVER_CHART_VERSION \
uottrembd5a20572020-03-06 09:15:01 +0100314 NUM_OF_BBSIM \
divyadesai59f987a2020-05-27 12:11:33 +0000315 ELASTICSEARCH_CHART \
316 ELASTICSEARCH_CHART_VERSION \
317 KIBANA_CHART \
318 KIBANA_CHART_VERSION \
319 FLUENTD_ELASTICSEARCH_CHART \
320 FLUENTD_ELASTICSEARCH_CHART_VERSION \
Matteo Scandolo67335f02020-04-09 11:19:53 -0700321 NUM_OF_OPENONU \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000322 VOLTHA_ADAPTER_SIM_CHART \
David Bainbridge90fd8e32019-08-21 23:32:47 +0000323 VOLTHA_ADAPTER_SIM_CHART_VERSION \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000324 VOLTHA_ADAPTER_OPEN_OLT_CHART \
David Bainbridge90fd8e32019-08-21 23:32:47 +0000325 VOLTHA_ADAPTER_OPEN_OLT_CHART_VERSION \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000326 VOLTHA_ADAPTER_OPEN_ONU_CHART \
David Bainbridge90fd8e32019-08-21 23:32:47 +0000327 VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION \
David K. Bainbridgeda33d652020-03-06 10:31:23 -0800328 ONOS_CHART \
Andrea Campanella21323292019-12-18 11:44:19 -0800329 ONOS_CHART_VERSION \
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700330 ONOS_CLASSIC_CHART \
331 ONOS_CLASSIC_CHART_VERSION \
David Bainbridgecf546362020-04-21 23:18:50 -0700332 KAFKA_CHART \
David Bainbridgeb9093522020-04-15 14:32:44 -0700333 KAFKA_CHART_VERSION \
David Bainbridge879439b2020-06-12 15:59:35 -0700334 ETCD_CHART \
335 ETCD_CHART_VERSION \
336 RADIUS_CHART \
337 RADIUS_CHART_VERSION \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000338 ONOS_API_PORT \
339 ONOS_SSH_PORT \
Hardik Windlassb3147602020-03-09 16:59:15 +0530340 SADIS_CFG \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000341 VOLTHA_API_PORT \
342 VOLTHA_SSH_PORT \
343 VOLTHA_ETCD_PORT \
divyadesai59f987a2020-05-27 12:11:33 +0000344 ELASTICSEARCH_PORT \
345 KIBANA_PORT \
David K. Bainbridge00ecd382020-02-28 12:31:58 -0800346 VOLTHA_KAFKA_PORT \
Matteo Scandoloefee0432020-05-05 13:56:20 -0700347 VOLTHA_PPROF_PORT \
348 OPENOLT_PPROF_PORT \
Matteo Scandolo65c35192020-05-13 10:41:21 -0700349 OFAGENT_PPROF_PORT \
David K. Bainbridge8f7f30b2020-01-08 13:06:16 -0800350 VK_RELEASE \
351 KIND_VERSION \
352 VOLTCTL_VERSION \
David Bainbridgea34993d2020-04-01 09:15:42 -0700353 HELM_VERSION \
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700354 NUM_OF_ONOS \
355 NUM_OF_ATOMIX \
David Bainbridge6ca40102020-04-08 11:30:40 -0700356 VOLTHA_NS \
357 ADAPTER_NS \
358 INFRA_NS \
359 BBSIM_NS \
David Bainbridge7db44002020-04-09 12:54:29 -0700360 SADIS_BANDWIDTH_PROFILES \
361 SADIS_SUBSCRIBERS \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000362 "
David Bainbridge01294952019-07-30 19:33:45 +0000363
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000364# Iterate over yes/no configuration options and validate
365for VAR in $ALL_YES_NO; do
David Bainbridged18f4942020-04-14 16:46:13 -0700366 eval "$VAR"="$(verify_yes_no "$VAR")"
367 if [ "$(eval echo "\$$VAR")" == "INVALID" ]; then
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000368 exit 1;
369 fi
370done
David Bainbridgeb270c202019-07-26 01:44:42 +0000371
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700372# Iterate over optional yes/no configuration options and
373# normalize values if they are truth values
374for VAR in $OPT_YES_NO; do
375 eval "$VAR"="$(normalize_yes_no "$VAR")"
376done
David Bainbridge15f6f232020-03-30 09:15:43 -0700377
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700378# normalize non-truth value options
379if is_in "$WITH_KAFKA" "e,external"; then
David Bainbridge76afd812020-04-06 09:53:52 -0700380 WITH_KAFKA="external"
381fi
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700382if is_in "$WITH_ETCD" "e,external"; then
David Bainbridge76afd812020-04-06 09:53:52 -0700383 WITH_ETCD="external"
384fi
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700385if is_in "$WITH_ONOS" "l,legacy"; then
386 WITH_ONOS="legacy"
387elif is_in "$WITH_ONOS" "c,classic"; then
388 WITH_ONOS="classic"
389elif is_in "$WITH_ONOS" "u,m,micro"; then
390 WITH_ONOS="micro"
David Bainbridge29c31cb2020-04-06 09:45:50 -0700391fi
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700392
393if [ "$WITH_ONOS" == "micro" ]; then
394 >&2 echo -e "${YELLOW}${BOLD}${ERROR}WARNING:${NORMAL}${YELLOW} The value specified as WITH_ONOS, '$WITH_ONOS', is not valid.${NORMAL}"
395 exit 1
David Bainbridge29c31cb2020-04-06 09:45:50 -0700396fi
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700397
398if is_in "$WITH_ONOS" "yes,classic"; then
399 # there is an extra utility required if we are using ONOS CLASSIC as
400 # the chart for classic specifies images differently
401 EXTRA_TOOLS+=" yq"
David Bainbridge76afd812020-04-06 09:53:52 -0700402fi
David Bainbridge696bc632020-04-05 21:49:37 -0700403
David Bainbridge22db5dd2020-05-26 12:21:21 -0700404if [ "$LEGACY_BBSIM_INDEX" == "no" ]; then
405 BBSIM_SADIS_SVC="bbsim0"
406else
407 BBSIM_SADIS_SVC="bbsim"
408fi
409
410SADIS_SUBSCRIBERS=${SADIS_SUBSCRIBERS:-http://$BBSIM_SADIS_SVC.$VOLTHA_NS.svc:50074/v2/subscribers/%s}
411SADIS_BANDWIDTH_PROFILES=${SADIS_BANDWIDTH_PROFILES:-http://$BBSIM_SADIS_SVC.$VOLTHA_NS.svc:50074/v2/bandwidthprofiles/%s}
412
David Bainbridged18f4942020-04-14 16:46:13 -0700413if [ "$HELM_USE_UPGRADE" == "yes" ]; then
David Bainbridge7f8bf992020-04-08 21:53:22 -0700414 _HELM_DESC="Upgrade/Install"
415else
416 _HELM_DESC="Install"
417fi
418
David K. Bainbridgeda33d652020-03-06 10:31:23 -0800419# Check for prerequiste tools
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700420TOOLS="curl sed jq $EXTRA_TOOLS"
David Bainbridged18f4942020-04-14 16:46:13 -0700421if [ "$DEPLOY_K8S" == "yes" ]; then
David K. Bainbridgeda33d652020-03-06 10:31:23 -0800422 TOOLS+=" docker"
423fi
424NOT_FOUND=""
425for T in $TOOLS; do
David Bainbridged18f4942020-04-14 16:46:13 -0700426 if [ -z "$(command -v "$T")" ]; then
David K. Bainbridgeda33d652020-03-06 10:31:23 -0800427 NOT_FOUND+=" $T"
428 fi
429done
430
David Bainbridged18f4942020-04-14 16:46:13 -0700431if [ -n "$NOT_FOUND" ]; then
David K. Bainbridgeda33d652020-03-06 10:31:23 -0800432 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} The following required tools where not found, please install them:$NOT_FOUND"
433 exit 1
434fi
435
David Bainbridged18f4942020-04-14 16:46:13 -0700436TIMEOUT_SECONDS="$(parseDuration "$WAIT_TIMEOUT")"
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700437
David Bainbridge0774b232019-08-02 06:37:19 +0000438mkdir -p .voltha
439touch .voltha/ports
David Bainbridged18f4942020-04-14 16:46:13 -0700440HAVE="$(grep "$NAME" .voltha/ports)"
David Bainbridge0774b232019-08-02 06:37:19 +0000441if [ "$HAVE X" == " X" ]; then
442 # Find free port prefix
443 START=81
444 while true; do
David Bainbridged18f4942020-04-14 16:46:13 -0700445 if [ "$(grep -c $START .voltha/ports)" -eq 0 ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000446 break
447 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700448 START="$((START + 1))"
David Bainbridge0774b232019-08-02 06:37:19 +0000449 done
David Bainbridged18f4942020-04-14 16:46:13 -0700450 DELTA="$((START - 81))"
David Bainbridgea2595422019-10-22 03:54:28 +0000451 ONOS_API_PORT=${ONOS_API_PORT:-${START}81}
452 ONOS_SSH_PORT=${ONOS_SSH_PORT:-${START}01}
David Bainbridged18f4942020-04-14 16:46:13 -0700453 VOLTHA_API_PORT=${VOLTHA_API_PORT:-5$((55 + DELTA))55}
454 VOLTHA_SSH_PORT=${VOLTHA_SSH_PORT:-$((50 + DELTA))22}
455 VOLTHA_ETCD_PORT=${VOLTHA_ETCD_PORT:-$((23 + DELTA))79}
456 VOLTHA_KAFKA_PORT=${VOLTHA_KAFKA_PORT:-$((90 + DELTA))92}
Matteo Scandoloefee0432020-05-05 13:56:20 -0700457 VOLTHA_PPROF_PORT=${VOLTHA_PPROF_PORT:-$((60 + DELTA))60}
458 OPENOLT_PPROF_PORT=${OPENOLT_PPROF_PORT:-$((60 + DELTA))61}
Matteo Scandolo65c35192020-05-13 10:41:21 -0700459 OFAGENT_PPROF_PORT=${OFAGENT_PPROF_PORT:-$((60 + DELTA))62}
divyadesai59f987a2020-05-27 12:11:33 +0000460 ELASTICSEARCH_PORT=${ELASTICSEARCH_PORT:-$((92 + DELTA))00}
461 KIBANA_PORT=${KIBANA_PORT:-$((56 + DELTA))01}
Test User01ed0642019-07-03 20:17:06 +0000462else
David Bainbridged18f4942020-04-14 16:46:13 -0700463 VALUES="$(echo "$HAVE" | sed -e 's/\s//g' | cut -d= -f2)"
464 ONOS_API_PORT=${ONOS_API_PORT:-$(echo "$VALUES" | cut -d, -f1)}
465 ONOS_SSH_PORT=${ONOS_SSH_PORT:-$(echo "$VALUES" | cut -d, -f2)}
466 VOLTHA_API_PORT=${VOLTHA_API_PORT:-$(echo "$VALUES" | cut -d, -f3)}
467 VOLTHA_SSH_PORT=${VOLTHA_SSH_PORT:-$(echo "$VALUES" | cut -d, -f4)}
468 VOLTHA_ETCD_PORT=${VOLTHA_ETCD_PORT:-$(echo "$VALUES" | cut -d, -f5)}
469 VOLTHA_KAFKA_PORT=${VOLTHA_KAFKA_PORT:-$(echo "$VALUES" | cut -d, -f6)}
Matteo Scandoloefee0432020-05-05 13:56:20 -0700470 VOLTHA_PPROF_PORT=${VOLTHA_PPROF_PORT:-$(echo "$VALUES" | cut -d, -f7)}
471 OPENOLT_PPROF_PORT=${OPENOLT_PPROF_PORT:-$(echo "$VALUES" | cut -d, -f8)}
Matteo Scandolo65c35192020-05-13 10:41:21 -0700472 OFAGENT_PPROF_PORT=${OFAGENT_PPROF_PORT:-$(echo "$VALUES" | cut -d, -f9)}
divyadesai59f987a2020-05-27 12:11:33 +0000473 ELASTICSEARCH_PORT=${ELASTICSEARCH_PORT:-$(echo "$VALUES" | cut -d, -f10)}
474 KIBANA_PORT=${KIBANA_PORT:-$(echo "$VALUES" | cut -d, -f11)}
David K. Bainbridge00ecd382020-02-28 12:31:58 -0800475
Matteo Scandoloefee0432020-05-05 13:56:20 -0700476 # Some ports were added after the .voltha/ports files was created.
477 # Calculate the original DELTA from the VOLTHA_SSH_PORT so that it can
478 # be used to set up newer port-forwards.
479 DELTA="$((VOLTHA_SSH_PORT/100-50))"
480
David K. Bainbridge00ecd382020-02-28 12:31:58 -0800481 if [ -z "$VOLTHA_KAFKA_PORT" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -0700482 VOLTHA_KAFKA_PORT=${VOLTHA_KAFKA_PORT:-$((90 + DELTA))92}
David K. Bainbridge00ecd382020-02-28 12:31:58 -0800483 fi
Matteo Scandoloefee0432020-05-05 13:56:20 -0700484
485 if [ -z "$VOLTHA_PPROF_PORT" ]; then
divyadesai59f987a2020-05-27 12:11:33 +0000486 VOLTHA_PPROF_PORT=${VOLTHA_PPROF_PORT:-$((60 + DELTA))60}
Matteo Scandoloefee0432020-05-05 13:56:20 -0700487 fi
488 if [ -z "$OPENOLT_PPROF_PORT" ]; then
divyadesai59f987a2020-05-27 12:11:33 +0000489 OPENOLT_PPROF_PORT=${OPENOLT_PPROF_PORT:-$((60 + DELTA))61}
Matteo Scandoloefee0432020-05-05 13:56:20 -0700490 fi
Matteo Scandolo65c35192020-05-13 10:41:21 -0700491 if [ -z "$OFAGENT_PPROF_PORT" ]; then
divyadesai59f987a2020-05-27 12:11:33 +0000492 OFAGENT_PPROF_PORT=${OFAGENT_PPROF_PORT:-$((60 + DELTA))62}
493 fi
494
495 if [ -z "$ELASTICSEARCH_PORT" ]; then
496 ELASTICSEARCH_PORT=${ELASTICSEARCH_PORT:-$((92 + DELTA))00}
497 fi
498
499 if [ -z "$KIBANA_PORT" ]; then
500 KIBANA_PORT=${KIBANA_PORT:-$((56 + DELTA))01}
Matteo Scandolo65c35192020-05-13 10:41:21 -0700501 fi
Test User01ed0642019-07-03 20:17:06 +0000502fi
503
David Bainbridged18f4942020-04-14 16:46:13 -0700504PORTTMP="$(mktemp -u)"
505grep -v "$NAME" .voltha/ports > "$PORTTMP"
divyadesai59f987a2020-05-27 12:11:33 +0000506echo "$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 -0700507cp "$PORTTMP" .voltha/ports
508rm -f "$PORTTMP"
David Bainbridge0774b232019-08-02 06:37:19 +0000509
David Bainbridge27790d62019-08-13 22:43:19 +0000510export ONOS_API_PORT ONOS_SSH_PORT
David Bainbridge01294952019-07-30 19:33:45 +0000511
Test Userd87942b2019-07-03 07:20:24 +0000512IDX=1
David Bainbridgee87067b2019-08-12 22:00:12 +0000513CLOCK="TIME:"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000514SPIN_PARTS=
515NOT_VERIFIED=
David Bainbridgef858a022019-08-14 21:25:11 +0000516THEX=
517BUILD=
David Bainbridge38dc1e82019-08-12 15:18:45 +0000518VERIFIED=
519HELM=
520OLD_KEY=
521BIRD=
522HIGH_VOLTAGE=
523PLUG=
David Bainbridge38dc1e82019-08-12 15:18:45 +0000524FORWARD=
David Bainbridge38dc1e82019-08-12 15:18:45 +0000525GO=
526DOWNLOAD=
527GEAR=
528NO_ENTRY=
529LOCK=
530
David Bainbridged18f4942020-04-14 16:46:13 -0700531if [ "$FANCY" -eq 1 ]; then
532 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 +0000533 CLOCK="\xe2\x8f\xb1"
David Bainbridgef858a022019-08-14 21:25:11 +0000534 THEX="${RED}${BOLD}\xe2\x9c\x97\x20${NORMAL}"
David Bainbridgef858a022019-08-14 21:25:11 +0000535 BUILD="${YELLOW}${BOLD}\xf0\x9f\x8f\x97${NORMAL}"
536 NOT_VERIFIED="$BUILD"
537 VERIFIED="${GREEN}${BOLD}\xe2\x9c\x93\x20${NORMAL}"
538 HELM="${BLUE}${BOLD}\xE2\x8E\x88${NORMAL}"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000539 OLD_KEY="\xF0\x9F\x97\x9D"
540 BIRD="\xF0\x9F\x90\xA6"
541 HIGH_VOLTAGE="\xE2\x9A\xA1"
542 PLUG="\xF0\x9F\xa7\xa9"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000543 FORWARD="\xE2\x87\xA8"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000544 GO="\xf0\x9f\x9a\x80"
545 DOWNLOAD="\xf0\x9f\x93\xa5"
546 GEAR="\xe2\x9a\x99"
547 NO_ENTRY="\xe2\x9b\x94"
548 LOCK="\xf0\x9f\x94\x92"
549fi
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700550
David Bainbridge712afb82019-08-14 19:55:58 +0000551duration() {
David Bainbridged18f4942020-04-14 16:46:13 -0700552 local h m s t
553 h="$(($1 / 3600))"
554 m="$(($1 % 3600 / 60))"
555 s="$(($1 % 60))"
556 t=""
David Bainbridgee87067b2019-08-12 22:00:12 +0000557
David Bainbridged18f4942020-04-14 16:46:13 -0700558 if [ "$h" -gt 0 ]; then
David Bainbridgee87067b2019-08-12 22:00:12 +0000559 t="$t${h}h"
560 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700561 if [ "$m" -gt 0 ]; then
David Bainbridgee87067b2019-08-12 22:00:12 +0000562 t="$t${m}m"
563 fi
David Bainbridge712afb82019-08-14 19:55:58 +0000564 echo "$t${s}s"
565}
566
567printtime() {
David Bainbridged18f4942020-04-14 16:46:13 -0700568 local INDENT
David Bainbridge712afb82019-08-14 19:55:58 +0000569 if [ "$1" == "-" ]; then
570 INDENT=" "
571 shift
572 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700573 echo -e "$INDENT $CLOCK $(duration "$1")"
David Bainbridgee87067b2019-08-12 22:00:12 +0000574}
575
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700576bspin() {
Test Userd87942b2019-07-03 07:20:24 +0000577 IDX=1
David Bainbridged18f4942020-04-14 16:46:13 -0700578 local INDENT
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700579 if [ "$1" == "-" ]; then
580 INDENT=" "
581 shift
582 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700583 if [ "$FANCY" -eq 0 ]; then
584 LINE="${*//[[:space:]+-]}"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000585 if [ "$LINE X" == " X" ]; then
586 return
587 fi
588 echo -e "$CIVIS$INDENT$*"
589 else
590 echo -en "$CIVIS$INDENT $*"
591 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700592}
593
594sspin() {
David Bainbridged18f4942020-04-14 16:46:13 -0700595 local INDENT
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700596 if [ "$1" == "-" ]; then
597 INDENT=" "
598 shift
599 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700600 if [ "$FANCY" -eq 0 ]; then
601 LINE="${*//[[:space:]+-]}"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000602 if [ "$LINE X" == " X" ]; then
603 return
604 fi
605 echo -e "$INDENT$*"
606 else
David Bainbridged18f4942020-04-14 16:46:13 -0700607 C="$(echo "$SPIN_PARTS" | cut '-d ' -f "$IDX")"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000608 echo -en "\r$INDENT$C $*"
David Bainbridged18f4942020-04-14 16:46:13 -0700609 IDX="$((IDX + 1))"
610 if [ "$IDX" -gt 8 ]; then
David Bainbridge38dc1e82019-08-12 15:18:45 +0000611 IDX=1
612 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700613 fi
614}
615
616espin() {
David Bainbridged18f4942020-04-14 16:46:13 -0700617 local INDENT
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700618 if [ "$1" == "-" ]; then
619 INDENT=" "
620 shift
621 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700622 if [ "$FANCY" -eq 0 ]; then
623 LINE="${*//[[:space:]+-]}"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000624 if [ "$LINE X" == " X" ]; then
625 return
626 fi
627 echo -e "$INDENT$*"
628 else
629 echo -e "\r$INDENT$*$CNORM"
630 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700631}
632
David Bainbridged18f4942020-04-14 16:46:13 -0700633if [ "$1" == "get" ] && [ "$2" == "voltconfig" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000634 echo "$HOME/.volt/config-$NAME"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000635 exit
636fi
637
David Bainbridgee4d11ca2020-05-08 10:21:10 -0700638if [ $# -ne 1 ] || ! is_in "$1" "up,down,dump,clean"; then
David Bainbridgeac7f8072019-08-01 22:15:33 +0000639 >&2 echo "What wouild you like to do today:"
640 >&2 echo " up - bring up voltha"
641 >&2 echo " down - tear down voltha"
642 >&2 echo " dump - create a debug dump of running system"
643 exit 1
644fi
645
divyadesai59f987a2020-05-27 12:11:33 +0000646do_curl() {
647 local DATA_ARGS CREDS CMD_ECHO CMD_OUTPUT SC_OUTPUT WAIT_START INDENTA EXTRAA NOW
648 local INDENT=$1
649 local OP=$2
650 local USER=$3
651 local PASS=$4
652 local URL=$5
653 local DATA_TYPE=$6
654 local DATA=$7
655 local MSG=$8
656 local VALID_RESULTS=$9
657 local EXTRA=${10}
658 local ICON=${11}
659
660 # Turn into an array for passing
661 INDENTA=()
662 if [ -n "$INDENT" ]; then
663 INDENTA=("$INDENT")
664 fi
665 IFS=' ' read -r -a EXTRAA <<< "$EXTRA"
David Bainbridge4f1b5562019-08-19 04:46:52 +0000666
David K. Bainbridgeb4b163b2020-02-19 15:55:06 -0800667 # Thanks to the latest version of ONOS using the return code 207 this gets a
668 # whole lot nastier. Can't thank them enough for doing this. So in order to
669 # capture the command and the output in the log file as well as capture the
670 # status code to verify it is 200 and not 207 mutltiple files and a bit of
671 # hackery must be used. Thanks again ONOS.
David Bainbridged18f4942020-04-14 16:46:13 -0700672 CMD_ECHO="$(mktemp -u)"
673 CMD_OUTPUT="$(mktemp -u)"
674 SC_OUTPUT="$(mktemp -u)"
675 WAIT_START="$(date +%s)"
David K. Bainbridgeb4b163b2020-02-19 15:55:06 -0800676
divyadesai59f987a2020-05-27 12:11:33 +0000677 CREDS=()
678 if [ -n "$USER" ]; then
679 CREDS=("--user" "$USER:$PASS")
680 fi
681
682 DATA_ARGS=()
683 if [ -n "$DATA" ]; then
684 if [ "$DATA_TYPE" == "file" ]; then
685 DATA_ARGS=("--data" "@$DATA")
686 elif [ "$DATA_TYPE" == "json" ]; then
687 DATA_ARGS=("--data" "$DATA")
688 fi
689 fi
690
691 bspin "${INDENTA[@]}" "$MSG" "$ICON"
David Bainbridge4f1b5562019-08-19 04:46:52 +0000692 while true; do
David Bainbridged18f4942020-04-14 16:46:13 -0700693 NOW="$(date +%s)"
694 if [ "$((NOW - WAIT_START))" -gt "$TIMEOUT_SECONDS" ]; then
divyadesai59f987a2020-05-27 12:11:33 +0000695 espin "${INDENTA[@]}" "$THEX"
David Bainbridged18f4942020-04-14 16:46:13 -0700696 rm -f "$CMD_ECHO" "$CMD_OUTPUT" "$SC_OUTPUT"
divyadesai59f987a2020-05-27 12:11:33 +0000697 doTimeout "$MSG"
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700698 fi
divyadesai59f987a2020-05-27 12:11:33 +0000699 (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
700 RESULT=$?
David K. Bainbridgeb4b163b2020-02-19 15:55:06 -0800701 # Dump everything to the log
David Bainbridged18f4942020-04-14 16:46:13 -0700702 cat "$CMD_ECHO" >> "$LOG"
703 test -r "$CMD_OUTPUT" && cat "$CMD_OUTPUT" >> "$LOG"
704 SC="$(cat "$SC_OUTPUT")"
705 echo "RESPONSE CODE: $SC" >> "$LOG"
706 echo "ERROR CODE: $RESULT" >> "$LOG"
David K. Bainbridgeb4b163b2020-02-19 15:55:06 -0800707
708 # clean up temp files
David Bainbridged18f4942020-04-14 16:46:13 -0700709 rm -f "$CMD_ECHO" "$CMD_OUTPUT" "$SC_OUTPUT"
divyadesai59f987a2020-05-27 12:11:33 +0000710 if [ "$RESULT" -eq 0 ] && is_in "$SC" "$VALID_RESULTS"; then
David Bainbridge4f1b5562019-08-19 04:46:52 +0000711 break
712 fi
Matteo Scandolo9a77a732020-01-09 14:24:12 -0800713 sleep 1
divyadesai59f987a2020-05-27 12:11:33 +0000714 sspin "${INDENTA[@]}"
David Bainbridge4f1b5562019-08-19 04:46:52 +0000715 done
divyadesai59f987a2020-05-27 12:11:33 +0000716 espin "${INDENTA[@]}" "$VERIFIED"
717}
718
719push_onos_config() {
720 local DATA_TYPE=$1
721 local MSG=$2
722 local RESOURCE=$3
723 local DATA=$4
724
725 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 +0000726}
727
Matteo Scandolo9a77a732020-01-09 14:24:12 -0800728check_onos_app_active() {
David Bainbridged18f4942020-04-14 16:46:13 -0700729 local APP_ID WAIT_START RESULT NOW
730 APP_ID=$1
731 WAIT_START="$(date +%s)"
Matteo Scandolo9a77a732020-01-09 14:24:12 -0800732
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700733 bspin - "Checking that $APP_ID is active $CLOCK"
734 while true; do
David Bainbridged18f4942020-04-14 16:46:13 -0700735 NOW="$(date +%s)"
736 if [ "$((NOW - WAIT_START))" -gt "$TIMEOUT_SECONDS" ]; then
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700737 espin - "$THEX"
738 doTimeout "waiting for ONOS application activation '$APP_ID'"
739 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700740 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 -0700741 break
742 fi
743 sleep 1
744 sspin -
745 done
746 sleep 5 # OSGI components take a little longer that the app to activate
David Bainbridged18f4942020-04-14 16:46:13 -0700747 espin - "$VERIFIED"
Matteo Scandolo9a77a732020-01-09 14:24:12 -0800748}
749
David Bainbridge4f1b5562019-08-19 04:46:52 +0000750override_onos_app() {
David Bainbridged18f4942020-04-14 16:46:13 -0700751 local APP NAME WAIT_START NOW
752 APP=$1
753 NAME="$(basename "$APP" | sed -e 's/^[0-9][0-9]*-//g' -e 's/-.*$//g')"
754 WAIT_START="$(date +%s)"
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700755
David Bainbridge4f1b5562019-08-19 04:46:52 +0000756 while true; do
David Bainbridged18f4942020-04-14 16:46:13 -0700757 NOW="$(date +%s)"
758 if [ "$((NOW - WAIT_START))" -gt "$TIMEOUT_SECONDS" ]; then
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700759 espin - "$THEX"
760 doTimeout "waiting to overwrite ONOS application '$APP'"
761 fi
David Bainbridge4f1b5562019-08-19 04:46:52 +0000762 sspin -
763 # Attempt to delete old version (if it exists)
David Bainbridged18f4942020-04-14 16:46:13 -0700764 (set -x; curl --fail -sSL --user karaf:karaf -X DELETE "http://$_ONOS_API_EP/onos/v1/applications/$NAME" >>"$LOG" 2>&1) >>"$LOG" 2>&1
765 RESULT=$?
David Bainbridge4f1b5562019-08-19 04:46:52 +0000766 sspin -
David Bainbridged18f4942020-04-14 16:46:13 -0700767 if [ $RESULT -ne 0 ]; then
David Bainbridge4f1b5562019-08-19 04:46:52 +0000768 continue
769 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700770 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 +0000771 break
772 fi
773 sleep .2
774 done
775}
776
777activate_onos_app() {
David Bainbridged18f4942020-04-14 16:46:13 -0700778 local MSG APP WAIT_START NOW
779 MSG="$1"
780 APP=$2
781 WAIT_START="$(date +%s)"
David Bainbridge4f1b5562019-08-19 04:46:52 +0000782
783 bspin - "$MSG $GO"
784 while true; do
David Bainbridged18f4942020-04-14 16:46:13 -0700785 NOW="$(date +%s)"
786 if [ "$((NOW - WAIT_START))" -gt "$TIMEOUT_SECONDS" ]; then
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700787 espin - "$THEX"
788 doTimeout "waiting to activate ONOS application '$APP'"
789 fi
David Bainbridge4f1b5562019-08-19 04:46:52 +0000790 sspin -
David Bainbridged18f4942020-04-14 16:46:13 -0700791 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 +0000792 break
793 fi
794 sleep .2
795 done
796 espin - "$VERIFIED"
797}
798
799count_pods() {
David Bainbridged18f4942020-04-14 16:46:13 -0700800 local NAMESPACE STATES LABELS CMD PODS
801 NAMESPACE=$1; shift
David Bainbridge4f1b5562019-08-19 04:46:52 +0000802 if [ "$NAMESPACE" == "all-namespaces" ]; then
803 NAMESPACE="--all-namespaces"
804 else
805 NAMESPACE="-n $NAMESPACE"
806 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700807 STATES=$1; shift
808 LABELS=$1; shift
809 CMD=("kubectl get $NAMESPACE $LABELS pod")
810 PODS=$(${CMD[*]} -o go-template="{{range .items}}{{.metadata.name}}/{{.status.phase}}/_{{range .status.containerStatuses}}{{.ready}}_{{end}} {{end}}")
David Bainbridge4f1b5562019-08-19 04:46:52 +0000811 local COUNT=0
812 local PATTERNS="$*"
813 for POD in $PODS; do
David Bainbridged18f4942020-04-14 16:46:13 -0700814 local NAME STATE CONTAINERS TOTAL FOUND
815 NAME="$(echo "$POD" | cut -d/ -f 1)"
816 STATE="$(echo "$POD" | cut -d/ -f 2)"
817 CONTAINERS="$(echo "$POD" | cut -d/ -f 3 | sed -e 's/_/ /g')"
818 if [ "$STATES" == "*" ] || [ "$(echo "$STATES" | grep -c ":$STATE:")" -ne 0 ]; then
819 TOTAL="$(echo "$CONTAINERS" | wc -w)"
820 FOUND="$(echo "$CONTAINERS" | grep -o true | wc -l)"
821 if [ "$TOTAL" -eq "$FOUND" ]; then
David Bainbridge4f1b5562019-08-19 04:46:52 +0000822 for PATTERN in $PATTERNS; do
David Bainbridged18f4942020-04-14 16:46:13 -0700823 if [[ "$NAME" =~ $PATTERN ]]; then
824 COUNT="$((COUNT + 1))"
David Bainbridge4f1b5562019-08-19 04:46:52 +0000825 break
826 fi
827 done
828 fi
829 fi
830 done
David Bainbridge4f1b5562019-08-19 04:46:52 +0000831 echo $COUNT
832}
833
834wait_for_pods() {
David Bainbridged18f4942020-04-14 16:46:13 -0700835 local INDENT NAMESPACE EXPECT TYPE MESSAGE LABELS PATTERNS STATES HAVE ALL WAIT_START NOW
David Bainbridge4f1b5562019-08-19 04:46:52 +0000836 if [ "$1" == "-" ]; then
837 INDENT=$1; shift
838 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700839 NAMESPACE=$1; shift
840 EXPECT=$1; shift
841 TYPE=$1; shift
842 MESSAGE=$1; shift
843 LABELS=$1; shift
844 PATTERNS=("$*")
845 STATES=":Running:"
David Bainbridge99ac7a22019-08-31 02:26:43 +0000846 if [ "$TYPE" == "not" ]; then
847 STATES="*"
848 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700849 HAVE="$(count_pods "$NAMESPACE" "$STATES" "$LABELS" "${PATTERNS[@]}")"
850 ALL=$HAVE
David Bainbridge4f1b5562019-08-19 04:46:52 +0000851 if [ "$TYPE" == "only" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -0700852 ALL="$(count_pods "all-namespaces" "*" ".*")"
David Bainbridge4f1b5562019-08-19 04:46:52 +0000853 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700854 COUNT="$((300 / 15))"
855 WAIT_START="$(date +%s)"
856 bspin "$INDENT" "$MESSAGE"
857 sspin "$INDENT"
858 if [ "$HAVE" -ne "$EXPECT" ] || [ "$ALL" -ne "$HAVE" ]; then
859 while [ "$HAVE" -ne "$EXPECT" ] || [ "$ALL" -ne "$HAVE" ]; do
860 NOW="$(date +%s)"
861 if [ "$((NOW - WAIT_START))" -gt "$TIMEOUT_SECONDS" ]; then
862 espin "$INDENT" "$THEX"
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700863 doTimeout "waiting for PODs to start"
864 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700865 sspin "$INDENT"
866 COUNT="$((COUNT - 1))"
867 if [ "$COUNT" -eq 0 ]; then
868 HAVE="$(count_pods "$NAMESPACE" "$STATES" "$LABELS" "${PATTERNS[@]}")"
869 ALL="$HAVE"
David Bainbridge4f1b5562019-08-19 04:46:52 +0000870 if [ "$TYPE" == "only" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -0700871 ALL="$(count_pods "all-namespaces" "*" ".*")"
David Bainbridge4f1b5562019-08-19 04:46:52 +0000872 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700873 COUNT="$((300 / 15))"
David Bainbridge4f1b5562019-08-19 04:46:52 +0000874 fi
875 sleep .15
876 done
877 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700878 espin "$INDENT" "$VERIFIED"
879 if [ "$HAVE" -ne "$EXPECT" ]; then
David Bainbridge4f1b5562019-08-19 04:46:52 +0000880 return 1
881 fi
882 return 0
883}
884
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800885port_forward() {
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700886 local NS=$1; shift
887 local SVC=$1; shift
888 local PORTS="$*"
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800889 local TAG=$SVC-$NAME
890
David Bainbridge1d2c5842020-06-03 15:29:07 -0700891 (set -x; _TAG="$TAG" bash -c "while true; do kubectl port-forward --address 0.0.0.0 -n $NS service/$SVC $PORTS; done" >>"$PFLOG" 2>&1 &) >>"$PFLOG" 2>&1
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800892}
893
894kill_port_forward() {
David Bainbridge1d2c5842020-06-03 15:29:07 -0700895 local TAG P_IDS PARENTS KIDS UNKNOWN PP_ID PF
896
897 while [ $# -gt 0 ]; do
898 PF=$1; shift
899 TAG=
900 if [ "$PF" != "__ALL__" ]; then
901 TAG="$PF-$NAME"
902 fi
903 PARENTS=
904 KIDS=
905 UNKNOWN=
906 # shellcheck disable=SC2009
907 P_IDS="$(ps e -ww -A | grep "_TAG=$TAG" | grep -v grep | awk '{print $1}')"
908 if [ -n "$P_IDS" ]; then
909 for P_ID in $P_IDS; do
910 PP_ID="$(ps -o ppid "$P_ID" | tail -n +2)"
911 if [ -n "$PP_ID" ]; then
912 if [ "$PP_ID" -eq 1 ]; then
913 PARENTS="$PARENTS $P_ID"
914 else
915 KIDS="$KIDS $P_ID"
916 fi
David Bainbridgec6871d22019-11-13 17:10:31 +0000917 else
David Bainbridge1d2c5842020-06-03 15:29:07 -0700918 UNKNOWN="$UNKNOWN $P_ID"
David Bainbridgec6871d22019-11-13 17:10:31 +0000919 fi
David Bainbridge1d2c5842020-06-03 15:29:07 -0700920 done
921 if [ -n "$PARENTS" ]; then
922 # shellcheck disable=SC2086
923 while ps -h $PARENTS >/dev/null 2>&1; do
924 (set -x; eval "kill -9 $PARENTS" >>"$LOG" 2>&1) >>"$LOG" 2>&1
925 done
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800926 fi
David Bainbridge1d2c5842020-06-03 15:29:07 -0700927 if [ -n "$KIDS" ]; then
928 # shellcheck disable=SC2086
929 while ps -h $KIDS >/dev/null 2>&1; do
930 (set -x; eval "kill -9 $KIDS" >>"$LOG" 2>&1) >>"$LOG" 2>&1
931 done
932 fi
933 if [ -n "$UNKNOWN" ]; then
934 # shellcheck disable=SC2086
935 while ps -h $UNKNOWN >/dev/null 2>&1; do
936 (set -x; eval "kill -9 $UNKNOWN" >>"$LOG" 2>&1) >>"$LOG" 2>&1
937 done
938 fi
939 fi
940 done
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800941}
942
David Bainbridgecf546362020-04-21 23:18:50 -0700943resolve_chart_version() {
944 [ "$2" != "latest" ] && echo "$2" && return
945 helm inspect chart "$1" | grep "^version:" | awk '{print $2}'
946}
947
Jonathan Hart6a91e6c2020-04-16 14:28:33 -0700948# Compares two semver-formatted version strings (e.g. 2.4.3)
949# Returns 0 if $1 == $2, returns 1 if $1 > $2 and returns 2 if $1 < $2
950compare_versions() {
951 [ "$1" == "$2" ] && return 0
Jonathan Hart6a91e6c2020-04-16 14:28:33 -0700952 local lowest
953 lowest=$(echo -e "$1\n$2" | sort -V | head -1)
954 [ "$lowest" == "$1" ] && return 2
955 return 1
956}
957
David Bainbridgeac7f8072019-08-01 22:15:33 +0000958if [ "$1" == "down" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000959 echo "Tearing down voltha cluster $NAME"
960 LOG="down-$NAME.log"
David Bainbridged18f4942020-04-14 16:46:13 -0700961 date -u +"%Y%m%dT%H%M%SZ" >"$LOG"
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700962 if is_in "$WITH_ONOS" "yes,legacy,classic"; then
David Bainbridge696bc632020-04-05 21:49:37 -0700963 bspin "Remove port-forwards: onos-ui-$NAME"
964 kill_port_forward onos-ui
965 sspin "Remove port-forwards: onos-ssh-$NAME$CEOL"
966 kill_port_forward onos-ssh
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700967 bspin "Remove port-forwards: onos-onos-classic-hs-$NAME$CEOL"
968 kill_port_forward onos-onos-classic-hs
David Bainbridge696bc632020-04-05 21:49:37 -0700969 fi
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800970 sspin "Remove port-forwards: voltha-api-$NAME$CEOL"
David Bainbridge1d2c5842020-06-03 15:29:07 -0700971 kill_port_forward voltha-api voltha-voltha-api
David Bainbridgec7220622020-05-28 12:31:47 -0700972 if is_in "$WITH_ETCD" "yes,external"; then
973 sspin "Remove port-forwards: etcd-$NAME$CEOL"
974 kill_port_forward "etcd"
David Bainbridge696bc632020-04-05 21:49:37 -0700975 fi
David Bainbridgec7220622020-05-28 12:31:47 -0700976 if is_in "$WITH_KAFKA" "yes,external"; then
977 sspin "Remove port-forwards: kafka-$NAME$CEOL"
978 kill_port_forward "kafka"
David Bainbridge696bc632020-04-05 21:49:37 -0700979 fi
Matteo Scandoloefee0432020-05-05 13:56:20 -0700980
981 if [ "$WITH_PPROF" == "yes" ]; then
David Bainbridgec7220622020-05-28 12:31:47 -0700982 sspin "Remove port-forwards: *-profiler$CEOL"
David Bainbridge1d2c5842020-06-03 15:29:07 -0700983 kill_port_forward voltha-rw-core-profiler voltha-voltha-rw-core-profiler
984 kill_port_forward voltha-of-agent-profiler voltha-voltha-of-agent-profiler
David Bainbridgec7220622020-05-28 12:31:47 -0700985 if [ "$WITH_OPEN_ADAPTERS" == "yes" ]; then
David Bainbridge1d2c5842020-06-03 15:29:07 -0700986 kill_port_forward adapter-open-olt-profiler open-olt-adapter-open-olt-profiler
David Bainbridgec7220622020-05-28 12:31:47 -0700987 fi
Matteo Scandoloefee0432020-05-05 13:56:20 -0700988 fi
989
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800990 espin "$VERIFIED Remove port-forwards$CEOL"
David Bainbridged18f4942020-04-14 16:46:13 -0700991 if [ "$DEPLOY_K8S" == "yes" ]; then
David Bainbridgeac7f8072019-08-01 22:15:33 +0000992 if [ -x ./bin/kind ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000993 bspin "Delete Kubernetes Kind Cluster"
David Bainbridged18f4942020-04-14 16:46:13 -0700994 (set -x; ./bin/kind delete cluster --name "voltha-$NAME" >>"$LOG" 2>&1) >>"$LOG" 2>&1
995 espin "$VERIFIED"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000996 else
David Bainbridge0774b232019-08-02 06:37:19 +0000997 espin "$NO_ENTRY Delete Kubernetes Kind Cluster: kind command not found"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000998 fi
999 else
David Bainbridge309099c2020-05-05 08:47:29 -07001000 if [ "$CONFIG_SADIS" == "external" ]; then
1001 bspin "Remove configmap for BBSIM SADIS server"
1002 (set -x; kubectl -n "$BBSIM_NS" delete --ignore-not-found configmap kube-config >>"$LOG" 2>&1) >>"$LOG" 2>&1
1003 espin "$VERIFIED"
1004 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001005 EXISTS="$(helm list -q)"
David Bainbridge76afd812020-04-06 09:53:52 -07001006 EXPECT="voltha"
David Bainbridge60ffc0f2020-04-27 22:13:22 -07001007 if is_in "$WITH_ONOS" "yes,legacy,classic"; then
David Bainbridge696bc632020-04-05 21:49:37 -07001008 EXPECT+=" onos"
1009 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001010 if [ "$WITH_RADIUS" == "yes" ]; then
David Bainbridge696bc632020-04-05 21:49:37 -07001011 EXPECT+=" radius"
1012 fi
David Bainbridge309099c2020-05-05 08:47:29 -07001013 if [ "$CONFIG_SADIS" == "external" ]; then
1014 EXPECT+=" bbsim-sadis-server"
1015 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001016 if [ "$WITH_BBSIM" == "yes" ]; then
David Bainbridge696bc632020-04-05 21:49:37 -07001017 EXPECT+=" bbsim"
1018 fi
divyadesai59f987a2020-05-27 12:11:33 +00001019 if [ "$WITH_EFK" == "yes" ]; then
1020 EXPECT+=" elasticsearch kibana fluentd"
1021 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001022 if [ "$WITH_OPEN_ADAPTERS" == "yes" ]; then
David Bainbridge696bc632020-04-05 21:49:37 -07001023 EXPECT+=" open-olt open-onu"
1024 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001025 if [ "$WITH_SIM_ADAPTERS" == "yes" ]; then
David Bainbridge696bc632020-04-05 21:49:37 -07001026 EXPECT+=" sim"
1027 fi
David Bainbridgec7220622020-05-28 12:31:47 -07001028 if is_in "$WITH_ETCD" "yes,external"; then
1029 EXPECT+=" etcd"
David Bainbridge76afd812020-04-06 09:53:52 -07001030 fi
David Bainbridgec7220622020-05-28 12:31:47 -07001031 if is_in "$WITH_KAFKA" "yes,external"; then
David Bainbridge76afd812020-04-06 09:53:52 -07001032 EXPECT+=" kafka"
1033 fi
David Bainbridge0774b232019-08-02 06:37:19 +00001034 bspin "Remove Helm Deployments"
David Bainbridgeac7f8072019-08-01 22:15:33 +00001035 for i in $EXISTS; do
David K. Bainbridge43422402020-03-06 07:41:22 -08001036 for j in $EXPECT; do
David Bainbridged18f4942020-04-14 16:46:13 -07001037 if [[ "$i" =~ $j ]]; then
David K. Bainbridge43422402020-03-06 07:41:22 -08001038 sspin "Remove Helm Deployments: $i$CEOL"
David Bainbridged18f4942020-04-14 16:46:13 -07001039 (set -x; ./bin/helm delete --no-hooks --purge "$i" >>"$LOG" 2>&1) >>"$LOG" 2>&1
David K. Bainbridge43422402020-03-06 07:41:22 -08001040 fi
1041 done
uottrembb16d3982020-02-28 08:34:36 +01001042 done
David Bainbridge0774b232019-08-02 06:37:19 +00001043 espin "$VERIFIED Remove Helm Deployments$CEOL"
David Bainbridge4f1b5562019-08-19 04:46:52 +00001044 if [ "$WAIT_ON_DOWN" == "yes" ]; then
Matteo Scandoloe93c9eb2020-06-03 12:08:51 -07001045 PODS="voltha-ofagent.* voltha-rw-core.*"
David Bainbridge76afd812020-04-06 09:53:52 -07001046 INFRA_PODS=
1047 ADAPT_PODS=
1048 SIM_PODS=
divyadesai59f987a2020-05-27 12:11:33 +00001049 EFK_PODS=
David Bainbridged18f4942020-04-14 16:46:13 -07001050 if [ "$WITH_RADIUS" == "yes" ]; then
David Bainbridge696bc632020-04-05 21:49:37 -07001051 PODS+=" radius.*"
1052 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001053 if [ "$WITH_BBSIM" == "yes" ]; then
David Bainbridge76afd812020-04-06 09:53:52 -07001054 SIM_PODS+=" bbsim.*"
David Bainbridge696bc632020-04-05 21:49:37 -07001055 fi
divyadesai59f987a2020-05-27 12:11:33 +00001056 if [ "$WITH_EFK" == "yes" ]; then
1057 EFK_PODS+=" kibana-* elasticsearch-* fluentd-*"
1058 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001059 if [ "$WITH_OPEN_ADAPTERS" ] || [ "$WITH_SIM_ADAPTERS" ]; then
David Bainbridge76afd812020-04-06 09:53:52 -07001060 ADAPT_PODS+=" adapter-*"
David Bainbridge696bc632020-04-05 21:49:37 -07001061 fi
David Bainbridge60ffc0f2020-04-27 22:13:22 -07001062 if is_in "$WITH_ONOS" "yes,legacy,classic"; then
David Bainbridge76afd812020-04-06 09:53:52 -07001063 INFRA_PODS+=" onos-.*"
1064 fi
David Bainbridgec7220622020-05-28 12:31:47 -07001065 if is_in "$WITH_ETCD" "yes,external"; then
1066 INFRA_PODS+=" etcd.*"
David Bainbridge76afd812020-04-06 09:53:52 -07001067 fi
David Bainbridgec7220622020-05-28 12:31:47 -07001068 if is_in "$WITH_KAFKA" "yes,external"; then
David Bainbridge76afd812020-04-06 09:53:52 -07001069 INFRA_PODS+=" kafka.*"
1070 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001071 if [ -n "$SIM_PODS" ]; then
1072 wait_for_pods "$BBSIM_NS" 0 "not" "Waiting for BBSIM PODs to terminate" "$BBSIM_LABEL" "$SIM_PODS"
David Bainbridge76afd812020-04-06 09:53:52 -07001073 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001074 if [ -n "$INFRA_PODS" ]; then
1075 wait_for_pods "$INFRA_NS" 0 "not" "Waiting for infrastructure PODs to terminate" "$NO_LABEL" "$INFRA_PODS"
David Bainbridge76afd812020-04-06 09:53:52 -07001076 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001077 if [ -n "$ADAPT_PODS" ]; then
1078 wait_for_pods "$ADAPTER_NS" 0 "not" "Waiting for adapter PODs to terminate" "$NO_LABEL" "$ADAPT_PODS"
David Bainbridge76afd812020-04-06 09:53:52 -07001079 fi
divyadesai59f987a2020-05-27 12:11:33 +00001080 if [ -n "$EFK_PODS" ]; then
1081 wait_for_pods "$INFRA_NS" 0 "not" "Waiting for EFK PODs to terminate" "$NO_LABEL" "$EFK_PODS"
1082 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001083 wait_for_pods "$VOLTHA_NS" 0 "not" "Waiting for VOLTHA PODs to terminate" "$NO_LABEL" "$PODS"
David Bainbridge4f1b5562019-08-19 04:46:52 +00001084 fi
David Bainbridgeac7f8072019-08-01 22:15:33 +00001085 fi
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001086 exit
David Bainbridgeac7f8072019-08-01 22:15:33 +00001087fi
1088
1089if [ "$1" == "dump" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +00001090 LOG="dump-$NAME.log"
David Bainbridged18f4942020-04-14 16:46:13 -07001091 TS="$(date -u +"%Y%m%dT%H%M%SZ")"
1092 if [ -n "$DUMP_FROM" ]; then
1093 TS=${DUMP_FROM//[:-]}
David Bainbridge76514a02019-10-08 01:50:35 +00001094 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001095 WORK="$(mktemp -u -d)"
David Bainbridge0774b232019-08-02 06:37:19 +00001096 DATA=$WORK/voltha-debug-dump-$NAME-$TS
David Bainbridged18f4942020-04-14 16:46:13 -07001097 mkdir -p "$DATA"
1098 echo "$TS" > "$LOG"
David Bainbridge0774b232019-08-02 06:37:19 +00001099 echo -e "Capturing debug dump to voltha-debug-dump-$NAME-$TS.tgz"
David Bainbridgeac7f8072019-08-01 22:15:33 +00001100 bspin - "Copy install log"
David Bainbridged18f4942020-04-14 16:46:13 -07001101 if [ -f "install-$NAME.log" ]; then
1102 (set -x; cp "install-$NAME.log" "$DATA/install-$NAME.log") >>"$LOG" 2>&1
1103 espin - "$VERIFIED"
David Bainbridgeac7f8072019-08-01 22:15:33 +00001104 else
David Bainbridge0774b232019-08-02 06:37:19 +00001105 espin - "$NO_ENTRY Copy install log: install-$NAME.log not found"
David Bainbridgeac7f8072019-08-01 22:15:33 +00001106 fi
1107 bspin - "Dumping Kubernetes PODs"
David Bainbridged18f4942020-04-14 16:46:13 -07001108 (set -x; kubectl get --all-namespaces pods >> "$DATA/all-pods.txt" 2>&1) >>"$LOG" 2>&1
1109 espin - "$VERIFIED"
David Bainbridgeac7f8072019-08-01 22:15:33 +00001110 bspin - "Dumping Kubernetes SERVICEs"
David Bainbridged18f4942020-04-14 16:46:13 -07001111 (set -x; kubectl get --all-namespaces svc >> "$DATA/all-services.txt" 2>&1) >>"$LOG" 2>&1
1112 espin - "$VERIFIED"
David Bainbridgeac7f8072019-08-01 22:15:33 +00001113 bspin - "Dumping Kubernetes EVENTs"
David Bainbridged18f4942020-04-14 16:46:13 -07001114 (set -x; kubectl get --all-namespaces events >> "$DATA/all-events.txt" 2>&1) >>"$LOG" 2>&1
1115 espin - "$VERIFIED"
David Bainbridgeac7f8072019-08-01 22:15:33 +00001116 bspin - "Dumping VOLTHA POD details"
David Bainbridged18f4942020-04-14 16:46:13 -07001117 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 +00001118 SINCE=
David Bainbridged18f4942020-04-14 16:46:13 -07001119 if [ -n "$DUMP_FROM" ]; then
David Bainbridgecfd7ca12019-10-06 03:31:41 +00001120 SINCE="--since-time=$DUMP_FROM"
1121 fi
David Bainbridgeac7f8072019-08-01 22:15:33 +00001122 for POD in $PODS; do
David Bainbridged18f4942020-04-14 16:46:13 -07001123 NS="$(echo "$POD" | cut -d: -f1)"
1124 POD="$(echo "$POD" | cut -d: -f2)"
David Bainbridgeac7f8072019-08-01 22:15:33 +00001125 sspin - "Dumping VOLTHA POD details: $POD$CEOL"
David Bainbridged18f4942020-04-14 16:46:13 -07001126 mkdir -p "$DATA/$POD"
1127 (set -x; kubectl describe -n "$NS" "$POD" >> "$DATA/$POD/describe.txt" 2>&1) >>"$LOG" 2>&1
David Bainbridgeac7f8072019-08-01 22:15:33 +00001128 sspin - "Dumping VOLTHA POD details: $POD"
David Bainbridged18f4942020-04-14 16:46:13 -07001129 (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 +00001130 sspin - "Dumping VOLTHA POD details: $POD"
David Bainbridged18f4942020-04-14 16:46:13 -07001131 (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 +00001132 sspin - "Dumping VOLTHA POD details: $POD"
1133 done
1134 espin - "$VERIFIED Dumping VOLTHA POD details$CEOL"
1135 bspin - "Dumping ETCD"
David Bainbridged18f4942020-04-14 16:46:13 -07001136 if [ -n "$(command -v etcdctl)" ]; then
1137 (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
1138 espin - "$VERIFIED"
David Bainbridgeac7f8072019-08-01 22:15:33 +00001139 else
1140 espin - "$NO_ENTRY Dumping ETCD: etcdctl command not available"
1141 fi
David Bainbridge0774b232019-08-02 06:37:19 +00001142 bspin - "Creating compressed TAR: voltha-debug-dump-$NAME-$TS.tgz"
David Bainbridged18f4942020-04-14 16:46:13 -07001143 (set -x; tar -C "$WORK" -zcf "voltha-debug-dump-$NAME-$TS.tgz" "./voltha-debug-dump-$NAME-$TS") >>"$LOG" 2>&1
1144 espin - "$VERIFIED"
David Bainbridgeac7f8072019-08-01 22:15:33 +00001145 bspin - "Cleanup"
David Bainbridged18f4942020-04-14 16:46:13 -07001146 (set -x; rm -rf "$WORK") >>"$LOG" 2>&1
1147 espin - "$VERIFIED"
1148 bspin - "$(ls -l "voltha-debug-dump-$NAME-$TS.tgz")"
1149 espin - "$VERIFIED"
David Bainbridgeac7f8072019-08-01 22:15:33 +00001150 exit
1151fi
1152
David Bainbridge0774b232019-08-02 06:37:19 +00001153LOG="install-$NAME.log"
David Bainbridge1d2c5842020-06-03 15:29:07 -07001154PFLOG="port-forward-$NAME.log"
David Bainbridged18f4942020-04-14 16:46:13 -07001155date > "$LOG"
divyadesai59f987a2020-05-27 12:11:33 +00001156echo "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 +00001157
1158# Output install options to log
David Bainbridged18f4942020-04-14 16:46:13 -07001159echo "OPTIONS" >> "$LOG"
David Bainbridgeac7f8072019-08-01 22:15:33 +00001160for O in $ALL_OPTIONS; do
David Bainbridged18f4942020-04-14 16:46:13 -07001161 VAL="$(eval echo "\$$O")"
1162 if [ -n "$VAL" ]; then
1163 printf " %-30s = %s\n" "$O" "$VAL" >> "$LOG"
David Bainbridgeac7f8072019-08-01 22:15:33 +00001164 fi
1165done
1166
David Bainbridgee4d11ca2020-05-08 10:21:10 -07001167# Force remove any existing k8s port-forward processes. This will
1168# remove them for all kind clusters.
David Bainbridgee4d11ca2020-05-08 10:21:10 -07001169if [ "$1" == "clean" ]; then
1170 kill_port_forward __ALL__
1171 exit
1172fi
1173
David Bainbridgefad50732020-05-01 17:00:12 -07001174helm_values() {
1175 local NAMESPACE=$1; shift
1176 local INAME=$1; shift
1177 local CHART=$1; shift
1178 local CHART_VERSION=$1; shift
1179
1180 if [ "$CHART_VERSION X" != " X" ] && [ "$CHART_VERSION" != "latest" ]; then
1181 CHART_VERSION="--version $CHART_VERSION"
1182 else
1183 CHART_VERSION=
1184 fi
1185
1186 local CHART_ARGS=
1187 if [ -r "${INAME}-values.yaml" ]; then
1188 CHART_ARGS="-f ${INAME}-values.yaml"
1189 fi
1190
1191 if [ "$HELM_USE_UPGRADE" == "yes" ]; then
1192 _HELM_COMMAND="upgrade --install"
1193 _HELM_ARGS="xxxdryrunxxx"
1194 else
1195 _HELM_COMMAND="install"
1196 _HELM_ARGS="--name xxxdryrunxxx"
1197 fi
1198 CMD=("helm $_HELM_COMMAND --debug --dry-run -f $NAME-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 $CHART")
1199 ${CMD[*]} 2>/dev/null | awk 'PRINT==1 {print}; /^USER-SUPPLIED VALUES:/ {PRINT = 1}; /^$/ {PRINT = 0}'
1200}
1201
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001202helm_install() {
David Bainbridgec7220622020-05-28 12:31:47 -07001203 local INDENT NOW VALUES_FILE PPROF_ARG
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001204 if [ "$1" == "-" ]; then
1205 INDENT=$1; shift
1206 fi
1207 local NAMESPACE=$1; shift
David Bainbridge0774b232019-08-02 06:37:19 +00001208 local INAME=$1; shift
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001209 local CHART=$1; shift
David Bainbridge90fd8e32019-08-21 23:32:47 +00001210 local CHART_VERSION=$1; shift
David Bainbridgec7220622020-05-28 12:31:47 -07001211 local FILTER=$1; shift
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001212 local MESSAGE=$*
1213
David Bainbridged18f4942020-04-14 16:46:13 -07001214 if [ "$CHART_VERSION X" != " X" ] && [ "$CHART_VERSION" != "latest" ]; then
David Bainbridge90fd8e32019-08-21 23:32:47 +00001215 CHART_VERSION="--version $CHART_VERSION"
1216 else
1217 CHART_VERSION=
1218 fi
1219
David Bainbridge99ac7a22019-08-31 02:26:43 +00001220 local CHART_ARGS=
1221 if [ -r "${INAME}-values.yaml" ]; then
1222 CHART_ARGS="-f ${INAME}-values.yaml"
1223 fi
1224
David Bainbridged18f4942020-04-14 16:46:13 -07001225 local WAIT_START CMD
1226 WAIT_START="$(date +%s)"
1227 COUNT="$((300 / 15))"
1228 bspin "$INDENT" "$MESSAGE"
1229 if [ "$HELM_USE_UPGRADE" == "yes" ]; then
David Bainbridge7f8bf992020-04-08 21:53:22 -07001230 _HELM_COMMAND="upgrade --install"
1231 _HELM_ARGS="$INAME"
1232 else
1233 _HELM_COMMAND="install"
1234 _HELM_ARGS="--name $INAME"
1235 fi
David Bainbridgec7220622020-05-28 12:31:47 -07001236
1237 VALUES_FILE="$(mktemp)"
1238 if [ "$FILTER" == "-" ]; then
1239 cp "$NAME-values.yaml" "$VALUES_FILE"
David Bainbridgea965ca22020-06-09 17:45:04 -07001240 elif [ "${FILTER:0:1}" == "+" ]; then
1241 cp "$NAME-values.yaml" "$VALUES_FILE"
1242 yq r - "${FILTER:1}" <"$NAME-values.yaml" >>"$VALUES_FILE"
David Bainbridge33e56c72020-06-11 11:39:56 -07001243 cat "$VALUES_FILE" >>"$LOG"
David Bainbridgec7220622020-05-28 12:31:47 -07001244 else
David Bainbridge43f2df52020-06-02 15:30:54 -07001245 yq r - "$FILTER" <"$NAME-values.yaml" >"$VALUES_FILE"
David Bainbridgec7220622020-05-28 12:31:47 -07001246 fi
1247 if [ "$WITH_PPROF" == "yes" ]; then
1248 PPROF_ARG="--set profiler.enabled=true"
1249 fi
1250 CMD=("helm $_HELM_COMMAND -f $VALUES_FILE $CHART_ARGS $PPROF_ARG $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 $CHART")
David Bainbridged18f4942020-04-14 16:46:13 -07001251 (set -x; ${CMD[*]} >>"$LOG" 2>&1) >>"$LOG" 2>&1
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001252 SUCCESS=$?
David Bainbridged18f4942020-04-14 16:46:13 -07001253 while [ "$SUCCESS" -ne 0 ]; do
1254 NOW="$(date +%s)"
1255 if [ "$((NOW - WAIT_START))" -gt "$TIMEOUT_SECONDS" ]; then
David Bainbridge52e6e9d2020-03-23 13:48:27 -07001256 espin "$THEX"
David Bainbridgec7220622020-05-28 12:31:47 -07001257 rm -f "$VALUES_FILE"
David Bainbridge52e6e9d2020-03-23 13:48:27 -07001258 doTimeout "waiting for helm install $CHART"
1259 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001260 sspin "$INDENT"
1261 COUNT="$((COUNT - 1))"
1262 if [ "$COUNT" -eq 0 ]; then
1263 if [ "$HELM_USE_UPGRADE" == "no" ]; then
1264 (set -x; helm delete --purge "$INAME" >>"$LOG" 2>&1) >>"$LOG" 2>&1
David Bainbridge7f8bf992020-04-08 21:53:22 -07001265 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001266 (set -x; ${CMD[*]} >>"$LOG" 2>&1) >>"$LOG" 2>&1
Andy Baviere22ff252019-12-19 11:40:31 -07001267 SUCCESS=$?
David Bainbridged18f4942020-04-14 16:46:13 -07001268 COUNT="$((300 / 15))"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001269 fi
1270 sleep .15
1271 done
David Bainbridgec7220622020-05-28 12:31:47 -07001272 rm -f "$VALUES_FILE"
David Bainbridged18f4942020-04-14 16:46:13 -07001273 espin "$INDENT" "$VERIFIED"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001274}
1275
David Bainbridged18f4942020-04-14 16:46:13 -07001276echo "INSTALL TYPE: $TYPE" >> "$LOG"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001277
1278bspin "Verify GOPATH"
David Bainbridged18f4942020-04-14 16:46:13 -07001279GOPATH="$(pwd)"; export GOPATH
1280mkdir -p "$GOPATH/bin"
1281espin "$VERIFIED"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001282
David Bainbridged18f4942020-04-14 16:46:13 -07001283STIME="$(date +%s)"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001284if [ "$INSTALL_KUBECTL" == "no" ]; then
1285 bspin "Skip kubectl install"
1286 espin $NO_ENTRY
Test Userc13bdc92019-07-03 20:57:49 +00001287else
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001288 bspin "Verify kubectl $HELM"
David Bainbridged18f4942020-04-14 16:46:13 -07001289 if [ -x "$GOPATH/bin/kubectl" ]; then
1290 espin "$VERIFIED"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001291 else
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001292 ERR_OUT="$(mktemp)"
David Bainbridged18f4942020-04-14 16:46:13 -07001293 espin "$NOT_VERIFIED"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001294 bspin - "Download and install Kubernetes/kubectl $DOWNLOAD"
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001295 (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
1296 RESULT=$?
1297 if [ "$RESULT" -ne 0 ]; then
1298 espin - "$THEX"
David Bainbridgee3fc0c32020-04-21 15:34:04 -07001299 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR: unable to download kubectl: $(tail "$ERR_OUT")${NORMAL}"
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001300 cat "$ERR_OUT" >> "$LOG"
Zack Williamsded60cb2020-04-13 10:02:20 -07001301 rm -rf "$ERR_OUT" "$GOPATH/bin/kubectl"
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001302 exit 1
1303 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001304 (set -x; chmod 755 "$GOPATH/bin/kubectl" >>"$LOG" 2>&1) >>"$LOG" 2>&1
1305 espin - "$VERIFIED"
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001306 rm -rf "$ERR_OUT"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001307 fi
Test Userc13bdc92019-07-03 20:57:49 +00001308fi
David Bainbridgee87067b2019-08-12 22:00:12 +00001309if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001310 NOW="$(date +%s)"
1311 printtime $((NOW - STIME))
David Bainbridgee87067b2019-08-12 22:00:12 +00001312fi
Test Userc13bdc92019-07-03 20:57:49 +00001313
David Bainbridged18f4942020-04-14 16:46:13 -07001314STIME="$(date +%s)"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001315if [ "$DEPLOY_K8S" == "no" ]; then
1316 bspin "Skip Kubernetes/Kind Deployment"
1317 espin $NO_ENTRY
1318else
Test Userba1e7e72019-07-10 22:27:54 +00001319 bspin "Verify Kubernetes/Kind $HELM"
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -08001320 IS_INSTALLED=0
1321 OP_TYPE="install"
David Bainbridged18f4942020-04-14 16:46:13 -07001322 if [ -x "$GOPATH/bin/kind" ]; then
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -08001323 OP_TYPE="upgrade"
David Bainbridged18f4942020-04-14 16:46:13 -07001324 if [ "$("$GOPATH/bin/kind" --version | grep -c "$KIND_VERSION")" -eq 1 ]; then
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -08001325 IS_INSTALLED=1
David Bainbridged18f4942020-04-14 16:46:13 -07001326 espin "$VERIFIED"
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -08001327 fi
1328 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001329 if [ "$IS_INSTALLED" -eq 0 ]; then
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001330 ERR_OUT="$(mktemp)"
David Bainbridged18f4942020-04-14 16:46:13 -07001331 espin "$NOT_VERIFIED"
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -08001332 bspin - "Download and $OP_TYPE Kubernetes/kind $DOWNLOAD"
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001333 (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
1334 RESULT=$?
1335 if [ $RESULT -ne 0 ]; then
1336 espin - "$THEX"
David Bainbridgee3fc0c32020-04-21 15:34:04 -07001337 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR: unable to download kind: $(tail "$ERR_OUT")${NORMAL}"
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001338 cat "$ERR_OUT" >> "$LOG"
Zack Williamsded60cb2020-04-13 10:02:20 -07001339 rm -rf "$ERR_OUT" "$GOPATH/bin/kind"
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001340 exit 1
1341 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001342 (set -x; chmod 755 "$GOPATH/bin/kind" >>"$LOG" 2>&1) >>"$LOG" 2>&1
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001343 rm -rf "$ERR_OUT"
David Bainbridged18f4942020-04-14 16:46:13 -07001344 espin - "$VERIFIED"
Test Userba1e7e72019-07-10 22:27:54 +00001345 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001346fi
1347
David Bainbridgee87067b2019-08-12 22:00:12 +00001348if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001349 NOW="$(date +%s)"
1350 printtime $((NOW - STIME))
David Bainbridgee87067b2019-08-12 22:00:12 +00001351fi
1352
David Bainbridged18f4942020-04-14 16:46:13 -07001353STIME="$(date +%s)"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001354if [ "$INSTALL_HELM" == "no" ]; then
1355 bspin "Skip Helm Install"
1356 espin $NO_ENTRY
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001357else
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001358 bspin "Verify Helm $HELM"
David Bainbridgea34993d2020-04-01 09:15:42 -07001359 HELM_UPGRADE=0
1360 HELM_UPGRADE_DESC="install"
David Bainbridged18f4942020-04-14 16:46:13 -07001361 if [ -x "$GOPATH/bin/helm" ]; then
1362 HAVE_VER="$("$GOPATH/bin/helm" version -c --template '{{.Client.SemVer}}')"
1363 HELM_UP_DOWN="$(echo -e "$HAVE_VER\n$HELM_VERSION" | sort -V | head -1)"
1364 if [ "$HAVE_VER" != "$HELM_VERSION" ]; then
1365 if [ "$HELM_UP_DOWN" == "$HELM_VERSION" ]; then
David Bainbridgea34993d2020-04-01 09:15:42 -07001366 HELM_UPGRADE_DESC="downgrade"
1367 else
1368 HELM_UPGRADE_DESC="upgrade"
1369 fi
1370 HELM_UPGRADE=1
1371 else
David Bainbridged18f4942020-04-14 16:46:13 -07001372 espin "$VERIFIED"
David Bainbridgea34993d2020-04-01 09:15:42 -07001373 fi
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001374 else
David Bainbridgea34993d2020-04-01 09:15:42 -07001375 HELM_UPGRADE=1
1376 fi
1377
David Bainbridged18f4942020-04-14 16:46:13 -07001378 if [ "$HELM_UPGRADE" -ne 0 ]; then
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001379 ERR_OUT="$(mktemp)"
1380 INSTALL_HELM_BIN=$(mktemp)
David Bainbridged18f4942020-04-14 16:46:13 -07001381 espin "$NOT_VERIFIED"
David Bainbridgea34993d2020-04-01 09:15:42 -07001382 bspin - "Download and $HELM_UPGRADE_DESC Helm $DOWNLOAD"
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001383 (set -x; curl -o "$INSTALL_HELM_BIN" --fail -sSL https://git.io/get_helm.sh >>"$LOG" 2>"$ERR_OUT") >>"$LOG" 2>&1
1384 RESULT=$?
1385 if [ $RESULT -ne 0 ]; then
1386 espin - "$THEX"
David Bainbridgee3fc0c32020-04-21 15:34:04 -07001387 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR: unable to download helm installer: $(tail "$ERR_OUT")${NORMAL}"
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001388 cat "$ERR_OUT" >> "$LOG"
1389 rm -rf "$INSTALL_HELM_BIN" "$ERR_OUT" "$GOPATH/bin/helm" "$GOPATH/bin/tiller"
1390 exit 1
1391 fi
1392 rm -rf "$ERR_OUT"
1393 chmod +x "$INSTALL_HELM_BIN"
1394 (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
1395 RESULT=$?
1396 if [ $RESULT -ne 0 ]; then
1397 espin - "$THEX"
1398 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR: unable to install helm, see install log for details${NORMAL}"
1399 rm -rf "$INSTALL_HELM_BIN" "$ERR_OUT" "$GOPATH/bin/helm" "$GOPATH/bin/tiller"
1400 exit 1
1401 fi
1402 rm -rf "$INSTALL_HELM_BIN" "$ERR_OUT"
David Bainbridged18f4942020-04-14 16:46:13 -07001403 espin - "$VERIFIED"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001404 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001405fi
David Bainbridgee87067b2019-08-12 22:00:12 +00001406if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001407 NOW="$(date +%s)"
1408 printtime $((NOW - STIME))
David Bainbridgee87067b2019-08-12 22:00:12 +00001409fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001410
David Bainbridged18f4942020-04-14 16:46:13 -07001411STIME="$(date +%s)"
Test Userb5712372019-07-03 21:52:17 +00001412bspin "Verify voltctl $HIGH_VOLTAGE"
David Bainbridged2811972019-12-14 01:14:09 +00001413VOK=0
1414VMESSAGE="install"
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001415ERR_OUT=$(mktemp)
David K. Bainbridgeebf38d92020-02-10 10:46:31 -08001416export VC_VERSION="$VOLTCTL_VERSION"
1417if [ "$VC_VERSION" == "latest" ]; then
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001418 set -o pipefail # TODO: would be nice to run all in pipefail mode
1419 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')"
1420 RESULT=$?
1421 set +o pipefail
1422 if [ "$RESULT" -ne 0 ]; then
1423 espin - "$THEX"
1424 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR: unable to determine released version of voltctl: $(cat "$ERR_OUT")${NORMAL}"
1425 rm -rf "$ERR_OUT" "$GOPATH/bin/voltctl"
1426 exit 1
1427 fi
1428 export VC_VERSION
David K. Bainbridgeebf38d92020-02-10 10:46:31 -08001429fi
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001430
David Bainbridged18f4942020-04-14 16:46:13 -07001431if [ -x "$GOPATH/bin/voltctl" ]; then
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001432 VHAVE="$("$GOPATH/bin/voltctl" version --clientonly -o json 2>/dev/null | jq -r .version)"
David Bainbridged18f4942020-04-14 16:46:13 -07001433 RESULT=$?
1434 if [ $RESULT -eq 0 ] && [ "$VHAVE" == "$VC_VERSION" ]; then
David Bainbridged2811972019-12-14 01:14:09 +00001435 VOK=1
David Bainbridged18f4942020-04-14 16:46:13 -07001436 espin "$VERIFIED"
David Bainbridge1ba64f12019-12-18 00:40:13 +00001437 else
David Bainbridged18f4942020-04-14 16:46:13 -07001438 VCHECK="$(echo -e "$VHAVE\n$VC_VERSION" | sort -V | head -1)"
David K. Bainbridgeebf38d92020-02-10 10:46:31 -08001439 if [ "$VCHECK" == "$VHAVE" ]; then
1440 VMESSAGE="upgrade"
1441 else
1442 VMESSAGE="downgrade"
1443 fi
David Bainbridged2811972019-12-14 01:14:09 +00001444 fi
1445fi
1446
David Bainbridged18f4942020-04-14 16:46:13 -07001447if [ "$VOK" -eq 0 ]; then
1448 espin "$NOT_VERIFIED"
David Bainbridged2811972019-12-14 01:14:09 +00001449 bspin - "Download and $VMESSAGE voltctl $DOWNLOAD"
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001450 (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
1451 RESULT=$?
1452 if [ $RESULT -ne 0 ]; then
1453 espin - "$THEX"
1454 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR: unable to download voltctl (version $VC_VERSION): $(cat "$ERR_OUT")${NORMAL}"
1455 rm -rf "$ERR_OUT" "$GOPATH/bin/voltctl"
1456 exit 1
1457 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001458 (set -x; chmod 755 "$GOPATH/bin/voltctl" >>"$LOG" 2>&1) >>"$LOG" 2>&1
1459 espin - "$VERIFIED"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001460fi
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001461rm -rf "$ERR_OUT"
David Bainbridgee87067b2019-08-12 22:00:12 +00001462if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001463 NOW="$(date +%s)"
1464 printtime $((NOW - STIME))
David Bainbridgee87067b2019-08-12 22:00:12 +00001465fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001466
1467bspin "Verify command PATH"
Test Userba1e7e72019-07-10 22:27:54 +00001468export PATH=$GOPATH/bin:$PATH
David Bainbridged18f4942020-04-14 16:46:13 -07001469espin "$VERIFIED"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001470
David Bainbridged18f4942020-04-14 16:46:13 -07001471STIME="$(date +%s)"
Test Userba1e7e72019-07-10 22:27:54 +00001472if [ "$DEPLOY_K8S" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001473 HAVE="$(kind get clusters | grep -c "voltha-$NAME")"
Test Userba1e7e72019-07-10 22:27:54 +00001474 bspin "Verify Kubernetes/Kind Cluster"
1475 sspin
David Bainbridged18f4942020-04-14 16:46:13 -07001476 if [ "$HAVE" -eq 0 ]; then
1477 espin "$NOT_VERIFIED"
David Bainbridge491b1bd2019-07-11 17:53:11 +00001478 bspin - "Verify cluster configuration"
David Bainbridged18f4942020-04-14 16:46:13 -07001479 if [ ! -r "./$NAME-cluster.cfg" ]; then
1480 espin - "$NOT_VERIFIED"
David K. Bainbridge43422402020-03-06 07:41:22 -08001481 bspin - "Download cluster configuration: $TYPE-cluster.cfg to $NAME-cluster.cfg $DOWNLOAD"
David Bainbridged18f4942020-04-14 16:46:13 -07001482 ERR_OUT="$(mktemp)"
serkant.uluderya4d315132020-04-15 16:25:54 -07001483 if ! (set -x; curl --fail -o "./$NAME-cluster.cfg" -sSL "https://raw.githubusercontent.com/opencord/kind-voltha/$VK_RELEASE/$TYPE-cluster.cfg" >>"$LOG" 2>>"$ERR_OUT") >>"$LOG" 2>&1; then
David Bainbridged18f4942020-04-14 16:46:13 -07001484 espin - "$THEX"
1485 echo -e "${RED}${BOLD}${ERROR}ERROR: $NAME-cluster.cfg${NORMAL}${RED} - $(cat "$ERR_OUT")${NORMAL}"
1486 echo "ERROR: $(cat "$ERR_OUT")" >>"$LOG"
1487 rm -rf "$ERR_OUT" "./$NAME-cluster.cfg"
David K. Bainbridgea00736b2020-01-08 14:33:17 -08001488 exit 1
1489 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001490 rm -rf "$ERR_OUT"
David K. Bainbridgea00736b2020-01-08 14:33:17 -08001491 else
David Bainbridged18f4942020-04-14 16:46:13 -07001492 espin - "$VERIFIED"
David K. Bainbridgea00736b2020-01-08 14:33:17 -08001493 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001494 kind create cluster --name "voltha-$NAME" --config "$NAME-cluster.cfg"
David Bainbridge491b1bd2019-07-11 17:53:11 +00001495 else
David Bainbridged18f4942020-04-14 16:46:13 -07001496 espin "$VERIFIED"
Test Userba1e7e72019-07-10 22:27:54 +00001497 fi
1498
David Bainbridge1d2c5842020-06-03 15:29:07 -07001499 export KUBECONFIG="./kube-config-$NAME"
1500 kind get kubeconfig --name="voltha-$NAME" >"$KUBECONFIG"
1501 # For backward compatibility also copy to old location
David Bainbridgedee3f022020-06-05 07:45:13 -07001502 mkdir -p "$HOME/.kube"
David Bainbridge7b3c1632020-06-05 10:04:14 -07001503 cp "$KUBECONFIG" "$HOME/.kube/kind-config-voltha-$NAME"
David Bainbridge1d2c5842020-06-03 15:29:07 -07001504
Test Userba1e7e72019-07-10 22:27:54 +00001505 P="coredns-.* \
David Bainbridge0774b232019-08-02 06:37:19 +00001506 etcd-voltha-$NAME-control-plane \
Test Userba1e7e72019-07-10 22:27:54 +00001507 kindnet-.* \
David Bainbridge0774b232019-08-02 06:37:19 +00001508 kube-apiserver-voltha-$NAME-control-plane \
1509 kube-controller-manager-voltha-$NAME-control-plane \
Test Userba1e7e72019-07-10 22:27:54 +00001510 kube-proxy-.* \
David Bainbridge0774b232019-08-02 06:37:19 +00001511 kube-scheduler-voltha-$NAME-control-plane"
Test Userba1e7e72019-07-10 22:27:54 +00001512
David Bainbridged18f4942020-04-14 16:46:13 -07001513 EXPECT="$(test "$TYPE" == "minimal" && echo "12" || echo "14")"
1514 wait_for_pods - "kube-system" "$EXPECT" "includes" "Waiting for system PODs to start" "$NO_LABEL" "$P"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001515fi
David Bainbridgee87067b2019-08-12 22:00:12 +00001516if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001517 NOW="$(date +%s)"
1518 printtime $((NOW - STIME))
David Bainbridgee87067b2019-08-12 22:00:12 +00001519fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001520
David Bainbridgee4d11ca2020-05-08 10:21:10 -07001521if [ "$SCHEDULE_ON_CONTROL_NODES" == "yes" ]; then
1522 bspin "Untaint control nodes to allow scheduling $LOCK"
1523 for MNODE in $(kubectl get node --selector='node-role.kubernetes.io/master' -o json | jq -r '.items[].metadata.name'); do
1524 (set -x; kubectl taint node "$MNODE" node-role.kubernetes.io/master:NoSchedule- >>"$LOG" 2>&1) >>"$LOG" 2>&1
1525 sspin
1526 done
1527 espin "$VERIFIED"
1528fi
1529
David Bainbridged18f4942020-04-14 16:46:13 -07001530STIME="$(date +%s)"
1531COUNT="$(count_pods "kube-system" ":Running:" "$NO_LABEL" "tiller-deploy-.*")"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001532bspin "Verify Helm"
David Bainbridged18f4942020-04-14 16:46:13 -07001533if [ "$COUNT" -ne 1 ]; then
1534 espin "$NOT_VERIFIED"
Test Userb5712372019-07-03 21:52:17 +00001535 echo -e "Configuring Helm $GEAR"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001536 if [ "$INSTALL_HELM" == "no" ]; then
1537 bspin - "Skip Helm/Tiller Initialization"
1538 espin - $NO_ENTRY
1539 else
1540 bspin - "Initialize Helm"
David Bainbridged18f4942020-04-14 16:46:13 -07001541 (set -x; helm init --upgrade >>"$LOG" 2>&1) >>"$LOG" 2>&1
1542 espin - "$VERIFIED"
1543 wait_for_pods - "kube-system" 1 "includes" "Waiting for Tiller POD to start" "$NO_LABEL" "tiller-deploy-.*"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001544 fi
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001545
Test Userba1e7e72019-07-10 22:27:54 +00001546 # HACK (sort-of) - the config for tiller is about to be patched, which will
1547 # cause the tiller pod to be recreated. This can sometimes cause a timing
1548 # issue with the "wait_for_pods" call on tiller as it may incorrectly
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001549 # identify the running/ready tiller pod that is soon to be terminated as
Test Userba1e7e72019-07-10 22:27:54 +00001550 # what it is waiting for. To avoid this issue we do a clean scale down and
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001551 # scale up of the pod so the script controlls when it should be expecting
Test Userba1e7e72019-07-10 22:27:54 +00001552 # things
David Bainbridged18f4942020-04-14 16:46:13 -07001553 (set -x; kubectl -n kube-system scale deploy tiller-deploy --replicas=0 >>"$LOG" 2>&1) >>"$LOG" 2>&1
David Bainbridgeddeab482020-06-24 12:43:40 -07001554 wait_for_pods - "kube-system" 0 "not" "Waiting for Tiller POD to shutdown" "$NO_LABEL" "tiller-deploy-.*"
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001555
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001556 # Create and k8s service account so that Helm can create pods
Test Userb5712372019-07-03 21:52:17 +00001557 bspin - "Create Tiller ServiceAccount"
David Bainbridged18f4942020-04-14 16:46:13 -07001558 (set -x; kubectl create serviceaccount --namespace kube-system tiller >>"$LOG" 2>&1) >>"$LOG" 2>&1
1559 espin - "$VERIFIED"
Test Userb5712372019-07-03 21:52:17 +00001560 bspin - "Create Tiller ClusterRoleBinding"
David Bainbridged18f4942020-04-14 16:46:13 -07001561 (set -x; kubectl create clusterrolebinding tiller-cluster-rule --clusterrole=cluster-admin --serviceaccount=kube-system:tiller >>"$LOG" 2>&1) >>"$LOG" 2>&1
1562 espin - "$VERIFIED"
Test Userb5712372019-07-03 21:52:17 +00001563 bspin - "Update Tiller Manifest"
David Bainbridged18f4942020-04-14 16:46:13 -07001564 (set -x; kubectl patch deploy --namespace kube-system tiller-deploy -p '{"spec":{"template":{"spec":{"serviceAccount":"tiller"}}}}' >>"$LOG" 2>&1) >>"$LOG" 2>&1
Test Userba1e7e72019-07-10 22:27:54 +00001565
1566 # HACK (sort-of) - part to, spin it back up
David Bainbridged18f4942020-04-14 16:46:13 -07001567 (set -x; kubectl -n kube-system scale deploy tiller-deploy --replicas=1 >>"$LOG" 2>&1) >>"$LOG" 2>&1
1568 espin - "$VERIFIED"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001569else
David Bainbridged18f4942020-04-14 16:46:13 -07001570 if [ "$(helm version -s --template '{{.Server.SemVer}}')" != "$HELM_VERSION" ]; then
1571 espin "$NOT_VERIFIED"
David Bainbridgea34993d2020-04-01 09:15:42 -07001572 bspin - "Sync Tiller server version with helm client"
David Bainbridged18f4942020-04-14 16:46:13 -07001573 (set -x; helm init --upgrade --force-upgrade --wait >>"$LOG" 2>&1) >>"$LOG" 2>&1
1574 espin - "$VERIFIED"
David Bainbridgea34993d2020-04-01 09:15:42 -07001575 else
David Bainbridged18f4942020-04-14 16:46:13 -07001576 espin "$VERIFIED"
David Bainbridgea34993d2020-04-01 09:15:42 -07001577 fi
1578
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001579fi
David Bainbridged18f4942020-04-14 16:46:13 -07001580wait_for_pods - "kube-system" 1 "includes" "Waiting for Tiller POD to start" "$NO_LABEL" "tiller-deploy-.*"
David Bainbridgeddeab482020-06-24 12:43:40 -07001581
1582REPOS="onf|https://charts.opencord.org|ONF_VOLTHA \
1583 stable|https://kubernetes-charts.storage.googleapis.com|Google_Stable \
Ubuntubaab12f2020-06-30 01:08:19 +00001584 incubator|https://kubernetes-charts-incubator.storage.googleapis.com|Google_Incubator \
1585 onos|https://charts.onosproject.org|ONF_ONOS \
1586 atomix|https://charts.atomix.io|ONF_Atomix \
1587 bbsim-sadis|https://ciena.github.io/bbsim-sadis-server/charts|Custom_BBSIM_SADIS_Server \
1588 elastic|https://helm.elastic.co|Elastic \
David Bainbridgeddeab482020-06-24 12:43:40 -07001589 kiwigrid|https://kiwigrid.github.io|Fluentd-ElasticSearch"
David Bainbridgeddeab482020-06-24 12:43:40 -07001590REPO_UPDATE_REQ="no"
1591
1592bspin - "Verify Helm Repository"
1593for REPO in $REPOS; do
1594 REPO_NAME="$(echo "$REPO" | cut -d\| -f1)"
1595 REPO_URL="$(echo "$REPO" | cut -d\| -f2)"
1596 REPO_LABEL="$(echo "$REPO" | cut -d\| -f3 | sed -e 's/_/ /g')"
1597
1598 sspin - "Verify Helm Repository: $REPO_LABEL$CEOL"
1599 if [ "$(helm repo list 2>/dev/null | grep -c "$REPO_NAME" 2>/dev/null)" -eq 0 ]; then
1600 sspin - "Add Helm Repository: $REPO_LABEL$CEOL"
1601 (set -x; helm repo add "$REPO_NAME" "$REPO_URL" >>"$LOG" 2>&1) >>"$LOG" 2>&1
1602 REPO_UPDATE_REQ="yes"
1603 fi
1604done
1605sspin - "Verify Helm Repositories$CEOL"
1606espin - "$VERIFIED"
1607
1608if [ "$REPO_UPDATE_REQ" == "yes" ] || [ "$UPDATE_HELM_REPOS" == "yes" ]; then
1609 bspin - "Update Helm repository cache"
1610 (set -x; helm repo update >>"$LOG" 2>&1) >>"$LOG" 2>&1
1611 espin - "$VERIFIED"
1612fi
1613
David Bainbridgee87067b2019-08-12 22:00:12 +00001614if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001615 NOW="$(date +%s)"
1616 printtime $((NOW - STIME))
David Bainbridgee87067b2019-08-12 22:00:12 +00001617fi
David Bainbridgecf546362020-04-21 23:18:50 -07001618# Resolve chart versions and log them for debug/support
1619RESOLVED_VOLTHA_CHART_VERSION=$(resolve_chart_version "$VOLTHA_CHART" "$VOLTHA_CHART_VERSION")
1620RESOLVED_VOLTHA_BBSIM_CHART_VERSION=$(resolve_chart_version "$VOLTHA_BBSIM_CHART" "$VOLTHA_BBSIM_CHART_VERSION")
1621RESOLVED_VOLTHA_ADAPTER_SIM_CHART_VERSION=$(resolve_chart_version "$VOLTHA_ADAPTER_SIM_CHART" "$VOLTHA_ADAPTER_SIM_CHART_VERSION")
1622RESOLVED_VOLTHA_ADAPTER_OPEN_OLT_CHART_VERSION=$(resolve_chart_version "$VOLTHA_ADAPTER_OPEN_OLT_CHART" "$VOLTHA_ADAPTER_OPEN_OLT_CHART_VERSION")
1623RESOLVED_VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION=$(resolve_chart_version "$VOLTHA_ADAPTER_OPEN_ONU_CHART" "$VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION")
1624RESOLVED_ONOS_CHART_VERSION=$(resolve_chart_version "$ONOS_CHART" "$ONOS_CHART_VERSION")
David Bainbridge60ffc0f2020-04-27 22:13:22 -07001625RESOLVED_ONOS_CLASSIC_CHART_VERSION=$(resolve_chart_version "$ONOS_CLASSIC_CHART" "$ONOS_CLASSIC_CHART_VERSION")
David Bainbridgecf546362020-04-21 23:18:50 -07001626RESOLVED_KAFKA_CHART_VERSION=$(resolve_chart_version "$KAFKA_CHART" "$KAFKA_CHART_VERSION")
divyadesai59f987a2020-05-27 12:11:33 +00001627RESOLVED_ELASTICSEARCH_CHART_VERSION=$(resolve_chart_version "$ELASTICSEARCH_CHART" "$ELASTICSEARCH_CHART_VERSION")
1628RESOLVED_KIBANA_CHART_VERSION=$(resolve_chart_version "$KIBANA_CHART" "$KIBANA_CHART_VERSION")
1629RESOLVED_FLUENTD_ELASTICSEARCH_CHART_VERSION=$(resolve_chart_version "$FLUENTD_ELASTICSEARCH_CHART" "$FLUENTD_ELASTICSEARCH_CHART_VERSION")
David K. Bainbridge450c15c2020-06-29 10:12:06 -07001630RESOLVED_BBSIM_SADIS_SERVER_CHART_VERSION=$(resolve_chart_version "$BBSIM_SADIS_SERVER_CHART" "$BBSIM_SADIS_SERVER_CHART_VERSION")
1631RESOLVED_RADIUS_CHART_VERSION=$(resolve_chart_version "$RADIUS_CHART" "$RADIUS_CHART_VERSION")
David Bainbridgecf546362020-04-21 23:18:50 -07001632cat <<EOV >>"$LOG"
1633Resolved helm charts and versions:
1634 $VOLTHA_CHART:$RESOLVED_VOLTHA_CHART_VERSION
1635 $VOLTHA_BBSIM_CHART:$RESOLVED_VOLTHA_BBSIM_CHART_VERSION
1636 $VOLTHA_ADAPTER_SIM_CHART:$RESOLVED_VOLTHA_ADAPTER_SIM_CHART_VERSION
1637 $VOLTHA_ADAPTER_OPEN_OLT_CHART:$RESOLVED_VOLTHA_ADAPTER_OPEN_OLT_CHART_VERSION
1638 $VOLTHA_ADAPTER_OPEN_ONU_CHART:$RESOLVED_VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION
1639 $ONOS_CHART:$RESOLVED_ONOS_CHART_VERSION
David Bainbridge60ffc0f2020-04-27 22:13:22 -07001640 $ONOS_CLASSIC_CHART:$RESOLVED_ONOS_CLASSIC_CHART_VERSION
David Bainbridgecf546362020-04-21 23:18:50 -07001641 $KAFKA_CHART:$RESOLVED_KAFKA_CHART_VERSION
divyadesai59f987a2020-05-27 12:11:33 +00001642 $ELASTICSEARCH_CHART:$RESOLVED_ELASTICSEARCH_CHART_VERSION
1643 $KIBANA_CHART:$RESOLVED_KIBANA_CHART_VERSION
1644 $FLUENTD_ELASTICSEARCH_CHART:$RESOLVED_FLUENTD_ELASTICSEARCH_CHART_VERSION
David K. Bainbridge450c15c2020-06-29 10:12:06 -07001645 $BBSIM_SADIS_SERVER_CHART:$RESOLVED_BBSIM_SADIS_SERVER_CHART_VERSION
1646 $RADIUS_CHART:$RESOLVED_RADIUS_CHART_VERSION
David Bainbridgecf546362020-04-21 23:18:50 -07001647EOV
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001648
David Bainbridged18f4942020-04-14 16:46:13 -07001649STIME="$(date +%s)"
David Bainbridge0774b232019-08-02 06:37:19 +00001650bspin "Verify Helm values file: $NAME-values.yaml"
1651if [ ! -r "./$NAME-values.yaml" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001652 espin "$NOT_VERIFIED"
David Bainbridge0774b232019-08-02 06:37:19 +00001653 bspin - "Download Helm values file: $TYPE-values.yaml to $NAME-values.yaml $DOWNLOAD"
David Bainbridged18f4942020-04-14 16:46:13 -07001654 ERR_OUT="$(mktemp)"
serkant.uluderya4d315132020-04-15 16:25:54 -07001655 if ! (set -x; curl --fail -o "./$NAME-values.yaml" -sSL "https://raw.githubusercontent.com/opencord/kind-voltha/$VK_RELEASE/$TYPE-values.yaml" >>"$LOG" 2>"$ERR_OUT") >>"$LOG" 2>&1; then
David Bainbridged18f4942020-04-14 16:46:13 -07001656 espin - "$THEX"
1657 echo -e "${RED}${BOLD}${ERROR}ERROR: $NAME-values.yaml${NORMAL}${RED} - $(cat "$ERR_OUT")${NORMAL}"
1658 echo "ERROR: $(cat "$ERR_OUT")" >>"$LOG"
1659 rm -rf "$ERR_OUT" "./$NAME-values.yaml"
David K. Bainbridgea00736b2020-01-08 14:33:17 -08001660 exit 1
1661 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001662 rm -rf "$ERR_OUT"
1663 espin - "$VERIFIED"
Test Userba1e7e72019-07-10 22:27:54 +00001664else
David Bainbridged18f4942020-04-14 16:46:13 -07001665 espin "$VERIFIED"
Test Userba1e7e72019-07-10 22:27:54 +00001666fi
David Bainbridgee87067b2019-08-12 22:00:12 +00001667if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001668 NOW="$(date +%s)"
1669 printtime $((NOW - STIME))
David Bainbridgee87067b2019-08-12 22:00:12 +00001670fi
Test Userba1e7e72019-07-10 22:27:54 +00001671
David Bainbridged18f4942020-04-14 16:46:13 -07001672STIME="$(date +%s)"
David Bainbridge99ac7a22019-08-31 02:26:43 +00001673bspin "Verify or download chart specific values files $DOWNLOAD"
1674VALUES_FILES="monkey-values.yaml"
David Bainbridged18f4942020-04-14 16:46:13 -07001675ERR_OUT="$(mktemp)"
David Bainbridge99ac7a22019-08-31 02:26:43 +00001676for i in $VALUES_FILES; do
1677 if [ ! -r ./$i ]; then
serkant.uluderya4d315132020-04-15 16:25:54 -07001678 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 -07001679 espin "$THEX"
1680 echo -e "${RED}${BOLD}${ERROR}ERROR: $i${NORMAL}${RED} - $(cat "$ERR_OUT")${NORMAL}"
1681 echo "ERROR: $i - $(cat "$ERR_OUT")" >>"$LOG"
1682 rm -rf "$ERR_OUT" "./$i"
David K. Bainbridgea00736b2020-01-08 14:33:17 -08001683 exit 1