blob: c88108b5d6ec77714cbb3a399a9eaaf690cd8d59 [file] [log] [blame]
Test User01ed0642019-07-03 20:17:06 +00001#!/bin/bash
David K. Bainbridgeb7285432019-07-02 22:05:24 -07002# Copyright 2019 Ciena Corporation
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
David Bainbridged049a612020-03-16 17:22:54 -070015set -f
David Bainbridged18f4942020-04-14 16:46:13 -070016unalias -a
David Bainbridge60ffc0f2020-04-27 22:13:22 -070017shopt -s extglob
David Bainbridged18f4942020-04-14 16:46:13 -070018TOTAL_START_TIME="$(date +%s)"
David K. Bainbridgeb7285432019-07-02 22:05:24 -070019
David Bainbridge38dc1e82019-08-12 15:18:45 +000020FANCY=${FANCY:-1}
21if [ "$TERM X" == " X" ]; then
22 FANCY=0
23fi
24
David K. Bainbridgeb7285432019-07-02 22:05:24 -070025# trap ctrl-c and call ctrl_c()
26trap ctrl_c INT
27
28function ctrl_c() {
David Bainbridged18f4942020-04-14 16:46:13 -070029 echo -en "$CNORM"
David K. Bainbridgeb7285432019-07-02 22:05:24 -070030 echo ""
31 echo "ctrl-c trapped"
David Bainbridgec6a6eb62019-10-18 22:50:07 +000032 echo "Thank you for trying 'voltha up'"
David K. Bainbridgeb7285432019-07-02 22:05:24 -070033 exit
34}
35
David Bainbridgea34993d2020-04-01 09:15:42 -070036HELM_VERSION=${HELM_VERSION:-v2.14.3}
David K. Bainbridgeebf38d92020-02-10 10:46:31 -080037VOLTCTL_VERSION=${VOLTCTL_VERSION:-latest}
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -080038KIND_VERSION=${KIND_VERSION:-v0.5.1}
David K. Bainbridgeb3a99372020-01-08 14:39:06 -080039VK_RELEASE=${VK_RELEASE:-master}
David Bainbridge60ffc0f2020-04-27 22:13:22 -070040EXTRA_TOOLS=
Test User08ebbd92019-07-03 17:15:39 +000041
David Bainbridge38dc1e82019-08-12 15:18:45 +000042RED=
43GREEN=
44YELLOW=
45BLUE=
David Bainbridge38dc1e82019-08-12 15:18:45 +000046BOLD=
47NORMAL=
48ERROR=
49CEOL=
50CNORM=
51CIVIS=
David Bainbridged18f4942020-04-14 16:46:13 -070052if [ "$FANCY" -eq 1 ]; then
53 RED="$(tput setaf 1)"
54 GREEN="$(tput setaf 2)"
55 YELLOW="$(tput setaf 3)"
56 BLUE="$(tput setaf 4)"
57 BOLD="$(tput bold)"
58 NORMAL="$(tput sgr0)"
David Bainbridge38dc1e82019-08-12 15:18:45 +000059 ERROR="\xe2\x9c\x97\x20"
David Bainbridged18f4942020-04-14 16:46:13 -070060 CEOL="$(tput el)"
61 CNORM="$(tput cnorm)"
62 CIVIS="$(tput civis)"
David Bainbridge38dc1e82019-08-12 15:18:45 +000063fi
Test User7d866122019-07-09 17:52:35 +000064
Test User3d7ad8e2019-07-03 06:15:44 +000065TYPE=${TYPE:-minimal}
David Bainbridge0774b232019-08-02 06:37:19 +000066NAME=${NAME:-$TYPE}
David K. Bainbridge484d80c2020-03-05 21:44:34 -080067
68ENABLE_ONOS_EXTRANEOUS_RULES=${ENABLE_ONOS_EXTRANEOUS_RULES:-no}
David Bainbridge76afd812020-04-06 09:53:52 -070069INFRA_NS=${INFRA_NS:-default}
70VOLTHA_NS=${VOLTHA_NS:-voltha}
71BBSIM_NS=${BBSIM_NS:-voltha}
72ADAPTER_NS=${ADAPTER_NS:-voltha}
David Bainbridgee87067b2019-08-12 22:00:12 +000073WITH_TIMINGS=${WITH_TIMINGS:-no}
Test User7d866122019-07-09 17:52:35 +000074WITH_BBSIM=${WITH_BBSIM:-no}
David Bainbridge5b7b96b2019-07-25 20:29:13 +000075WITH_RADIUS=${WITH_RADIUS:-no}
Matteo Scandolo78dfee02020-02-13 16:18:03 -080076WITH_EAPOL=${WITH_EAPOL:-yes}
77WITH_DHCP=${WITH_DHCP:-yes}
78WITH_IGMP=${WITH_IGMP:-no}
David Bainbridgeb270c202019-07-26 01:44:42 +000079WITH_ONOS=${WITH_ONOS:-yes}
David Bainbridge60ffc0f2020-04-27 22:13:22 -070080NUM_OF_ONOS=${NUM_OF_ONOS:-1}
81NUM_OF_ATOMIX=${NUM_OF_ATOMIX:-0}
David Bainbridge99ac7a22019-08-31 02:26:43 +000082WITH_CHAOS=${WITH_CHAOS:-no}
David Bainbridge46505fb2019-10-01 21:13:20 +000083WITH_ADAPTERS=${WITH_ADAPTERS:-yes}
David K. Bainbridgeda33d652020-03-06 10:31:23 -080084WITH_SIM_ADAPTERS=${WITH_SIM_ADAPTERS:-no}
David Bainbridge46505fb2019-10-01 21:13:20 +000085WITH_OPEN_ADAPTERS=${WITH_OPEN_ADAPTERS:-yes}
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -080086WITH_PORT_FORWARDS=${WITH_PORT_FORWARDS:-yes}
David Bainbridge696bc632020-04-05 21:49:37 -070087WITH_KAFKA=${WITH_KAFKA:-yes}
88WITH_ETCD=${WITH_ETCD:-yes}
David Bainbridge05cd8822019-11-19 17:43:53 +000089ONLY_ONE=${ONLY_ONE:-yes}
David K. Bainbridgeb859e912020-03-13 14:07:52 -070090CONFIG_SADIS=${CONFIG_SADIS:-no} # yes | no | file | bbsim | URL
David Bainbridge76afd812020-04-06 09:53:52 -070091SADIS_SUBSCRIBERS=${SADIS_SUBSCRIBERS:-http://bbsim.$VOLTHA_NS.svc:50074/v2/subscribers/%s}
92SADIS_BANDWIDTH_PROFILES=${SADIS_BANDWIDTH_PROFILES:-http://bbsim.$VOLTHA_NS.svc:50074/v2/bandwidthprofiles/%s}
Hardik Windlassb3147602020-03-09 16:59:15 +053093SADIS_CFG=${SADIS_CFG:-onos-files/onos-sadis-sample.json}
David Bainbridge27790d62019-08-13 22:43:19 +000094INSTALL_ONOS_APPS=${INSTALL_ONOS_APPS:-no}
Test Userba1e7e72019-07-10 22:27:54 +000095JUST_K8S=${JUST_K8S:-no}
96DEPLOY_K8S=${DEPLOY_K8S:-yes}
David K. Bainbridge0e89cb92019-07-17 11:30:10 -070097INSTALL_KUBECTL=${INSTALL_KUBECTL:-yes}
98INSTALL_HELM=${INSTALL_HELM:-yes}
David Bainbridge7f8bf992020-04-08 21:53:22 -070099HELM_USE_UPGRADE=${HELM_USE_UPGRADE:-no}
David Bainbridge46505fb2019-10-01 21:13:20 +0000100UPDATE_HELM_REPOS=${UPDATE_HELM_REPOS:-yes}
Matteo Scandolofab98622020-01-28 15:17:20 -0800101WAIT_ON_DOWN=${WAIT_ON_DOWN:-yes}
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700102WAIT_TIMEOUT=${WAIT_TIMEOUT:-30m}
103VOLTHA_DOWN_ON_TIMEOUT=${VOLTHA_DOWN_ON_TIMEOUT:-no}
David Bainbridge5b7b96b2019-07-25 20:29:13 +0000104VOLTHA_LOG_LEVEL=${VOLTHA_LOG_LEVEL:-WARN}
David Bainbridge90fd8e32019-08-21 23:32:47 +0000105VOLTHA_CHART=${VOLTHA_CHART:-onf/voltha}
106VOLTHA_CHART_VERSION=${VOLTHA_CHART_VERSION:-latest}
107VOLTHA_BBSIM_CHART=${VOLTHA_BBSIM_CHART:-onf/bbsim}
Matteo Scandolodcd29f52019-10-07 15:42:42 -0700108VOLTHA_BBSIM_CHART_VERSION=${VOLTHA_BBSIM_CHART_VERSION:-latest}
David Bainbridgee10f6d52019-07-25 00:28:13 +0000109VOLTHA_ADAPTER_SIM_CHART=${VOLTHA_ADAPTER_SIM_CHART:-onf/voltha-adapter-simulated}
David Bainbridge90fd8e32019-08-21 23:32:47 +0000110VOLTHA_ADAPTER_SIM_CHART_VERSION=${VOLTHA_ADAPTER_SIM_CHART_VERSION:-latest}
David Bainbridgee10f6d52019-07-25 00:28:13 +0000111VOLTHA_ADAPTER_OPEN_OLT_CHART=${VOLTHA_ADAPTER_OPEN_OLT_CHART:-onf/voltha-adapter-openolt}
David Bainbridge90fd8e32019-08-21 23:32:47 +0000112VOLTHA_ADAPTER_OPEN_OLT_CHART_VERSION=${VOLTHA_ADAPTER_OPEN_OLT_CHART_VERSION:-latest}
David Bainbridgee10f6d52019-07-25 00:28:13 +0000113VOLTHA_ADAPTER_OPEN_ONU_CHART=${VOLTHA_ADAPTER_OPEN_ONU_CHART:-onf/voltha-adapter-openonu}
David Bainbridge90fd8e32019-08-21 23:32:47 +0000114VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION=${VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION:-latest}
David K. Bainbridgeda33d652020-03-06 10:31:23 -0800115ONOS_CHART=${ONOS_CHART:-onf/onos}
Andrea Campanella21323292019-12-18 11:44:19 -0800116ONOS_CHART_VERSION=${ONOS_CHART_VERSION:-latest}
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700117ONOS_CLASSIC_CHART=${ONOS_CLASSIC_CHART:-onos/onos-classic}
118ONOS_CLASSIC_CHART_VERSION=${ONOS_CHART_VERSION:-latest}
David Bainbridgecf546362020-04-21 23:18:50 -0700119KAFKA_CHART=${KAFKA_CHART:-incubator/kafka}
David Bainbridgeb9093522020-04-15 14:32:44 -0700120KAFKA_CHART_VERSION=${KAFKA_CHART_VERSION:=0.15.3}
David Bainbridge2eaf2cf2020-03-18 12:54:08 -0700121EXTRA_HELM_INSTALL_ARGS=${EXTRA_HELM_INSTALL_ARGS:-}
122INTERNAL_EXTRA_HELM_INSTALL_ARGS=
uottrembb16d3982020-02-28 08:34:36 +0100123NUM_OF_BBSIM=${NUM_OF_BBSIM:-1}
Matteo Scandolo67335f02020-04-09 11:19:53 -0700124NUM_OF_OPENONU=${NUM_OF_OPENONU:-1}
uottrembb16d3982020-02-28 08:34:36 +0100125MAX_NUM_OF_BBSIM=10
Matteo Scandolo67335f02020-04-09 11:19:53 -0700126MAX_NUM_OF_OPENONU=10
Matteo Scandoloc2eb0672020-05-01 14:43:15 -0700127LEGACY_BBSIM_INDEX=${LEGACY_BBSIM_INDEX:-no}
Test Userba1e7e72019-07-10 22:27:54 +0000128
David Bainbridged18f4942020-04-14 16:46:13 -0700129HOSTOS="$(uname -s | tr "[:upper:]" "[:lower:"])"
130HOSTARCH="$(uname -m | tr "[:upper:]" "[:lower:"])"
131if [ "$HOSTARCH" == "x86_64" ]; then
Test Userba1e7e72019-07-10 22:27:54 +0000132 HOSTARCH="amd64"
133fi
David Bainbridge7db44002020-04-09 12:54:29 -0700134BBSIM_LABEL="-l app=bbsim"
David Bainbridged18f4942020-04-14 16:46:13 -0700135NO_LABEL=
Test User7d866122019-07-09 17:52:35 +0000136
uottrembb16d3982020-02-28 08:34:36 +0100137# check number (range) of bbsim, max bbsim must not exceed 10 instances!
138# note: instances will be numbered from 0 to 9
139if [ "$1" == "up" ]; then
David K. Bainbridge43422402020-03-06 07:41:22 -0800140 if [ "$NUM_OF_BBSIM" -lt 1 ]; then
Matteo Scandolo67335f02020-04-09 11:19:53 -0700141 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} Invalid setting of BBSIM instances. NUM_OF_BBSIM (${NUM_OF_BBSIM}) is less than 1${NORMAL}"
David K. Bainbridge43422402020-03-06 07:41:22 -0800142 exit 1
143 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700144 if [ "$NUM_OF_BBSIM" -gt "$MAX_NUM_OF_BBSIM" ]; then
Matteo Scandolo67335f02020-04-09 11:19:53 -0700145 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} Invalid setting of BBSIM instances. NUM_OF_BBSIM (${NUM_OF_BBSIM}) is greater than $MAX_NUM_OF_BBSIM${NORMAL}"
146 exit 1
147 fi
148
149 if [ "$NUM_OF_OPENONU" -lt 1 ]; then
150 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} Invalid setting of OPENONU instances. NUM_OF_OPENONU (${NUM_OF_OPENONU}) is less than 1${NORMAL}"
151 exit 1
152 fi
153 if [ "$NUM_OF_OPENONU" -gt "$MAX_NUM_OF_OPENONU" ]; then
154 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} Invalid setting of OPENONU instances. NUM_OF_OPENONU (${NUM_OF_OPENONU}) is greater than $MAX_NUM_OF_OPENONU${NORMAL}"
David K. Bainbridge43422402020-03-06 07:41:22 -0800155 exit 1
156 fi
uottrembb16d3982020-02-28 08:34:36 +0100157fi
Test User7d866122019-07-09 17:52:35 +0000158# Verify TYPE setting
David Bainbridged18f4942020-04-14 16:46:13 -0700159if [ "$(echo ":minimal:full:" | grep -ic ":$TYPE:")" -eq 0 ]; then
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700160 >&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 +0000161 exit 1
162fi
163
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700164# checks to see if a given WORD is in the given LIST of words
165function is_in() {
166 local WORD LIST
167 WORD="$1"; shift
168 LIST="$*"
169 LIST=${LIST//+([[:space:],|])/:}
170
171 [ "$(echo ":$LIST:" | grep -ic ":$WORD:")" -ne 0 ]
172}
173
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700174function parseDuration() {
David Bainbridged18f4942020-04-14 16:46:13 -0700175 local DUR RESULT TERM TERMS VALUE UNIT
176 DUR=$1
177 RESULT=0
178 TERMS="$(echo "$DUR" | sed -Ee 's/([sSmMhHdD])/\1 /g' -e 's/,$//g')"
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700179 for TERM in $TERMS; do
David Bainbridged18f4942020-04-14 16:46:13 -0700180 VALUE="$(echo "$TERM" | sed -Ee 's/([0-9]+)[sSmMhHdD]/\1/')"
181 UNIT="$(echo "$TERM" | sed -Ee 's/[0-9]+([sSmMhHdD])/\1/')"
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700182 case $UNIT in
183 s|S)
David Bainbridged18f4942020-04-14 16:46:13 -0700184 RESULT=$((RESULT + VALUE)) ;;
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700185 m|M)
David Bainbridged18f4942020-04-14 16:46:13 -0700186 RESULT=$((RESULT + (VALUE * 60))) ;;
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700187 h|H)
David Bainbridged18f4942020-04-14 16:46:13 -0700188 RESULT=$((RESULT + (VALUE * 3600))) ;;
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700189 d|D)
David Bainbridged18f4942020-04-14 16:46:13 -0700190 RESULT=$((RESULT + (VALUE * 86400))) ;;
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700191 *) ;;
192 esac
193 done
194 echo $RESULT
195}
196
197function doTimeout() {
198 local MSG=$1
199 2>&1 echo -e "\n${RED}${BOLD}${ERROR}TIMEOUT:${NORMAL}${RED} Operation timed out after '$WAIT_TIMEOUT': $MSG"
200 exit 125
201}
202
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -0800203function get_service_ep() {
204 local NS=$1
205 local NAME=$2
David Bainbridged18f4942020-04-14 16:46:13 -0700206 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 -0800207}
208
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000209# Used to verify configuration values are set to "yes" or "no" value or convert
210# equivalents to "yes" or "no"
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700211YES="y,yes,t,true,1"
212NO="n,no,f,false,0"
213YES_OR_NO="$YES,$NO"
214
215# If the given VAR matches a truth value then normalize that
216# value, else return original value
217function normalize_yes_no() {
218 local VAR VAL
219 VAR=$1
220 VAL="$(eval echo "\$$VAR")"
221 if ! is_in "$VAL" "$YES_OR_NO"; then
222 echo "$VAL"
223 return 1
224 fi
225 if is_in "$VAL" "$YES"; then
226 echo "yes"
227 else
228 echo "no"
229 fi
230 return 0
231}
232
233# If the given VAR matches a truth value then normalize that
234# value, else display an error
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000235function verify_yes_no() {
David Bainbridged18f4942020-04-14 16:46:13 -0700236 local VAR VAL
237 VAR=$1
238 VAL="$(eval echo "\$$VAR")"
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700239 if ! is_in "$VAL" "$YES_OR_NO"; then
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000240 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} Invalid '$VAR' value of '$VAL'. Should be 'yes' or 'no'${NORMAL}"
241 echo "INVALID"
242 return 1
243 fi
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700244 if is_in "$VAL" "$YES"; then
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000245 echo "yes"
246 else
247 echo "no"
248 fi
249 return 0
250}
Test User7d866122019-07-09 17:52:35 +0000251
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000252ALL_YES_NO="\
David K. Bainbridge484d80c2020-03-05 21:44:34 -0800253 ENABLE_ONOS_EXTRANEOUS_RULES \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000254 WITH_TIMINGS \
255 WITH_BBSIM \
Matteo Scandolo78dfee02020-02-13 16:18:03 -0800256 WITH_EAPOL \
257 WITH_DHCP \
258 WITH_IGMP \
David Bainbridge99ac7a22019-08-31 02:26:43 +0000259 WITH_CHAOS \
David Bainbridge46505fb2019-10-01 21:13:20 +0000260 WITH_ADAPTERS \
261 WITH_SIM_ADAPTERS \
262 WITH_OPEN_ADAPTERS \
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -0800263 WITH_PORT_FORWARDS \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000264 JUST_K8S \
265 DEPLOY_K8S \
266 INSTALL_ONOS_APPS \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000267 INSTALL_KUBECTL \
268 INSTALL_HELM \
David Bainbridge7f8bf992020-04-08 21:53:22 -0700269 HELM_USE_UPGRADE \
David Bainbridge46505fb2019-10-01 21:13:20 +0000270 UPDATE_HELM_REPOS \
David Bainbridge4f1b5562019-08-19 04:46:52 +0000271 WAIT_ON_DOWN \
David Bainbridge70c0ea82019-11-14 23:25:26 +0000272 ONLY_ONE \
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700273 VOLTHA_DOWN_ON_TIMEOUT \
Matteo Scandoloc2eb0672020-05-01 14:43:15 -0700274 LEGACY_BBSIM_INDEX \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000275 "
David Bainbridge5b7b96b2019-07-25 20:29:13 +0000276
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700277OPT_YES_NO="\
278 CONFIG_SADIS \
279 WITH_KAFKA \
280 WITH_RADIUS \
281 WITH_ETCD \
282 WITH_ONOS \
283 "
284
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000285ALL_OPTIONS="\
286 NAME \
287 TYPE \
288 $ALL_YES_NO \
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700289 $OPT_YES_NO \
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700290 WAIT_TIMEOUT \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000291 VOLTHA_LOG_LEVEL \
292 VOLTHA_CHART \
David Bainbridge90fd8e32019-08-21 23:32:47 +0000293 VOLTHA_CHART_VERSION \
294 VOLTHA_BBSIM_CHART \
295 VOLTHA_BBSIM_CHART_VERSION \
uottrembd5a20572020-03-06 09:15:01 +0100296 NUM_OF_BBSIM \
Matteo Scandolo67335f02020-04-09 11:19:53 -0700297 NUM_OF_OPENONU \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000298 VOLTHA_ADAPTER_SIM_CHART \
David Bainbridge90fd8e32019-08-21 23:32:47 +0000299 VOLTHA_ADAPTER_SIM_CHART_VERSION \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000300 VOLTHA_ADAPTER_OPEN_OLT_CHART \
David Bainbridge90fd8e32019-08-21 23:32:47 +0000301 VOLTHA_ADAPTER_OPEN_OLT_CHART_VERSION \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000302 VOLTHA_ADAPTER_OPEN_ONU_CHART \
David Bainbridge90fd8e32019-08-21 23:32:47 +0000303 VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION \
David K. Bainbridgeda33d652020-03-06 10:31:23 -0800304 ONOS_CHART \
Andrea Campanella21323292019-12-18 11:44:19 -0800305 ONOS_CHART_VERSION \
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700306 ONOS_CLASSIC_CHART \
307 ONOS_CLASSIC_CHART_VERSION \
David Bainbridgecf546362020-04-21 23:18:50 -0700308 KAFKA_CHART \
David Bainbridgeb9093522020-04-15 14:32:44 -0700309 KAFKA_CHART_VERSION \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000310 ONOS_API_PORT \
311 ONOS_SSH_PORT \
Hardik Windlassb3147602020-03-09 16:59:15 +0530312 SADIS_CFG \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000313 VOLTHA_API_PORT \
314 VOLTHA_SSH_PORT \
315 VOLTHA_ETCD_PORT \
David K. Bainbridge00ecd382020-02-28 12:31:58 -0800316 VOLTHA_KAFKA_PORT \
David K. Bainbridge8f7f30b2020-01-08 13:06:16 -0800317 VK_RELEASE \
318 KIND_VERSION \
319 VOLTCTL_VERSION \
David Bainbridgea34993d2020-04-01 09:15:42 -0700320 HELM_VERSION \
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700321 NUM_OF_ONOS \
322 NUM_OF_ATOMIX \
David Bainbridge6ca40102020-04-08 11:30:40 -0700323 VOLTHA_NS \
324 ADAPTER_NS \
325 INFRA_NS \
326 BBSIM_NS \
David Bainbridge7db44002020-04-09 12:54:29 -0700327 SADIS_BANDWIDTH_PROFILES \
328 SADIS_SUBSCRIBERS \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000329 "
David Bainbridge01294952019-07-30 19:33:45 +0000330
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000331# Iterate over yes/no configuration options and validate
332for VAR in $ALL_YES_NO; do
David Bainbridged18f4942020-04-14 16:46:13 -0700333 eval "$VAR"="$(verify_yes_no "$VAR")"
334 if [ "$(eval echo "\$$VAR")" == "INVALID" ]; then
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000335 exit 1;
336 fi
337done
David Bainbridgeb270c202019-07-26 01:44:42 +0000338
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700339# Iterate over optional yes/no configuration options and
340# normalize values if they are truth values
341for VAR in $OPT_YES_NO; do
342 eval "$VAR"="$(normalize_yes_no "$VAR")"
343done
David Bainbridge15f6f232020-03-30 09:15:43 -0700344
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700345# normalize non-truth value options
346if is_in "$WITH_KAFKA" "e,external"; then
David Bainbridge76afd812020-04-06 09:53:52 -0700347 WITH_KAFKA="external"
348fi
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700349if is_in "$WITH_ETCD" "e,external"; then
David Bainbridge76afd812020-04-06 09:53:52 -0700350 WITH_ETCD="external"
351fi
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700352if is_in "$WITH_ONOS" "l,legacy"; then
353 WITH_ONOS="legacy"
354elif is_in "$WITH_ONOS" "c,classic"; then
355 WITH_ONOS="classic"
356elif is_in "$WITH_ONOS" "u,m,micro"; then
357 WITH_ONOS="micro"
David Bainbridge29c31cb2020-04-06 09:45:50 -0700358fi
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700359
360if [ "$WITH_ONOS" == "micro" ]; then
361 >&2 echo -e "${YELLOW}${BOLD}${ERROR}WARNING:${NORMAL}${YELLOW} The value specified as WITH_ONOS, '$WITH_ONOS', is not valid.${NORMAL}"
362 exit 1
David Bainbridge29c31cb2020-04-06 09:45:50 -0700363fi
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700364
365if is_in "$WITH_ONOS" "yes,classic"; then
366 # there is an extra utility required if we are using ONOS CLASSIC as
367 # the chart for classic specifies images differently
368 EXTRA_TOOLS+=" yq"
David Bainbridge76afd812020-04-06 09:53:52 -0700369fi
David Bainbridge696bc632020-04-05 21:49:37 -0700370
David Bainbridged18f4942020-04-14 16:46:13 -0700371if [ "$HELM_USE_UPGRADE" == "yes" ]; then
David Bainbridge7f8bf992020-04-08 21:53:22 -0700372 _HELM_DESC="Upgrade/Install"
373else
374 _HELM_DESC="Install"
375fi
376
David Bainbridged18f4942020-04-14 16:46:13 -0700377ETCD_PREFIX=
378KAFKA_PREFIX=
379if [ "$WITH_ETCD" == "yes" ]; then
380 ETCD_PREFIX="voltha-"
381fi
382if [ "$WITH_KAFKA" == "yes" ]; then
383 KAFKA_PREFIX="voltha-"
384fi
385
David K. Bainbridgeda33d652020-03-06 10:31:23 -0800386# Check for prerequiste tools
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700387TOOLS="curl sed jq $EXTRA_TOOLS"
David Bainbridged18f4942020-04-14 16:46:13 -0700388if [ "$DEPLOY_K8S" == "yes" ]; then
David K. Bainbridgeda33d652020-03-06 10:31:23 -0800389 TOOLS+=" docker"
390fi
391NOT_FOUND=""
392for T in $TOOLS; do
David Bainbridged18f4942020-04-14 16:46:13 -0700393 if [ -z "$(command -v "$T")" ]; then
David K. Bainbridgeda33d652020-03-06 10:31:23 -0800394 NOT_FOUND+=" $T"
395 fi
396done
397
David Bainbridged18f4942020-04-14 16:46:13 -0700398if [ -n "$NOT_FOUND" ]; then
David K. Bainbridgeda33d652020-03-06 10:31:23 -0800399 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} The following required tools where not found, please install them:$NOT_FOUND"
400 exit 1
401fi
402
David Bainbridged18f4942020-04-14 16:46:13 -0700403TIMEOUT_SECONDS="$(parseDuration "$WAIT_TIMEOUT")"
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700404
David Bainbridge0774b232019-08-02 06:37:19 +0000405mkdir -p .voltha
406touch .voltha/ports
David Bainbridged18f4942020-04-14 16:46:13 -0700407HAVE="$(grep "$NAME" .voltha/ports)"
David Bainbridge0774b232019-08-02 06:37:19 +0000408if [ "$HAVE X" == " X" ]; then
409 # Find free port prefix
410 START=81
411 while true; do
David Bainbridged18f4942020-04-14 16:46:13 -0700412 if [ "$(grep -c $START .voltha/ports)" -eq 0 ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000413 break
414 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700415 START="$((START + 1))"
David Bainbridge0774b232019-08-02 06:37:19 +0000416 done
David Bainbridged18f4942020-04-14 16:46:13 -0700417 DELTA="$((START - 81))"
David Bainbridgea2595422019-10-22 03:54:28 +0000418 ONOS_API_PORT=${ONOS_API_PORT:-${START}81}
419 ONOS_SSH_PORT=${ONOS_SSH_PORT:-${START}01}
David Bainbridged18f4942020-04-14 16:46:13 -0700420 VOLTHA_API_PORT=${VOLTHA_API_PORT:-5$((55 + DELTA))55}
421 VOLTHA_SSH_PORT=${VOLTHA_SSH_PORT:-$((50 + DELTA))22}
422 VOLTHA_ETCD_PORT=${VOLTHA_ETCD_PORT:-$((23 + DELTA))79}
423 VOLTHA_KAFKA_PORT=${VOLTHA_KAFKA_PORT:-$((90 + DELTA))92}
Test User01ed0642019-07-03 20:17:06 +0000424else
David Bainbridged18f4942020-04-14 16:46:13 -0700425 VALUES="$(echo "$HAVE" | sed -e 's/\s//g' | cut -d= -f2)"
426 ONOS_API_PORT=${ONOS_API_PORT:-$(echo "$VALUES" | cut -d, -f1)}
427 ONOS_SSH_PORT=${ONOS_SSH_PORT:-$(echo "$VALUES" | cut -d, -f2)}
428 VOLTHA_API_PORT=${VOLTHA_API_PORT:-$(echo "$VALUES" | cut -d, -f3)}
429 VOLTHA_SSH_PORT=${VOLTHA_SSH_PORT:-$(echo "$VALUES" | cut -d, -f4)}
430 VOLTHA_ETCD_PORT=${VOLTHA_ETCD_PORT:-$(echo "$VALUES" | cut -d, -f5)}
431 VOLTHA_KAFKA_PORT=${VOLTHA_KAFKA_PORT:-$(echo "$VALUES" | cut -d, -f6)}
David K. Bainbridge00ecd382020-02-28 12:31:58 -0800432
David K. Bainbridge00ecd382020-02-28 12:31:58 -0800433 # A bit of a hueristic required here as the KAFKA port forward was
434 # added after the .voltha/ports files was created. Basically, if
435 # the VOLTHA_KAFKA_PORT isn't in the file then calculate the original
436 # DELTA from the VOLTHA_SSH_PORT and apply it to the VOLTHA_KAFKA_PORT
437 if [ -z "$VOLTHA_KAFKA_PORT" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -0700438 DELTA="$((VOLTHA_SSH_PORT/100-50))"
439 VOLTHA_KAFKA_PORT=${VOLTHA_KAFKA_PORT:-$((90 + DELTA))92}
David K. Bainbridge00ecd382020-02-28 12:31:58 -0800440 fi
Test User01ed0642019-07-03 20:17:06 +0000441fi
442
David Bainbridged18f4942020-04-14 16:46:13 -0700443PORTTMP="$(mktemp -u)"
444grep -v "$NAME" .voltha/ports > "$PORTTMP"
445echo "$NAME=$ONOS_API_PORT,$ONOS_SSH_PORT,$VOLTHA_API_PORT,$VOLTHA_SSH_PORT,$VOLTHA_ETCD_PORT,$VOLTHA_KAFKA_PORT" >> "$PORTTMP"
446cp "$PORTTMP" .voltha/ports
447rm -f "$PORTTMP"
David Bainbridge0774b232019-08-02 06:37:19 +0000448
David Bainbridge27790d62019-08-13 22:43:19 +0000449export ONOS_API_PORT ONOS_SSH_PORT
David Bainbridge01294952019-07-30 19:33:45 +0000450
Test Userd87942b2019-07-03 07:20:24 +0000451IDX=1
David Bainbridgee87067b2019-08-12 22:00:12 +0000452CLOCK="TIME:"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000453SPIN_PARTS=
454NOT_VERIFIED=
David Bainbridgef858a022019-08-14 21:25:11 +0000455THEX=
456BUILD=
David Bainbridge38dc1e82019-08-12 15:18:45 +0000457VERIFIED=
458HELM=
459OLD_KEY=
460BIRD=
461HIGH_VOLTAGE=
462PLUG=
David Bainbridge38dc1e82019-08-12 15:18:45 +0000463FORWARD=
David Bainbridge38dc1e82019-08-12 15:18:45 +0000464GO=
465DOWNLOAD=
466GEAR=
467NO_ENTRY=
468LOCK=
469
David Bainbridged18f4942020-04-14 16:46:13 -0700470if [ "$FANCY" -eq 1 ]; then
471 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 +0000472 CLOCK="\xe2\x8f\xb1"
David Bainbridgef858a022019-08-14 21:25:11 +0000473 THEX="${RED}${BOLD}\xe2\x9c\x97\x20${NORMAL}"
David Bainbridgef858a022019-08-14 21:25:11 +0000474 BUILD="${YELLOW}${BOLD}\xf0\x9f\x8f\x97${NORMAL}"
475 NOT_VERIFIED="$BUILD"
476 VERIFIED="${GREEN}${BOLD}\xe2\x9c\x93\x20${NORMAL}"
477 HELM="${BLUE}${BOLD}\xE2\x8E\x88${NORMAL}"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000478 OLD_KEY="\xF0\x9F\x97\x9D"
479 BIRD="\xF0\x9F\x90\xA6"
480 HIGH_VOLTAGE="\xE2\x9A\xA1"
481 PLUG="\xF0\x9F\xa7\xa9"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000482 FORWARD="\xE2\x87\xA8"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000483 GO="\xf0\x9f\x9a\x80"
484 DOWNLOAD="\xf0\x9f\x93\xa5"
485 GEAR="\xe2\x9a\x99"
486 NO_ENTRY="\xe2\x9b\x94"
487 LOCK="\xf0\x9f\x94\x92"
488fi
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700489
David Bainbridge712afb82019-08-14 19:55:58 +0000490duration() {
David Bainbridged18f4942020-04-14 16:46:13 -0700491 local h m s t
492 h="$(($1 / 3600))"
493 m="$(($1 % 3600 / 60))"
494 s="$(($1 % 60))"
495 t=""
David Bainbridgee87067b2019-08-12 22:00:12 +0000496
David Bainbridged18f4942020-04-14 16:46:13 -0700497 if [ "$h" -gt 0 ]; then
David Bainbridgee87067b2019-08-12 22:00:12 +0000498 t="$t${h}h"
499 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700500 if [ "$m" -gt 0 ]; then
David Bainbridgee87067b2019-08-12 22:00:12 +0000501 t="$t${m}m"
502 fi
David Bainbridge712afb82019-08-14 19:55:58 +0000503 echo "$t${s}s"
504}
505
506printtime() {
David Bainbridged18f4942020-04-14 16:46:13 -0700507 local INDENT
David Bainbridge712afb82019-08-14 19:55:58 +0000508 if [ "$1" == "-" ]; then
509 INDENT=" "
510 shift
511 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700512 echo -e "$INDENT $CLOCK $(duration "$1")"
David Bainbridgee87067b2019-08-12 22:00:12 +0000513}
514
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700515bspin() {
Test Userd87942b2019-07-03 07:20:24 +0000516 IDX=1
David Bainbridged18f4942020-04-14 16:46:13 -0700517 local INDENT
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700518 if [ "$1" == "-" ]; then
519 INDENT=" "
520 shift
521 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700522 if [ "$FANCY" -eq 0 ]; then
523 LINE="${*//[[:space:]+-]}"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000524 if [ "$LINE X" == " X" ]; then
525 return
526 fi
527 echo -e "$CIVIS$INDENT$*"
528 else
529 echo -en "$CIVIS$INDENT $*"
530 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700531}
532
533sspin() {
David Bainbridged18f4942020-04-14 16:46:13 -0700534 local INDENT
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700535 if [ "$1" == "-" ]; then
536 INDENT=" "
537 shift
538 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700539 if [ "$FANCY" -eq 0 ]; then
540 LINE="${*//[[:space:]+-]}"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000541 if [ "$LINE X" == " X" ]; then
542 return
543 fi
544 echo -e "$INDENT$*"
545 else
David Bainbridged18f4942020-04-14 16:46:13 -0700546 C="$(echo "$SPIN_PARTS" | cut '-d ' -f "$IDX")"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000547 echo -en "\r$INDENT$C $*"
David Bainbridged18f4942020-04-14 16:46:13 -0700548 IDX="$((IDX + 1))"
549 if [ "$IDX" -gt 8 ]; then
David Bainbridge38dc1e82019-08-12 15:18:45 +0000550 IDX=1
551 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700552 fi
553}
554
555espin() {
David Bainbridged18f4942020-04-14 16:46:13 -0700556 local INDENT
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700557 if [ "$1" == "-" ]; then
558 INDENT=" "
559 shift
560 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700561 if [ "$FANCY" -eq 0 ]; then
562 LINE="${*//[[:space:]+-]}"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000563 if [ "$LINE X" == " X" ]; then
564 return
565 fi
566 echo -e "$INDENT$*"
567 else
568 echo -e "\r$INDENT$*$CNORM"
569 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700570}
571
David Bainbridged18f4942020-04-14 16:46:13 -0700572if [ "$1" == "get" ] && [ "$2" == "voltconfig" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000573 echo "$HOME/.volt/config-$NAME"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000574 exit
575fi
576
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700577if [ $# -ne 1 ] || ! is_in "$1" "up,down,dump"; then
David Bainbridgeac7f8072019-08-01 22:15:33 +0000578 >&2 echo "What wouild you like to do today:"
579 >&2 echo " up - bring up voltha"
580 >&2 echo " down - tear down voltha"
581 >&2 echo " dump - create a debug dump of running system"
582 exit 1
583fi
584
David Bainbridge4f1b5562019-08-19 04:46:52 +0000585push_onos_config() {
David Bainbridged18f4942020-04-14 16:46:13 -0700586 local TYPE MSG RESOURCE DATA CMD_ECHO CMD_OUTPUT SC_OUTPUT WAIT_START NOW
587 TYPE=$1
588 MSG=$2
589 RESOURCE=$3
590 DATA=$4
David Bainbridge4f1b5562019-08-19 04:46:52 +0000591
David K. Bainbridgeb4b163b2020-02-19 15:55:06 -0800592 # Thanks to the latest version of ONOS using the return code 207 this gets a
593 # whole lot nastier. Can't thank them enough for doing this. So in order to
594 # capture the command and the output in the log file as well as capture the
595 # status code to verify it is 200 and not 207 mutltiple files and a bit of
596 # hackery must be used. Thanks again ONOS.
David Bainbridged18f4942020-04-14 16:46:13 -0700597 CMD_ECHO="$(mktemp -u)"
598 CMD_OUTPUT="$(mktemp -u)"
599 SC_OUTPUT="$(mktemp -u)"
600 WAIT_START="$(date +%s)"
David K. Bainbridgeb4b163b2020-02-19 15:55:06 -0800601
David Bainbridge4f1b5562019-08-19 04:46:52 +0000602 bspin - "$MSG $GEAR"
603 while true; do
David Bainbridged18f4942020-04-14 16:46:13 -0700604 NOW="$(date +%s)"
605 if [ "$((NOW - WAIT_START))" -gt "$TIMEOUT_SECONDS" ]; then
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700606 espin - "$THEX"
David Bainbridged18f4942020-04-14 16:46:13 -0700607 rm -f "$CMD_ECHO" "$CMD_OUTPUT" "$SC_OUTPUT"
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700608 doTimeout "waiting for ONOS config push on $RESOURCE"
609 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700610 if [ "$TYPE" == "file" ]; then
611 (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 -0700612 RESULT=$?
Matteo Scandolo78dfee02020-02-13 16:18:03 -0800613 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700614 if [ "$TYPE" == "json" ]; then
615 (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 -0700616 RESULT=$?
Matteo Scandolo78dfee02020-02-13 16:18:03 -0800617 fi
David K. Bainbridgeb4b163b2020-02-19 15:55:06 -0800618 # Dump everything to the log
David Bainbridged18f4942020-04-14 16:46:13 -0700619 cat "$CMD_ECHO" >> "$LOG"
620 test -r "$CMD_OUTPUT" && cat "$CMD_OUTPUT" >> "$LOG"
621 SC="$(cat "$SC_OUTPUT")"
622 echo "RESPONSE CODE: $SC" >> "$LOG"
623 echo "ERROR CODE: $RESULT" >> "$LOG"
David K. Bainbridgeb4b163b2020-02-19 15:55:06 -0800624
625 # clean up temp files
David Bainbridged18f4942020-04-14 16:46:13 -0700626 rm -f "$CMD_ECHO" "$CMD_OUTPUT" "$SC_OUTPUT"
627 if [ "$RESULT" -eq 0 ] && [ "$SC" == "200" ]; then
David Bainbridge4f1b5562019-08-19 04:46:52 +0000628 break
629 fi
Matteo Scandolo9a77a732020-01-09 14:24:12 -0800630 sleep 1
David Bainbridge4f1b5562019-08-19 04:46:52 +0000631 sspin -
632 done
David Bainbridged18f4942020-04-14 16:46:13 -0700633 espin - "$VERIFIED"
David Bainbridge4f1b5562019-08-19 04:46:52 +0000634}
635
Matteo Scandolo9a77a732020-01-09 14:24:12 -0800636check_onos_app_active() {
David Bainbridged18f4942020-04-14 16:46:13 -0700637 local APP_ID WAIT_START RESULT NOW
638 APP_ID=$1
639 WAIT_START="$(date +%s)"
Matteo Scandolo9a77a732020-01-09 14:24:12 -0800640
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700641 bspin - "Checking that $APP_ID is active $CLOCK"
642 while true; do
David Bainbridged18f4942020-04-14 16:46:13 -0700643 NOW="$(date +%s)"
644 if [ "$((NOW - WAIT_START))" -gt "$TIMEOUT_SECONDS" ]; then
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700645 espin - "$THEX"
646 doTimeout "waiting for ONOS application activation '$APP_ID'"
647 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700648 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 -0700649 break
650 fi
651 sleep 1
652 sspin -
653 done
654 sleep 5 # OSGI components take a little longer that the app to activate
David Bainbridged18f4942020-04-14 16:46:13 -0700655 espin - "$VERIFIED"
Matteo Scandolo9a77a732020-01-09 14:24:12 -0800656}
657
David Bainbridge4f1b5562019-08-19 04:46:52 +0000658override_onos_app() {
David Bainbridged18f4942020-04-14 16:46:13 -0700659 local APP NAME WAIT_START NOW
660 APP=$1
661 NAME="$(basename "$APP" | sed -e 's/^[0-9][0-9]*-//g' -e 's/-.*$//g')"
662 WAIT_START="$(date +%s)"
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700663
David Bainbridge4f1b5562019-08-19 04:46:52 +0000664 while true; do
David Bainbridged18f4942020-04-14 16:46:13 -0700665 NOW="$(date +%s)"
666 if [ "$((NOW - WAIT_START))" -gt "$TIMEOUT_SECONDS" ]; then
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700667 espin - "$THEX"
668 doTimeout "waiting to overwrite ONOS application '$APP'"
669 fi
David Bainbridge4f1b5562019-08-19 04:46:52 +0000670 sspin -
671 # Attempt to delete old version (if it exists)
David Bainbridged18f4942020-04-14 16:46:13 -0700672 (set -x; curl --fail -sSL --user karaf:karaf -X DELETE "http://$_ONOS_API_EP/onos/v1/applications/$NAME" >>"$LOG" 2>&1) >>"$LOG" 2>&1
673 RESULT=$?
David Bainbridge4f1b5562019-08-19 04:46:52 +0000674 sspin -
David Bainbridged18f4942020-04-14 16:46:13 -0700675 if [ $RESULT -ne 0 ]; then
David Bainbridge4f1b5562019-08-19 04:46:52 +0000676 continue
677 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700678 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 +0000679 break
680 fi
681 sleep .2
682 done
683}
684
685activate_onos_app() {
David Bainbridged18f4942020-04-14 16:46:13 -0700686 local MSG APP WAIT_START NOW
687 MSG="$1"
688 APP=$2
689 WAIT_START="$(date +%s)"
David Bainbridge4f1b5562019-08-19 04:46:52 +0000690
691 bspin - "$MSG $GO"
692 while true; do
David Bainbridged18f4942020-04-14 16:46:13 -0700693 NOW="$(date +%s)"
694 if [ "$((NOW - WAIT_START))" -gt "$TIMEOUT_SECONDS" ]; then
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700695 espin - "$THEX"
696 doTimeout "waiting to activate ONOS application '$APP'"
697 fi
David Bainbridge4f1b5562019-08-19 04:46:52 +0000698 sspin -
David Bainbridged18f4942020-04-14 16:46:13 -0700699 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 +0000700 break
701 fi
702 sleep .2
703 done
704 espin - "$VERIFIED"
705}
706
707count_pods() {
David Bainbridged18f4942020-04-14 16:46:13 -0700708 local NAMESPACE STATES LABELS CMD PODS
709 NAMESPACE=$1; shift
David Bainbridge4f1b5562019-08-19 04:46:52 +0000710 if [ "$NAMESPACE" == "all-namespaces" ]; then
711 NAMESPACE="--all-namespaces"
712 else
713 NAMESPACE="-n $NAMESPACE"
714 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700715 STATES=$1; shift
716 LABELS=$1; shift
717 CMD=("kubectl get $NAMESPACE $LABELS pod")
718 PODS=$(${CMD[*]} -o go-template="{{range .items}}{{.metadata.name}}/{{.status.phase}}/_{{range .status.containerStatuses}}{{.ready}}_{{end}} {{end}}")
David Bainbridge4f1b5562019-08-19 04:46:52 +0000719 local COUNT=0
720 local PATTERNS="$*"
721 for POD in $PODS; do
David Bainbridged18f4942020-04-14 16:46:13 -0700722 local NAME STATE CONTAINERS TOTAL FOUND
723 NAME="$(echo "$POD" | cut -d/ -f 1)"
724 STATE="$(echo "$POD" | cut -d/ -f 2)"
725 CONTAINERS="$(echo "$POD" | cut -d/ -f 3 | sed -e 's/_/ /g')"
726 if [ "$STATES" == "*" ] || [ "$(echo "$STATES" | grep -c ":$STATE:")" -ne 0 ]; then
727 TOTAL="$(echo "$CONTAINERS" | wc -w)"
728 FOUND="$(echo "$CONTAINERS" | grep -o true | wc -l)"
729 if [ "$TOTAL" -eq "$FOUND" ]; then
David Bainbridge4f1b5562019-08-19 04:46:52 +0000730 for PATTERN in $PATTERNS; do
David Bainbridged18f4942020-04-14 16:46:13 -0700731 if [[ "$NAME" =~ $PATTERN ]]; then
732 COUNT="$((COUNT + 1))"
David Bainbridge4f1b5562019-08-19 04:46:52 +0000733 break
734 fi
735 done
736 fi
737 fi
738 done
David Bainbridge4f1b5562019-08-19 04:46:52 +0000739 echo $COUNT
740}
741
742wait_for_pods() {
David Bainbridged18f4942020-04-14 16:46:13 -0700743 local INDENT NAMESPACE EXPECT TYPE MESSAGE LABELS PATTERNS STATES HAVE ALL WAIT_START NOW
David Bainbridge4f1b5562019-08-19 04:46:52 +0000744 if [ "$1" == "-" ]; then
745 INDENT=$1; shift
746 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700747 NAMESPACE=$1; shift
748 EXPECT=$1; shift
749 TYPE=$1; shift
750 MESSAGE=$1; shift
751 LABELS=$1; shift
752 PATTERNS=("$*")
753 STATES=":Running:"
David Bainbridge99ac7a22019-08-31 02:26:43 +0000754 if [ "$TYPE" == "not" ]; then
755 STATES="*"
756 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700757 HAVE="$(count_pods "$NAMESPACE" "$STATES" "$LABELS" "${PATTERNS[@]}")"
758 ALL=$HAVE
David Bainbridge4f1b5562019-08-19 04:46:52 +0000759 if [ "$TYPE" == "only" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -0700760 ALL="$(count_pods "all-namespaces" "*" ".*")"
David Bainbridge4f1b5562019-08-19 04:46:52 +0000761 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700762 COUNT="$((300 / 15))"
763 WAIT_START="$(date +%s)"
764 bspin "$INDENT" "$MESSAGE"
765 sspin "$INDENT"
766 if [ "$HAVE" -ne "$EXPECT" ] || [ "$ALL" -ne "$HAVE" ]; then
767 while [ "$HAVE" -ne "$EXPECT" ] || [ "$ALL" -ne "$HAVE" ]; do
768 NOW="$(date +%s)"
769 if [ "$((NOW - WAIT_START))" -gt "$TIMEOUT_SECONDS" ]; then
770 espin "$INDENT" "$THEX"
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700771 doTimeout "waiting for PODs to start"
772 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700773 sspin "$INDENT"
774 COUNT="$((COUNT - 1))"
775 if [ "$COUNT" -eq 0 ]; then
776 HAVE="$(count_pods "$NAMESPACE" "$STATES" "$LABELS" "${PATTERNS[@]}")"
777 ALL="$HAVE"
David Bainbridge4f1b5562019-08-19 04:46:52 +0000778 if [ "$TYPE" == "only" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -0700779 ALL="$(count_pods "all-namespaces" "*" ".*")"
David Bainbridge4f1b5562019-08-19 04:46:52 +0000780 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700781 COUNT="$((300 / 15))"
David Bainbridge4f1b5562019-08-19 04:46:52 +0000782 fi
783 sleep .15
784 done
785 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700786 espin "$INDENT" "$VERIFIED"
787 if [ "$HAVE" -ne "$EXPECT" ]; then
David Bainbridge4f1b5562019-08-19 04:46:52 +0000788 return 1
789 fi
790 return 0
791}
792
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800793port_forward() {
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700794 local NS=$1; shift
795 local SVC=$1; shift
796 local PORTS="$*"
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800797 local TAG=$SVC-$NAME
798
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700799 (set -x; _TAG="$TAG" bash -c "while true; do kubectl port-forward --address 0.0.0.0 -n $NS service/$SVC $PORTS; done" >>"$LOG" 2>&1 &) >>"$LOG" 2>&1
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800800}
801
802kill_port_forward() {
David Bainbridged18f4942020-04-14 16:46:13 -0700803 local TAG P_IDS PARENTS KIDS UNKNOWN PP_ID
804 TAG="$1-$NAME"
805 # shellcheck disable=SC2009
806 P_IDS="$(ps e -ww -A | grep "_TAG=$TAG" | grep -v grep | awk '{print $1}')"
807 if [ -n "$P_IDS" ]; then
David Bainbridgec6871d22019-11-13 17:10:31 +0000808 for P_ID in $P_IDS; do
David Bainbridged18f4942020-04-14 16:46:13 -0700809 PP_ID="$(ps -o ppid "$P_ID" | tail -n +2)"
810 if [ -n "$PP_ID" ]; then
811 if [ "$PP_ID" -eq 1 ]; then
David Bainbridgec6871d22019-11-13 17:10:31 +0000812 PARENTS="$PARENTS $P_ID"
813 else
814 KIDS="$KIDS $P_ID"
815 fi
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800816 else
David Bainbridgec6871d22019-11-13 17:10:31 +0000817 UNKNOWN="$UNKNOWN $P_ID"
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800818 fi
819 done
David Bainbridged18f4942020-04-14 16:46:13 -0700820 (set -x; kill -9 "$PARENTS" "$KIDS" "$UNKNOWN" >>"$LOG" 2>&1) >>"$LOG" 2>&1
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800821 fi
822}
823
David Bainbridgecf546362020-04-21 23:18:50 -0700824resolve_chart_version() {
825 [ "$2" != "latest" ] && echo "$2" && return
826 helm inspect chart "$1" | grep "^version:" | awk '{print $2}'
827}
828
Jonathan Hart6a91e6c2020-04-16 14:28:33 -0700829# Compares two semver-formatted version strings (e.g. 2.4.3)
830# Returns 0 if $1 == $2, returns 1 if $1 > $2 and returns 2 if $1 < $2
831compare_versions() {
832 [ "$1" == "$2" ] && return 0
Jonathan Hart6a91e6c2020-04-16 14:28:33 -0700833 local lowest
834 lowest=$(echo -e "$1\n$2" | sort -V | head -1)
835 [ "$lowest" == "$1" ] && return 2
836 return 1
837}
838
David Bainbridgeac7f8072019-08-01 22:15:33 +0000839if [ "$1" == "down" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000840 echo "Tearing down voltha cluster $NAME"
841 LOG="down-$NAME.log"
David Bainbridged18f4942020-04-14 16:46:13 -0700842 date -u +"%Y%m%dT%H%M%SZ" >"$LOG"
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700843 if is_in "$WITH_ONOS" "yes,legacy,classic"; then
David Bainbridge696bc632020-04-05 21:49:37 -0700844 bspin "Remove port-forwards: onos-ui-$NAME"
845 kill_port_forward onos-ui
846 sspin "Remove port-forwards: onos-ssh-$NAME$CEOL"
847 kill_port_forward onos-ssh
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700848 bspin "Remove port-forwards: onos-onos-classic-hs-$NAME$CEOL"
849 kill_port_forward onos-onos-classic-hs
David Bainbridge696bc632020-04-05 21:49:37 -0700850 fi
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800851 sspin "Remove port-forwards: voltha-api-$NAME$CEOL"
852 kill_port_forward voltha-api
David Bainbridged18f4942020-04-14 16:46:13 -0700853 if [ "$WITH_ETCD" == "yes" ] || [ "$WITH_ETCD" == "external" ]; then
854 sspin "Remove port-forwards: ${ETCD_PREFIX}etcd-$NAME$CEOL"
855 kill_port_forward "${ETCD_PREFIX}etcd-cluster-client"
David Bainbridge696bc632020-04-05 21:49:37 -0700856 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700857 if [ "$WITH_KAFKA" == "yes" ] || [ "$WITH_KAFKA" == "external" ]; then
858 sspin "Remove port-forwards: ${KAFKA_PREFIX}kafka-$NAME$CEOL"
859 kill_port_forward "${KAFKA_PREFIX}kafka"
David Bainbridge696bc632020-04-05 21:49:37 -0700860 fi
861
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800862 espin "$VERIFIED Remove port-forwards$CEOL"
David Bainbridged18f4942020-04-14 16:46:13 -0700863 if [ "$DEPLOY_K8S" == "yes" ]; then
David Bainbridgeac7f8072019-08-01 22:15:33 +0000864 if [ -x ./bin/kind ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000865 bspin "Delete Kubernetes Kind Cluster"
David Bainbridged18f4942020-04-14 16:46:13 -0700866 (set -x; ./bin/kind delete cluster --name "voltha-$NAME" >>"$LOG" 2>&1) >>"$LOG" 2>&1
867 espin "$VERIFIED"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000868 else
David Bainbridge0774b232019-08-02 06:37:19 +0000869 espin "$NO_ENTRY Delete Kubernetes Kind Cluster: kind command not found"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000870 fi
871 else
David Bainbridged18f4942020-04-14 16:46:13 -0700872 EXISTS="$(helm list -q)"
David Bainbridge76afd812020-04-06 09:53:52 -0700873 EXPECT="voltha"
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700874 if is_in "$WITH_ONOS" "yes,legacy,classic"; then
David Bainbridge696bc632020-04-05 21:49:37 -0700875 EXPECT+=" onos"
876 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700877 if [ "$WITH_RADIUS" == "yes" ]; then
David Bainbridge696bc632020-04-05 21:49:37 -0700878 EXPECT+=" radius"
879 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700880 if [ "$WITH_BBSIM" == "yes" ]; then
David Bainbridge696bc632020-04-05 21:49:37 -0700881 EXPECT+=" bbsim"
882 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700883 if [ "$WITH_OPEN_ADAPTERS" == "yes" ]; then
David Bainbridge696bc632020-04-05 21:49:37 -0700884 EXPECT+=" open-olt open-onu"
885 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700886 if [ "$WITH_SIM_ADAPTERS" == "yes" ]; then
David Bainbridge696bc632020-04-05 21:49:37 -0700887 EXPECT+=" sim"
888 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700889 if [ "$WITH_ETCD" == "external" ]; then
David Bainbridge76afd812020-04-06 09:53:52 -0700890 EXPECT+=" etcd-operator etcd-cluster"
David Bainbridged18f4942020-04-14 16:46:13 -0700891 elif [ "$WITH_ETCD" == "yes" ]; then
David Bainbridge76afd812020-04-06 09:53:52 -0700892 EXPECT+=" etcd-operator"
893 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700894 if [ "$WITH_KAFKA" == "external" ]; then
David Bainbridge76afd812020-04-06 09:53:52 -0700895 EXPECT+=" kafka"
896 fi
David Bainbridge0774b232019-08-02 06:37:19 +0000897 bspin "Remove Helm Deployments"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000898 for i in $EXISTS; do
David K. Bainbridge43422402020-03-06 07:41:22 -0800899 for j in $EXPECT; do
David Bainbridged18f4942020-04-14 16:46:13 -0700900 if [[ "$i" =~ $j ]]; then
David K. Bainbridge43422402020-03-06 07:41:22 -0800901 sspin "Remove Helm Deployments: $i$CEOL"
David Bainbridged18f4942020-04-14 16:46:13 -0700902 (set -x; ./bin/helm delete --no-hooks --purge "$i" >>"$LOG" 2>&1) >>"$LOG" 2>&1
David K. Bainbridge43422402020-03-06 07:41:22 -0800903 fi
904 done
uottrembb16d3982020-02-28 08:34:36 +0100905 done
David Bainbridge0774b232019-08-02 06:37:19 +0000906 espin "$VERIFIED Remove Helm Deployments$CEOL"
David Bainbridge4f1b5562019-08-19 04:46:52 +0000907 if [ "$WAIT_ON_DOWN" == "yes" ]; then
David Bainbridge76afd812020-04-06 09:53:52 -0700908 PODS="voltha-kafka.* voltha-ofagent.* voltha-rw-core.* voltha-etcd.*"
909 INFRA_PODS=
910 ADAPT_PODS=
911 SIM_PODS=
David Bainbridged18f4942020-04-14 16:46:13 -0700912 if [ "$WITH_RADIUS" == "yes" ]; then
David Bainbridge696bc632020-04-05 21:49:37 -0700913 PODS+=" radius.*"
914 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700915 if [ "$WITH_BBSIM" == "yes" ]; then
David Bainbridge76afd812020-04-06 09:53:52 -0700916 SIM_PODS+=" bbsim.*"
David Bainbridge696bc632020-04-05 21:49:37 -0700917 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700918 if [ "$WITH_OPEN_ADAPTERS" ] || [ "$WITH_SIM_ADAPTERS" ]; then
David Bainbridge76afd812020-04-06 09:53:52 -0700919 ADAPT_PODS+=" adapter-*"
David Bainbridge696bc632020-04-05 21:49:37 -0700920 fi
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700921 if is_in "$WITH_ONOS" "yes,legacy,classic"; then
David Bainbridge76afd812020-04-06 09:53:52 -0700922 INFRA_PODS+=" onos-.*"
923 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700924 if [ "$WITH_ETCD" == "external" ]; then
David Bainbridge76afd812020-04-06 09:53:52 -0700925 INFRA_PODS+=" etcd-operator.* etcd-cluster.*"
David Bainbridged18f4942020-04-14 16:46:13 -0700926 elif [ "$WITH_ETCD" == "yes" ]; then
David Bainbridge76afd812020-04-06 09:53:52 -0700927 PODS+=" etcd-operator.*"
928 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700929 if [ "$WITH_KAFKA" == "external" ]; then
David Bainbridge76afd812020-04-06 09:53:52 -0700930 INFRA_PODS+=" kafka.*"
931 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700932 if [ -n "$SIM_PODS" ]; then
933 wait_for_pods "$BBSIM_NS" 0 "not" "Waiting for BBSIM PODs to terminate" "$BBSIM_LABEL" "$SIM_PODS"
David Bainbridge76afd812020-04-06 09:53:52 -0700934 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700935 if [ -n "$INFRA_PODS" ]; then
936 wait_for_pods "$INFRA_NS" 0 "not" "Waiting for infrastructure PODs to terminate" "$NO_LABEL" "$INFRA_PODS"
David Bainbridge76afd812020-04-06 09:53:52 -0700937 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700938 if [ -n "$ADAPT_PODS" ]; then
939 wait_for_pods "$ADAPTER_NS" 0 "not" "Waiting for adapter PODs to terminate" "$NO_LABEL" "$ADAPT_PODS"
David Bainbridge76afd812020-04-06 09:53:52 -0700940 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700941 wait_for_pods "$VOLTHA_NS" 0 "not" "Waiting for VOLTHA PODs to terminate" "$NO_LABEL" "$PODS"
David Bainbridge4f1b5562019-08-19 04:46:52 +0000942 fi
David Bainbridgeac7f8072019-08-01 22:15:33 +0000943 fi
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -0700944 exit
David Bainbridgeac7f8072019-08-01 22:15:33 +0000945fi
946
947if [ "$1" == "dump" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000948 LOG="dump-$NAME.log"
David Bainbridged18f4942020-04-14 16:46:13 -0700949 TS="$(date -u +"%Y%m%dT%H%M%SZ")"
950 if [ -n "$DUMP_FROM" ]; then
951 TS=${DUMP_FROM//[:-]}
David Bainbridge76514a02019-10-08 01:50:35 +0000952 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700953 WORK="$(mktemp -u -d)"
David Bainbridge0774b232019-08-02 06:37:19 +0000954 DATA=$WORK/voltha-debug-dump-$NAME-$TS
David Bainbridged18f4942020-04-14 16:46:13 -0700955 mkdir -p "$DATA"
956 echo "$TS" > "$LOG"
David Bainbridge0774b232019-08-02 06:37:19 +0000957 echo -e "Capturing debug dump to voltha-debug-dump-$NAME-$TS.tgz"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000958 bspin - "Copy install log"
David Bainbridged18f4942020-04-14 16:46:13 -0700959 if [ -f "install-$NAME.log" ]; then
960 (set -x; cp "install-$NAME.log" "$DATA/install-$NAME.log") >>"$LOG" 2>&1
961 espin - "$VERIFIED"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000962 else
David Bainbridge0774b232019-08-02 06:37:19 +0000963 espin - "$NO_ENTRY Copy install log: install-$NAME.log not found"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000964 fi
965 bspin - "Dumping Kubernetes PODs"
David Bainbridged18f4942020-04-14 16:46:13 -0700966 (set -x; kubectl get --all-namespaces pods >> "$DATA/all-pods.txt" 2>&1) >>"$LOG" 2>&1
967 espin - "$VERIFIED"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000968 bspin - "Dumping Kubernetes SERVICEs"
David Bainbridged18f4942020-04-14 16:46:13 -0700969 (set -x; kubectl get --all-namespaces svc >> "$DATA/all-services.txt" 2>&1) >>"$LOG" 2>&1
970 espin - "$VERIFIED"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000971 bspin - "Dumping Kubernetes EVENTs"
David Bainbridged18f4942020-04-14 16:46:13 -0700972 (set -x; kubectl get --all-namespaces events >> "$DATA/all-events.txt" 2>&1) >>"$LOG" 2>&1
973 espin - "$VERIFIED"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000974 bspin - "Dumping VOLTHA POD details"
David Bainbridged18f4942020-04-14 16:46:13 -0700975 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 +0000976 SINCE=
David Bainbridged18f4942020-04-14 16:46:13 -0700977 if [ -n "$DUMP_FROM" ]; then
David Bainbridgecfd7ca12019-10-06 03:31:41 +0000978 SINCE="--since-time=$DUMP_FROM"
979 fi
David Bainbridgeac7f8072019-08-01 22:15:33 +0000980 for POD in $PODS; do
David Bainbridged18f4942020-04-14 16:46:13 -0700981 NS="$(echo "$POD" | cut -d: -f1)"
982 POD="$(echo "$POD" | cut -d: -f2)"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000983 sspin - "Dumping VOLTHA POD details: $POD$CEOL"
David Bainbridged18f4942020-04-14 16:46:13 -0700984 mkdir -p "$DATA/$POD"
985 (set -x; kubectl describe -n "$NS" "$POD" >> "$DATA/$POD/describe.txt" 2>&1) >>"$LOG" 2>&1
David Bainbridgeac7f8072019-08-01 22:15:33 +0000986 sspin - "Dumping VOLTHA POD details: $POD"
David Bainbridged18f4942020-04-14 16:46:13 -0700987 (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 +0000988 sspin - "Dumping VOLTHA POD details: $POD"
David Bainbridged18f4942020-04-14 16:46:13 -0700989 (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 +0000990 sspin - "Dumping VOLTHA POD details: $POD"
991 done
992 espin - "$VERIFIED Dumping VOLTHA POD details$CEOL"
993 bspin - "Dumping ETCD"
David Bainbridged18f4942020-04-14 16:46:13 -0700994 if [ -n "$(command -v etcdctl)" ]; then
995 (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
996 espin - "$VERIFIED"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000997 else
998 espin - "$NO_ENTRY Dumping ETCD: etcdctl command not available"
999 fi
David Bainbridge0774b232019-08-02 06:37:19 +00001000 bspin - "Creating compressed TAR: voltha-debug-dump-$NAME-$TS.tgz"
David Bainbridged18f4942020-04-14 16:46:13 -07001001 (set -x; tar -C "$WORK" -zcf "voltha-debug-dump-$NAME-$TS.tgz" "./voltha-debug-dump-$NAME-$TS") >>"$LOG" 2>&1
1002 espin - "$VERIFIED"
David Bainbridgeac7f8072019-08-01 22:15:33 +00001003 bspin - "Cleanup"
David Bainbridged18f4942020-04-14 16:46:13 -07001004 (set -x; rm -rf "$WORK") >>"$LOG" 2>&1
1005 espin - "$VERIFIED"
1006 bspin - "$(ls -l "voltha-debug-dump-$NAME-$TS.tgz")"
1007 espin - "$VERIFIED"
David Bainbridgeac7f8072019-08-01 22:15:33 +00001008 exit
1009fi
1010
David Bainbridge0774b232019-08-02 06:37:19 +00001011LOG="install-$NAME.log"
David Bainbridged18f4942020-04-14 16:46:13 -07001012date > "$LOG"
1013echo "PORTS=$ONOS_API_PORT,$ONOS_SSH_PORT,$VOLTHA_API_PORT,$VOLTHA_SSH_PORT,$VOLTHA_ETCD_PORT" >> "$LOG"
David Bainbridgeac7f8072019-08-01 22:15:33 +00001014
1015# Output install options to log
David Bainbridged18f4942020-04-14 16:46:13 -07001016echo "OPTIONS" >> "$LOG"
David Bainbridgeac7f8072019-08-01 22:15:33 +00001017for O in $ALL_OPTIONS; do
David Bainbridged18f4942020-04-14 16:46:13 -07001018 VAL="$(eval echo "\$$O")"
1019 if [ -n "$VAL" ]; then
1020 printf " %-30s = %s\n" "$O" "$VAL" >> "$LOG"
David Bainbridgeac7f8072019-08-01 22:15:33 +00001021 fi
1022done
1023
David Bainbridgefad50732020-05-01 17:00:12 -07001024helm_values() {
1025 local NAMESPACE=$1; shift
1026 local INAME=$1; shift
1027 local CHART=$1; shift
1028 local CHART_VERSION=$1; shift
1029
1030 if [ "$CHART_VERSION X" != " X" ] && [ "$CHART_VERSION" != "latest" ]; then
1031 CHART_VERSION="--version $CHART_VERSION"
1032 else
1033 CHART_VERSION=
1034 fi
1035
1036 local CHART_ARGS=
1037 if [ -r "${INAME}-values.yaml" ]; then
1038 CHART_ARGS="-f ${INAME}-values.yaml"
1039 fi
1040
1041 if [ "$HELM_USE_UPGRADE" == "yes" ]; then
1042 _HELM_COMMAND="upgrade --install"
1043 _HELM_ARGS="xxxdryrunxxx"
1044 else
1045 _HELM_COMMAND="install"
1046 _HELM_ARGS="--name xxxdryrunxxx"
1047 fi
1048 CMD=("helm $_HELM_COMMAND --debug --dry-run -f $NAME-values.yaml $CHART_ARGS $INTERNAL_EXTRA_HELM_INSTALL_ARGS $EXTRA_HELM_INSTALL_ARGS --set defaults.log_level=$VOLTHA_LOG_LEVEL --namespace $NAMESPACE $_HELM_ARGS $CHART_VERSION $EXTRA_HELM_FLAGS $CHART")
1049 ${CMD[*]} 2>/dev/null | awk 'PRINT==1 {print}; /^USER-SUPPLIED VALUES:/ {PRINT = 1}; /^$/ {PRINT = 0}'
1050}
1051
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001052helm_install() {
David Bainbridged18f4942020-04-14 16:46:13 -07001053 local INDENT NOW
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001054 if [ "$1" == "-" ]; then
1055 INDENT=$1; shift
1056 fi
1057 local NAMESPACE=$1; shift
David Bainbridge0774b232019-08-02 06:37:19 +00001058 local INAME=$1; shift
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001059 local CHART=$1; shift
David Bainbridge90fd8e32019-08-21 23:32:47 +00001060 local CHART_VERSION=$1; shift
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001061 local MESSAGE=$*
1062
David Bainbridged18f4942020-04-14 16:46:13 -07001063 if [ "$CHART_VERSION X" != " X" ] && [ "$CHART_VERSION" != "latest" ]; then
David Bainbridge90fd8e32019-08-21 23:32:47 +00001064 CHART_VERSION="--version $CHART_VERSION"
1065 else
1066 CHART_VERSION=
1067 fi
1068
David Bainbridge99ac7a22019-08-31 02:26:43 +00001069 local CHART_ARGS=
1070 if [ -r "${INAME}-values.yaml" ]; then
1071 CHART_ARGS="-f ${INAME}-values.yaml"
1072 fi
1073
David Bainbridged18f4942020-04-14 16:46:13 -07001074 local WAIT_START CMD
1075 WAIT_START="$(date +%s)"
1076 COUNT="$((300 / 15))"
1077 bspin "$INDENT" "$MESSAGE"
1078 if [ "$HELM_USE_UPGRADE" == "yes" ]; then
David Bainbridge7f8bf992020-04-08 21:53:22 -07001079 _HELM_COMMAND="upgrade --install"
1080 _HELM_ARGS="$INAME"
1081 else
1082 _HELM_COMMAND="install"
1083 _HELM_ARGS="--name $INAME"
1084 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001085 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")
1086 (set -x; ${CMD[*]} >>"$LOG" 2>&1) >>"$LOG" 2>&1
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001087 SUCCESS=$?
David Bainbridged18f4942020-04-14 16:46:13 -07001088 while [ "$SUCCESS" -ne 0 ]; do
1089 NOW="$(date +%s)"
1090 if [ "$((NOW - WAIT_START))" -gt "$TIMEOUT_SECONDS" ]; then
David Bainbridge52e6e9d2020-03-23 13:48:27 -07001091 espin "$THEX"
1092 doTimeout "waiting for helm install $CHART"
1093 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001094 sspin "$INDENT"
1095 COUNT="$((COUNT - 1))"
1096 if [ "$COUNT" -eq 0 ]; then
1097 if [ "$HELM_USE_UPGRADE" == "no" ]; then
1098 (set -x; helm delete --purge "$INAME" >>"$LOG" 2>&1) >>"$LOG" 2>&1
David Bainbridge7f8bf992020-04-08 21:53:22 -07001099 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001100 (set -x; ${CMD[*]} >>"$LOG" 2>&1) >>"$LOG" 2>&1
Andy Baviere22ff252019-12-19 11:40:31 -07001101 SUCCESS=$?
David Bainbridged18f4942020-04-14 16:46:13 -07001102 COUNT="$((300 / 15))"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001103 fi
1104 sleep .15
1105 done
David Bainbridged18f4942020-04-14 16:46:13 -07001106 espin "$INDENT" "$VERIFIED"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001107}
1108
David Bainbridged18f4942020-04-14 16:46:13 -07001109echo "INSTALL TYPE: $TYPE" >> "$LOG"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001110
1111bspin "Verify GOPATH"
David Bainbridged18f4942020-04-14 16:46:13 -07001112GOPATH="$(pwd)"; export GOPATH
1113mkdir -p "$GOPATH/bin"
1114espin "$VERIFIED"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001115
David Bainbridged18f4942020-04-14 16:46:13 -07001116STIME="$(date +%s)"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001117if [ "$INSTALL_KUBECTL" == "no" ]; then
1118 bspin "Skip kubectl install"
1119 espin $NO_ENTRY
Test Userc13bdc92019-07-03 20:57:49 +00001120else
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001121 bspin "Verify kubectl $HELM"
David Bainbridged18f4942020-04-14 16:46:13 -07001122 if [ -x "$GOPATH/bin/kubectl" ]; then
1123 espin "$VERIFIED"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001124 else
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001125 ERR_OUT="$(mktemp)"
David Bainbridged18f4942020-04-14 16:46:13 -07001126 espin "$NOT_VERIFIED"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001127 bspin - "Download and install Kubernetes/kubectl $DOWNLOAD"
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001128 (set -x; curl --fail -o "$GOPATH/bin/kubectl" -sSL "https://storage.googleapis.com/kubernetes-release/release/$(curl --fail -sSL https://storage.googleapis.com/kubernetes-release/release/stable.txt 2>>"$ERR_OUT")/bin/$HOSTOS/$HOSTARCH/kubectl" >>"$LOG" 2>>"$ERR_OUT") >>"$LOG" 2>&1
1129 RESULT=$?
1130 if [ "$RESULT" -ne 0 ]; then
1131 espin - "$THEX"
David Bainbridgee3fc0c32020-04-21 15:34:04 -07001132 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR: unable to download kubectl: $(tail "$ERR_OUT")${NORMAL}"
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001133 cat "$ERR_OUT" >> "$LOG"
Zack Williamsded60cb2020-04-13 10:02:20 -07001134 rm -rf "$ERR_OUT" "$GOPATH/bin/kubectl"
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001135 exit 1
1136 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001137 (set -x; chmod 755 "$GOPATH/bin/kubectl" >>"$LOG" 2>&1) >>"$LOG" 2>&1
1138 espin - "$VERIFIED"
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001139 rm -rf "$ERR_OUT"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001140 fi
Test Userc13bdc92019-07-03 20:57:49 +00001141fi
David Bainbridgee87067b2019-08-12 22:00:12 +00001142if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001143 NOW="$(date +%s)"
1144 printtime $((NOW - STIME))
David Bainbridgee87067b2019-08-12 22:00:12 +00001145fi
Test Userc13bdc92019-07-03 20:57:49 +00001146
David Bainbridged18f4942020-04-14 16:46:13 -07001147STIME="$(date +%s)"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001148if [ "$DEPLOY_K8S" == "no" ]; then
1149 bspin "Skip Kubernetes/Kind Deployment"
1150 espin $NO_ENTRY
1151else
Test Userba1e7e72019-07-10 22:27:54 +00001152 bspin "Verify Kubernetes/Kind $HELM"
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -08001153 IS_INSTALLED=0
1154 OP_TYPE="install"
David Bainbridged18f4942020-04-14 16:46:13 -07001155 if [ -x "$GOPATH/bin/kind" ]; then
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -08001156 OP_TYPE="upgrade"
David Bainbridged18f4942020-04-14 16:46:13 -07001157 if [ "$("$GOPATH/bin/kind" --version | grep -c "$KIND_VERSION")" -eq 1 ]; then
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -08001158 IS_INSTALLED=1
David Bainbridged18f4942020-04-14 16:46:13 -07001159 espin "$VERIFIED"
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -08001160 fi
1161 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001162 if [ "$IS_INSTALLED" -eq 0 ]; then
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001163 ERR_OUT="$(mktemp)"
David Bainbridged18f4942020-04-14 16:46:13 -07001164 espin "$NOT_VERIFIED"
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -08001165 bspin - "Download and $OP_TYPE Kubernetes/kind $DOWNLOAD"
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001166 (set -x; curl -o "$GOPATH/bin/kind" --fail -sSL "https://github.com/kubernetes-sigs/kind/releases/download/$KIND_VERSION/kind-$HOSTOS-$HOSTARCH" >>"$LOG" 2>"$ERR_OUT") >>"$LOG" 2>&1
1167 RESULT=$?
1168 if [ $RESULT -ne 0 ]; then
1169 espin - "$THEX"
David Bainbridgee3fc0c32020-04-21 15:34:04 -07001170 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR: unable to download kind: $(tail "$ERR_OUT")${NORMAL}"
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001171 cat "$ERR_OUT" >> "$LOG"
Zack Williamsded60cb2020-04-13 10:02:20 -07001172 rm -rf "$ERR_OUT" "$GOPATH/bin/kind"
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001173 exit 1
1174 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001175 (set -x; chmod 755 "$GOPATH/bin/kind" >>"$LOG" 2>&1) >>"$LOG" 2>&1
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001176 rm -rf "$ERR_OUT"
David Bainbridged18f4942020-04-14 16:46:13 -07001177 espin - "$VERIFIED"
Test Userba1e7e72019-07-10 22:27:54 +00001178 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001179fi
1180
David Bainbridgee87067b2019-08-12 22:00:12 +00001181if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001182 NOW="$(date +%s)"
1183 printtime $((NOW - STIME))
David Bainbridgee87067b2019-08-12 22:00:12 +00001184fi
1185
David Bainbridged18f4942020-04-14 16:46:13 -07001186STIME="$(date +%s)"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001187if [ "$INSTALL_HELM" == "no" ]; then
1188 bspin "Skip Helm Install"
1189 espin $NO_ENTRY
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001190else
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001191 bspin "Verify Helm $HELM"
David Bainbridgea34993d2020-04-01 09:15:42 -07001192 HELM_UPGRADE=0
1193 HELM_UPGRADE_DESC="install"
David Bainbridged18f4942020-04-14 16:46:13 -07001194 if [ -x "$GOPATH/bin/helm" ]; then
1195 HAVE_VER="$("$GOPATH/bin/helm" version -c --template '{{.Client.SemVer}}')"
1196 HELM_UP_DOWN="$(echo -e "$HAVE_VER\n$HELM_VERSION" | sort -V | head -1)"
1197 if [ "$HAVE_VER" != "$HELM_VERSION" ]; then
1198 if [ "$HELM_UP_DOWN" == "$HELM_VERSION" ]; then
David Bainbridgea34993d2020-04-01 09:15:42 -07001199 HELM_UPGRADE_DESC="downgrade"
1200 else
1201 HELM_UPGRADE_DESC="upgrade"
1202 fi
1203 HELM_UPGRADE=1
1204 else
David Bainbridged18f4942020-04-14 16:46:13 -07001205 espin "$VERIFIED"
David Bainbridgea34993d2020-04-01 09:15:42 -07001206 fi
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001207 else
David Bainbridgea34993d2020-04-01 09:15:42 -07001208 HELM_UPGRADE=1
1209 fi
1210
David Bainbridged18f4942020-04-14 16:46:13 -07001211 if [ "$HELM_UPGRADE" -ne 0 ]; then
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001212 ERR_OUT="$(mktemp)"
1213 INSTALL_HELM_BIN=$(mktemp)
David Bainbridged18f4942020-04-14 16:46:13 -07001214 espin "$NOT_VERIFIED"
David Bainbridgea34993d2020-04-01 09:15:42 -07001215 bspin - "Download and $HELM_UPGRADE_DESC Helm $DOWNLOAD"
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001216 (set -x; curl -o "$INSTALL_HELM_BIN" --fail -sSL https://git.io/get_helm.sh >>"$LOG" 2>"$ERR_OUT") >>"$LOG" 2>&1
1217 RESULT=$?
1218 if [ $RESULT -ne 0 ]; then
1219 espin - "$THEX"
David Bainbridgee3fc0c32020-04-21 15:34:04 -07001220 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR: unable to download helm installer: $(tail "$ERR_OUT")${NORMAL}"
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001221 cat "$ERR_OUT" >> "$LOG"
1222 rm -rf "$INSTALL_HELM_BIN" "$ERR_OUT" "$GOPATH/bin/helm" "$GOPATH/bin/tiller"
1223 exit 1
1224 fi
1225 rm -rf "$ERR_OUT"
1226 chmod +x "$INSTALL_HELM_BIN"
1227 (set -x; PATH="$GOPATH/bin:$PATH" DESIRED_VERSION=$HELM_VERSION USE_SUDO=false HELM_INSTALL_DIR=$GOPATH/bin "$INSTALL_HELM_BIN" >>"$LOG" 2>&1) >>"$LOG" 2>&1
1228 RESULT=$?
1229 if [ $RESULT -ne 0 ]; then
1230 espin - "$THEX"
1231 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR: unable to install helm, see install log for details${NORMAL}"
1232 rm -rf "$INSTALL_HELM_BIN" "$ERR_OUT" "$GOPATH/bin/helm" "$GOPATH/bin/tiller"
1233 exit 1
1234 fi
1235 rm -rf "$INSTALL_HELM_BIN" "$ERR_OUT"
David Bainbridged18f4942020-04-14 16:46:13 -07001236 espin - "$VERIFIED"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001237 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001238fi
David Bainbridgee87067b2019-08-12 22:00:12 +00001239if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001240 NOW="$(date +%s)"
1241 printtime $((NOW - STIME))
David Bainbridgee87067b2019-08-12 22:00:12 +00001242fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001243
David Bainbridged18f4942020-04-14 16:46:13 -07001244STIME="$(date +%s)"
Test Userb5712372019-07-03 21:52:17 +00001245bspin "Verify voltctl $HIGH_VOLTAGE"
David Bainbridged2811972019-12-14 01:14:09 +00001246VOK=0
1247VMESSAGE="install"
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001248ERR_OUT=$(mktemp)
David K. Bainbridgeebf38d92020-02-10 10:46:31 -08001249export VC_VERSION="$VOLTCTL_VERSION"
1250if [ "$VC_VERSION" == "latest" ]; then
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001251 set -o pipefail # TODO: would be nice to run all in pipefail mode
1252 VC_VERSION="$(curl --fail -sSL https://api.github.com/repos/opencord/voltctl/releases/latest 2>"$ERR_OUT" | jq -r .tag_name | sed -e 's/^v//g')"
1253 RESULT=$?
1254 set +o pipefail
1255 if [ "$RESULT" -ne 0 ]; then
1256 espin - "$THEX"
1257 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR: unable to determine released version of voltctl: $(cat "$ERR_OUT")${NORMAL}"
1258 rm -rf "$ERR_OUT" "$GOPATH/bin/voltctl"
1259 exit 1
1260 fi
1261 export VC_VERSION
David K. Bainbridgeebf38d92020-02-10 10:46:31 -08001262fi
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001263
David Bainbridged18f4942020-04-14 16:46:13 -07001264if [ -x "$GOPATH/bin/voltctl" ]; then
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001265 VHAVE="$("$GOPATH/bin/voltctl" version --clientonly -o json 2>/dev/null | jq -r .version)"
David Bainbridged18f4942020-04-14 16:46:13 -07001266 RESULT=$?
1267 if [ $RESULT -eq 0 ] && [ "$VHAVE" == "$VC_VERSION" ]; then
David Bainbridged2811972019-12-14 01:14:09 +00001268 VOK=1
David Bainbridged18f4942020-04-14 16:46:13 -07001269 espin "$VERIFIED"
David Bainbridge1ba64f12019-12-18 00:40:13 +00001270 else
David Bainbridged18f4942020-04-14 16:46:13 -07001271 VCHECK="$(echo -e "$VHAVE\n$VC_VERSION" | sort -V | head -1)"
David K. Bainbridgeebf38d92020-02-10 10:46:31 -08001272 if [ "$VCHECK" == "$VHAVE" ]; then
1273 VMESSAGE="upgrade"
1274 else
1275 VMESSAGE="downgrade"
1276 fi
David Bainbridged2811972019-12-14 01:14:09 +00001277 fi
1278fi
1279
David Bainbridged18f4942020-04-14 16:46:13 -07001280if [ "$VOK" -eq 0 ]; then
1281 espin "$NOT_VERIFIED"
David Bainbridged2811972019-12-14 01:14:09 +00001282 bspin - "Download and $VMESSAGE voltctl $DOWNLOAD"
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001283 (set -x; curl --fail -o "$GOPATH/bin/voltctl" -sSL "https://github.com/opencord/voltctl/releases/download/v$VC_VERSION/voltctl-$VC_VERSION-$HOSTOS-$HOSTARCH" >>"$LOG" 2>"$ERR_OUT") >>"$LOG" 2>&1
1284 RESULT=$?
1285 if [ $RESULT -ne 0 ]; then
1286 espin - "$THEX"
1287 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR: unable to download voltctl (version $VC_VERSION): $(cat "$ERR_OUT")${NORMAL}"
1288 rm -rf "$ERR_OUT" "$GOPATH/bin/voltctl"
1289 exit 1
1290 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001291 (set -x; chmod 755 "$GOPATH/bin/voltctl" >>"$LOG" 2>&1) >>"$LOG" 2>&1
1292 espin - "$VERIFIED"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001293fi
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001294rm -rf "$ERR_OUT"
David Bainbridgee87067b2019-08-12 22:00:12 +00001295if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001296 NOW="$(date +%s)"
1297 printtime $((NOW - STIME))
David Bainbridgee87067b2019-08-12 22:00:12 +00001298fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001299
1300bspin "Verify command PATH"
Test Userba1e7e72019-07-10 22:27:54 +00001301export PATH=$GOPATH/bin:$PATH
David Bainbridged18f4942020-04-14 16:46:13 -07001302espin "$VERIFIED"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001303
David Bainbridged18f4942020-04-14 16:46:13 -07001304STIME="$(date +%s)"
Test Userba1e7e72019-07-10 22:27:54 +00001305if [ "$DEPLOY_K8S" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001306 HAVE="$(kind get clusters | grep -c "voltha-$NAME")"
Test Userba1e7e72019-07-10 22:27:54 +00001307 bspin "Verify Kubernetes/Kind Cluster"
1308 sspin
David Bainbridged18f4942020-04-14 16:46:13 -07001309 if [ "$HAVE" -eq 0 ]; then
1310 espin "$NOT_VERIFIED"
David Bainbridge491b1bd2019-07-11 17:53:11 +00001311 bspin - "Verify cluster configuration"
David Bainbridged18f4942020-04-14 16:46:13 -07001312 if [ ! -r "./$NAME-cluster.cfg" ]; then
1313 espin - "$NOT_VERIFIED"
David K. Bainbridge43422402020-03-06 07:41:22 -08001314 bspin - "Download cluster configuration: $TYPE-cluster.cfg to $NAME-cluster.cfg $DOWNLOAD"
David Bainbridged18f4942020-04-14 16:46:13 -07001315 ERR_OUT="$(mktemp)"
serkant.uluderya4d315132020-04-15 16:25:54 -07001316 if ! (set -x; curl --fail -o "./$NAME-cluster.cfg" -sSL "https://raw.githubusercontent.com/opencord/kind-voltha/$VK_RELEASE/$TYPE-cluster.cfg" >>"$LOG" 2>>"$ERR_OUT") >>"$LOG" 2>&1; then
David Bainbridged18f4942020-04-14 16:46:13 -07001317 espin - "$THEX"
1318 echo -e "${RED}${BOLD}${ERROR}ERROR: $NAME-cluster.cfg${NORMAL}${RED} - $(cat "$ERR_OUT")${NORMAL}"
1319 echo "ERROR: $(cat "$ERR_OUT")" >>"$LOG"
1320 rm -rf "$ERR_OUT" "./$NAME-cluster.cfg"
David K. Bainbridgea00736b2020-01-08 14:33:17 -08001321 exit 1
1322 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001323 rm -rf "$ERR_OUT"
David K. Bainbridgea00736b2020-01-08 14:33:17 -08001324 else
David Bainbridged18f4942020-04-14 16:46:13 -07001325 espin - "$VERIFIED"
David K. Bainbridgea00736b2020-01-08 14:33:17 -08001326 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001327 kind create cluster --name "voltha-$NAME" --config "$NAME-cluster.cfg"
David Bainbridge491b1bd2019-07-11 17:53:11 +00001328 else
David Bainbridged18f4942020-04-14 16:46:13 -07001329 espin "$VERIFIED"
Test Userba1e7e72019-07-10 22:27:54 +00001330 fi
1331
David Bainbridged18f4942020-04-14 16:46:13 -07001332 KUBECONFIG="$(kind get kubeconfig-path --name="voltha-$NAME")"; export KUBECONFIG
Test Userba1e7e72019-07-10 22:27:54 +00001333 P="coredns-.* \
David Bainbridge0774b232019-08-02 06:37:19 +00001334 etcd-voltha-$NAME-control-plane \
Test Userba1e7e72019-07-10 22:27:54 +00001335 kindnet-.* \
David Bainbridge0774b232019-08-02 06:37:19 +00001336 kube-apiserver-voltha-$NAME-control-plane \
1337 kube-controller-manager-voltha-$NAME-control-plane \
Test Userba1e7e72019-07-10 22:27:54 +00001338 kube-proxy-.* \
David Bainbridge0774b232019-08-02 06:37:19 +00001339 kube-scheduler-voltha-$NAME-control-plane"
Test Userba1e7e72019-07-10 22:27:54 +00001340
David Bainbridged18f4942020-04-14 16:46:13 -07001341 EXPECT="$(test "$TYPE" == "minimal" && echo "12" || echo "14")"
1342 wait_for_pods - "kube-system" "$EXPECT" "includes" "Waiting for system PODs to start" "$NO_LABEL" "$P"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001343fi
David Bainbridgee87067b2019-08-12 22:00:12 +00001344if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001345 NOW="$(date +%s)"
1346 printtime $((NOW - STIME))
David Bainbridgee87067b2019-08-12 22:00:12 +00001347fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001348
David Bainbridged18f4942020-04-14 16:46:13 -07001349STIME="$(date +%s)"
1350COUNT="$(count_pods "kube-system" ":Running:" "$NO_LABEL" "tiller-deploy-.*")"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001351bspin "Verify Helm"
David Bainbridged18f4942020-04-14 16:46:13 -07001352if [ "$COUNT" -ne 1 ]; then
1353 espin "$NOT_VERIFIED"
Test Userb5712372019-07-03 21:52:17 +00001354 echo -e "Configuring Helm $GEAR"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001355 if [ "$INSTALL_HELM" == "no" ]; then
1356 bspin - "Skip Helm/Tiller Initialization"
1357 espin - $NO_ENTRY
1358 else
1359 bspin - "Initialize Helm"
David Bainbridged18f4942020-04-14 16:46:13 -07001360 (set -x; helm init --upgrade >>"$LOG" 2>&1) >>"$LOG" 2>&1
1361 espin - "$VERIFIED"
1362 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 -07001363 fi
Test Userb5712372019-07-03 21:52:17 +00001364 bspin - "Add Google Incubator repository to Helm"
David Bainbridged18f4942020-04-14 16:46:13 -07001365 (set -x; helm repo add incubator https://kubernetes-charts-incubator.storage.googleapis.com >>"$LOG" 2>&1) >>"$LOG" 2>&1
1366 espin - "$VERIFIED"
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001367
Test Userba1e7e72019-07-10 22:27:54 +00001368 # HACK (sort-of) - the config for tiller is about to be patched, which will
1369 # cause the tiller pod to be recreated. This can sometimes cause a timing
1370 # issue with the "wait_for_pods" call on tiller as it may incorrectly
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001371 # identify the running/ready tiller pod that is soon to be terminated as
Test Userba1e7e72019-07-10 22:27:54 +00001372 # what it is waiting for. To avoid this issue we do a clean scale down and
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001373 # scale up of the pod so the script controlls when it should be expecting
Test Userba1e7e72019-07-10 22:27:54 +00001374 # things
David Bainbridged18f4942020-04-14 16:46:13 -07001375 (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 -07001376
Test Userb5712372019-07-03 21:52:17 +00001377 bspin - "Add Google Stable repository to Helm"
David Bainbridged18f4942020-04-14 16:46:13 -07001378 (set -x; helm repo add stable https://kubernetes-charts.storage.googleapis.com >>"$LOG" 2>&1) >>"$LOG" 2>&1
1379 espin - "$VERIFIED"
David Bainbridge60ffc0f2020-04-27 22:13:22 -07001380 bspin - "Add ONF VOLTHA repository to Helm"
David Bainbridged18f4942020-04-14 16:46:13 -07001381 (set -x; helm repo add onf https://charts.opencord.org >>"$LOG" 2>&1) >>"$LOG" 2>&1
1382 espin - "$VERIFIED"
David Bainbridge60ffc0f2020-04-27 22:13:22 -07001383 bspin - "Add ONF ONOS repository to Helm"
1384 (set -x; helm repo add onos https://charts.onosproject.org >>"$LOG" 2>&1) >>"$LOG" 2>&1
1385 espin - "$VERIFIED"
1386 bspin - "Add ONF Atomix repository to Helm"
1387 (set -x; helm repo add atomix https://charts.atomix.io >>"$LOG" 2>&1) >>"$LOG" 2>&1
1388 espin - "$VERIFIED"
Test Userb5712372019-07-03 21:52:17 +00001389 bspin - "Update Helm repository cache"
David Bainbridged18f4942020-04-14 16:46:13 -07001390 (set -x; helm repo update >>"$LOG" 2>&1) >>"$LOG" 2>&1
1391 espin - "$VERIFIED"
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001392
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001393 # Create and k8s service account so that Helm can create pods
Test Userb5712372019-07-03 21:52:17 +00001394 bspin - "Create Tiller ServiceAccount"
David Bainbridged18f4942020-04-14 16:46:13 -07001395 (set -x; kubectl create serviceaccount --namespace kube-system tiller >>"$LOG" 2>&1) >>"$LOG" 2>&1
1396 espin - "$VERIFIED"
Test Userb5712372019-07-03 21:52:17 +00001397 bspin - "Create Tiller ClusterRoleBinding"
David Bainbridged18f4942020-04-14 16:46:13 -07001398 (set -x; kubectl create clusterrolebinding tiller-cluster-rule --clusterrole=cluster-admin --serviceaccount=kube-system:tiller >>"$LOG" 2>&1) >>"$LOG" 2>&1
1399 espin - "$VERIFIED"
Test Userb5712372019-07-03 21:52:17 +00001400 bspin - "Update Tiller Manifest"
David Bainbridged18f4942020-04-14 16:46:13 -07001401 (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 +00001402
1403 # HACK (sort-of) - part to, spin it back up
David Bainbridged18f4942020-04-14 16:46:13 -07001404 (set -x; kubectl -n kube-system scale deploy tiller-deploy --replicas=1 >>"$LOG" 2>&1) >>"$LOG" 2>&1
1405 espin - "$VERIFIED"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001406else
David Bainbridged18f4942020-04-14 16:46:13 -07001407 if [ "$(helm version -s --template '{{.Server.SemVer}}')" != "$HELM_VERSION" ]; then
1408 espin "$NOT_VERIFIED"
David Bainbridgea34993d2020-04-01 09:15:42 -07001409 bspin - "Sync Tiller server version with helm client"
David Bainbridged18f4942020-04-14 16:46:13 -07001410 (set -x; helm init --upgrade --force-upgrade --wait >>"$LOG" 2>&1) >>"$LOG" 2>&1
1411 espin - "$VERIFIED"
David Bainbridgea34993d2020-04-01 09:15:42 -07001412 else
David Bainbridged18f4942020-04-14 16:46:13 -07001413 espin "$VERIFIED"
David Bainbridgea34993d2020-04-01 09:15:42 -07001414 fi
1415
David Bainbridge46505fb2019-10-01 21:13:20 +00001416 if [ "$UPDATE_HELM_REPOS" == "yes" ]; then
1417 bspin - "Update Helm repository cache"
David Bainbridged18f4942020-04-14 16:46:13 -07001418 (set -x; helm repo update >>"$LOG" 2>&1) >>"$LOG" 2>&1
1419 espin - "$VERIFIED"
David Bainbridge46505fb2019-10-01 21:13:20 +00001420 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001421fi
David Bainbridged18f4942020-04-14 16:46:13 -07001422wait_for_pods - "kube-system" 1 "includes" "Waiting for Tiller POD to start" "$NO_LABEL" "tiller-deploy-.*"
David Bainbridgee87067b2019-08-12 22:00:12 +00001423if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001424 NOW="$(date +%s)"
1425 printtime $((NOW - STIME))
David Bainbridgee87067b2019-08-12 22:00:12 +00001426fi
David Bainbridgecf546362020-04-21 23:18:50 -07001427# Resolve chart versions and log them for debug/support
1428RESOLVED_VOLTHA_CHART_VERSION=$(resolve_chart_version "$VOLTHA_CHART" "$VOLTHA_CHART_VERSION")
1429RESOLVED_VOLTHA_BBSIM_CHART_VERSION=$(resolve_chart_version "$VOLTHA_BBSIM_CHART" "$VOLTHA_BBSIM_CHART_VERSION")
1430RESOLVED_VOLTHA_ADAPTER_SIM_CHART_VERSION=$(resolve_chart_version "$VOLTHA_ADAPTER_SIM_CHART" "$VOLTHA_ADAPTER_SIM_CHART_VERSION")
1431RESOLVED_VOLTHA_ADAPTER_OPEN_OLT_CHART_VERSION=$(resolve_chart_version "$VOLTHA_ADAPTER_OPEN_OLT_CHART" "$VOLTHA_ADAPTER_OPEN_OLT_CHART_VERSION")
1432RESOLVED_VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION=$(resolve_chart_version "$VOLTHA_ADAPTER_OPEN_ONU_CHART" "$VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION")
1433RESOLVED_ONOS_CHART_VERSION=$(resolve_chart_version "$ONOS_CHART" "$ONOS_CHART_VERSION")
David Bainbridge60ffc0f2020-04-27 22:13:22 -07001434RESOLVED_ONOS_CLASSIC_CHART_VERSION=$(resolve_chart_version "$ONOS_CLASSIC_CHART" "$ONOS_CLASSIC_CHART_VERSION")
David Bainbridgecf546362020-04-21 23:18:50 -07001435RESOLVED_KAFKA_CHART_VERSION=$(resolve_chart_version "$KAFKA_CHART" "$KAFKA_CHART_VERSION")
1436cat <<EOV >>"$LOG"
1437Resolved helm charts and versions:
1438 $VOLTHA_CHART:$RESOLVED_VOLTHA_CHART_VERSION
1439 $VOLTHA_BBSIM_CHART:$RESOLVED_VOLTHA_BBSIM_CHART_VERSION
1440 $VOLTHA_ADAPTER_SIM_CHART:$RESOLVED_VOLTHA_ADAPTER_SIM_CHART_VERSION
1441 $VOLTHA_ADAPTER_OPEN_OLT_CHART:$RESOLVED_VOLTHA_ADAPTER_OPEN_OLT_CHART_VERSION
1442 $VOLTHA_ADAPTER_OPEN_ONU_CHART:$RESOLVED_VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION
1443 $ONOS_CHART:$RESOLVED_ONOS_CHART_VERSION
David Bainbridge60ffc0f2020-04-27 22:13:22 -07001444 $ONOS_CLASSIC_CHART:$RESOLVED_ONOS_CLASSIC_CHART_VERSION
David Bainbridgecf546362020-04-21 23:18:50 -07001445 $KAFKA_CHART:$RESOLVED_KAFKA_CHART_VERSION
1446EOV
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001447
David Bainbridged18f4942020-04-14 16:46:13 -07001448STIME="$(date +%s)"
David Bainbridge0774b232019-08-02 06:37:19 +00001449bspin "Verify Helm values file: $NAME-values.yaml"
1450if [ ! -r "./$NAME-values.yaml" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001451 espin "$NOT_VERIFIED"
David Bainbridge0774b232019-08-02 06:37:19 +00001452 bspin - "Download Helm values file: $TYPE-values.yaml to $NAME-values.yaml $DOWNLOAD"
David Bainbridged18f4942020-04-14 16:46:13 -07001453 ERR_OUT="$(mktemp)"
serkant.uluderya4d315132020-04-15 16:25:54 -07001454 if ! (set -x; curl --fail -o "./$NAME-values.yaml" -sSL "https://raw.githubusercontent.com/opencord/kind-voltha/$VK_RELEASE/$TYPE-values.yaml" >>"$LOG" 2>"$ERR_OUT") >>"$LOG" 2>&1; then
David Bainbridged18f4942020-04-14 16:46:13 -07001455 espin - "$THEX"
1456 echo -e "${RED}${BOLD}${ERROR}ERROR: $NAME-values.yaml${NORMAL}${RED} - $(cat "$ERR_OUT")${NORMAL}"
1457 echo "ERROR: $(cat "$ERR_OUT")" >>"$LOG"
1458 rm -rf "$ERR_OUT" "./$NAME-values.yaml"
David K. Bainbridgea00736b2020-01-08 14:33:17 -08001459 exit 1
1460 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001461 rm -rf "$ERR_OUT"
1462 espin - "$VERIFIED"
Test Userba1e7e72019-07-10 22:27:54 +00001463else
David Bainbridged18f4942020-04-14 16:46:13 -07001464 espin "$VERIFIED"
Test Userba1e7e72019-07-10 22:27:54 +00001465fi
David Bainbridgee87067b2019-08-12 22:00:12 +00001466if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001467 NOW="$(date +%s)"
1468 printtime $((NOW - STIME))
David Bainbridgee87067b2019-08-12 22:00:12 +00001469fi
Test Userba1e7e72019-07-10 22:27:54 +00001470
David Bainbridged18f4942020-04-14 16:46:13 -07001471STIME="$(date +%s)"
David Bainbridge99ac7a22019-08-31 02:26:43 +00001472bspin "Verify or download chart specific values files $DOWNLOAD"
1473VALUES_FILES="monkey-values.yaml"
David Bainbridged18f4942020-04-14 16:46:13 -07001474ERR_OUT="$(mktemp)"
David Bainbridge99ac7a22019-08-31 02:26:43 +00001475for i in $VALUES_FILES; do
1476 if [ ! -r ./$i ]; then
serkant.uluderya4d315132020-04-15 16:25:54 -07001477 if ! (set -x; curl --fail -o "./$i" -sSL "https://raw.githubusercontent.com/opencord/kind-voltha/$VK_RELEASE/$i" >>"$LOG" 2>"$ERR_OUT") >>"$LOG" 2>&1; then
David Bainbridged18f4942020-04-14 16:46:13 -07001478 espin "$THEX"
1479 echo -e "${RED}${BOLD}${ERROR}ERROR: $i${NORMAL}${RED} - $(cat "$ERR_OUT")${NORMAL}"
1480 echo "ERROR: $i - $(cat "$ERR_OUT")" >>"$LOG"
1481 rm -rf "$ERR_OUT" "./$i"
David K. Bainbridgea00736b2020-01-08 14:33:17 -08001482 exit 1
1483 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001484 rm -rf "$ERR_OUT"
David Bainbridge99ac7a22019-08-31 02:26:43 +00001485 fi
1486done
David Bainbridged18f4942020-04-14 16:46:13 -07001487rm -rf "$ERR_OUT"
1488espin "$VERIFIED"
David Bainbridge99ac7a22019-08-31 02:26:43 +00001489if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001490 NOW="$(date +%s)"
1491 printtime $((NOW - STIME))
David Bainbridge99ac7a22019-08-31 02:26:43 +00001492fi
1493
1494if [ "$WITH_CHAOS" == "yes" ]; then
1495 bspin "Verify or clone kube-monkey helm chart $DOWNLOAD"
1496 if [ -r ./kube-monkey ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001497 espin "$VERIFIED"
David Bainbridge99ac7a22019-08-31 02:26:43 +00001498 else
David Bainbridged18f4942020-04-14 16:46:13 -07001499 espin "$NOT_VERIFIED"
David Bainbridge99ac7a22019-08-31 02:26:43 +00001500 bspin - "GIT clone kube-monkey"
David Bainbridged18f4942020-04-14 16:46:13 -07001501 (set -x; git clone https://github.com/asobti/kube-monkey kube-monkey >>"$LOG" 2>&1) >>"$LOG" 2>&1
1502 espin - "$VERIFIED"
David Bainbridge99ac7a22019-08-31 02:26:43 +00001503 fi
1504fi
1505
Test Userba1e7e72019-07-10 22:27:54 +00001506if [ "$JUST_K8S" == "yes" ]; then
1507 echo "Environment deployed, not deploying VOLTHA artifacts as requested. Good bye."
1508 echo ""
David Bainbridged18f4942020-04-14 16:46:13 -07001509 echo "Please issue the following commands in your terminal to ensure that you" | tee -a "$LOG"
1510 echo "are accessing the correct Kubernetes/Kind cluster as well as have the " | tee -a "$LOG"
1511 echo "tools required by VOLTHA in your command path. " | tee -a "$LOG"
1512 echo "" | tee -a "$LOG"
1513 echo -en "$BOLD"
1514 if [ "$DEPLOY_K8S" == "yes" ]; then
1515 echo "export KUBECONFIG=\"\$(./bin/kind get kubeconfig-path --name=\"voltha-$NAME\")\"" | tee -a "$LOG"
Test Userba1e7e72019-07-10 22:27:54 +00001516 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001517 echo "export PATH=$GOPATH/bin:\$PATH" | tee -a "$LOG"
1518 echo -en "$NORMAL"
1519 echo "" | tee -a "$LOG"
1520 echo "Thank you for choosing kind-voltha for you quick cluster needs." | tee -a "$LOG"
Test Userba1e7e72019-07-10 22:27:54 +00001521 exit 0
1522fi
1523
David Bainbridged18f4942020-04-14 16:46:13 -07001524if [ "$WITH_ETCD" != "yes" ] && [ "$WITH_ETCD" != "external" ]; then
David Bainbridge696bc632020-04-05 21:49:37 -07001525 bspin "Skip ETCD Operator Deployment"
1526 espin $NO_ENTRY
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001527else
David Bainbridged18f4942020-04-14 16:46:13 -07001528 STIME="$(date +%s)"
David Bainbridge76afd812020-04-06 09:53:52 -07001529 NS=$VOLTHA_NS
David Bainbridged18f4942020-04-14 16:46:13 -07001530 if [ "$WITH_ETCD" == "external" ]; then
David Bainbridge76afd812020-04-06 09:53:52 -07001531 NS=$INFRA_NS
1532 fi
David Bainbridge696bc632020-04-05 21:49:37 -07001533 bspin "Verify ETCD Operator $OLD_KEY"
David Bainbridged18f4942020-04-14 16:46:13 -07001534 if [ "$HELM_USE_UPGRADE" == "yes" ] || [ "$(helm list --deployed --short --namespace "$NS" "^etcd-operator\$" | wc -l)" -ne 1 ]; then
1535 espin "$NOT_VERIFIED"
1536 helm_install - "$NS" etcd-operator stable/etcd-operator latest "$_HELM_DESC ETCD Operator"
David Bainbridge696bc632020-04-05 21:49:37 -07001537 else
David Bainbridged18f4942020-04-14 16:46:13 -07001538 espin "$VERIFIED"
David Bainbridge696bc632020-04-05 21:49:37 -07001539 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001540 EXPECT="$(test "$TYPE" == "minimal" && echo "1" || echo "3")"
1541 wait_for_pods - "$NS" "$EXPECT" "includes" "Waiting for ETCD Operator to start" "$NO_LABEL" "etcd-operator-.*"
David Bainbridge696bc632020-04-05 21:49:37 -07001542 if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001543 NOW="$(date +%s)"
1544 printtime $((NOW - STIME))
David Bainbridge696bc632020-04-05 21:49:37 -07001545 fi
David Bainbridgee87067b2019-08-12 22:00:12 +00001546fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001547
David Bainbridged18f4942020-04-14 16:46:13 -07001548STIME="$(date +%s)"
David Bainbridge60ffc0f2020-04-27 22:13:22 -07001549if is_in "$WITH_ONOS" "yes,legacy,classic"; then
1550 if is_in "$WITH_ONOS" "legacy"; then
1551 bspin "Verify ONOS LEGACY installed $BIRD"
1552 if [ "$HELM_USE_UPGRADE" == "yes" ] || [ "$(helm list --deployed --short --namespace "$INFRA_NS" "^onos\$" | wc -l)" -ne 1 ]; then
1553 espin "$NOT_VERIFIED"
1554 INTERNAL_EXTRA_HELM_INSTALL_ARGS="$SET_TAG $EXTRA_HELM_FLAGS" helm_install - "$INFRA_NS" onos "$ONOS_CHART" "$ONOS_CHART_VERSION" "$_HELM_DESC ONOS LEGACY"
1555 INTERNAL_EXTRA_HELM_INSTALL_ARGS=
1556 else
1557 espin "$VERIFIED"
1558 fi
1559 wait_for_pods - "$INFRA_NS" 1 "includes" "Waiting for ONOS to start" "$NO_LABEL" "onos-.*"
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001560
David Bainbridge60ffc0f2020-04-27 22:13:22 -07001561 if [ "$WITH_PORT_FORWARDS" == "yes" ]; then
1562 bspin - "Forward ONOS API port $FORWARD"
1563 kill_port_forward onos-ui
1564 port_forward "$INFRA_NS" onos-ui "$ONOS_API_PORT:8181"
1565 espin - "$VERIFIED"
1566 bspin - "Forward ONOS SSH port $FORWARD"
1567 kill_port_forward onos-ssh
1568 port_forward "$INFRA_NS" onos-ssh "$ONOS_SSH_PORT:8101"
1569 espin - "$VERIFIED"
1570 _ONOS_API_EP="127.0.0.1:$ONOS_API_PORT"
1571 else
1572 _ONOS_API_EP="$(get_service_ep "$INFRA_NS" onos-ui)"
1573 fi
1574 elif is_in "$WITH_ONOS" "yes,classic"; then
1575 bspin "Verify ONOS CLASSIC installed $BIRD"
1576 if [ "$HELM_USE_UPGRADE" == "yes" ] || [ "$(helm list --deployed --short --namespace "$INFRA_NS" "^onos\$" | wc -l)" -ne 1 ]; then
1577 espin "$NOT_VERIFIED"
1578 # ONOS CLASSIC identifies its image repo/tag differently, so yq is used to grab the values from the
1579 # values value
David Bainbridgefad50732020-05-01 17:00:12 -07001580 YAML_VALUES=$(INTERNAL_EXTRA_HELM_INSTALL_ARGS="--set replicas=$NUM_OF_ONOS --set atomix.replicas=$NUM_OF_ATOMIX" \
1581 helm_values "$INFRA_NS" onos "$ONOS_CLASSIC_CHART" "$ONOS_CLASSIC_CHART_VERSION")
1582 _ONOS_REPO="$(echo "$YAML_VALUES" | yq read - images.onos.repository)"
1583 _ONOS_TAG="$(echo "$YAML_VALUES" | yq read - images.onos.tag)"
1584 _TAG_DEFAULT="$(echo "$YAML_VALUES" | yq read - defaults.image_tag)"
David Bainbridge60ffc0f2020-04-27 22:13:22 -07001585 if [ -z "$_ONOS_TAG" ]; then
1586 _ONOS_TAG="$_TAG_DEFAULT"
1587 fi
David Bainbridgefad50732020-05-01 17:00:12 -07001588
David Bainbridge60ffc0f2020-04-27 22:13:22 -07001589 INTERNAL_EXTRA_HELM_INSTALL_ARGS="--set image.repository=$_ONOS_REPO --set image.tag=$_ONOS_TAG --set replicas=$NUM_OF_ONOS --set atomix.replicas=$NUM_OF_ATOMIX" \
1590 helm_install - "$INFRA_NS" onos "$ONOS_CLASSIC_CHART" "$ONOS_CLASSIC_CHART_VERSION" "$_HELM_DESC ONOS CLASSIC"
1591 INTERNAL_EXTRA_HELM_INSTALL_ARGS=
1592 else
1593 espin "$VERIFIED"
1594 fi
1595 wait_for_pods - "$INFRA_NS" $((NUM_OF_ONOS + NUM_OF_ATOMIX)) "includes" "Waiting for ONOS CLASSIC to start" "$NO_LABEL" "onos-.*"
1596 if [ "$WITH_PORT_FORWARDS" == "yes" ]; then
1597 bspin - "Forward ONOS API port $FORWARD"
1598 kill_port_forward onos-onos-classic-hs
1599 port_forward "$INFRA_NS" onos-onos-classic-hs "$ONOS_API_PORT:8181" "$ONOS_SSH_PORT:8101"
1600 espin - "$VERIFIED"
1601 _ONOS_API_EP="127.0.0.1:$ONOS_API_PORT"
1602 else
1603 _ONOS_API_EP="$(get_service_ep "$INFRA_NS" onos-onos-classic-hs)"
1604 fi
1605 elif [ "$WITH_ONOS" == "micro" ]; then
1606 bspin "Verify micro-ONOS installed $BIRD"
1607 # We should never get here
1608 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} Micro ONOS not currently supported${NORMAL}"
1609 exit 1
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -08001610 fi
David Bainbridged31d6122019-08-13 19:37:59 +00001611 bspin - "Verify or download ONOS configuration support files $DOWNLOAD"
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001612 ONOS_FILES="olt-onos-enableExtraneousRules.json onos-aaa.json \
David Bainbridge696bc632020-04-05 21:49:37 -07001613 onos-dhcpl2relay.json onos-sadis-sample.json"
David Bainbridged18f4942020-04-14 16:46:13 -07001614 (set -x; mkdir -p ./onos-files >>"$LOG" 2>&1) >>"$LOG" 2>&1
1615 ERR_OUT="$(mktemp)"
David Bainbridge2b19e832019-08-16 02:40:53 +00001616 for i in $ONOS_FILES; do
David Bainbridged18f4942020-04-14 16:46:13 -07001617 if [ ! -r "./onos-files/$i" ]; then
serkant.uluderya4d315132020-04-15 16:25:54 -07001618 if ! (set -x; curl --fail -o "./onos-files/$i" -sSL "https://raw.githubusercontent.com/opencord/kind-voltha/$VK_RELEASE/onos-files/$i" >>"$LOG" 2>"$ERR_OUT") >>"$LOG" 2>&1; then
David Bainbridged18f4942020-04-14 16:46:13 -07001619 espin - "$THEX"
1620 echo -e "${RED}${BOLD}${ERROR}ERROR: $i${NORMAL}${RED} - $(cat "$ERR_OUT")${NORMAL}"
1621 echo "ERROR: $(cat "$ERR_OUT")" >>"$LOG"
1622 rm -rf "$ERR_OUT" "./onos-files/$i"
David K. Bainbridgea00736b2020-01-08 14:33:17 -08001623 exit 1
1624 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001625 rm -rf "$ERR_OUT"
David Bainbridged31d6122019-08-13 19:37:59 +00001626 fi
1627 done
David Bainbridged18f4942020-04-14 16:46:13 -07001628 rm -rf "$ERR_OUT"
1629 espin - "$VERIFIED"
David Bainbridge27790d62019-08-13 22:43:19 +00001630
David Bainbridged18f4942020-04-14 16:46:13 -07001631 if [ "$INSTALL_ONOS_APPS" == "yes" ]; then
David Bainbridge27790d62019-08-13 22:43:19 +00001632 bspin - "Installing custom ONOS applications"
David Bainbridged18f4942020-04-14 16:46:13 -07001633 if [ -x onos-files/onos-apps ] && [ "$(find onos-files/onos-apps -name "*.oar" 2>/dev/null | wc -l)" -gt 0 ]; then
1634 for OAR in onos-files/onos-apps/*.oar; do
David Bainbridge27790d62019-08-13 22:43:19 +00001635 sspin - "Installing custom ONOS applications - $OAR$CEOL"
David Bainbridged18f4942020-04-14 16:46:13 -07001636 override_onos_app "$OAR"
David Bainbridge27790d62019-08-13 22:43:19 +00001637 done
1638 espin - "$VERIFIED Installing custom ONOS applications$CEOL"
1639 else
1640 espin - "$NOT_VERIFIED Installing custom ONOS applications - None Found"
1641 fi
1642 fi
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001643
David Bainbridged18f4942020-04-14 16:46:13 -07001644 if [ "$WITH_KAFKA" != "no" ]; then
David Bainbridge837e8bd2020-04-06 13:17:14 -07001645 check_onos_app_active org.opencord.kafka
David Bainbridge76afd812020-04-06 09:53:52 -07001646 _HOST=voltha-kafka.$INFRA_NS.svc.cluster.local
David Bainbridge837e8bd2020-04-06 13:17:14 -07001647 _PORT=9092
David Bainbridged18f4942020-04-14 16:46:13 -07001648 if [ "$WITH_KAFKA" == "yes" ]; then
David Bainbridge76afd812020-04-06 09:53:52 -07001649 _HOST=voltha-kafka.$VOLTHA_NS.svc.cluster.local
1650 _PORT=9092
David Bainbridged18f4942020-04-14 16:46:13 -07001651 elif [ "$WITH_KAFKA" == "external" ]; then
David Bainbridge76afd812020-04-06 09:53:52 -07001652 _HOST=kafka.$INFRA_NS.svc.cluster.local
1653 _PORT=9092
1654 else
David Bainbridged18f4942020-04-14 16:46:13 -07001655 _HOST="$(echo "$WITH_KAFKA" | cut -d: -f1)"
1656 _PORT="$(echo "$WITH_KAFKA" | cut -s -d: -f2)"
David Bainbridge837e8bd2020-04-06 13:17:14 -07001657 _PORT=${_PORT:-9092}
1658 fi
1659 push_onos_config "json" "Push ONOS Kafka Configuration" "network/configuration/apps/org.opencord.kafka" \
David Bainbridged18f4942020-04-14 16:46:13 -07001660 "$(cat <<EOJ | tr -d '[:space:]'
David Bainbridge696bc632020-04-05 21:49:37 -07001661{
1662 "kafka": {
1663 "bootstrapServers": "$_HOST:$_PORT"
1664 }
1665}
1666EOJ
David Bainbridged18f4942020-04-14 16:46:13 -07001667)"
David Bainbridge837e8bd2020-04-06 13:17:14 -07001668 fi
Matteo Scandolo9a77a732020-01-09 14:24:12 -08001669 check_onos_app_active org.opencord.dhcpl2relay
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001670 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 -08001671 check_onos_app_active org.opencord.olt
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001672 # FIXME use WITH_DHCP and WITH_EAPOL flags to configre OLT App
Hardik Windlassa7501fb2020-02-17 14:28:20 +00001673 # Default value for "enableEapol" is true in OLT App
David Bainbridged18f4942020-04-14 16:46:13 -07001674 if [ "$WITH_EAPOL" == "yes" ]; then
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001675 push_onos_config "json" "Enable VOLTHA ONOS EAPOL provisioning" "configuration/org.opencord.olt.impl.OltFlowService" '{"enableEapol":true}'
David Bainbridged18f4942020-04-14 16:46:13 -07001676 elif [ "$WITH_EAPOL" == "no" ]; then
Hardik Windlassa7501fb2020-02-17 14:28:20 +00001677 push_onos_config "json" "Disable VOLTHA ONOS EAPOL provisioning" "configuration/org.opencord.olt.impl.OltFlowService" '{"enableEapol":false}'
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001678 fi
Hardik Windlassa7501fb2020-02-17 14:28:20 +00001679 # Default value for "enableDhcpOnProvisioning" is false and for "enableDhcpV4" is true in OLT App
David Bainbridged18f4942020-04-14 16:46:13 -07001680 if [ "$WITH_DHCP" == "yes" ]; then
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001681 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 -07001682 elif [ "$WITH_DHCP" == "no" ]; then
Hardik Windlassa7501fb2020-02-17 14:28:20 +00001683 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 -08001684 fi
Hardik Windlassa7501fb2020-02-17 14:28:20 +00001685 # Default value for "enableIgmpOnProvisioning" is false in OLT App
David Bainbridged18f4942020-04-14 16:46:13 -07001686 if [ "$WITH_IGMP" == "yes" ]; then
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001687 push_onos_config "json" "Enable VOLTHA ONOS IGMP provisioning" "configuration/org.opencord.olt.impl.OltFlowService" '{"enableIgmpOnProvisioning":true}'
David Bainbridged18f4942020-04-14 16:46:13 -07001688 elif [ "$WITH_IGMP" == "no" ]; then
Hardik Windlassa7501fb2020-02-17 14:28:20 +00001689 push_onos_config "json" "Disable VOLTHA ONOS IGMP provisioning" "configuration/org.opencord.olt.impl.OltFlowService" '{"enableIgmpOnProvisioning":false}'
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001690 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001691 if [ "$ENABLE_ONOS_EXTRANEOUS_RULES" == "yes" ]; then
David K. Bainbridge484d80c2020-03-05 21:44:34 -08001692 push_onos_config "file" "Enabling extraneous rules for ONOS" "configuration/org.onosproject.net.flow.impl.FlowRuleManager" "onos-files/olt-onos-enableExtraneousRules.json"
1693 fi
David Bainbridge60ffc0f2020-04-27 22:13:22 -07001694 if is_in "$CONFIG_SADIS" "yes,file"; then
Matteo Scandolo9a77a732020-01-09 14:24:12 -08001695 check_onos_app_active org.opencord.sadis
Hardik Windlassb3147602020-03-09 16:59:15 +05301696 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 -07001697 elif [ "$CONFIG_SADIS" == "bbsim" ]; then
1698 push_onos_config "json" \
1699 "[optional] Push ONOS configuration for BBSIM SADIS servers" \
1700 "network/configuration/apps/org.opencord.sadis" \
David Bainbridged18f4942020-04-14 16:46:13 -07001701 "$(cat <<EOJ | tr -d '[:space:]'
David K. Bainbridgeb859e912020-03-13 14:07:52 -07001702{
1703 "sadis": {
1704 "integration": {
David Bainbridge76afd812020-04-06 09:53:52 -07001705 "url": "http://bbsim.$BBSIM_NS.svc.cluster.local:50074/v2/subscribers/%s",
David K. Bainbridgeb859e912020-03-13 14:07:52 -07001706 "cache": {
1707 "enabled": true,
1708 "maxsize": 50,
1709 "ttl": "PT1m"
1710 }
1711 }
1712 },
1713 "bandwidthprofile": {
1714 "integration": {
David Bainbridge76afd812020-04-06 09:53:52 -07001715 "url": "http://bbsim.$BBSIM_NS.svc.cluster.local:50074/v2/bandwidthprofiles/%s",
David K. Bainbridgeb859e912020-03-13 14:07:52 -07001716 "cache": {
1717 "enabled": true,
1718 "maxsize": 50,
1719 "ttl": "PT1m"
1720 }
1721 }
1722 }
1723}
1724EOJ
David Bainbridged18f4942020-04-14 16:46:13 -07001725)"
David K. Bainbridgeb859e912020-03-13 14:07:52 -07001726 elif [ "$CONFIG_SADIS" == "url" ]; then
1727 push_onos_config "json" \
1728 "[optional] Push ONOS configuration for custom SADIS and Bandwidth Profile servers" \
1729 "network/configuration/apps/org.opencord.sadis" \
David Bainbridged18f4942020-04-14 16:46:13 -07001730 "$(cat <<EOJ | tr -d '[:space:]'
David K. Bainbridgeb859e912020-03-13 14:07:52 -07001731{
1732 "sadis": {
1733 "integration": {
1734 "url": "$SADIS_SUBSCRIBERS",
1735 "cache": {
1736 "enabled": true,
1737 "maxsize": 50,
1738 "ttl": "PT1m"
1739 }
1740 }
1741 },
1742 "bandwidthprofile": {
1743 "integration": {
1744 "url": "$SADIS_BANDWIDTH_PROFILES",
1745 "cache": {
1746 "enabled": true,
1747 "maxsize": 50,
1748 "ttl": "PT1m"
1749 }
1750 }
1751 }
1752}
1753EOJ
David Bainbridged18f4942020-04-14 16:46:13 -07001754)"
David Bainbridge2b19e832019-08-16 02:40:53 +00001755 fi
Test Userba1e7e72019-07-10 22:27:54 +00001756fi
David Bainbridgee87067b2019-08-12 22:00:12 +00001757if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001758 NOW="$(date +%s)"
1759 printtime $((NOW - STIME))
David Bainbridgee87067b2019-08-12 22:00:12 +00001760fi
Test Userba1e7e72019-07-10 22:27:54 +00001761
David Bainbridged18f4942020-04-14 16:46:13 -07001762if [ "$WITH_ETCD" == "external" ]; then
1763 STIME="$(date +%s)"
David Bainbridge76afd812020-04-06 09:53:52 -07001764 bspin "Verify external ETCD cluster $OLD_KEY"
David Bainbridged18f4942020-04-14 16:46:13 -07001765 EXPECT="$(test "$TYPE" == "minimal" && echo "1" || echo "3")"
1766 if [ "$HELM_USE_UPGRADE" == "yes" ] || [ "$(helm list --deployed --short --namespace "$INFRA_NS" "^etcd-cluster\$" | wc -l)" -ne 1 ]; then
1767 espin "$NOT_VERIFIED"
David Bainbridge76afd812020-04-06 09:53:52 -07001768 INTERNAL_EXTRA_HELM_INSTALL_ARGS+="--set clusterName=etcd-cluster --set autoCompactionRetention=1 --set clusterSize=$EXPECT"
David Bainbridged18f4942020-04-14 16:46:13 -07001769 helm_install - "$INFRA_NS" etcd-cluster onf/voltha-etcd-cluster latest "$_HELM_DESC external ETCD cluster"
David Bainbridge76afd812020-04-06 09:53:52 -07001770 else
David Bainbridged18f4942020-04-14 16:46:13 -07001771 espin "$VERIFIED"
David Bainbridge76afd812020-04-06 09:53:52 -07001772 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001773 wait_for_pods - "$INFRA_NS" "$EXPECT" "includes" "Waiting for ETCD cluster to start" "$NO_LABEL" "etcd-cluster-.*"
David Bainbridge76afd812020-04-06 09:53:52 -07001774 if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001775 NOW="$(date +%s)"
1776 printtime $((NOW - STIME))
David Bainbridge76afd812020-04-06 09:53:52 -07001777 fi
1778fi
1779
David Bainbridged18f4942020-04-14 16:46:13 -07001780if [ "$WITH_KAFKA" == "external" ]; then
1781 _TMP="$(mktemp -u)"
1782 _COUNT="$(test "$TYPE" == "minimal" && echo "1" || echo "3")"
1783 cat << EOC > "$_TMP"
David Bainbridge76afd812020-04-06 09:53:52 -07001784configurationOverrides:
1785 "default.replication.factor": $_COUNT
1786 "offsets.topic.replication.factor": $_COUNT
1787 "log.retention.hours": 4
1788 "log.message.timestamp.type": "LogAppendTime"
1789persistence:
1790 enabled: false
1791zookeeper:
1792 replicaCount: 1
1793 persistence:
1794 enabled: false
1795replicas: $_COUNT
1796EOC
David Bainbridged18f4942020-04-14 16:46:13 -07001797 STIME="$(date +%s)"
David Bainbridge76afd812020-04-06 09:53:52 -07001798 bspin "Verify external Kafka cluster $OLD_KEY"
David Bainbridged18f4942020-04-14 16:46:13 -07001799 EXPECT="$(test "$TYPE" == "minimal" && echo "2" || echo "4")"
1800 if [ "$HELM_USE_UPGRADE" == "yes" ] || [ "$(helm list --deployed --short --namespace "$INFRA_NS" "^kafka\$" | wc -l)" -ne 1 ]; then
1801 espin "$NOT_VERIFIED"
David Bainbridge76afd812020-04-06 09:53:52 -07001802 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" -f $_TMP"
David Bainbridgecf546362020-04-21 23:18:50 -07001803 helm_install - "$INFRA_NS" kafka "$KAFKA_CHART" "$KAFKA_CHART_VERSION" "$_HELM_DESC external Kafka cluster"
David Bainbridge76afd812020-04-06 09:53:52 -07001804 else
David Bainbridged18f4942020-04-14 16:46:13 -07001805 espin "$VERIFIED"
David Bainbridge76afd812020-04-06 09:53:52 -07001806 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001807 wait_for_pods - "$INFRA_NS" "$EXPECT" "includes" "Waiting for Kafka cluster to start" "$NO_LABEL" "kafka-.*"
David Bainbridge76afd812020-04-06 09:53:52 -07001808 if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001809 NOW="$(date +%s)"
1810 printtime $((NOW - STIME))
David Bainbridge76afd812020-04-06 09:53:52 -07001811 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001812 rm -rf "$_TMP"
David Bainbridge76afd812020-04-06 09:53:52 -07001813fi
1814
David Bainbridged18f4942020-04-14 16:46:13 -07001815STIME="$(date +%s)"
David Bainbridge696bc632020-04-05 21:49:37 -07001816EXPECT=1
1817if [ "$ONLY_ONE" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001818 EXPECT="$((EXPECT+1))"
David Bainbridge696bc632020-04-05 21:49:37 -07001819 INTERNAL_EXTRA_HELM_INSTALL_ARGS="--set therecanbeonlyone=true"
1820else
David Bainbridged18f4942020-04-14 16:46:13 -07001821 EXPECT="$((EXPECT+2))"
David Bainbridge696bc632020-04-05 21:49:37 -07001822fi
Matteo Scandolo67335f02020-04-09 11:19:53 -07001823case $WITH_ETCD in
David Bainbridge76afd812020-04-06 09:53:52 -07001824 no)
1825 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set private_etcd_cluster=false"
1826 ;;
1827 yes)
1828 _HOST="voltha-etcd-cluster-client.$VOLTHA_NS.svc.cluster.local"
1829 _PORT=2379
1830 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set services.etcd.service=$_HOST --set services.etcd.port=$_PORT"
David Bainbridged18f4942020-04-14 16:46:13 -07001831 EXPECT="$((EXPECT+$(test "$TYPE" == "minimal" && echo "1" || echo "3")))"
David Bainbridge76afd812020-04-06 09:53:52 -07001832 ;;
1833 external)
1834 _HOST="etcd-cluster-client.$INFRA_NS.svc.cluster.local"
1835 _PORT=2379
1836 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set private_etcd_cluster=false --set services.etcd.service=$_HOST --set services.etcd.port=$_PORT"
1837 ;;
1838 *)
David Bainbridged18f4942020-04-14 16:46:13 -07001839 _HOST="$(echo "$WITH_ETCD" | cut -d: -f1)"
1840 _PORT="$(echo "$WITH_ETCD" | cut -s -d: -f2)"
David Bainbridge696bc632020-04-05 21:49:37 -07001841 _PORT=${_PORT:-2379}
David Bainbridge76afd812020-04-06 09:53:52 -07001842 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set private_etcd_cluster=false --set services.etcd.service=$_HOST --set services.etcd.port=$_PORT"
1843 ;;
1844esac
1845case $WITH_KAFKA in
1846 no)
1847 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set private_kafka_cluster=false"
1848 ;;
1849 yes)
1850 _HOST=voltha-kafka.$VOLTHA_NS.svc.cluster.local
1851 _PORT=9092
1852 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 -07001853 EXPECT="$((EXPECT+$(test "$TYPE" == "minimal" && echo "2" || echo "4")))"
David Bainbridge76afd812020-04-06 09:53:52 -07001854 ;;
1855 external)
1856 _HOST=kafka.$INFRA_NS.svc.cluster.local
1857 _PORT=9092
1858 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"
1859 ;;
1860 *)
David Bainbridged18f4942020-04-14 16:46:13 -07001861 _HOST="$(echo "$WITH_KAFKA" | cut -d: -f1)"
1862 _PORT="$(echo "$WITH_KAFKA" | cut -s -d: -f2)"
David Bainbridge696bc632020-04-05 21:49:37 -07001863 _PORT=${_PORT:-9092}
David Bainbridge76afd812020-04-06 09:53:52 -07001864 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"
1865 ;;
1866esac
1867
David Bainbridge60ffc0f2020-04-27 22:13:22 -07001868if is_in "$WITH_ONOS" "legacy"; then
David Bainbridge76afd812020-04-06 09:53:52 -07001869 _HOST=onos-openflow.$INFRA_NS.svc.cluster.local
1870 _PORT=6653
David Bainbridge60ffc0f2020-04-27 22:13:22 -07001871elif is_in "$WITH_ONOS" "yes,classic"; then
1872 _HOST=onos-onos-classic-hs.$INFRA_NS.svc.cluster.local
1873 _PORT=6653
David Bainbridged18f4942020-04-14 16:46:13 -07001874elif [ "$WITH_ONOS" != "no" ]; then
1875 _HOST="$(echo "$WITH_ONOS" | cut -d: -f1)"
1876 _PORT="$(echo "$WITH_ONOS" | cut -s -d: -f2)"
David Bainbridge76afd812020-04-06 09:53:52 -07001877 _PORT=${_PORT:-6653}
Jonathan Hart6a91e6c2020-04-16 14:28:33 -07001878fi
David Bainbridge60ffc0f2020-04-27 22:13:22 -07001879
David Bainbridgecf546362020-04-21 23:18:50 -07001880compare_versions "$RESOLVED_VOLTHA_CHART_VERSION" 2.4.2
Jonathan Hart6a91e6c2020-04-16 14:28:33 -07001881if [ "$?" == "1" ]; then
1882 # voltha chart > 2.4.2 uses list of controllers
1883 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set services.controller[0].service=$_HOST --set services.controller[0].port=$_PORT"
1884else
1885 # voltha chart <= 2.4.2 uses single controller
David Bainbridge76afd812020-04-06 09:53:52 -07001886 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set services.controller.service=$_HOST --set services.controller.port=$_PORT"
David Bainbridge696bc632020-04-05 21:49:37 -07001887fi
Jonathan Hart6a91e6c2020-04-16 14:28:33 -07001888
Test Userb5712372019-07-03 21:52:17 +00001889bspin "Verify VOLTHA installed $HIGH_VOLTAGE"
David Bainbridged18f4942020-04-14 16:46:13 -07001890if [ "$HELM_USE_UPGRADE" == "yes" ] || [ "$(helm list --deployed --short --namespace "$VOLTHA_NS" "^voltha\$" | wc -l)" -ne 1 ]; then
1891 espin "$NOT_VERIFIED"
1892 helm_install - "$VOLTHA_NS" voltha "$VOLTHA_CHART" "$VOLTHA_CHART_VERSION" "$_HELM_DESC VOLTHA Core"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001893else
David Bainbridged18f4942020-04-14 16:46:13 -07001894 espin "$VERIFIED"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001895fi
David Bainbridge696bc632020-04-05 21:49:37 -07001896INTERNAL_EXTRA_HELM_INSTALL_ARGS=
Test Userba1e7e72019-07-10 22:27:54 +00001897
David Bainbridge90fd8e32019-08-21 23:32:47 +00001898VOLTHA="voltha-ofagent-.* \
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001899 rw-core.* \
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001900 voltha-etcd-cluster-.* \
1901 voltha-kafka-.* \
1902 voltha-zookeeper-.*"
David Bainbridged18f4942020-04-14 16:46:13 -07001903wait_for_pods - "$VOLTHA_NS" "$EXPECT" "includes" "Waiting for VOLTHA Core to start" "$NO_LABEL" "$VOLTHA"
David Bainbridgee87067b2019-08-12 22:00:12 +00001904if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001905 NOW="$(date +%s)"
1906 printtime $((NOW - STIME))
David Bainbridgee87067b2019-08-12 22:00:12 +00001907fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001908
David Bainbridge46505fb2019-10-01 21:13:20 +00001909if [ "$WITH_ADAPTERS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001910 STIME="$(date +%s)"
David Bainbridge46505fb2019-10-01 21:13:20 +00001911 EXPECT=0
David Bainbridged18f4942020-04-14 16:46:13 -07001912 if [ "$WITH_ETCD" == "yes" ]; then
David Bainbridge3517f6c2020-04-08 12:14:08 -07001913 _HOST=voltha-etcd-cluster-client.$VOLTHA_NS.svc.cluster.local
1914 _PORT=2379
1915 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set services.etcd.service=$_HOST --set services.etcd.port=$_PORT"
David Bainbridged18f4942020-04-14 16:46:13 -07001916 elif [ "$WITH_ETCD" == "external" ]; then
David Bainbridge3517f6c2020-04-08 12:14:08 -07001917 _HOST=etcd-cluster-client.$INFRA_NS.svc.cluster.local
1918 _PORT=2379
1919 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set services.etcd.service=$_HOST --set services.etcd.port=$_PORT"
David Bainbridged18f4942020-04-14 16:46:13 -07001920 elif [ "$WITH_ETCD" != "no" ]; then
1921 _HOST="$(echo "$WITH_ETCD" | cut -d: -f1)"
1922 _PORT="$(echo "$WITH_ETCD" | cut -s -d: -f2)"
David Bainbridge3517f6c2020-04-08 12:14:08 -07001923 _PORT=${_PORT:-2379}
1924 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set services.etcd.service=$_HOST --set services.etcd.port=$_PORT"
David Bainbridge696bc632020-04-05 21:49:37 -07001925 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001926 if [ "$WITH_KAFKA" == "yes" ]; then
David Bainbridge3517f6c2020-04-08 12:14:08 -07001927 _HOST=voltha-kafka.$VOLTHA_NS.svc.cluster.local
1928 _PORT=9092
1929 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 -07001930 elif [ "$WITH_KAFKA" == "external" ]; then
David Bainbridge3517f6c2020-04-08 12:14:08 -07001931 _HOST=kafka.$INFRA_NS.svc.cluster.local
1932 _PORT=9092
1933 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 -07001934 elif [ "$WITH_KAFKA" != "no" ]; then
1935 _HOST="$(echo "$WITH_KAFKA" | cut -d: -f1)"
1936 _PORT="$(echo "$WITH_KAFKA" | cut -s -d: -f2)"
David Bainbridge3517f6c2020-04-08 12:14:08 -07001937 _PORT=${_PORT:-9092}
1938 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 -07001939 fi
David Bainbridge46505fb2019-10-01 21:13:20 +00001940 echo -e "Verify Adapters $PLUG"
1941 if [ "$WITH_SIM_ADAPTERS" == "yes" ]; then
1942 bspin - "Verify Simulated Adapters installed"
David Bainbridged18f4942020-04-14 16:46:13 -07001943 if [ "$HELM_USE_UPGRADE" == "yes" ] || [ "$(helm list --deployed --short --namespace "$ADAPTER_NS" "^sim\$" | wc -l)" -ne 1 ]; then
1944 espin - "$NOT_VERIFIED"
1945 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 +00001946 else
David Bainbridged18f4942020-04-14 16:46:13 -07001947 espin - "$VERIFIED"
David Bainbridge46505fb2019-10-01 21:13:20 +00001948 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001949 EXPECT="$((EXPECT + 2))"
David Bainbridge46505fb2019-10-01 21:13:20 +00001950 fi
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001951
David Bainbridge46505fb2019-10-01 21:13:20 +00001952 if [ "$WITH_OPEN_ADAPTERS" == "yes" ]; then
1953 bspin - "Verify OpenOLT Adapter installed"
David Bainbridged18f4942020-04-14 16:46:13 -07001954 if [ "$HELM_USE_UPGRADE" == "yes" ] || [ "$(helm list --deployed --short --namespace "$ADAPTER_NS" "^open-olt\$" | wc -l)" -ne 1 ]; then
1955 espin - "$NOT_VERIFIED"
1956 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 +00001957 else
David Bainbridged18f4942020-04-14 16:46:13 -07001958 espin - "$VERIFIED"
David Bainbridge46505fb2019-10-01 21:13:20 +00001959 fi
Matteo Scandolo67335f02020-04-09 11:19:53 -07001960 EXPECT="$((EXPECT + 1))"
David Bainbridge46505fb2019-10-01 21:13:20 +00001961 bspin - "Verify OpenONU Adapter installed"
David Bainbridged18f4942020-04-14 16:46:13 -07001962 if [ "$HELM_USE_UPGRADE" == "yes" ] || [ "$(helm list --deployed --short --namespace "$ADAPTER_NS" "^open-onu\$" | wc -l)" -ne 1 ]; then
Matteo Scandolo67335f02020-04-09 11:19:53 -07001963 _ORIGINAL_EXTRA_HELM_INSTALL_ARGS="$INTERNAL_EXTRA_HELM_INSTALL_ARGS"
1964 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set replicas.adapter_open_onu=$NUM_OF_OPENONU"
David Bainbridged18f4942020-04-14 16:46:13 -07001965 espin - "$NOT_VERIFIED"
Matteo Scandolo67335f02020-04-09 11:19:53 -07001966 helm_install - "$ADAPTER_NS" open-onu "$VOLTHA_ADAPTER_OPEN_ONU_CHART" "$VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION" "$_HELM_DESC OpenONU Adapter"
1967 INTERNAL_EXTRA_HELM_INSTALL_ARGS="$_ORIGINAL_EXTRA_HELM_INSTALL_ARGS"
David Bainbridge46505fb2019-10-01 21:13:20 +00001968 else
David Bainbridged18f4942020-04-14 16:46:13 -07001969 espin - "$VERIFIED"
David Bainbridge46505fb2019-10-01 21:13:20 +00001970 fi
Matteo Scandolo67335f02020-04-09 11:19:53 -07001971 EXPECT=$((EXPECT + NUM_OF_OPENONU))
David Bainbridge46505fb2019-10-01 21:13:20 +00001972 fi
David Bainbridge696bc632020-04-05 21:49:37 -07001973 INTERNAL_EXTRA_HELM_INSTALL_ARGS=
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001974
David Bainbridge46505fb2019-10-01 21:13:20 +00001975 ADAPTERS="adapter-.*"
David Bainbridged18f4942020-04-14 16:46:13 -07001976 wait_for_pods - "$ADAPTER_NS" "$EXPECT" "includes" "Waiting for adapters to start" "$NO_LABEL" "$ADAPTERS"
David Bainbridge46505fb2019-10-01 21:13:20 +00001977 if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001978 NOW="$(date +%s)"
1979 printtime $((NOW - STIME))
David Bainbridge46505fb2019-10-01 21:13:20 +00001980 fi
David Bainbridgee87067b2019-08-12 22:00:12 +00001981fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001982
David Bainbridged18f4942020-04-14 16:46:13 -07001983if [ "$WITH_BBSIM" == "yes" ]; then
1984 STIME="$(date +%s)"
Test User7d866122019-07-09 17:52:35 +00001985 echo -e "Verify BBSIM $PLUG"
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001986 bspin - "Verify BBSIM Installed"
David Bainbridged18f4942020-04-14 16:46:13 -07001987 for instance in $(seq 0 $((NUM_OF_BBSIM-1))); do
Matteo Scandoloc2eb0672020-05-01 14:43:15 -07001988
1989 if [ "$LEGACY_BBSIM_INDEX" == "yes" ]; then
1990 if [ "$instance" -eq 0 ]; then
1991 instance_num=""
1992 else
1993 instance_num=$instance
1994 fi
David K. Bainbridge43422402020-03-06 07:41:22 -08001995 else
1996 instance_num=$instance
1997 fi
Matteo Scandoloc2eb0672020-05-01 14:43:15 -07001998
1999
David Bainbridged18f4942020-04-14 16:46:13 -07002000 if [ "$HELM_USE_UPGRADE" == "yes" ] || [ "$(helm list --deployed --short --namespace "$BBSIM_NS" "^bbsim${instance_num}\$" | wc -l)" -ne 1 ]; then
2001 espin - "$NOT_VERIFIED"
2002 S_TAG="$((900+instance))"
Matteo Scandolo5a149572020-04-01 10:14:57 -07002003 INTERNAL_EXTRA_HELM_INSTALL_ARGS="--set olt_id=$instance,s_tag=$S_TAG"
David Bainbridged9329af2020-05-01 11:58:52 -07002004 if [ "$WITH_EAPOL" == "yes" ]; then
2005 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set auth=true"
2006 else
2007 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set auth=false"
2008 fi
2009 if [ "$WITH_DHCP" == "yes" ]; then
2010 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set dhcp=true"
2011 else
2012 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set dhcp=false"
2013 fi
David Bainbridged18f4942020-04-14 16:46:13 -07002014 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 -07002015 INTERNAL_EXTRA_HELM_INSTALL_ARGS=
David K. Bainbridge43422402020-03-06 07:41:22 -08002016 else
David Bainbridged18f4942020-04-14 16:46:13 -07002017 espin - "$VERIFIED"
David K. Bainbridge43422402020-03-06 07:41:22 -08002018 fi
2019 done
David Bainbridged18f4942020-04-14 16:46:13 -07002020 wait_for_pods - "$BBSIM_NS" "$NUM_OF_BBSIM" "includes" "Waiting for BBSIM to start" "$BBSIM_LABEL" "bbsim*"
David Bainbridgee87067b2019-08-12 22:00:12 +00002021 if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07002022 NOW="$(date +%s)"
2023 printtime $((NOW - STIME))
David Bainbridgee87067b2019-08-12 22:00:12 +00002024 fi
Test User7d866122019-07-09 17:52:35 +00002025fi
2026
David Bainbridged18f4942020-04-14 16:46:13 -07002027if [ "$WITH_RADIUS" == "yes" ]; then
2028 STIME="$(date +%s)"
David Bainbridge5b7b96b2019-07-25 20:29:13 +00002029 echo -e "Verify RADIUS $LOCK"
2030 bspin - "Verify RADIUS Installed"
David Bainbridged18f4942020-04-14 16:46:13 -07002031 if [ "$HELM_USE_UPGRADE" == "yes" ] || [ "$(helm list --deployed --short --namespace "$INFRA_NS" "^radius\$" | wc -l)" -ne 1 ]; then
2032 espin - "$NOT_VERIFIED"
2033 helm_install - "$INFRA_NS" radius onf/freeradius latest "$_HELM_DESC RADIUS"
David Bainbridge5b7b96b2019-07-25 20:29:13 +00002034 else
David Bainbridged18f4942020-04-14 16:46:13 -07002035 espin - "$VERIFIED"
David Bainbridge5b7b96b2019-07-25 20:29:13 +00002036 fi
David Bainbridged18f4942020-04-14 16:46:13 -07002037 wait_for_pods - "$INFRA_NS" 1 "includes" "Waiting for RADIUS to start" "$NO_LABEL" "radius-.*"
David Bainbridgee87067b2019-08-12 22:00:12 +00002038 if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07002039 NOW="$(date +%s)"
2040 printtime $((NOW - STIME))
David Bainbridgee87067b2019-08-12 22:00:12 +00002041 fi
David Bainbridge5b7b96b2019-07-25 20:29:13 +00002042fi
2043
David Bainbridged18f4942020-04-14 16:46:13 -07002044if [ "$WITH_PORT_FORWARDS" == "yes" ]; then
2045 STIME="$(date +%s)"
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -08002046 bspin - "Forward VOLTHA API port $FORWARD"
2047 kill_port_forward voltha-api
David Bainbridge60ffc0f2020-04-27 22:13:22 -07002048 port_forward "$VOLTHA_NS" voltha-api "$VOLTHA_API_PORT:55555"
David Bainbridged18f4942020-04-14 16:46:13 -07002049 espin - "$VERIFIED"
2050 if [ "$WITH_ETCD" == "yes" ] || [ "$WITH_ETCD" == "external" ]; then
2051 _NS="$(test "$WITH_ETCD" == "yes" && echo "$VOLTHA_NS" || echo "$INFRA_NS")"
David Bainbridge696bc632020-04-05 21:49:37 -07002052 bspin - "Forward VOLTHA ETCD port $FORWARD"
David Bainbridged18f4942020-04-14 16:46:13 -07002053 kill_port_forward "${ETCD_PREFIX}etcd-cluster-client"
David Bainbridge60ffc0f2020-04-27 22:13:22 -07002054 port_forward "$_NS" "${ETCD_PREFIX}etcd-cluster-client" "$VOLTHA_ETCD_PORT:2379"
David Bainbridged18f4942020-04-14 16:46:13 -07002055 espin - "$VERIFIED"
David Bainbridge696bc632020-04-05 21:49:37 -07002056 fi
David Bainbridged18f4942020-04-14 16:46:13 -07002057 if [ "$WITH_KAFKA" == "yes" ] || [ $WITH_KAFKA == "external" ]; then
2058 _NS="$(test "$WITH_ETCD" == "yes" && echo "$VOLTHA_NS" || echo "$INFRA_NS")"
David Bainbridge696bc632020-04-05 21:49:37 -07002059 bspin - "Forward VOLTHA Kafka port $FORWARD"
David Bainbridged18f4942020-04-14 16:46:13 -07002060 kill_port_forward "${KAFKA_PREFIX}kafka"
David Bainbridge60ffc0f2020-04-27 22:13:22 -07002061 port_forward "$_NS" ${KAFKA_PREFIX}kafka "$VOLTHA_KAFKA_PORT:9092"
David Bainbridged18f4942020-04-14 16:46:13 -07002062 espin - "$VERIFIED"
David Bainbridge696bc632020-04-05 21:49:37 -07002063 fi
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -08002064 if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07002065 NOW="$(date +%s)"
2066 printtime $((NOW - STIME))
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -08002067 fi
David Bainbridgee87067b2019-08-12 22:00:12 +00002068fi
Test User3d7ad8e2019-07-03 06:15:44 +00002069
David Bainbridge60ffc0f2020-04-27 22:13:22 -07002070if is_in "$WITH_ONOS" "yes,legacy,classic" && [ "$WITH_RADIUS" != "no" ]; then
David Bainbridge76afd812020-04-06 09:53:52 -07002071 _HOST=radius.$INFRA_NS.svc.cluster.local
David Bainbridge696bc632020-04-05 21:49:37 -07002072 _PORT=1812
David Bainbridged18f4942020-04-14 16:46:13 -07002073 if [ "$WITH_RADIUS" != "yes" ]; then
2074 _HOST="$(echo "$WITH_RADIUS" | cut -d: -f1)"
2075 _PORT="$(echo "$WITH_RADIUS" | cut -s -d: -f2)"
David Bainbridge696bc632020-04-05 21:49:37 -07002076 _PORT=${_PORT:-1812}
2077 fi
David Bainbridge5b7b96b2019-07-25 20:29:13 +00002078 bspin "Configure ONOS RADIUS Connection $GEAR"
David Bainbridged18f4942020-04-14 16:46:13 -07002079 (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
2080 espin "$VERIFIED"
David Bainbridge5b7b96b2019-07-25 20:29:13 +00002081fi
2082
David Bainbridge99ac7a22019-08-31 02:26:43 +00002083if [ "$WITH_CHAOS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07002084 STIME="$(date +%s)"
David Bainbridge99ac7a22019-08-31 02:26:43 +00002085 echo -e "Verify kube-monkey $LOCK"
2086 bspin - "Verify kube-monkey Installed"
David Bainbridged18f4942020-04-14 16:46:13 -07002087 if [ "$HELM_USE_UPGRADE" == "yes" ] || [ "$(helm list --deployed --short --namespace kube-monkey "^monkey\$" | wc -l)" -ne 1 ]; then
2088 espin - "$NOT_VERIFIED"
David Bainbridge7f8bf992020-04-08 21:53:22 -07002089 helm_install - kube-monkey monkey ./kube-monkey/helm/kubemonkey latest "$_HELM_DESC Chaos Monkey"
David Bainbridge99ac7a22019-08-31 02:26:43 +00002090 else
David Bainbridged18f4942020-04-14 16:46:13 -07002091 espin - "$VERIFIED"
David Bainbridge99ac7a22019-08-31 02:26:43 +00002092 fi
David Bainbridged18f4942020-04-14 16:46:13 -07002093 wait_for_pods - "kube-monkey" 1 "includes" "Waiting for Chaos to start" "$NO_LABEL" "monkey-.*"
David Bainbridge99ac7a22019-08-31 02:26:43 +00002094 if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07002095 NOW="$(date +%s)"
2096 printtime $((NOW - STIME))
David Bainbridge99ac7a22019-08-31 02:26:43 +00002097 fi
2098fi
2099
David Bainbridge5b7b96b2019-07-25 20:29:13 +00002100bspin "Create voltctl configuration file"
David Bainbridged18f4942020-04-14 16:46:13 -07002101(set -x; mkdir -p "$HOME/.volt" >>"$LOG" 2>&1) >>"$LOG" 2>&1
2102MIN_VC_VERSION="$(echo -e "1.0.15\n$VC_VERSION" | sort -V | head -1)"
2103if [ "$WITH_PORT_FORWARDS" == "yes" ]; then
David K. Bainbridgeb859e912020-03-13 14:07:52 -07002104 KAFKA_FLAG="-k localhost:$VOLTHA_KAFKA_PORT"
2105 SERVER_FLAG="-s localhost:$VOLTHA_API_PORT"
2106 ETCD_FLAG=
2107 if [ "$MIN_VC_VERSION" == "1.0.15" ]; then
2108 ETCD_FLAG="-e localhost:$VOLTHA_ETCD_PORT"
2109 fi
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -08002110else
David Bainbridged18f4942020-04-14 16:46:13 -07002111 KAFKA_FLAG="-k $(get_service_ep "$INFRA_NS" "${KAFKA_PREFIX}kafka")"
2112 SERVER_FLAG="-s $(get_service_ep "$VOLTHA_NS" voltha-api)"
David K. Bainbridgeb859e912020-03-13 14:07:52 -07002113 ETCD_FLAG=
2114 if [ "$MIN_VC_VERSION" == "1.0.15" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07002115 ETCD_FLAG="-e $(get_service_ep "$INFRA_NS" ${ETCD_PREFIX}etcd-client)"
David K. Bainbridgeb859e912020-03-13 14:07:52 -07002116 fi
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -08002117fi
David Bainbridged18f4942020-04-14 16:46:13 -07002118CMD=("voltctl -a v3 $KAFKA_FLAG $SERVER_FLAG $ETCD_FLAG config")
2119(set -x; ${CMD[*]} > "$HOME/.volt/config-$NAME" 2>>"$LOG") >>"$LOG" 2>&1
2120#(set -x; voltctl -a v3 "$KAFKA_FLAG" "$SERVER_FLAG" "$ETCD_FLAG" config > "$HOME/.volt/config-$NAME" 2>>"$LOG") >>"$LOG" 2>&1
2121espin "$VERIFIED"
Test User08ebbd92019-07-03 17:15:39 +00002122
David Bainbridge0774b232019-08-02 06:37:19 +00002123if [ ! -f "$NAME-env.sh" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07002124 touch "$NAME-env.sh"
David Bainbridgeb07fdf72019-07-29 22:51:40 +00002125fi
2126
David Bainbridge596f30d2019-07-30 17:07:59 +00002127for O in $ALL_OPTIONS; do
David Bainbridged18f4942020-04-14 16:46:13 -07002128 VAL="$(eval echo "\$$O")"
2129 if [ -n "$VAL" ] && [ "$(grep -c "^export $O=" "$NAME-env.sh")" -eq 0 ]; then
2130 echo "export $O=\"$(eval echo "\$$O")\"" >> "$NAME-env.sh"
David Bainbridgeb07fdf72019-07-29 22:51:40 +00002131 fi
2132done
2133
David Bainbridged18f4942020-04-14 16:46:13 -07002134if [ "$DEPLOY_K8S" == "yes" ] && [ "$(grep -c "^export KUBECONFIG=" "$NAME-env.sh")" -eq 0 ]; then
2135 echo "export KUBECONFIG=\"$(./bin/kind get kubeconfig-path "--name=voltha-$NAME")\"" >> "$NAME-env.sh"
David Bainbridgeb07fdf72019-07-29 22:51:40 +00002136fi
2137
David Bainbridged18f4942020-04-14 16:46:13 -07002138if [ "$(grep -c "^export VOLTCONFIG=" "$NAME-env.sh")" -eq 0 ]; then
2139 echo "export VOLTCONFIG=\"$HOME/.volt/config-$NAME\"" >> "$NAME-env.sh"
David Bainbridgeb07fdf72019-07-29 22:51:40 +00002140fi
2141
David Bainbridged18f4942020-04-14 16:46:13 -07002142if [ "$(grep -c "^export PATH=" "$NAME-env.sh")" -eq 0 ]; then
2143 echo "export PATH=\"$GOPATH/bin:\$PATH\"" >> "$NAME-env.sh"
David Bainbridgeb07fdf72019-07-29 22:51:40 +00002144fi
2145
Test User7d866122019-07-09 17:52:35 +00002146echo ""
David Bainbridged18f4942020-04-14 16:46:13 -07002147echo "Please issue the following commands in your terminal to ensure that you" | tee -a "$LOG"
2148echo "are accessing the correct Kubernetes/Kind cluster as well as have the " | tee -a "$LOG"
2149echo "tools required by VOLTHA in your command path. " | tee -a "$LOG"
2150echo "" | tee -a "$LOG"
2151echo -en "$BOLD"
2152if [ "$DEPLOY_K8S" == "yes" ]; then
2153 echo "export KUBECONFIG=\"\$(./bin/kind get kubeconfig-path --name=\"voltha-$NAME\")\"" | tee -a "$LOG"
Test Userba1e7e72019-07-10 22:27:54 +00002154fi
David Bainbridged18f4942020-04-14 16:46:13 -07002155echo "export VOLTCONFIG=\"$HOME/.volt/config-$NAME\"" | tee -a "$LOG"
2156echo "export PATH=$GOPATH/bin:\$PATH" | tee -a "$LOG"
2157echo -en "$NORMAL"
2158echo "" | tee -a "$LOG"
2159echo "Thank you for choosing kind-voltha for you quick cluster needs." | tee -a "$LOG"
Test User08ebbd92019-07-03 17:15:39 +00002160
David Bainbridge712afb82019-08-14 19:55:58 +00002161if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07002162 NOW="$(date +%s)"
2163 echo -e "$CLOCK ${BOLD}TOTAL: $(duration $((NOW - TOTAL_START_TIME)))${NORMAL}"
David Bainbridge712afb82019-08-14 19:55:58 +00002164fi