blob: 53d95596cf1bfcc5d17ab403eeca54a644878519 [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
Test Userba1e7e72019-07-10 22:27:54 +0000127
David Bainbridged18f4942020-04-14 16:46:13 -0700128HOSTOS="$(uname -s | tr "[:upper:]" "[:lower:"])"
129HOSTARCH="$(uname -m | tr "[:upper:]" "[:lower:"])"
130if [ "$HOSTARCH" == "x86_64" ]; then
Test Userba1e7e72019-07-10 22:27:54 +0000131 HOSTARCH="amd64"
132fi
David Bainbridge7db44002020-04-09 12:54:29 -0700133BBSIM_LABEL="-l app=bbsim"
David Bainbridged18f4942020-04-14 16:46:13 -0700134NO_LABEL=
Test User7d866122019-07-09 17:52:35 +0000135
uottrembb16d3982020-02-28 08:34:36 +0100136# check number (range) of bbsim, max bbsim must not exceed 10 instances!
137# note: instances will be numbered from 0 to 9
138if [ "$1" == "up" ]; then
David K. Bainbridge43422402020-03-06 07:41:22 -0800139 if [ "$NUM_OF_BBSIM" -lt 1 ]; then
Matteo Scandolo67335f02020-04-09 11:19:53 -0700140 >&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 -0800141 exit 1
142 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700143 if [ "$NUM_OF_BBSIM" -gt "$MAX_NUM_OF_BBSIM" ]; then
Matteo Scandolo67335f02020-04-09 11:19:53 -0700144 >&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}"
145 exit 1
146 fi
147
148 if [ "$NUM_OF_OPENONU" -lt 1 ]; then
149 >&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}"
150 exit 1
151 fi
152 if [ "$NUM_OF_OPENONU" -gt "$MAX_NUM_OF_OPENONU" ]; then
153 >&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 -0800154 exit 1
155 fi
uottrembb16d3982020-02-28 08:34:36 +0100156fi
Test User7d866122019-07-09 17:52:35 +0000157# Verify TYPE setting
David Bainbridged18f4942020-04-14 16:46:13 -0700158if [ "$(echo ":minimal:full:" | grep -ic ":$TYPE:")" -eq 0 ]; then
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700159 >&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 +0000160 exit 1
161fi
162
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700163# checks to see if a given WORD is in the given LIST of words
164function is_in() {
165 local WORD LIST
166 WORD="$1"; shift
167 LIST="$*"
168 LIST=${LIST//+([[:space:],|])/:}
169
170 [ "$(echo ":$LIST:" | grep -ic ":$WORD:")" -ne 0 ]
171}
172
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700173function parseDuration() {
David Bainbridged18f4942020-04-14 16:46:13 -0700174 local DUR RESULT TERM TERMS VALUE UNIT
175 DUR=$1
176 RESULT=0
177 TERMS="$(echo "$DUR" | sed -Ee 's/([sSmMhHdD])/\1 /g' -e 's/,$//g')"
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700178 for TERM in $TERMS; do
David Bainbridged18f4942020-04-14 16:46:13 -0700179 VALUE="$(echo "$TERM" | sed -Ee 's/([0-9]+)[sSmMhHdD]/\1/')"
180 UNIT="$(echo "$TERM" | sed -Ee 's/[0-9]+([sSmMhHdD])/\1/')"
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700181 case $UNIT in
182 s|S)
David Bainbridged18f4942020-04-14 16:46:13 -0700183 RESULT=$((RESULT + VALUE)) ;;
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700184 m|M)
David Bainbridged18f4942020-04-14 16:46:13 -0700185 RESULT=$((RESULT + (VALUE * 60))) ;;
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700186 h|H)
David Bainbridged18f4942020-04-14 16:46:13 -0700187 RESULT=$((RESULT + (VALUE * 3600))) ;;
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700188 d|D)
David Bainbridged18f4942020-04-14 16:46:13 -0700189 RESULT=$((RESULT + (VALUE * 86400))) ;;
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700190 *) ;;
191 esac
192 done
193 echo $RESULT
194}
195
196function doTimeout() {
197 local MSG=$1
198 2>&1 echo -e "\n${RED}${BOLD}${ERROR}TIMEOUT:${NORMAL}${RED} Operation timed out after '$WAIT_TIMEOUT': $MSG"
199 exit 125
200}
201
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -0800202function get_service_ep() {
203 local NS=$1
204 local NAME=$2
David Bainbridged18f4942020-04-14 16:46:13 -0700205 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 -0800206}
207
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000208# Used to verify configuration values are set to "yes" or "no" value or convert
209# equivalents to "yes" or "no"
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700210YES="y,yes,t,true,1"
211NO="n,no,f,false,0"
212YES_OR_NO="$YES,$NO"
213
214# If the given VAR matches a truth value then normalize that
215# value, else return original value
216function normalize_yes_no() {
217 local VAR VAL
218 VAR=$1
219 VAL="$(eval echo "\$$VAR")"
220 if ! is_in "$VAL" "$YES_OR_NO"; then
221 echo "$VAL"
222 return 1
223 fi
224 if is_in "$VAL" "$YES"; then
225 echo "yes"
226 else
227 echo "no"
228 fi
229 return 0
230}
231
232# If the given VAR matches a truth value then normalize that
233# value, else display an error
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000234function verify_yes_no() {
David Bainbridged18f4942020-04-14 16:46:13 -0700235 local VAR VAL
236 VAR=$1
237 VAL="$(eval echo "\$$VAR")"
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700238 if ! is_in "$VAL" "$YES_OR_NO"; then
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000239 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} Invalid '$VAR' value of '$VAL'. Should be 'yes' or 'no'${NORMAL}"
240 echo "INVALID"
241 return 1
242 fi
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700243 if is_in "$VAL" "$YES"; then
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000244 echo "yes"
245 else
246 echo "no"
247 fi
248 return 0
249}
Test User7d866122019-07-09 17:52:35 +0000250
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000251ALL_YES_NO="\
David K. Bainbridge484d80c2020-03-05 21:44:34 -0800252 ENABLE_ONOS_EXTRANEOUS_RULES \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000253 WITH_TIMINGS \
254 WITH_BBSIM \
Matteo Scandolo78dfee02020-02-13 16:18:03 -0800255 WITH_EAPOL \
256 WITH_DHCP \
257 WITH_IGMP \
David Bainbridge99ac7a22019-08-31 02:26:43 +0000258 WITH_CHAOS \
David Bainbridge46505fb2019-10-01 21:13:20 +0000259 WITH_ADAPTERS \
260 WITH_SIM_ADAPTERS \
261 WITH_OPEN_ADAPTERS \
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -0800262 WITH_PORT_FORWARDS \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000263 JUST_K8S \
264 DEPLOY_K8S \
265 INSTALL_ONOS_APPS \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000266 INSTALL_KUBECTL \
267 INSTALL_HELM \
David Bainbridge7f8bf992020-04-08 21:53:22 -0700268 HELM_USE_UPGRADE \
David Bainbridge46505fb2019-10-01 21:13:20 +0000269 UPDATE_HELM_REPOS \
David Bainbridge4f1b5562019-08-19 04:46:52 +0000270 WAIT_ON_DOWN \
David Bainbridge70c0ea82019-11-14 23:25:26 +0000271 ONLY_ONE \
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700272 VOLTHA_DOWN_ON_TIMEOUT \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000273 "
David Bainbridge5b7b96b2019-07-25 20:29:13 +0000274
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700275OPT_YES_NO="\
276 CONFIG_SADIS \
277 WITH_KAFKA \
278 WITH_RADIUS \
279 WITH_ETCD \
280 WITH_ONOS \
281 "
282
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000283ALL_OPTIONS="\
284 NAME \
285 TYPE \
286 $ALL_YES_NO \
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700287 $OPT_YES_NO \
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700288 WAIT_TIMEOUT \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000289 VOLTHA_LOG_LEVEL \
290 VOLTHA_CHART \
David Bainbridge90fd8e32019-08-21 23:32:47 +0000291 VOLTHA_CHART_VERSION \
292 VOLTHA_BBSIM_CHART \
293 VOLTHA_BBSIM_CHART_VERSION \
uottrembd5a20572020-03-06 09:15:01 +0100294 NUM_OF_BBSIM \
Matteo Scandolo67335f02020-04-09 11:19:53 -0700295 NUM_OF_OPENONU \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000296 VOLTHA_ADAPTER_SIM_CHART \
David Bainbridge90fd8e32019-08-21 23:32:47 +0000297 VOLTHA_ADAPTER_SIM_CHART_VERSION \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000298 VOLTHA_ADAPTER_OPEN_OLT_CHART \
David Bainbridge90fd8e32019-08-21 23:32:47 +0000299 VOLTHA_ADAPTER_OPEN_OLT_CHART_VERSION \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000300 VOLTHA_ADAPTER_OPEN_ONU_CHART \
David Bainbridge90fd8e32019-08-21 23:32:47 +0000301 VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION \
David K. Bainbridgeda33d652020-03-06 10:31:23 -0800302 ONOS_CHART \
Andrea Campanella21323292019-12-18 11:44:19 -0800303 ONOS_CHART_VERSION \
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700304 ONOS_CLASSIC_CHART \
305 ONOS_CLASSIC_CHART_VERSION \
David Bainbridgecf546362020-04-21 23:18:50 -0700306 KAFKA_CHART \
David Bainbridgeb9093522020-04-15 14:32:44 -0700307 KAFKA_CHART_VERSION \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000308 ONOS_API_PORT \
309 ONOS_SSH_PORT \
Hardik Windlassb3147602020-03-09 16:59:15 +0530310 SADIS_CFG \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000311 VOLTHA_API_PORT \
312 VOLTHA_SSH_PORT \
313 VOLTHA_ETCD_PORT \
David K. Bainbridge00ecd382020-02-28 12:31:58 -0800314 VOLTHA_KAFKA_PORT \
David K. Bainbridge8f7f30b2020-01-08 13:06:16 -0800315 VK_RELEASE \
316 KIND_VERSION \
317 VOLTCTL_VERSION \
David Bainbridgea34993d2020-04-01 09:15:42 -0700318 HELM_VERSION \
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700319 NUM_OF_ONOS \
320 NUM_OF_ATOMIX \
David Bainbridge6ca40102020-04-08 11:30:40 -0700321 VOLTHA_NS \
322 ADAPTER_NS \
323 INFRA_NS \
324 BBSIM_NS \
David Bainbridge7db44002020-04-09 12:54:29 -0700325 SADIS_BANDWIDTH_PROFILES \
326 SADIS_SUBSCRIBERS \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000327 "
David Bainbridge01294952019-07-30 19:33:45 +0000328
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000329# Iterate over yes/no configuration options and validate
330for VAR in $ALL_YES_NO; do
David Bainbridged18f4942020-04-14 16:46:13 -0700331 eval "$VAR"="$(verify_yes_no "$VAR")"
332 if [ "$(eval echo "\$$VAR")" == "INVALID" ]; then
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000333 exit 1;
334 fi
335done
David Bainbridgeb270c202019-07-26 01:44:42 +0000336
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700337# Iterate over optional yes/no configuration options and
338# normalize values if they are truth values
339for VAR in $OPT_YES_NO; do
340 eval "$VAR"="$(normalize_yes_no "$VAR")"
341done
David Bainbridge15f6f232020-03-30 09:15:43 -0700342
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700343# normalize non-truth value options
344if is_in "$WITH_KAFKA" "e,external"; then
David Bainbridge76afd812020-04-06 09:53:52 -0700345 WITH_KAFKA="external"
346fi
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700347if is_in "$WITH_ETCD" "e,external"; then
David Bainbridge76afd812020-04-06 09:53:52 -0700348 WITH_ETCD="external"
349fi
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700350if is_in "$WITH_ONOS" "l,legacy"; then
351 WITH_ONOS="legacy"
352elif is_in "$WITH_ONOS" "c,classic"; then
353 WITH_ONOS="classic"
354elif is_in "$WITH_ONOS" "u,m,micro"; then
355 WITH_ONOS="micro"
David Bainbridge29c31cb2020-04-06 09:45:50 -0700356fi
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700357
358if [ "$WITH_ONOS" == "micro" ]; then
359 >&2 echo -e "${YELLOW}${BOLD}${ERROR}WARNING:${NORMAL}${YELLOW} The value specified as WITH_ONOS, '$WITH_ONOS', is not valid.${NORMAL}"
360 exit 1
David Bainbridge29c31cb2020-04-06 09:45:50 -0700361fi
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700362
363if is_in "$WITH_ONOS" "yes,classic"; then
364 # there is an extra utility required if we are using ONOS CLASSIC as
365 # the chart for classic specifies images differently
366 EXTRA_TOOLS+=" yq"
David Bainbridge76afd812020-04-06 09:53:52 -0700367fi
David Bainbridge696bc632020-04-05 21:49:37 -0700368
David Bainbridged18f4942020-04-14 16:46:13 -0700369if [ "$HELM_USE_UPGRADE" == "yes" ]; then
David Bainbridge7f8bf992020-04-08 21:53:22 -0700370 _HELM_DESC="Upgrade/Install"
371else
372 _HELM_DESC="Install"
373fi
374
David Bainbridged18f4942020-04-14 16:46:13 -0700375ETCD_PREFIX=
376KAFKA_PREFIX=
377if [ "$WITH_ETCD" == "yes" ]; then
378 ETCD_PREFIX="voltha-"
379fi
380if [ "$WITH_KAFKA" == "yes" ]; then
381 KAFKA_PREFIX="voltha-"
382fi
383
David K. Bainbridgeda33d652020-03-06 10:31:23 -0800384# Check for prerequiste tools
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700385TOOLS="curl sed jq $EXTRA_TOOLS"
David Bainbridged18f4942020-04-14 16:46:13 -0700386if [ "$DEPLOY_K8S" == "yes" ]; then
David K. Bainbridgeda33d652020-03-06 10:31:23 -0800387 TOOLS+=" docker"
388fi
389NOT_FOUND=""
390for T in $TOOLS; do
David Bainbridged18f4942020-04-14 16:46:13 -0700391 if [ -z "$(command -v "$T")" ]; then
David K. Bainbridgeda33d652020-03-06 10:31:23 -0800392 NOT_FOUND+=" $T"
393 fi
394done
395
David Bainbridged18f4942020-04-14 16:46:13 -0700396if [ -n "$NOT_FOUND" ]; then
David K. Bainbridgeda33d652020-03-06 10:31:23 -0800397 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} The following required tools where not found, please install them:$NOT_FOUND"
398 exit 1
399fi
400
David Bainbridged18f4942020-04-14 16:46:13 -0700401TIMEOUT_SECONDS="$(parseDuration "$WAIT_TIMEOUT")"
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700402
David Bainbridge0774b232019-08-02 06:37:19 +0000403mkdir -p .voltha
404touch .voltha/ports
David Bainbridged18f4942020-04-14 16:46:13 -0700405HAVE="$(grep "$NAME" .voltha/ports)"
David Bainbridge0774b232019-08-02 06:37:19 +0000406if [ "$HAVE X" == " X" ]; then
407 # Find free port prefix
408 START=81
409 while true; do
David Bainbridged18f4942020-04-14 16:46:13 -0700410 if [ "$(grep -c $START .voltha/ports)" -eq 0 ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000411 break
412 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700413 START="$((START + 1))"
David Bainbridge0774b232019-08-02 06:37:19 +0000414 done
David Bainbridged18f4942020-04-14 16:46:13 -0700415 DELTA="$((START - 81))"
David Bainbridgea2595422019-10-22 03:54:28 +0000416 ONOS_API_PORT=${ONOS_API_PORT:-${START}81}
417 ONOS_SSH_PORT=${ONOS_SSH_PORT:-${START}01}
David Bainbridged18f4942020-04-14 16:46:13 -0700418 VOLTHA_API_PORT=${VOLTHA_API_PORT:-5$((55 + DELTA))55}
419 VOLTHA_SSH_PORT=${VOLTHA_SSH_PORT:-$((50 + DELTA))22}
420 VOLTHA_ETCD_PORT=${VOLTHA_ETCD_PORT:-$((23 + DELTA))79}
421 VOLTHA_KAFKA_PORT=${VOLTHA_KAFKA_PORT:-$((90 + DELTA))92}
Test User01ed0642019-07-03 20:17:06 +0000422else
David Bainbridged18f4942020-04-14 16:46:13 -0700423 VALUES="$(echo "$HAVE" | sed -e 's/\s//g' | cut -d= -f2)"
424 ONOS_API_PORT=${ONOS_API_PORT:-$(echo "$VALUES" | cut -d, -f1)}
425 ONOS_SSH_PORT=${ONOS_SSH_PORT:-$(echo "$VALUES" | cut -d, -f2)}
426 VOLTHA_API_PORT=${VOLTHA_API_PORT:-$(echo "$VALUES" | cut -d, -f3)}
427 VOLTHA_SSH_PORT=${VOLTHA_SSH_PORT:-$(echo "$VALUES" | cut -d, -f4)}
428 VOLTHA_ETCD_PORT=${VOLTHA_ETCD_PORT:-$(echo "$VALUES" | cut -d, -f5)}
429 VOLTHA_KAFKA_PORT=${VOLTHA_KAFKA_PORT:-$(echo "$VALUES" | cut -d, -f6)}
David K. Bainbridge00ecd382020-02-28 12:31:58 -0800430
David K. Bainbridge00ecd382020-02-28 12:31:58 -0800431 # A bit of a hueristic required here as the KAFKA port forward was
432 # added after the .voltha/ports files was created. Basically, if
433 # the VOLTHA_KAFKA_PORT isn't in the file then calculate the original
434 # DELTA from the VOLTHA_SSH_PORT and apply it to the VOLTHA_KAFKA_PORT
435 if [ -z "$VOLTHA_KAFKA_PORT" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -0700436 DELTA="$((VOLTHA_SSH_PORT/100-50))"
437 VOLTHA_KAFKA_PORT=${VOLTHA_KAFKA_PORT:-$((90 + DELTA))92}
David K. Bainbridge00ecd382020-02-28 12:31:58 -0800438 fi
Test User01ed0642019-07-03 20:17:06 +0000439fi
440
David Bainbridged18f4942020-04-14 16:46:13 -0700441PORTTMP="$(mktemp -u)"
442grep -v "$NAME" .voltha/ports > "$PORTTMP"
443echo "$NAME=$ONOS_API_PORT,$ONOS_SSH_PORT,$VOLTHA_API_PORT,$VOLTHA_SSH_PORT,$VOLTHA_ETCD_PORT,$VOLTHA_KAFKA_PORT" >> "$PORTTMP"
444cp "$PORTTMP" .voltha/ports
445rm -f "$PORTTMP"
David Bainbridge0774b232019-08-02 06:37:19 +0000446
David Bainbridge27790d62019-08-13 22:43:19 +0000447export ONOS_API_PORT ONOS_SSH_PORT
David Bainbridge01294952019-07-30 19:33:45 +0000448
Test Userd87942b2019-07-03 07:20:24 +0000449IDX=1
David Bainbridgee87067b2019-08-12 22:00:12 +0000450CLOCK="TIME:"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000451SPIN_PARTS=
452NOT_VERIFIED=
David Bainbridgef858a022019-08-14 21:25:11 +0000453THEX=
454BUILD=
David Bainbridge38dc1e82019-08-12 15:18:45 +0000455VERIFIED=
456HELM=
457OLD_KEY=
458BIRD=
459HIGH_VOLTAGE=
460PLUG=
David Bainbridge38dc1e82019-08-12 15:18:45 +0000461FORWARD=
David Bainbridge38dc1e82019-08-12 15:18:45 +0000462GO=
463DOWNLOAD=
464GEAR=
465NO_ENTRY=
466LOCK=
467
David Bainbridged18f4942020-04-14 16:46:13 -0700468if [ "$FANCY" -eq 1 ]; then
469 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 +0000470 CLOCK="\xe2\x8f\xb1"
David Bainbridgef858a022019-08-14 21:25:11 +0000471 THEX="${RED}${BOLD}\xe2\x9c\x97\x20${NORMAL}"
David Bainbridgef858a022019-08-14 21:25:11 +0000472 BUILD="${YELLOW}${BOLD}\xf0\x9f\x8f\x97${NORMAL}"
473 NOT_VERIFIED="$BUILD"
474 VERIFIED="${GREEN}${BOLD}\xe2\x9c\x93\x20${NORMAL}"
475 HELM="${BLUE}${BOLD}\xE2\x8E\x88${NORMAL}"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000476 OLD_KEY="\xF0\x9F\x97\x9D"
477 BIRD="\xF0\x9F\x90\xA6"
478 HIGH_VOLTAGE="\xE2\x9A\xA1"
479 PLUG="\xF0\x9F\xa7\xa9"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000480 FORWARD="\xE2\x87\xA8"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000481 GO="\xf0\x9f\x9a\x80"
482 DOWNLOAD="\xf0\x9f\x93\xa5"
483 GEAR="\xe2\x9a\x99"
484 NO_ENTRY="\xe2\x9b\x94"
485 LOCK="\xf0\x9f\x94\x92"
486fi
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700487
David Bainbridge712afb82019-08-14 19:55:58 +0000488duration() {
David Bainbridged18f4942020-04-14 16:46:13 -0700489 local h m s t
490 h="$(($1 / 3600))"
491 m="$(($1 % 3600 / 60))"
492 s="$(($1 % 60))"
493 t=""
David Bainbridgee87067b2019-08-12 22:00:12 +0000494
David Bainbridged18f4942020-04-14 16:46:13 -0700495 if [ "$h" -gt 0 ]; then
David Bainbridgee87067b2019-08-12 22:00:12 +0000496 t="$t${h}h"
497 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700498 if [ "$m" -gt 0 ]; then
David Bainbridgee87067b2019-08-12 22:00:12 +0000499 t="$t${m}m"
500 fi
David Bainbridge712afb82019-08-14 19:55:58 +0000501 echo "$t${s}s"
502}
503
504printtime() {
David Bainbridged18f4942020-04-14 16:46:13 -0700505 local INDENT
David Bainbridge712afb82019-08-14 19:55:58 +0000506 if [ "$1" == "-" ]; then
507 INDENT=" "
508 shift
509 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700510 echo -e "$INDENT $CLOCK $(duration "$1")"
David Bainbridgee87067b2019-08-12 22:00:12 +0000511}
512
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700513bspin() {
Test Userd87942b2019-07-03 07:20:24 +0000514 IDX=1
David Bainbridged18f4942020-04-14 16:46:13 -0700515 local INDENT
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700516 if [ "$1" == "-" ]; then
517 INDENT=" "
518 shift
519 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700520 if [ "$FANCY" -eq 0 ]; then
521 LINE="${*//[[:space:]+-]}"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000522 if [ "$LINE X" == " X" ]; then
523 return
524 fi
525 echo -e "$CIVIS$INDENT$*"
526 else
527 echo -en "$CIVIS$INDENT $*"
528 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700529}
530
531sspin() {
David Bainbridged18f4942020-04-14 16:46:13 -0700532 local INDENT
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700533 if [ "$1" == "-" ]; then
534 INDENT=" "
535 shift
536 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700537 if [ "$FANCY" -eq 0 ]; then
538 LINE="${*//[[:space:]+-]}"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000539 if [ "$LINE X" == " X" ]; then
540 return
541 fi
542 echo -e "$INDENT$*"
543 else
David Bainbridged18f4942020-04-14 16:46:13 -0700544 C="$(echo "$SPIN_PARTS" | cut '-d ' -f "$IDX")"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000545 echo -en "\r$INDENT$C $*"
David Bainbridged18f4942020-04-14 16:46:13 -0700546 IDX="$((IDX + 1))"
547 if [ "$IDX" -gt 8 ]; then
David Bainbridge38dc1e82019-08-12 15:18:45 +0000548 IDX=1
549 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700550 fi
551}
552
553espin() {
David Bainbridged18f4942020-04-14 16:46:13 -0700554 local INDENT
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700555 if [ "$1" == "-" ]; then
556 INDENT=" "
557 shift
558 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700559 if [ "$FANCY" -eq 0 ]; then
560 LINE="${*//[[:space:]+-]}"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000561 if [ "$LINE X" == " X" ]; then
562 return
563 fi
564 echo -e "$INDENT$*"
565 else
566 echo -e "\r$INDENT$*$CNORM"
567 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700568}
569
David Bainbridged18f4942020-04-14 16:46:13 -0700570if [ "$1" == "get" ] && [ "$2" == "voltconfig" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000571 echo "$HOME/.volt/config-$NAME"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000572 exit
573fi
574
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700575if [ $# -ne 1 ] || ! is_in "$1" "up,down,dump"; then
David Bainbridgeac7f8072019-08-01 22:15:33 +0000576 >&2 echo "What wouild you like to do today:"
577 >&2 echo " up - bring up voltha"
578 >&2 echo " down - tear down voltha"
579 >&2 echo " dump - create a debug dump of running system"
580 exit 1
581fi
582
David Bainbridge4f1b5562019-08-19 04:46:52 +0000583push_onos_config() {
David Bainbridged18f4942020-04-14 16:46:13 -0700584 local TYPE MSG RESOURCE DATA CMD_ECHO CMD_OUTPUT SC_OUTPUT WAIT_START NOW
585 TYPE=$1
586 MSG=$2
587 RESOURCE=$3
588 DATA=$4
David Bainbridge4f1b5562019-08-19 04:46:52 +0000589
David K. Bainbridgeb4b163b2020-02-19 15:55:06 -0800590 # Thanks to the latest version of ONOS using the return code 207 this gets a
591 # whole lot nastier. Can't thank them enough for doing this. So in order to
592 # capture the command and the output in the log file as well as capture the
593 # status code to verify it is 200 and not 207 mutltiple files and a bit of
594 # hackery must be used. Thanks again ONOS.
David Bainbridged18f4942020-04-14 16:46:13 -0700595 CMD_ECHO="$(mktemp -u)"
596 CMD_OUTPUT="$(mktemp -u)"
597 SC_OUTPUT="$(mktemp -u)"
598 WAIT_START="$(date +%s)"
David K. Bainbridgeb4b163b2020-02-19 15:55:06 -0800599
David Bainbridge4f1b5562019-08-19 04:46:52 +0000600 bspin - "$MSG $GEAR"
601 while true; do
David Bainbridged18f4942020-04-14 16:46:13 -0700602 NOW="$(date +%s)"
603 if [ "$((NOW - WAIT_START))" -gt "$TIMEOUT_SECONDS" ]; then
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700604 espin - "$THEX"
David Bainbridged18f4942020-04-14 16:46:13 -0700605 rm -f "$CMD_ECHO" "$CMD_OUTPUT" "$SC_OUTPUT"
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700606 doTimeout "waiting for ONOS config push on $RESOURCE"
607 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700608 if [ "$TYPE" == "file" ]; then
609 (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 -0700610 RESULT=$?
Matteo Scandolo78dfee02020-02-13 16:18:03 -0800611 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700612 if [ "$TYPE" == "json" ]; then
613 (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 -0700614 RESULT=$?
Matteo Scandolo78dfee02020-02-13 16:18:03 -0800615 fi
David K. Bainbridgeb4b163b2020-02-19 15:55:06 -0800616 # Dump everything to the log
David Bainbridged18f4942020-04-14 16:46:13 -0700617 cat "$CMD_ECHO" >> "$LOG"
618 test -r "$CMD_OUTPUT" && cat "$CMD_OUTPUT" >> "$LOG"
619 SC="$(cat "$SC_OUTPUT")"
620 echo "RESPONSE CODE: $SC" >> "$LOG"
621 echo "ERROR CODE: $RESULT" >> "$LOG"
David K. Bainbridgeb4b163b2020-02-19 15:55:06 -0800622
623 # clean up temp files
David Bainbridged18f4942020-04-14 16:46:13 -0700624 rm -f "$CMD_ECHO" "$CMD_OUTPUT" "$SC_OUTPUT"
625 if [ "$RESULT" -eq 0 ] && [ "$SC" == "200" ]; then
David Bainbridge4f1b5562019-08-19 04:46:52 +0000626 break
627 fi
Matteo Scandolo9a77a732020-01-09 14:24:12 -0800628 sleep 1
David Bainbridge4f1b5562019-08-19 04:46:52 +0000629 sspin -
630 done
David Bainbridged18f4942020-04-14 16:46:13 -0700631 espin - "$VERIFIED"
David Bainbridge4f1b5562019-08-19 04:46:52 +0000632}
633
Matteo Scandolo9a77a732020-01-09 14:24:12 -0800634check_onos_app_active() {
David Bainbridged18f4942020-04-14 16:46:13 -0700635 local APP_ID WAIT_START RESULT NOW
636 APP_ID=$1
637 WAIT_START="$(date +%s)"
Matteo Scandolo9a77a732020-01-09 14:24:12 -0800638
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700639 bspin - "Checking that $APP_ID is active $CLOCK"
640 while true; do
David Bainbridged18f4942020-04-14 16:46:13 -0700641 NOW="$(date +%s)"
642 if [ "$((NOW - WAIT_START))" -gt "$TIMEOUT_SECONDS" ]; then
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700643 espin - "$THEX"
644 doTimeout "waiting for ONOS application activation '$APP_ID'"
645 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700646 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 -0700647 break
648 fi
649 sleep 1
650 sspin -
651 done
652 sleep 5 # OSGI components take a little longer that the app to activate
David Bainbridged18f4942020-04-14 16:46:13 -0700653 espin - "$VERIFIED"
Matteo Scandolo9a77a732020-01-09 14:24:12 -0800654}
655
David Bainbridge4f1b5562019-08-19 04:46:52 +0000656override_onos_app() {
David Bainbridged18f4942020-04-14 16:46:13 -0700657 local APP NAME WAIT_START NOW
658 APP=$1
659 NAME="$(basename "$APP" | sed -e 's/^[0-9][0-9]*-//g' -e 's/-.*$//g')"
660 WAIT_START="$(date +%s)"
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700661
David Bainbridge4f1b5562019-08-19 04:46:52 +0000662 while true; do
David Bainbridged18f4942020-04-14 16:46:13 -0700663 NOW="$(date +%s)"
664 if [ "$((NOW - WAIT_START))" -gt "$TIMEOUT_SECONDS" ]; then
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700665 espin - "$THEX"
666 doTimeout "waiting to overwrite ONOS application '$APP'"
667 fi
David Bainbridge4f1b5562019-08-19 04:46:52 +0000668 sspin -
669 # Attempt to delete old version (if it exists)
David Bainbridged18f4942020-04-14 16:46:13 -0700670 (set -x; curl --fail -sSL --user karaf:karaf -X DELETE "http://$_ONOS_API_EP/onos/v1/applications/$NAME" >>"$LOG" 2>&1) >>"$LOG" 2>&1
671 RESULT=$?
David Bainbridge4f1b5562019-08-19 04:46:52 +0000672 sspin -
David Bainbridged18f4942020-04-14 16:46:13 -0700673 if [ $RESULT -ne 0 ]; then
David Bainbridge4f1b5562019-08-19 04:46:52 +0000674 continue
675 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700676 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 +0000677 break
678 fi
679 sleep .2
680 done
681}
682
683activate_onos_app() {
David Bainbridged18f4942020-04-14 16:46:13 -0700684 local MSG APP WAIT_START NOW
685 MSG="$1"
686 APP=$2
687 WAIT_START="$(date +%s)"
David Bainbridge4f1b5562019-08-19 04:46:52 +0000688
689 bspin - "$MSG $GO"
690 while true; do
David Bainbridged18f4942020-04-14 16:46:13 -0700691 NOW="$(date +%s)"
692 if [ "$((NOW - WAIT_START))" -gt "$TIMEOUT_SECONDS" ]; then
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700693 espin - "$THEX"
694 doTimeout "waiting to activate ONOS application '$APP'"
695 fi
David Bainbridge4f1b5562019-08-19 04:46:52 +0000696 sspin -
David Bainbridged18f4942020-04-14 16:46:13 -0700697 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 +0000698 break
699 fi
700 sleep .2
701 done
702 espin - "$VERIFIED"
703}
704
705count_pods() {
David Bainbridged18f4942020-04-14 16:46:13 -0700706 local NAMESPACE STATES LABELS CMD PODS
707 NAMESPACE=$1; shift
David Bainbridge4f1b5562019-08-19 04:46:52 +0000708 if [ "$NAMESPACE" == "all-namespaces" ]; then
709 NAMESPACE="--all-namespaces"
710 else
711 NAMESPACE="-n $NAMESPACE"
712 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700713 STATES=$1; shift
714 LABELS=$1; shift
715 CMD=("kubectl get $NAMESPACE $LABELS pod")
716 PODS=$(${CMD[*]} -o go-template="{{range .items}}{{.metadata.name}}/{{.status.phase}}/_{{range .status.containerStatuses}}{{.ready}}_{{end}} {{end}}")
David Bainbridge4f1b5562019-08-19 04:46:52 +0000717 local COUNT=0
718 local PATTERNS="$*"
719 for POD in $PODS; do
David Bainbridged18f4942020-04-14 16:46:13 -0700720 local NAME STATE CONTAINERS TOTAL FOUND
721 NAME="$(echo "$POD" | cut -d/ -f 1)"
722 STATE="$(echo "$POD" | cut -d/ -f 2)"
723 CONTAINERS="$(echo "$POD" | cut -d/ -f 3 | sed -e 's/_/ /g')"
724 if [ "$STATES" == "*" ] || [ "$(echo "$STATES" | grep -c ":$STATE:")" -ne 0 ]; then
725 TOTAL="$(echo "$CONTAINERS" | wc -w)"
726 FOUND="$(echo "$CONTAINERS" | grep -o true | wc -l)"
727 if [ "$TOTAL" -eq "$FOUND" ]; then
David Bainbridge4f1b5562019-08-19 04:46:52 +0000728 for PATTERN in $PATTERNS; do
David Bainbridged18f4942020-04-14 16:46:13 -0700729 if [[ "$NAME" =~ $PATTERN ]]; then
730 COUNT="$((COUNT + 1))"
David Bainbridge4f1b5562019-08-19 04:46:52 +0000731 break
732 fi
733 done
734 fi
735 fi
736 done
David Bainbridge4f1b5562019-08-19 04:46:52 +0000737 echo $COUNT
738}
739
740wait_for_pods() {
David Bainbridged18f4942020-04-14 16:46:13 -0700741 local INDENT NAMESPACE EXPECT TYPE MESSAGE LABELS PATTERNS STATES HAVE ALL WAIT_START NOW
David Bainbridge4f1b5562019-08-19 04:46:52 +0000742 if [ "$1" == "-" ]; then
743 INDENT=$1; shift
744 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700745 NAMESPACE=$1; shift
746 EXPECT=$1; shift
747 TYPE=$1; shift
748 MESSAGE=$1; shift
749 LABELS=$1; shift
750 PATTERNS=("$*")
751 STATES=":Running:"
David Bainbridge99ac7a22019-08-31 02:26:43 +0000752 if [ "$TYPE" == "not" ]; then
753 STATES="*"
754 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700755 HAVE="$(count_pods "$NAMESPACE" "$STATES" "$LABELS" "${PATTERNS[@]}")"
756 ALL=$HAVE
David Bainbridge4f1b5562019-08-19 04:46:52 +0000757 if [ "$TYPE" == "only" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -0700758 ALL="$(count_pods "all-namespaces" "*" ".*")"
David Bainbridge4f1b5562019-08-19 04:46:52 +0000759 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700760 COUNT="$((300 / 15))"
761 WAIT_START="$(date +%s)"
762 bspin "$INDENT" "$MESSAGE"
763 sspin "$INDENT"
764 if [ "$HAVE" -ne "$EXPECT" ] || [ "$ALL" -ne "$HAVE" ]; then
765 while [ "$HAVE" -ne "$EXPECT" ] || [ "$ALL" -ne "$HAVE" ]; do
766 NOW="$(date +%s)"
767 if [ "$((NOW - WAIT_START))" -gt "$TIMEOUT_SECONDS" ]; then
768 espin "$INDENT" "$THEX"
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700769 doTimeout "waiting for PODs to start"
770 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700771 sspin "$INDENT"
772 COUNT="$((COUNT - 1))"
773 if [ "$COUNT" -eq 0 ]; then
774 HAVE="$(count_pods "$NAMESPACE" "$STATES" "$LABELS" "${PATTERNS[@]}")"
775 ALL="$HAVE"
David Bainbridge4f1b5562019-08-19 04:46:52 +0000776 if [ "$TYPE" == "only" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -0700777 ALL="$(count_pods "all-namespaces" "*" ".*")"
David Bainbridge4f1b5562019-08-19 04:46:52 +0000778 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700779 COUNT="$((300 / 15))"
David Bainbridge4f1b5562019-08-19 04:46:52 +0000780 fi
781 sleep .15
782 done
783 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700784 espin "$INDENT" "$VERIFIED"
785 if [ "$HAVE" -ne "$EXPECT" ]; then
David Bainbridge4f1b5562019-08-19 04:46:52 +0000786 return 1
787 fi
788 return 0
789}
790
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800791port_forward() {
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700792 local NS=$1; shift
793 local SVC=$1; shift
794 local PORTS="$*"
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800795 local TAG=$SVC-$NAME
796
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700797 (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 -0800798}
799
800kill_port_forward() {
David Bainbridged18f4942020-04-14 16:46:13 -0700801 local TAG P_IDS PARENTS KIDS UNKNOWN PP_ID
802 TAG="$1-$NAME"
803 # shellcheck disable=SC2009
804 P_IDS="$(ps e -ww -A | grep "_TAG=$TAG" | grep -v grep | awk '{print $1}')"
805 if [ -n "$P_IDS" ]; then
David Bainbridgec6871d22019-11-13 17:10:31 +0000806 for P_ID in $P_IDS; do
David Bainbridged18f4942020-04-14 16:46:13 -0700807 PP_ID="$(ps -o ppid "$P_ID" | tail -n +2)"
808 if [ -n "$PP_ID" ]; then
809 if [ "$PP_ID" -eq 1 ]; then
David Bainbridgec6871d22019-11-13 17:10:31 +0000810 PARENTS="$PARENTS $P_ID"
811 else
812 KIDS="$KIDS $P_ID"
813 fi
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800814 else
David Bainbridgec6871d22019-11-13 17:10:31 +0000815 UNKNOWN="$UNKNOWN $P_ID"
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800816 fi
817 done
David Bainbridged18f4942020-04-14 16:46:13 -0700818 (set -x; kill -9 "$PARENTS" "$KIDS" "$UNKNOWN" >>"$LOG" 2>&1) >>"$LOG" 2>&1
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800819 fi
820}
821
David Bainbridgecf546362020-04-21 23:18:50 -0700822resolve_chart_version() {
823 [ "$2" != "latest" ] && echo "$2" && return
824 helm inspect chart "$1" | grep "^version:" | awk '{print $2}'
825}
826
Jonathan Hart6a91e6c2020-04-16 14:28:33 -0700827# Compares two semver-formatted version strings (e.g. 2.4.3)
828# Returns 0 if $1 == $2, returns 1 if $1 > $2 and returns 2 if $1 < $2
829compare_versions() {
830 [ "$1" == "$2" ] && return 0
Jonathan Hart6a91e6c2020-04-16 14:28:33 -0700831 local lowest
832 lowest=$(echo -e "$1\n$2" | sort -V | head -1)
833 [ "$lowest" == "$1" ] && return 2
834 return 1
835}
836
David Bainbridgeac7f8072019-08-01 22:15:33 +0000837if [ "$1" == "down" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000838 echo "Tearing down voltha cluster $NAME"
839 LOG="down-$NAME.log"
David Bainbridged18f4942020-04-14 16:46:13 -0700840 date -u +"%Y%m%dT%H%M%SZ" >"$LOG"
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700841 if is_in "$WITH_ONOS" "yes,legacy,classic"; then
David Bainbridge696bc632020-04-05 21:49:37 -0700842 bspin "Remove port-forwards: onos-ui-$NAME"
843 kill_port_forward onos-ui
844 sspin "Remove port-forwards: onos-ssh-$NAME$CEOL"
845 kill_port_forward onos-ssh
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700846 bspin "Remove port-forwards: onos-onos-classic-hs-$NAME$CEOL"
847 kill_port_forward onos-onos-classic-hs
David Bainbridge696bc632020-04-05 21:49:37 -0700848 fi
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800849 sspin "Remove port-forwards: voltha-api-$NAME$CEOL"
850 kill_port_forward voltha-api
David Bainbridged18f4942020-04-14 16:46:13 -0700851 if [ "$WITH_ETCD" == "yes" ] || [ "$WITH_ETCD" == "external" ]; then
852 sspin "Remove port-forwards: ${ETCD_PREFIX}etcd-$NAME$CEOL"
853 kill_port_forward "${ETCD_PREFIX}etcd-cluster-client"
David Bainbridge696bc632020-04-05 21:49:37 -0700854 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700855 if [ "$WITH_KAFKA" == "yes" ] || [ "$WITH_KAFKA" == "external" ]; then
856 sspin "Remove port-forwards: ${KAFKA_PREFIX}kafka-$NAME$CEOL"
857 kill_port_forward "${KAFKA_PREFIX}kafka"
David Bainbridge696bc632020-04-05 21:49:37 -0700858 fi
859
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800860 espin "$VERIFIED Remove port-forwards$CEOL"
David Bainbridged18f4942020-04-14 16:46:13 -0700861 if [ "$DEPLOY_K8S" == "yes" ]; then
David Bainbridgeac7f8072019-08-01 22:15:33 +0000862 if [ -x ./bin/kind ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000863 bspin "Delete Kubernetes Kind Cluster"
David Bainbridged18f4942020-04-14 16:46:13 -0700864 (set -x; ./bin/kind delete cluster --name "voltha-$NAME" >>"$LOG" 2>&1) >>"$LOG" 2>&1
865 espin "$VERIFIED"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000866 else
David Bainbridge0774b232019-08-02 06:37:19 +0000867 espin "$NO_ENTRY Delete Kubernetes Kind Cluster: kind command not found"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000868 fi
869 else
David Bainbridged18f4942020-04-14 16:46:13 -0700870 EXISTS="$(helm list -q)"
David Bainbridge76afd812020-04-06 09:53:52 -0700871 EXPECT="voltha"
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700872 if is_in "$WITH_ONOS" "yes,legacy,classic"; then
David Bainbridge696bc632020-04-05 21:49:37 -0700873 EXPECT+=" onos"
874 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700875 if [ "$WITH_RADIUS" == "yes" ]; then
David Bainbridge696bc632020-04-05 21:49:37 -0700876 EXPECT+=" radius"
877 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700878 if [ "$WITH_BBSIM" == "yes" ]; then
David Bainbridge696bc632020-04-05 21:49:37 -0700879 EXPECT+=" bbsim"
880 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700881 if [ "$WITH_OPEN_ADAPTERS" == "yes" ]; then
David Bainbridge696bc632020-04-05 21:49:37 -0700882 EXPECT+=" open-olt open-onu"
883 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700884 if [ "$WITH_SIM_ADAPTERS" == "yes" ]; then
David Bainbridge696bc632020-04-05 21:49:37 -0700885 EXPECT+=" sim"
886 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700887 if [ "$WITH_ETCD" == "external" ]; then
David Bainbridge76afd812020-04-06 09:53:52 -0700888 EXPECT+=" etcd-operator etcd-cluster"
David Bainbridged18f4942020-04-14 16:46:13 -0700889 elif [ "$WITH_ETCD" == "yes" ]; then
David Bainbridge76afd812020-04-06 09:53:52 -0700890 EXPECT+=" etcd-operator"
891 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700892 if [ "$WITH_KAFKA" == "external" ]; then
David Bainbridge76afd812020-04-06 09:53:52 -0700893 EXPECT+=" kafka"
894 fi
David Bainbridge0774b232019-08-02 06:37:19 +0000895 bspin "Remove Helm Deployments"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000896 for i in $EXISTS; do
David K. Bainbridge43422402020-03-06 07:41:22 -0800897 for j in $EXPECT; do
David Bainbridged18f4942020-04-14 16:46:13 -0700898 if [[ "$i" =~ $j ]]; then
David K. Bainbridge43422402020-03-06 07:41:22 -0800899 sspin "Remove Helm Deployments: $i$CEOL"
David Bainbridged18f4942020-04-14 16:46:13 -0700900 (set -x; ./bin/helm delete --no-hooks --purge "$i" >>"$LOG" 2>&1) >>"$LOG" 2>&1
David K. Bainbridge43422402020-03-06 07:41:22 -0800901 fi
902 done
uottrembb16d3982020-02-28 08:34:36 +0100903 done
David Bainbridge0774b232019-08-02 06:37:19 +0000904 espin "$VERIFIED Remove Helm Deployments$CEOL"
David Bainbridge4f1b5562019-08-19 04:46:52 +0000905 if [ "$WAIT_ON_DOWN" == "yes" ]; then
David Bainbridge76afd812020-04-06 09:53:52 -0700906 PODS="voltha-kafka.* voltha-ofagent.* voltha-rw-core.* voltha-etcd.*"
907 INFRA_PODS=
908 ADAPT_PODS=
909 SIM_PODS=
David Bainbridged18f4942020-04-14 16:46:13 -0700910 if [ "$WITH_RADIUS" == "yes" ]; then
David Bainbridge696bc632020-04-05 21:49:37 -0700911 PODS+=" radius.*"
912 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700913 if [ "$WITH_BBSIM" == "yes" ]; then
David Bainbridge76afd812020-04-06 09:53:52 -0700914 SIM_PODS+=" bbsim.*"
David Bainbridge696bc632020-04-05 21:49:37 -0700915 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700916 if [ "$WITH_OPEN_ADAPTERS" ] || [ "$WITH_SIM_ADAPTERS" ]; then
David Bainbridge76afd812020-04-06 09:53:52 -0700917 ADAPT_PODS+=" adapter-*"
David Bainbridge696bc632020-04-05 21:49:37 -0700918 fi
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700919 if is_in "$WITH_ONOS" "yes,legacy,classic"; then
David Bainbridge76afd812020-04-06 09:53:52 -0700920 INFRA_PODS+=" onos-.*"
921 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700922 if [ "$WITH_ETCD" == "external" ]; then
David Bainbridge76afd812020-04-06 09:53:52 -0700923 INFRA_PODS+=" etcd-operator.* etcd-cluster.*"
David Bainbridged18f4942020-04-14 16:46:13 -0700924 elif [ "$WITH_ETCD" == "yes" ]; then
David Bainbridge76afd812020-04-06 09:53:52 -0700925 PODS+=" etcd-operator.*"
926 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700927 if [ "$WITH_KAFKA" == "external" ]; then
David Bainbridge76afd812020-04-06 09:53:52 -0700928 INFRA_PODS+=" kafka.*"
929 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700930 if [ -n "$SIM_PODS" ]; then
931 wait_for_pods "$BBSIM_NS" 0 "not" "Waiting for BBSIM PODs to terminate" "$BBSIM_LABEL" "$SIM_PODS"
David Bainbridge76afd812020-04-06 09:53:52 -0700932 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700933 if [ -n "$INFRA_PODS" ]; then
934 wait_for_pods "$INFRA_NS" 0 "not" "Waiting for infrastructure PODs to terminate" "$NO_LABEL" "$INFRA_PODS"
David Bainbridge76afd812020-04-06 09:53:52 -0700935 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700936 if [ -n "$ADAPT_PODS" ]; then
937 wait_for_pods "$ADAPTER_NS" 0 "not" "Waiting for adapter PODs to terminate" "$NO_LABEL" "$ADAPT_PODS"
David Bainbridge76afd812020-04-06 09:53:52 -0700938 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700939 wait_for_pods "$VOLTHA_NS" 0 "not" "Waiting for VOLTHA PODs to terminate" "$NO_LABEL" "$PODS"
David Bainbridge4f1b5562019-08-19 04:46:52 +0000940 fi
David Bainbridgeac7f8072019-08-01 22:15:33 +0000941 fi
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -0700942 exit
David Bainbridgeac7f8072019-08-01 22:15:33 +0000943fi
944
945if [ "$1" == "dump" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000946 LOG="dump-$NAME.log"
David Bainbridged18f4942020-04-14 16:46:13 -0700947 TS="$(date -u +"%Y%m%dT%H%M%SZ")"
948 if [ -n "$DUMP_FROM" ]; then
949 TS=${DUMP_FROM//[:-]}
David Bainbridge76514a02019-10-08 01:50:35 +0000950 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700951 WORK="$(mktemp -u -d)"
David Bainbridge0774b232019-08-02 06:37:19 +0000952 DATA=$WORK/voltha-debug-dump-$NAME-$TS
David Bainbridged18f4942020-04-14 16:46:13 -0700953 mkdir -p "$DATA"
954 echo "$TS" > "$LOG"
David Bainbridge0774b232019-08-02 06:37:19 +0000955 echo -e "Capturing debug dump to voltha-debug-dump-$NAME-$TS.tgz"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000956 bspin - "Copy install log"
David Bainbridged18f4942020-04-14 16:46:13 -0700957 if [ -f "install-$NAME.log" ]; then
958 (set -x; cp "install-$NAME.log" "$DATA/install-$NAME.log") >>"$LOG" 2>&1
959 espin - "$VERIFIED"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000960 else
David Bainbridge0774b232019-08-02 06:37:19 +0000961 espin - "$NO_ENTRY Copy install log: install-$NAME.log not found"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000962 fi
963 bspin - "Dumping Kubernetes PODs"
David Bainbridged18f4942020-04-14 16:46:13 -0700964 (set -x; kubectl get --all-namespaces pods >> "$DATA/all-pods.txt" 2>&1) >>"$LOG" 2>&1
965 espin - "$VERIFIED"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000966 bspin - "Dumping Kubernetes SERVICEs"
David Bainbridged18f4942020-04-14 16:46:13 -0700967 (set -x; kubectl get --all-namespaces svc >> "$DATA/all-services.txt" 2>&1) >>"$LOG" 2>&1
968 espin - "$VERIFIED"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000969 bspin - "Dumping Kubernetes EVENTs"
David Bainbridged18f4942020-04-14 16:46:13 -0700970 (set -x; kubectl get --all-namespaces events >> "$DATA/all-events.txt" 2>&1) >>"$LOG" 2>&1
971 espin - "$VERIFIED"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000972 bspin - "Dumping VOLTHA POD details"
David Bainbridged18f4942020-04-14 16:46:13 -0700973 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 +0000974 SINCE=
David Bainbridged18f4942020-04-14 16:46:13 -0700975 if [ -n "$DUMP_FROM" ]; then
David Bainbridgecfd7ca12019-10-06 03:31:41 +0000976 SINCE="--since-time=$DUMP_FROM"
977 fi
David Bainbridgeac7f8072019-08-01 22:15:33 +0000978 for POD in $PODS; do
David Bainbridged18f4942020-04-14 16:46:13 -0700979 NS="$(echo "$POD" | cut -d: -f1)"
980 POD="$(echo "$POD" | cut -d: -f2)"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000981 sspin - "Dumping VOLTHA POD details: $POD$CEOL"
David Bainbridged18f4942020-04-14 16:46:13 -0700982 mkdir -p "$DATA/$POD"
983 (set -x; kubectl describe -n "$NS" "$POD" >> "$DATA/$POD/describe.txt" 2>&1) >>"$LOG" 2>&1
David Bainbridgeac7f8072019-08-01 22:15:33 +0000984 sspin - "Dumping VOLTHA POD details: $POD"
David Bainbridged18f4942020-04-14 16:46:13 -0700985 (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 +0000986 sspin - "Dumping VOLTHA POD details: $POD"
David Bainbridged18f4942020-04-14 16:46:13 -0700987 (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 +0000988 sspin - "Dumping VOLTHA POD details: $POD"
989 done
990 espin - "$VERIFIED Dumping VOLTHA POD details$CEOL"
991 bspin - "Dumping ETCD"
David Bainbridged18f4942020-04-14 16:46:13 -0700992 if [ -n "$(command -v etcdctl)" ]; then
993 (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
994 espin - "$VERIFIED"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000995 else
996 espin - "$NO_ENTRY Dumping ETCD: etcdctl command not available"
997 fi
David Bainbridge0774b232019-08-02 06:37:19 +0000998 bspin - "Creating compressed TAR: voltha-debug-dump-$NAME-$TS.tgz"
David Bainbridged18f4942020-04-14 16:46:13 -0700999 (set -x; tar -C "$WORK" -zcf "voltha-debug-dump-$NAME-$TS.tgz" "./voltha-debug-dump-$NAME-$TS") >>"$LOG" 2>&1
1000 espin - "$VERIFIED"
David Bainbridgeac7f8072019-08-01 22:15:33 +00001001 bspin - "Cleanup"
David Bainbridged18f4942020-04-14 16:46:13 -07001002 (set -x; rm -rf "$WORK") >>"$LOG" 2>&1
1003 espin - "$VERIFIED"
1004 bspin - "$(ls -l "voltha-debug-dump-$NAME-$TS.tgz")"
1005 espin - "$VERIFIED"
David Bainbridgeac7f8072019-08-01 22:15:33 +00001006 exit
1007fi
1008
David Bainbridge0774b232019-08-02 06:37:19 +00001009LOG="install-$NAME.log"
David Bainbridged18f4942020-04-14 16:46:13 -07001010date > "$LOG"
1011echo "PORTS=$ONOS_API_PORT,$ONOS_SSH_PORT,$VOLTHA_API_PORT,$VOLTHA_SSH_PORT,$VOLTHA_ETCD_PORT" >> "$LOG"
David Bainbridgeac7f8072019-08-01 22:15:33 +00001012
1013# Output install options to log
David Bainbridged18f4942020-04-14 16:46:13 -07001014echo "OPTIONS" >> "$LOG"
David Bainbridgeac7f8072019-08-01 22:15:33 +00001015for O in $ALL_OPTIONS; do
David Bainbridged18f4942020-04-14 16:46:13 -07001016 VAL="$(eval echo "\$$O")"
1017 if [ -n "$VAL" ]; then
1018 printf " %-30s = %s\n" "$O" "$VAL" >> "$LOG"
David Bainbridgeac7f8072019-08-01 22:15:33 +00001019 fi
1020done
1021
David Bainbridgefad50732020-05-01 17:00:12 -07001022helm_values() {
1023 local NAMESPACE=$1; shift
1024 local INAME=$1; shift
1025 local CHART=$1; shift
1026 local CHART_VERSION=$1; shift
1027
1028 if [ "$CHART_VERSION X" != " X" ] && [ "$CHART_VERSION" != "latest" ]; then
1029 CHART_VERSION="--version $CHART_VERSION"
1030 else
1031 CHART_VERSION=
1032 fi
1033
1034 local CHART_ARGS=
1035 if [ -r "${INAME}-values.yaml" ]; then
1036 CHART_ARGS="-f ${INAME}-values.yaml"
1037 fi
1038
1039 if [ "$HELM_USE_UPGRADE" == "yes" ]; then
1040 _HELM_COMMAND="upgrade --install"
1041 _HELM_ARGS="xxxdryrunxxx"
1042 else
1043 _HELM_COMMAND="install"
1044 _HELM_ARGS="--name xxxdryrunxxx"
1045 fi
1046 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")
1047 ${CMD[*]} 2>/dev/null | awk 'PRINT==1 {print}; /^USER-SUPPLIED VALUES:/ {PRINT = 1}; /^$/ {PRINT = 0}'
1048}
1049
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001050helm_install() {
David Bainbridged18f4942020-04-14 16:46:13 -07001051 local INDENT NOW
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001052 if [ "$1" == "-" ]; then
1053 INDENT=$1; shift
1054 fi
1055 local NAMESPACE=$1; shift
David Bainbridge0774b232019-08-02 06:37:19 +00001056 local INAME=$1; shift
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001057 local CHART=$1; shift
David Bainbridge90fd8e32019-08-21 23:32:47 +00001058 local CHART_VERSION=$1; shift
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001059 local MESSAGE=$*
1060
David Bainbridged18f4942020-04-14 16:46:13 -07001061 if [ "$CHART_VERSION X" != " X" ] && [ "$CHART_VERSION" != "latest" ]; then
David Bainbridge90fd8e32019-08-21 23:32:47 +00001062 CHART_VERSION="--version $CHART_VERSION"
1063 else
1064 CHART_VERSION=
1065 fi
1066
David Bainbridge99ac7a22019-08-31 02:26:43 +00001067 local CHART_ARGS=
1068 if [ -r "${INAME}-values.yaml" ]; then
1069 CHART_ARGS="-f ${INAME}-values.yaml"
1070 fi
1071
David Bainbridged18f4942020-04-14 16:46:13 -07001072 local WAIT_START CMD
1073 WAIT_START="$(date +%s)"
1074 COUNT="$((300 / 15))"
1075 bspin "$INDENT" "$MESSAGE"
1076 if [ "$HELM_USE_UPGRADE" == "yes" ]; then
David Bainbridge7f8bf992020-04-08 21:53:22 -07001077 _HELM_COMMAND="upgrade --install"
1078 _HELM_ARGS="$INAME"
1079 else
1080 _HELM_COMMAND="install"
1081 _HELM_ARGS="--name $INAME"
1082 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001083 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")
1084 (set -x; ${CMD[*]} >>"$LOG" 2>&1) >>"$LOG" 2>&1
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001085 SUCCESS=$?
David Bainbridged18f4942020-04-14 16:46:13 -07001086 while [ "$SUCCESS" -ne 0 ]; do
1087 NOW="$(date +%s)"
1088 if [ "$((NOW - WAIT_START))" -gt "$TIMEOUT_SECONDS" ]; then
David Bainbridge52e6e9d2020-03-23 13:48:27 -07001089 espin "$THEX"
1090 doTimeout "waiting for helm install $CHART"
1091 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001092 sspin "$INDENT"
1093 COUNT="$((COUNT - 1))"
1094 if [ "$COUNT" -eq 0 ]; then
1095 if [ "$HELM_USE_UPGRADE" == "no" ]; then
1096 (set -x; helm delete --purge "$INAME" >>"$LOG" 2>&1) >>"$LOG" 2>&1
David Bainbridge7f8bf992020-04-08 21:53:22 -07001097 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001098 (set -x; ${CMD[*]} >>"$LOG" 2>&1) >>"$LOG" 2>&1
Andy Baviere22ff252019-12-19 11:40:31 -07001099 SUCCESS=$?
David Bainbridged18f4942020-04-14 16:46:13 -07001100 COUNT="$((300 / 15))"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001101 fi
1102 sleep .15
1103 done
David Bainbridged18f4942020-04-14 16:46:13 -07001104 espin "$INDENT" "$VERIFIED"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001105}
1106
David Bainbridged18f4942020-04-14 16:46:13 -07001107echo "INSTALL TYPE: $TYPE" >> "$LOG"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001108
1109bspin "Verify GOPATH"
David Bainbridged18f4942020-04-14 16:46:13 -07001110GOPATH="$(pwd)"; export GOPATH
1111mkdir -p "$GOPATH/bin"
1112espin "$VERIFIED"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001113
David Bainbridged18f4942020-04-14 16:46:13 -07001114STIME="$(date +%s)"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001115if [ "$INSTALL_KUBECTL" == "no" ]; then
1116 bspin "Skip kubectl install"
1117 espin $NO_ENTRY
Test Userc13bdc92019-07-03 20:57:49 +00001118else
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001119 bspin "Verify kubectl $HELM"
David Bainbridged18f4942020-04-14 16:46:13 -07001120 if [ -x "$GOPATH/bin/kubectl" ]; then
1121 espin "$VERIFIED"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001122 else
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001123 ERR_OUT="$(mktemp)"
David Bainbridged18f4942020-04-14 16:46:13 -07001124 espin "$NOT_VERIFIED"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001125 bspin - "Download and install Kubernetes/kubectl $DOWNLOAD"
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001126 (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
1127 RESULT=$?
1128 if [ "$RESULT" -ne 0 ]; then
1129 espin - "$THEX"
David Bainbridgee3fc0c32020-04-21 15:34:04 -07001130 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR: unable to download kubectl: $(tail "$ERR_OUT")${NORMAL}"
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001131 cat "$ERR_OUT" >> "$LOG"
Zack Williamsded60cb2020-04-13 10:02:20 -07001132 rm -rf "$ERR_OUT" "$GOPATH/bin/kubectl"
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001133 exit 1
1134 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001135 (set -x; chmod 755 "$GOPATH/bin/kubectl" >>"$LOG" 2>&1) >>"$LOG" 2>&1
1136 espin - "$VERIFIED"
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001137 rm -rf "$ERR_OUT"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001138 fi
Test Userc13bdc92019-07-03 20:57:49 +00001139fi
David Bainbridgee87067b2019-08-12 22:00:12 +00001140if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001141 NOW="$(date +%s)"
1142 printtime $((NOW - STIME))
David Bainbridgee87067b2019-08-12 22:00:12 +00001143fi
Test Userc13bdc92019-07-03 20:57:49 +00001144
David Bainbridged18f4942020-04-14 16:46:13 -07001145STIME="$(date +%s)"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001146if [ "$DEPLOY_K8S" == "no" ]; then
1147 bspin "Skip Kubernetes/Kind Deployment"
1148 espin $NO_ENTRY
1149else
Test Userba1e7e72019-07-10 22:27:54 +00001150 bspin "Verify Kubernetes/Kind $HELM"
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -08001151 IS_INSTALLED=0
1152 OP_TYPE="install"
David Bainbridged18f4942020-04-14 16:46:13 -07001153 if [ -x "$GOPATH/bin/kind" ]; then
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -08001154 OP_TYPE="upgrade"
David Bainbridged18f4942020-04-14 16:46:13 -07001155 if [ "$("$GOPATH/bin/kind" --version | grep -c "$KIND_VERSION")" -eq 1 ]; then
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -08001156 IS_INSTALLED=1
David Bainbridged18f4942020-04-14 16:46:13 -07001157 espin "$VERIFIED"
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -08001158 fi
1159 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001160 if [ "$IS_INSTALLED" -eq 0 ]; then
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001161 ERR_OUT="$(mktemp)"
David Bainbridged18f4942020-04-14 16:46:13 -07001162 espin "$NOT_VERIFIED"
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -08001163 bspin - "Download and $OP_TYPE Kubernetes/kind $DOWNLOAD"
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001164 (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
1165 RESULT=$?
1166 if [ $RESULT -ne 0 ]; then
1167 espin - "$THEX"
David Bainbridgee3fc0c32020-04-21 15:34:04 -07001168 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR: unable to download kind: $(tail "$ERR_OUT")${NORMAL}"
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001169 cat "$ERR_OUT" >> "$LOG"
Zack Williamsded60cb2020-04-13 10:02:20 -07001170 rm -rf "$ERR_OUT" "$GOPATH/bin/kind"
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001171 exit 1
1172 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001173 (set -x; chmod 755 "$GOPATH/bin/kind" >>"$LOG" 2>&1) >>"$LOG" 2>&1
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001174 rm -rf "$ERR_OUT"
David Bainbridged18f4942020-04-14 16:46:13 -07001175 espin - "$VERIFIED"
Test Userba1e7e72019-07-10 22:27:54 +00001176 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001177fi
1178
David Bainbridgee87067b2019-08-12 22:00:12 +00001179if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001180 NOW="$(date +%s)"
1181 printtime $((NOW - STIME))
David Bainbridgee87067b2019-08-12 22:00:12 +00001182fi
1183
David Bainbridged18f4942020-04-14 16:46:13 -07001184STIME="$(date +%s)"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001185if [ "$INSTALL_HELM" == "no" ]; then
1186 bspin "Skip Helm Install"
1187 espin $NO_ENTRY
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001188else
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001189 bspin "Verify Helm $HELM"
David Bainbridgea34993d2020-04-01 09:15:42 -07001190 HELM_UPGRADE=0
1191 HELM_UPGRADE_DESC="install"
David Bainbridged18f4942020-04-14 16:46:13 -07001192 if [ -x "$GOPATH/bin/helm" ]; then
1193 HAVE_VER="$("$GOPATH/bin/helm" version -c --template '{{.Client.SemVer}}')"
1194 HELM_UP_DOWN="$(echo -e "$HAVE_VER\n$HELM_VERSION" | sort -V | head -1)"
1195 if [ "$HAVE_VER" != "$HELM_VERSION" ]; then
1196 if [ "$HELM_UP_DOWN" == "$HELM_VERSION" ]; then
David Bainbridgea34993d2020-04-01 09:15:42 -07001197 HELM_UPGRADE_DESC="downgrade"
1198 else
1199 HELM_UPGRADE_DESC="upgrade"
1200 fi
1201 HELM_UPGRADE=1
1202 else
David Bainbridged18f4942020-04-14 16:46:13 -07001203 espin "$VERIFIED"
David Bainbridgea34993d2020-04-01 09:15:42 -07001204 fi
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001205 else
David Bainbridgea34993d2020-04-01 09:15:42 -07001206 HELM_UPGRADE=1
1207 fi
1208
David Bainbridged18f4942020-04-14 16:46:13 -07001209 if [ "$HELM_UPGRADE" -ne 0 ]; then
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001210 ERR_OUT="$(mktemp)"
1211 INSTALL_HELM_BIN=$(mktemp)
David Bainbridged18f4942020-04-14 16:46:13 -07001212 espin "$NOT_VERIFIED"
David Bainbridgea34993d2020-04-01 09:15:42 -07001213 bspin - "Download and $HELM_UPGRADE_DESC Helm $DOWNLOAD"
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001214 (set -x; curl -o "$INSTALL_HELM_BIN" --fail -sSL https://git.io/get_helm.sh >>"$LOG" 2>"$ERR_OUT") >>"$LOG" 2>&1
1215 RESULT=$?
1216 if [ $RESULT -ne 0 ]; then
1217 espin - "$THEX"
David Bainbridgee3fc0c32020-04-21 15:34:04 -07001218 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR: unable to download helm installer: $(tail "$ERR_OUT")${NORMAL}"
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001219 cat "$ERR_OUT" >> "$LOG"
1220 rm -rf "$INSTALL_HELM_BIN" "$ERR_OUT" "$GOPATH/bin/helm" "$GOPATH/bin/tiller"
1221 exit 1
1222 fi
1223 rm -rf "$ERR_OUT"
1224 chmod +x "$INSTALL_HELM_BIN"
1225 (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
1226 RESULT=$?
1227 if [ $RESULT -ne 0 ]; then
1228 espin - "$THEX"
1229 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR: unable to install helm, see install log for details${NORMAL}"
1230 rm -rf "$INSTALL_HELM_BIN" "$ERR_OUT" "$GOPATH/bin/helm" "$GOPATH/bin/tiller"
1231 exit 1
1232 fi
1233 rm -rf "$INSTALL_HELM_BIN" "$ERR_OUT"
David Bainbridged18f4942020-04-14 16:46:13 -07001234 espin - "$VERIFIED"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001235 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001236fi
David Bainbridgee87067b2019-08-12 22:00:12 +00001237if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001238 NOW="$(date +%s)"
1239 printtime $((NOW - STIME))
David Bainbridgee87067b2019-08-12 22:00:12 +00001240fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001241
David Bainbridged18f4942020-04-14 16:46:13 -07001242STIME="$(date +%s)"
Test Userb5712372019-07-03 21:52:17 +00001243bspin "Verify voltctl $HIGH_VOLTAGE"
David Bainbridged2811972019-12-14 01:14:09 +00001244VOK=0
1245VMESSAGE="install"
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001246ERR_OUT=$(mktemp)
David K. Bainbridgeebf38d92020-02-10 10:46:31 -08001247export VC_VERSION="$VOLTCTL_VERSION"
1248if [ "$VC_VERSION" == "latest" ]; then
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001249 set -o pipefail # TODO: would be nice to run all in pipefail mode
1250 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')"
1251 RESULT=$?
1252 set +o pipefail
1253 if [ "$RESULT" -ne 0 ]; then
1254 espin - "$THEX"
1255 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR: unable to determine released version of voltctl: $(cat "$ERR_OUT")${NORMAL}"
1256 rm -rf "$ERR_OUT" "$GOPATH/bin/voltctl"
1257 exit 1
1258 fi
1259 export VC_VERSION
David K. Bainbridgeebf38d92020-02-10 10:46:31 -08001260fi
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001261
David Bainbridged18f4942020-04-14 16:46:13 -07001262if [ -x "$GOPATH/bin/voltctl" ]; then
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001263 VHAVE="$("$GOPATH/bin/voltctl" version --clientonly -o json 2>/dev/null | jq -r .version)"
David Bainbridged18f4942020-04-14 16:46:13 -07001264 RESULT=$?
1265 if [ $RESULT -eq 0 ] && [ "$VHAVE" == "$VC_VERSION" ]; then
David Bainbridged2811972019-12-14 01:14:09 +00001266 VOK=1
David Bainbridged18f4942020-04-14 16:46:13 -07001267 espin "$VERIFIED"
David Bainbridge1ba64f12019-12-18 00:40:13 +00001268 else
David Bainbridged18f4942020-04-14 16:46:13 -07001269 VCHECK="$(echo -e "$VHAVE\n$VC_VERSION" | sort -V | head -1)"
David K. Bainbridgeebf38d92020-02-10 10:46:31 -08001270 if [ "$VCHECK" == "$VHAVE" ]; then
1271 VMESSAGE="upgrade"
1272 else
1273 VMESSAGE="downgrade"
1274 fi
David Bainbridged2811972019-12-14 01:14:09 +00001275 fi
1276fi
1277
David Bainbridged18f4942020-04-14 16:46:13 -07001278if [ "$VOK" -eq 0 ]; then
1279 espin "$NOT_VERIFIED"
David Bainbridged2811972019-12-14 01:14:09 +00001280 bspin - "Download and $VMESSAGE voltctl $DOWNLOAD"
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001281 (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
1282 RESULT=$?
1283 if [ $RESULT -ne 0 ]; then
1284 espin - "$THEX"
1285 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR: unable to download voltctl (version $VC_VERSION): $(cat "$ERR_OUT")${NORMAL}"
1286 rm -rf "$ERR_OUT" "$GOPATH/bin/voltctl"
1287 exit 1
1288 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001289 (set -x; chmod 755 "$GOPATH/bin/voltctl" >>"$LOG" 2>&1) >>"$LOG" 2>&1
1290 espin - "$VERIFIED"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001291fi
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001292rm -rf "$ERR_OUT"
David Bainbridgee87067b2019-08-12 22:00:12 +00001293if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001294 NOW="$(date +%s)"
1295 printtime $((NOW - STIME))
David Bainbridgee87067b2019-08-12 22:00:12 +00001296fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001297
1298bspin "Verify command PATH"
Test Userba1e7e72019-07-10 22:27:54 +00001299export PATH=$GOPATH/bin:$PATH
David Bainbridged18f4942020-04-14 16:46:13 -07001300espin "$VERIFIED"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001301
David Bainbridged18f4942020-04-14 16:46:13 -07001302STIME="$(date +%s)"
Test Userba1e7e72019-07-10 22:27:54 +00001303if [ "$DEPLOY_K8S" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001304 HAVE="$(kind get clusters | grep -c "voltha-$NAME")"
Test Userba1e7e72019-07-10 22:27:54 +00001305 bspin "Verify Kubernetes/Kind Cluster"
1306 sspin
David Bainbridged18f4942020-04-14 16:46:13 -07001307 if [ "$HAVE" -eq 0 ]; then
1308 espin "$NOT_VERIFIED"
David Bainbridge491b1bd2019-07-11 17:53:11 +00001309 bspin - "Verify cluster configuration"
David Bainbridged18f4942020-04-14 16:46:13 -07001310 if [ ! -r "./$NAME-cluster.cfg" ]; then
1311 espin - "$NOT_VERIFIED"
David K. Bainbridge43422402020-03-06 07:41:22 -08001312 bspin - "Download cluster configuration: $TYPE-cluster.cfg to $NAME-cluster.cfg $DOWNLOAD"
David Bainbridged18f4942020-04-14 16:46:13 -07001313 ERR_OUT="$(mktemp)"
serkant.uluderya4d315132020-04-15 16:25:54 -07001314 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 -07001315 espin - "$THEX"
1316 echo -e "${RED}${BOLD}${ERROR}ERROR: $NAME-cluster.cfg${NORMAL}${RED} - $(cat "$ERR_OUT")${NORMAL}"
1317 echo "ERROR: $(cat "$ERR_OUT")" >>"$LOG"
1318 rm -rf "$ERR_OUT" "./$NAME-cluster.cfg"
David K. Bainbridgea00736b2020-01-08 14:33:17 -08001319 exit 1
1320 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001321 rm -rf "$ERR_OUT"
David K. Bainbridgea00736b2020-01-08 14:33:17 -08001322 else
David Bainbridged18f4942020-04-14 16:46:13 -07001323 espin - "$VERIFIED"
David K. Bainbridgea00736b2020-01-08 14:33:17 -08001324 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001325 kind create cluster --name "voltha-$NAME" --config "$NAME-cluster.cfg"
David Bainbridge491b1bd2019-07-11 17:53:11 +00001326 else
David Bainbridged18f4942020-04-14 16:46:13 -07001327 espin "$VERIFIED"
Test Userba1e7e72019-07-10 22:27:54 +00001328 fi
1329
David Bainbridged18f4942020-04-14 16:46:13 -07001330 KUBECONFIG="$(kind get kubeconfig-path --name="voltha-$NAME")"; export KUBECONFIG
Test Userba1e7e72019-07-10 22:27:54 +00001331 P="coredns-.* \
David Bainbridge0774b232019-08-02 06:37:19 +00001332 etcd-voltha-$NAME-control-plane \
Test Userba1e7e72019-07-10 22:27:54 +00001333 kindnet-.* \
David Bainbridge0774b232019-08-02 06:37:19 +00001334 kube-apiserver-voltha-$NAME-control-plane \
1335 kube-controller-manager-voltha-$NAME-control-plane \
Test Userba1e7e72019-07-10 22:27:54 +00001336 kube-proxy-.* \
David Bainbridge0774b232019-08-02 06:37:19 +00001337 kube-scheduler-voltha-$NAME-control-plane"
Test Userba1e7e72019-07-10 22:27:54 +00001338
David Bainbridged18f4942020-04-14 16:46:13 -07001339 EXPECT="$(test "$TYPE" == "minimal" && echo "12" || echo "14")"
1340 wait_for_pods - "kube-system" "$EXPECT" "includes" "Waiting for system PODs to start" "$NO_LABEL" "$P"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001341fi
David Bainbridgee87067b2019-08-12 22:00:12 +00001342if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001343 NOW="$(date +%s)"
1344 printtime $((NOW - STIME))
David Bainbridgee87067b2019-08-12 22:00:12 +00001345fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001346
David Bainbridged18f4942020-04-14 16:46:13 -07001347STIME="$(date +%s)"
1348COUNT="$(count_pods "kube-system" ":Running:" "$NO_LABEL" "tiller-deploy-.*")"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001349bspin "Verify Helm"
David Bainbridged18f4942020-04-14 16:46:13 -07001350if [ "$COUNT" -ne 1 ]; then
1351 espin "$NOT_VERIFIED"
Test Userb5712372019-07-03 21:52:17 +00001352 echo -e "Configuring Helm $GEAR"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001353 if [ "$INSTALL_HELM" == "no" ]; then
1354 bspin - "Skip Helm/Tiller Initialization"
1355 espin - $NO_ENTRY
1356 else
1357 bspin - "Initialize Helm"
David Bainbridged18f4942020-04-14 16:46:13 -07001358 (set -x; helm init --upgrade >>"$LOG" 2>&1) >>"$LOG" 2>&1
1359 espin - "$VERIFIED"
1360 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 -07001361 fi
Test Userb5712372019-07-03 21:52:17 +00001362 bspin - "Add Google Incubator repository to Helm"
David Bainbridged18f4942020-04-14 16:46:13 -07001363 (set -x; helm repo add incubator https://kubernetes-charts-incubator.storage.googleapis.com >>"$LOG" 2>&1) >>"$LOG" 2>&1
1364 espin - "$VERIFIED"
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001365
Test Userba1e7e72019-07-10 22:27:54 +00001366 # HACK (sort-of) - the config for tiller is about to be patched, which will
1367 # cause the tiller pod to be recreated. This can sometimes cause a timing
1368 # issue with the "wait_for_pods" call on tiller as it may incorrectly
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001369 # identify the running/ready tiller pod that is soon to be terminated as
Test Userba1e7e72019-07-10 22:27:54 +00001370 # what it is waiting for. To avoid this issue we do a clean scale down and
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001371 # scale up of the pod so the script controlls when it should be expecting
Test Userba1e7e72019-07-10 22:27:54 +00001372 # things
David Bainbridged18f4942020-04-14 16:46:13 -07001373 (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 -07001374
Test Userb5712372019-07-03 21:52:17 +00001375 bspin - "Add Google Stable repository to Helm"
David Bainbridged18f4942020-04-14 16:46:13 -07001376 (set -x; helm repo add stable https://kubernetes-charts.storage.googleapis.com >>"$LOG" 2>&1) >>"$LOG" 2>&1
1377 espin - "$VERIFIED"
David Bainbridge60ffc0f2020-04-27 22:13:22 -07001378 bspin - "Add ONF VOLTHA repository to Helm"
David Bainbridged18f4942020-04-14 16:46:13 -07001379 (set -x; helm repo add onf https://charts.opencord.org >>"$LOG" 2>&1) >>"$LOG" 2>&1
1380 espin - "$VERIFIED"
David Bainbridge60ffc0f2020-04-27 22:13:22 -07001381 bspin - "Add ONF ONOS repository to Helm"
1382 (set -x; helm repo add onos https://charts.onosproject.org >>"$LOG" 2>&1) >>"$LOG" 2>&1
1383 espin - "$VERIFIED"
1384 bspin - "Add ONF Atomix repository to Helm"
1385 (set -x; helm repo add atomix https://charts.atomix.io >>"$LOG" 2>&1) >>"$LOG" 2>&1
1386 espin - "$VERIFIED"
Test Userb5712372019-07-03 21:52:17 +00001387 bspin - "Update Helm repository cache"
David Bainbridged18f4942020-04-14 16:46:13 -07001388 (set -x; helm repo update >>"$LOG" 2>&1) >>"$LOG" 2>&1
1389 espin - "$VERIFIED"
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001390
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001391 # Create and k8s service account so that Helm can create pods
Test Userb5712372019-07-03 21:52:17 +00001392 bspin - "Create Tiller ServiceAccount"
David Bainbridged18f4942020-04-14 16:46:13 -07001393 (set -x; kubectl create serviceaccount --namespace kube-system tiller >>"$LOG" 2>&1) >>"$LOG" 2>&1
1394 espin - "$VERIFIED"
Test Userb5712372019-07-03 21:52:17 +00001395 bspin - "Create Tiller ClusterRoleBinding"
David Bainbridged18f4942020-04-14 16:46:13 -07001396 (set -x; kubectl create clusterrolebinding tiller-cluster-rule --clusterrole=cluster-admin --serviceaccount=kube-system:tiller >>"$LOG" 2>&1) >>"$LOG" 2>&1
1397 espin - "$VERIFIED"
Test Userb5712372019-07-03 21:52:17 +00001398 bspin - "Update Tiller Manifest"
David Bainbridged18f4942020-04-14 16:46:13 -07001399 (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 +00001400
1401 # HACK (sort-of) - part to, spin it back up
David Bainbridged18f4942020-04-14 16:46:13 -07001402 (set -x; kubectl -n kube-system scale deploy tiller-deploy --replicas=1 >>"$LOG" 2>&1) >>"$LOG" 2>&1
1403 espin - "$VERIFIED"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001404else
David Bainbridged18f4942020-04-14 16:46:13 -07001405 if [ "$(helm version -s --template '{{.Server.SemVer}}')" != "$HELM_VERSION" ]; then
1406 espin "$NOT_VERIFIED"
David Bainbridgea34993d2020-04-01 09:15:42 -07001407 bspin - "Sync Tiller server version with helm client"
David Bainbridged18f4942020-04-14 16:46:13 -07001408 (set -x; helm init --upgrade --force-upgrade --wait >>"$LOG" 2>&1) >>"$LOG" 2>&1
1409 espin - "$VERIFIED"
David Bainbridgea34993d2020-04-01 09:15:42 -07001410 else
David Bainbridged18f4942020-04-14 16:46:13 -07001411 espin "$VERIFIED"
David Bainbridgea34993d2020-04-01 09:15:42 -07001412 fi
1413
David Bainbridge46505fb2019-10-01 21:13:20 +00001414 if [ "$UPDATE_HELM_REPOS" == "yes" ]; then
1415 bspin - "Update Helm repository cache"
David Bainbridged18f4942020-04-14 16:46:13 -07001416 (set -x; helm repo update >>"$LOG" 2>&1) >>"$LOG" 2>&1
1417 espin - "$VERIFIED"
David Bainbridge46505fb2019-10-01 21:13:20 +00001418 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001419fi
David Bainbridged18f4942020-04-14 16:46:13 -07001420wait_for_pods - "kube-system" 1 "includes" "Waiting for Tiller POD to start" "$NO_LABEL" "tiller-deploy-.*"
David Bainbridgee87067b2019-08-12 22:00:12 +00001421if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001422 NOW="$(date +%s)"
1423 printtime $((NOW - STIME))
David Bainbridgee87067b2019-08-12 22:00:12 +00001424fi
David Bainbridgecf546362020-04-21 23:18:50 -07001425# Resolve chart versions and log them for debug/support
1426RESOLVED_VOLTHA_CHART_VERSION=$(resolve_chart_version "$VOLTHA_CHART" "$VOLTHA_CHART_VERSION")
1427RESOLVED_VOLTHA_BBSIM_CHART_VERSION=$(resolve_chart_version "$VOLTHA_BBSIM_CHART" "$VOLTHA_BBSIM_CHART_VERSION")
1428RESOLVED_VOLTHA_ADAPTER_SIM_CHART_VERSION=$(resolve_chart_version "$VOLTHA_ADAPTER_SIM_CHART" "$VOLTHA_ADAPTER_SIM_CHART_VERSION")
1429RESOLVED_VOLTHA_ADAPTER_OPEN_OLT_CHART_VERSION=$(resolve_chart_version "$VOLTHA_ADAPTER_OPEN_OLT_CHART" "$VOLTHA_ADAPTER_OPEN_OLT_CHART_VERSION")
1430RESOLVED_VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION=$(resolve_chart_version "$VOLTHA_ADAPTER_OPEN_ONU_CHART" "$VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION")
1431RESOLVED_ONOS_CHART_VERSION=$(resolve_chart_version "$ONOS_CHART" "$ONOS_CHART_VERSION")
David Bainbridge60ffc0f2020-04-27 22:13:22 -07001432RESOLVED_ONOS_CLASSIC_CHART_VERSION=$(resolve_chart_version "$ONOS_CLASSIC_CHART" "$ONOS_CLASSIC_CHART_VERSION")
David Bainbridgecf546362020-04-21 23:18:50 -07001433RESOLVED_KAFKA_CHART_VERSION=$(resolve_chart_version "$KAFKA_CHART" "$KAFKA_CHART_VERSION")
1434cat <<EOV >>"$LOG"
1435Resolved helm charts and versions:
1436 $VOLTHA_CHART:$RESOLVED_VOLTHA_CHART_VERSION
1437 $VOLTHA_BBSIM_CHART:$RESOLVED_VOLTHA_BBSIM_CHART_VERSION
1438 $VOLTHA_ADAPTER_SIM_CHART:$RESOLVED_VOLTHA_ADAPTER_SIM_CHART_VERSION
1439 $VOLTHA_ADAPTER_OPEN_OLT_CHART:$RESOLVED_VOLTHA_ADAPTER_OPEN_OLT_CHART_VERSION
1440 $VOLTHA_ADAPTER_OPEN_ONU_CHART:$RESOLVED_VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION
1441 $ONOS_CHART:$RESOLVED_ONOS_CHART_VERSION
David Bainbridge60ffc0f2020-04-27 22:13:22 -07001442 $ONOS_CLASSIC_CHART:$RESOLVED_ONOS_CLASSIC_CHART_VERSION
David Bainbridgecf546362020-04-21 23:18:50 -07001443 $KAFKA_CHART:$RESOLVED_KAFKA_CHART_VERSION
1444EOV
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001445
David Bainbridged18f4942020-04-14 16:46:13 -07001446STIME="$(date +%s)"
David Bainbridge0774b232019-08-02 06:37:19 +00001447bspin "Verify Helm values file: $NAME-values.yaml"
1448if [ ! -r "./$NAME-values.yaml" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001449 espin "$NOT_VERIFIED"
David Bainbridge0774b232019-08-02 06:37:19 +00001450 bspin - "Download Helm values file: $TYPE-values.yaml to $NAME-values.yaml $DOWNLOAD"
David Bainbridged18f4942020-04-14 16:46:13 -07001451 ERR_OUT="$(mktemp)"
serkant.uluderya4d315132020-04-15 16:25:54 -07001452 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 -07001453 espin - "$THEX"
1454 echo -e "${RED}${BOLD}${ERROR}ERROR: $NAME-values.yaml${NORMAL}${RED} - $(cat "$ERR_OUT")${NORMAL}"
1455 echo "ERROR: $(cat "$ERR_OUT")" >>"$LOG"
1456 rm -rf "$ERR_OUT" "./$NAME-values.yaml"
David K. Bainbridgea00736b2020-01-08 14:33:17 -08001457 exit 1
1458 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001459 rm -rf "$ERR_OUT"
1460 espin - "$VERIFIED"
Test Userba1e7e72019-07-10 22:27:54 +00001461else
David Bainbridged18f4942020-04-14 16:46:13 -07001462 espin "$VERIFIED"
Test Userba1e7e72019-07-10 22:27:54 +00001463fi
David Bainbridgee87067b2019-08-12 22:00:12 +00001464if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001465 NOW="$(date +%s)"
1466 printtime $((NOW - STIME))
David Bainbridgee87067b2019-08-12 22:00:12 +00001467fi
Test Userba1e7e72019-07-10 22:27:54 +00001468
David Bainbridged18f4942020-04-14 16:46:13 -07001469STIME="$(date +%s)"
David Bainbridge99ac7a22019-08-31 02:26:43 +00001470bspin "Verify or download chart specific values files $DOWNLOAD"
1471VALUES_FILES="monkey-values.yaml"
David Bainbridged18f4942020-04-14 16:46:13 -07001472ERR_OUT="$(mktemp)"
David Bainbridge99ac7a22019-08-31 02:26:43 +00001473for i in $VALUES_FILES; do
1474 if [ ! -r ./$i ]; then
serkant.uluderya4d315132020-04-15 16:25:54 -07001475 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 -07001476 espin "$THEX"
1477 echo -e "${RED}${BOLD}${ERROR}ERROR: $i${NORMAL}${RED} - $(cat "$ERR_OUT")${NORMAL}"
1478 echo "ERROR: $i - $(cat "$ERR_OUT")" >>"$LOG"
1479 rm -rf "$ERR_OUT" "./$i"
David K. Bainbridgea00736b2020-01-08 14:33:17 -08001480 exit 1
1481 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001482 rm -rf "$ERR_OUT"
David Bainbridge99ac7a22019-08-31 02:26:43 +00001483 fi
1484done
David Bainbridged18f4942020-04-14 16:46:13 -07001485rm -rf "$ERR_OUT"
1486espin "$VERIFIED"
David Bainbridge99ac7a22019-08-31 02:26:43 +00001487if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001488 NOW="$(date +%s)"
1489 printtime $((NOW - STIME))
David Bainbridge99ac7a22019-08-31 02:26:43 +00001490fi
1491
1492if [ "$WITH_CHAOS" == "yes" ]; then
1493 bspin "Verify or clone kube-monkey helm chart $DOWNLOAD"
1494 if [ -r ./kube-monkey ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001495 espin "$VERIFIED"
David Bainbridge99ac7a22019-08-31 02:26:43 +00001496 else
David Bainbridged18f4942020-04-14 16:46:13 -07001497 espin "$NOT_VERIFIED"
David Bainbridge99ac7a22019-08-31 02:26:43 +00001498 bspin - "GIT clone kube-monkey"
David Bainbridged18f4942020-04-14 16:46:13 -07001499 (set -x; git clone https://github.com/asobti/kube-monkey kube-monkey >>"$LOG" 2>&1) >>"$LOG" 2>&1
1500 espin - "$VERIFIED"
David Bainbridge99ac7a22019-08-31 02:26:43 +00001501 fi
1502fi
1503
Test Userba1e7e72019-07-10 22:27:54 +00001504if [ "$JUST_K8S" == "yes" ]; then
1505 echo "Environment deployed, not deploying VOLTHA artifacts as requested. Good bye."
1506 echo ""
David Bainbridged18f4942020-04-14 16:46:13 -07001507 echo "Please issue the following commands in your terminal to ensure that you" | tee -a "$LOG"
1508 echo "are accessing the correct Kubernetes/Kind cluster as well as have the " | tee -a "$LOG"
1509 echo "tools required by VOLTHA in your command path. " | tee -a "$LOG"
1510 echo "" | tee -a "$LOG"
1511 echo -en "$BOLD"
1512 if [ "$DEPLOY_K8S" == "yes" ]; then
1513 echo "export KUBECONFIG=\"\$(./bin/kind get kubeconfig-path --name=\"voltha-$NAME\")\"" | tee -a "$LOG"
Test Userba1e7e72019-07-10 22:27:54 +00001514 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001515 echo "export PATH=$GOPATH/bin:\$PATH" | tee -a "$LOG"
1516 echo -en "$NORMAL"
1517 echo "" | tee -a "$LOG"
1518 echo "Thank you for choosing kind-voltha for you quick cluster needs." | tee -a "$LOG"
Test Userba1e7e72019-07-10 22:27:54 +00001519 exit 0
1520fi
1521
David Bainbridged18f4942020-04-14 16:46:13 -07001522if [ "$WITH_ETCD" != "yes" ] && [ "$WITH_ETCD" != "external" ]; then
David Bainbridge696bc632020-04-05 21:49:37 -07001523 bspin "Skip ETCD Operator Deployment"
1524 espin $NO_ENTRY
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001525else
David Bainbridged18f4942020-04-14 16:46:13 -07001526 STIME="$(date +%s)"
David Bainbridge76afd812020-04-06 09:53:52 -07001527 NS=$VOLTHA_NS
David Bainbridged18f4942020-04-14 16:46:13 -07001528 if [ "$WITH_ETCD" == "external" ]; then
David Bainbridge76afd812020-04-06 09:53:52 -07001529 NS=$INFRA_NS
1530 fi
David Bainbridge696bc632020-04-05 21:49:37 -07001531 bspin "Verify ETCD Operator $OLD_KEY"
David Bainbridged18f4942020-04-14 16:46:13 -07001532 if [ "$HELM_USE_UPGRADE" == "yes" ] || [ "$(helm list --deployed --short --namespace "$NS" "^etcd-operator\$" | wc -l)" -ne 1 ]; then
1533 espin "$NOT_VERIFIED"
1534 helm_install - "$NS" etcd-operator stable/etcd-operator latest "$_HELM_DESC ETCD Operator"
David Bainbridge696bc632020-04-05 21:49:37 -07001535 else
David Bainbridged18f4942020-04-14 16:46:13 -07001536 espin "$VERIFIED"
David Bainbridge696bc632020-04-05 21:49:37 -07001537 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001538 EXPECT="$(test "$TYPE" == "minimal" && echo "1" || echo "3")"
1539 wait_for_pods - "$NS" "$EXPECT" "includes" "Waiting for ETCD Operator to start" "$NO_LABEL" "etcd-operator-.*"
David Bainbridge696bc632020-04-05 21:49:37 -07001540 if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001541 NOW="$(date +%s)"
1542 printtime $((NOW - STIME))
David Bainbridge696bc632020-04-05 21:49:37 -07001543 fi
David Bainbridgee87067b2019-08-12 22:00:12 +00001544fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001545
David Bainbridged18f4942020-04-14 16:46:13 -07001546STIME="$(date +%s)"
David Bainbridge60ffc0f2020-04-27 22:13:22 -07001547if is_in "$WITH_ONOS" "yes,legacy,classic"; then
1548 if is_in "$WITH_ONOS" "legacy"; then
1549 bspin "Verify ONOS LEGACY installed $BIRD"
1550 if [ "$HELM_USE_UPGRADE" == "yes" ] || [ "$(helm list --deployed --short --namespace "$INFRA_NS" "^onos\$" | wc -l)" -ne 1 ]; then
1551 espin "$NOT_VERIFIED"
1552 INTERNAL_EXTRA_HELM_INSTALL_ARGS="$SET_TAG $EXTRA_HELM_FLAGS" helm_install - "$INFRA_NS" onos "$ONOS_CHART" "$ONOS_CHART_VERSION" "$_HELM_DESC ONOS LEGACY"
1553 INTERNAL_EXTRA_HELM_INSTALL_ARGS=
1554 else
1555 espin "$VERIFIED"
1556 fi
1557 wait_for_pods - "$INFRA_NS" 1 "includes" "Waiting for ONOS to start" "$NO_LABEL" "onos-.*"
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001558
David Bainbridge60ffc0f2020-04-27 22:13:22 -07001559 if [ "$WITH_PORT_FORWARDS" == "yes" ]; then
1560 bspin - "Forward ONOS API port $FORWARD"
1561 kill_port_forward onos-ui
1562 port_forward "$INFRA_NS" onos-ui "$ONOS_API_PORT:8181"
1563 espin - "$VERIFIED"
1564 bspin - "Forward ONOS SSH port $FORWARD"
1565 kill_port_forward onos-ssh
1566 port_forward "$INFRA_NS" onos-ssh "$ONOS_SSH_PORT:8101"
1567 espin - "$VERIFIED"
1568 _ONOS_API_EP="127.0.0.1:$ONOS_API_PORT"
1569 else
1570 _ONOS_API_EP="$(get_service_ep "$INFRA_NS" onos-ui)"
1571 fi
1572 elif is_in "$WITH_ONOS" "yes,classic"; then
1573 bspin "Verify ONOS CLASSIC installed $BIRD"
1574 if [ "$HELM_USE_UPGRADE" == "yes" ] || [ "$(helm list --deployed --short --namespace "$INFRA_NS" "^onos\$" | wc -l)" -ne 1 ]; then
1575 espin "$NOT_VERIFIED"
1576 # ONOS CLASSIC identifies its image repo/tag differently, so yq is used to grab the values from the
1577 # values value
David Bainbridgefad50732020-05-01 17:00:12 -07001578 YAML_VALUES=$(INTERNAL_EXTRA_HELM_INSTALL_ARGS="--set replicas=$NUM_OF_ONOS --set atomix.replicas=$NUM_OF_ATOMIX" \
1579 helm_values "$INFRA_NS" onos "$ONOS_CLASSIC_CHART" "$ONOS_CLASSIC_CHART_VERSION")
1580 _ONOS_REPO="$(echo "$YAML_VALUES" | yq read - images.onos.repository)"
1581 _ONOS_TAG="$(echo "$YAML_VALUES" | yq read - images.onos.tag)"
1582 _TAG_DEFAULT="$(echo "$YAML_VALUES" | yq read - defaults.image_tag)"
David Bainbridge60ffc0f2020-04-27 22:13:22 -07001583 if [ -z "$_ONOS_TAG" ]; then
1584 _ONOS_TAG="$_TAG_DEFAULT"
1585 fi
David Bainbridgefad50732020-05-01 17:00:12 -07001586
David Bainbridge60ffc0f2020-04-27 22:13:22 -07001587 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" \
1588 helm_install - "$INFRA_NS" onos "$ONOS_CLASSIC_CHART" "$ONOS_CLASSIC_CHART_VERSION" "$_HELM_DESC ONOS CLASSIC"
1589 INTERNAL_EXTRA_HELM_INSTALL_ARGS=
1590 else
1591 espin "$VERIFIED"
1592 fi
1593 wait_for_pods - "$INFRA_NS" $((NUM_OF_ONOS + NUM_OF_ATOMIX)) "includes" "Waiting for ONOS CLASSIC to start" "$NO_LABEL" "onos-.*"
1594 if [ "$WITH_PORT_FORWARDS" == "yes" ]; then
1595 bspin - "Forward ONOS API port $FORWARD"
1596 kill_port_forward onos-onos-classic-hs
1597 port_forward "$INFRA_NS" onos-onos-classic-hs "$ONOS_API_PORT:8181" "$ONOS_SSH_PORT:8101"
1598 espin - "$VERIFIED"
1599 _ONOS_API_EP="127.0.0.1:$ONOS_API_PORT"
1600 else
1601 _ONOS_API_EP="$(get_service_ep "$INFRA_NS" onos-onos-classic-hs)"
1602 fi
1603 elif [ "$WITH_ONOS" == "micro" ]; then
1604 bspin "Verify micro-ONOS installed $BIRD"
1605 # We should never get here
1606 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} Micro ONOS not currently supported${NORMAL}"
1607 exit 1
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -08001608 fi
David Bainbridged31d6122019-08-13 19:37:59 +00001609 bspin - "Verify or download ONOS configuration support files $DOWNLOAD"
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001610 ONOS_FILES="olt-onos-enableExtraneousRules.json onos-aaa.json \
David Bainbridge696bc632020-04-05 21:49:37 -07001611 onos-dhcpl2relay.json onos-sadis-sample.json"
David Bainbridged18f4942020-04-14 16:46:13 -07001612 (set -x; mkdir -p ./onos-files >>"$LOG" 2>&1) >>"$LOG" 2>&1
1613 ERR_OUT="$(mktemp)"
David Bainbridge2b19e832019-08-16 02:40:53 +00001614 for i in $ONOS_FILES; do
David Bainbridged18f4942020-04-14 16:46:13 -07001615 if [ ! -r "./onos-files/$i" ]; then
serkant.uluderya4d315132020-04-15 16:25:54 -07001616 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 -07001617 espin - "$THEX"
1618 echo -e "${RED}${BOLD}${ERROR}ERROR: $i${NORMAL}${RED} - $(cat "$ERR_OUT")${NORMAL}"
1619 echo "ERROR: $(cat "$ERR_OUT")" >>"$LOG"
1620 rm -rf "$ERR_OUT" "./onos-files/$i"
David K. Bainbridgea00736b2020-01-08 14:33:17 -08001621 exit 1
1622 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001623 rm -rf "$ERR_OUT"
David Bainbridged31d6122019-08-13 19:37:59 +00001624 fi
1625 done
David Bainbridged18f4942020-04-14 16:46:13 -07001626 rm -rf "$ERR_OUT"
1627 espin - "$VERIFIED"
David Bainbridge27790d62019-08-13 22:43:19 +00001628
David Bainbridged18f4942020-04-14 16:46:13 -07001629 if [ "$INSTALL_ONOS_APPS" == "yes" ]; then
David Bainbridge27790d62019-08-13 22:43:19 +00001630 bspin - "Installing custom ONOS applications"
David Bainbridged18f4942020-04-14 16:46:13 -07001631 if [ -x onos-files/onos-apps ] && [ "$(find onos-files/onos-apps -name "*.oar" 2>/dev/null | wc -l)" -gt 0 ]; then
1632 for OAR in onos-files/onos-apps/*.oar; do
David Bainbridge27790d62019-08-13 22:43:19 +00001633 sspin - "Installing custom ONOS applications - $OAR$CEOL"
David Bainbridged18f4942020-04-14 16:46:13 -07001634 override_onos_app "$OAR"
David Bainbridge27790d62019-08-13 22:43:19 +00001635 done
1636 espin - "$VERIFIED Installing custom ONOS applications$CEOL"
1637 else
1638 espin - "$NOT_VERIFIED Installing custom ONOS applications - None Found"
1639 fi
1640 fi
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001641
David Bainbridged18f4942020-04-14 16:46:13 -07001642 if [ "$WITH_KAFKA" != "no" ]; then
David Bainbridge837e8bd2020-04-06 13:17:14 -07001643 check_onos_app_active org.opencord.kafka
David Bainbridge76afd812020-04-06 09:53:52 -07001644 _HOST=voltha-kafka.$INFRA_NS.svc.cluster.local
David Bainbridge837e8bd2020-04-06 13:17:14 -07001645 _PORT=9092
David Bainbridged18f4942020-04-14 16:46:13 -07001646 if [ "$WITH_KAFKA" == "yes" ]; then
David Bainbridge76afd812020-04-06 09:53:52 -07001647 _HOST=voltha-kafka.$VOLTHA_NS.svc.cluster.local
1648 _PORT=9092
David Bainbridged18f4942020-04-14 16:46:13 -07001649 elif [ "$WITH_KAFKA" == "external" ]; then
David Bainbridge76afd812020-04-06 09:53:52 -07001650 _HOST=kafka.$INFRA_NS.svc.cluster.local
1651 _PORT=9092
1652 else
David Bainbridged18f4942020-04-14 16:46:13 -07001653 _HOST="$(echo "$WITH_KAFKA" | cut -d: -f1)"
1654 _PORT="$(echo "$WITH_KAFKA" | cut -s -d: -f2)"
David Bainbridge837e8bd2020-04-06 13:17:14 -07001655 _PORT=${_PORT:-9092}
1656 fi
1657 push_onos_config "json" "Push ONOS Kafka Configuration" "network/configuration/apps/org.opencord.kafka" \
David Bainbridged18f4942020-04-14 16:46:13 -07001658 "$(cat <<EOJ | tr -d '[:space:]'
David Bainbridge696bc632020-04-05 21:49:37 -07001659{
1660 "kafka": {
1661 "bootstrapServers": "$_HOST:$_PORT"
1662 }
1663}
1664EOJ
David Bainbridged18f4942020-04-14 16:46:13 -07001665)"
David Bainbridge837e8bd2020-04-06 13:17:14 -07001666 fi
Matteo Scandolo9a77a732020-01-09 14:24:12 -08001667 check_onos_app_active org.opencord.dhcpl2relay
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001668 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 -08001669 check_onos_app_active org.opencord.olt
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001670 # FIXME use WITH_DHCP and WITH_EAPOL flags to configre OLT App
Hardik Windlassa7501fb2020-02-17 14:28:20 +00001671 # Default value for "enableEapol" is true in OLT App
David Bainbridged18f4942020-04-14 16:46:13 -07001672 if [ "$WITH_EAPOL" == "yes" ]; then
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001673 push_onos_config "json" "Enable VOLTHA ONOS EAPOL provisioning" "configuration/org.opencord.olt.impl.OltFlowService" '{"enableEapol":true}'
David Bainbridged18f4942020-04-14 16:46:13 -07001674 elif [ "$WITH_EAPOL" == "no" ]; then
Hardik Windlassa7501fb2020-02-17 14:28:20 +00001675 push_onos_config "json" "Disable VOLTHA ONOS EAPOL provisioning" "configuration/org.opencord.olt.impl.OltFlowService" '{"enableEapol":false}'
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001676 fi
Hardik Windlassa7501fb2020-02-17 14:28:20 +00001677 # Default value for "enableDhcpOnProvisioning" is false and for "enableDhcpV4" is true in OLT App
David Bainbridged18f4942020-04-14 16:46:13 -07001678 if [ "$WITH_DHCP" == "yes" ]; then
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001679 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 -07001680 elif [ "$WITH_DHCP" == "no" ]; then
Hardik Windlassa7501fb2020-02-17 14:28:20 +00001681 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 -08001682 fi
Hardik Windlassa7501fb2020-02-17 14:28:20 +00001683 # Default value for "enableIgmpOnProvisioning" is false in OLT App
David Bainbridged18f4942020-04-14 16:46:13 -07001684 if [ "$WITH_IGMP" == "yes" ]; then
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001685 push_onos_config "json" "Enable VOLTHA ONOS IGMP provisioning" "configuration/org.opencord.olt.impl.OltFlowService" '{"enableIgmpOnProvisioning":true}'
David Bainbridged18f4942020-04-14 16:46:13 -07001686 elif [ "$WITH_IGMP" == "no" ]; then
Hardik Windlassa7501fb2020-02-17 14:28:20 +00001687 push_onos_config "json" "Disable VOLTHA ONOS IGMP provisioning" "configuration/org.opencord.olt.impl.OltFlowService" '{"enableIgmpOnProvisioning":false}'
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001688 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001689 if [ "$ENABLE_ONOS_EXTRANEOUS_RULES" == "yes" ]; then
David K. Bainbridge484d80c2020-03-05 21:44:34 -08001690 push_onos_config "file" "Enabling extraneous rules for ONOS" "configuration/org.onosproject.net.flow.impl.FlowRuleManager" "onos-files/olt-onos-enableExtraneousRules.json"
1691 fi
David Bainbridge60ffc0f2020-04-27 22:13:22 -07001692 if is_in "$CONFIG_SADIS" "yes,file"; then
Matteo Scandolo9a77a732020-01-09 14:24:12 -08001693 check_onos_app_active org.opencord.sadis
Hardik Windlassb3147602020-03-09 16:59:15 +05301694 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 -07001695 elif [ "$CONFIG_SADIS" == "bbsim" ]; then
1696 push_onos_config "json" \
1697 "[optional] Push ONOS configuration for BBSIM SADIS servers" \
1698 "network/configuration/apps/org.opencord.sadis" \
David Bainbridged18f4942020-04-14 16:46:13 -07001699 "$(cat <<EOJ | tr -d '[:space:]'
David K. Bainbridgeb859e912020-03-13 14:07:52 -07001700{
1701 "sadis": {
1702 "integration": {
David Bainbridge76afd812020-04-06 09:53:52 -07001703 "url": "http://bbsim.$BBSIM_NS.svc.cluster.local:50074/v2/subscribers/%s",
David K. Bainbridgeb859e912020-03-13 14:07:52 -07001704 "cache": {
1705 "enabled": true,
1706 "maxsize": 50,
1707 "ttl": "PT1m"
1708 }
1709 }
1710 },
1711 "bandwidthprofile": {
1712 "integration": {
David Bainbridge76afd812020-04-06 09:53:52 -07001713 "url": "http://bbsim.$BBSIM_NS.svc.cluster.local:50074/v2/bandwidthprofiles/%s",
David K. Bainbridgeb859e912020-03-13 14:07:52 -07001714 "cache": {
1715 "enabled": true,
1716 "maxsize": 50,
1717 "ttl": "PT1m"
1718 }
1719 }
1720 }
1721}
1722EOJ
David Bainbridged18f4942020-04-14 16:46:13 -07001723)"
David K. Bainbridgeb859e912020-03-13 14:07:52 -07001724 elif [ "$CONFIG_SADIS" == "url" ]; then
1725 push_onos_config "json" \
1726 "[optional] Push ONOS configuration for custom SADIS and Bandwidth Profile servers" \
1727 "network/configuration/apps/org.opencord.sadis" \
David Bainbridged18f4942020-04-14 16:46:13 -07001728 "$(cat <<EOJ | tr -d '[:space:]'
David K. Bainbridgeb859e912020-03-13 14:07:52 -07001729{
1730 "sadis": {
1731 "integration": {
1732 "url": "$SADIS_SUBSCRIBERS",
1733 "cache": {
1734 "enabled": true,
1735 "maxsize": 50,
1736 "ttl": "PT1m"
1737 }
1738 }
1739 },
1740 "bandwidthprofile": {
1741 "integration": {
1742 "url": "$SADIS_BANDWIDTH_PROFILES",
1743 "cache": {
1744 "enabled": true,
1745 "maxsize": 50,
1746 "ttl": "PT1m"
1747 }
1748 }
1749 }
1750}
1751EOJ
David Bainbridged18f4942020-04-14 16:46:13 -07001752)"
David Bainbridge2b19e832019-08-16 02:40:53 +00001753 fi
Test Userba1e7e72019-07-10 22:27:54 +00001754fi
David Bainbridgee87067b2019-08-12 22:00:12 +00001755if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001756 NOW="$(date +%s)"
1757 printtime $((NOW - STIME))
David Bainbridgee87067b2019-08-12 22:00:12 +00001758fi
Test Userba1e7e72019-07-10 22:27:54 +00001759
David Bainbridged18f4942020-04-14 16:46:13 -07001760if [ "$WITH_ETCD" == "external" ]; then
1761 STIME="$(date +%s)"
David Bainbridge76afd812020-04-06 09:53:52 -07001762 bspin "Verify external ETCD cluster $OLD_KEY"
David Bainbridged18f4942020-04-14 16:46:13 -07001763 EXPECT="$(test "$TYPE" == "minimal" && echo "1" || echo "3")"
1764 if [ "$HELM_USE_UPGRADE" == "yes" ] || [ "$(helm list --deployed --short --namespace "$INFRA_NS" "^etcd-cluster\$" | wc -l)" -ne 1 ]; then
1765 espin "$NOT_VERIFIED"
David Bainbridge76afd812020-04-06 09:53:52 -07001766 INTERNAL_EXTRA_HELM_INSTALL_ARGS+="--set clusterName=etcd-cluster --set autoCompactionRetention=1 --set clusterSize=$EXPECT"
David Bainbridged18f4942020-04-14 16:46:13 -07001767 helm_install - "$INFRA_NS" etcd-cluster onf/voltha-etcd-cluster latest "$_HELM_DESC external ETCD cluster"
David Bainbridge76afd812020-04-06 09:53:52 -07001768 else
David Bainbridged18f4942020-04-14 16:46:13 -07001769 espin "$VERIFIED"
David Bainbridge76afd812020-04-06 09:53:52 -07001770 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001771 wait_for_pods - "$INFRA_NS" "$EXPECT" "includes" "Waiting for ETCD cluster to start" "$NO_LABEL" "etcd-cluster-.*"
David Bainbridge76afd812020-04-06 09:53:52 -07001772 if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001773 NOW="$(date +%s)"
1774 printtime $((NOW - STIME))
David Bainbridge76afd812020-04-06 09:53:52 -07001775 fi
1776fi
1777
David Bainbridged18f4942020-04-14 16:46:13 -07001778if [ "$WITH_KAFKA" == "external" ]; then
1779 _TMP="$(mktemp -u)"
1780 _COUNT="$(test "$TYPE" == "minimal" && echo "1" || echo "3")"
1781 cat << EOC > "$_TMP"
David Bainbridge76afd812020-04-06 09:53:52 -07001782configurationOverrides:
1783 "default.replication.factor": $_COUNT
1784 "offsets.topic.replication.factor": $_COUNT
1785 "log.retention.hours": 4
1786 "log.message.timestamp.type": "LogAppendTime"
1787persistence:
1788 enabled: false
1789zookeeper:
1790 replicaCount: 1
1791 persistence:
1792 enabled: false
1793replicas: $_COUNT
1794EOC
David Bainbridged18f4942020-04-14 16:46:13 -07001795 STIME="$(date +%s)"
David Bainbridge76afd812020-04-06 09:53:52 -07001796 bspin "Verify external Kafka cluster $OLD_KEY"
David Bainbridged18f4942020-04-14 16:46:13 -07001797 EXPECT="$(test "$TYPE" == "minimal" && echo "2" || echo "4")"
1798 if [ "$HELM_USE_UPGRADE" == "yes" ] || [ "$(helm list --deployed --short --namespace "$INFRA_NS" "^kafka\$" | wc -l)" -ne 1 ]; then
1799 espin "$NOT_VERIFIED"
David Bainbridge76afd812020-04-06 09:53:52 -07001800 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" -f $_TMP"
David Bainbridgecf546362020-04-21 23:18:50 -07001801 helm_install - "$INFRA_NS" kafka "$KAFKA_CHART" "$KAFKA_CHART_VERSION" "$_HELM_DESC external Kafka cluster"
David Bainbridge76afd812020-04-06 09:53:52 -07001802 else
David Bainbridged18f4942020-04-14 16:46:13 -07001803 espin "$VERIFIED"
David Bainbridge76afd812020-04-06 09:53:52 -07001804 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001805 wait_for_pods - "$INFRA_NS" "$EXPECT" "includes" "Waiting for Kafka cluster to start" "$NO_LABEL" "kafka-.*"
David Bainbridge76afd812020-04-06 09:53:52 -07001806 if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001807 NOW="$(date +%s)"
1808 printtime $((NOW - STIME))
David Bainbridge76afd812020-04-06 09:53:52 -07001809 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001810 rm -rf "$_TMP"
David Bainbridge76afd812020-04-06 09:53:52 -07001811fi
1812
David Bainbridged18f4942020-04-14 16:46:13 -07001813STIME="$(date +%s)"
David Bainbridge696bc632020-04-05 21:49:37 -07001814EXPECT=1
1815if [ "$ONLY_ONE" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001816 EXPECT="$((EXPECT+1))"
David Bainbridge696bc632020-04-05 21:49:37 -07001817 INTERNAL_EXTRA_HELM_INSTALL_ARGS="--set therecanbeonlyone=true"
1818else
David Bainbridged18f4942020-04-14 16:46:13 -07001819 EXPECT="$((EXPECT+2))"
David Bainbridge696bc632020-04-05 21:49:37 -07001820fi
Matteo Scandolo67335f02020-04-09 11:19:53 -07001821case $WITH_ETCD in
David Bainbridge76afd812020-04-06 09:53:52 -07001822 no)
1823 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set private_etcd_cluster=false"
1824 ;;
1825 yes)
1826 _HOST="voltha-etcd-cluster-client.$VOLTHA_NS.svc.cluster.local"
1827 _PORT=2379
1828 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set services.etcd.service=$_HOST --set services.etcd.port=$_PORT"
David Bainbridged18f4942020-04-14 16:46:13 -07001829 EXPECT="$((EXPECT+$(test "$TYPE" == "minimal" && echo "1" || echo "3")))"
David Bainbridge76afd812020-04-06 09:53:52 -07001830 ;;
1831 external)
1832 _HOST="etcd-cluster-client.$INFRA_NS.svc.cluster.local"
1833 _PORT=2379
1834 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set private_etcd_cluster=false --set services.etcd.service=$_HOST --set services.etcd.port=$_PORT"
1835 ;;
1836 *)
David Bainbridged18f4942020-04-14 16:46:13 -07001837 _HOST="$(echo "$WITH_ETCD" | cut -d: -f1)"
1838 _PORT="$(echo "$WITH_ETCD" | cut -s -d: -f2)"
David Bainbridge696bc632020-04-05 21:49:37 -07001839 _PORT=${_PORT:-2379}
David Bainbridge76afd812020-04-06 09:53:52 -07001840 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set private_etcd_cluster=false --set services.etcd.service=$_HOST --set services.etcd.port=$_PORT"
1841 ;;
1842esac
1843case $WITH_KAFKA in
1844 no)
1845 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set private_kafka_cluster=false"
1846 ;;
1847 yes)
1848 _HOST=voltha-kafka.$VOLTHA_NS.svc.cluster.local
1849 _PORT=9092
1850 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 -07001851 EXPECT="$((EXPECT+$(test "$TYPE" == "minimal" && echo "2" || echo "4")))"
David Bainbridge76afd812020-04-06 09:53:52 -07001852 ;;
1853 external)
1854 _HOST=kafka.$INFRA_NS.svc.cluster.local
1855 _PORT=9092
1856 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"
1857 ;;
1858 *)
David Bainbridged18f4942020-04-14 16:46:13 -07001859 _HOST="$(echo "$WITH_KAFKA" | cut -d: -f1)"
1860 _PORT="$(echo "$WITH_KAFKA" | cut -s -d: -f2)"
David Bainbridge696bc632020-04-05 21:49:37 -07001861 _PORT=${_PORT:-9092}
David Bainbridge76afd812020-04-06 09:53:52 -07001862 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"
1863 ;;
1864esac
1865
David Bainbridge60ffc0f2020-04-27 22:13:22 -07001866if is_in "$WITH_ONOS" "legacy"; then
David Bainbridge76afd812020-04-06 09:53:52 -07001867 _HOST=onos-openflow.$INFRA_NS.svc.cluster.local
1868 _PORT=6653
David Bainbridge60ffc0f2020-04-27 22:13:22 -07001869elif is_in "$WITH_ONOS" "yes,classic"; then
1870 _HOST=onos-onos-classic-hs.$INFRA_NS.svc.cluster.local
1871 _PORT=6653
David Bainbridged18f4942020-04-14 16:46:13 -07001872elif [ "$WITH_ONOS" != "no" ]; then
1873 _HOST="$(echo "$WITH_ONOS" | cut -d: -f1)"
1874 _PORT="$(echo "$WITH_ONOS" | cut -s -d: -f2)"
David Bainbridge76afd812020-04-06 09:53:52 -07001875 _PORT=${_PORT:-6653}
Jonathan Hart6a91e6c2020-04-16 14:28:33 -07001876fi
David Bainbridge60ffc0f2020-04-27 22:13:22 -07001877
David Bainbridgecf546362020-04-21 23:18:50 -07001878compare_versions "$RESOLVED_VOLTHA_CHART_VERSION" 2.4.2
Jonathan Hart6a91e6c2020-04-16 14:28:33 -07001879if [ "$?" == "1" ]; then
1880 # voltha chart > 2.4.2 uses list of controllers
1881 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set services.controller[0].service=$_HOST --set services.controller[0].port=$_PORT"
1882else
1883 # voltha chart <= 2.4.2 uses single controller
David Bainbridge76afd812020-04-06 09:53:52 -07001884 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set services.controller.service=$_HOST --set services.controller.port=$_PORT"
David Bainbridge696bc632020-04-05 21:49:37 -07001885fi
Jonathan Hart6a91e6c2020-04-16 14:28:33 -07001886
Test Userb5712372019-07-03 21:52:17 +00001887bspin "Verify VOLTHA installed $HIGH_VOLTAGE"
David Bainbridged18f4942020-04-14 16:46:13 -07001888if [ "$HELM_USE_UPGRADE" == "yes" ] || [ "$(helm list --deployed --short --namespace "$VOLTHA_NS" "^voltha\$" | wc -l)" -ne 1 ]; then
1889 espin "$NOT_VERIFIED"
1890 helm_install - "$VOLTHA_NS" voltha "$VOLTHA_CHART" "$VOLTHA_CHART_VERSION" "$_HELM_DESC VOLTHA Core"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001891else
David Bainbridged18f4942020-04-14 16:46:13 -07001892 espin "$VERIFIED"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001893fi
David Bainbridge696bc632020-04-05 21:49:37 -07001894INTERNAL_EXTRA_HELM_INSTALL_ARGS=
Test Userba1e7e72019-07-10 22:27:54 +00001895
David Bainbridge90fd8e32019-08-21 23:32:47 +00001896VOLTHA="voltha-ofagent-.* \
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001897 rw-core.* \
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001898 voltha-etcd-cluster-.* \
1899 voltha-kafka-.* \
1900 voltha-zookeeper-.*"
David Bainbridged18f4942020-04-14 16:46:13 -07001901wait_for_pods - "$VOLTHA_NS" "$EXPECT" "includes" "Waiting for VOLTHA Core to start" "$NO_LABEL" "$VOLTHA"
David Bainbridgee87067b2019-08-12 22:00:12 +00001902if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001903 NOW="$(date +%s)"
1904 printtime $((NOW - STIME))
David Bainbridgee87067b2019-08-12 22:00:12 +00001905fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001906
David Bainbridge46505fb2019-10-01 21:13:20 +00001907if [ "$WITH_ADAPTERS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001908 STIME="$(date +%s)"
David Bainbridge46505fb2019-10-01 21:13:20 +00001909 EXPECT=0
David Bainbridged18f4942020-04-14 16:46:13 -07001910 if [ "$WITH_ETCD" == "yes" ]; then
David Bainbridge3517f6c2020-04-08 12:14:08 -07001911 _HOST=voltha-etcd-cluster-client.$VOLTHA_NS.svc.cluster.local
1912 _PORT=2379
1913 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set services.etcd.service=$_HOST --set services.etcd.port=$_PORT"
David Bainbridged18f4942020-04-14 16:46:13 -07001914 elif [ "$WITH_ETCD" == "external" ]; then
David Bainbridge3517f6c2020-04-08 12:14:08 -07001915 _HOST=etcd-cluster-client.$INFRA_NS.svc.cluster.local
1916 _PORT=2379
1917 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set services.etcd.service=$_HOST --set services.etcd.port=$_PORT"
David Bainbridged18f4942020-04-14 16:46:13 -07001918 elif [ "$WITH_ETCD" != "no" ]; then
1919 _HOST="$(echo "$WITH_ETCD" | cut -d: -f1)"
1920 _PORT="$(echo "$WITH_ETCD" | cut -s -d: -f2)"
David Bainbridge3517f6c2020-04-08 12:14:08 -07001921 _PORT=${_PORT:-2379}
1922 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set services.etcd.service=$_HOST --set services.etcd.port=$_PORT"
David Bainbridge696bc632020-04-05 21:49:37 -07001923 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001924 if [ "$WITH_KAFKA" == "yes" ]; then
David Bainbridge3517f6c2020-04-08 12:14:08 -07001925 _HOST=voltha-kafka.$VOLTHA_NS.svc.cluster.local
1926 _PORT=9092
1927 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 -07001928 elif [ "$WITH_KAFKA" == "external" ]; then
David Bainbridge3517f6c2020-04-08 12:14:08 -07001929 _HOST=kafka.$INFRA_NS.svc.cluster.local
1930 _PORT=9092
1931 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 -07001932 elif [ "$WITH_KAFKA" != "no" ]; then
1933 _HOST="$(echo "$WITH_KAFKA" | cut -d: -f1)"
1934 _PORT="$(echo "$WITH_KAFKA" | cut -s -d: -f2)"
David Bainbridge3517f6c2020-04-08 12:14:08 -07001935 _PORT=${_PORT:-9092}
1936 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 -07001937 fi
David Bainbridge46505fb2019-10-01 21:13:20 +00001938 echo -e "Verify Adapters $PLUG"
1939 if [ "$WITH_SIM_ADAPTERS" == "yes" ]; then
1940 bspin - "Verify Simulated Adapters installed"
David Bainbridged18f4942020-04-14 16:46:13 -07001941 if [ "$HELM_USE_UPGRADE" == "yes" ] || [ "$(helm list --deployed --short --namespace "$ADAPTER_NS" "^sim\$" | wc -l)" -ne 1 ]; then
1942 espin - "$NOT_VERIFIED"
1943 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 +00001944 else
David Bainbridged18f4942020-04-14 16:46:13 -07001945 espin - "$VERIFIED"
David Bainbridge46505fb2019-10-01 21:13:20 +00001946 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001947 EXPECT="$((EXPECT + 2))"
David Bainbridge46505fb2019-10-01 21:13:20 +00001948 fi
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001949
David Bainbridge46505fb2019-10-01 21:13:20 +00001950 if [ "$WITH_OPEN_ADAPTERS" == "yes" ]; then
1951 bspin - "Verify OpenOLT Adapter installed"
David Bainbridged18f4942020-04-14 16:46:13 -07001952 if [ "$HELM_USE_UPGRADE" == "yes" ] || [ "$(helm list --deployed --short --namespace "$ADAPTER_NS" "^open-olt\$" | wc -l)" -ne 1 ]; then
1953 espin - "$NOT_VERIFIED"
1954 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 +00001955 else
David Bainbridged18f4942020-04-14 16:46:13 -07001956 espin - "$VERIFIED"
David Bainbridge46505fb2019-10-01 21:13:20 +00001957 fi
Matteo Scandolo67335f02020-04-09 11:19:53 -07001958 EXPECT="$((EXPECT + 1))"
David Bainbridge46505fb2019-10-01 21:13:20 +00001959 bspin - "Verify OpenONU Adapter installed"
David Bainbridged18f4942020-04-14 16:46:13 -07001960 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 -07001961 _ORIGINAL_EXTRA_HELM_INSTALL_ARGS="$INTERNAL_EXTRA_HELM_INSTALL_ARGS"
1962 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set replicas.adapter_open_onu=$NUM_OF_OPENONU"
David Bainbridged18f4942020-04-14 16:46:13 -07001963 espin - "$NOT_VERIFIED"
Matteo Scandolo67335f02020-04-09 11:19:53 -07001964 helm_install - "$ADAPTER_NS" open-onu "$VOLTHA_ADAPTER_OPEN_ONU_CHART" "$VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION" "$_HELM_DESC OpenONU Adapter"
1965 INTERNAL_EXTRA_HELM_INSTALL_ARGS="$_ORIGINAL_EXTRA_HELM_INSTALL_ARGS"
David Bainbridge46505fb2019-10-01 21:13:20 +00001966 else
David Bainbridged18f4942020-04-14 16:46:13 -07001967 espin - "$VERIFIED"
David Bainbridge46505fb2019-10-01 21:13:20 +00001968 fi
Matteo Scandolo67335f02020-04-09 11:19:53 -07001969 EXPECT=$((EXPECT + NUM_OF_OPENONU))
David Bainbridge46505fb2019-10-01 21:13:20 +00001970 fi
David Bainbridge696bc632020-04-05 21:49:37 -07001971 INTERNAL_EXTRA_HELM_INSTALL_ARGS=
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001972
David Bainbridge46505fb2019-10-01 21:13:20 +00001973 ADAPTERS="adapter-.*"
David Bainbridged18f4942020-04-14 16:46:13 -07001974 wait_for_pods - "$ADAPTER_NS" "$EXPECT" "includes" "Waiting for adapters to start" "$NO_LABEL" "$ADAPTERS"
David Bainbridge46505fb2019-10-01 21:13:20 +00001975 if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001976 NOW="$(date +%s)"
1977 printtime $((NOW - STIME))
David Bainbridge46505fb2019-10-01 21:13:20 +00001978 fi
David Bainbridgee87067b2019-08-12 22:00:12 +00001979fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001980
David Bainbridged18f4942020-04-14 16:46:13 -07001981if [ "$WITH_BBSIM" == "yes" ]; then
1982 STIME="$(date +%s)"
Test User7d866122019-07-09 17:52:35 +00001983 echo -e "Verify BBSIM $PLUG"
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001984 bspin - "Verify BBSIM Installed"
David Bainbridged18f4942020-04-14 16:46:13 -07001985 for instance in $(seq 0 $((NUM_OF_BBSIM-1))); do
1986 if [ "$instance" -eq 0 ]; then
David K. Bainbridge43422402020-03-06 07:41:22 -08001987 instance_num=""
1988 else
1989 instance_num=$instance
1990 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001991 if [ "$HELM_USE_UPGRADE" == "yes" ] || [ "$(helm list --deployed --short --namespace "$BBSIM_NS" "^bbsim${instance_num}\$" | wc -l)" -ne 1 ]; then
1992 espin - "$NOT_VERIFIED"
1993 S_TAG="$((900+instance))"
Matteo Scandolo5a149572020-04-01 10:14:57 -07001994 INTERNAL_EXTRA_HELM_INSTALL_ARGS="--set olt_id=$instance,s_tag=$S_TAG"
David Bainbridged9329af2020-05-01 11:58:52 -07001995 if [ "$WITH_EAPOL" == "yes" ]; then
1996 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set auth=true"
1997 else
1998 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set auth=false"
1999 fi
2000 if [ "$WITH_DHCP" == "yes" ]; then
2001 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set dhcp=true"
2002 else
2003 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set dhcp=false"
2004 fi
David Bainbridged18f4942020-04-14 16:46:13 -07002005 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 -07002006 INTERNAL_EXTRA_HELM_INSTALL_ARGS=
David K. Bainbridge43422402020-03-06 07:41:22 -08002007 else
David Bainbridged18f4942020-04-14 16:46:13 -07002008 espin - "$VERIFIED"
David K. Bainbridge43422402020-03-06 07:41:22 -08002009 fi
2010 done
David Bainbridged18f4942020-04-14 16:46:13 -07002011 wait_for_pods - "$BBSIM_NS" "$NUM_OF_BBSIM" "includes" "Waiting for BBSIM to start" "$BBSIM_LABEL" "bbsim*"
David Bainbridgee87067b2019-08-12 22:00:12 +00002012 if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07002013 NOW="$(date +%s)"
2014 printtime $((NOW - STIME))
David Bainbridgee87067b2019-08-12 22:00:12 +00002015 fi
Test User7d866122019-07-09 17:52:35 +00002016fi
2017
David Bainbridged18f4942020-04-14 16:46:13 -07002018if [ "$WITH_RADIUS" == "yes" ]; then
2019 STIME="$(date +%s)"
David Bainbridge5b7b96b2019-07-25 20:29:13 +00002020 echo -e "Verify RADIUS $LOCK"
2021 bspin - "Verify RADIUS Installed"
David Bainbridged18f4942020-04-14 16:46:13 -07002022 if [ "$HELM_USE_UPGRADE" == "yes" ] || [ "$(helm list --deployed --short --namespace "$INFRA_NS" "^radius\$" | wc -l)" -ne 1 ]; then
2023 espin - "$NOT_VERIFIED"
2024 helm_install - "$INFRA_NS" radius onf/freeradius latest "$_HELM_DESC RADIUS"
David Bainbridge5b7b96b2019-07-25 20:29:13 +00002025 else
David Bainbridged18f4942020-04-14 16:46:13 -07002026 espin - "$VERIFIED"
David Bainbridge5b7b96b2019-07-25 20:29:13 +00002027 fi
David Bainbridged18f4942020-04-14 16:46:13 -07002028 wait_for_pods - "$INFRA_NS" 1 "includes" "Waiting for RADIUS to start" "$NO_LABEL" "radius-.*"
David Bainbridgee87067b2019-08-12 22:00:12 +00002029 if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07002030 NOW="$(date +%s)"
2031 printtime $((NOW - STIME))
David Bainbridgee87067b2019-08-12 22:00:12 +00002032 fi
David Bainbridge5b7b96b2019-07-25 20:29:13 +00002033fi
2034
David Bainbridged18f4942020-04-14 16:46:13 -07002035if [ "$WITH_PORT_FORWARDS" == "yes" ]; then
2036 STIME="$(date +%s)"
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -08002037 bspin - "Forward VOLTHA API port $FORWARD"
2038 kill_port_forward voltha-api
David Bainbridge60ffc0f2020-04-27 22:13:22 -07002039 port_forward "$VOLTHA_NS" voltha-api "$VOLTHA_API_PORT:55555"
David Bainbridged18f4942020-04-14 16:46:13 -07002040 espin - "$VERIFIED"
2041 if [ "$WITH_ETCD" == "yes" ] || [ "$WITH_ETCD" == "external" ]; then
2042 _NS="$(test "$WITH_ETCD" == "yes" && echo "$VOLTHA_NS" || echo "$INFRA_NS")"
David Bainbridge696bc632020-04-05 21:49:37 -07002043 bspin - "Forward VOLTHA ETCD port $FORWARD"
David Bainbridged18f4942020-04-14 16:46:13 -07002044 kill_port_forward "${ETCD_PREFIX}etcd-cluster-client"
David Bainbridge60ffc0f2020-04-27 22:13:22 -07002045 port_forward "$_NS" "${ETCD_PREFIX}etcd-cluster-client" "$VOLTHA_ETCD_PORT:2379"
David Bainbridged18f4942020-04-14 16:46:13 -07002046 espin - "$VERIFIED"
David Bainbridge696bc632020-04-05 21:49:37 -07002047 fi
David Bainbridged18f4942020-04-14 16:46:13 -07002048 if [ "$WITH_KAFKA" == "yes" ] || [ $WITH_KAFKA == "external" ]; then
2049 _NS="$(test "$WITH_ETCD" == "yes" && echo "$VOLTHA_NS" || echo "$INFRA_NS")"
David Bainbridge696bc632020-04-05 21:49:37 -07002050 bspin - "Forward VOLTHA Kafka port $FORWARD"
David Bainbridged18f4942020-04-14 16:46:13 -07002051 kill_port_forward "${KAFKA_PREFIX}kafka"
David Bainbridge60ffc0f2020-04-27 22:13:22 -07002052 port_forward "$_NS" ${KAFKA_PREFIX}kafka "$VOLTHA_KAFKA_PORT:9092"
David Bainbridged18f4942020-04-14 16:46:13 -07002053 espin - "$VERIFIED"
David Bainbridge696bc632020-04-05 21:49:37 -07002054 fi
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -08002055 if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07002056 NOW="$(date +%s)"
2057 printtime $((NOW - STIME))
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -08002058 fi
David Bainbridgee87067b2019-08-12 22:00:12 +00002059fi
Test User3d7ad8e2019-07-03 06:15:44 +00002060
David Bainbridge60ffc0f2020-04-27 22:13:22 -07002061if is_in "$WITH_ONOS" "yes,legacy,classic" && [ "$WITH_RADIUS" != "no" ]; then
David Bainbridge76afd812020-04-06 09:53:52 -07002062 _HOST=radius.$INFRA_NS.svc.cluster.local
David Bainbridge696bc632020-04-05 21:49:37 -07002063 _PORT=1812
David Bainbridged18f4942020-04-14 16:46:13 -07002064 if [ "$WITH_RADIUS" != "yes" ]; then
2065 _HOST="$(echo "$WITH_RADIUS" | cut -d: -f1)"
2066 _PORT="$(echo "$WITH_RADIUS" | cut -s -d: -f2)"
David Bainbridge696bc632020-04-05 21:49:37 -07002067 _PORT=${_PORT:-1812}
2068 fi
David Bainbridge5b7b96b2019-07-25 20:29:13 +00002069 bspin "Configure ONOS RADIUS Connection $GEAR"
David Bainbridged18f4942020-04-14 16:46:13 -07002070 (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
2071 espin "$VERIFIED"
David Bainbridge5b7b96b2019-07-25 20:29:13 +00002072fi
2073
David Bainbridge99ac7a22019-08-31 02:26:43 +00002074if [ "$WITH_CHAOS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07002075 STIME="$(date +%s)"
David Bainbridge99ac7a22019-08-31 02:26:43 +00002076 echo -e "Verify kube-monkey $LOCK"
2077 bspin - "Verify kube-monkey Installed"
David Bainbridged18f4942020-04-14 16:46:13 -07002078 if [ "$HELM_USE_UPGRADE" == "yes" ] || [ "$(helm list --deployed --short --namespace kube-monkey "^monkey\$" | wc -l)" -ne 1 ]; then
2079 espin - "$NOT_VERIFIED"
David Bainbridge7f8bf992020-04-08 21:53:22 -07002080 helm_install - kube-monkey monkey ./kube-monkey/helm/kubemonkey latest "$_HELM_DESC Chaos Monkey"
David Bainbridge99ac7a22019-08-31 02:26:43 +00002081 else
David Bainbridged18f4942020-04-14 16:46:13 -07002082 espin - "$VERIFIED"
David Bainbridge99ac7a22019-08-31 02:26:43 +00002083 fi
David Bainbridged18f4942020-04-14 16:46:13 -07002084 wait_for_pods - "kube-monkey" 1 "includes" "Waiting for Chaos to start" "$NO_LABEL" "monkey-.*"
David Bainbridge99ac7a22019-08-31 02:26:43 +00002085 if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07002086 NOW="$(date +%s)"
2087 printtime $((NOW - STIME))
David Bainbridge99ac7a22019-08-31 02:26:43 +00002088 fi
2089fi
2090
David Bainbridge5b7b96b2019-07-25 20:29:13 +00002091bspin "Create voltctl configuration file"
David Bainbridged18f4942020-04-14 16:46:13 -07002092(set -x; mkdir -p "$HOME/.volt" >>"$LOG" 2>&1) >>"$LOG" 2>&1
2093MIN_VC_VERSION="$(echo -e "1.0.15\n$VC_VERSION" | sort -V | head -1)"
2094if [ "$WITH_PORT_FORWARDS" == "yes" ]; then
David K. Bainbridgeb859e912020-03-13 14:07:52 -07002095 KAFKA_FLAG="-k localhost:$VOLTHA_KAFKA_PORT"
2096 SERVER_FLAG="-s localhost:$VOLTHA_API_PORT"
2097 ETCD_FLAG=
2098 if [ "$MIN_VC_VERSION" == "1.0.15" ]; then
2099 ETCD_FLAG="-e localhost:$VOLTHA_ETCD_PORT"
2100 fi
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -08002101else
David Bainbridged18f4942020-04-14 16:46:13 -07002102 KAFKA_FLAG="-k $(get_service_ep "$INFRA_NS" "${KAFKA_PREFIX}kafka")"
2103 SERVER_FLAG="-s $(get_service_ep "$VOLTHA_NS" voltha-api)"
David K. Bainbridgeb859e912020-03-13 14:07:52 -07002104 ETCD_FLAG=
2105 if [ "$MIN_VC_VERSION" == "1.0.15" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07002106 ETCD_FLAG="-e $(get_service_ep "$INFRA_NS" ${ETCD_PREFIX}etcd-client)"
David K. Bainbridgeb859e912020-03-13 14:07:52 -07002107 fi
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -08002108fi
David Bainbridged18f4942020-04-14 16:46:13 -07002109CMD=("voltctl -a v3 $KAFKA_FLAG $SERVER_FLAG $ETCD_FLAG config")
2110(set -x; ${CMD[*]} > "$HOME/.volt/config-$NAME" 2>>"$LOG") >>"$LOG" 2>&1
2111#(set -x; voltctl -a v3 "$KAFKA_FLAG" "$SERVER_FLAG" "$ETCD_FLAG" config > "$HOME/.volt/config-$NAME" 2>>"$LOG") >>"$LOG" 2>&1
2112espin "$VERIFIED"
Test User08ebbd92019-07-03 17:15:39 +00002113
David Bainbridge0774b232019-08-02 06:37:19 +00002114if [ ! -f "$NAME-env.sh" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07002115 touch "$NAME-env.sh"
David Bainbridgeb07fdf72019-07-29 22:51:40 +00002116fi
2117
David Bainbridge596f30d2019-07-30 17:07:59 +00002118for O in $ALL_OPTIONS; do
David Bainbridged18f4942020-04-14 16:46:13 -07002119 VAL="$(eval echo "\$$O")"
2120 if [ -n "$VAL" ] && [ "$(grep -c "^export $O=" "$NAME-env.sh")" -eq 0 ]; then
2121 echo "export $O=\"$(eval echo "\$$O")\"" >> "$NAME-env.sh"
David Bainbridgeb07fdf72019-07-29 22:51:40 +00002122 fi
2123done
2124
David Bainbridged18f4942020-04-14 16:46:13 -07002125if [ "$DEPLOY_K8S" == "yes" ] && [ "$(grep -c "^export KUBECONFIG=" "$NAME-env.sh")" -eq 0 ]; then
2126 echo "export KUBECONFIG=\"$(./bin/kind get kubeconfig-path "--name=voltha-$NAME")\"" >> "$NAME-env.sh"
David Bainbridgeb07fdf72019-07-29 22:51:40 +00002127fi
2128
David Bainbridged18f4942020-04-14 16:46:13 -07002129if [ "$(grep -c "^export VOLTCONFIG=" "$NAME-env.sh")" -eq 0 ]; then
2130 echo "export VOLTCONFIG=\"$HOME/.volt/config-$NAME\"" >> "$NAME-env.sh"
David Bainbridgeb07fdf72019-07-29 22:51:40 +00002131fi
2132
David Bainbridged18f4942020-04-14 16:46:13 -07002133if [ "$(grep -c "^export PATH=" "$NAME-env.sh")" -eq 0 ]; then
2134 echo "export PATH=\"$GOPATH/bin:\$PATH\"" >> "$NAME-env.sh"
David Bainbridgeb07fdf72019-07-29 22:51:40 +00002135fi
2136
Test User7d866122019-07-09 17:52:35 +00002137echo ""
David Bainbridged18f4942020-04-14 16:46:13 -07002138echo "Please issue the following commands in your terminal to ensure that you" | tee -a "$LOG"
2139echo "are accessing the correct Kubernetes/Kind cluster as well as have the " | tee -a "$LOG"
2140echo "tools required by VOLTHA in your command path. " | tee -a "$LOG"
2141echo "" | tee -a "$LOG"
2142echo -en "$BOLD"
2143if [ "$DEPLOY_K8S" == "yes" ]; then
2144 echo "export KUBECONFIG=\"\$(./bin/kind get kubeconfig-path --name=\"voltha-$NAME\")\"" | tee -a "$LOG"
Test Userba1e7e72019-07-10 22:27:54 +00002145fi
David Bainbridged18f4942020-04-14 16:46:13 -07002146echo "export VOLTCONFIG=\"$HOME/.volt/config-$NAME\"" | tee -a "$LOG"
2147echo "export PATH=$GOPATH/bin:\$PATH" | tee -a "$LOG"
2148echo -en "$NORMAL"
2149echo "" | tee -a "$LOG"
2150echo "Thank you for choosing kind-voltha for you quick cluster needs." | tee -a "$LOG"
Test User08ebbd92019-07-03 17:15:39 +00002151
David Bainbridge712afb82019-08-14 19:55:58 +00002152if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07002153 NOW="$(date +%s)"
2154 echo -e "$CLOCK ${BOLD}TOTAL: $(duration $((NOW - TOTAL_START_TIME)))${NORMAL}"
David Bainbridge712afb82019-08-14 19:55:58 +00002155fi