blob: ba85f845c5c17a9c438653ba453783a200c347c3 [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
17TOTAL_START_TIME="$(date +%s)"
David K. Bainbridgeb7285432019-07-02 22:05:24 -070018
David Bainbridge38dc1e82019-08-12 15:18:45 +000019FANCY=${FANCY:-1}
20if [ "$TERM X" == " X" ]; then
21 FANCY=0
22fi
23
David K. Bainbridgeb7285432019-07-02 22:05:24 -070024# trap ctrl-c and call ctrl_c()
25trap ctrl_c INT
26
27function ctrl_c() {
David Bainbridged18f4942020-04-14 16:46:13 -070028 echo -en "$CNORM"
David K. Bainbridgeb7285432019-07-02 22:05:24 -070029 echo ""
30 echo "ctrl-c trapped"
David Bainbridgec6a6eb62019-10-18 22:50:07 +000031 echo "Thank you for trying 'voltha up'"
David K. Bainbridgeb7285432019-07-02 22:05:24 -070032 exit
33}
34
David Bainbridgea34993d2020-04-01 09:15:42 -070035HELM_VERSION=${HELM_VERSION:-v2.14.3}
David K. Bainbridgeebf38d92020-02-10 10:46:31 -080036VOLTCTL_VERSION=${VOLTCTL_VERSION:-latest}
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -080037KIND_VERSION=${KIND_VERSION:-v0.5.1}
David K. Bainbridgeb3a99372020-01-08 14:39:06 -080038VK_RELEASE=${VK_RELEASE:-master}
Test User08ebbd92019-07-03 17:15:39 +000039
David Bainbridge38dc1e82019-08-12 15:18:45 +000040RED=
41GREEN=
42YELLOW=
43BLUE=
David Bainbridge38dc1e82019-08-12 15:18:45 +000044BOLD=
45NORMAL=
46ERROR=
47CEOL=
48CNORM=
49CIVIS=
David Bainbridged18f4942020-04-14 16:46:13 -070050if [ "$FANCY" -eq 1 ]; then
51 RED="$(tput setaf 1)"
52 GREEN="$(tput setaf 2)"
53 YELLOW="$(tput setaf 3)"
54 BLUE="$(tput setaf 4)"
55 BOLD="$(tput bold)"
56 NORMAL="$(tput sgr0)"
David Bainbridge38dc1e82019-08-12 15:18:45 +000057 ERROR="\xe2\x9c\x97\x20"
David Bainbridged18f4942020-04-14 16:46:13 -070058 CEOL="$(tput el)"
59 CNORM="$(tput cnorm)"
60 CIVIS="$(tput civis)"
David Bainbridge38dc1e82019-08-12 15:18:45 +000061fi
Test User7d866122019-07-09 17:52:35 +000062
Test User3d7ad8e2019-07-03 06:15:44 +000063TYPE=${TYPE:-minimal}
David Bainbridge0774b232019-08-02 06:37:19 +000064NAME=${NAME:-$TYPE}
David K. Bainbridge484d80c2020-03-05 21:44:34 -080065
66ENABLE_ONOS_EXTRANEOUS_RULES=${ENABLE_ONOS_EXTRANEOUS_RULES:-no}
David Bainbridge76afd812020-04-06 09:53:52 -070067INFRA_NS=${INFRA_NS:-default}
68VOLTHA_NS=${VOLTHA_NS:-voltha}
69BBSIM_NS=${BBSIM_NS:-voltha}
70ADAPTER_NS=${ADAPTER_NS:-voltha}
David Bainbridgee87067b2019-08-12 22:00:12 +000071WITH_TIMINGS=${WITH_TIMINGS:-no}
Test User7d866122019-07-09 17:52:35 +000072WITH_BBSIM=${WITH_BBSIM:-no}
David Bainbridge5b7b96b2019-07-25 20:29:13 +000073WITH_RADIUS=${WITH_RADIUS:-no}
Matteo Scandolo78dfee02020-02-13 16:18:03 -080074WITH_EAPOL=${WITH_EAPOL:-yes}
75WITH_DHCP=${WITH_DHCP:-yes}
76WITH_IGMP=${WITH_IGMP:-no}
David Bainbridgeb270c202019-07-26 01:44:42 +000077WITH_ONOS=${WITH_ONOS:-yes}
David Bainbridge99ac7a22019-08-31 02:26:43 +000078WITH_CHAOS=${WITH_CHAOS:-no}
David Bainbridge46505fb2019-10-01 21:13:20 +000079WITH_ADAPTERS=${WITH_ADAPTERS:-yes}
David K. Bainbridgeda33d652020-03-06 10:31:23 -080080WITH_SIM_ADAPTERS=${WITH_SIM_ADAPTERS:-no}
David Bainbridge46505fb2019-10-01 21:13:20 +000081WITH_OPEN_ADAPTERS=${WITH_OPEN_ADAPTERS:-yes}
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -080082WITH_PORT_FORWARDS=${WITH_PORT_FORWARDS:-yes}
David Bainbridge696bc632020-04-05 21:49:37 -070083WITH_KAFKA=${WITH_KAFKA:-yes}
84WITH_ETCD=${WITH_ETCD:-yes}
David Bainbridge05cd8822019-11-19 17:43:53 +000085ONLY_ONE=${ONLY_ONE:-yes}
David K. Bainbridgeb859e912020-03-13 14:07:52 -070086CONFIG_SADIS=${CONFIG_SADIS:-no} # yes | no | file | bbsim | URL
David Bainbridge76afd812020-04-06 09:53:52 -070087SADIS_SUBSCRIBERS=${SADIS_SUBSCRIBERS:-http://bbsim.$VOLTHA_NS.svc:50074/v2/subscribers/%s}
88SADIS_BANDWIDTH_PROFILES=${SADIS_BANDWIDTH_PROFILES:-http://bbsim.$VOLTHA_NS.svc:50074/v2/bandwidthprofiles/%s}
Hardik Windlassb3147602020-03-09 16:59:15 +053089SADIS_CFG=${SADIS_CFG:-onos-files/onos-sadis-sample.json}
David Bainbridge27790d62019-08-13 22:43:19 +000090INSTALL_ONOS_APPS=${INSTALL_ONOS_APPS:-no}
Test Userba1e7e72019-07-10 22:27:54 +000091JUST_K8S=${JUST_K8S:-no}
92DEPLOY_K8S=${DEPLOY_K8S:-yes}
David K. Bainbridge0e89cb92019-07-17 11:30:10 -070093INSTALL_KUBECTL=${INSTALL_KUBECTL:-yes}
94INSTALL_HELM=${INSTALL_HELM:-yes}
David Bainbridge7f8bf992020-04-08 21:53:22 -070095HELM_USE_UPGRADE=${HELM_USE_UPGRADE:-no}
David Bainbridge46505fb2019-10-01 21:13:20 +000096UPDATE_HELM_REPOS=${UPDATE_HELM_REPOS:-yes}
Matteo Scandolofab98622020-01-28 15:17:20 -080097WAIT_ON_DOWN=${WAIT_ON_DOWN:-yes}
David Bainbridge52e6e9d2020-03-23 13:48:27 -070098WAIT_TIMEOUT=${WAIT_TIMEOUT:-30m}
99VOLTHA_DOWN_ON_TIMEOUT=${VOLTHA_DOWN_ON_TIMEOUT:-no}
David Bainbridge5b7b96b2019-07-25 20:29:13 +0000100VOLTHA_LOG_LEVEL=${VOLTHA_LOG_LEVEL:-WARN}
David Bainbridge90fd8e32019-08-21 23:32:47 +0000101VOLTHA_CHART=${VOLTHA_CHART:-onf/voltha}
102VOLTHA_CHART_VERSION=${VOLTHA_CHART_VERSION:-latest}
103VOLTHA_BBSIM_CHART=${VOLTHA_BBSIM_CHART:-onf/bbsim}
Matteo Scandolodcd29f52019-10-07 15:42:42 -0700104VOLTHA_BBSIM_CHART_VERSION=${VOLTHA_BBSIM_CHART_VERSION:-latest}
David Bainbridgee10f6d52019-07-25 00:28:13 +0000105VOLTHA_ADAPTER_SIM_CHART=${VOLTHA_ADAPTER_SIM_CHART:-onf/voltha-adapter-simulated}
David Bainbridge90fd8e32019-08-21 23:32:47 +0000106VOLTHA_ADAPTER_SIM_CHART_VERSION=${VOLTHA_ADAPTER_SIM_CHART_VERSION:-latest}
David Bainbridgee10f6d52019-07-25 00:28:13 +0000107VOLTHA_ADAPTER_OPEN_OLT_CHART=${VOLTHA_ADAPTER_OPEN_OLT_CHART:-onf/voltha-adapter-openolt}
David Bainbridge90fd8e32019-08-21 23:32:47 +0000108VOLTHA_ADAPTER_OPEN_OLT_CHART_VERSION=${VOLTHA_ADAPTER_OPEN_OLT_CHART_VERSION:-latest}
David Bainbridgee10f6d52019-07-25 00:28:13 +0000109VOLTHA_ADAPTER_OPEN_ONU_CHART=${VOLTHA_ADAPTER_OPEN_ONU_CHART:-onf/voltha-adapter-openonu}
David Bainbridge90fd8e32019-08-21 23:32:47 +0000110VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION=${VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION:-latest}
David K. Bainbridgeda33d652020-03-06 10:31:23 -0800111ONOS_CHART=${ONOS_CHART:-onf/onos}
Andrea Campanella21323292019-12-18 11:44:19 -0800112ONOS_CHART_VERSION=${ONOS_CHART_VERSION:-latest}
David Bainbridge2eaf2cf2020-03-18 12:54:08 -0700113EXTRA_HELM_INSTALL_ARGS=${EXTRA_HELM_INSTALL_ARGS:-}
114INTERNAL_EXTRA_HELM_INSTALL_ARGS=
uottrembb16d3982020-02-28 08:34:36 +0100115NUM_OF_BBSIM=${NUM_OF_BBSIM:-1}
Matteo Scandolo67335f02020-04-09 11:19:53 -0700116NUM_OF_OPENONU=${NUM_OF_OPENONU:-1}
uottrembb16d3982020-02-28 08:34:36 +0100117MAX_NUM_OF_BBSIM=10
Matteo Scandolo67335f02020-04-09 11:19:53 -0700118MAX_NUM_OF_OPENONU=10
Test Userba1e7e72019-07-10 22:27:54 +0000119
David Bainbridged18f4942020-04-14 16:46:13 -0700120HOSTOS="$(uname -s | tr "[:upper:]" "[:lower:"])"
121HOSTARCH="$(uname -m | tr "[:upper:]" "[:lower:"])"
122if [ "$HOSTARCH" == "x86_64" ]; then
Test Userba1e7e72019-07-10 22:27:54 +0000123 HOSTARCH="amd64"
124fi
David Bainbridge7db44002020-04-09 12:54:29 -0700125BBSIM_LABEL="-l app=bbsim"
David Bainbridged18f4942020-04-14 16:46:13 -0700126NO_LABEL=
Test User7d866122019-07-09 17:52:35 +0000127
uottrembb16d3982020-02-28 08:34:36 +0100128# check number (range) of bbsim, max bbsim must not exceed 10 instances!
129# note: instances will be numbered from 0 to 9
130if [ "$1" == "up" ]; then
David K. Bainbridge43422402020-03-06 07:41:22 -0800131 if [ "$NUM_OF_BBSIM" -lt 1 ]; then
Matteo Scandolo67335f02020-04-09 11:19:53 -0700132 >&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 -0800133 exit 1
134 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700135 if [ "$NUM_OF_BBSIM" -gt "$MAX_NUM_OF_BBSIM" ]; then
Matteo Scandolo67335f02020-04-09 11:19:53 -0700136 >&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}"
137 exit 1
138 fi
139
140 if [ "$NUM_OF_OPENONU" -lt 1 ]; then
141 >&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}"
142 exit 1
143 fi
144 if [ "$NUM_OF_OPENONU" -gt "$MAX_NUM_OF_OPENONU" ]; then
145 >&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 -0800146 exit 1
147 fi
uottrembb16d3982020-02-28 08:34:36 +0100148fi
Test User7d866122019-07-09 17:52:35 +0000149# Verify TYPE setting
David Bainbridged18f4942020-04-14 16:46:13 -0700150if [ "$(echo ":minimal:full:" | grep -ic ":$TYPE:")" -eq 0 ]; then
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700151 >&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 +0000152 exit 1
153fi
154
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700155function parseDuration() {
David Bainbridged18f4942020-04-14 16:46:13 -0700156 local DUR RESULT TERM TERMS VALUE UNIT
157 DUR=$1
158 RESULT=0
159 TERMS="$(echo "$DUR" | sed -Ee 's/([sSmMhHdD])/\1 /g' -e 's/,$//g')"
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700160 for TERM in $TERMS; do
David Bainbridged18f4942020-04-14 16:46:13 -0700161 VALUE="$(echo "$TERM" | sed -Ee 's/([0-9]+)[sSmMhHdD]/\1/')"
162 UNIT="$(echo "$TERM" | sed -Ee 's/[0-9]+([sSmMhHdD])/\1/')"
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700163 case $UNIT in
164 s|S)
David Bainbridged18f4942020-04-14 16:46:13 -0700165 RESULT=$((RESULT + VALUE)) ;;
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700166 m|M)
David Bainbridged18f4942020-04-14 16:46:13 -0700167 RESULT=$((RESULT + (VALUE * 60))) ;;
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700168 h|H)
David Bainbridged18f4942020-04-14 16:46:13 -0700169 RESULT=$((RESULT + (VALUE * 3600))) ;;
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700170 d|D)
David Bainbridged18f4942020-04-14 16:46:13 -0700171 RESULT=$((RESULT + (VALUE * 86400))) ;;
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700172 *) ;;
173 esac
174 done
175 echo $RESULT
176}
177
178function doTimeout() {
179 local MSG=$1
180 2>&1 echo -e "\n${RED}${BOLD}${ERROR}TIMEOUT:${NORMAL}${RED} Operation timed out after '$WAIT_TIMEOUT': $MSG"
181 exit 125
182}
183
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -0800184function get_service_ep() {
185 local NS=$1
186 local NAME=$2
David Bainbridged18f4942020-04-14 16:46:13 -0700187 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 -0800188}
189
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000190# Used to verify configuration values are set to "yes" or "no" value or convert
191# equivalents to "yes" or "no"
192function verify_yes_no() {
David Bainbridged18f4942020-04-14 16:46:13 -0700193 local VAR VAL
194 VAR=$1
195 VAL="$(eval echo "\$$VAR")"
196 if [ "$(echo ":y:yes:true:n:no:false:1:0:" | grep -ic ":$VAL:")" -eq 0 ]; then
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000197 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} Invalid '$VAR' value of '$VAL'. Should be 'yes' or 'no'${NORMAL}"
198 echo "INVALID"
199 return 1
200 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700201 if [ "$(echo ":y:yes:true:1:" | grep -ic ":$VAL:")" -eq 1 ]; then
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000202 echo "yes"
203 else
204 echo "no"
205 fi
206 return 0
207}
Test User7d866122019-07-09 17:52:35 +0000208
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000209ALL_YES_NO="\
David K. Bainbridge484d80c2020-03-05 21:44:34 -0800210 ENABLE_ONOS_EXTRANEOUS_RULES \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000211 WITH_TIMINGS \
212 WITH_BBSIM \
Matteo Scandolo78dfee02020-02-13 16:18:03 -0800213 WITH_EAPOL \
214 WITH_DHCP \
215 WITH_IGMP \
David Bainbridge99ac7a22019-08-31 02:26:43 +0000216 WITH_CHAOS \
David Bainbridge46505fb2019-10-01 21:13:20 +0000217 WITH_ADAPTERS \
218 WITH_SIM_ADAPTERS \
219 WITH_OPEN_ADAPTERS \
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -0800220 WITH_PORT_FORWARDS \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000221 JUST_K8S \
222 DEPLOY_K8S \
223 INSTALL_ONOS_APPS \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000224 INSTALL_KUBECTL \
225 INSTALL_HELM \
David Bainbridge7f8bf992020-04-08 21:53:22 -0700226 HELM_USE_UPGRADE \
David Bainbridge46505fb2019-10-01 21:13:20 +0000227 UPDATE_HELM_REPOS \
David Bainbridge4f1b5562019-08-19 04:46:52 +0000228 WAIT_ON_DOWN \
David Bainbridge70c0ea82019-11-14 23:25:26 +0000229 ONLY_ONE \
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700230 VOLTHA_DOWN_ON_TIMEOUT \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000231 "
David Bainbridge5b7b96b2019-07-25 20:29:13 +0000232
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000233ALL_OPTIONS="\
234 NAME \
235 TYPE \
236 $ALL_YES_NO \
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700237 WAIT_TIMEOUT \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000238 VOLTHA_LOG_LEVEL \
239 VOLTHA_CHART \
David Bainbridge90fd8e32019-08-21 23:32:47 +0000240 VOLTHA_CHART_VERSION \
241 VOLTHA_BBSIM_CHART \
242 VOLTHA_BBSIM_CHART_VERSION \
uottrembd5a20572020-03-06 09:15:01 +0100243 NUM_OF_BBSIM \
Matteo Scandolo67335f02020-04-09 11:19:53 -0700244 NUM_OF_OPENONU \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000245 VOLTHA_ADAPTER_SIM_CHART \
David Bainbridge90fd8e32019-08-21 23:32:47 +0000246 VOLTHA_ADAPTER_SIM_CHART_VERSION \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000247 VOLTHA_ADAPTER_OPEN_OLT_CHART \
David Bainbridge90fd8e32019-08-21 23:32:47 +0000248 VOLTHA_ADAPTER_OPEN_OLT_CHART_VERSION \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000249 VOLTHA_ADAPTER_OPEN_ONU_CHART \
David Bainbridge90fd8e32019-08-21 23:32:47 +0000250 VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION \
David K. Bainbridgeda33d652020-03-06 10:31:23 -0800251 ONOS_CHART \
Andrea Campanella21323292019-12-18 11:44:19 -0800252 ONOS_CHART_VERSION \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000253 ONOS_API_PORT \
254 ONOS_SSH_PORT \
David K. Bainbridgeb859e912020-03-13 14:07:52 -0700255 CONFIG_SADIS \
Hardik Windlassb3147602020-03-09 16:59:15 +0530256 SADIS_CFG \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000257 VOLTHA_API_PORT \
258 VOLTHA_SSH_PORT \
259 VOLTHA_ETCD_PORT \
David K. Bainbridge00ecd382020-02-28 12:31:58 -0800260 VOLTHA_KAFKA_PORT \
David K. Bainbridge8f7f30b2020-01-08 13:06:16 -0800261 VK_RELEASE \
262 KIND_VERSION \
263 VOLTCTL_VERSION \
David Bainbridgea34993d2020-04-01 09:15:42 -0700264 HELM_VERSION \
David Bainbridge696bc632020-04-05 21:49:37 -0700265 WITH_RADIUS \
266 WITH_KAFKA \
267 WITH_ETCD \
David Bainbridge76afd812020-04-06 09:53:52 -0700268 WITH_ONOS \
David Bainbridge6ca40102020-04-08 11:30:40 -0700269 VOLTHA_NS \
270 ADAPTER_NS \
271 INFRA_NS \
272 BBSIM_NS \
David Bainbridge7db44002020-04-09 12:54:29 -0700273 SADIS_BANDWIDTH_PROFILES \
274 SADIS_SUBSCRIBERS \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000275 "
David Bainbridge01294952019-07-30 19:33:45 +0000276
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000277# Iterate over yes/no configuration options and validate
278for VAR in $ALL_YES_NO; do
David Bainbridged18f4942020-04-14 16:46:13 -0700279 eval "$VAR"="$(verify_yes_no "$VAR")"
280 if [ "$(eval echo "\$$VAR")" == "INVALID" ]; then
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000281 exit 1;
282 fi
283done
David Bainbridgeb270c202019-07-26 01:44:42 +0000284
David Bainbridge15f6f232020-03-30 09:15:43 -0700285# Special case for CONFIG_SADIS
David Bainbridged18f4942020-04-14 16:46:13 -0700286if [ "$(echo ":y:yes:true:1:" | grep -ic ":$CONFIG_SADIS:")" -eq 1 ]; then
David Bainbridge15f6f232020-03-30 09:15:43 -0700287 CONFIG_SADIS="yes"
288fi
David Bainbridged18f4942020-04-14 16:46:13 -0700289if [ "$(echo ":n:no:false:0:" | grep -ic ":$CONFIG_SADIS:")" -eq 1 ]; then
David Bainbridge15f6f232020-03-30 09:15:43 -0700290 CONFIG_SADIS="no"
291fi
292
David Bainbridge76afd812020-04-06 09:53:52 -0700293# Special case for WITH_ONOS, WITH_RADIUS, WITH_KAFKA, and WITH_ETCD
David Bainbridged18f4942020-04-14 16:46:13 -0700294if [ "$(echo ":y:yes:true:1:" | grep -ic ":$WITH_KAFKA:")" -eq 1 ]; then
David Bainbridge696bc632020-04-05 21:49:37 -0700295 WITH_KAFKA="yes"
296fi
David Bainbridged18f4942020-04-14 16:46:13 -0700297if [ "$(echo ":n:no:false:0:" | grep -ic ":$WITH_KAFKA:")" -eq 1 ]; then
David Bainbridge696bc632020-04-05 21:49:37 -0700298 WITH_KAFKA="no"
299fi
David Bainbridged18f4942020-04-14 16:46:13 -0700300if [ "$(echo ":external:" | grep -ic ":$WITH_KAFKA:")" -eq 1 ]; then
David Bainbridge76afd812020-04-06 09:53:52 -0700301 WITH_KAFKA="external"
302fi
David Bainbridged18f4942020-04-14 16:46:13 -0700303if [ "$(echo ":y:yes:true:1:" | grep -ic ":$WITH_ETCD:")" -eq 1 ]; then
David Bainbridge696bc632020-04-05 21:49:37 -0700304 WITH_ETCD="yes"
305fi
David Bainbridged18f4942020-04-14 16:46:13 -0700306if [ "$(echo ":n:no:false:0:" | grep -ic ":$WITH_ETCD:")" -eq 1 ]; then
David Bainbridge696bc632020-04-05 21:49:37 -0700307 WITH_ETCD="no"
308fi
David Bainbridged18f4942020-04-14 16:46:13 -0700309if [ "$(echo ":external:" | grep -ic ":$WITH_ETCD:")" -eq 1 ]; then
David Bainbridge76afd812020-04-06 09:53:52 -0700310 WITH_ETCD="external"
311fi
David Bainbridged18f4942020-04-14 16:46:13 -0700312if [ "$(echo ":y:yes:true:1:" | grep -ic ":$WITH_RADIUS:")" -eq 1 ]; then
David Bainbridge29c31cb2020-04-06 09:45:50 -0700313 WITH_RADIUS="yes"
314fi
David Bainbridged18f4942020-04-14 16:46:13 -0700315if [ "$(echo ":n:no:false:0:" | grep -ic ":$WITH_RADIUS:")" -eq 1 ]; then
David Bainbridge29c31cb2020-04-06 09:45:50 -0700316 WITH_RADIUS="no"
317fi
David Bainbridged18f4942020-04-14 16:46:13 -0700318if [ "$(echo ":y:yes:true:1:" | grep -ic ":$WITH_ONOS:")" -eq 1 ]; then
David Bainbridge76afd812020-04-06 09:53:52 -0700319 WITH_ONOS="yes"
320fi
David Bainbridged18f4942020-04-14 16:46:13 -0700321if [ "$(echo ":n:no:false:0:" | grep -ic ":$WITH_ONOS:")" -eq 1 ]; then
David Bainbridge76afd812020-04-06 09:53:52 -0700322 WITH_ONOS="no"
323fi
David Bainbridge696bc632020-04-05 21:49:37 -0700324
David Bainbridged18f4942020-04-14 16:46:13 -0700325if [ "$HELM_USE_UPGRADE" == "yes" ]; then
David Bainbridge7f8bf992020-04-08 21:53:22 -0700326 _HELM_DESC="Upgrade/Install"
327else
328 _HELM_DESC="Install"
329fi
330
David Bainbridged18f4942020-04-14 16:46:13 -0700331ETCD_PREFIX=
332KAFKA_PREFIX=
333if [ "$WITH_ETCD" == "yes" ]; then
334 ETCD_PREFIX="voltha-"
335fi
336if [ "$WITH_KAFKA" == "yes" ]; then
337 KAFKA_PREFIX="voltha-"
338fi
339
David K. Bainbridgeda33d652020-03-06 10:31:23 -0800340# Check for prerequiste tools
David K. Bainbridge726ff6a2020-03-06 11:09:50 -0800341TOOLS="curl sed jq"
David Bainbridged18f4942020-04-14 16:46:13 -0700342if [ "$DEPLOY_K8S" == "yes" ]; then
David K. Bainbridgeda33d652020-03-06 10:31:23 -0800343 TOOLS+=" docker"
344fi
345NOT_FOUND=""
346for T in $TOOLS; do
David Bainbridged18f4942020-04-14 16:46:13 -0700347 if [ -z "$(command -v "$T")" ]; then
David K. Bainbridgeda33d652020-03-06 10:31:23 -0800348 NOT_FOUND+=" $T"
349 fi
350done
351
David Bainbridged18f4942020-04-14 16:46:13 -0700352if [ -n "$NOT_FOUND" ]; then
David K. Bainbridgeda33d652020-03-06 10:31:23 -0800353 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} The following required tools where not found, please install them:$NOT_FOUND"
354 exit 1
355fi
356
David Bainbridged18f4942020-04-14 16:46:13 -0700357TIMEOUT_SECONDS="$(parseDuration "$WAIT_TIMEOUT")"
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700358
David Bainbridge0774b232019-08-02 06:37:19 +0000359mkdir -p .voltha
360touch .voltha/ports
David Bainbridged18f4942020-04-14 16:46:13 -0700361HAVE="$(grep "$NAME" .voltha/ports)"
David Bainbridge0774b232019-08-02 06:37:19 +0000362if [ "$HAVE X" == " X" ]; then
363 # Find free port prefix
364 START=81
365 while true; do
David Bainbridged18f4942020-04-14 16:46:13 -0700366 if [ "$(grep -c $START .voltha/ports)" -eq 0 ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000367 break
368 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700369 START="$((START + 1))"
David Bainbridge0774b232019-08-02 06:37:19 +0000370 done
David Bainbridged18f4942020-04-14 16:46:13 -0700371 DELTA="$((START - 81))"
David Bainbridgea2595422019-10-22 03:54:28 +0000372 ONOS_API_PORT=${ONOS_API_PORT:-${START}81}
373 ONOS_SSH_PORT=${ONOS_SSH_PORT:-${START}01}
David Bainbridged18f4942020-04-14 16:46:13 -0700374 VOLTHA_API_PORT=${VOLTHA_API_PORT:-5$((55 + DELTA))55}
375 VOLTHA_SSH_PORT=${VOLTHA_SSH_PORT:-$((50 + DELTA))22}
376 VOLTHA_ETCD_PORT=${VOLTHA_ETCD_PORT:-$((23 + DELTA))79}
377 VOLTHA_KAFKA_PORT=${VOLTHA_KAFKA_PORT:-$((90 + DELTA))92}
Test User01ed0642019-07-03 20:17:06 +0000378else
David Bainbridged18f4942020-04-14 16:46:13 -0700379 VALUES="$(echo "$HAVE" | sed -e 's/\s//g' | cut -d= -f2)"
380 ONOS_API_PORT=${ONOS_API_PORT:-$(echo "$VALUES" | cut -d, -f1)}
381 ONOS_SSH_PORT=${ONOS_SSH_PORT:-$(echo "$VALUES" | cut -d, -f2)}
382 VOLTHA_API_PORT=${VOLTHA_API_PORT:-$(echo "$VALUES" | cut -d, -f3)}
383 VOLTHA_SSH_PORT=${VOLTHA_SSH_PORT:-$(echo "$VALUES" | cut -d, -f4)}
384 VOLTHA_ETCD_PORT=${VOLTHA_ETCD_PORT:-$(echo "$VALUES" | cut -d, -f5)}
385 VOLTHA_KAFKA_PORT=${VOLTHA_KAFKA_PORT:-$(echo "$VALUES" | cut -d, -f6)}
David K. Bainbridge00ecd382020-02-28 12:31:58 -0800386
David K. Bainbridge00ecd382020-02-28 12:31:58 -0800387 # A bit of a hueristic required here as the KAFKA port forward was
388 # added after the .voltha/ports files was created. Basically, if
389 # the VOLTHA_KAFKA_PORT isn't in the file then calculate the original
390 # DELTA from the VOLTHA_SSH_PORT and apply it to the VOLTHA_KAFKA_PORT
391 if [ -z "$VOLTHA_KAFKA_PORT" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -0700392 DELTA="$((VOLTHA_SSH_PORT/100-50))"
393 VOLTHA_KAFKA_PORT=${VOLTHA_KAFKA_PORT:-$((90 + DELTA))92}
David K. Bainbridge00ecd382020-02-28 12:31:58 -0800394 fi
Test User01ed0642019-07-03 20:17:06 +0000395fi
396
David Bainbridged18f4942020-04-14 16:46:13 -0700397PORTTMP="$(mktemp -u)"
398grep -v "$NAME" .voltha/ports > "$PORTTMP"
399echo "$NAME=$ONOS_API_PORT,$ONOS_SSH_PORT,$VOLTHA_API_PORT,$VOLTHA_SSH_PORT,$VOLTHA_ETCD_PORT,$VOLTHA_KAFKA_PORT" >> "$PORTTMP"
400cp "$PORTTMP" .voltha/ports
401rm -f "$PORTTMP"
David Bainbridge0774b232019-08-02 06:37:19 +0000402
David Bainbridge27790d62019-08-13 22:43:19 +0000403export ONOS_API_PORT ONOS_SSH_PORT
David Bainbridge01294952019-07-30 19:33:45 +0000404
Test Userd87942b2019-07-03 07:20:24 +0000405IDX=1
David Bainbridgee87067b2019-08-12 22:00:12 +0000406CLOCK="TIME:"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000407SPIN_PARTS=
408NOT_VERIFIED=
David Bainbridgef858a022019-08-14 21:25:11 +0000409THEX=
410BUILD=
David Bainbridge38dc1e82019-08-12 15:18:45 +0000411VERIFIED=
412HELM=
413OLD_KEY=
414BIRD=
415HIGH_VOLTAGE=
416PLUG=
David Bainbridge38dc1e82019-08-12 15:18:45 +0000417FORWARD=
David Bainbridge38dc1e82019-08-12 15:18:45 +0000418GO=
419DOWNLOAD=
420GEAR=
421NO_ENTRY=
422LOCK=
423
David Bainbridged18f4942020-04-14 16:46:13 -0700424if [ "$FANCY" -eq 1 ]; then
425 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 +0000426 CLOCK="\xe2\x8f\xb1"
David Bainbridgef858a022019-08-14 21:25:11 +0000427 THEX="${RED}${BOLD}\xe2\x9c\x97\x20${NORMAL}"
David Bainbridgef858a022019-08-14 21:25:11 +0000428 BUILD="${YELLOW}${BOLD}\xf0\x9f\x8f\x97${NORMAL}"
429 NOT_VERIFIED="$BUILD"
430 VERIFIED="${GREEN}${BOLD}\xe2\x9c\x93\x20${NORMAL}"
431 HELM="${BLUE}${BOLD}\xE2\x8E\x88${NORMAL}"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000432 OLD_KEY="\xF0\x9F\x97\x9D"
433 BIRD="\xF0\x9F\x90\xA6"
434 HIGH_VOLTAGE="\xE2\x9A\xA1"
435 PLUG="\xF0\x9F\xa7\xa9"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000436 FORWARD="\xE2\x87\xA8"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000437 GO="\xf0\x9f\x9a\x80"
438 DOWNLOAD="\xf0\x9f\x93\xa5"
439 GEAR="\xe2\x9a\x99"
440 NO_ENTRY="\xe2\x9b\x94"
441 LOCK="\xf0\x9f\x94\x92"
442fi
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700443
David Bainbridge712afb82019-08-14 19:55:58 +0000444duration() {
David Bainbridged18f4942020-04-14 16:46:13 -0700445 local h m s t
446 h="$(($1 / 3600))"
447 m="$(($1 % 3600 / 60))"
448 s="$(($1 % 60))"
449 t=""
David Bainbridgee87067b2019-08-12 22:00:12 +0000450
David Bainbridged18f4942020-04-14 16:46:13 -0700451 if [ "$h" -gt 0 ]; then
David Bainbridgee87067b2019-08-12 22:00:12 +0000452 t="$t${h}h"
453 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700454 if [ "$m" -gt 0 ]; then
David Bainbridgee87067b2019-08-12 22:00:12 +0000455 t="$t${m}m"
456 fi
David Bainbridge712afb82019-08-14 19:55:58 +0000457 echo "$t${s}s"
458}
459
460printtime() {
David Bainbridged18f4942020-04-14 16:46:13 -0700461 local INDENT
David Bainbridge712afb82019-08-14 19:55:58 +0000462 if [ "$1" == "-" ]; then
463 INDENT=" "
464 shift
465 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700466 echo -e "$INDENT $CLOCK $(duration "$1")"
David Bainbridgee87067b2019-08-12 22:00:12 +0000467}
468
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700469bspin() {
Test Userd87942b2019-07-03 07:20:24 +0000470 IDX=1
David Bainbridged18f4942020-04-14 16:46:13 -0700471 local INDENT
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700472 if [ "$1" == "-" ]; then
473 INDENT=" "
474 shift
475 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700476 if [ "$FANCY" -eq 0 ]; then
477 LINE="${*//[[:space:]+-]}"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000478 if [ "$LINE X" == " X" ]; then
479 return
480 fi
481 echo -e "$CIVIS$INDENT$*"
482 else
483 echo -en "$CIVIS$INDENT $*"
484 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700485}
486
487sspin() {
David Bainbridged18f4942020-04-14 16:46:13 -0700488 local INDENT
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700489 if [ "$1" == "-" ]; then
490 INDENT=" "
491 shift
492 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700493 if [ "$FANCY" -eq 0 ]; then
494 LINE="${*//[[:space:]+-]}"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000495 if [ "$LINE X" == " X" ]; then
496 return
497 fi
498 echo -e "$INDENT$*"
499 else
David Bainbridged18f4942020-04-14 16:46:13 -0700500 C="$(echo "$SPIN_PARTS" | cut '-d ' -f "$IDX")"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000501 echo -en "\r$INDENT$C $*"
David Bainbridged18f4942020-04-14 16:46:13 -0700502 IDX="$((IDX + 1))"
503 if [ "$IDX" -gt 8 ]; then
David Bainbridge38dc1e82019-08-12 15:18:45 +0000504 IDX=1
505 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700506 fi
507}
508
509espin() {
David Bainbridged18f4942020-04-14 16:46:13 -0700510 local INDENT
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700511 if [ "$1" == "-" ]; then
512 INDENT=" "
513 shift
514 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700515 if [ "$FANCY" -eq 0 ]; then
516 LINE="${*//[[:space:]+-]}"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000517 if [ "$LINE X" == " X" ]; then
518 return
519 fi
520 echo -e "$INDENT$*"
521 else
522 echo -e "\r$INDENT$*$CNORM"
523 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700524}
525
David Bainbridged18f4942020-04-14 16:46:13 -0700526if [ "$1" == "get" ] && [ "$2" == "voltconfig" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000527 echo "$HOME/.volt/config-$NAME"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000528 exit
529fi
530
David Bainbridged18f4942020-04-14 16:46:13 -0700531if [ $# -ne 1 ] || [ "$(echo ":up:down:dump:" | grep -c ":$1:")" -ne 1 ]; then
David Bainbridgeac7f8072019-08-01 22:15:33 +0000532 >&2 echo "What wouild you like to do today:"
533 >&2 echo " up - bring up voltha"
534 >&2 echo " down - tear down voltha"
535 >&2 echo " dump - create a debug dump of running system"
536 exit 1
537fi
538
David Bainbridge4f1b5562019-08-19 04:46:52 +0000539push_onos_config() {
David Bainbridged18f4942020-04-14 16:46:13 -0700540 local TYPE MSG RESOURCE DATA CMD_ECHO CMD_OUTPUT SC_OUTPUT WAIT_START NOW
541 TYPE=$1
542 MSG=$2
543 RESOURCE=$3
544 DATA=$4
David Bainbridge4f1b5562019-08-19 04:46:52 +0000545
David K. Bainbridgeb4b163b2020-02-19 15:55:06 -0800546 # Thanks to the latest version of ONOS using the return code 207 this gets a
547 # whole lot nastier. Can't thank them enough for doing this. So in order to
548 # capture the command and the output in the log file as well as capture the
549 # status code to verify it is 200 and not 207 mutltiple files and a bit of
550 # hackery must be used. Thanks again ONOS.
David Bainbridged18f4942020-04-14 16:46:13 -0700551 CMD_ECHO="$(mktemp -u)"
552 CMD_OUTPUT="$(mktemp -u)"
553 SC_OUTPUT="$(mktemp -u)"
554 WAIT_START="$(date +%s)"
David K. Bainbridgeb4b163b2020-02-19 15:55:06 -0800555
David Bainbridge4f1b5562019-08-19 04:46:52 +0000556 bspin - "$MSG $GEAR"
557 while true; do
David Bainbridged18f4942020-04-14 16:46:13 -0700558 NOW="$(date +%s)"
559 if [ "$((NOW - WAIT_START))" -gt "$TIMEOUT_SECONDS" ]; then
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700560 espin - "$THEX"
David Bainbridged18f4942020-04-14 16:46:13 -0700561 rm -f "$CMD_ECHO" "$CMD_OUTPUT" "$SC_OUTPUT"
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700562 doTimeout "waiting for ONOS config push on $RESOURCE"
563 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700564 if [ "$TYPE" == "file" ]; then
565 (set -x; curl --fail -sSL --user karaf:karaf -w "%{http_code}" -o "$CMD_OUTPUT" -X POST -H Content-Type:application/json "http://$_ONOS_API_EP/onos/v1/$RESOURCE" --data "@$DATA" >"$SC_OUTPUT" 2>/dev/null) >>"$CMD_ECHO" 2>&1
David K. Bainbridgeb859e912020-03-13 14:07:52 -0700566 RESULT=$?
Matteo Scandolo78dfee02020-02-13 16:18:03 -0800567 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700568 if [ "$TYPE" == "json" ]; then
569 (set -x; curl --fail -sSL --user karaf:karaf -w "%{http_code}" -o "$CMD_OUTPUT" -X POST -H Content-Type:application/json "http://$_ONOS_API_EP/onos/v1/$RESOURCE" --data "$DATA" >"$SC_OUTPUT" 2>/dev/null) >>"$CMD_ECHO" 2>&1
David K. Bainbridgeb859e912020-03-13 14:07:52 -0700570 RESULT=$?
Matteo Scandolo78dfee02020-02-13 16:18:03 -0800571 fi
David K. Bainbridgeb4b163b2020-02-19 15:55:06 -0800572 # Dump everything to the log
David Bainbridged18f4942020-04-14 16:46:13 -0700573 cat "$CMD_ECHO" >> "$LOG"
574 test -r "$CMD_OUTPUT" && cat "$CMD_OUTPUT" >> "$LOG"
575 SC="$(cat "$SC_OUTPUT")"
576 echo "RESPONSE CODE: $SC" >> "$LOG"
577 echo "ERROR CODE: $RESULT" >> "$LOG"
David K. Bainbridgeb4b163b2020-02-19 15:55:06 -0800578
579 # clean up temp files
David Bainbridged18f4942020-04-14 16:46:13 -0700580 rm -f "$CMD_ECHO" "$CMD_OUTPUT" "$SC_OUTPUT"
581 if [ "$RESULT" -eq 0 ] && [ "$SC" == "200" ]; then
David Bainbridge4f1b5562019-08-19 04:46:52 +0000582 break
583 fi
Matteo Scandolo9a77a732020-01-09 14:24:12 -0800584 sleep 1
David Bainbridge4f1b5562019-08-19 04:46:52 +0000585 sspin -
586 done
David Bainbridged18f4942020-04-14 16:46:13 -0700587 espin - "$VERIFIED"
David Bainbridge4f1b5562019-08-19 04:46:52 +0000588}
589
Matteo Scandolo9a77a732020-01-09 14:24:12 -0800590check_onos_app_active() {
David Bainbridged18f4942020-04-14 16:46:13 -0700591 local APP_ID WAIT_START RESULT NOW
592 APP_ID=$1
593 WAIT_START="$(date +%s)"
Matteo Scandolo9a77a732020-01-09 14:24:12 -0800594
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700595 bspin - "Checking that $APP_ID is active $CLOCK"
596 while true; do
David Bainbridged18f4942020-04-14 16:46:13 -0700597 NOW="$(date +%s)"
598 if [ "$((NOW - WAIT_START))" -gt "$TIMEOUT_SECONDS" ]; then
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700599 espin - "$THEX"
600 doTimeout "waiting for ONOS application activation '$APP_ID'"
601 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700602 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 -0700603 break
604 fi
605 sleep 1
606 sspin -
607 done
608 sleep 5 # OSGI components take a little longer that the app to activate
David Bainbridged18f4942020-04-14 16:46:13 -0700609 espin - "$VERIFIED"
Matteo Scandolo9a77a732020-01-09 14:24:12 -0800610}
611
David Bainbridge4f1b5562019-08-19 04:46:52 +0000612override_onos_app() {
David Bainbridged18f4942020-04-14 16:46:13 -0700613 local APP NAME WAIT_START NOW
614 APP=$1
615 NAME="$(basename "$APP" | sed -e 's/^[0-9][0-9]*-//g' -e 's/-.*$//g')"
616 WAIT_START="$(date +%s)"
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700617
David Bainbridge4f1b5562019-08-19 04:46:52 +0000618 while true; do
David Bainbridged18f4942020-04-14 16:46:13 -0700619 NOW="$(date +%s)"
620 if [ "$((NOW - WAIT_START))" -gt "$TIMEOUT_SECONDS" ]; then
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700621 espin - "$THEX"
622 doTimeout "waiting to overwrite ONOS application '$APP'"
623 fi
David Bainbridge4f1b5562019-08-19 04:46:52 +0000624 sspin -
625 # Attempt to delete old version (if it exists)
David Bainbridged18f4942020-04-14 16:46:13 -0700626 (set -x; curl --fail -sSL --user karaf:karaf -X DELETE "http://$_ONOS_API_EP/onos/v1/applications/$NAME" >>"$LOG" 2>&1) >>"$LOG" 2>&1
627 RESULT=$?
David Bainbridge4f1b5562019-08-19 04:46:52 +0000628 sspin -
David Bainbridged18f4942020-04-14 16:46:13 -0700629 if [ $RESULT -ne 0 ]; then
David Bainbridge4f1b5562019-08-19 04:46:52 +0000630 continue
631 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700632 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 +0000633 break
634 fi
635 sleep .2
636 done
637}
638
639activate_onos_app() {
David Bainbridged18f4942020-04-14 16:46:13 -0700640 local MSG APP WAIT_START NOW
641 MSG="$1"
642 APP=$2
643 WAIT_START="$(date +%s)"
David Bainbridge4f1b5562019-08-19 04:46:52 +0000644
645 bspin - "$MSG $GO"
646 while true; do
David Bainbridged18f4942020-04-14 16:46:13 -0700647 NOW="$(date +%s)"
648 if [ "$((NOW - WAIT_START))" -gt "$TIMEOUT_SECONDS" ]; then
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700649 espin - "$THEX"
650 doTimeout "waiting to activate ONOS application '$APP'"
651 fi
David Bainbridge4f1b5562019-08-19 04:46:52 +0000652 sspin -
David Bainbridged18f4942020-04-14 16:46:13 -0700653 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 +0000654 break
655 fi
656 sleep .2
657 done
658 espin - "$VERIFIED"
659}
660
661count_pods() {
David Bainbridged18f4942020-04-14 16:46:13 -0700662 local NAMESPACE STATES LABELS CMD PODS
663 NAMESPACE=$1; shift
David Bainbridge4f1b5562019-08-19 04:46:52 +0000664 if [ "$NAMESPACE" == "all-namespaces" ]; then
665 NAMESPACE="--all-namespaces"
666 else
667 NAMESPACE="-n $NAMESPACE"
668 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700669 STATES=$1; shift
670 LABELS=$1; shift
671 CMD=("kubectl get $NAMESPACE $LABELS pod")
672 PODS=$(${CMD[*]} -o go-template="{{range .items}}{{.metadata.name}}/{{.status.phase}}/_{{range .status.containerStatuses}}{{.ready}}_{{end}} {{end}}")
David Bainbridge4f1b5562019-08-19 04:46:52 +0000673 local COUNT=0
674 local PATTERNS="$*"
675 for POD in $PODS; do
David Bainbridged18f4942020-04-14 16:46:13 -0700676 local NAME STATE CONTAINERS TOTAL FOUND
677 NAME="$(echo "$POD" | cut -d/ -f 1)"
678 STATE="$(echo "$POD" | cut -d/ -f 2)"
679 CONTAINERS="$(echo "$POD" | cut -d/ -f 3 | sed -e 's/_/ /g')"
680 if [ "$STATES" == "*" ] || [ "$(echo "$STATES" | grep -c ":$STATE:")" -ne 0 ]; then
681 TOTAL="$(echo "$CONTAINERS" | wc -w)"
682 FOUND="$(echo "$CONTAINERS" | grep -o true | wc -l)"
683 if [ "$TOTAL" -eq "$FOUND" ]; then
David Bainbridge4f1b5562019-08-19 04:46:52 +0000684 for PATTERN in $PATTERNS; do
David Bainbridged18f4942020-04-14 16:46:13 -0700685 if [[ "$NAME" =~ $PATTERN ]]; then
686 COUNT="$((COUNT + 1))"
David Bainbridge4f1b5562019-08-19 04:46:52 +0000687 break
688 fi
689 done
690 fi
691 fi
692 done
David Bainbridge4f1b5562019-08-19 04:46:52 +0000693 echo $COUNT
694}
695
696wait_for_pods() {
David Bainbridged18f4942020-04-14 16:46:13 -0700697 local INDENT NAMESPACE EXPECT TYPE MESSAGE LABELS PATTERNS STATES HAVE ALL WAIT_START NOW
David Bainbridge4f1b5562019-08-19 04:46:52 +0000698 if [ "$1" == "-" ]; then
699 INDENT=$1; shift
700 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700701 NAMESPACE=$1; shift
702 EXPECT=$1; shift
703 TYPE=$1; shift
704 MESSAGE=$1; shift
705 LABELS=$1; shift
706 PATTERNS=("$*")
707 STATES=":Running:"
David Bainbridge99ac7a22019-08-31 02:26:43 +0000708 if [ "$TYPE" == "not" ]; then
709 STATES="*"
710 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700711 HAVE="$(count_pods "$NAMESPACE" "$STATES" "$LABELS" "${PATTERNS[@]}")"
712 ALL=$HAVE
David Bainbridge4f1b5562019-08-19 04:46:52 +0000713 if [ "$TYPE" == "only" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -0700714 ALL="$(count_pods "all-namespaces" "*" ".*")"
David Bainbridge4f1b5562019-08-19 04:46:52 +0000715 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700716 COUNT="$((300 / 15))"
717 WAIT_START="$(date +%s)"
718 bspin "$INDENT" "$MESSAGE"
719 sspin "$INDENT"
720 if [ "$HAVE" -ne "$EXPECT" ] || [ "$ALL" -ne "$HAVE" ]; then
721 while [ "$HAVE" -ne "$EXPECT" ] || [ "$ALL" -ne "$HAVE" ]; do
722 NOW="$(date +%s)"
723 if [ "$((NOW - WAIT_START))" -gt "$TIMEOUT_SECONDS" ]; then
724 espin "$INDENT" "$THEX"
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700725 doTimeout "waiting for PODs to start"
726 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700727 sspin "$INDENT"
728 COUNT="$((COUNT - 1))"
729 if [ "$COUNT" -eq 0 ]; then
730 HAVE="$(count_pods "$NAMESPACE" "$STATES" "$LABELS" "${PATTERNS[@]}")"
731 ALL="$HAVE"
David Bainbridge4f1b5562019-08-19 04:46:52 +0000732 if [ "$TYPE" == "only" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -0700733 ALL="$(count_pods "all-namespaces" "*" ".*")"
David Bainbridge4f1b5562019-08-19 04:46:52 +0000734 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700735 COUNT="$((300 / 15))"
David Bainbridge4f1b5562019-08-19 04:46:52 +0000736 fi
737 sleep .15
738 done
739 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700740 espin "$INDENT" "$VERIFIED"
741 if [ "$HAVE" -ne "$EXPECT" ]; then
David Bainbridge4f1b5562019-08-19 04:46:52 +0000742 return 1
743 fi
744 return 0
745}
746
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800747port_forward() {
748 local NS=$1
749 local SVC=$2
750 local FROM_PORT=$3
751 local TO_PORT=$4
752 local TAG=$SVC-$NAME
753
David Bainbridged18f4942020-04-14 16:46:13 -0700754 (set -x; _TAG="$TAG" bash -c "while true; do kubectl port-forward --address 0.0.0.0 -n $NS service/$SVC $FROM_PORT:$TO_PORT; done" >>"$LOG" 2>&1 &) >>"$LOG" 2>&1
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800755}
756
757kill_port_forward() {
David Bainbridged18f4942020-04-14 16:46:13 -0700758 local TAG P_IDS PARENTS KIDS UNKNOWN PP_ID
759 TAG="$1-$NAME"
760 # shellcheck disable=SC2009
761 P_IDS="$(ps e -ww -A | grep "_TAG=$TAG" | grep -v grep | awk '{print $1}')"
762 if [ -n "$P_IDS" ]; then
David Bainbridgec6871d22019-11-13 17:10:31 +0000763 for P_ID in $P_IDS; do
David Bainbridged18f4942020-04-14 16:46:13 -0700764 PP_ID="$(ps -o ppid "$P_ID" | tail -n +2)"
765 if [ -n "$PP_ID" ]; then
766 if [ "$PP_ID" -eq 1 ]; then
David Bainbridgec6871d22019-11-13 17:10:31 +0000767 PARENTS="$PARENTS $P_ID"
768 else
769 KIDS="$KIDS $P_ID"
770 fi
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800771 else
David Bainbridgec6871d22019-11-13 17:10:31 +0000772 UNKNOWN="$UNKNOWN $P_ID"
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800773 fi
774 done
David Bainbridged18f4942020-04-14 16:46:13 -0700775 (set -x; kill -9 "$PARENTS" "$KIDS" "$UNKNOWN" >>"$LOG" 2>&1) >>"$LOG" 2>&1
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800776 fi
777}
778
David Bainbridgeac7f8072019-08-01 22:15:33 +0000779if [ "$1" == "down" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000780 echo "Tearing down voltha cluster $NAME"
781 LOG="down-$NAME.log"
David Bainbridged18f4942020-04-14 16:46:13 -0700782 date -u +"%Y%m%dT%H%M%SZ" >"$LOG"
783 if [ "$WITH_ONOS" == "yes" ]; then
David Bainbridge696bc632020-04-05 21:49:37 -0700784 bspin "Remove port-forwards: onos-ui-$NAME"
785 kill_port_forward onos-ui
786 sspin "Remove port-forwards: onos-ssh-$NAME$CEOL"
787 kill_port_forward onos-ssh
788 fi
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800789 sspin "Remove port-forwards: voltha-api-$NAME$CEOL"
790 kill_port_forward voltha-api
David Bainbridged18f4942020-04-14 16:46:13 -0700791 if [ "$WITH_ETCD" == "yes" ] || [ "$WITH_ETCD" == "external" ]; then
792 sspin "Remove port-forwards: ${ETCD_PREFIX}etcd-$NAME$CEOL"
793 kill_port_forward "${ETCD_PREFIX}etcd-cluster-client"
David Bainbridge696bc632020-04-05 21:49:37 -0700794 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700795 if [ "$WITH_KAFKA" == "yes" ] || [ "$WITH_KAFKA" == "external" ]; then
796 sspin "Remove port-forwards: ${KAFKA_PREFIX}kafka-$NAME$CEOL"
797 kill_port_forward "${KAFKA_PREFIX}kafka"
David Bainbridge696bc632020-04-05 21:49:37 -0700798 fi
799
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800800 espin "$VERIFIED Remove port-forwards$CEOL"
David Bainbridged18f4942020-04-14 16:46:13 -0700801 if [ "$DEPLOY_K8S" == "yes" ]; then
David Bainbridgeac7f8072019-08-01 22:15:33 +0000802 if [ -x ./bin/kind ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000803 bspin "Delete Kubernetes Kind Cluster"
David Bainbridged18f4942020-04-14 16:46:13 -0700804 (set -x; ./bin/kind delete cluster --name "voltha-$NAME" >>"$LOG" 2>&1) >>"$LOG" 2>&1
805 espin "$VERIFIED"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000806 else
David Bainbridge0774b232019-08-02 06:37:19 +0000807 espin "$NO_ENTRY Delete Kubernetes Kind Cluster: kind command not found"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000808 fi
809 else
David Bainbridged18f4942020-04-14 16:46:13 -0700810 EXISTS="$(helm list -q)"
David Bainbridge76afd812020-04-06 09:53:52 -0700811 EXPECT="voltha"
David Bainbridged18f4942020-04-14 16:46:13 -0700812 if [ "$WITH_ONOS" == yes ]; then
David Bainbridge696bc632020-04-05 21:49:37 -0700813 EXPECT+=" onos"
814 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700815 if [ "$WITH_RADIUS" == "yes" ]; then
David Bainbridge696bc632020-04-05 21:49:37 -0700816 EXPECT+=" radius"
817 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700818 if [ "$WITH_BBSIM" == "yes" ]; then
David Bainbridge696bc632020-04-05 21:49:37 -0700819 EXPECT+=" bbsim"
820 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700821 if [ "$WITH_OPEN_ADAPTERS" == "yes" ]; then
David Bainbridge696bc632020-04-05 21:49:37 -0700822 EXPECT+=" open-olt open-onu"
823 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700824 if [ "$WITH_SIM_ADAPTERS" == "yes" ]; then
David Bainbridge696bc632020-04-05 21:49:37 -0700825 EXPECT+=" sim"
826 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700827 if [ "$WITH_ETCD" == "external" ]; then
David Bainbridge76afd812020-04-06 09:53:52 -0700828 EXPECT+=" etcd-operator etcd-cluster"
David Bainbridged18f4942020-04-14 16:46:13 -0700829 elif [ "$WITH_ETCD" == "yes" ]; then
David Bainbridge76afd812020-04-06 09:53:52 -0700830 EXPECT+=" etcd-operator"
831 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700832 if [ "$WITH_KAFKA" == "external" ]; then
David Bainbridge76afd812020-04-06 09:53:52 -0700833 EXPECT+=" kafka"
834 fi
David Bainbridge0774b232019-08-02 06:37:19 +0000835 bspin "Remove Helm Deployments"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000836 for i in $EXISTS; do
David K. Bainbridge43422402020-03-06 07:41:22 -0800837 for j in $EXPECT; do
David Bainbridged18f4942020-04-14 16:46:13 -0700838 if [[ "$i" =~ $j ]]; then
David K. Bainbridge43422402020-03-06 07:41:22 -0800839 sspin "Remove Helm Deployments: $i$CEOL"
David Bainbridged18f4942020-04-14 16:46:13 -0700840 (set -x; ./bin/helm delete --no-hooks --purge "$i" >>"$LOG" 2>&1) >>"$LOG" 2>&1
David K. Bainbridge43422402020-03-06 07:41:22 -0800841 fi
842 done
uottrembb16d3982020-02-28 08:34:36 +0100843 done
David Bainbridge0774b232019-08-02 06:37:19 +0000844 espin "$VERIFIED Remove Helm Deployments$CEOL"
David Bainbridge4f1b5562019-08-19 04:46:52 +0000845 if [ "$WAIT_ON_DOWN" == "yes" ]; then
David Bainbridge76afd812020-04-06 09:53:52 -0700846 PODS="voltha-kafka.* voltha-ofagent.* voltha-rw-core.* voltha-etcd.*"
847 INFRA_PODS=
848 ADAPT_PODS=
849 SIM_PODS=
David Bainbridged18f4942020-04-14 16:46:13 -0700850 if [ "$WITH_RADIUS" == "yes" ]; then
David Bainbridge696bc632020-04-05 21:49:37 -0700851 PODS+=" radius.*"
852 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700853 if [ "$WITH_BBSIM" == "yes" ]; then
David Bainbridge76afd812020-04-06 09:53:52 -0700854 SIM_PODS+=" bbsim.*"
David Bainbridge696bc632020-04-05 21:49:37 -0700855 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700856 if [ "$WITH_OPEN_ADAPTERS" ] || [ "$WITH_SIM_ADAPTERS" ]; then
David Bainbridge76afd812020-04-06 09:53:52 -0700857 ADAPT_PODS+=" adapter-*"
David Bainbridge696bc632020-04-05 21:49:37 -0700858 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700859 if [ "$WITH_ONOS" == "yes" ]; then
David Bainbridge76afd812020-04-06 09:53:52 -0700860 INFRA_PODS+=" onos-.*"
861 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700862 if [ "$WITH_ETCD" == "external" ]; then
David Bainbridge76afd812020-04-06 09:53:52 -0700863 INFRA_PODS+=" etcd-operator.* etcd-cluster.*"
David Bainbridged18f4942020-04-14 16:46:13 -0700864 elif [ "$WITH_ETCD" == "yes" ]; then
David Bainbridge76afd812020-04-06 09:53:52 -0700865 PODS+=" etcd-operator.*"
866 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700867 if [ "$WITH_KAFKA" == "external" ]; then
David Bainbridge76afd812020-04-06 09:53:52 -0700868 INFRA_PODS+=" kafka.*"
869 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700870 if [ -n "$SIM_PODS" ]; then
871 wait_for_pods "$BBSIM_NS" 0 "not" "Waiting for BBSIM PODs to terminate" "$BBSIM_LABEL" "$SIM_PODS"
David Bainbridge76afd812020-04-06 09:53:52 -0700872 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700873 if [ -n "$INFRA_PODS" ]; then
874 wait_for_pods "$INFRA_NS" 0 "not" "Waiting for infrastructure PODs to terminate" "$NO_LABEL" "$INFRA_PODS"
David Bainbridge76afd812020-04-06 09:53:52 -0700875 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700876 if [ -n "$ADAPT_PODS" ]; then
877 wait_for_pods "$ADAPTER_NS" 0 "not" "Waiting for adapter PODs to terminate" "$NO_LABEL" "$ADAPT_PODS"
David Bainbridge76afd812020-04-06 09:53:52 -0700878 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700879 wait_for_pods "$VOLTHA_NS" 0 "not" "Waiting for VOLTHA PODs to terminate" "$NO_LABEL" "$PODS"
David Bainbridge4f1b5562019-08-19 04:46:52 +0000880 fi
David Bainbridgeac7f8072019-08-01 22:15:33 +0000881 fi
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -0700882 exit
David Bainbridgeac7f8072019-08-01 22:15:33 +0000883fi
884
885if [ "$1" == "dump" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000886 LOG="dump-$NAME.log"
David Bainbridged18f4942020-04-14 16:46:13 -0700887 TS="$(date -u +"%Y%m%dT%H%M%SZ")"
888 if [ -n "$DUMP_FROM" ]; then
889 TS=${DUMP_FROM//[:-]}
David Bainbridge76514a02019-10-08 01:50:35 +0000890 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700891 WORK="$(mktemp -u -d)"
David Bainbridge0774b232019-08-02 06:37:19 +0000892 DATA=$WORK/voltha-debug-dump-$NAME-$TS
David Bainbridged18f4942020-04-14 16:46:13 -0700893 mkdir -p "$DATA"
894 echo "$TS" > "$LOG"
David Bainbridge0774b232019-08-02 06:37:19 +0000895 echo -e "Capturing debug dump to voltha-debug-dump-$NAME-$TS.tgz"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000896 bspin - "Copy install log"
David Bainbridged18f4942020-04-14 16:46:13 -0700897 if [ -f "install-$NAME.log" ]; then
898 (set -x; cp "install-$NAME.log" "$DATA/install-$NAME.log") >>"$LOG" 2>&1
899 espin - "$VERIFIED"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000900 else
David Bainbridge0774b232019-08-02 06:37:19 +0000901 espin - "$NO_ENTRY Copy install log: install-$NAME.log not found"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000902 fi
903 bspin - "Dumping Kubernetes PODs"
David Bainbridged18f4942020-04-14 16:46:13 -0700904 (set -x; kubectl get --all-namespaces pods >> "$DATA/all-pods.txt" 2>&1) >>"$LOG" 2>&1
905 espin - "$VERIFIED"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000906 bspin - "Dumping Kubernetes SERVICEs"
David Bainbridged18f4942020-04-14 16:46:13 -0700907 (set -x; kubectl get --all-namespaces svc >> "$DATA/all-services.txt" 2>&1) >>"$LOG" 2>&1
908 espin - "$VERIFIED"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000909 bspin - "Dumping Kubernetes EVENTs"
David Bainbridged18f4942020-04-14 16:46:13 -0700910 (set -x; kubectl get --all-namespaces events >> "$DATA/all-events.txt" 2>&1) >>"$LOG" 2>&1
911 espin - "$VERIFIED"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000912 bspin - "Dumping VOLTHA POD details"
David Bainbridged18f4942020-04-14 16:46:13 -0700913 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 +0000914 SINCE=
David Bainbridged18f4942020-04-14 16:46:13 -0700915 if [ -n "$DUMP_FROM" ]; then
David Bainbridgecfd7ca12019-10-06 03:31:41 +0000916 SINCE="--since-time=$DUMP_FROM"
917 fi
David Bainbridgeac7f8072019-08-01 22:15:33 +0000918 for POD in $PODS; do
David Bainbridged18f4942020-04-14 16:46:13 -0700919 NS="$(echo "$POD" | cut -d: -f1)"
920 POD="$(echo "$POD" | cut -d: -f2)"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000921 sspin - "Dumping VOLTHA POD details: $POD$CEOL"
David Bainbridged18f4942020-04-14 16:46:13 -0700922 mkdir -p "$DATA/$POD"
923 (set -x; kubectl describe -n "$NS" "$POD" >> "$DATA/$POD/describe.txt" 2>&1) >>"$LOG" 2>&1
David Bainbridgeac7f8072019-08-01 22:15:33 +0000924 sspin - "Dumping VOLTHA POD details: $POD"
David Bainbridged18f4942020-04-14 16:46:13 -0700925 (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 +0000926 sspin - "Dumping VOLTHA POD details: $POD"
David Bainbridged18f4942020-04-14 16:46:13 -0700927 (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 +0000928 sspin - "Dumping VOLTHA POD details: $POD"
929 done
930 espin - "$VERIFIED Dumping VOLTHA POD details$CEOL"
931 bspin - "Dumping ETCD"
David Bainbridged18f4942020-04-14 16:46:13 -0700932 if [ -n "$(command -v etcdctl)" ]; then
933 (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
934 espin - "$VERIFIED"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000935 else
936 espin - "$NO_ENTRY Dumping ETCD: etcdctl command not available"
937 fi
David Bainbridge0774b232019-08-02 06:37:19 +0000938 bspin - "Creating compressed TAR: voltha-debug-dump-$NAME-$TS.tgz"
David Bainbridged18f4942020-04-14 16:46:13 -0700939 (set -x; tar -C "$WORK" -zcf "voltha-debug-dump-$NAME-$TS.tgz" "./voltha-debug-dump-$NAME-$TS") >>"$LOG" 2>&1
940 espin - "$VERIFIED"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000941 bspin - "Cleanup"
David Bainbridged18f4942020-04-14 16:46:13 -0700942 (set -x; rm -rf "$WORK") >>"$LOG" 2>&1
943 espin - "$VERIFIED"
944 bspin - "$(ls -l "voltha-debug-dump-$NAME-$TS.tgz")"
945 espin - "$VERIFIED"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000946 exit
947fi
948
David Bainbridge0774b232019-08-02 06:37:19 +0000949LOG="install-$NAME.log"
David Bainbridged18f4942020-04-14 16:46:13 -0700950date > "$LOG"
951echo "PORTS=$ONOS_API_PORT,$ONOS_SSH_PORT,$VOLTHA_API_PORT,$VOLTHA_SSH_PORT,$VOLTHA_ETCD_PORT" >> "$LOG"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000952
953# Output install options to log
David Bainbridged18f4942020-04-14 16:46:13 -0700954echo "OPTIONS" >> "$LOG"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000955for O in $ALL_OPTIONS; do
David Bainbridged18f4942020-04-14 16:46:13 -0700956 VAL="$(eval echo "\$$O")"
957 if [ -n "$VAL" ]; then
958 printf " %-30s = %s\n" "$O" "$VAL" >> "$LOG"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000959 fi
960done
961
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -0700962helm_install() {
David Bainbridged18f4942020-04-14 16:46:13 -0700963 local INDENT NOW
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700964 if [ "$1" == "-" ]; then
965 INDENT=$1; shift
966 fi
967 local NAMESPACE=$1; shift
David Bainbridge0774b232019-08-02 06:37:19 +0000968 local INAME=$1; shift
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700969 local CHART=$1; shift
David Bainbridge90fd8e32019-08-21 23:32:47 +0000970 local CHART_VERSION=$1; shift
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700971 local MESSAGE=$*
972
David Bainbridged18f4942020-04-14 16:46:13 -0700973 if [ "$CHART_VERSION X" != " X" ] && [ "$CHART_VERSION" != "latest" ]; then
David Bainbridge90fd8e32019-08-21 23:32:47 +0000974 CHART_VERSION="--version $CHART_VERSION"
975 else
976 CHART_VERSION=
977 fi
978
David Bainbridge99ac7a22019-08-31 02:26:43 +0000979 local CHART_ARGS=
980 if [ -r "${INAME}-values.yaml" ]; then
981 CHART_ARGS="-f ${INAME}-values.yaml"
982 fi
983
David Bainbridged18f4942020-04-14 16:46:13 -0700984 local WAIT_START CMD
985 WAIT_START="$(date +%s)"
986 COUNT="$((300 / 15))"
987 bspin "$INDENT" "$MESSAGE"
988 if [ "$HELM_USE_UPGRADE" == "yes" ]; then
David Bainbridge7f8bf992020-04-08 21:53:22 -0700989 _HELM_COMMAND="upgrade --install"
990 _HELM_ARGS="$INAME"
991 else
992 _HELM_COMMAND="install"
993 _HELM_ARGS="--name $INAME"
994 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700995 CMD=("helm $_HELM_COMMAND -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")
996 (set -x; ${CMD[*]} >>"$LOG" 2>&1) >>"$LOG" 2>&1
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700997 SUCCESS=$?
David Bainbridged18f4942020-04-14 16:46:13 -0700998 while [ "$SUCCESS" -ne 0 ]; do
999 NOW="$(date +%s)"
1000 if [ "$((NOW - WAIT_START))" -gt "$TIMEOUT_SECONDS" ]; then
David Bainbridge52e6e9d2020-03-23 13:48:27 -07001001 espin "$THEX"
1002 doTimeout "waiting for helm install $CHART"
1003 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001004 sspin "$INDENT"
1005 COUNT="$((COUNT - 1))"
1006 if [ "$COUNT" -eq 0 ]; then
1007 if [ "$HELM_USE_UPGRADE" == "no" ]; then
1008 (set -x; helm delete --purge "$INAME" >>"$LOG" 2>&1) >>"$LOG" 2>&1
David Bainbridge7f8bf992020-04-08 21:53:22 -07001009 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001010 (set -x; ${CMD[*]} >>"$LOG" 2>&1) >>"$LOG" 2>&1
Andy Baviere22ff252019-12-19 11:40:31 -07001011 SUCCESS=$?
David Bainbridged18f4942020-04-14 16:46:13 -07001012 COUNT="$((300 / 15))"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001013 fi
1014 sleep .15
1015 done
David Bainbridged18f4942020-04-14 16:46:13 -07001016 espin "$INDENT" "$VERIFIED"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001017}
1018
David Bainbridged18f4942020-04-14 16:46:13 -07001019echo "INSTALL TYPE: $TYPE" >> "$LOG"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001020
1021bspin "Verify GOPATH"
David Bainbridged18f4942020-04-14 16:46:13 -07001022GOPATH="$(pwd)"; export GOPATH
1023mkdir -p "$GOPATH/bin"
1024espin "$VERIFIED"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001025
David Bainbridged18f4942020-04-14 16:46:13 -07001026STIME="$(date +%s)"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001027if [ "$INSTALL_KUBECTL" == "no" ]; then
1028 bspin "Skip kubectl install"
1029 espin $NO_ENTRY
Test Userc13bdc92019-07-03 20:57:49 +00001030else
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001031 bspin "Verify kubectl $HELM"
David Bainbridged18f4942020-04-14 16:46:13 -07001032 if [ -x "$GOPATH/bin/kubectl" ]; then
1033 espin "$VERIFIED"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001034 else
David Bainbridged18f4942020-04-14 16:46:13 -07001035 espin "$NOT_VERIFIED"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001036 bspin - "Download and install Kubernetes/kubectl $DOWNLOAD"
David Bainbridged18f4942020-04-14 16:46:13 -07001037 (set -x; curl -o "$GOPATH/bin/kubectl" -sSL "https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/$HOSTOS/$HOSTARCH/kubectl" >>"$LOG" 2>&1) >>"$LOG" 2>&1
1038 (set -x; chmod 755 "$GOPATH/bin/kubectl" >>"$LOG" 2>&1) >>"$LOG" 2>&1
1039 espin - "$VERIFIED"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001040 fi
Test Userc13bdc92019-07-03 20:57:49 +00001041fi
David Bainbridgee87067b2019-08-12 22:00:12 +00001042if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001043 NOW="$(date +%s)"
1044 printtime $((NOW - STIME))
David Bainbridgee87067b2019-08-12 22:00:12 +00001045fi
Test Userc13bdc92019-07-03 20:57:49 +00001046
David Bainbridged18f4942020-04-14 16:46:13 -07001047STIME="$(date +%s)"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001048if [ "$DEPLOY_K8S" == "no" ]; then
1049 bspin "Skip Kubernetes/Kind Deployment"
1050 espin $NO_ENTRY
1051else
Test Userba1e7e72019-07-10 22:27:54 +00001052 bspin "Verify Kubernetes/Kind $HELM"
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -08001053 IS_INSTALLED=0
1054 OP_TYPE="install"
David Bainbridged18f4942020-04-14 16:46:13 -07001055 if [ -x "$GOPATH/bin/kind" ]; then
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -08001056 OP_TYPE="upgrade"
David Bainbridged18f4942020-04-14 16:46:13 -07001057 if [ "$("$GOPATH/bin/kind" --version | grep -c "$KIND_VERSION")" -eq 1 ]; then
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -08001058 IS_INSTALLED=1
David Bainbridged18f4942020-04-14 16:46:13 -07001059 espin "$VERIFIED"
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -08001060 fi
1061 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001062 if [ "$IS_INSTALLED" -eq 0 ]; then
1063 espin "$NOT_VERIFIED"
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -08001064 bspin - "Download and $OP_TYPE Kubernetes/kind $DOWNLOAD"
David Bainbridged18f4942020-04-14 16:46:13 -07001065 (set -x; curl -o "$GOPATH/bin/kind" -sSL "https://github.com/kubernetes-sigs/kind/releases/download/$KIND_VERSION/kind-$HOSTOS-$HOSTARCH" >>"$LOG" 2>&1) >>"$LOG" 2>&1
1066 (set -x; chmod 755 "$GOPATH/bin/kind" >>"$LOG" 2>&1) >>"$LOG" 2>&1
1067 espin - "$VERIFIED"
Test Userba1e7e72019-07-10 22:27:54 +00001068 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001069fi
1070
David Bainbridgee87067b2019-08-12 22:00:12 +00001071if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001072 NOW="$(date +%s)"
1073 printtime $((NOW - STIME))
David Bainbridgee87067b2019-08-12 22:00:12 +00001074fi
1075
David Bainbridged18f4942020-04-14 16:46:13 -07001076STIME="$(date +%s)"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001077if [ "$INSTALL_HELM" == "no" ]; then
1078 bspin "Skip Helm Install"
1079 espin $NO_ENTRY
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001080else
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001081 bspin "Verify Helm $HELM"
David Bainbridgea34993d2020-04-01 09:15:42 -07001082 HELM_UPGRADE=0
1083 HELM_UPGRADE_DESC="install"
David Bainbridged18f4942020-04-14 16:46:13 -07001084 if [ -x "$GOPATH/bin/helm" ]; then
1085 HAVE_VER="$("$GOPATH/bin/helm" version -c --template '{{.Client.SemVer}}')"
1086 HELM_UP_DOWN="$(echo -e "$HAVE_VER\n$HELM_VERSION" | sort -V | head -1)"
1087 if [ "$HAVE_VER" != "$HELM_VERSION" ]; then
1088 if [ "$HELM_UP_DOWN" == "$HELM_VERSION" ]; then
David Bainbridgea34993d2020-04-01 09:15:42 -07001089 HELM_UPGRADE_DESC="downgrade"
1090 else
1091 HELM_UPGRADE_DESC="upgrade"
1092 fi
1093 HELM_UPGRADE=1
1094 else
David Bainbridged18f4942020-04-14 16:46:13 -07001095 espin "$VERIFIED"
David Bainbridgea34993d2020-04-01 09:15:42 -07001096 fi
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001097 else
David Bainbridgea34993d2020-04-01 09:15:42 -07001098 HELM_UPGRADE=1
1099 fi
1100
David Bainbridged18f4942020-04-14 16:46:13 -07001101 if [ "$HELM_UPGRADE" -ne 0 ]; then
1102 espin "$NOT_VERIFIED"
David Bainbridgea34993d2020-04-01 09:15:42 -07001103 bspin - "Download and $HELM_UPGRADE_DESC Helm $DOWNLOAD"
David Bainbridged18f4942020-04-14 16:46:13 -07001104 (set -x; curl -sSL https://git.io/get_helm.sh | DESIRED_VERSION=$HELM_VERSION USE_SUDO=false HELM_INSTALL_DIR=$GOPATH/bin bash >>"$LOG" 2>&1) >>"$LOG" 2>&1
1105 espin - "$VERIFIED"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001106 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001107fi
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -08001108
David Bainbridgee87067b2019-08-12 22:00:12 +00001109if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001110 NOW="$(date +%s)"
1111 printtime $((NOW - STIME))
David Bainbridgee87067b2019-08-12 22:00:12 +00001112fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001113
David Bainbridged18f4942020-04-14 16:46:13 -07001114STIME="$(date +%s)"
Test Userb5712372019-07-03 21:52:17 +00001115bspin "Verify voltctl $HIGH_VOLTAGE"
David Bainbridged2811972019-12-14 01:14:09 +00001116VOK=0
1117VMESSAGE="install"
David K. Bainbridgeebf38d92020-02-10 10:46:31 -08001118export VC_VERSION="$VOLTCTL_VERSION"
1119if [ "$VC_VERSION" == "latest" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001120 VC_VERSION="$(curl -sSL https://api.github.com/repos/opencord/voltctl/releases/latest | jq -r .tag_name | sed -e 's/^v//g')"; export VC_VERSION
David K. Bainbridgeebf38d92020-02-10 10:46:31 -08001121fi
David Bainbridged18f4942020-04-14 16:46:13 -07001122if [ -x "$GOPATH/bin/voltctl" ]; then
1123 VHAVE="$("$GOPATH/bin/voltctl" version --clientonly -o json | jq -r .version)"
1124 RESULT=$?
1125 if [ $RESULT -eq 0 ] && [ "$VHAVE" == "$VC_VERSION" ]; then
David Bainbridged2811972019-12-14 01:14:09 +00001126 VOK=1
David Bainbridged18f4942020-04-14 16:46:13 -07001127 espin "$VERIFIED"
David Bainbridge1ba64f12019-12-18 00:40:13 +00001128 else
David Bainbridged18f4942020-04-14 16:46:13 -07001129 VCHECK="$(echo -e "$VHAVE\n$VC_VERSION" | sort -V | head -1)"
David K. Bainbridgeebf38d92020-02-10 10:46:31 -08001130 if [ "$VCHECK" == "$VHAVE" ]; then
1131 VMESSAGE="upgrade"
1132 else
1133 VMESSAGE="downgrade"
1134 fi
David Bainbridged2811972019-12-14 01:14:09 +00001135 fi
1136fi
1137
David Bainbridged18f4942020-04-14 16:46:13 -07001138if [ "$VOK" -eq 0 ]; then
1139 espin "$NOT_VERIFIED"
David Bainbridged2811972019-12-14 01:14:09 +00001140 bspin - "Download and $VMESSAGE voltctl $DOWNLOAD"
David Bainbridged18f4942020-04-14 16:46:13 -07001141 (set -x; curl -o "$GOPATH/bin/voltctl" -sSL "https://github.com/opencord/voltctl/releases/download/v$VC_VERSION/voltctl-$VC_VERSION-$HOSTOS-$HOSTARCH" >>"$LOG" 2>&1) >>"$LOG" 2>&1
1142 (set -x; chmod 755 "$GOPATH/bin/voltctl" >>"$LOG" 2>&1) >>"$LOG" 2>&1
1143 espin - "$VERIFIED"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001144fi
David Bainbridgee87067b2019-08-12 22:00:12 +00001145if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001146 NOW="$(date +%s)"
1147 printtime $((NOW - STIME))
David Bainbridgee87067b2019-08-12 22:00:12 +00001148fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001149
1150bspin "Verify command PATH"
Test Userba1e7e72019-07-10 22:27:54 +00001151export PATH=$GOPATH/bin:$PATH
David Bainbridged18f4942020-04-14 16:46:13 -07001152espin "$VERIFIED"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001153
David Bainbridged18f4942020-04-14 16:46:13 -07001154STIME="$(date +%s)"
Test Userba1e7e72019-07-10 22:27:54 +00001155if [ "$DEPLOY_K8S" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001156 HAVE="$(kind get clusters | grep -c "voltha-$NAME")"
Test Userba1e7e72019-07-10 22:27:54 +00001157 bspin "Verify Kubernetes/Kind Cluster"
1158 sspin
David Bainbridged18f4942020-04-14 16:46:13 -07001159 if [ "$HAVE" -eq 0 ]; then
1160 espin "$NOT_VERIFIED"
David Bainbridge491b1bd2019-07-11 17:53:11 +00001161 bspin - "Verify cluster configuration"
David Bainbridged18f4942020-04-14 16:46:13 -07001162 if [ ! -r "./$NAME-cluster.cfg" ]; then
1163 espin - "$NOT_VERIFIED"
David K. Bainbridge43422402020-03-06 07:41:22 -08001164 bspin - "Download cluster configuration: $TYPE-cluster.cfg to $NAME-cluster.cfg $DOWNLOAD"
David Bainbridged18f4942020-04-14 16:46:13 -07001165 ERR_OUT="$(mktemp)"
1166 if ! (set -x; curl --fail -o "./$NAME-cluster.cfg" -sSL "https://raw.githubusercontent.com/ciena/kind-voltha/$VK_RELEASE/$TYPE-cluster.cfg" >>"$LOG" 2>>"$ERR_OUT") >>"$LOG" 2>&1; then
1167 espin - "$THEX"
1168 echo -e "${RED}${BOLD}${ERROR}ERROR: $NAME-cluster.cfg${NORMAL}${RED} - $(cat "$ERR_OUT")${NORMAL}"
1169 echo "ERROR: $(cat "$ERR_OUT")" >>"$LOG"
1170 rm -rf "$ERR_OUT" "./$NAME-cluster.cfg"
David K. Bainbridgea00736b2020-01-08 14:33:17 -08001171 exit 1
1172 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001173 rm -rf "$ERR_OUT"
David K. Bainbridgea00736b2020-01-08 14:33:17 -08001174 else
David Bainbridged18f4942020-04-14 16:46:13 -07001175 espin - "$VERIFIED"
David K. Bainbridgea00736b2020-01-08 14:33:17 -08001176 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001177 kind create cluster --name "voltha-$NAME" --config "$NAME-cluster.cfg"
David Bainbridge491b1bd2019-07-11 17:53:11 +00001178 else
David Bainbridged18f4942020-04-14 16:46:13 -07001179 espin "$VERIFIED"
Test Userba1e7e72019-07-10 22:27:54 +00001180 fi
1181
David Bainbridged18f4942020-04-14 16:46:13 -07001182 KUBECONFIG="$(kind get kubeconfig-path --name="voltha-$NAME")"; export KUBECONFIG
Test Userba1e7e72019-07-10 22:27:54 +00001183 P="coredns-.* \
David Bainbridge0774b232019-08-02 06:37:19 +00001184 etcd-voltha-$NAME-control-plane \
Test Userba1e7e72019-07-10 22:27:54 +00001185 kindnet-.* \
David Bainbridge0774b232019-08-02 06:37:19 +00001186 kube-apiserver-voltha-$NAME-control-plane \
1187 kube-controller-manager-voltha-$NAME-control-plane \
Test Userba1e7e72019-07-10 22:27:54 +00001188 kube-proxy-.* \
David Bainbridge0774b232019-08-02 06:37:19 +00001189 kube-scheduler-voltha-$NAME-control-plane"
Test Userba1e7e72019-07-10 22:27:54 +00001190
David Bainbridged18f4942020-04-14 16:46:13 -07001191 EXPECT="$(test "$TYPE" == "minimal" && echo "12" || echo "14")"
1192 wait_for_pods - "kube-system" "$EXPECT" "includes" "Waiting for system PODs to start" "$NO_LABEL" "$P"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001193fi
David Bainbridgee87067b2019-08-12 22:00:12 +00001194if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001195 NOW="$(date +%s)"
1196 printtime $((NOW - STIME))
David Bainbridgee87067b2019-08-12 22:00:12 +00001197fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001198
David Bainbridged18f4942020-04-14 16:46:13 -07001199STIME="$(date +%s)"
1200COUNT="$(count_pods "kube-system" ":Running:" "$NO_LABEL" "tiller-deploy-.*")"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001201bspin "Verify Helm"
David Bainbridged18f4942020-04-14 16:46:13 -07001202if [ "$COUNT" -ne 1 ]; then
1203 espin "$NOT_VERIFIED"
Test Userb5712372019-07-03 21:52:17 +00001204 echo -e "Configuring Helm $GEAR"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001205 if [ "$INSTALL_HELM" == "no" ]; then
1206 bspin - "Skip Helm/Tiller Initialization"
1207 espin - $NO_ENTRY
1208 else
1209 bspin - "Initialize Helm"
David Bainbridged18f4942020-04-14 16:46:13 -07001210 (set -x; helm init --upgrade >>"$LOG" 2>&1) >>"$LOG" 2>&1
1211 espin - "$VERIFIED"
1212 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 -07001213 fi
Test Userb5712372019-07-03 21:52:17 +00001214 bspin - "Add Google Incubator repository to Helm"
David Bainbridged18f4942020-04-14 16:46:13 -07001215 (set -x; helm repo add incubator https://kubernetes-charts-incubator.storage.googleapis.com >>"$LOG" 2>&1) >>"$LOG" 2>&1
1216 espin - "$VERIFIED"
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001217
Test Userba1e7e72019-07-10 22:27:54 +00001218 # HACK (sort-of) - the config for tiller is about to be patched, which will
1219 # cause the tiller pod to be recreated. This can sometimes cause a timing
1220 # issue with the "wait_for_pods" call on tiller as it may incorrectly
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001221 # identify the running/ready tiller pod that is soon to be terminated as
Test Userba1e7e72019-07-10 22:27:54 +00001222 # what it is waiting for. To avoid this issue we do a clean scale down and
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001223 # scale up of the pod so the script controlls when it should be expecting
Test Userba1e7e72019-07-10 22:27:54 +00001224 # things
David Bainbridged18f4942020-04-14 16:46:13 -07001225 (set -x; kubectl -n kube-system scale deploy tiller-deploy --replicas=0 >>"$LOG" 2>&1) >>"$LOG" 2>&1
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001226
Test Userb5712372019-07-03 21:52:17 +00001227 bspin - "Add Google Stable repository to Helm"
David Bainbridged18f4942020-04-14 16:46:13 -07001228 (set -x; helm repo add stable https://kubernetes-charts.storage.googleapis.com >>"$LOG" 2>&1) >>"$LOG" 2>&1
1229 espin - "$VERIFIED"
Test Userb5712372019-07-03 21:52:17 +00001230 bspin - "Add ONF repository to Helm"
David Bainbridged18f4942020-04-14 16:46:13 -07001231 (set -x; helm repo add onf https://charts.opencord.org >>"$LOG" 2>&1) >>"$LOG" 2>&1
1232 espin - "$VERIFIED"
Test Userb5712372019-07-03 21:52:17 +00001233 bspin - "Update Helm repository cache"
David Bainbridged18f4942020-04-14 16:46:13 -07001234 (set -x; helm repo update >>"$LOG" 2>&1) >>"$LOG" 2>&1
1235 espin - "$VERIFIED"
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001236
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001237 # Create and k8s service account so that Helm can create pods
Test Userb5712372019-07-03 21:52:17 +00001238 bspin - "Create Tiller ServiceAccount"
David Bainbridged18f4942020-04-14 16:46:13 -07001239 (set -x; kubectl create serviceaccount --namespace kube-system tiller >>"$LOG" 2>&1) >>"$LOG" 2>&1
1240 espin - "$VERIFIED"
Test Userb5712372019-07-03 21:52:17 +00001241 bspin - "Create Tiller ClusterRoleBinding"
David Bainbridged18f4942020-04-14 16:46:13 -07001242 (set -x; kubectl create clusterrolebinding tiller-cluster-rule --clusterrole=cluster-admin --serviceaccount=kube-system:tiller >>"$LOG" 2>&1) >>"$LOG" 2>&1
1243 espin - "$VERIFIED"
Test Userb5712372019-07-03 21:52:17 +00001244 bspin - "Update Tiller Manifest"
David Bainbridged18f4942020-04-14 16:46:13 -07001245 (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 +00001246
1247 # HACK (sort-of) - part to, spin it back up
David Bainbridged18f4942020-04-14 16:46:13 -07001248 (set -x; kubectl -n kube-system scale deploy tiller-deploy --replicas=1 >>"$LOG" 2>&1) >>"$LOG" 2>&1
1249 espin - "$VERIFIED"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001250else
David Bainbridged18f4942020-04-14 16:46:13 -07001251 if [ "$(helm version -s --template '{{.Server.SemVer}}')" != "$HELM_VERSION" ]; then
1252 espin "$NOT_VERIFIED"
David Bainbridgea34993d2020-04-01 09:15:42 -07001253 bspin - "Sync Tiller server version with helm client"
David Bainbridged18f4942020-04-14 16:46:13 -07001254 (set -x; helm init --upgrade --force-upgrade --wait >>"$LOG" 2>&1) >>"$LOG" 2>&1
1255 espin - "$VERIFIED"
David Bainbridgea34993d2020-04-01 09:15:42 -07001256 else
David Bainbridged18f4942020-04-14 16:46:13 -07001257 espin "$VERIFIED"
David Bainbridgea34993d2020-04-01 09:15:42 -07001258 fi
1259
David Bainbridge46505fb2019-10-01 21:13:20 +00001260 if [ "$UPDATE_HELM_REPOS" == "yes" ]; then
1261 bspin - "Update Helm repository cache"
David Bainbridged18f4942020-04-14 16:46:13 -07001262 (set -x; helm repo update >>"$LOG" 2>&1) >>"$LOG" 2>&1
1263 espin - "$VERIFIED"
David Bainbridge46505fb2019-10-01 21:13:20 +00001264 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001265fi
David Bainbridged18f4942020-04-14 16:46:13 -07001266wait_for_pods - "kube-system" 1 "includes" "Waiting for Tiller POD to start" "$NO_LABEL" "tiller-deploy-.*"
David Bainbridgee87067b2019-08-12 22:00:12 +00001267if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001268 NOW="$(date +%s)"
1269 printtime $((NOW - STIME))
David Bainbridgee87067b2019-08-12 22:00:12 +00001270fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001271
David Bainbridged18f4942020-04-14 16:46:13 -07001272STIME="$(date +%s)"
David Bainbridge0774b232019-08-02 06:37:19 +00001273bspin "Verify Helm values file: $NAME-values.yaml"
1274if [ ! -r "./$NAME-values.yaml" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001275 espin "$NOT_VERIFIED"
David Bainbridge0774b232019-08-02 06:37:19 +00001276 bspin - "Download Helm values file: $TYPE-values.yaml to $NAME-values.yaml $DOWNLOAD"
David Bainbridged18f4942020-04-14 16:46:13 -07001277 ERR_OUT="$(mktemp)"
1278 if ! (set -x; curl --fail -o "./$NAME-values.yaml" -sSL "https://raw.githubusercontent.com/ciena/kind-voltha/$VK_RELEASE/$TYPE-values.yaml" >>"$LOG" 2>"$ERR_OUT") >>"$LOG" 2>&1; then
1279 espin - "$THEX"
1280 echo -e "${RED}${BOLD}${ERROR}ERROR: $NAME-values.yaml${NORMAL}${RED} - $(cat "$ERR_OUT")${NORMAL}"
1281 echo "ERROR: $(cat "$ERR_OUT")" >>"$LOG"
1282 rm -rf "$ERR_OUT" "./$NAME-values.yaml"
David K. Bainbridgea00736b2020-01-08 14:33:17 -08001283 exit 1
1284 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001285 rm -rf "$ERR_OUT"
1286 espin - "$VERIFIED"
Test Userba1e7e72019-07-10 22:27:54 +00001287else
David Bainbridged18f4942020-04-14 16:46:13 -07001288 espin "$VERIFIED"
Test Userba1e7e72019-07-10 22:27:54 +00001289fi
David Bainbridgee87067b2019-08-12 22:00:12 +00001290if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001291 NOW="$(date +%s)"
1292 printtime $((NOW - STIME))
David Bainbridgee87067b2019-08-12 22:00:12 +00001293fi
Test Userba1e7e72019-07-10 22:27:54 +00001294
David Bainbridged18f4942020-04-14 16:46:13 -07001295STIME="$(date +%s)"
David Bainbridge99ac7a22019-08-31 02:26:43 +00001296bspin "Verify or download chart specific values files $DOWNLOAD"
1297VALUES_FILES="monkey-values.yaml"
David Bainbridged18f4942020-04-14 16:46:13 -07001298ERR_OUT="$(mktemp)"
David Bainbridge99ac7a22019-08-31 02:26:43 +00001299for i in $VALUES_FILES; do
1300 if [ ! -r ./$i ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001301 if ! (set -x; curl --fail -o "./$i" -sSL "https://raw.githubusercontent.com/ciena/kind-voltha/$VK_RELEASE/$i" >>"$LOG" 2>"$ERR_OUT") >>"$LOG" 2>&1; then
1302 espin "$THEX"
1303 echo -e "${RED}${BOLD}${ERROR}ERROR: $i${NORMAL}${RED} - $(cat "$ERR_OUT")${NORMAL}"
1304 echo "ERROR: $i - $(cat "$ERR_OUT")" >>"$LOG"
1305 rm -rf "$ERR_OUT" "./$i"
David K. Bainbridgea00736b2020-01-08 14:33:17 -08001306 exit 1
1307 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001308 rm -rf "$ERR_OUT"
David Bainbridge99ac7a22019-08-31 02:26:43 +00001309 fi
1310done
David Bainbridged18f4942020-04-14 16:46:13 -07001311rm -rf "$ERR_OUT"
1312espin "$VERIFIED"
David Bainbridge99ac7a22019-08-31 02:26:43 +00001313if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001314 NOW="$(date +%s)"
1315 printtime $((NOW - STIME))
David Bainbridge99ac7a22019-08-31 02:26:43 +00001316fi
1317
1318if [ "$WITH_CHAOS" == "yes" ]; then
1319 bspin "Verify or clone kube-monkey helm chart $DOWNLOAD"
1320 if [ -r ./kube-monkey ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001321 espin "$VERIFIED"
David Bainbridge99ac7a22019-08-31 02:26:43 +00001322 else
David Bainbridged18f4942020-04-14 16:46:13 -07001323 espin "$NOT_VERIFIED"
David Bainbridge99ac7a22019-08-31 02:26:43 +00001324 bspin - "GIT clone kube-monkey"
David Bainbridged18f4942020-04-14 16:46:13 -07001325 (set -x; git clone https://github.com/asobti/kube-monkey kube-monkey >>"$LOG" 2>&1) >>"$LOG" 2>&1
1326 espin - "$VERIFIED"
David Bainbridge99ac7a22019-08-31 02:26:43 +00001327 fi
1328fi
1329
Test Userba1e7e72019-07-10 22:27:54 +00001330if [ "$JUST_K8S" == "yes" ]; then
1331 echo "Environment deployed, not deploying VOLTHA artifacts as requested. Good bye."
1332 echo ""
David Bainbridged18f4942020-04-14 16:46:13 -07001333 echo "Please issue the following commands in your terminal to ensure that you" | tee -a "$LOG"
1334 echo "are accessing the correct Kubernetes/Kind cluster as well as have the " | tee -a "$LOG"
1335 echo "tools required by VOLTHA in your command path. " | tee -a "$LOG"
1336 echo "" | tee -a "$LOG"
1337 echo -en "$BOLD"
1338 if [ "$DEPLOY_K8S" == "yes" ]; then
1339 echo "export KUBECONFIG=\"\$(./bin/kind get kubeconfig-path --name=\"voltha-$NAME\")\"" | tee -a "$LOG"
Test Userba1e7e72019-07-10 22:27:54 +00001340 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001341 echo "export PATH=$GOPATH/bin:\$PATH" | tee -a "$LOG"
1342 echo -en "$NORMAL"
1343 echo "" | tee -a "$LOG"
1344 echo "Thank you for choosing kind-voltha for you quick cluster needs." | tee -a "$LOG"
Test Userba1e7e72019-07-10 22:27:54 +00001345 exit 0
1346fi
1347
David Bainbridged18f4942020-04-14 16:46:13 -07001348if [ "$WITH_ETCD" != "yes" ] && [ "$WITH_ETCD" != "external" ]; then
David Bainbridge696bc632020-04-05 21:49:37 -07001349 bspin "Skip ETCD Operator Deployment"
1350 espin $NO_ENTRY
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001351else
David Bainbridged18f4942020-04-14 16:46:13 -07001352 STIME="$(date +%s)"
David Bainbridge76afd812020-04-06 09:53:52 -07001353 NS=$VOLTHA_NS
David Bainbridged18f4942020-04-14 16:46:13 -07001354 if [ "$WITH_ETCD" == "external" ]; then
David Bainbridge76afd812020-04-06 09:53:52 -07001355 NS=$INFRA_NS
1356 fi
David Bainbridge696bc632020-04-05 21:49:37 -07001357 bspin "Verify ETCD Operator $OLD_KEY"
David Bainbridged18f4942020-04-14 16:46:13 -07001358 if [ "$HELM_USE_UPGRADE" == "yes" ] || [ "$(helm list --deployed --short --namespace "$NS" "^etcd-operator\$" | wc -l)" -ne 1 ]; then
1359 espin "$NOT_VERIFIED"
1360 helm_install - "$NS" etcd-operator stable/etcd-operator latest "$_HELM_DESC ETCD Operator"
David Bainbridge696bc632020-04-05 21:49:37 -07001361 else
David Bainbridged18f4942020-04-14 16:46:13 -07001362 espin "$VERIFIED"
David Bainbridge696bc632020-04-05 21:49:37 -07001363 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001364 EXPECT="$(test "$TYPE" == "minimal" && echo "1" || echo "3")"
1365 wait_for_pods - "$NS" "$EXPECT" "includes" "Waiting for ETCD Operator to start" "$NO_LABEL" "etcd-operator-.*"
David Bainbridge696bc632020-04-05 21:49:37 -07001366 if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001367 NOW="$(date +%s)"
1368 printtime $((NOW - STIME))
David Bainbridge696bc632020-04-05 21:49:37 -07001369 fi
David Bainbridgee87067b2019-08-12 22:00:12 +00001370fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001371
David Bainbridged18f4942020-04-14 16:46:13 -07001372STIME="$(date +%s)"
1373if [ "$WITH_ONOS" == "yes" ]; then
David Bainbridgeb270c202019-07-26 01:44:42 +00001374 bspin "Verify ONOS installed $BIRD"
David Bainbridged18f4942020-04-14 16:46:13 -07001375 if [ "$HELM_USE_UPGRADE" == "yes" ] || [ "$(helm list --deployed --short --namespace "$INFRA_NS" "^onos\$" | wc -l)" -ne 1 ]; then
1376 espin "$NOT_VERIFIED"
1377 EXTRA_HELM_FLAGS="$SET_TAG $EXTRA_HELM_FLAGS" helm_install - "$INFRA_NS" onos "$ONOS_CHART" "$ONOS_CHART_VERSION" "$_HELM_DESC ONOS"
David Bainbridgeb270c202019-07-26 01:44:42 +00001378 else
David Bainbridged18f4942020-04-14 16:46:13 -07001379 espin "$VERIFIED"
David Bainbridgeb270c202019-07-26 01:44:42 +00001380 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001381 wait_for_pods - "$INFRA_NS" 1 "includes" "Waiting for ONOS to start" "$NO_LABEL" "onos-.*"
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001382
David Bainbridged18f4942020-04-14 16:46:13 -07001383 if [ "$WITH_PORT_FORWARDS" == "yes" ]; then
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -08001384 bspin - "Forward ONOS API port $FORWARD"
1385 kill_port_forward onos-ui
David Bainbridged18f4942020-04-14 16:46:13 -07001386 port_forward "$INFRA_NS" onos-ui "$ONOS_API_PORT" 8181
1387 espin - "$VERIFIED"
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -08001388 bspin - "Forward ONOS SSH port $FORWARD"
1389 kill_port_forward onos-ssh
David Bainbridged18f4942020-04-14 16:46:13 -07001390 port_forward "$INFRA_NS" onos-ssh "$ONOS_SSH_PORT" 8101
1391 espin - "$VERIFIED"
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -08001392 _ONOS_API_EP="127.0.0.1:$ONOS_API_PORT"
1393 else
David Bainbridged18f4942020-04-14 16:46:13 -07001394 _ONOS_API_EP="$(get_service_ep "$INFRA_NS" onos-ui)"
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -08001395 fi
David Bainbridged31d6122019-08-13 19:37:59 +00001396 bspin - "Verify or download ONOS configuration support files $DOWNLOAD"
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001397 ONOS_FILES="olt-onos-enableExtraneousRules.json onos-aaa.json \
David Bainbridge696bc632020-04-05 21:49:37 -07001398 onos-dhcpl2relay.json onos-sadis-sample.json"
David Bainbridged18f4942020-04-14 16:46:13 -07001399 (set -x; mkdir -p ./onos-files >>"$LOG" 2>&1) >>"$LOG" 2>&1
1400 ERR_OUT="$(mktemp)"
David Bainbridge2b19e832019-08-16 02:40:53 +00001401 for i in $ONOS_FILES; do
David Bainbridged18f4942020-04-14 16:46:13 -07001402 if [ ! -r "./onos-files/$i" ]; then
1403 if ! (set -x; curl --fail -o "./onos-files/$i" -sSL "https://raw.githubusercontent.com/ciena/kind-voltha/$VK_RELEASE/onos-files/$i" >>"$LOG" 2>"$ERR_OUT") >>"$LOG" 2>&1; then
1404 espin - "$THEX"
1405 echo -e "${RED}${BOLD}${ERROR}ERROR: $i${NORMAL}${RED} - $(cat "$ERR_OUT")${NORMAL}"
1406 echo "ERROR: $(cat "$ERR_OUT")" >>"$LOG"
1407 rm -rf "$ERR_OUT" "./onos-files/$i"
David K. Bainbridgea00736b2020-01-08 14:33:17 -08001408 exit 1
1409 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001410 rm -rf "$ERR_OUT"
David Bainbridged31d6122019-08-13 19:37:59 +00001411 fi
1412 done
David Bainbridged18f4942020-04-14 16:46:13 -07001413 rm -rf "$ERR_OUT"
1414 espin - "$VERIFIED"
David Bainbridge27790d62019-08-13 22:43:19 +00001415
David Bainbridged18f4942020-04-14 16:46:13 -07001416 if [ "$INSTALL_ONOS_APPS" == "yes" ]; then
David Bainbridge27790d62019-08-13 22:43:19 +00001417 bspin - "Installing custom ONOS applications"
David Bainbridged18f4942020-04-14 16:46:13 -07001418 if [ -x onos-files/onos-apps ] && [ "$(find onos-files/onos-apps -name "*.oar" 2>/dev/null | wc -l)" -gt 0 ]; then
1419 for OAR in onos-files/onos-apps/*.oar; do
David Bainbridge27790d62019-08-13 22:43:19 +00001420 sspin - "Installing custom ONOS applications - $OAR$CEOL"
David Bainbridged18f4942020-04-14 16:46:13 -07001421 override_onos_app "$OAR"
David Bainbridge27790d62019-08-13 22:43:19 +00001422 done
1423 espin - "$VERIFIED Installing custom ONOS applications$CEOL"
1424 else
1425 espin - "$NOT_VERIFIED Installing custom ONOS applications - None Found"
1426 fi
1427 fi
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001428
David Bainbridged18f4942020-04-14 16:46:13 -07001429 if [ "$WITH_KAFKA" != "no" ]; then
David Bainbridge837e8bd2020-04-06 13:17:14 -07001430 check_onos_app_active org.opencord.kafka
David Bainbridge76afd812020-04-06 09:53:52 -07001431 _HOST=voltha-kafka.$INFRA_NS.svc.cluster.local
David Bainbridge837e8bd2020-04-06 13:17:14 -07001432 _PORT=9092
David Bainbridged18f4942020-04-14 16:46:13 -07001433 if [ "$WITH_KAFKA" == "yes" ]; then
David Bainbridge76afd812020-04-06 09:53:52 -07001434 _HOST=voltha-kafka.$VOLTHA_NS.svc.cluster.local
1435 _PORT=9092
David Bainbridged18f4942020-04-14 16:46:13 -07001436 elif [ "$WITH_KAFKA" == "external" ]; then
David Bainbridge76afd812020-04-06 09:53:52 -07001437 _HOST=kafka.$INFRA_NS.svc.cluster.local
1438 _PORT=9092
1439 else
David Bainbridged18f4942020-04-14 16:46:13 -07001440 _HOST="$(echo "$WITH_KAFKA" | cut -d: -f1)"
1441 _PORT="$(echo "$WITH_KAFKA" | cut -s -d: -f2)"
David Bainbridge837e8bd2020-04-06 13:17:14 -07001442 _PORT=${_PORT:-9092}
1443 fi
1444 push_onos_config "json" "Push ONOS Kafka Configuration" "network/configuration/apps/org.opencord.kafka" \
David Bainbridged18f4942020-04-14 16:46:13 -07001445 "$(cat <<EOJ | tr -d '[:space:]'
David Bainbridge696bc632020-04-05 21:49:37 -07001446{
1447 "kafka": {
1448 "bootstrapServers": "$_HOST:$_PORT"
1449 }
1450}
1451EOJ
David Bainbridged18f4942020-04-14 16:46:13 -07001452)"
David Bainbridge837e8bd2020-04-06 13:17:14 -07001453 fi
Matteo Scandolo9a77a732020-01-09 14:24:12 -08001454 check_onos_app_active org.opencord.dhcpl2relay
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001455 push_onos_config "file" "Push ONOS DHCP L2 Relay Configuration" "network/configuration/apps/org.opencord.dhcpl2relay" "onos-files/onos-dhcpl2relay.json"
Matteo Scandolo9a77a732020-01-09 14:24:12 -08001456 check_onos_app_active org.opencord.olt
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001457 # FIXME use WITH_DHCP and WITH_EAPOL flags to configre OLT App
Hardik Windlassa7501fb2020-02-17 14:28:20 +00001458 # Default value for "enableEapol" is true in OLT App
David Bainbridged18f4942020-04-14 16:46:13 -07001459 if [ "$WITH_EAPOL" == "yes" ]; then
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001460 push_onos_config "json" "Enable VOLTHA ONOS EAPOL provisioning" "configuration/org.opencord.olt.impl.OltFlowService" '{"enableEapol":true}'
David Bainbridged18f4942020-04-14 16:46:13 -07001461 elif [ "$WITH_EAPOL" == "no" ]; then
Hardik Windlassa7501fb2020-02-17 14:28:20 +00001462 push_onos_config "json" "Disable VOLTHA ONOS EAPOL provisioning" "configuration/org.opencord.olt.impl.OltFlowService" '{"enableEapol":false}'
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001463 fi
Hardik Windlassa7501fb2020-02-17 14:28:20 +00001464 # Default value for "enableDhcpOnProvisioning" is false and for "enableDhcpV4" is true in OLT App
David Bainbridged18f4942020-04-14 16:46:13 -07001465 if [ "$WITH_DHCP" == "yes" ]; then
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001466 push_onos_config "json" "Enable VOLTHA ONOS DHCP provisioning" "configuration/org.opencord.olt.impl.OltFlowService" '{"enableDhcpOnProvisioning":true,"enableDhcpV4":true}'
David Bainbridged18f4942020-04-14 16:46:13 -07001467 elif [ "$WITH_DHCP" == "no" ]; then
Hardik Windlassa7501fb2020-02-17 14:28:20 +00001468 push_onos_config "json" "Disable VOLTHA ONOS DHCP provisioning" "configuration/org.opencord.olt.impl.OltFlowService" '{"enableDhcpOnProvisioning":false,"enableDhcpV4":false}'
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001469 fi
Hardik Windlassa7501fb2020-02-17 14:28:20 +00001470 # Default value for "enableIgmpOnProvisioning" is false in OLT App
David Bainbridged18f4942020-04-14 16:46:13 -07001471 if [ "$WITH_IGMP" == "yes" ]; then
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001472 push_onos_config "json" "Enable VOLTHA ONOS IGMP provisioning" "configuration/org.opencord.olt.impl.OltFlowService" '{"enableIgmpOnProvisioning":true}'
David Bainbridged18f4942020-04-14 16:46:13 -07001473 elif [ "$WITH_IGMP" == "no" ]; then
Hardik Windlassa7501fb2020-02-17 14:28:20 +00001474 push_onos_config "json" "Disable VOLTHA ONOS IGMP provisioning" "configuration/org.opencord.olt.impl.OltFlowService" '{"enableIgmpOnProvisioning":false}'
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001475 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001476 if [ "$ENABLE_ONOS_EXTRANEOUS_RULES" == "yes" ]; then
David K. Bainbridge484d80c2020-03-05 21:44:34 -08001477 push_onos_config "file" "Enabling extraneous rules for ONOS" "configuration/org.onosproject.net.flow.impl.FlowRuleManager" "onos-files/olt-onos-enableExtraneousRules.json"
1478 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001479 if [ "$(echo ":yes:file:" | grep -c ":$CONFIG_SADIS:")" -eq 1 ]; then
Matteo Scandolo9a77a732020-01-09 14:24:12 -08001480 check_onos_app_active org.opencord.sadis
Hardik Windlassb3147602020-03-09 16:59:15 +05301481 push_onos_config "file" "[optional] Push ONOS SADIS Configuration: $SADIS_CFG" "network/configuration/apps/org.opencord.sadis" "$SADIS_CFG"
David K. Bainbridgeb859e912020-03-13 14:07:52 -07001482 elif [ "$CONFIG_SADIS" == "bbsim" ]; then
1483 push_onos_config "json" \
1484 "[optional] Push ONOS configuration for BBSIM SADIS servers" \
1485 "network/configuration/apps/org.opencord.sadis" \
David Bainbridged18f4942020-04-14 16:46:13 -07001486 "$(cat <<EOJ | tr -d '[:space:]'
David K. Bainbridgeb859e912020-03-13 14:07:52 -07001487{
1488 "sadis": {
1489 "integration": {
David Bainbridge76afd812020-04-06 09:53:52 -07001490 "url": "http://bbsim.$BBSIM_NS.svc.cluster.local:50074/v2/subscribers/%s",
David K. Bainbridgeb859e912020-03-13 14:07:52 -07001491 "cache": {
1492 "enabled": true,
1493 "maxsize": 50,
1494 "ttl": "PT1m"
1495 }
1496 }
1497 },
1498 "bandwidthprofile": {
1499 "integration": {
David Bainbridge76afd812020-04-06 09:53:52 -07001500 "url": "http://bbsim.$BBSIM_NS.svc.cluster.local:50074/v2/bandwidthprofiles/%s",
David K. Bainbridgeb859e912020-03-13 14:07:52 -07001501 "cache": {
1502 "enabled": true,
1503 "maxsize": 50,
1504 "ttl": "PT1m"
1505 }
1506 }
1507 }
1508}
1509EOJ
David Bainbridged18f4942020-04-14 16:46:13 -07001510)"
David K. Bainbridgeb859e912020-03-13 14:07:52 -07001511 elif [ "$CONFIG_SADIS" == "url" ]; then
1512 push_onos_config "json" \
1513 "[optional] Push ONOS configuration for custom SADIS and Bandwidth Profile servers" \
1514 "network/configuration/apps/org.opencord.sadis" \
David Bainbridged18f4942020-04-14 16:46:13 -07001515 "$(cat <<EOJ | tr -d '[:space:]'
David K. Bainbridgeb859e912020-03-13 14:07:52 -07001516{
1517 "sadis": {
1518 "integration": {
1519 "url": "$SADIS_SUBSCRIBERS",
1520 "cache": {
1521 "enabled": true,
1522 "maxsize": 50,
1523 "ttl": "PT1m"
1524 }
1525 }
1526 },
1527 "bandwidthprofile": {
1528 "integration": {
1529 "url": "$SADIS_BANDWIDTH_PROFILES",
1530 "cache": {
1531 "enabled": true,
1532 "maxsize": 50,
1533 "ttl": "PT1m"
1534 }
1535 }
1536 }
1537}
1538EOJ
David Bainbridged18f4942020-04-14 16:46:13 -07001539)"
David Bainbridge2b19e832019-08-16 02:40:53 +00001540 fi
Test Userba1e7e72019-07-10 22:27:54 +00001541fi
David Bainbridgee87067b2019-08-12 22:00:12 +00001542if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001543 NOW="$(date +%s)"
1544 printtime $((NOW - STIME))
David Bainbridgee87067b2019-08-12 22:00:12 +00001545fi
Test Userba1e7e72019-07-10 22:27:54 +00001546
David Bainbridged18f4942020-04-14 16:46:13 -07001547if [ "$WITH_ETCD" == "external" ]; then
1548 STIME="$(date +%s)"
David Bainbridge76afd812020-04-06 09:53:52 -07001549 bspin "Verify external ETCD cluster $OLD_KEY"
David Bainbridged18f4942020-04-14 16:46:13 -07001550 EXPECT="$(test "$TYPE" == "minimal" && echo "1" || echo "3")"
1551 if [ "$HELM_USE_UPGRADE" == "yes" ] || [ "$(helm list --deployed --short --namespace "$INFRA_NS" "^etcd-cluster\$" | wc -l)" -ne 1 ]; then
1552 espin "$NOT_VERIFIED"
David Bainbridge76afd812020-04-06 09:53:52 -07001553 INTERNAL_EXTRA_HELM_INSTALL_ARGS+="--set clusterName=etcd-cluster --set autoCompactionRetention=1 --set clusterSize=$EXPECT"
David Bainbridged18f4942020-04-14 16:46:13 -07001554 helm_install - "$INFRA_NS" etcd-cluster onf/voltha-etcd-cluster latest "$_HELM_DESC external ETCD cluster"
David Bainbridge76afd812020-04-06 09:53:52 -07001555 else
David Bainbridged18f4942020-04-14 16:46:13 -07001556 espin "$VERIFIED"
David Bainbridge76afd812020-04-06 09:53:52 -07001557 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001558 wait_for_pods - "$INFRA_NS" "$EXPECT" "includes" "Waiting for ETCD cluster to start" "$NO_LABEL" "etcd-cluster-.*"
David Bainbridge76afd812020-04-06 09:53:52 -07001559 if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001560 NOW="$(date +%s)"
1561 printtime $((NOW - STIME))
David Bainbridge76afd812020-04-06 09:53:52 -07001562 fi
1563fi
1564
David Bainbridged18f4942020-04-14 16:46:13 -07001565if [ "$WITH_KAFKA" == "external" ]; then
1566 _TMP="$(mktemp -u)"
1567 _COUNT="$(test "$TYPE" == "minimal" && echo "1" || echo "3")"
1568 cat << EOC > "$_TMP"
David Bainbridge76afd812020-04-06 09:53:52 -07001569configurationOverrides:
1570 "default.replication.factor": $_COUNT
1571 "offsets.topic.replication.factor": $_COUNT
1572 "log.retention.hours": 4
1573 "log.message.timestamp.type": "LogAppendTime"
1574persistence:
1575 enabled: false
1576zookeeper:
1577 replicaCount: 1
1578 persistence:
1579 enabled: false
1580replicas: $_COUNT
1581EOC
David Bainbridged18f4942020-04-14 16:46:13 -07001582 STIME="$(date +%s)"
David Bainbridge76afd812020-04-06 09:53:52 -07001583 bspin "Verify external Kafka cluster $OLD_KEY"
David Bainbridged18f4942020-04-14 16:46:13 -07001584 EXPECT="$(test "$TYPE" == "minimal" && echo "2" || echo "4")"
1585 if [ "$HELM_USE_UPGRADE" == "yes" ] || [ "$(helm list --deployed --short --namespace "$INFRA_NS" "^kafka\$" | wc -l)" -ne 1 ]; then
1586 espin "$NOT_VERIFIED"
David Bainbridge76afd812020-04-06 09:53:52 -07001587 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" -f $_TMP"
David Bainbridged18f4942020-04-14 16:46:13 -07001588 helm_install - "$INFRA_NS" kafka incubator/kafka latest "$_HELM_DESC external Kafka cluster"
David Bainbridge76afd812020-04-06 09:53:52 -07001589 else
David Bainbridged18f4942020-04-14 16:46:13 -07001590 espin "$VERIFIED"
David Bainbridge76afd812020-04-06 09:53:52 -07001591 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001592 wait_for_pods - "$INFRA_NS" "$EXPECT" "includes" "Waiting for Kafka cluster to start" "$NO_LABEL" "kafka-.*"
David Bainbridge76afd812020-04-06 09:53:52 -07001593 if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001594 NOW="$(date +%s)"
1595 printtime $((NOW - STIME))
David Bainbridge76afd812020-04-06 09:53:52 -07001596 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001597 rm -rf "$_TMP"
David Bainbridge76afd812020-04-06 09:53:52 -07001598fi
1599
David Bainbridged18f4942020-04-14 16:46:13 -07001600STIME="$(date +%s)"
David Bainbridge696bc632020-04-05 21:49:37 -07001601EXPECT=1
1602if [ "$ONLY_ONE" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001603 EXPECT="$((EXPECT+1))"
David Bainbridge696bc632020-04-05 21:49:37 -07001604 INTERNAL_EXTRA_HELM_INSTALL_ARGS="--set therecanbeonlyone=true"
1605else
David Bainbridged18f4942020-04-14 16:46:13 -07001606 EXPECT="$((EXPECT+2))"
David Bainbridge696bc632020-04-05 21:49:37 -07001607fi
Matteo Scandolo67335f02020-04-09 11:19:53 -07001608case $WITH_ETCD in
David Bainbridge76afd812020-04-06 09:53:52 -07001609 no)
1610 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set private_etcd_cluster=false"
1611 ;;
1612 yes)
1613 _HOST="voltha-etcd-cluster-client.$VOLTHA_NS.svc.cluster.local"
1614 _PORT=2379
1615 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set services.etcd.service=$_HOST --set services.etcd.port=$_PORT"
David Bainbridged18f4942020-04-14 16:46:13 -07001616 EXPECT="$((EXPECT+$(test "$TYPE" == "minimal" && echo "1" || echo "3")))"
David Bainbridge76afd812020-04-06 09:53:52 -07001617 ;;
1618 external)
1619 _HOST="etcd-cluster-client.$INFRA_NS.svc.cluster.local"
1620 _PORT=2379
1621 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set private_etcd_cluster=false --set services.etcd.service=$_HOST --set services.etcd.port=$_PORT"
1622 ;;
1623 *)
David Bainbridged18f4942020-04-14 16:46:13 -07001624 _HOST="$(echo "$WITH_ETCD" | cut -d: -f1)"
1625 _PORT="$(echo "$WITH_ETCD" | cut -s -d: -f2)"
David Bainbridge696bc632020-04-05 21:49:37 -07001626 _PORT=${_PORT:-2379}
David Bainbridge76afd812020-04-06 09:53:52 -07001627 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set private_etcd_cluster=false --set services.etcd.service=$_HOST --set services.etcd.port=$_PORT"
1628 ;;
1629esac
1630case $WITH_KAFKA in
1631 no)
1632 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set private_kafka_cluster=false"
1633 ;;
1634 yes)
1635 _HOST=voltha-kafka.$VOLTHA_NS.svc.cluster.local
1636 _PORT=9092
1637 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set kafka_broker=$_HOST:$_PORT --set services.kafka.adapter.service=$_HOST --set services.kafka.adapter.port=$_PORT --set services.kafka.cluster.service=$_HOST --set services.kafka.cluster.port=$_PORT"
David Bainbridged18f4942020-04-14 16:46:13 -07001638 EXPECT="$((EXPECT+$(test "$TYPE" == "minimal" && echo "2" || echo "4")))"
David Bainbridge76afd812020-04-06 09:53:52 -07001639 ;;
1640 external)
1641 _HOST=kafka.$INFRA_NS.svc.cluster.local
1642 _PORT=9092
1643 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set private_kafka_cluster=false --set kafka_broker=$_HOST:$_PORT --set services.kafka.adapter.service=$_HOST --set services.kafka.adapter.port=$_PORT --set services.kafka.cluster.service=$_HOST --set services.kafka.cluster.port=$_PORT"
1644 ;;
1645 *)
David Bainbridged18f4942020-04-14 16:46:13 -07001646 _HOST="$(echo "$WITH_KAFKA" | cut -d: -f1)"
1647 _PORT="$(echo "$WITH_KAFKA" | cut -s -d: -f2)"
David Bainbridge696bc632020-04-05 21:49:37 -07001648 _PORT=${_PORT:-9092}
David Bainbridge76afd812020-04-06 09:53:52 -07001649 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set private_kafka_cluster=false --set kafka_broker=$_HOST:$_PORT --set services.kafka.adapter.service=$_HOST --set services.kafka.adapter.port=$_PORT --set services.kafka.cluster.service=$_HOST --set services.kafka.cluster.port=$_PORT"
1650 ;;
1651esac
1652
David Bainbridged18f4942020-04-14 16:46:13 -07001653if [ "$WITH_ONOS" == "yes" ]; then
David Bainbridge76afd812020-04-06 09:53:52 -07001654 _HOST=onos-openflow.$INFRA_NS.svc.cluster.local
1655 _PORT=6653
1656 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set services.controller.service=$_HOST --set services.controller.port=$_PORT"
David Bainbridged18f4942020-04-14 16:46:13 -07001657elif [ "$WITH_ONOS" != "no" ]; then
1658 _HOST="$(echo "$WITH_ONOS" | cut -d: -f1)"
1659 _PORT="$(echo "$WITH_ONOS" | cut -s -d: -f2)"
David Bainbridge76afd812020-04-06 09:53:52 -07001660 _PORT=${_PORT:-6653}
1661 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set services.controller.service=$_HOST --set services.controller.port=$_PORT"
David Bainbridge696bc632020-04-05 21:49:37 -07001662fi
Test Userb5712372019-07-03 21:52:17 +00001663bspin "Verify VOLTHA installed $HIGH_VOLTAGE"
David Bainbridged18f4942020-04-14 16:46:13 -07001664if [ "$HELM_USE_UPGRADE" == "yes" ] || [ "$(helm list --deployed --short --namespace "$VOLTHA_NS" "^voltha\$" | wc -l)" -ne 1 ]; then
1665 espin "$NOT_VERIFIED"
1666 helm_install - "$VOLTHA_NS" voltha "$VOLTHA_CHART" "$VOLTHA_CHART_VERSION" "$_HELM_DESC VOLTHA Core"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001667else
David Bainbridged18f4942020-04-14 16:46:13 -07001668 espin "$VERIFIED"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001669fi
David Bainbridge696bc632020-04-05 21:49:37 -07001670INTERNAL_EXTRA_HELM_INSTALL_ARGS=
Test Userba1e7e72019-07-10 22:27:54 +00001671
David Bainbridge90fd8e32019-08-21 23:32:47 +00001672VOLTHA="voltha-ofagent-.* \
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001673 rw-core.* \
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001674 voltha-etcd-cluster-.* \
1675 voltha-kafka-.* \
1676 voltha-zookeeper-.*"
David Bainbridged18f4942020-04-14 16:46:13 -07001677wait_for_pods - "$VOLTHA_NS" "$EXPECT" "includes" "Waiting for VOLTHA Core to start" "$NO_LABEL" "$VOLTHA"
David Bainbridgee87067b2019-08-12 22:00:12 +00001678if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001679 NOW="$(date +%s)"
1680 printtime $((NOW - STIME))
David Bainbridgee87067b2019-08-12 22:00:12 +00001681fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001682
David Bainbridge46505fb2019-10-01 21:13:20 +00001683if [ "$WITH_ADAPTERS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001684 STIME="$(date +%s)"
David Bainbridge46505fb2019-10-01 21:13:20 +00001685 EXPECT=0
David Bainbridged18f4942020-04-14 16:46:13 -07001686 if [ "$WITH_ETCD" == "yes" ]; then
David Bainbridge3517f6c2020-04-08 12:14:08 -07001687 _HOST=voltha-etcd-cluster-client.$VOLTHA_NS.svc.cluster.local
1688 _PORT=2379
1689 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set services.etcd.service=$_HOST --set services.etcd.port=$_PORT"
David Bainbridged18f4942020-04-14 16:46:13 -07001690 elif [ "$WITH_ETCD" == "external" ]; then
David Bainbridge3517f6c2020-04-08 12:14:08 -07001691 _HOST=etcd-cluster-client.$INFRA_NS.svc.cluster.local
1692 _PORT=2379
1693 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set services.etcd.service=$_HOST --set services.etcd.port=$_PORT"
David Bainbridged18f4942020-04-14 16:46:13 -07001694 elif [ "$WITH_ETCD" != "no" ]; then
1695 _HOST="$(echo "$WITH_ETCD" | cut -d: -f1)"
1696 _PORT="$(echo "$WITH_ETCD" | cut -s -d: -f2)"
David Bainbridge3517f6c2020-04-08 12:14:08 -07001697 _PORT=${_PORT:-2379}
1698 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set services.etcd.service=$_HOST --set services.etcd.port=$_PORT"
David Bainbridge696bc632020-04-05 21:49:37 -07001699 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001700 if [ "$WITH_KAFKA" == "yes" ]; then
David Bainbridge3517f6c2020-04-08 12:14:08 -07001701 _HOST=voltha-kafka.$VOLTHA_NS.svc.cluster.local
1702 _PORT=9092
1703 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set kafka_broker=$_HOST:$_PORT --set services.kafka.adapter.service=$_HOST --set services.kafka.adapter.port=$_PORT --set services.kafka.cluster.service=$_HOST --set services.kafka.cluster.port=$_PORT"
David Bainbridged18f4942020-04-14 16:46:13 -07001704 elif [ "$WITH_KAFKA" == "external" ]; then
David Bainbridge3517f6c2020-04-08 12:14:08 -07001705 _HOST=kafka.$INFRA_NS.svc.cluster.local
1706 _PORT=9092
1707 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set kafka_broker=$_HOST:$_PORT --set services.kafka.adapter.service=$_HOST --set services.kafka.adapter.port=$_PORT --set services.kafka.cluster.service=$_HOST --set services.kafka.cluster.port=$_PORT"
David Bainbridged18f4942020-04-14 16:46:13 -07001708 elif [ "$WITH_KAFKA" != "no" ]; then
1709 _HOST="$(echo "$WITH_KAFKA" | cut -d: -f1)"
1710 _PORT="$(echo "$WITH_KAFKA" | cut -s -d: -f2)"
David Bainbridge3517f6c2020-04-08 12:14:08 -07001711 _PORT=${_PORT:-9092}
1712 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set kafka_broker=$_HOST:$_PORT --set services.kafka.adapter.service=$_HOST --set services.kafka.adapter.port=$_PORT --set services.kafka.cluster.service=$_HOST --set services.kafka.cluster.port=$_PORT"
David Bainbridge696bc632020-04-05 21:49:37 -07001713 fi
David Bainbridge46505fb2019-10-01 21:13:20 +00001714 echo -e "Verify Adapters $PLUG"
1715 if [ "$WITH_SIM_ADAPTERS" == "yes" ]; then
1716 bspin - "Verify Simulated Adapters installed"
David Bainbridged18f4942020-04-14 16:46:13 -07001717 if [ "$HELM_USE_UPGRADE" == "yes" ] || [ "$(helm list --deployed --short --namespace "$ADAPTER_NS" "^sim\$" | wc -l)" -ne 1 ]; then
1718 espin - "$NOT_VERIFIED"
1719 helm_install - "$ADAPTER_NS" sim "$VOLTHA_ADAPTER_SIM_CHART" "$VOLTHA_ADAPTER_SIM_CHART_VERSION" "$_HELM_DESC Simulated Adapters"
David Bainbridge46505fb2019-10-01 21:13:20 +00001720 else
David Bainbridged18f4942020-04-14 16:46:13 -07001721 espin - "$VERIFIED"
David Bainbridge46505fb2019-10-01 21:13:20 +00001722 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001723 EXPECT="$((EXPECT + 2))"
David Bainbridge46505fb2019-10-01 21:13:20 +00001724 fi
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001725
David Bainbridge46505fb2019-10-01 21:13:20 +00001726 if [ "$WITH_OPEN_ADAPTERS" == "yes" ]; then
1727 bspin - "Verify OpenOLT Adapter installed"
David Bainbridged18f4942020-04-14 16:46:13 -07001728 if [ "$HELM_USE_UPGRADE" == "yes" ] || [ "$(helm list --deployed --short --namespace "$ADAPTER_NS" "^open-olt\$" | wc -l)" -ne 1 ]; then
1729 espin - "$NOT_VERIFIED"
1730 helm_install - "$ADAPTER_NS" open-olt "$VOLTHA_ADAPTER_OPEN_OLT_CHART" "$VOLTHA_ADAPTER_OPEN_OLT_CHART_VERSION" "$_HELM_DESC OpenOLT Adapter"
David Bainbridge46505fb2019-10-01 21:13:20 +00001731 else
David Bainbridged18f4942020-04-14 16:46:13 -07001732 espin - "$VERIFIED"
David Bainbridge46505fb2019-10-01 21:13:20 +00001733 fi
Matteo Scandolo67335f02020-04-09 11:19:53 -07001734 EXPECT="$((EXPECT + 1))"
David Bainbridge46505fb2019-10-01 21:13:20 +00001735 bspin - "Verify OpenONU Adapter installed"
David Bainbridged18f4942020-04-14 16:46:13 -07001736 if [ "$HELM_USE_UPGRADE" == "yes" ] || [ "$(helm list --deployed --short --namespace "$ADAPTER_NS" "^open-onu\$" | wc -l)" -ne 1 ]; then
Matteo Scandolo67335f02020-04-09 11:19:53 -07001737 _ORIGINAL_EXTRA_HELM_INSTALL_ARGS="$INTERNAL_EXTRA_HELM_INSTALL_ARGS"
1738 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set replicas.adapter_open_onu=$NUM_OF_OPENONU"
David Bainbridged18f4942020-04-14 16:46:13 -07001739 espin - "$NOT_VERIFIED"
Matteo Scandolo67335f02020-04-09 11:19:53 -07001740 helm_install - "$ADAPTER_NS" open-onu "$VOLTHA_ADAPTER_OPEN_ONU_CHART" "$VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION" "$_HELM_DESC OpenONU Adapter"
1741 INTERNAL_EXTRA_HELM_INSTALL_ARGS="$_ORIGINAL_EXTRA_HELM_INSTALL_ARGS"
David Bainbridge46505fb2019-10-01 21:13:20 +00001742 else
David Bainbridged18f4942020-04-14 16:46:13 -07001743 espin - "$VERIFIED"
David Bainbridge46505fb2019-10-01 21:13:20 +00001744 fi
Matteo Scandolo67335f02020-04-09 11:19:53 -07001745 EXPECT=$((EXPECT + NUM_OF_OPENONU))
David Bainbridge46505fb2019-10-01 21:13:20 +00001746 fi
David Bainbridge696bc632020-04-05 21:49:37 -07001747 INTERNAL_EXTRA_HELM_INSTALL_ARGS=
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001748
David Bainbridge46505fb2019-10-01 21:13:20 +00001749 ADAPTERS="adapter-.*"
David Bainbridged18f4942020-04-14 16:46:13 -07001750 wait_for_pods - "$ADAPTER_NS" "$EXPECT" "includes" "Waiting for adapters to start" "$NO_LABEL" "$ADAPTERS"
David Bainbridge46505fb2019-10-01 21:13:20 +00001751 if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001752 NOW="$(date +%s)"
1753 printtime $((NOW - STIME))
David Bainbridge46505fb2019-10-01 21:13:20 +00001754 fi
David Bainbridgee87067b2019-08-12 22:00:12 +00001755fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001756
David Bainbridged18f4942020-04-14 16:46:13 -07001757if [ "$WITH_BBSIM" == "yes" ]; then
1758 STIME="$(date +%s)"
Test User7d866122019-07-09 17:52:35 +00001759 echo -e "Verify BBSIM $PLUG"
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001760 bspin - "Verify BBSIM Installed"
David Bainbridged18f4942020-04-14 16:46:13 -07001761 for instance in $(seq 0 $((NUM_OF_BBSIM-1))); do
1762 if [ "$instance" -eq 0 ]; then
David K. Bainbridge43422402020-03-06 07:41:22 -08001763 instance_num=""
1764 else
1765 instance_num=$instance
1766 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001767 if [ "$HELM_USE_UPGRADE" == "yes" ] || [ "$(helm list --deployed --short --namespace "$BBSIM_NS" "^bbsim${instance_num}\$" | wc -l)" -ne 1 ]; then
1768 espin - "$NOT_VERIFIED"
1769 S_TAG="$((900+instance))"
Matteo Scandolo5a149572020-04-01 10:14:57 -07001770 INTERNAL_EXTRA_HELM_INSTALL_ARGS="--set olt_id=$instance,s_tag=$S_TAG"
David Bainbridged18f4942020-04-14 16:46:13 -07001771 helm_install - "$BBSIM_NS" "bbsim${instance_num}" "$VOLTHA_BBSIM_CHART" "$VOLTHA_BBSIM_CHART_VERSION" "$_HELM_DESC BBSIM${instance_num}"
David Bainbridge2eaf2cf2020-03-18 12:54:08 -07001772 INTERNAL_EXTRA_HELM_INSTALL_ARGS=
David K. Bainbridge43422402020-03-06 07:41:22 -08001773 else
David Bainbridged18f4942020-04-14 16:46:13 -07001774 espin - "$VERIFIED"
David K. Bainbridge43422402020-03-06 07:41:22 -08001775 fi
1776 done
David Bainbridged18f4942020-04-14 16:46:13 -07001777 wait_for_pods - "$BBSIM_NS" "$NUM_OF_BBSIM" "includes" "Waiting for BBSIM to start" "$BBSIM_LABEL" "bbsim*"
David Bainbridgee87067b2019-08-12 22:00:12 +00001778 if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001779 NOW="$(date +%s)"
1780 printtime $((NOW - STIME))
David Bainbridgee87067b2019-08-12 22:00:12 +00001781 fi
Test User7d866122019-07-09 17:52:35 +00001782fi
1783
David Bainbridged18f4942020-04-14 16:46:13 -07001784if [ "$WITH_RADIUS" == "yes" ]; then
1785 STIME="$(date +%s)"
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001786 echo -e "Verify RADIUS $LOCK"
1787 bspin - "Verify RADIUS Installed"
David Bainbridged18f4942020-04-14 16:46:13 -07001788 if [ "$HELM_USE_UPGRADE" == "yes" ] || [ "$(helm list --deployed --short --namespace "$INFRA_NS" "^radius\$" | wc -l)" -ne 1 ]; then
1789 espin - "$NOT_VERIFIED"
1790 helm_install - "$INFRA_NS" radius onf/freeradius latest "$_HELM_DESC RADIUS"
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001791 else
David Bainbridged18f4942020-04-14 16:46:13 -07001792 espin - "$VERIFIED"
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001793 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001794 wait_for_pods - "$INFRA_NS" 1 "includes" "Waiting for RADIUS to start" "$NO_LABEL" "radius-.*"
David Bainbridgee87067b2019-08-12 22:00:12 +00001795 if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001796 NOW="$(date +%s)"
1797 printtime $((NOW - STIME))
David Bainbridgee87067b2019-08-12 22:00:12 +00001798 fi
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001799fi
1800
David Bainbridged18f4942020-04-14 16:46:13 -07001801if [ "$WITH_PORT_FORWARDS" == "yes" ]; then
1802 STIME="$(date +%s)"
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -08001803 bspin - "Forward VOLTHA API port $FORWARD"
1804 kill_port_forward voltha-api
David Bainbridged18f4942020-04-14 16:46:13 -07001805 port_forward "$VOLTHA_NS" voltha-api "$VOLTHA_API_PORT" 55555
1806 espin - "$VERIFIED"
1807 if [ "$WITH_ETCD" == "yes" ] || [ "$WITH_ETCD" == "external" ]; then
1808 _NS="$(test "$WITH_ETCD" == "yes" && echo "$VOLTHA_NS" || echo "$INFRA_NS")"
David Bainbridge696bc632020-04-05 21:49:37 -07001809 bspin - "Forward VOLTHA ETCD port $FORWARD"
David Bainbridged18f4942020-04-14 16:46:13 -07001810 kill_port_forward "${ETCD_PREFIX}etcd-cluster-client"
1811 port_forward "$_NS" "${ETCD_PREFIX}etcd-cluster-client" "$VOLTHA_ETCD_PORT" 2379
1812 espin - "$VERIFIED"
David Bainbridge696bc632020-04-05 21:49:37 -07001813 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001814 if [ "$WITH_KAFKA" == "yes" ] || [ $WITH_KAFKA == "external" ]; then
1815 _NS="$(test "$WITH_ETCD" == "yes" && echo "$VOLTHA_NS" || echo "$INFRA_NS")"
David Bainbridge696bc632020-04-05 21:49:37 -07001816 bspin - "Forward VOLTHA Kafka port $FORWARD"
David Bainbridged18f4942020-04-14 16:46:13 -07001817 kill_port_forward "${KAFKA_PREFIX}kafka"
1818 port_forward "$_NS" ${KAFKA_PREFIX}kafka "$VOLTHA_KAFKA_PORT" 9092
1819 espin - "$VERIFIED"
David Bainbridge696bc632020-04-05 21:49:37 -07001820 fi
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -08001821 if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001822 NOW="$(date +%s)"
1823 printtime $((NOW - STIME))
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -08001824 fi
David Bainbridgee87067b2019-08-12 22:00:12 +00001825fi
Test User3d7ad8e2019-07-03 06:15:44 +00001826
David Bainbridged18f4942020-04-14 16:46:13 -07001827if [ "$WITH_ONOS" == "yes" ] && [ "$WITH_RADIUS" != "no" ]; then
David Bainbridge76afd812020-04-06 09:53:52 -07001828 _HOST=radius.$INFRA_NS.svc.cluster.local
David Bainbridge696bc632020-04-05 21:49:37 -07001829 _PORT=1812
David Bainbridged18f4942020-04-14 16:46:13 -07001830 if [ "$WITH_RADIUS" != "yes" ]; then
1831 _HOST="$(echo "$WITH_RADIUS" | cut -d: -f1)"
1832 _PORT="$(echo "$WITH_RADIUS" | cut -s -d: -f2)"
David Bainbridge696bc632020-04-05 21:49:37 -07001833 _PORT=${_PORT:-1812}
1834 fi
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001835 bspin "Configure ONOS RADIUS Connection $GEAR"
David Bainbridged18f4942020-04-14 16:46:13 -07001836 (set -x; sed -e "s/:RADIUS_SVC:/$_HOST/g" -e "s/:RADIUS_PORT:/$_PORT/" onos-files/onos-aaa.json | curl --fail -sSL --user karaf:karaf -X POST "http://$_ONOS_API_EP/onos/v1/network/configuration/apps/org.opencord.aaa" -H Content-type:application/json -d@- >>"$LOG" 2>&1) >>"$LOG" 2>&1
1837 espin "$VERIFIED"
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001838fi
1839
David Bainbridge99ac7a22019-08-31 02:26:43 +00001840if [ "$WITH_CHAOS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001841 STIME="$(date +%s)"
David Bainbridge99ac7a22019-08-31 02:26:43 +00001842 echo -e "Verify kube-monkey $LOCK"
1843 bspin - "Verify kube-monkey Installed"
David Bainbridged18f4942020-04-14 16:46:13 -07001844 if [ "$HELM_USE_UPGRADE" == "yes" ] || [ "$(helm list --deployed --short --namespace kube-monkey "^monkey\$" | wc -l)" -ne 1 ]; then
1845 espin - "$NOT_VERIFIED"
David Bainbridge7f8bf992020-04-08 21:53:22 -07001846 helm_install - kube-monkey monkey ./kube-monkey/helm/kubemonkey latest "$_HELM_DESC Chaos Monkey"
David Bainbridge99ac7a22019-08-31 02:26:43 +00001847 else
David Bainbridged18f4942020-04-14 16:46:13 -07001848 espin - "$VERIFIED"
David Bainbridge99ac7a22019-08-31 02:26:43 +00001849 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001850 wait_for_pods - "kube-monkey" 1 "includes" "Waiting for Chaos to start" "$NO_LABEL" "monkey-.*"
David Bainbridge99ac7a22019-08-31 02:26:43 +00001851 if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001852 NOW="$(date +%s)"
1853 printtime $((NOW - STIME))
David Bainbridge99ac7a22019-08-31 02:26:43 +00001854 fi
1855fi
1856
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001857bspin "Create voltctl configuration file"
David Bainbridged18f4942020-04-14 16:46:13 -07001858(set -x; mkdir -p "$HOME/.volt" >>"$LOG" 2>&1) >>"$LOG" 2>&1
1859MIN_VC_VERSION="$(echo -e "1.0.15\n$VC_VERSION" | sort -V | head -1)"
1860if [ "$WITH_PORT_FORWARDS" == "yes" ]; then
David K. Bainbridgeb859e912020-03-13 14:07:52 -07001861 KAFKA_FLAG="-k localhost:$VOLTHA_KAFKA_PORT"
1862 SERVER_FLAG="-s localhost:$VOLTHA_API_PORT"
1863 ETCD_FLAG=
1864 if [ "$MIN_VC_VERSION" == "1.0.15" ]; then
1865 ETCD_FLAG="-e localhost:$VOLTHA_ETCD_PORT"
1866 fi
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -08001867else
David Bainbridged18f4942020-04-14 16:46:13 -07001868 KAFKA_FLAG="-k $(get_service_ep "$INFRA_NS" "${KAFKA_PREFIX}kafka")"
1869 SERVER_FLAG="-s $(get_service_ep "$VOLTHA_NS" voltha-api)"
David K. Bainbridgeb859e912020-03-13 14:07:52 -07001870 ETCD_FLAG=
1871 if [ "$MIN_VC_VERSION" == "1.0.15" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001872 ETCD_FLAG="-e $(get_service_ep "$INFRA_NS" ${ETCD_PREFIX}etcd-client)"
David K. Bainbridgeb859e912020-03-13 14:07:52 -07001873 fi
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -08001874fi
David Bainbridged18f4942020-04-14 16:46:13 -07001875CMD=("voltctl -a v3 $KAFKA_FLAG $SERVER_FLAG $ETCD_FLAG config")
1876(set -x; ${CMD[*]} > "$HOME/.volt/config-$NAME" 2>>"$LOG") >>"$LOG" 2>&1
1877#(set -x; voltctl -a v3 "$KAFKA_FLAG" "$SERVER_FLAG" "$ETCD_FLAG" config > "$HOME/.volt/config-$NAME" 2>>"$LOG") >>"$LOG" 2>&1
1878espin "$VERIFIED"
Test User08ebbd92019-07-03 17:15:39 +00001879
David Bainbridge0774b232019-08-02 06:37:19 +00001880if [ ! -f "$NAME-env.sh" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001881 touch "$NAME-env.sh"
David Bainbridgeb07fdf72019-07-29 22:51:40 +00001882fi
1883
David Bainbridge596f30d2019-07-30 17:07:59 +00001884for O in $ALL_OPTIONS; do
David Bainbridged18f4942020-04-14 16:46:13 -07001885 VAL="$(eval echo "\$$O")"
1886 if [ -n "$VAL" ] && [ "$(grep -c "^export $O=" "$NAME-env.sh")" -eq 0 ]; then
1887 echo "export $O=\"$(eval echo "\$$O")\"" >> "$NAME-env.sh"
David Bainbridgeb07fdf72019-07-29 22:51:40 +00001888 fi
1889done
1890
David Bainbridged18f4942020-04-14 16:46:13 -07001891if [ "$DEPLOY_K8S" == "yes" ] && [ "$(grep -c "^export KUBECONFIG=" "$NAME-env.sh")" -eq 0 ]; then
1892 echo "export KUBECONFIG=\"$(./bin/kind get kubeconfig-path "--name=voltha-$NAME")\"" >> "$NAME-env.sh"
David Bainbridgeb07fdf72019-07-29 22:51:40 +00001893fi
1894
David Bainbridged18f4942020-04-14 16:46:13 -07001895if [ "$(grep -c "^export VOLTCONFIG=" "$NAME-env.sh")" -eq 0 ]; then
1896 echo "export VOLTCONFIG=\"$HOME/.volt/config-$NAME\"" >> "$NAME-env.sh"
David Bainbridgeb07fdf72019-07-29 22:51:40 +00001897fi
1898
David Bainbridged18f4942020-04-14 16:46:13 -07001899if [ "$(grep -c "^export PATH=" "$NAME-env.sh")" -eq 0 ]; then
1900 echo "export PATH=\"$GOPATH/bin:\$PATH\"" >> "$NAME-env.sh"
David Bainbridgeb07fdf72019-07-29 22:51:40 +00001901fi
1902
Test User7d866122019-07-09 17:52:35 +00001903echo ""
David Bainbridged18f4942020-04-14 16:46:13 -07001904echo "Please issue the following commands in your terminal to ensure that you" | tee -a "$LOG"
1905echo "are accessing the correct Kubernetes/Kind cluster as well as have the " | tee -a "$LOG"
1906echo "tools required by VOLTHA in your command path. " | tee -a "$LOG"
1907echo "" | tee -a "$LOG"
1908echo -en "$BOLD"
1909if [ "$DEPLOY_K8S" == "yes" ]; then
1910 echo "export KUBECONFIG=\"\$(./bin/kind get kubeconfig-path --name=\"voltha-$NAME\")\"" | tee -a "$LOG"
Test Userba1e7e72019-07-10 22:27:54 +00001911fi
David Bainbridged18f4942020-04-14 16:46:13 -07001912echo "export VOLTCONFIG=\"$HOME/.volt/config-$NAME\"" | tee -a "$LOG"
1913echo "export PATH=$GOPATH/bin:\$PATH" | tee -a "$LOG"
1914echo -en "$NORMAL"
1915echo "" | tee -a "$LOG"
1916echo "Thank you for choosing kind-voltha for you quick cluster needs." | tee -a "$LOG"
Test User08ebbd92019-07-03 17:15:39 +00001917
David Bainbridge712afb82019-08-14 19:55:58 +00001918if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001919 NOW="$(date +%s)"
1920 echo -e "$CLOCK ${BOLD}TOTAL: $(duration $((NOW - TOTAL_START_TIME)))${NORMAL}"
David Bainbridge712afb82019-08-14 19:55:58 +00001921fi