blob: a8877424663c3f957659fa5c12236e935eed2a87 [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}
116MAX_NUM_OF_BBSIM=10
Test Userba1e7e72019-07-10 22:27:54 +0000117
David Bainbridged18f4942020-04-14 16:46:13 -0700118HOSTOS="$(uname -s | tr "[:upper:]" "[:lower:"])"
119HOSTARCH="$(uname -m | tr "[:upper:]" "[:lower:"])"
120if [ "$HOSTARCH" == "x86_64" ]; then
Test Userba1e7e72019-07-10 22:27:54 +0000121 HOSTARCH="amd64"
122fi
David Bainbridge7db44002020-04-09 12:54:29 -0700123BBSIM_LABEL="-l app=bbsim"
David Bainbridged18f4942020-04-14 16:46:13 -0700124NO_LABEL=
Test User7d866122019-07-09 17:52:35 +0000125
uottrembb16d3982020-02-28 08:34:36 +0100126# check number (range) of bbsim, max bbsim must not exceed 10 instances!
127# note: instances will be numbered from 0 to 9
128if [ "$1" == "up" ]; then
David K. Bainbridge43422402020-03-06 07:41:22 -0800129 if [ "$NUM_OF_BBSIM" -lt 1 ]; then
130 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} Invalid setting of BBSIM instances. NUM_OF_BBSIM is less than 1${NORMAL}"
131 exit 1
132 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700133 if [ "$NUM_OF_BBSIM" -gt "$MAX_NUM_OF_BBSIM" ]; then
David K. Bainbridge43422402020-03-06 07:41:22 -0800134 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} Invalid setting of BBSIM instances. NUM_OF_BBSIM is greater than $MAX_NUM_OF_BBSIM${NORMAL}"
135 exit 1
136 fi
uottrembb16d3982020-02-28 08:34:36 +0100137fi
Test User7d866122019-07-09 17:52:35 +0000138# Verify TYPE setting
David Bainbridged18f4942020-04-14 16:46:13 -0700139if [ "$(echo ":minimal:full:" | grep -ic ":$TYPE:")" -eq 0 ]; then
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700140 >&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 +0000141 exit 1
142fi
143
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700144function parseDuration() {
David Bainbridged18f4942020-04-14 16:46:13 -0700145 local DUR RESULT TERM TERMS VALUE UNIT
146 DUR=$1
147 RESULT=0
148 TERMS="$(echo "$DUR" | sed -Ee 's/([sSmMhHdD])/\1 /g' -e 's/,$//g')"
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700149 for TERM in $TERMS; do
David Bainbridged18f4942020-04-14 16:46:13 -0700150 VALUE="$(echo "$TERM" | sed -Ee 's/([0-9]+)[sSmMhHdD]/\1/')"
151 UNIT="$(echo "$TERM" | sed -Ee 's/[0-9]+([sSmMhHdD])/\1/')"
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700152 case $UNIT in
153 s|S)
David Bainbridged18f4942020-04-14 16:46:13 -0700154 RESULT=$((RESULT + VALUE)) ;;
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700155 m|M)
David Bainbridged18f4942020-04-14 16:46:13 -0700156 RESULT=$((RESULT + (VALUE * 60))) ;;
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700157 h|H)
David Bainbridged18f4942020-04-14 16:46:13 -0700158 RESULT=$((RESULT + (VALUE * 3600))) ;;
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700159 d|D)
David Bainbridged18f4942020-04-14 16:46:13 -0700160 RESULT=$((RESULT + (VALUE * 86400))) ;;
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700161 *) ;;
162 esac
163 done
164 echo $RESULT
165}
166
167function doTimeout() {
168 local MSG=$1
169 2>&1 echo -e "\n${RED}${BOLD}${ERROR}TIMEOUT:${NORMAL}${RED} Operation timed out after '$WAIT_TIMEOUT': $MSG"
170 exit 125
171}
172
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -0800173function get_service_ep() {
174 local NS=$1
175 local NAME=$2
David Bainbridged18f4942020-04-14 16:46:13 -0700176 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 -0800177}
178
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000179# Used to verify configuration values are set to "yes" or "no" value or convert
180# equivalents to "yes" or "no"
181function verify_yes_no() {
David Bainbridged18f4942020-04-14 16:46:13 -0700182 local VAR VAL
183 VAR=$1
184 VAL="$(eval echo "\$$VAR")"
185 if [ "$(echo ":y:yes:true:n:no:false:1:0:" | grep -ic ":$VAL:")" -eq 0 ]; then
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000186 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} Invalid '$VAR' value of '$VAL'. Should be 'yes' or 'no'${NORMAL}"
187 echo "INVALID"
188 return 1
189 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700190 if [ "$(echo ":y:yes:true:1:" | grep -ic ":$VAL:")" -eq 1 ]; then
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000191 echo "yes"
192 else
193 echo "no"
194 fi
195 return 0
196}
Test User7d866122019-07-09 17:52:35 +0000197
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000198ALL_YES_NO="\
David K. Bainbridge484d80c2020-03-05 21:44:34 -0800199 ENABLE_ONOS_EXTRANEOUS_RULES \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000200 WITH_TIMINGS \
201 WITH_BBSIM \
Matteo Scandolo78dfee02020-02-13 16:18:03 -0800202 WITH_EAPOL \
203 WITH_DHCP \
204 WITH_IGMP \
David Bainbridge99ac7a22019-08-31 02:26:43 +0000205 WITH_CHAOS \
David Bainbridge46505fb2019-10-01 21:13:20 +0000206 WITH_ADAPTERS \
207 WITH_SIM_ADAPTERS \
208 WITH_OPEN_ADAPTERS \
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -0800209 WITH_PORT_FORWARDS \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000210 JUST_K8S \
211 DEPLOY_K8S \
212 INSTALL_ONOS_APPS \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000213 INSTALL_KUBECTL \
214 INSTALL_HELM \
David Bainbridge7f8bf992020-04-08 21:53:22 -0700215 HELM_USE_UPGRADE \
David Bainbridge46505fb2019-10-01 21:13:20 +0000216 UPDATE_HELM_REPOS \
David Bainbridge4f1b5562019-08-19 04:46:52 +0000217 WAIT_ON_DOWN \
David Bainbridge70c0ea82019-11-14 23:25:26 +0000218 ONLY_ONE \
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700219 VOLTHA_DOWN_ON_TIMEOUT \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000220 "
David Bainbridge5b7b96b2019-07-25 20:29:13 +0000221
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000222ALL_OPTIONS="\
223 NAME \
224 TYPE \
225 $ALL_YES_NO \
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700226 WAIT_TIMEOUT \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000227 VOLTHA_LOG_LEVEL \
228 VOLTHA_CHART \
David Bainbridge90fd8e32019-08-21 23:32:47 +0000229 VOLTHA_CHART_VERSION \
230 VOLTHA_BBSIM_CHART \
231 VOLTHA_BBSIM_CHART_VERSION \
uottrembd5a20572020-03-06 09:15:01 +0100232 NUM_OF_BBSIM \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000233 VOLTHA_ADAPTER_SIM_CHART \
David Bainbridge90fd8e32019-08-21 23:32:47 +0000234 VOLTHA_ADAPTER_SIM_CHART_VERSION \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000235 VOLTHA_ADAPTER_OPEN_OLT_CHART \
David Bainbridge90fd8e32019-08-21 23:32:47 +0000236 VOLTHA_ADAPTER_OPEN_OLT_CHART_VERSION \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000237 VOLTHA_ADAPTER_OPEN_ONU_CHART \
David Bainbridge90fd8e32019-08-21 23:32:47 +0000238 VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION \
David K. Bainbridgeda33d652020-03-06 10:31:23 -0800239 ONOS_CHART \
Andrea Campanella21323292019-12-18 11:44:19 -0800240 ONOS_CHART_VERSION \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000241 ONOS_API_PORT \
242 ONOS_SSH_PORT \
David K. Bainbridgeb859e912020-03-13 14:07:52 -0700243 CONFIG_SADIS \
Hardik Windlassb3147602020-03-09 16:59:15 +0530244 SADIS_CFG \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000245 VOLTHA_API_PORT \
246 VOLTHA_SSH_PORT \
247 VOLTHA_ETCD_PORT \
David K. Bainbridge00ecd382020-02-28 12:31:58 -0800248 VOLTHA_KAFKA_PORT \
David K. Bainbridge8f7f30b2020-01-08 13:06:16 -0800249 VK_RELEASE \
250 KIND_VERSION \
251 VOLTCTL_VERSION \
David Bainbridgea34993d2020-04-01 09:15:42 -0700252 HELM_VERSION \
David Bainbridge696bc632020-04-05 21:49:37 -0700253 WITH_RADIUS \
254 WITH_KAFKA \
255 WITH_ETCD \
David Bainbridge76afd812020-04-06 09:53:52 -0700256 WITH_ONOS \
David Bainbridge6ca40102020-04-08 11:30:40 -0700257 VOLTHA_NS \
258 ADAPTER_NS \
259 INFRA_NS \
260 BBSIM_NS \
David Bainbridge7db44002020-04-09 12:54:29 -0700261 SADIS_BANDWIDTH_PROFILES \
262 SADIS_SUBSCRIBERS \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000263 "
David Bainbridge01294952019-07-30 19:33:45 +0000264
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000265# Iterate over yes/no configuration options and validate
266for VAR in $ALL_YES_NO; do
David Bainbridged18f4942020-04-14 16:46:13 -0700267 eval "$VAR"="$(verify_yes_no "$VAR")"
268 if [ "$(eval echo "\$$VAR")" == "INVALID" ]; then
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000269 exit 1;
270 fi
271done
David Bainbridgeb270c202019-07-26 01:44:42 +0000272
David Bainbridge15f6f232020-03-30 09:15:43 -0700273# Special case for CONFIG_SADIS
David Bainbridged18f4942020-04-14 16:46:13 -0700274if [ "$(echo ":y:yes:true:1:" | grep -ic ":$CONFIG_SADIS:")" -eq 1 ]; then
David Bainbridge15f6f232020-03-30 09:15:43 -0700275 CONFIG_SADIS="yes"
276fi
David Bainbridged18f4942020-04-14 16:46:13 -0700277if [ "$(echo ":n:no:false:0:" | grep -ic ":$CONFIG_SADIS:")" -eq 1 ]; then
David Bainbridge15f6f232020-03-30 09:15:43 -0700278 CONFIG_SADIS="no"
279fi
280
David Bainbridge76afd812020-04-06 09:53:52 -0700281# Special case for WITH_ONOS, WITH_RADIUS, WITH_KAFKA, and WITH_ETCD
David Bainbridged18f4942020-04-14 16:46:13 -0700282if [ "$(echo ":y:yes:true:1:" | grep -ic ":$WITH_KAFKA:")" -eq 1 ]; then
David Bainbridge696bc632020-04-05 21:49:37 -0700283 WITH_KAFKA="yes"
284fi
David Bainbridged18f4942020-04-14 16:46:13 -0700285if [ "$(echo ":n:no:false:0:" | grep -ic ":$WITH_KAFKA:")" -eq 1 ]; then
David Bainbridge696bc632020-04-05 21:49:37 -0700286 WITH_KAFKA="no"
287fi
David Bainbridged18f4942020-04-14 16:46:13 -0700288if [ "$(echo ":external:" | grep -ic ":$WITH_KAFKA:")" -eq 1 ]; then
David Bainbridge76afd812020-04-06 09:53:52 -0700289 WITH_KAFKA="external"
290fi
David Bainbridged18f4942020-04-14 16:46:13 -0700291if [ "$(echo ":y:yes:true:1:" | grep -ic ":$WITH_ETCD:")" -eq 1 ]; then
David Bainbridge696bc632020-04-05 21:49:37 -0700292 WITH_ETCD="yes"
293fi
David Bainbridged18f4942020-04-14 16:46:13 -0700294if [ "$(echo ":n:no:false:0:" | grep -ic ":$WITH_ETCD:")" -eq 1 ]; then
David Bainbridge696bc632020-04-05 21:49:37 -0700295 WITH_ETCD="no"
296fi
David Bainbridged18f4942020-04-14 16:46:13 -0700297if [ "$(echo ":external:" | grep -ic ":$WITH_ETCD:")" -eq 1 ]; then
David Bainbridge76afd812020-04-06 09:53:52 -0700298 WITH_ETCD="external"
299fi
David Bainbridged18f4942020-04-14 16:46:13 -0700300if [ "$(echo ":y:yes:true:1:" | grep -ic ":$WITH_RADIUS:")" -eq 1 ]; then
David Bainbridge29c31cb2020-04-06 09:45:50 -0700301 WITH_RADIUS="yes"
302fi
David Bainbridged18f4942020-04-14 16:46:13 -0700303if [ "$(echo ":n:no:false:0:" | grep -ic ":$WITH_RADIUS:")" -eq 1 ]; then
David Bainbridge29c31cb2020-04-06 09:45:50 -0700304 WITH_RADIUS="no"
305fi
David Bainbridged18f4942020-04-14 16:46:13 -0700306if [ "$(echo ":y:yes:true:1:" | grep -ic ":$WITH_ONOS:")" -eq 1 ]; then
David Bainbridge76afd812020-04-06 09:53:52 -0700307 WITH_ONOS="yes"
308fi
David Bainbridged18f4942020-04-14 16:46:13 -0700309if [ "$(echo ":n:no:false:0:" | grep -ic ":$WITH_ONOS:")" -eq 1 ]; then
David Bainbridge76afd812020-04-06 09:53:52 -0700310 WITH_ONOS="no"
311fi
David Bainbridge696bc632020-04-05 21:49:37 -0700312
David Bainbridged18f4942020-04-14 16:46:13 -0700313if [ "$HELM_USE_UPGRADE" == "yes" ]; then
David Bainbridge7f8bf992020-04-08 21:53:22 -0700314 _HELM_DESC="Upgrade/Install"
315else
316 _HELM_DESC="Install"
317fi
318
David Bainbridged18f4942020-04-14 16:46:13 -0700319ETCD_PREFIX=
320KAFKA_PREFIX=
321if [ "$WITH_ETCD" == "yes" ]; then
322 ETCD_PREFIX="voltha-"
323fi
324if [ "$WITH_KAFKA" == "yes" ]; then
325 KAFKA_PREFIX="voltha-"
326fi
327
David K. Bainbridgeda33d652020-03-06 10:31:23 -0800328# Check for prerequiste tools
David K. Bainbridge726ff6a2020-03-06 11:09:50 -0800329TOOLS="curl sed jq"
David Bainbridged18f4942020-04-14 16:46:13 -0700330if [ "$DEPLOY_K8S" == "yes" ]; then
David K. Bainbridgeda33d652020-03-06 10:31:23 -0800331 TOOLS+=" docker"
332fi
333NOT_FOUND=""
334for T in $TOOLS; do
David Bainbridged18f4942020-04-14 16:46:13 -0700335 if [ -z "$(command -v "$T")" ]; then
David K. Bainbridgeda33d652020-03-06 10:31:23 -0800336 NOT_FOUND+=" $T"
337 fi
338done
339
David Bainbridged18f4942020-04-14 16:46:13 -0700340if [ -n "$NOT_FOUND" ]; then
David K. Bainbridgeda33d652020-03-06 10:31:23 -0800341 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} The following required tools where not found, please install them:$NOT_FOUND"
342 exit 1
343fi
344
David Bainbridged18f4942020-04-14 16:46:13 -0700345TIMEOUT_SECONDS="$(parseDuration "$WAIT_TIMEOUT")"
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700346
David Bainbridge0774b232019-08-02 06:37:19 +0000347mkdir -p .voltha
348touch .voltha/ports
David Bainbridged18f4942020-04-14 16:46:13 -0700349HAVE="$(grep "$NAME" .voltha/ports)"
David Bainbridge0774b232019-08-02 06:37:19 +0000350if [ "$HAVE X" == " X" ]; then
351 # Find free port prefix
352 START=81
353 while true; do
David Bainbridged18f4942020-04-14 16:46:13 -0700354 if [ "$(grep -c $START .voltha/ports)" -eq 0 ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000355 break
356 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700357 START="$((START + 1))"
David Bainbridge0774b232019-08-02 06:37:19 +0000358 done
David Bainbridged18f4942020-04-14 16:46:13 -0700359 DELTA="$((START - 81))"
David Bainbridgea2595422019-10-22 03:54:28 +0000360 ONOS_API_PORT=${ONOS_API_PORT:-${START}81}
361 ONOS_SSH_PORT=${ONOS_SSH_PORT:-${START}01}
David Bainbridged18f4942020-04-14 16:46:13 -0700362 VOLTHA_API_PORT=${VOLTHA_API_PORT:-5$((55 + DELTA))55}
363 VOLTHA_SSH_PORT=${VOLTHA_SSH_PORT:-$((50 + DELTA))22}
364 VOLTHA_ETCD_PORT=${VOLTHA_ETCD_PORT:-$((23 + DELTA))79}
365 VOLTHA_KAFKA_PORT=${VOLTHA_KAFKA_PORT:-$((90 + DELTA))92}
Test User01ed0642019-07-03 20:17:06 +0000366else
David Bainbridged18f4942020-04-14 16:46:13 -0700367 VALUES="$(echo "$HAVE" | sed -e 's/\s//g' | cut -d= -f2)"
368 ONOS_API_PORT=${ONOS_API_PORT:-$(echo "$VALUES" | cut -d, -f1)}
369 ONOS_SSH_PORT=${ONOS_SSH_PORT:-$(echo "$VALUES" | cut -d, -f2)}
370 VOLTHA_API_PORT=${VOLTHA_API_PORT:-$(echo "$VALUES" | cut -d, -f3)}
371 VOLTHA_SSH_PORT=${VOLTHA_SSH_PORT:-$(echo "$VALUES" | cut -d, -f4)}
372 VOLTHA_ETCD_PORT=${VOLTHA_ETCD_PORT:-$(echo "$VALUES" | cut -d, -f5)}
373 VOLTHA_KAFKA_PORT=${VOLTHA_KAFKA_PORT:-$(echo "$VALUES" | cut -d, -f6)}
David K. Bainbridge00ecd382020-02-28 12:31:58 -0800374
David K. Bainbridge00ecd382020-02-28 12:31:58 -0800375 # A bit of a hueristic required here as the KAFKA port forward was
376 # added after the .voltha/ports files was created. Basically, if
377 # the VOLTHA_KAFKA_PORT isn't in the file then calculate the original
378 # DELTA from the VOLTHA_SSH_PORT and apply it to the VOLTHA_KAFKA_PORT
379 if [ -z "$VOLTHA_KAFKA_PORT" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -0700380 DELTA="$((VOLTHA_SSH_PORT/100-50))"
381 VOLTHA_KAFKA_PORT=${VOLTHA_KAFKA_PORT:-$((90 + DELTA))92}
David K. Bainbridge00ecd382020-02-28 12:31:58 -0800382 fi
Test User01ed0642019-07-03 20:17:06 +0000383fi
384
David Bainbridged18f4942020-04-14 16:46:13 -0700385PORTTMP="$(mktemp -u)"
386grep -v "$NAME" .voltha/ports > "$PORTTMP"
387echo "$NAME=$ONOS_API_PORT,$ONOS_SSH_PORT,$VOLTHA_API_PORT,$VOLTHA_SSH_PORT,$VOLTHA_ETCD_PORT,$VOLTHA_KAFKA_PORT" >> "$PORTTMP"
388cp "$PORTTMP" .voltha/ports
389rm -f "$PORTTMP"
David Bainbridge0774b232019-08-02 06:37:19 +0000390
David Bainbridge27790d62019-08-13 22:43:19 +0000391export ONOS_API_PORT ONOS_SSH_PORT
David Bainbridge01294952019-07-30 19:33:45 +0000392
Test Userd87942b2019-07-03 07:20:24 +0000393IDX=1
David Bainbridgee87067b2019-08-12 22:00:12 +0000394CLOCK="TIME:"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000395SPIN_PARTS=
396NOT_VERIFIED=
David Bainbridgef858a022019-08-14 21:25:11 +0000397THEX=
398BUILD=
David Bainbridge38dc1e82019-08-12 15:18:45 +0000399VERIFIED=
400HELM=
401OLD_KEY=
402BIRD=
403HIGH_VOLTAGE=
404PLUG=
David Bainbridge38dc1e82019-08-12 15:18:45 +0000405FORWARD=
David Bainbridge38dc1e82019-08-12 15:18:45 +0000406GO=
407DOWNLOAD=
408GEAR=
409NO_ENTRY=
410LOCK=
411
David Bainbridged18f4942020-04-14 16:46:13 -0700412if [ "$FANCY" -eq 1 ]; then
413 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 +0000414 CLOCK="\xe2\x8f\xb1"
David Bainbridgef858a022019-08-14 21:25:11 +0000415 THEX="${RED}${BOLD}\xe2\x9c\x97\x20${NORMAL}"
David Bainbridgef858a022019-08-14 21:25:11 +0000416 BUILD="${YELLOW}${BOLD}\xf0\x9f\x8f\x97${NORMAL}"
417 NOT_VERIFIED="$BUILD"
418 VERIFIED="${GREEN}${BOLD}\xe2\x9c\x93\x20${NORMAL}"
419 HELM="${BLUE}${BOLD}\xE2\x8E\x88${NORMAL}"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000420 OLD_KEY="\xF0\x9F\x97\x9D"
421 BIRD="\xF0\x9F\x90\xA6"
422 HIGH_VOLTAGE="\xE2\x9A\xA1"
423 PLUG="\xF0\x9F\xa7\xa9"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000424 FORWARD="\xE2\x87\xA8"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000425 GO="\xf0\x9f\x9a\x80"
426 DOWNLOAD="\xf0\x9f\x93\xa5"
427 GEAR="\xe2\x9a\x99"
428 NO_ENTRY="\xe2\x9b\x94"
429 LOCK="\xf0\x9f\x94\x92"
430fi
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700431
David Bainbridge712afb82019-08-14 19:55:58 +0000432duration() {
David Bainbridged18f4942020-04-14 16:46:13 -0700433 local h m s t
434 h="$(($1 / 3600))"
435 m="$(($1 % 3600 / 60))"
436 s="$(($1 % 60))"
437 t=""
David Bainbridgee87067b2019-08-12 22:00:12 +0000438
David Bainbridged18f4942020-04-14 16:46:13 -0700439 if [ "$h" -gt 0 ]; then
David Bainbridgee87067b2019-08-12 22:00:12 +0000440 t="$t${h}h"
441 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700442 if [ "$m" -gt 0 ]; then
David Bainbridgee87067b2019-08-12 22:00:12 +0000443 t="$t${m}m"
444 fi
David Bainbridge712afb82019-08-14 19:55:58 +0000445 echo "$t${s}s"
446}
447
448printtime() {
David Bainbridged18f4942020-04-14 16:46:13 -0700449 local INDENT
David Bainbridge712afb82019-08-14 19:55:58 +0000450 if [ "$1" == "-" ]; then
451 INDENT=" "
452 shift
453 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700454 echo -e "$INDENT $CLOCK $(duration "$1")"
David Bainbridgee87067b2019-08-12 22:00:12 +0000455}
456
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700457bspin() {
Test Userd87942b2019-07-03 07:20:24 +0000458 IDX=1
David Bainbridged18f4942020-04-14 16:46:13 -0700459 local INDENT
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700460 if [ "$1" == "-" ]; then
461 INDENT=" "
462 shift
463 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700464 if [ "$FANCY" -eq 0 ]; then
465 LINE="${*//[[:space:]+-]}"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000466 if [ "$LINE X" == " X" ]; then
467 return
468 fi
469 echo -e "$CIVIS$INDENT$*"
470 else
471 echo -en "$CIVIS$INDENT $*"
472 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700473}
474
475sspin() {
David Bainbridged18f4942020-04-14 16:46:13 -0700476 local INDENT
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700477 if [ "$1" == "-" ]; then
478 INDENT=" "
479 shift
480 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700481 if [ "$FANCY" -eq 0 ]; then
482 LINE="${*//[[:space:]+-]}"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000483 if [ "$LINE X" == " X" ]; then
484 return
485 fi
486 echo -e "$INDENT$*"
487 else
David Bainbridged18f4942020-04-14 16:46:13 -0700488 C="$(echo "$SPIN_PARTS" | cut '-d ' -f "$IDX")"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000489 echo -en "\r$INDENT$C $*"
David Bainbridged18f4942020-04-14 16:46:13 -0700490 IDX="$((IDX + 1))"
491 if [ "$IDX" -gt 8 ]; then
David Bainbridge38dc1e82019-08-12 15:18:45 +0000492 IDX=1
493 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700494 fi
495}
496
497espin() {
David Bainbridged18f4942020-04-14 16:46:13 -0700498 local INDENT
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700499 if [ "$1" == "-" ]; then
500 INDENT=" "
501 shift
502 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700503 if [ "$FANCY" -eq 0 ]; then
504 LINE="${*//[[:space:]+-]}"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000505 if [ "$LINE X" == " X" ]; then
506 return
507 fi
508 echo -e "$INDENT$*"
509 else
510 echo -e "\r$INDENT$*$CNORM"
511 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700512}
513
David Bainbridged18f4942020-04-14 16:46:13 -0700514if [ "$1" == "get" ] && [ "$2" == "voltconfig" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000515 echo "$HOME/.volt/config-$NAME"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000516 exit
517fi
518
David Bainbridged18f4942020-04-14 16:46:13 -0700519if [ $# -ne 1 ] || [ "$(echo ":up:down:dump:" | grep -c ":$1:")" -ne 1 ]; then
David Bainbridgeac7f8072019-08-01 22:15:33 +0000520 >&2 echo "What wouild you like to do today:"
521 >&2 echo " up - bring up voltha"
522 >&2 echo " down - tear down voltha"
523 >&2 echo " dump - create a debug dump of running system"
524 exit 1
525fi
526
David Bainbridge4f1b5562019-08-19 04:46:52 +0000527push_onos_config() {
David Bainbridged18f4942020-04-14 16:46:13 -0700528 local TYPE MSG RESOURCE DATA CMD_ECHO CMD_OUTPUT SC_OUTPUT WAIT_START NOW
529 TYPE=$1
530 MSG=$2
531 RESOURCE=$3
532 DATA=$4
David Bainbridge4f1b5562019-08-19 04:46:52 +0000533
David K. Bainbridgeb4b163b2020-02-19 15:55:06 -0800534 # Thanks to the latest version of ONOS using the return code 207 this gets a
535 # whole lot nastier. Can't thank them enough for doing this. So in order to
536 # capture the command and the output in the log file as well as capture the
537 # status code to verify it is 200 and not 207 mutltiple files and a bit of
538 # hackery must be used. Thanks again ONOS.
David Bainbridged18f4942020-04-14 16:46:13 -0700539 CMD_ECHO="$(mktemp -u)"
540 CMD_OUTPUT="$(mktemp -u)"
541 SC_OUTPUT="$(mktemp -u)"
542 WAIT_START="$(date +%s)"
David K. Bainbridgeb4b163b2020-02-19 15:55:06 -0800543
David Bainbridge4f1b5562019-08-19 04:46:52 +0000544 bspin - "$MSG $GEAR"
545 while true; do
David Bainbridged18f4942020-04-14 16:46:13 -0700546 NOW="$(date +%s)"
547 if [ "$((NOW - WAIT_START))" -gt "$TIMEOUT_SECONDS" ]; then
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700548 espin - "$THEX"
David Bainbridged18f4942020-04-14 16:46:13 -0700549 rm -f "$CMD_ECHO" "$CMD_OUTPUT" "$SC_OUTPUT"
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700550 doTimeout "waiting for ONOS config push on $RESOURCE"
551 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700552 if [ "$TYPE" == "file" ]; then
553 (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 -0700554 RESULT=$?
Matteo Scandolo78dfee02020-02-13 16:18:03 -0800555 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700556 if [ "$TYPE" == "json" ]; then
557 (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 -0700558 RESULT=$?
Matteo Scandolo78dfee02020-02-13 16:18:03 -0800559 fi
David K. Bainbridgeb4b163b2020-02-19 15:55:06 -0800560 # Dump everything to the log
David Bainbridged18f4942020-04-14 16:46:13 -0700561 cat "$CMD_ECHO" >> "$LOG"
562 test -r "$CMD_OUTPUT" && cat "$CMD_OUTPUT" >> "$LOG"
563 SC="$(cat "$SC_OUTPUT")"
564 echo "RESPONSE CODE: $SC" >> "$LOG"
565 echo "ERROR CODE: $RESULT" >> "$LOG"
David K. Bainbridgeb4b163b2020-02-19 15:55:06 -0800566
567 # clean up temp files
David Bainbridged18f4942020-04-14 16:46:13 -0700568 rm -f "$CMD_ECHO" "$CMD_OUTPUT" "$SC_OUTPUT"
569 if [ "$RESULT" -eq 0 ] && [ "$SC" == "200" ]; then
David Bainbridge4f1b5562019-08-19 04:46:52 +0000570 break
571 fi
Matteo Scandolo9a77a732020-01-09 14:24:12 -0800572 sleep 1
David Bainbridge4f1b5562019-08-19 04:46:52 +0000573 sspin -
574 done
David Bainbridged18f4942020-04-14 16:46:13 -0700575 espin - "$VERIFIED"
David Bainbridge4f1b5562019-08-19 04:46:52 +0000576}
577
Matteo Scandolo9a77a732020-01-09 14:24:12 -0800578check_onos_app_active() {
David Bainbridged18f4942020-04-14 16:46:13 -0700579 local APP_ID WAIT_START RESULT NOW
580 APP_ID=$1
581 WAIT_START="$(date +%s)"
Matteo Scandolo9a77a732020-01-09 14:24:12 -0800582
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700583 bspin - "Checking that $APP_ID is active $CLOCK"
584 while true; do
David Bainbridged18f4942020-04-14 16:46:13 -0700585 NOW="$(date +%s)"
586 if [ "$((NOW - WAIT_START))" -gt "$TIMEOUT_SECONDS" ]; then
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700587 espin - "$THEX"
588 doTimeout "waiting for ONOS application activation '$APP_ID'"
589 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700590 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 -0700591 break
592 fi
593 sleep 1
594 sspin -
595 done
596 sleep 5 # OSGI components take a little longer that the app to activate
David Bainbridged18f4942020-04-14 16:46:13 -0700597 espin - "$VERIFIED"
Matteo Scandolo9a77a732020-01-09 14:24:12 -0800598}
599
David Bainbridge4f1b5562019-08-19 04:46:52 +0000600override_onos_app() {
David Bainbridged18f4942020-04-14 16:46:13 -0700601 local APP NAME WAIT_START NOW
602 APP=$1
603 NAME="$(basename "$APP" | sed -e 's/^[0-9][0-9]*-//g' -e 's/-.*$//g')"
604 WAIT_START="$(date +%s)"
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700605
David Bainbridge4f1b5562019-08-19 04:46:52 +0000606 while true; do
David Bainbridged18f4942020-04-14 16:46:13 -0700607 NOW="$(date +%s)"
608 if [ "$((NOW - WAIT_START))" -gt "$TIMEOUT_SECONDS" ]; then
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700609 espin - "$THEX"
610 doTimeout "waiting to overwrite ONOS application '$APP'"
611 fi
David Bainbridge4f1b5562019-08-19 04:46:52 +0000612 sspin -
613 # Attempt to delete old version (if it exists)
David Bainbridged18f4942020-04-14 16:46:13 -0700614 (set -x; curl --fail -sSL --user karaf:karaf -X DELETE "http://$_ONOS_API_EP/onos/v1/applications/$NAME" >>"$LOG" 2>&1) >>"$LOG" 2>&1
615 RESULT=$?
David Bainbridge4f1b5562019-08-19 04:46:52 +0000616 sspin -
David Bainbridged18f4942020-04-14 16:46:13 -0700617 if [ $RESULT -ne 0 ]; then
David Bainbridge4f1b5562019-08-19 04:46:52 +0000618 continue
619 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700620 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 +0000621 break
622 fi
623 sleep .2
624 done
625}
626
627activate_onos_app() {
David Bainbridged18f4942020-04-14 16:46:13 -0700628 local MSG APP WAIT_START NOW
629 MSG="$1"
630 APP=$2
631 WAIT_START="$(date +%s)"
David Bainbridge4f1b5562019-08-19 04:46:52 +0000632
633 bspin - "$MSG $GO"
634 while true; do
David Bainbridged18f4942020-04-14 16:46:13 -0700635 NOW="$(date +%s)"
636 if [ "$((NOW - WAIT_START))" -gt "$TIMEOUT_SECONDS" ]; then
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700637 espin - "$THEX"
638 doTimeout "waiting to activate ONOS application '$APP'"
639 fi
David Bainbridge4f1b5562019-08-19 04:46:52 +0000640 sspin -
David Bainbridged18f4942020-04-14 16:46:13 -0700641 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 +0000642 break
643 fi
644 sleep .2
645 done
646 espin - "$VERIFIED"
647}
648
649count_pods() {
David Bainbridged18f4942020-04-14 16:46:13 -0700650 local NAMESPACE STATES LABELS CMD PODS
651 NAMESPACE=$1; shift
David Bainbridge4f1b5562019-08-19 04:46:52 +0000652 if [ "$NAMESPACE" == "all-namespaces" ]; then
653 NAMESPACE="--all-namespaces"
654 else
655 NAMESPACE="-n $NAMESPACE"
656 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700657 STATES=$1; shift
658 LABELS=$1; shift
659 CMD=("kubectl get $NAMESPACE $LABELS pod")
660 PODS=$(${CMD[*]} -o go-template="{{range .items}}{{.metadata.name}}/{{.status.phase}}/_{{range .status.containerStatuses}}{{.ready}}_{{end}} {{end}}")
David Bainbridge4f1b5562019-08-19 04:46:52 +0000661 local COUNT=0
662 local PATTERNS="$*"
663 for POD in $PODS; do
David Bainbridged18f4942020-04-14 16:46:13 -0700664 local NAME STATE CONTAINERS TOTAL FOUND
665 NAME="$(echo "$POD" | cut -d/ -f 1)"
666 STATE="$(echo "$POD" | cut -d/ -f 2)"
667 CONTAINERS="$(echo "$POD" | cut -d/ -f 3 | sed -e 's/_/ /g')"
668 if [ "$STATES" == "*" ] || [ "$(echo "$STATES" | grep -c ":$STATE:")" -ne 0 ]; then
669 TOTAL="$(echo "$CONTAINERS" | wc -w)"
670 FOUND="$(echo "$CONTAINERS" | grep -o true | wc -l)"
671 if [ "$TOTAL" -eq "$FOUND" ]; then
David Bainbridge4f1b5562019-08-19 04:46:52 +0000672 for PATTERN in $PATTERNS; do
David Bainbridged18f4942020-04-14 16:46:13 -0700673 if [[ "$NAME" =~ $PATTERN ]]; then
674 COUNT="$((COUNT + 1))"
David Bainbridge4f1b5562019-08-19 04:46:52 +0000675 break
676 fi
677 done
678 fi
679 fi
680 done
David Bainbridge4f1b5562019-08-19 04:46:52 +0000681 echo $COUNT
682}
683
684wait_for_pods() {
David Bainbridged18f4942020-04-14 16:46:13 -0700685 local INDENT NAMESPACE EXPECT TYPE MESSAGE LABELS PATTERNS STATES HAVE ALL WAIT_START NOW
David Bainbridge4f1b5562019-08-19 04:46:52 +0000686 if [ "$1" == "-" ]; then
687 INDENT=$1; shift
688 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700689 NAMESPACE=$1; shift
690 EXPECT=$1; shift
691 TYPE=$1; shift
692 MESSAGE=$1; shift
693 LABELS=$1; shift
694 PATTERNS=("$*")
695 STATES=":Running:"
David Bainbridge99ac7a22019-08-31 02:26:43 +0000696 if [ "$TYPE" == "not" ]; then
697 STATES="*"
698 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700699 HAVE="$(count_pods "$NAMESPACE" "$STATES" "$LABELS" "${PATTERNS[@]}")"
700 ALL=$HAVE
David Bainbridge4f1b5562019-08-19 04:46:52 +0000701 if [ "$TYPE" == "only" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -0700702 ALL="$(count_pods "all-namespaces" "*" ".*")"
David Bainbridge4f1b5562019-08-19 04:46:52 +0000703 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700704 COUNT="$((300 / 15))"
705 WAIT_START="$(date +%s)"
706 bspin "$INDENT" "$MESSAGE"
707 sspin "$INDENT"
708 if [ "$HAVE" -ne "$EXPECT" ] || [ "$ALL" -ne "$HAVE" ]; then
709 while [ "$HAVE" -ne "$EXPECT" ] || [ "$ALL" -ne "$HAVE" ]; do
710 NOW="$(date +%s)"
711 if [ "$((NOW - WAIT_START))" -gt "$TIMEOUT_SECONDS" ]; then
712 espin "$INDENT" "$THEX"
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700713 doTimeout "waiting for PODs to start"
714 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700715 sspin "$INDENT"
716 COUNT="$((COUNT - 1))"
717 if [ "$COUNT" -eq 0 ]; then
718 HAVE="$(count_pods "$NAMESPACE" "$STATES" "$LABELS" "${PATTERNS[@]}")"
719 ALL="$HAVE"
David Bainbridge4f1b5562019-08-19 04:46:52 +0000720 if [ "$TYPE" == "only" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -0700721 ALL="$(count_pods "all-namespaces" "*" ".*")"
David Bainbridge4f1b5562019-08-19 04:46:52 +0000722 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700723 COUNT="$((300 / 15))"
David Bainbridge4f1b5562019-08-19 04:46:52 +0000724 fi
725 sleep .15
726 done
727 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700728 espin "$INDENT" "$VERIFIED"
729 if [ "$HAVE" -ne "$EXPECT" ]; then
David Bainbridge4f1b5562019-08-19 04:46:52 +0000730 return 1
731 fi
732 return 0
733}
734
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800735port_forward() {
736 local NS=$1
737 local SVC=$2
738 local FROM_PORT=$3
739 local TO_PORT=$4
740 local TAG=$SVC-$NAME
741
David Bainbridged18f4942020-04-14 16:46:13 -0700742 (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 -0800743}
744
745kill_port_forward() {
David Bainbridged18f4942020-04-14 16:46:13 -0700746 local TAG P_IDS PARENTS KIDS UNKNOWN PP_ID
747 TAG="$1-$NAME"
748 # shellcheck disable=SC2009
749 P_IDS="$(ps e -ww -A | grep "_TAG=$TAG" | grep -v grep | awk '{print $1}')"
750 if [ -n "$P_IDS" ]; then
David Bainbridgec6871d22019-11-13 17:10:31 +0000751 for P_ID in $P_IDS; do
David Bainbridged18f4942020-04-14 16:46:13 -0700752 PP_ID="$(ps -o ppid "$P_ID" | tail -n +2)"
753 if [ -n "$PP_ID" ]; then
754 if [ "$PP_ID" -eq 1 ]; then
David Bainbridgec6871d22019-11-13 17:10:31 +0000755 PARENTS="$PARENTS $P_ID"
756 else
757 KIDS="$KIDS $P_ID"
758 fi
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800759 else
David Bainbridgec6871d22019-11-13 17:10:31 +0000760 UNKNOWN="$UNKNOWN $P_ID"
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800761 fi
762 done
David Bainbridged18f4942020-04-14 16:46:13 -0700763 (set -x; kill -9 "$PARENTS" "$KIDS" "$UNKNOWN" >>"$LOG" 2>&1) >>"$LOG" 2>&1
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800764 fi
765}
766
David Bainbridgeac7f8072019-08-01 22:15:33 +0000767if [ "$1" == "down" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000768 echo "Tearing down voltha cluster $NAME"
769 LOG="down-$NAME.log"
David Bainbridged18f4942020-04-14 16:46:13 -0700770 date -u +"%Y%m%dT%H%M%SZ" >"$LOG"
771 if [ "$WITH_ONOS" == "yes" ]; then
David Bainbridge696bc632020-04-05 21:49:37 -0700772 bspin "Remove port-forwards: onos-ui-$NAME"
773 kill_port_forward onos-ui
774 sspin "Remove port-forwards: onos-ssh-$NAME$CEOL"
775 kill_port_forward onos-ssh
776 fi
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800777 sspin "Remove port-forwards: voltha-api-$NAME$CEOL"
778 kill_port_forward voltha-api
David Bainbridged18f4942020-04-14 16:46:13 -0700779 if [ "$WITH_ETCD" == "yes" ] || [ "$WITH_ETCD" == "external" ]; then
780 sspin "Remove port-forwards: ${ETCD_PREFIX}etcd-$NAME$CEOL"
781 kill_port_forward "${ETCD_PREFIX}etcd-cluster-client"
David Bainbridge696bc632020-04-05 21:49:37 -0700782 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700783 if [ "$WITH_KAFKA" == "yes" ] || [ "$WITH_KAFKA" == "external" ]; then
784 sspin "Remove port-forwards: ${KAFKA_PREFIX}kafka-$NAME$CEOL"
785 kill_port_forward "${KAFKA_PREFIX}kafka"
David Bainbridge696bc632020-04-05 21:49:37 -0700786 fi
787
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800788 espin "$VERIFIED Remove port-forwards$CEOL"
David Bainbridged18f4942020-04-14 16:46:13 -0700789 if [ "$DEPLOY_K8S" == "yes" ]; then
David Bainbridgeac7f8072019-08-01 22:15:33 +0000790 if [ -x ./bin/kind ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000791 bspin "Delete Kubernetes Kind Cluster"
David Bainbridged18f4942020-04-14 16:46:13 -0700792 (set -x; ./bin/kind delete cluster --name "voltha-$NAME" >>"$LOG" 2>&1) >>"$LOG" 2>&1
793 espin "$VERIFIED"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000794 else
David Bainbridge0774b232019-08-02 06:37:19 +0000795 espin "$NO_ENTRY Delete Kubernetes Kind Cluster: kind command not found"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000796 fi
797 else
David Bainbridged18f4942020-04-14 16:46:13 -0700798 EXISTS="$(helm list -q)"
David Bainbridge76afd812020-04-06 09:53:52 -0700799 EXPECT="voltha"
David Bainbridged18f4942020-04-14 16:46:13 -0700800 if [ "$WITH_ONOS" == yes ]; then
David Bainbridge696bc632020-04-05 21:49:37 -0700801 EXPECT+=" onos"
802 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700803 if [ "$WITH_RADIUS" == "yes" ]; then
David Bainbridge696bc632020-04-05 21:49:37 -0700804 EXPECT+=" radius"
805 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700806 if [ "$WITH_BBSIM" == "yes" ]; then
David Bainbridge696bc632020-04-05 21:49:37 -0700807 EXPECT+=" bbsim"
808 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700809 if [ "$WITH_OPEN_ADAPTERS" == "yes" ]; then
David Bainbridge696bc632020-04-05 21:49:37 -0700810 EXPECT+=" open-olt open-onu"
811 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700812 if [ "$WITH_SIM_ADAPTERS" == "yes" ]; then
David Bainbridge696bc632020-04-05 21:49:37 -0700813 EXPECT+=" sim"
814 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700815 if [ "$WITH_ETCD" == "external" ]; then
David Bainbridge76afd812020-04-06 09:53:52 -0700816 EXPECT+=" etcd-operator etcd-cluster"
David Bainbridged18f4942020-04-14 16:46:13 -0700817 elif [ "$WITH_ETCD" == "yes" ]; then
David Bainbridge76afd812020-04-06 09:53:52 -0700818 EXPECT+=" etcd-operator"
819 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700820 if [ "$WITH_KAFKA" == "external" ]; then
David Bainbridge76afd812020-04-06 09:53:52 -0700821 EXPECT+=" kafka"
822 fi
David Bainbridge0774b232019-08-02 06:37:19 +0000823 bspin "Remove Helm Deployments"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000824 for i in $EXISTS; do
David K. Bainbridge43422402020-03-06 07:41:22 -0800825 for j in $EXPECT; do
David Bainbridged18f4942020-04-14 16:46:13 -0700826 if [[ "$i" =~ $j ]]; then
David K. Bainbridge43422402020-03-06 07:41:22 -0800827 sspin "Remove Helm Deployments: $i$CEOL"
David Bainbridged18f4942020-04-14 16:46:13 -0700828 (set -x; ./bin/helm delete --no-hooks --purge "$i" >>"$LOG" 2>&1) >>"$LOG" 2>&1
David K. Bainbridge43422402020-03-06 07:41:22 -0800829 fi
830 done
uottrembb16d3982020-02-28 08:34:36 +0100831 done
David Bainbridge0774b232019-08-02 06:37:19 +0000832 espin "$VERIFIED Remove Helm Deployments$CEOL"
David Bainbridge4f1b5562019-08-19 04:46:52 +0000833 if [ "$WAIT_ON_DOWN" == "yes" ]; then
David Bainbridge76afd812020-04-06 09:53:52 -0700834 PODS="voltha-kafka.* voltha-ofagent.* voltha-rw-core.* voltha-etcd.*"
835 INFRA_PODS=
836 ADAPT_PODS=
837 SIM_PODS=
David Bainbridged18f4942020-04-14 16:46:13 -0700838 if [ "$WITH_RADIUS" == "yes" ]; then
David Bainbridge696bc632020-04-05 21:49:37 -0700839 PODS+=" radius.*"
840 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700841 if [ "$WITH_BBSIM" == "yes" ]; then
David Bainbridge76afd812020-04-06 09:53:52 -0700842 SIM_PODS+=" bbsim.*"
David Bainbridge696bc632020-04-05 21:49:37 -0700843 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700844 if [ "$WITH_OPEN_ADAPTERS" ] || [ "$WITH_SIM_ADAPTERS" ]; then
David Bainbridge76afd812020-04-06 09:53:52 -0700845 ADAPT_PODS+=" adapter-*"
David Bainbridge696bc632020-04-05 21:49:37 -0700846 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700847 if [ "$WITH_ONOS" == "yes" ]; then
David Bainbridge76afd812020-04-06 09:53:52 -0700848 INFRA_PODS+=" onos-.*"
849 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700850 if [ "$WITH_ETCD" == "external" ]; then
David Bainbridge76afd812020-04-06 09:53:52 -0700851 INFRA_PODS+=" etcd-operator.* etcd-cluster.*"
David Bainbridged18f4942020-04-14 16:46:13 -0700852 elif [ "$WITH_ETCD" == "yes" ]; then
David Bainbridge76afd812020-04-06 09:53:52 -0700853 PODS+=" etcd-operator.*"
854 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700855 if [ "$WITH_KAFKA" == "external" ]; then
David Bainbridge76afd812020-04-06 09:53:52 -0700856 INFRA_PODS+=" kafka.*"
857 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700858 if [ -n "$SIM_PODS" ]; then
859 wait_for_pods "$BBSIM_NS" 0 "not" "Waiting for BBSIM PODs to terminate" "$BBSIM_LABEL" "$SIM_PODS"
David Bainbridge76afd812020-04-06 09:53:52 -0700860 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700861 if [ -n "$INFRA_PODS" ]; then
862 wait_for_pods "$INFRA_NS" 0 "not" "Waiting for infrastructure PODs to terminate" "$NO_LABEL" "$INFRA_PODS"
David Bainbridge76afd812020-04-06 09:53:52 -0700863 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700864 if [ -n "$ADAPT_PODS" ]; then
865 wait_for_pods "$ADAPTER_NS" 0 "not" "Waiting for adapter PODs to terminate" "$NO_LABEL" "$ADAPT_PODS"
David Bainbridge76afd812020-04-06 09:53:52 -0700866 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700867 wait_for_pods "$VOLTHA_NS" 0 "not" "Waiting for VOLTHA PODs to terminate" "$NO_LABEL" "$PODS"
David Bainbridge4f1b5562019-08-19 04:46:52 +0000868 fi
David Bainbridgeac7f8072019-08-01 22:15:33 +0000869 fi
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -0700870 exit
David Bainbridgeac7f8072019-08-01 22:15:33 +0000871fi
872
873if [ "$1" == "dump" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000874 LOG="dump-$NAME.log"
David Bainbridged18f4942020-04-14 16:46:13 -0700875 TS="$(date -u +"%Y%m%dT%H%M%SZ")"
876 if [ -n "$DUMP_FROM" ]; then
877 TS=${DUMP_FROM//[:-]}
David Bainbridge76514a02019-10-08 01:50:35 +0000878 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700879 WORK="$(mktemp -u -d)"
David Bainbridge0774b232019-08-02 06:37:19 +0000880 DATA=$WORK/voltha-debug-dump-$NAME-$TS
David Bainbridged18f4942020-04-14 16:46:13 -0700881 mkdir -p "$DATA"
882 echo "$TS" > "$LOG"
David Bainbridge0774b232019-08-02 06:37:19 +0000883 echo -e "Capturing debug dump to voltha-debug-dump-$NAME-$TS.tgz"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000884 bspin - "Copy install log"
David Bainbridged18f4942020-04-14 16:46:13 -0700885 if [ -f "install-$NAME.log" ]; then
886 (set -x; cp "install-$NAME.log" "$DATA/install-$NAME.log") >>"$LOG" 2>&1
887 espin - "$VERIFIED"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000888 else
David Bainbridge0774b232019-08-02 06:37:19 +0000889 espin - "$NO_ENTRY Copy install log: install-$NAME.log not found"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000890 fi
891 bspin - "Dumping Kubernetes PODs"
David Bainbridged18f4942020-04-14 16:46:13 -0700892 (set -x; kubectl get --all-namespaces pods >> "$DATA/all-pods.txt" 2>&1) >>"$LOG" 2>&1
893 espin - "$VERIFIED"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000894 bspin - "Dumping Kubernetes SERVICEs"
David Bainbridged18f4942020-04-14 16:46:13 -0700895 (set -x; kubectl get --all-namespaces svc >> "$DATA/all-services.txt" 2>&1) >>"$LOG" 2>&1
896 espin - "$VERIFIED"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000897 bspin - "Dumping Kubernetes EVENTs"
David Bainbridged18f4942020-04-14 16:46:13 -0700898 (set -x; kubectl get --all-namespaces events >> "$DATA/all-events.txt" 2>&1) >>"$LOG" 2>&1
899 espin - "$VERIFIED"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000900 bspin - "Dumping VOLTHA POD details"
David Bainbridged18f4942020-04-14 16:46:13 -0700901 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 +0000902 SINCE=
David Bainbridged18f4942020-04-14 16:46:13 -0700903 if [ -n "$DUMP_FROM" ]; then
David Bainbridgecfd7ca12019-10-06 03:31:41 +0000904 SINCE="--since-time=$DUMP_FROM"
905 fi
David Bainbridgeac7f8072019-08-01 22:15:33 +0000906 for POD in $PODS; do
David Bainbridged18f4942020-04-14 16:46:13 -0700907 NS="$(echo "$POD" | cut -d: -f1)"
908 POD="$(echo "$POD" | cut -d: -f2)"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000909 sspin - "Dumping VOLTHA POD details: $POD$CEOL"
David Bainbridged18f4942020-04-14 16:46:13 -0700910 mkdir -p "$DATA/$POD"
911 (set -x; kubectl describe -n "$NS" "$POD" >> "$DATA/$POD/describe.txt" 2>&1) >>"$LOG" 2>&1
David Bainbridgeac7f8072019-08-01 22:15:33 +0000912 sspin - "Dumping VOLTHA POD details: $POD"
David Bainbridged18f4942020-04-14 16:46:13 -0700913 (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 +0000914 sspin - "Dumping VOLTHA POD details: $POD"
David Bainbridged18f4942020-04-14 16:46:13 -0700915 (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 +0000916 sspin - "Dumping VOLTHA POD details: $POD"
917 done
918 espin - "$VERIFIED Dumping VOLTHA POD details$CEOL"
919 bspin - "Dumping ETCD"
David Bainbridged18f4942020-04-14 16:46:13 -0700920 if [ -n "$(command -v etcdctl)" ]; then
921 (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
922 espin - "$VERIFIED"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000923 else
924 espin - "$NO_ENTRY Dumping ETCD: etcdctl command not available"
925 fi
David Bainbridge0774b232019-08-02 06:37:19 +0000926 bspin - "Creating compressed TAR: voltha-debug-dump-$NAME-$TS.tgz"
David Bainbridged18f4942020-04-14 16:46:13 -0700927 (set -x; tar -C "$WORK" -zcf "voltha-debug-dump-$NAME-$TS.tgz" "./voltha-debug-dump-$NAME-$TS") >>"$LOG" 2>&1
928 espin - "$VERIFIED"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000929 bspin - "Cleanup"
David Bainbridged18f4942020-04-14 16:46:13 -0700930 (set -x; rm -rf "$WORK") >>"$LOG" 2>&1
931 espin - "$VERIFIED"
932 bspin - "$(ls -l "voltha-debug-dump-$NAME-$TS.tgz")"
933 espin - "$VERIFIED"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000934 exit
935fi
936
David Bainbridge0774b232019-08-02 06:37:19 +0000937LOG="install-$NAME.log"
David Bainbridged18f4942020-04-14 16:46:13 -0700938date > "$LOG"
939echo "PORTS=$ONOS_API_PORT,$ONOS_SSH_PORT,$VOLTHA_API_PORT,$VOLTHA_SSH_PORT,$VOLTHA_ETCD_PORT" >> "$LOG"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000940
941# Output install options to log
David Bainbridged18f4942020-04-14 16:46:13 -0700942echo "OPTIONS" >> "$LOG"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000943for O in $ALL_OPTIONS; do
David Bainbridged18f4942020-04-14 16:46:13 -0700944 VAL="$(eval echo "\$$O")"
945 if [ -n "$VAL" ]; then
946 printf " %-30s = %s\n" "$O" "$VAL" >> "$LOG"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000947 fi
948done
949
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -0700950helm_install() {
David Bainbridged18f4942020-04-14 16:46:13 -0700951 local INDENT NOW
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700952 if [ "$1" == "-" ]; then
953 INDENT=$1; shift
954 fi
955 local NAMESPACE=$1; shift
David Bainbridge0774b232019-08-02 06:37:19 +0000956 local INAME=$1; shift
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700957 local CHART=$1; shift
David Bainbridge90fd8e32019-08-21 23:32:47 +0000958 local CHART_VERSION=$1; shift
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700959 local MESSAGE=$*
960
David Bainbridged18f4942020-04-14 16:46:13 -0700961 if [ "$CHART_VERSION X" != " X" ] && [ "$CHART_VERSION" != "latest" ]; then
David Bainbridge90fd8e32019-08-21 23:32:47 +0000962 CHART_VERSION="--version $CHART_VERSION"
963 else
964 CHART_VERSION=
965 fi
966
David Bainbridge99ac7a22019-08-31 02:26:43 +0000967 local CHART_ARGS=
968 if [ -r "${INAME}-values.yaml" ]; then
969 CHART_ARGS="-f ${INAME}-values.yaml"
970 fi
971
David Bainbridged18f4942020-04-14 16:46:13 -0700972 local WAIT_START CMD
973 WAIT_START="$(date +%s)"
974 COUNT="$((300 / 15))"
975 bspin "$INDENT" "$MESSAGE"
976 if [ "$HELM_USE_UPGRADE" == "yes" ]; then
David Bainbridge7f8bf992020-04-08 21:53:22 -0700977 _HELM_COMMAND="upgrade --install"
978 _HELM_ARGS="$INAME"
979 else
980 _HELM_COMMAND="install"
981 _HELM_ARGS="--name $INAME"
982 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700983 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")
984 (set -x; ${CMD[*]} >>"$LOG" 2>&1) >>"$LOG" 2>&1
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700985 SUCCESS=$?
David Bainbridged18f4942020-04-14 16:46:13 -0700986 while [ "$SUCCESS" -ne 0 ]; do
987 NOW="$(date +%s)"
988 if [ "$((NOW - WAIT_START))" -gt "$TIMEOUT_SECONDS" ]; then
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700989 espin "$THEX"
990 doTimeout "waiting for helm install $CHART"
991 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700992 sspin "$INDENT"
993 COUNT="$((COUNT - 1))"
994 if [ "$COUNT" -eq 0 ]; then
995 if [ "$HELM_USE_UPGRADE" == "no" ]; then
996 (set -x; helm delete --purge "$INAME" >>"$LOG" 2>&1) >>"$LOG" 2>&1
David Bainbridge7f8bf992020-04-08 21:53:22 -0700997 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700998 (set -x; ${CMD[*]} >>"$LOG" 2>&1) >>"$LOG" 2>&1
Andy Baviere22ff252019-12-19 11:40:31 -0700999 SUCCESS=$?
David Bainbridged18f4942020-04-14 16:46:13 -07001000 COUNT="$((300 / 15))"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001001 fi
1002 sleep .15
1003 done
David Bainbridged18f4942020-04-14 16:46:13 -07001004 espin "$INDENT" "$VERIFIED"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001005}
1006
David Bainbridged18f4942020-04-14 16:46:13 -07001007echo "INSTALL TYPE: $TYPE" >> "$LOG"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001008
1009bspin "Verify GOPATH"
David Bainbridged18f4942020-04-14 16:46:13 -07001010GOPATH="$(pwd)"; export GOPATH
1011mkdir -p "$GOPATH/bin"
1012espin "$VERIFIED"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001013
David Bainbridged18f4942020-04-14 16:46:13 -07001014STIME="$(date +%s)"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001015if [ "$INSTALL_KUBECTL" == "no" ]; then
1016 bspin "Skip kubectl install"
1017 espin $NO_ENTRY
Test Userc13bdc92019-07-03 20:57:49 +00001018else
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001019 bspin "Verify kubectl $HELM"
David Bainbridged18f4942020-04-14 16:46:13 -07001020 if [ -x "$GOPATH/bin/kubectl" ]; then
1021 espin "$VERIFIED"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001022 else
David Bainbridged18f4942020-04-14 16:46:13 -07001023 espin "$NOT_VERIFIED"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001024 bspin - "Download and install Kubernetes/kubectl $DOWNLOAD"
David Bainbridged18f4942020-04-14 16:46:13 -07001025 (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
1026 (set -x; chmod 755 "$GOPATH/bin/kubectl" >>"$LOG" 2>&1) >>"$LOG" 2>&1
1027 espin - "$VERIFIED"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001028 fi
Test Userc13bdc92019-07-03 20:57:49 +00001029fi
David Bainbridgee87067b2019-08-12 22:00:12 +00001030if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001031 NOW="$(date +%s)"
1032 printtime $((NOW - STIME))
David Bainbridgee87067b2019-08-12 22:00:12 +00001033fi
Test Userc13bdc92019-07-03 20:57:49 +00001034
David Bainbridged18f4942020-04-14 16:46:13 -07001035STIME="$(date +%s)"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001036if [ "$DEPLOY_K8S" == "no" ]; then
1037 bspin "Skip Kubernetes/Kind Deployment"
1038 espin $NO_ENTRY
1039else
Test Userba1e7e72019-07-10 22:27:54 +00001040 bspin "Verify Kubernetes/Kind $HELM"
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -08001041 IS_INSTALLED=0
1042 OP_TYPE="install"
David Bainbridged18f4942020-04-14 16:46:13 -07001043 if [ -x "$GOPATH/bin/kind" ]; then
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -08001044 OP_TYPE="upgrade"
David Bainbridged18f4942020-04-14 16:46:13 -07001045 if [ "$("$GOPATH/bin/kind" --version | grep -c "$KIND_VERSION")" -eq 1 ]; then
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -08001046 IS_INSTALLED=1
David Bainbridged18f4942020-04-14 16:46:13 -07001047 espin "$VERIFIED"
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -08001048 fi
1049 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001050 if [ "$IS_INSTALLED" -eq 0 ]; then
1051 espin "$NOT_VERIFIED"
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -08001052 bspin - "Download and $OP_TYPE Kubernetes/kind $DOWNLOAD"
David Bainbridged18f4942020-04-14 16:46:13 -07001053 (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
1054 (set -x; chmod 755 "$GOPATH/bin/kind" >>"$LOG" 2>&1) >>"$LOG" 2>&1
1055 espin - "$VERIFIED"
Test Userba1e7e72019-07-10 22:27:54 +00001056 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001057fi
1058
David Bainbridgee87067b2019-08-12 22:00:12 +00001059if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001060 NOW="$(date +%s)"
1061 printtime $((NOW - STIME))
David Bainbridgee87067b2019-08-12 22:00:12 +00001062fi
1063
David Bainbridged18f4942020-04-14 16:46:13 -07001064STIME="$(date +%s)"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001065if [ "$INSTALL_HELM" == "no" ]; then
1066 bspin "Skip Helm Install"
1067 espin $NO_ENTRY
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001068else
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001069 bspin "Verify Helm $HELM"
David Bainbridgea34993d2020-04-01 09:15:42 -07001070 HELM_UPGRADE=0
1071 HELM_UPGRADE_DESC="install"
David Bainbridged18f4942020-04-14 16:46:13 -07001072 if [ -x "$GOPATH/bin/helm" ]; then
1073 HAVE_VER="$("$GOPATH/bin/helm" version -c --template '{{.Client.SemVer}}')"
1074 HELM_UP_DOWN="$(echo -e "$HAVE_VER\n$HELM_VERSION" | sort -V | head -1)"
1075 if [ "$HAVE_VER" != "$HELM_VERSION" ]; then
1076 if [ "$HELM_UP_DOWN" == "$HELM_VERSION" ]; then
David Bainbridgea34993d2020-04-01 09:15:42 -07001077 HELM_UPGRADE_DESC="downgrade"
1078 else
1079 HELM_UPGRADE_DESC="upgrade"
1080 fi
1081 HELM_UPGRADE=1
1082 else
David Bainbridged18f4942020-04-14 16:46:13 -07001083 espin "$VERIFIED"
David Bainbridgea34993d2020-04-01 09:15:42 -07001084 fi
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001085 else
David Bainbridgea34993d2020-04-01 09:15:42 -07001086 HELM_UPGRADE=1
1087 fi
1088
David Bainbridged18f4942020-04-14 16:46:13 -07001089 if [ "$HELM_UPGRADE" -ne 0 ]; then
1090 espin "$NOT_VERIFIED"
David Bainbridgea34993d2020-04-01 09:15:42 -07001091 bspin - "Download and $HELM_UPGRADE_DESC Helm $DOWNLOAD"
David Bainbridged18f4942020-04-14 16:46:13 -07001092 (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
1093 espin - "$VERIFIED"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001094 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001095fi
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -08001096
David Bainbridgee87067b2019-08-12 22:00:12 +00001097if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001098 NOW="$(date +%s)"
1099 printtime $((NOW - STIME))
David Bainbridgee87067b2019-08-12 22:00:12 +00001100fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001101
David Bainbridged18f4942020-04-14 16:46:13 -07001102STIME="$(date +%s)"
Test Userb5712372019-07-03 21:52:17 +00001103bspin "Verify voltctl $HIGH_VOLTAGE"
David Bainbridged2811972019-12-14 01:14:09 +00001104VOK=0
1105VMESSAGE="install"
David K. Bainbridgeebf38d92020-02-10 10:46:31 -08001106export VC_VERSION="$VOLTCTL_VERSION"
1107if [ "$VC_VERSION" == "latest" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001108 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 -08001109fi
David Bainbridged18f4942020-04-14 16:46:13 -07001110if [ -x "$GOPATH/bin/voltctl" ]; then
1111 VHAVE="$("$GOPATH/bin/voltctl" version --clientonly -o json | jq -r .version)"
1112 RESULT=$?
1113 if [ $RESULT -eq 0 ] && [ "$VHAVE" == "$VC_VERSION" ]; then
David Bainbridged2811972019-12-14 01:14:09 +00001114 VOK=1
David Bainbridged18f4942020-04-14 16:46:13 -07001115 espin "$VERIFIED"
David Bainbridge1ba64f12019-12-18 00:40:13 +00001116 else
David Bainbridged18f4942020-04-14 16:46:13 -07001117 VCHECK="$(echo -e "$VHAVE\n$VC_VERSION" | sort -V | head -1)"
David K. Bainbridgeebf38d92020-02-10 10:46:31 -08001118 if [ "$VCHECK" == "$VHAVE" ]; then
1119 VMESSAGE="upgrade"
1120 else
1121 VMESSAGE="downgrade"
1122 fi
David Bainbridged2811972019-12-14 01:14:09 +00001123 fi
1124fi
1125
David Bainbridged18f4942020-04-14 16:46:13 -07001126if [ "$VOK" -eq 0 ]; then
1127 espin "$NOT_VERIFIED"
David Bainbridged2811972019-12-14 01:14:09 +00001128 bspin - "Download and $VMESSAGE voltctl $DOWNLOAD"
David Bainbridged18f4942020-04-14 16:46:13 -07001129 (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
1130 (set -x; chmod 755 "$GOPATH/bin/voltctl" >>"$LOG" 2>&1) >>"$LOG" 2>&1
1131 espin - "$VERIFIED"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001132fi
David Bainbridgee87067b2019-08-12 22:00:12 +00001133if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001134 NOW="$(date +%s)"
1135 printtime $((NOW - STIME))
David Bainbridgee87067b2019-08-12 22:00:12 +00001136fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001137
1138bspin "Verify command PATH"
Test Userba1e7e72019-07-10 22:27:54 +00001139export PATH=$GOPATH/bin:$PATH
David Bainbridged18f4942020-04-14 16:46:13 -07001140espin "$VERIFIED"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001141
David Bainbridged18f4942020-04-14 16:46:13 -07001142STIME="$(date +%s)"
Test Userba1e7e72019-07-10 22:27:54 +00001143if [ "$DEPLOY_K8S" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001144 HAVE="$(kind get clusters | grep -c "voltha-$NAME")"
Test Userba1e7e72019-07-10 22:27:54 +00001145 bspin "Verify Kubernetes/Kind Cluster"
1146 sspin
David Bainbridged18f4942020-04-14 16:46:13 -07001147 if [ "$HAVE" -eq 0 ]; then
1148 espin "$NOT_VERIFIED"
David Bainbridge491b1bd2019-07-11 17:53:11 +00001149 bspin - "Verify cluster configuration"
David Bainbridged18f4942020-04-14 16:46:13 -07001150 if [ ! -r "./$NAME-cluster.cfg" ]; then
1151 espin - "$NOT_VERIFIED"
David K. Bainbridge43422402020-03-06 07:41:22 -08001152 bspin - "Download cluster configuration: $TYPE-cluster.cfg to $NAME-cluster.cfg $DOWNLOAD"
David Bainbridged18f4942020-04-14 16:46:13 -07001153 ERR_OUT="$(mktemp)"
1154 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
1155 espin - "$THEX"
1156 echo -e "${RED}${BOLD}${ERROR}ERROR: $NAME-cluster.cfg${NORMAL}${RED} - $(cat "$ERR_OUT")${NORMAL}"
1157 echo "ERROR: $(cat "$ERR_OUT")" >>"$LOG"
1158 rm -rf "$ERR_OUT" "./$NAME-cluster.cfg"
David K. Bainbridgea00736b2020-01-08 14:33:17 -08001159 exit 1
1160 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001161 rm -rf "$ERR_OUT"
David K. Bainbridgea00736b2020-01-08 14:33:17 -08001162 else
David Bainbridged18f4942020-04-14 16:46:13 -07001163 espin - "$VERIFIED"
David K. Bainbridgea00736b2020-01-08 14:33:17 -08001164 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001165 kind create cluster --name "voltha-$NAME" --config "$NAME-cluster.cfg"
David Bainbridge491b1bd2019-07-11 17:53:11 +00001166 else
David Bainbridged18f4942020-04-14 16:46:13 -07001167 espin "$VERIFIED"
Test Userba1e7e72019-07-10 22:27:54 +00001168 fi
1169
David Bainbridged18f4942020-04-14 16:46:13 -07001170 KUBECONFIG="$(kind get kubeconfig-path --name="voltha-$NAME")"; export KUBECONFIG
Test Userba1e7e72019-07-10 22:27:54 +00001171 P="coredns-.* \
David Bainbridge0774b232019-08-02 06:37:19 +00001172 etcd-voltha-$NAME-control-plane \
Test Userba1e7e72019-07-10 22:27:54 +00001173 kindnet-.* \
David Bainbridge0774b232019-08-02 06:37:19 +00001174 kube-apiserver-voltha-$NAME-control-plane \
1175 kube-controller-manager-voltha-$NAME-control-plane \
Test Userba1e7e72019-07-10 22:27:54 +00001176 kube-proxy-.* \
David Bainbridge0774b232019-08-02 06:37:19 +00001177 kube-scheduler-voltha-$NAME-control-plane"
Test Userba1e7e72019-07-10 22:27:54 +00001178
David Bainbridged18f4942020-04-14 16:46:13 -07001179 EXPECT="$(test "$TYPE" == "minimal" && echo "12" || echo "14")"
1180 wait_for_pods - "kube-system" "$EXPECT" "includes" "Waiting for system PODs to start" "$NO_LABEL" "$P"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001181fi
David Bainbridgee87067b2019-08-12 22:00:12 +00001182if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001183 NOW="$(date +%s)"
1184 printtime $((NOW - STIME))
David Bainbridgee87067b2019-08-12 22:00:12 +00001185fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001186
David Bainbridged18f4942020-04-14 16:46:13 -07001187STIME="$(date +%s)"
1188COUNT="$(count_pods "kube-system" ":Running:" "$NO_LABEL" "tiller-deploy-.*")"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001189bspin "Verify Helm"
David Bainbridged18f4942020-04-14 16:46:13 -07001190if [ "$COUNT" -ne 1 ]; then
1191 espin "$NOT_VERIFIED"
Test Userb5712372019-07-03 21:52:17 +00001192 echo -e "Configuring Helm $GEAR"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001193 if [ "$INSTALL_HELM" == "no" ]; then
1194 bspin - "Skip Helm/Tiller Initialization"
1195 espin - $NO_ENTRY
1196 else
1197 bspin - "Initialize Helm"
David Bainbridged18f4942020-04-14 16:46:13 -07001198 (set -x; helm init --upgrade >>"$LOG" 2>&1) >>"$LOG" 2>&1
1199 espin - "$VERIFIED"
1200 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 -07001201 fi
Test Userb5712372019-07-03 21:52:17 +00001202 bspin - "Add Google Incubator repository to Helm"
David Bainbridged18f4942020-04-14 16:46:13 -07001203 (set -x; helm repo add incubator https://kubernetes-charts-incubator.storage.googleapis.com >>"$LOG" 2>&1) >>"$LOG" 2>&1
1204 espin - "$VERIFIED"
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001205
Test Userba1e7e72019-07-10 22:27:54 +00001206 # HACK (sort-of) - the config for tiller is about to be patched, which will
1207 # cause the tiller pod to be recreated. This can sometimes cause a timing
1208 # issue with the "wait_for_pods" call on tiller as it may incorrectly
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001209 # identify the running/ready tiller pod that is soon to be terminated as
Test Userba1e7e72019-07-10 22:27:54 +00001210 # what it is waiting for. To avoid this issue we do a clean scale down and
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001211 # scale up of the pod so the script controlls when it should be expecting
Test Userba1e7e72019-07-10 22:27:54 +00001212 # things
David Bainbridged18f4942020-04-14 16:46:13 -07001213 (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 -07001214
Test Userb5712372019-07-03 21:52:17 +00001215 bspin - "Add Google Stable repository to Helm"
David Bainbridged18f4942020-04-14 16:46:13 -07001216 (set -x; helm repo add stable https://kubernetes-charts.storage.googleapis.com >>"$LOG" 2>&1) >>"$LOG" 2>&1
1217 espin - "$VERIFIED"
Test Userb5712372019-07-03 21:52:17 +00001218 bspin - "Add ONF repository to Helm"
David Bainbridged18f4942020-04-14 16:46:13 -07001219 (set -x; helm repo add onf https://charts.opencord.org >>"$LOG" 2>&1) >>"$LOG" 2>&1
1220 espin - "$VERIFIED"
Test Userb5712372019-07-03 21:52:17 +00001221 bspin - "Update Helm repository cache"
David Bainbridged18f4942020-04-14 16:46:13 -07001222 (set -x; helm repo update >>"$LOG" 2>&1) >>"$LOG" 2>&1
1223 espin - "$VERIFIED"
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001224
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001225 # Create and k8s service account so that Helm can create pods
Test Userb5712372019-07-03 21:52:17 +00001226 bspin - "Create Tiller ServiceAccount"
David Bainbridged18f4942020-04-14 16:46:13 -07001227 (set -x; kubectl create serviceaccount --namespace kube-system tiller >>"$LOG" 2>&1) >>"$LOG" 2>&1
1228 espin - "$VERIFIED"
Test Userb5712372019-07-03 21:52:17 +00001229 bspin - "Create Tiller ClusterRoleBinding"
David Bainbridged18f4942020-04-14 16:46:13 -07001230 (set -x; kubectl create clusterrolebinding tiller-cluster-rule --clusterrole=cluster-admin --serviceaccount=kube-system:tiller >>"$LOG" 2>&1) >>"$LOG" 2>&1
1231 espin - "$VERIFIED"
Test Userb5712372019-07-03 21:52:17 +00001232 bspin - "Update Tiller Manifest"
David Bainbridged18f4942020-04-14 16:46:13 -07001233 (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 +00001234
1235 # HACK (sort-of) - part to, spin it back up
David Bainbridged18f4942020-04-14 16:46:13 -07001236 (set -x; kubectl -n kube-system scale deploy tiller-deploy --replicas=1 >>"$LOG" 2>&1) >>"$LOG" 2>&1
1237 espin - "$VERIFIED"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001238else
David Bainbridged18f4942020-04-14 16:46:13 -07001239 if [ "$(helm version -s --template '{{.Server.SemVer}}')" != "$HELM_VERSION" ]; then
1240 espin "$NOT_VERIFIED"
David Bainbridgea34993d2020-04-01 09:15:42 -07001241 bspin - "Sync Tiller server version with helm client"
David Bainbridged18f4942020-04-14 16:46:13 -07001242 (set -x; helm init --upgrade --force-upgrade --wait >>"$LOG" 2>&1) >>"$LOG" 2>&1
1243 espin - "$VERIFIED"
David Bainbridgea34993d2020-04-01 09:15:42 -07001244 else
David Bainbridged18f4942020-04-14 16:46:13 -07001245 espin "$VERIFIED"
David Bainbridgea34993d2020-04-01 09:15:42 -07001246 fi
1247
David Bainbridge46505fb2019-10-01 21:13:20 +00001248 if [ "$UPDATE_HELM_REPOS" == "yes" ]; then
1249 bspin - "Update Helm repository cache"
David Bainbridged18f4942020-04-14 16:46:13 -07001250 (set -x; helm repo update >>"$LOG" 2>&1) >>"$LOG" 2>&1
1251 espin - "$VERIFIED"
David Bainbridge46505fb2019-10-01 21:13:20 +00001252 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001253fi
David Bainbridged18f4942020-04-14 16:46:13 -07001254wait_for_pods - "kube-system" 1 "includes" "Waiting for Tiller POD to start" "$NO_LABEL" "tiller-deploy-.*"
David Bainbridgee87067b2019-08-12 22:00:12 +00001255if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001256 NOW="$(date +%s)"
1257 printtime $((NOW - STIME))
David Bainbridgee87067b2019-08-12 22:00:12 +00001258fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001259
David Bainbridged18f4942020-04-14 16:46:13 -07001260STIME="$(date +%s)"
David Bainbridge0774b232019-08-02 06:37:19 +00001261bspin "Verify Helm values file: $NAME-values.yaml"
1262if [ ! -r "./$NAME-values.yaml" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001263 espin "$NOT_VERIFIED"
David Bainbridge0774b232019-08-02 06:37:19 +00001264 bspin - "Download Helm values file: $TYPE-values.yaml to $NAME-values.yaml $DOWNLOAD"
David Bainbridged18f4942020-04-14 16:46:13 -07001265 ERR_OUT="$(mktemp)"
1266 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
1267 espin - "$THEX"
1268 echo -e "${RED}${BOLD}${ERROR}ERROR: $NAME-values.yaml${NORMAL}${RED} - $(cat "$ERR_OUT")${NORMAL}"
1269 echo "ERROR: $(cat "$ERR_OUT")" >>"$LOG"
1270 rm -rf "$ERR_OUT" "./$NAME-values.yaml"
David K. Bainbridgea00736b2020-01-08 14:33:17 -08001271 exit 1
1272 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001273 rm -rf "$ERR_OUT"
1274 espin - "$VERIFIED"
Test Userba1e7e72019-07-10 22:27:54 +00001275else
David Bainbridged18f4942020-04-14 16:46:13 -07001276 espin "$VERIFIED"
Test Userba1e7e72019-07-10 22:27:54 +00001277fi
David Bainbridgee87067b2019-08-12 22:00:12 +00001278if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001279 NOW="$(date +%s)"
1280 printtime $((NOW - STIME))
David Bainbridgee87067b2019-08-12 22:00:12 +00001281fi
Test Userba1e7e72019-07-10 22:27:54 +00001282
David Bainbridged18f4942020-04-14 16:46:13 -07001283STIME="$(date +%s)"
David Bainbridge99ac7a22019-08-31 02:26:43 +00001284bspin "Verify or download chart specific values files $DOWNLOAD"
1285VALUES_FILES="monkey-values.yaml"
David Bainbridged18f4942020-04-14 16:46:13 -07001286ERR_OUT="$(mktemp)"
David Bainbridge99ac7a22019-08-31 02:26:43 +00001287for i in $VALUES_FILES; do
1288 if [ ! -r ./$i ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001289 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
1290 espin "$THEX"
1291 echo -e "${RED}${BOLD}${ERROR}ERROR: $i${NORMAL}${RED} - $(cat "$ERR_OUT")${NORMAL}"
1292 echo "ERROR: $i - $(cat "$ERR_OUT")" >>"$LOG"
1293 rm -rf "$ERR_OUT" "./$i"
David K. Bainbridgea00736b2020-01-08 14:33:17 -08001294 exit 1
1295 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001296 rm -rf "$ERR_OUT"
David Bainbridge99ac7a22019-08-31 02:26:43 +00001297 fi
1298done
David Bainbridged18f4942020-04-14 16:46:13 -07001299rm -rf "$ERR_OUT"
1300espin "$VERIFIED"
David Bainbridge99ac7a22019-08-31 02:26:43 +00001301if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001302 NOW="$(date +%s)"
1303 printtime $((NOW - STIME))
David Bainbridge99ac7a22019-08-31 02:26:43 +00001304fi
1305
1306if [ "$WITH_CHAOS" == "yes" ]; then
1307 bspin "Verify or clone kube-monkey helm chart $DOWNLOAD"
1308 if [ -r ./kube-monkey ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001309 espin "$VERIFIED"
David Bainbridge99ac7a22019-08-31 02:26:43 +00001310 else
David Bainbridged18f4942020-04-14 16:46:13 -07001311 espin "$NOT_VERIFIED"
David Bainbridge99ac7a22019-08-31 02:26:43 +00001312 bspin - "GIT clone kube-monkey"
David Bainbridged18f4942020-04-14 16:46:13 -07001313 (set -x; git clone https://github.com/asobti/kube-monkey kube-monkey >>"$LOG" 2>&1) >>"$LOG" 2>&1
1314 espin - "$VERIFIED"
David Bainbridge99ac7a22019-08-31 02:26:43 +00001315 fi
1316fi
1317
Test Userba1e7e72019-07-10 22:27:54 +00001318if [ "$JUST_K8S" == "yes" ]; then
1319 echo "Environment deployed, not deploying VOLTHA artifacts as requested. Good bye."
1320 echo ""
David Bainbridged18f4942020-04-14 16:46:13 -07001321 echo "Please issue the following commands in your terminal to ensure that you" | tee -a "$LOG"
1322 echo "are accessing the correct Kubernetes/Kind cluster as well as have the " | tee -a "$LOG"
1323 echo "tools required by VOLTHA in your command path. " | tee -a "$LOG"
1324 echo "" | tee -a "$LOG"
1325 echo -en "$BOLD"
1326 if [ "$DEPLOY_K8S" == "yes" ]; then
1327 echo "export KUBECONFIG=\"\$(./bin/kind get kubeconfig-path --name=\"voltha-$NAME\")\"" | tee -a "$LOG"
Test Userba1e7e72019-07-10 22:27:54 +00001328 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001329 echo "export PATH=$GOPATH/bin:\$PATH" | tee -a "$LOG"
1330 echo -en "$NORMAL"
1331 echo "" | tee -a "$LOG"
1332 echo "Thank you for choosing kind-voltha for you quick cluster needs." | tee -a "$LOG"
Test Userba1e7e72019-07-10 22:27:54 +00001333 exit 0
1334fi
1335
David Bainbridged18f4942020-04-14 16:46:13 -07001336if [ "$WITH_ETCD" != "yes" ] && [ "$WITH_ETCD" != "external" ]; then
David Bainbridge696bc632020-04-05 21:49:37 -07001337 bspin "Skip ETCD Operator Deployment"
1338 espin $NO_ENTRY
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001339else
David Bainbridged18f4942020-04-14 16:46:13 -07001340 STIME="$(date +%s)"
David Bainbridge76afd812020-04-06 09:53:52 -07001341 NS=$VOLTHA_NS
David Bainbridged18f4942020-04-14 16:46:13 -07001342 if [ "$WITH_ETCD" == "external" ]; then
David Bainbridge76afd812020-04-06 09:53:52 -07001343 NS=$INFRA_NS
1344 fi
David Bainbridge696bc632020-04-05 21:49:37 -07001345 bspin "Verify ETCD Operator $OLD_KEY"
David Bainbridged18f4942020-04-14 16:46:13 -07001346 if [ "$HELM_USE_UPGRADE" == "yes" ] || [ "$(helm list --deployed --short --namespace "$NS" "^etcd-operator\$" | wc -l)" -ne 1 ]; then
1347 espin "$NOT_VERIFIED"
1348 helm_install - "$NS" etcd-operator stable/etcd-operator latest "$_HELM_DESC ETCD Operator"
David Bainbridge696bc632020-04-05 21:49:37 -07001349 else
David Bainbridged18f4942020-04-14 16:46:13 -07001350 espin "$VERIFIED"
David Bainbridge696bc632020-04-05 21:49:37 -07001351 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001352 EXPECT="$(test "$TYPE" == "minimal" && echo "1" || echo "3")"
1353 wait_for_pods - "$NS" "$EXPECT" "includes" "Waiting for ETCD Operator to start" "$NO_LABEL" "etcd-operator-.*"
David Bainbridge696bc632020-04-05 21:49:37 -07001354 if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001355 NOW="$(date +%s)"
1356 printtime $((NOW - STIME))
David Bainbridge696bc632020-04-05 21:49:37 -07001357 fi
David Bainbridgee87067b2019-08-12 22:00:12 +00001358fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001359
David Bainbridged18f4942020-04-14 16:46:13 -07001360STIME="$(date +%s)"
1361if [ "$WITH_ONOS" == "yes" ]; then
David Bainbridgeb270c202019-07-26 01:44:42 +00001362 bspin "Verify ONOS installed $BIRD"
David Bainbridged18f4942020-04-14 16:46:13 -07001363 if [ "$HELM_USE_UPGRADE" == "yes" ] || [ "$(helm list --deployed --short --namespace "$INFRA_NS" "^onos\$" | wc -l)" -ne 1 ]; then
1364 espin "$NOT_VERIFIED"
1365 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 +00001366 else
David Bainbridged18f4942020-04-14 16:46:13 -07001367 espin "$VERIFIED"
David Bainbridgeb270c202019-07-26 01:44:42 +00001368 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001369 wait_for_pods - "$INFRA_NS" 1 "includes" "Waiting for ONOS to start" "$NO_LABEL" "onos-.*"
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001370
David Bainbridged18f4942020-04-14 16:46:13 -07001371 if [ "$WITH_PORT_FORWARDS" == "yes" ]; then
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -08001372 bspin - "Forward ONOS API port $FORWARD"
1373 kill_port_forward onos-ui
David Bainbridged18f4942020-04-14 16:46:13 -07001374 port_forward "$INFRA_NS" onos-ui "$ONOS_API_PORT" 8181
1375 espin - "$VERIFIED"
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -08001376 bspin - "Forward ONOS SSH port $FORWARD"
1377 kill_port_forward onos-ssh
David Bainbridged18f4942020-04-14 16:46:13 -07001378 port_forward "$INFRA_NS" onos-ssh "$ONOS_SSH_PORT" 8101
1379 espin - "$VERIFIED"
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -08001380 _ONOS_API_EP="127.0.0.1:$ONOS_API_PORT"
1381 else
David Bainbridged18f4942020-04-14 16:46:13 -07001382 _ONOS_API_EP="$(get_service_ep "$INFRA_NS" onos-ui)"
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -08001383 fi
David Bainbridged31d6122019-08-13 19:37:59 +00001384 bspin - "Verify or download ONOS configuration support files $DOWNLOAD"
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001385 ONOS_FILES="olt-onos-enableExtraneousRules.json onos-aaa.json \
David Bainbridge696bc632020-04-05 21:49:37 -07001386 onos-dhcpl2relay.json onos-sadis-sample.json"
David Bainbridged18f4942020-04-14 16:46:13 -07001387 (set -x; mkdir -p ./onos-files >>"$LOG" 2>&1) >>"$LOG" 2>&1
1388 ERR_OUT="$(mktemp)"
David Bainbridge2b19e832019-08-16 02:40:53 +00001389 for i in $ONOS_FILES; do
David Bainbridged18f4942020-04-14 16:46:13 -07001390 if [ ! -r "./onos-files/$i" ]; then
1391 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
1392 espin - "$THEX"
1393 echo -e "${RED}${BOLD}${ERROR}ERROR: $i${NORMAL}${RED} - $(cat "$ERR_OUT")${NORMAL}"
1394 echo "ERROR: $(cat "$ERR_OUT")" >>"$LOG"
1395 rm -rf "$ERR_OUT" "./onos-files/$i"
David K. Bainbridgea00736b2020-01-08 14:33:17 -08001396 exit 1
1397 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001398 rm -rf "$ERR_OUT"
David Bainbridged31d6122019-08-13 19:37:59 +00001399 fi
1400 done
David Bainbridged18f4942020-04-14 16:46:13 -07001401 rm -rf "$ERR_OUT"
1402 espin - "$VERIFIED"
David Bainbridge27790d62019-08-13 22:43:19 +00001403
David Bainbridged18f4942020-04-14 16:46:13 -07001404 if [ "$INSTALL_ONOS_APPS" == "yes" ]; then
David Bainbridge27790d62019-08-13 22:43:19 +00001405 bspin - "Installing custom ONOS applications"
David Bainbridged18f4942020-04-14 16:46:13 -07001406 if [ -x onos-files/onos-apps ] && [ "$(find onos-files/onos-apps -name "*.oar" 2>/dev/null | wc -l)" -gt 0 ]; then
1407 for OAR in onos-files/onos-apps/*.oar; do
David Bainbridge27790d62019-08-13 22:43:19 +00001408 sspin - "Installing custom ONOS applications - $OAR$CEOL"
David Bainbridged18f4942020-04-14 16:46:13 -07001409 override_onos_app "$OAR"
David Bainbridge27790d62019-08-13 22:43:19 +00001410 done
1411 espin - "$VERIFIED Installing custom ONOS applications$CEOL"
1412 else
1413 espin - "$NOT_VERIFIED Installing custom ONOS applications - None Found"
1414 fi
1415 fi
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001416
David Bainbridged18f4942020-04-14 16:46:13 -07001417 if [ "$WITH_KAFKA" != "no" ]; then
David Bainbridge837e8bd2020-04-06 13:17:14 -07001418 check_onos_app_active org.opencord.kafka
David Bainbridge76afd812020-04-06 09:53:52 -07001419 _HOST=voltha-kafka.$INFRA_NS.svc.cluster.local
David Bainbridge837e8bd2020-04-06 13:17:14 -07001420 _PORT=9092
David Bainbridged18f4942020-04-14 16:46:13 -07001421 if [ "$WITH_KAFKA" == "yes" ]; then
David Bainbridge76afd812020-04-06 09:53:52 -07001422 _HOST=voltha-kafka.$VOLTHA_NS.svc.cluster.local
1423 _PORT=9092
David Bainbridged18f4942020-04-14 16:46:13 -07001424 elif [ "$WITH_KAFKA" == "external" ]; then
David Bainbridge76afd812020-04-06 09:53:52 -07001425 _HOST=kafka.$INFRA_NS.svc.cluster.local
1426 _PORT=9092
1427 else
David Bainbridged18f4942020-04-14 16:46:13 -07001428 _HOST="$(echo "$WITH_KAFKA" | cut -d: -f1)"
1429 _PORT="$(echo "$WITH_KAFKA" | cut -s -d: -f2)"
David Bainbridge837e8bd2020-04-06 13:17:14 -07001430 _PORT=${_PORT:-9092}
1431 fi
1432 push_onos_config "json" "Push ONOS Kafka Configuration" "network/configuration/apps/org.opencord.kafka" \
David Bainbridged18f4942020-04-14 16:46:13 -07001433 "$(cat <<EOJ | tr -d '[:space:]'
David Bainbridge696bc632020-04-05 21:49:37 -07001434{
1435 "kafka": {
1436 "bootstrapServers": "$_HOST:$_PORT"
1437 }
1438}
1439EOJ
David Bainbridged18f4942020-04-14 16:46:13 -07001440)"
David Bainbridge837e8bd2020-04-06 13:17:14 -07001441 fi
Matteo Scandolo9a77a732020-01-09 14:24:12 -08001442 check_onos_app_active org.opencord.dhcpl2relay
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001443 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 -08001444 check_onos_app_active org.opencord.olt
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001445 # FIXME use WITH_DHCP and WITH_EAPOL flags to configre OLT App
Hardik Windlassa7501fb2020-02-17 14:28:20 +00001446 # Default value for "enableEapol" is true in OLT App
David Bainbridged18f4942020-04-14 16:46:13 -07001447 if [ "$WITH_EAPOL" == "yes" ]; then
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001448 push_onos_config "json" "Enable VOLTHA ONOS EAPOL provisioning" "configuration/org.opencord.olt.impl.OltFlowService" '{"enableEapol":true}'
David Bainbridged18f4942020-04-14 16:46:13 -07001449 elif [ "$WITH_EAPOL" == "no" ]; then
Hardik Windlassa7501fb2020-02-17 14:28:20 +00001450 push_onos_config "json" "Disable VOLTHA ONOS EAPOL provisioning" "configuration/org.opencord.olt.impl.OltFlowService" '{"enableEapol":false}'
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001451 fi
Hardik Windlassa7501fb2020-02-17 14:28:20 +00001452 # Default value for "enableDhcpOnProvisioning" is false and for "enableDhcpV4" is true in OLT App
David Bainbridged18f4942020-04-14 16:46:13 -07001453 if [ "$WITH_DHCP" == "yes" ]; then
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001454 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 -07001455 elif [ "$WITH_DHCP" == "no" ]; then
Hardik Windlassa7501fb2020-02-17 14:28:20 +00001456 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 -08001457 fi
Hardik Windlassa7501fb2020-02-17 14:28:20 +00001458 # Default value for "enableIgmpOnProvisioning" is false in OLT App
David Bainbridged18f4942020-04-14 16:46:13 -07001459 if [ "$WITH_IGMP" == "yes" ]; then
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001460 push_onos_config "json" "Enable VOLTHA ONOS IGMP provisioning" "configuration/org.opencord.olt.impl.OltFlowService" '{"enableIgmpOnProvisioning":true}'
David Bainbridged18f4942020-04-14 16:46:13 -07001461 elif [ "$WITH_IGMP" == "no" ]; then
Hardik Windlassa7501fb2020-02-17 14:28:20 +00001462 push_onos_config "json" "Disable VOLTHA ONOS IGMP provisioning" "configuration/org.opencord.olt.impl.OltFlowService" '{"enableIgmpOnProvisioning":false}'
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001463 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001464 if [ "$ENABLE_ONOS_EXTRANEOUS_RULES" == "yes" ]; then
David K. Bainbridge484d80c2020-03-05 21:44:34 -08001465 push_onos_config "file" "Enabling extraneous rules for ONOS" "configuration/org.onosproject.net.flow.impl.FlowRuleManager" "onos-files/olt-onos-enableExtraneousRules.json"
1466 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001467 if [ "$(echo ":yes:file:" | grep -c ":$CONFIG_SADIS:")" -eq 1 ]; then
Matteo Scandolo9a77a732020-01-09 14:24:12 -08001468 check_onos_app_active org.opencord.sadis
Hardik Windlassb3147602020-03-09 16:59:15 +05301469 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 -07001470 elif [ "$CONFIG_SADIS" == "bbsim" ]; then
1471 push_onos_config "json" \
1472 "[optional] Push ONOS configuration for BBSIM SADIS servers" \
1473 "network/configuration/apps/org.opencord.sadis" \
David Bainbridged18f4942020-04-14 16:46:13 -07001474 "$(cat <<EOJ | tr -d '[:space:]'
David K. Bainbridgeb859e912020-03-13 14:07:52 -07001475{
1476 "sadis": {
1477 "integration": {
David Bainbridge76afd812020-04-06 09:53:52 -07001478 "url": "http://bbsim.$BBSIM_NS.svc.cluster.local:50074/v2/subscribers/%s",
David K. Bainbridgeb859e912020-03-13 14:07:52 -07001479 "cache": {
1480 "enabled": true,
1481 "maxsize": 50,
1482 "ttl": "PT1m"
1483 }
1484 }
1485 },
1486 "bandwidthprofile": {
1487 "integration": {
David Bainbridge76afd812020-04-06 09:53:52 -07001488 "url": "http://bbsim.$BBSIM_NS.svc.cluster.local:50074/v2/bandwidthprofiles/%s",
David K. Bainbridgeb859e912020-03-13 14:07:52 -07001489 "cache": {
1490 "enabled": true,
1491 "maxsize": 50,
1492 "ttl": "PT1m"
1493 }
1494 }
1495 }
1496}
1497EOJ
David Bainbridged18f4942020-04-14 16:46:13 -07001498)"
David K. Bainbridgeb859e912020-03-13 14:07:52 -07001499 elif [ "$CONFIG_SADIS" == "url" ]; then
1500 push_onos_config "json" \
1501 "[optional] Push ONOS configuration for custom SADIS and Bandwidth Profile servers" \
1502 "network/configuration/apps/org.opencord.sadis" \
David Bainbridged18f4942020-04-14 16:46:13 -07001503 "$(cat <<EOJ | tr -d '[:space:]'
David K. Bainbridgeb859e912020-03-13 14:07:52 -07001504{
1505 "sadis": {
1506 "integration": {
1507 "url": "$SADIS_SUBSCRIBERS",
1508 "cache": {
1509 "enabled": true,
1510 "maxsize": 50,
1511 "ttl": "PT1m"
1512 }
1513 }
1514 },
1515 "bandwidthprofile": {
1516 "integration": {
1517 "url": "$SADIS_BANDWIDTH_PROFILES",
1518 "cache": {
1519 "enabled": true,
1520 "maxsize": 50,
1521 "ttl": "PT1m"
1522 }
1523 }
1524 }
1525}
1526EOJ
David Bainbridged18f4942020-04-14 16:46:13 -07001527)"
David Bainbridge2b19e832019-08-16 02:40:53 +00001528 fi
Test Userba1e7e72019-07-10 22:27:54 +00001529fi
David Bainbridgee87067b2019-08-12 22:00:12 +00001530if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001531 NOW="$(date +%s)"
1532 printtime $((NOW - STIME))
David Bainbridgee87067b2019-08-12 22:00:12 +00001533fi
Test Userba1e7e72019-07-10 22:27:54 +00001534
David Bainbridged18f4942020-04-14 16:46:13 -07001535if [ "$WITH_ETCD" == "external" ]; then
1536 STIME="$(date +%s)"
David Bainbridge76afd812020-04-06 09:53:52 -07001537 bspin "Verify external ETCD cluster $OLD_KEY"
David Bainbridged18f4942020-04-14 16:46:13 -07001538 EXPECT="$(test "$TYPE" == "minimal" && echo "1" || echo "3")"
1539 if [ "$HELM_USE_UPGRADE" == "yes" ] || [ "$(helm list --deployed --short --namespace "$INFRA_NS" "^etcd-cluster\$" | wc -l)" -ne 1 ]; then
1540 espin "$NOT_VERIFIED"
David Bainbridge76afd812020-04-06 09:53:52 -07001541 INTERNAL_EXTRA_HELM_INSTALL_ARGS+="--set clusterName=etcd-cluster --set autoCompactionRetention=1 --set clusterSize=$EXPECT"
David Bainbridged18f4942020-04-14 16:46:13 -07001542 helm_install - "$INFRA_NS" etcd-cluster onf/voltha-etcd-cluster latest "$_HELM_DESC external ETCD cluster"
David Bainbridge76afd812020-04-06 09:53:52 -07001543 else
David Bainbridged18f4942020-04-14 16:46:13 -07001544 espin "$VERIFIED"
David Bainbridge76afd812020-04-06 09:53:52 -07001545 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001546 wait_for_pods - "$INFRA_NS" "$EXPECT" "includes" "Waiting for ETCD cluster to start" "$NO_LABEL" "etcd-cluster-.*"
David Bainbridge76afd812020-04-06 09:53:52 -07001547 if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001548 NOW="$(date +%s)"
1549 printtime $((NOW - STIME))
David Bainbridge76afd812020-04-06 09:53:52 -07001550 fi
1551fi
1552
David Bainbridged18f4942020-04-14 16:46:13 -07001553if [ "$WITH_KAFKA" == "external" ]; then
1554 _TMP="$(mktemp -u)"
1555 _COUNT="$(test "$TYPE" == "minimal" && echo "1" || echo "3")"
1556 cat << EOC > "$_TMP"
David Bainbridge76afd812020-04-06 09:53:52 -07001557configurationOverrides:
1558 "default.replication.factor": $_COUNT
1559 "offsets.topic.replication.factor": $_COUNT
1560 "log.retention.hours": 4
1561 "log.message.timestamp.type": "LogAppendTime"
1562persistence:
1563 enabled: false
1564zookeeper:
1565 replicaCount: 1
1566 persistence:
1567 enabled: false
1568replicas: $_COUNT
1569EOC
David Bainbridged18f4942020-04-14 16:46:13 -07001570 STIME="$(date +%s)"
David Bainbridge76afd812020-04-06 09:53:52 -07001571 bspin "Verify external Kafka cluster $OLD_KEY"
David Bainbridged18f4942020-04-14 16:46:13 -07001572 EXPECT="$(test "$TYPE" == "minimal" && echo "2" || echo "4")"
1573 if [ "$HELM_USE_UPGRADE" == "yes" ] || [ "$(helm list --deployed --short --namespace "$INFRA_NS" "^kafka\$" | wc -l)" -ne 1 ]; then
1574 espin "$NOT_VERIFIED"
David Bainbridge76afd812020-04-06 09:53:52 -07001575 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" -f $_TMP"
David Bainbridged18f4942020-04-14 16:46:13 -07001576 helm_install - "$INFRA_NS" kafka incubator/kafka latest "$_HELM_DESC external Kafka cluster"
David Bainbridge76afd812020-04-06 09:53:52 -07001577 else
David Bainbridged18f4942020-04-14 16:46:13 -07001578 espin "$VERIFIED"
David Bainbridge76afd812020-04-06 09:53:52 -07001579 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001580 wait_for_pods - "$INFRA_NS" "$EXPECT" "includes" "Waiting for Kafka cluster to start" "$NO_LABEL" "kafka-.*"
David Bainbridge76afd812020-04-06 09:53:52 -07001581 if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001582 NOW="$(date +%s)"
1583 printtime $((NOW - STIME))
David Bainbridge76afd812020-04-06 09:53:52 -07001584 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001585 rm -rf "$_TMP"
David Bainbridge76afd812020-04-06 09:53:52 -07001586fi
1587
David Bainbridged18f4942020-04-14 16:46:13 -07001588STIME="$(date +%s)"
David Bainbridge696bc632020-04-05 21:49:37 -07001589EXPECT=1
1590if [ "$ONLY_ONE" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001591 EXPECT="$((EXPECT+1))"
David Bainbridge696bc632020-04-05 21:49:37 -07001592 INTERNAL_EXTRA_HELM_INSTALL_ARGS="--set therecanbeonlyone=true"
1593else
David Bainbridged18f4942020-04-14 16:46:13 -07001594 EXPECT="$((EXPECT+2))"
David Bainbridge696bc632020-04-05 21:49:37 -07001595fi
David Bainbridge76afd812020-04-06 09:53:52 -07001596case $WITH_ETCD in
1597 no)
1598 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set private_etcd_cluster=false"
1599 ;;
1600 yes)
1601 _HOST="voltha-etcd-cluster-client.$VOLTHA_NS.svc.cluster.local"
1602 _PORT=2379
1603 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set services.etcd.service=$_HOST --set services.etcd.port=$_PORT"
David Bainbridged18f4942020-04-14 16:46:13 -07001604 EXPECT="$((EXPECT+$(test "$TYPE" == "minimal" && echo "1" || echo "3")))"
David Bainbridge76afd812020-04-06 09:53:52 -07001605 ;;
1606 external)
1607 _HOST="etcd-cluster-client.$INFRA_NS.svc.cluster.local"
1608 _PORT=2379
1609 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set private_etcd_cluster=false --set services.etcd.service=$_HOST --set services.etcd.port=$_PORT"
1610 ;;
1611 *)
David Bainbridged18f4942020-04-14 16:46:13 -07001612 _HOST="$(echo "$WITH_ETCD" | cut -d: -f1)"
1613 _PORT="$(echo "$WITH_ETCD" | cut -s -d: -f2)"
David Bainbridge696bc632020-04-05 21:49:37 -07001614 _PORT=${_PORT:-2379}
David Bainbridge76afd812020-04-06 09:53:52 -07001615 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set private_etcd_cluster=false --set services.etcd.service=$_HOST --set services.etcd.port=$_PORT"
1616 ;;
1617esac
1618case $WITH_KAFKA in
1619 no)
1620 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set private_kafka_cluster=false"
1621 ;;
1622 yes)
1623 _HOST=voltha-kafka.$VOLTHA_NS.svc.cluster.local
1624 _PORT=9092
1625 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 -07001626 EXPECT="$((EXPECT+$(test "$TYPE" == "minimal" && echo "2" || echo "4")))"
David Bainbridge76afd812020-04-06 09:53:52 -07001627 ;;
1628 external)
1629 _HOST=kafka.$INFRA_NS.svc.cluster.local
1630 _PORT=9092
1631 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"
1632 ;;
1633 *)
David Bainbridged18f4942020-04-14 16:46:13 -07001634 _HOST="$(echo "$WITH_KAFKA" | cut -d: -f1)"
1635 _PORT="$(echo "$WITH_KAFKA" | cut -s -d: -f2)"
David Bainbridge696bc632020-04-05 21:49:37 -07001636 _PORT=${_PORT:-9092}
David Bainbridge76afd812020-04-06 09:53:52 -07001637 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"
1638 ;;
1639esac
1640
David Bainbridged18f4942020-04-14 16:46:13 -07001641if [ "$WITH_ONOS" == "yes" ]; then
David Bainbridge76afd812020-04-06 09:53:52 -07001642 _HOST=onos-openflow.$INFRA_NS.svc.cluster.local
1643 _PORT=6653
1644 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set services.controller.service=$_HOST --set services.controller.port=$_PORT"
David Bainbridged18f4942020-04-14 16:46:13 -07001645elif [ "$WITH_ONOS" != "no" ]; then
1646 _HOST="$(echo "$WITH_ONOS" | cut -d: -f1)"
1647 _PORT="$(echo "$WITH_ONOS" | cut -s -d: -f2)"
David Bainbridge76afd812020-04-06 09:53:52 -07001648 _PORT=${_PORT:-6653}
1649 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set services.controller.service=$_HOST --set services.controller.port=$_PORT"
David Bainbridge696bc632020-04-05 21:49:37 -07001650fi
Test Userb5712372019-07-03 21:52:17 +00001651bspin "Verify VOLTHA installed $HIGH_VOLTAGE"
David Bainbridged18f4942020-04-14 16:46:13 -07001652if [ "$HELM_USE_UPGRADE" == "yes" ] || [ "$(helm list --deployed --short --namespace "$VOLTHA_NS" "^voltha\$" | wc -l)" -ne 1 ]; then
1653 espin "$NOT_VERIFIED"
1654 helm_install - "$VOLTHA_NS" voltha "$VOLTHA_CHART" "$VOLTHA_CHART_VERSION" "$_HELM_DESC VOLTHA Core"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001655else
David Bainbridged18f4942020-04-14 16:46:13 -07001656 espin "$VERIFIED"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001657fi
David Bainbridge696bc632020-04-05 21:49:37 -07001658INTERNAL_EXTRA_HELM_INSTALL_ARGS=
Test Userba1e7e72019-07-10 22:27:54 +00001659
David Bainbridge90fd8e32019-08-21 23:32:47 +00001660VOLTHA="voltha-ofagent-.* \
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001661 rw-core.* \
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001662 voltha-etcd-cluster-.* \
1663 voltha-kafka-.* \
1664 voltha-zookeeper-.*"
David Bainbridged18f4942020-04-14 16:46:13 -07001665wait_for_pods - "$VOLTHA_NS" "$EXPECT" "includes" "Waiting for VOLTHA Core to start" "$NO_LABEL" "$VOLTHA"
David Bainbridgee87067b2019-08-12 22:00:12 +00001666if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001667 NOW="$(date +%s)"
1668 printtime $((NOW - STIME))
David Bainbridgee87067b2019-08-12 22:00:12 +00001669fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001670
David Bainbridge46505fb2019-10-01 21:13:20 +00001671if [ "$WITH_ADAPTERS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001672 STIME="$(date +%s)"
David Bainbridge46505fb2019-10-01 21:13:20 +00001673 EXPECT=0
David Bainbridged18f4942020-04-14 16:46:13 -07001674 if [ "$WITH_ETCD" == "yes" ]; then
David Bainbridge3517f6c2020-04-08 12:14:08 -07001675 _HOST=voltha-etcd-cluster-client.$VOLTHA_NS.svc.cluster.local
1676 _PORT=2379
1677 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set services.etcd.service=$_HOST --set services.etcd.port=$_PORT"
David Bainbridged18f4942020-04-14 16:46:13 -07001678 elif [ "$WITH_ETCD" == "external" ]; then
David Bainbridge3517f6c2020-04-08 12:14:08 -07001679 _HOST=etcd-cluster-client.$INFRA_NS.svc.cluster.local
1680 _PORT=2379
1681 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set services.etcd.service=$_HOST --set services.etcd.port=$_PORT"
David Bainbridged18f4942020-04-14 16:46:13 -07001682 elif [ "$WITH_ETCD" != "no" ]; then
1683 _HOST="$(echo "$WITH_ETCD" | cut -d: -f1)"
1684 _PORT="$(echo "$WITH_ETCD" | cut -s -d: -f2)"
David Bainbridge3517f6c2020-04-08 12:14:08 -07001685 _PORT=${_PORT:-2379}
1686 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set services.etcd.service=$_HOST --set services.etcd.port=$_PORT"
David Bainbridge696bc632020-04-05 21:49:37 -07001687 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001688 if [ "$WITH_KAFKA" == "yes" ]; then
David Bainbridge3517f6c2020-04-08 12:14:08 -07001689 _HOST=voltha-kafka.$VOLTHA_NS.svc.cluster.local
1690 _PORT=9092
1691 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 -07001692 elif [ "$WITH_KAFKA" == "external" ]; then
David Bainbridge3517f6c2020-04-08 12:14:08 -07001693 _HOST=kafka.$INFRA_NS.svc.cluster.local
1694 _PORT=9092
1695 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 -07001696 elif [ "$WITH_KAFKA" != "no" ]; then
1697 _HOST="$(echo "$WITH_KAFKA" | cut -d: -f1)"
1698 _PORT="$(echo "$WITH_KAFKA" | cut -s -d: -f2)"
David Bainbridge3517f6c2020-04-08 12:14:08 -07001699 _PORT=${_PORT:-9092}
1700 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 -07001701 fi
David Bainbridge46505fb2019-10-01 21:13:20 +00001702 echo -e "Verify Adapters $PLUG"
1703 if [ "$WITH_SIM_ADAPTERS" == "yes" ]; then
1704 bspin - "Verify Simulated Adapters installed"
David Bainbridged18f4942020-04-14 16:46:13 -07001705 if [ "$HELM_USE_UPGRADE" == "yes" ] || [ "$(helm list --deployed --short --namespace "$ADAPTER_NS" "^sim\$" | wc -l)" -ne 1 ]; then
1706 espin - "$NOT_VERIFIED"
1707 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 +00001708 else
David Bainbridged18f4942020-04-14 16:46:13 -07001709 espin - "$VERIFIED"
David Bainbridge46505fb2019-10-01 21:13:20 +00001710 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001711 EXPECT="$((EXPECT + 2))"
David Bainbridge46505fb2019-10-01 21:13:20 +00001712 fi
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001713
David Bainbridge46505fb2019-10-01 21:13:20 +00001714 if [ "$WITH_OPEN_ADAPTERS" == "yes" ]; then
1715 bspin - "Verify OpenOLT Adapter installed"
David Bainbridged18f4942020-04-14 16:46:13 -07001716 if [ "$HELM_USE_UPGRADE" == "yes" ] || [ "$(helm list --deployed --short --namespace "$ADAPTER_NS" "^open-olt\$" | wc -l)" -ne 1 ]; then
1717 espin - "$NOT_VERIFIED"
1718 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 +00001719 else
David Bainbridged18f4942020-04-14 16:46:13 -07001720 espin - "$VERIFIED"
David Bainbridge46505fb2019-10-01 21:13:20 +00001721 fi
1722 bspin - "Verify OpenONU Adapter installed"
David Bainbridged18f4942020-04-14 16:46:13 -07001723 if [ "$HELM_USE_UPGRADE" == "yes" ] || [ "$(helm list --deployed --short --namespace "$ADAPTER_NS" "^open-onu\$" | wc -l)" -ne 1 ]; then
1724 espin - "$NOT_VERIFIED"
1725 helm_install - "$ADAPTER_NS" open-onu "$VOLTHA_ADAPTER_OPEN_ONU_CHART" "$VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION" "$_HELM_DESC OpenONU Adapter"
David Bainbridge46505fb2019-10-01 21:13:20 +00001726 else
David Bainbridged18f4942020-04-14 16:46:13 -07001727 espin - "$VERIFIED"
David Bainbridge46505fb2019-10-01 21:13:20 +00001728 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001729 EXPECT="$((EXPECT + 2))"
David Bainbridge46505fb2019-10-01 21:13:20 +00001730 fi
David Bainbridge696bc632020-04-05 21:49:37 -07001731 INTERNAL_EXTRA_HELM_INSTALL_ARGS=
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001732
David Bainbridge46505fb2019-10-01 21:13:20 +00001733 ADAPTERS="adapter-.*"
David Bainbridged18f4942020-04-14 16:46:13 -07001734 wait_for_pods - "$ADAPTER_NS" "$EXPECT" "includes" "Waiting for adapters to start" "$NO_LABEL" "$ADAPTERS"
David Bainbridge46505fb2019-10-01 21:13:20 +00001735 if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001736 NOW="$(date +%s)"
1737 printtime $((NOW - STIME))
David Bainbridge46505fb2019-10-01 21:13:20 +00001738 fi
David Bainbridgee87067b2019-08-12 22:00:12 +00001739fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001740
David Bainbridged18f4942020-04-14 16:46:13 -07001741if [ "$WITH_BBSIM" == "yes" ]; then
1742 STIME="$(date +%s)"
Test User7d866122019-07-09 17:52:35 +00001743 echo -e "Verify BBSIM $PLUG"
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001744 bspin - "Verify BBSIM Installed"
David Bainbridged18f4942020-04-14 16:46:13 -07001745 for instance in $(seq 0 $((NUM_OF_BBSIM-1))); do
1746 if [ "$instance" -eq 0 ]; then
David K. Bainbridge43422402020-03-06 07:41:22 -08001747 instance_num=""
1748 else
1749 instance_num=$instance
1750 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001751 if [ "$HELM_USE_UPGRADE" == "yes" ] || [ "$(helm list --deployed --short --namespace "$BBSIM_NS" "^bbsim${instance_num}\$" | wc -l)" -ne 1 ]; then
1752 espin - "$NOT_VERIFIED"
1753 S_TAG="$((900+instance))"
Matteo Scandolo5a149572020-04-01 10:14:57 -07001754 INTERNAL_EXTRA_HELM_INSTALL_ARGS="--set olt_id=$instance,s_tag=$S_TAG"
David Bainbridged18f4942020-04-14 16:46:13 -07001755 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 -07001756 INTERNAL_EXTRA_HELM_INSTALL_ARGS=
David K. Bainbridge43422402020-03-06 07:41:22 -08001757 else
David Bainbridged18f4942020-04-14 16:46:13 -07001758 espin - "$VERIFIED"
David K. Bainbridge43422402020-03-06 07:41:22 -08001759 fi
1760 done
David Bainbridged18f4942020-04-14 16:46:13 -07001761 wait_for_pods - "$BBSIM_NS" "$NUM_OF_BBSIM" "includes" "Waiting for BBSIM to start" "$BBSIM_LABEL" "bbsim*"
David Bainbridgee87067b2019-08-12 22:00:12 +00001762 if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001763 NOW="$(date +%s)"
1764 printtime $((NOW - STIME))
David Bainbridgee87067b2019-08-12 22:00:12 +00001765 fi
Test User7d866122019-07-09 17:52:35 +00001766fi
1767
David Bainbridged18f4942020-04-14 16:46:13 -07001768if [ "$WITH_RADIUS" == "yes" ]; then
1769 STIME="$(date +%s)"
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001770 echo -e "Verify RADIUS $LOCK"
1771 bspin - "Verify RADIUS Installed"
David Bainbridged18f4942020-04-14 16:46:13 -07001772 if [ "$HELM_USE_UPGRADE" == "yes" ] || [ "$(helm list --deployed --short --namespace "$INFRA_NS" "^radius\$" | wc -l)" -ne 1 ]; then
1773 espin - "$NOT_VERIFIED"
1774 helm_install - "$INFRA_NS" radius onf/freeradius latest "$_HELM_DESC RADIUS"
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001775 else
David Bainbridged18f4942020-04-14 16:46:13 -07001776 espin - "$VERIFIED"
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001777 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001778 wait_for_pods - "$INFRA_NS" 1 "includes" "Waiting for RADIUS to start" "$NO_LABEL" "radius-.*"
David Bainbridgee87067b2019-08-12 22:00:12 +00001779 if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001780 NOW="$(date +%s)"
1781 printtime $((NOW - STIME))
David Bainbridgee87067b2019-08-12 22:00:12 +00001782 fi
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001783fi
1784
David Bainbridged18f4942020-04-14 16:46:13 -07001785if [ "$WITH_PORT_FORWARDS" == "yes" ]; then
1786 STIME="$(date +%s)"
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -08001787 bspin - "Forward VOLTHA API port $FORWARD"
1788 kill_port_forward voltha-api
David Bainbridged18f4942020-04-14 16:46:13 -07001789 port_forward "$VOLTHA_NS" voltha-api "$VOLTHA_API_PORT" 55555
1790 espin - "$VERIFIED"
1791 if [ "$WITH_ETCD" == "yes" ] || [ "$WITH_ETCD" == "external" ]; then
1792 _NS="$(test "$WITH_ETCD" == "yes" && echo "$VOLTHA_NS" || echo "$INFRA_NS")"
David Bainbridge696bc632020-04-05 21:49:37 -07001793 bspin - "Forward VOLTHA ETCD port $FORWARD"
David Bainbridged18f4942020-04-14 16:46:13 -07001794 kill_port_forward "${ETCD_PREFIX}etcd-cluster-client"
1795 port_forward "$_NS" "${ETCD_PREFIX}etcd-cluster-client" "$VOLTHA_ETCD_PORT" 2379
1796 espin - "$VERIFIED"
David Bainbridge696bc632020-04-05 21:49:37 -07001797 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001798 if [ "$WITH_KAFKA" == "yes" ] || [ $WITH_KAFKA == "external" ]; then
1799 _NS="$(test "$WITH_ETCD" == "yes" && echo "$VOLTHA_NS" || echo "$INFRA_NS")"
David Bainbridge696bc632020-04-05 21:49:37 -07001800 bspin - "Forward VOLTHA Kafka port $FORWARD"
David Bainbridged18f4942020-04-14 16:46:13 -07001801 kill_port_forward "${KAFKA_PREFIX}kafka"
1802 port_forward "$_NS" ${KAFKA_PREFIX}kafka "$VOLTHA_KAFKA_PORT" 9092
1803 espin - "$VERIFIED"
David Bainbridge696bc632020-04-05 21:49:37 -07001804 fi
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -08001805 if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001806 NOW="$(date +%s)"
1807 printtime $((NOW - STIME))
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -08001808 fi
David Bainbridgee87067b2019-08-12 22:00:12 +00001809fi
Test User3d7ad8e2019-07-03 06:15:44 +00001810
David Bainbridged18f4942020-04-14 16:46:13 -07001811if [ "$WITH_ONOS" == "yes" ] && [ "$WITH_RADIUS" != "no" ]; then
David Bainbridge76afd812020-04-06 09:53:52 -07001812 _HOST=radius.$INFRA_NS.svc.cluster.local
David Bainbridge696bc632020-04-05 21:49:37 -07001813 _PORT=1812
David Bainbridged18f4942020-04-14 16:46:13 -07001814 if [ "$WITH_RADIUS" != "yes" ]; then
1815 _HOST="$(echo "$WITH_RADIUS" | cut -d: -f1)"
1816 _PORT="$(echo "$WITH_RADIUS" | cut -s -d: -f2)"
David Bainbridge696bc632020-04-05 21:49:37 -07001817 _PORT=${_PORT:-1812}
1818 fi
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001819 bspin "Configure ONOS RADIUS Connection $GEAR"
David Bainbridged18f4942020-04-14 16:46:13 -07001820 (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
1821 espin "$VERIFIED"
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001822fi
1823
David Bainbridge99ac7a22019-08-31 02:26:43 +00001824if [ "$WITH_CHAOS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001825 STIME="$(date +%s)"
David Bainbridge99ac7a22019-08-31 02:26:43 +00001826 echo -e "Verify kube-monkey $LOCK"
1827 bspin - "Verify kube-monkey Installed"
David Bainbridged18f4942020-04-14 16:46:13 -07001828 if [ "$HELM_USE_UPGRADE" == "yes" ] || [ "$(helm list --deployed --short --namespace kube-monkey "^monkey\$" | wc -l)" -ne 1 ]; then
1829 espin - "$NOT_VERIFIED"
David Bainbridge7f8bf992020-04-08 21:53:22 -07001830 helm_install - kube-monkey monkey ./kube-monkey/helm/kubemonkey latest "$_HELM_DESC Chaos Monkey"
David Bainbridge99ac7a22019-08-31 02:26:43 +00001831 else
David Bainbridged18f4942020-04-14 16:46:13 -07001832 espin - "$VERIFIED"
David Bainbridge99ac7a22019-08-31 02:26:43 +00001833 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001834 wait_for_pods - "kube-monkey" 1 "includes" "Waiting for Chaos to start" "$NO_LABEL" "monkey-.*"
David Bainbridge99ac7a22019-08-31 02:26:43 +00001835 if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001836 NOW="$(date +%s)"
1837 printtime $((NOW - STIME))
David Bainbridge99ac7a22019-08-31 02:26:43 +00001838 fi
1839fi
1840
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001841bspin "Create voltctl configuration file"
David Bainbridged18f4942020-04-14 16:46:13 -07001842(set -x; mkdir -p "$HOME/.volt" >>"$LOG" 2>&1) >>"$LOG" 2>&1
1843MIN_VC_VERSION="$(echo -e "1.0.15\n$VC_VERSION" | sort -V | head -1)"
1844if [ "$WITH_PORT_FORWARDS" == "yes" ]; then
David K. Bainbridgeb859e912020-03-13 14:07:52 -07001845 KAFKA_FLAG="-k localhost:$VOLTHA_KAFKA_PORT"
1846 SERVER_FLAG="-s localhost:$VOLTHA_API_PORT"
1847 ETCD_FLAG=
1848 if [ "$MIN_VC_VERSION" == "1.0.15" ]; then
1849 ETCD_FLAG="-e localhost:$VOLTHA_ETCD_PORT"
1850 fi
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -08001851else
David Bainbridged18f4942020-04-14 16:46:13 -07001852 KAFKA_FLAG="-k $(get_service_ep "$INFRA_NS" "${KAFKA_PREFIX}kafka")"
1853 SERVER_FLAG="-s $(get_service_ep "$VOLTHA_NS" voltha-api)"
David K. Bainbridgeb859e912020-03-13 14:07:52 -07001854 ETCD_FLAG=
1855 if [ "$MIN_VC_VERSION" == "1.0.15" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001856 ETCD_FLAG="-e $(get_service_ep "$INFRA_NS" ${ETCD_PREFIX}etcd-client)"
David K. Bainbridgeb859e912020-03-13 14:07:52 -07001857 fi
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -08001858fi
David Bainbridged18f4942020-04-14 16:46:13 -07001859CMD=("voltctl -a v3 $KAFKA_FLAG $SERVER_FLAG $ETCD_FLAG config")
1860(set -x; ${CMD[*]} > "$HOME/.volt/config-$NAME" 2>>"$LOG") >>"$LOG" 2>&1
1861#(set -x; voltctl -a v3 "$KAFKA_FLAG" "$SERVER_FLAG" "$ETCD_FLAG" config > "$HOME/.volt/config-$NAME" 2>>"$LOG") >>"$LOG" 2>&1
1862espin "$VERIFIED"
Test User08ebbd92019-07-03 17:15:39 +00001863
David Bainbridge0774b232019-08-02 06:37:19 +00001864if [ ! -f "$NAME-env.sh" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001865 touch "$NAME-env.sh"
David Bainbridgeb07fdf72019-07-29 22:51:40 +00001866fi
1867
David Bainbridge596f30d2019-07-30 17:07:59 +00001868for O in $ALL_OPTIONS; do
David Bainbridged18f4942020-04-14 16:46:13 -07001869 VAL="$(eval echo "\$$O")"
1870 if [ -n "$VAL" ] && [ "$(grep -c "^export $O=" "$NAME-env.sh")" -eq 0 ]; then
1871 echo "export $O=\"$(eval echo "\$$O")\"" >> "$NAME-env.sh"
David Bainbridgeb07fdf72019-07-29 22:51:40 +00001872 fi
1873done
1874
David Bainbridged18f4942020-04-14 16:46:13 -07001875if [ "$DEPLOY_K8S" == "yes" ] && [ "$(grep -c "^export KUBECONFIG=" "$NAME-env.sh")" -eq 0 ]; then
1876 echo "export KUBECONFIG=\"$(./bin/kind get kubeconfig-path "--name=voltha-$NAME")\"" >> "$NAME-env.sh"
David Bainbridgeb07fdf72019-07-29 22:51:40 +00001877fi
1878
David Bainbridged18f4942020-04-14 16:46:13 -07001879if [ "$(grep -c "^export VOLTCONFIG=" "$NAME-env.sh")" -eq 0 ]; then
1880 echo "export VOLTCONFIG=\"$HOME/.volt/config-$NAME\"" >> "$NAME-env.sh"
David Bainbridgeb07fdf72019-07-29 22:51:40 +00001881fi
1882
David Bainbridged18f4942020-04-14 16:46:13 -07001883if [ "$(grep -c "^export PATH=" "$NAME-env.sh")" -eq 0 ]; then
1884 echo "export PATH=\"$GOPATH/bin:\$PATH\"" >> "$NAME-env.sh"
David Bainbridgeb07fdf72019-07-29 22:51:40 +00001885fi
1886
Test User7d866122019-07-09 17:52:35 +00001887echo ""
David Bainbridged18f4942020-04-14 16:46:13 -07001888echo "Please issue the following commands in your terminal to ensure that you" | tee -a "$LOG"
1889echo "are accessing the correct Kubernetes/Kind cluster as well as have the " | tee -a "$LOG"
1890echo "tools required by VOLTHA in your command path. " | tee -a "$LOG"
1891echo "" | tee -a "$LOG"
1892echo -en "$BOLD"
1893if [ "$DEPLOY_K8S" == "yes" ]; then
1894 echo "export KUBECONFIG=\"\$(./bin/kind get kubeconfig-path --name=\"voltha-$NAME\")\"" | tee -a "$LOG"
Test Userba1e7e72019-07-10 22:27:54 +00001895fi
David Bainbridged18f4942020-04-14 16:46:13 -07001896echo "export VOLTCONFIG=\"$HOME/.volt/config-$NAME\"" | tee -a "$LOG"
1897echo "export PATH=$GOPATH/bin:\$PATH" | tee -a "$LOG"
1898echo -en "$NORMAL"
1899echo "" | tee -a "$LOG"
1900echo "Thank you for choosing kind-voltha for you quick cluster needs." | tee -a "$LOG"
Test User08ebbd92019-07-03 17:15:39 +00001901
David Bainbridge712afb82019-08-14 19:55:58 +00001902if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001903 NOW="$(date +%s)"
1904 echo -e "$CLOCK ${BOLD}TOTAL: $(duration $((NOW - TOTAL_START_TIME)))${NORMAL}"
David Bainbridge712afb82019-08-14 19:55:58 +00001905fi