blob: b07022971236cd5d283ed5fecb332c89a58ed3f7 [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}
Matteo Scandoloefee0432020-05-05 13:56:20 -070089WITH_PPROF=${WITH_PPROF:-no}
David Bainbridge05cd8822019-11-19 17:43:53 +000090ONLY_ONE=${ONLY_ONE:-yes}
David Bainbridge309099c2020-05-05 08:47:29 -070091CONFIG_SADIS=${CONFIG_SADIS:-no} # yes | no | file | bbsim | external | URL
David Bainbridge76afd812020-04-06 09:53:52 -070092SADIS_SUBSCRIBERS=${SADIS_SUBSCRIBERS:-http://bbsim.$VOLTHA_NS.svc:50074/v2/subscribers/%s}
93SADIS_BANDWIDTH_PROFILES=${SADIS_BANDWIDTH_PROFILES:-http://bbsim.$VOLTHA_NS.svc:50074/v2/bandwidthprofiles/%s}
Hardik Windlassb3147602020-03-09 16:59:15 +053094SADIS_CFG=${SADIS_CFG:-onos-files/onos-sadis-sample.json}
David Bainbridge27790d62019-08-13 22:43:19 +000095INSTALL_ONOS_APPS=${INSTALL_ONOS_APPS:-no}
Test Userba1e7e72019-07-10 22:27:54 +000096JUST_K8S=${JUST_K8S:-no}
97DEPLOY_K8S=${DEPLOY_K8S:-yes}
David K. Bainbridge0e89cb92019-07-17 11:30:10 -070098INSTALL_KUBECTL=${INSTALL_KUBECTL:-yes}
99INSTALL_HELM=${INSTALL_HELM:-yes}
David Bainbridge7f8bf992020-04-08 21:53:22 -0700100HELM_USE_UPGRADE=${HELM_USE_UPGRADE:-no}
David Bainbridge46505fb2019-10-01 21:13:20 +0000101UPDATE_HELM_REPOS=${UPDATE_HELM_REPOS:-yes}
Matteo Scandolofab98622020-01-28 15:17:20 -0800102WAIT_ON_DOWN=${WAIT_ON_DOWN:-yes}
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700103WAIT_TIMEOUT=${WAIT_TIMEOUT:-30m}
104VOLTHA_DOWN_ON_TIMEOUT=${VOLTHA_DOWN_ON_TIMEOUT:-no}
David Bainbridge5b7b96b2019-07-25 20:29:13 +0000105VOLTHA_LOG_LEVEL=${VOLTHA_LOG_LEVEL:-WARN}
David Bainbridge90fd8e32019-08-21 23:32:47 +0000106VOLTHA_CHART=${VOLTHA_CHART:-onf/voltha}
107VOLTHA_CHART_VERSION=${VOLTHA_CHART_VERSION:-latest}
108VOLTHA_BBSIM_CHART=${VOLTHA_BBSIM_CHART:-onf/bbsim}
Matteo Scandolodcd29f52019-10-07 15:42:42 -0700109VOLTHA_BBSIM_CHART_VERSION=${VOLTHA_BBSIM_CHART_VERSION:-latest}
David Bainbridgee10f6d52019-07-25 00:28:13 +0000110VOLTHA_ADAPTER_SIM_CHART=${VOLTHA_ADAPTER_SIM_CHART:-onf/voltha-adapter-simulated}
David Bainbridge90fd8e32019-08-21 23:32:47 +0000111VOLTHA_ADAPTER_SIM_CHART_VERSION=${VOLTHA_ADAPTER_SIM_CHART_VERSION:-latest}
David Bainbridgee10f6d52019-07-25 00:28:13 +0000112VOLTHA_ADAPTER_OPEN_OLT_CHART=${VOLTHA_ADAPTER_OPEN_OLT_CHART:-onf/voltha-adapter-openolt}
David Bainbridge90fd8e32019-08-21 23:32:47 +0000113VOLTHA_ADAPTER_OPEN_OLT_CHART_VERSION=${VOLTHA_ADAPTER_OPEN_OLT_CHART_VERSION:-latest}
David Bainbridgee10f6d52019-07-25 00:28:13 +0000114VOLTHA_ADAPTER_OPEN_ONU_CHART=${VOLTHA_ADAPTER_OPEN_ONU_CHART:-onf/voltha-adapter-openonu}
David Bainbridge90fd8e32019-08-21 23:32:47 +0000115VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION=${VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION:-latest}
David K. Bainbridgeda33d652020-03-06 10:31:23 -0800116ONOS_CHART=${ONOS_CHART:-onf/onos}
Andrea Campanella21323292019-12-18 11:44:19 -0800117ONOS_CHART_VERSION=${ONOS_CHART_VERSION:-latest}
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700118ONOS_CLASSIC_CHART=${ONOS_CLASSIC_CHART:-onos/onos-classic}
119ONOS_CLASSIC_CHART_VERSION=${ONOS_CHART_VERSION:-latest}
David Bainbridgecf546362020-04-21 23:18:50 -0700120KAFKA_CHART=${KAFKA_CHART:-incubator/kafka}
David Bainbridgeb9093522020-04-15 14:32:44 -0700121KAFKA_CHART_VERSION=${KAFKA_CHART_VERSION:=0.15.3}
David Bainbridge309099c2020-05-05 08:47:29 -0700122BBSIM_SADIS_SERVER_CHART=${BBSIM_SADIS_SERVER_CHART:-bbsim-sadis/bbsim-sadis-server}
123BBSIM_SADIS_SERVER_CHART_VERSION=${BBSIM_SADIS_SERVER_CHART_VERSION:-latest}
David Bainbridge2eaf2cf2020-03-18 12:54:08 -0700124EXTRA_HELM_INSTALL_ARGS=${EXTRA_HELM_INSTALL_ARGS:-}
125INTERNAL_EXTRA_HELM_INSTALL_ARGS=
uottrembb16d3982020-02-28 08:34:36 +0100126NUM_OF_BBSIM=${NUM_OF_BBSIM:-1}
Matteo Scandolo67335f02020-04-09 11:19:53 -0700127NUM_OF_OPENONU=${NUM_OF_OPENONU:-1}
uottrembb16d3982020-02-28 08:34:36 +0100128MAX_NUM_OF_BBSIM=10
Matteo Scandolo67335f02020-04-09 11:19:53 -0700129MAX_NUM_OF_OPENONU=10
Matteo Scandoloc2eb0672020-05-01 14:43:15 -0700130LEGACY_BBSIM_INDEX=${LEGACY_BBSIM_INDEX:-no}
Test Userba1e7e72019-07-10 22:27:54 +0000131
David Bainbridged18f4942020-04-14 16:46:13 -0700132HOSTOS="$(uname -s | tr "[:upper:]" "[:lower:"])"
133HOSTARCH="$(uname -m | tr "[:upper:]" "[:lower:"])"
134if [ "$HOSTARCH" == "x86_64" ]; then
Test Userba1e7e72019-07-10 22:27:54 +0000135 HOSTARCH="amd64"
136fi
David Bainbridge7db44002020-04-09 12:54:29 -0700137BBSIM_LABEL="-l app=bbsim"
David Bainbridged18f4942020-04-14 16:46:13 -0700138NO_LABEL=
Test User7d866122019-07-09 17:52:35 +0000139
uottrembb16d3982020-02-28 08:34:36 +0100140# check number (range) of bbsim, max bbsim must not exceed 10 instances!
141# note: instances will be numbered from 0 to 9
142if [ "$1" == "up" ]; then
David K. Bainbridge43422402020-03-06 07:41:22 -0800143 if [ "$NUM_OF_BBSIM" -lt 1 ]; 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 less than 1${NORMAL}"
David K. Bainbridge43422402020-03-06 07:41:22 -0800145 exit 1
146 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700147 if [ "$NUM_OF_BBSIM" -gt "$MAX_NUM_OF_BBSIM" ]; then
Matteo Scandolo67335f02020-04-09 11:19:53 -0700148 >&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}"
149 exit 1
150 fi
151
152 if [ "$NUM_OF_OPENONU" -lt 1 ]; then
153 >&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}"
154 exit 1
155 fi
156 if [ "$NUM_OF_OPENONU" -gt "$MAX_NUM_OF_OPENONU" ]; then
157 >&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 -0800158 exit 1
159 fi
uottrembb16d3982020-02-28 08:34:36 +0100160fi
Test User7d866122019-07-09 17:52:35 +0000161# Verify TYPE setting
David Bainbridged18f4942020-04-14 16:46:13 -0700162if [ "$(echo ":minimal:full:" | grep -ic ":$TYPE:")" -eq 0 ]; then
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700163 >&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 +0000164 exit 1
165fi
166
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700167# checks to see if a given WORD is in the given LIST of words
168function is_in() {
169 local WORD LIST
170 WORD="$1"; shift
171 LIST="$*"
172 LIST=${LIST//+([[:space:],|])/:}
173
174 [ "$(echo ":$LIST:" | grep -ic ":$WORD:")" -ne 0 ]
175}
176
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700177function parseDuration() {
David Bainbridged18f4942020-04-14 16:46:13 -0700178 local DUR RESULT TERM TERMS VALUE UNIT
179 DUR=$1
180 RESULT=0
181 TERMS="$(echo "$DUR" | sed -Ee 's/([sSmMhHdD])/\1 /g' -e 's/,$//g')"
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700182 for TERM in $TERMS; do
David Bainbridged18f4942020-04-14 16:46:13 -0700183 VALUE="$(echo "$TERM" | sed -Ee 's/([0-9]+)[sSmMhHdD]/\1/')"
184 UNIT="$(echo "$TERM" | sed -Ee 's/[0-9]+([sSmMhHdD])/\1/')"
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700185 case $UNIT in
186 s|S)
David Bainbridged18f4942020-04-14 16:46:13 -0700187 RESULT=$((RESULT + VALUE)) ;;
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700188 m|M)
David Bainbridged18f4942020-04-14 16:46:13 -0700189 RESULT=$((RESULT + (VALUE * 60))) ;;
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700190 h|H)
David Bainbridged18f4942020-04-14 16:46:13 -0700191 RESULT=$((RESULT + (VALUE * 3600))) ;;
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700192 d|D)
David Bainbridged18f4942020-04-14 16:46:13 -0700193 RESULT=$((RESULT + (VALUE * 86400))) ;;
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700194 *) ;;
195 esac
196 done
197 echo $RESULT
198}
199
200function doTimeout() {
201 local MSG=$1
202 2>&1 echo -e "\n${RED}${BOLD}${ERROR}TIMEOUT:${NORMAL}${RED} Operation timed out after '$WAIT_TIMEOUT': $MSG"
203 exit 125
204}
205
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -0800206function get_service_ep() {
207 local NS=$1
208 local NAME=$2
David Bainbridged18f4942020-04-14 16:46:13 -0700209 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 -0800210}
211
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000212# Used to verify configuration values are set to "yes" or "no" value or convert
213# equivalents to "yes" or "no"
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700214YES="y,yes,t,true,1"
215NO="n,no,f,false,0"
216YES_OR_NO="$YES,$NO"
217
218# If the given VAR matches a truth value then normalize that
219# value, else return original value
220function normalize_yes_no() {
221 local VAR VAL
222 VAR=$1
223 VAL="$(eval echo "\$$VAR")"
224 if ! is_in "$VAL" "$YES_OR_NO"; then
225 echo "$VAL"
226 return 1
227 fi
228 if is_in "$VAL" "$YES"; then
229 echo "yes"
230 else
231 echo "no"
232 fi
233 return 0
234}
235
236# If the given VAR matches a truth value then normalize that
237# value, else display an error
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000238function verify_yes_no() {
David Bainbridged18f4942020-04-14 16:46:13 -0700239 local VAR VAL
240 VAR=$1
241 VAL="$(eval echo "\$$VAR")"
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700242 if ! is_in "$VAL" "$YES_OR_NO"; then
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000243 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} Invalid '$VAR' value of '$VAL'. Should be 'yes' or 'no'${NORMAL}"
244 echo "INVALID"
245 return 1
246 fi
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700247 if is_in "$VAL" "$YES"; then
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000248 echo "yes"
249 else
250 echo "no"
251 fi
252 return 0
253}
Test User7d866122019-07-09 17:52:35 +0000254
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000255ALL_YES_NO="\
David K. Bainbridge484d80c2020-03-05 21:44:34 -0800256 ENABLE_ONOS_EXTRANEOUS_RULES \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000257 WITH_TIMINGS \
258 WITH_BBSIM \
Matteo Scandolo78dfee02020-02-13 16:18:03 -0800259 WITH_EAPOL \
260 WITH_DHCP \
261 WITH_IGMP \
David Bainbridge99ac7a22019-08-31 02:26:43 +0000262 WITH_CHAOS \
David Bainbridge46505fb2019-10-01 21:13:20 +0000263 WITH_ADAPTERS \
264 WITH_SIM_ADAPTERS \
265 WITH_OPEN_ADAPTERS \
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -0800266 WITH_PORT_FORWARDS \
Matteo Scandoloefee0432020-05-05 13:56:20 -0700267 WITH_PPROF \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000268 JUST_K8S \
269 DEPLOY_K8S \
270 INSTALL_ONOS_APPS \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000271 INSTALL_KUBECTL \
272 INSTALL_HELM \
David Bainbridge7f8bf992020-04-08 21:53:22 -0700273 HELM_USE_UPGRADE \
David Bainbridge46505fb2019-10-01 21:13:20 +0000274 UPDATE_HELM_REPOS \
David Bainbridge4f1b5562019-08-19 04:46:52 +0000275 WAIT_ON_DOWN \
David Bainbridge70c0ea82019-11-14 23:25:26 +0000276 ONLY_ONE \
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700277 VOLTHA_DOWN_ON_TIMEOUT \
Matteo Scandoloc2eb0672020-05-01 14:43:15 -0700278 LEGACY_BBSIM_INDEX \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000279 "
David Bainbridge5b7b96b2019-07-25 20:29:13 +0000280
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700281OPT_YES_NO="\
282 CONFIG_SADIS \
283 WITH_KAFKA \
284 WITH_RADIUS \
285 WITH_ETCD \
286 WITH_ONOS \
287 "
288
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000289ALL_OPTIONS="\
290 NAME \
291 TYPE \
292 $ALL_YES_NO \
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700293 $OPT_YES_NO \
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700294 WAIT_TIMEOUT \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000295 VOLTHA_LOG_LEVEL \
296 VOLTHA_CHART \
David Bainbridge90fd8e32019-08-21 23:32:47 +0000297 VOLTHA_CHART_VERSION \
298 VOLTHA_BBSIM_CHART \
299 VOLTHA_BBSIM_CHART_VERSION \
uottrembd5a20572020-03-06 09:15:01 +0100300 NUM_OF_BBSIM \
Matteo Scandolo67335f02020-04-09 11:19:53 -0700301 NUM_OF_OPENONU \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000302 VOLTHA_ADAPTER_SIM_CHART \
David Bainbridge90fd8e32019-08-21 23:32:47 +0000303 VOLTHA_ADAPTER_SIM_CHART_VERSION \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000304 VOLTHA_ADAPTER_OPEN_OLT_CHART \
David Bainbridge90fd8e32019-08-21 23:32:47 +0000305 VOLTHA_ADAPTER_OPEN_OLT_CHART_VERSION \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000306 VOLTHA_ADAPTER_OPEN_ONU_CHART \
David Bainbridge90fd8e32019-08-21 23:32:47 +0000307 VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION \
David K. Bainbridgeda33d652020-03-06 10:31:23 -0800308 ONOS_CHART \
Andrea Campanella21323292019-12-18 11:44:19 -0800309 ONOS_CHART_VERSION \
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700310 ONOS_CLASSIC_CHART \
311 ONOS_CLASSIC_CHART_VERSION \
David Bainbridgecf546362020-04-21 23:18:50 -0700312 KAFKA_CHART \
David Bainbridgeb9093522020-04-15 14:32:44 -0700313 KAFKA_CHART_VERSION \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000314 ONOS_API_PORT \
315 ONOS_SSH_PORT \
Hardik Windlassb3147602020-03-09 16:59:15 +0530316 SADIS_CFG \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000317 VOLTHA_API_PORT \
318 VOLTHA_SSH_PORT \
319 VOLTHA_ETCD_PORT \
David K. Bainbridge00ecd382020-02-28 12:31:58 -0800320 VOLTHA_KAFKA_PORT \
Matteo Scandoloefee0432020-05-05 13:56:20 -0700321 VOLTHA_PPROF_PORT \
322 OPENOLT_PPROF_PORT \
David K. Bainbridge8f7f30b2020-01-08 13:06:16 -0800323 VK_RELEASE \
324 KIND_VERSION \
325 VOLTCTL_VERSION \
David Bainbridgea34993d2020-04-01 09:15:42 -0700326 HELM_VERSION \
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700327 NUM_OF_ONOS \
328 NUM_OF_ATOMIX \
David Bainbridge6ca40102020-04-08 11:30:40 -0700329 VOLTHA_NS \
330 ADAPTER_NS \
331 INFRA_NS \
332 BBSIM_NS \
David Bainbridge7db44002020-04-09 12:54:29 -0700333 SADIS_BANDWIDTH_PROFILES \
334 SADIS_SUBSCRIBERS \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000335 "
David Bainbridge01294952019-07-30 19:33:45 +0000336
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000337# Iterate over yes/no configuration options and validate
338for VAR in $ALL_YES_NO; do
David Bainbridged18f4942020-04-14 16:46:13 -0700339 eval "$VAR"="$(verify_yes_no "$VAR")"
340 if [ "$(eval echo "\$$VAR")" == "INVALID" ]; then
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000341 exit 1;
342 fi
343done
David Bainbridgeb270c202019-07-26 01:44:42 +0000344
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700345# Iterate over optional yes/no configuration options and
346# normalize values if they are truth values
347for VAR in $OPT_YES_NO; do
348 eval "$VAR"="$(normalize_yes_no "$VAR")"
349done
David Bainbridge15f6f232020-03-30 09:15:43 -0700350
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700351# normalize non-truth value options
352if is_in "$WITH_KAFKA" "e,external"; then
David Bainbridge76afd812020-04-06 09:53:52 -0700353 WITH_KAFKA="external"
354fi
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700355if is_in "$WITH_ETCD" "e,external"; then
David Bainbridge76afd812020-04-06 09:53:52 -0700356 WITH_ETCD="external"
357fi
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700358if is_in "$WITH_ONOS" "l,legacy"; then
359 WITH_ONOS="legacy"
360elif is_in "$WITH_ONOS" "c,classic"; then
361 WITH_ONOS="classic"
362elif is_in "$WITH_ONOS" "u,m,micro"; then
363 WITH_ONOS="micro"
David Bainbridge29c31cb2020-04-06 09:45:50 -0700364fi
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700365
366if [ "$WITH_ONOS" == "micro" ]; then
367 >&2 echo -e "${YELLOW}${BOLD}${ERROR}WARNING:${NORMAL}${YELLOW} The value specified as WITH_ONOS, '$WITH_ONOS', is not valid.${NORMAL}"
368 exit 1
David Bainbridge29c31cb2020-04-06 09:45:50 -0700369fi
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700370
371if is_in "$WITH_ONOS" "yes,classic"; then
372 # there is an extra utility required if we are using ONOS CLASSIC as
373 # the chart for classic specifies images differently
374 EXTRA_TOOLS+=" yq"
David Bainbridge76afd812020-04-06 09:53:52 -0700375fi
David Bainbridge696bc632020-04-05 21:49:37 -0700376
David Bainbridged18f4942020-04-14 16:46:13 -0700377if [ "$HELM_USE_UPGRADE" == "yes" ]; then
David Bainbridge7f8bf992020-04-08 21:53:22 -0700378 _HELM_DESC="Upgrade/Install"
379else
380 _HELM_DESC="Install"
381fi
382
David Bainbridged18f4942020-04-14 16:46:13 -0700383ETCD_PREFIX=
384KAFKA_PREFIX=
385if [ "$WITH_ETCD" == "yes" ]; then
386 ETCD_PREFIX="voltha-"
387fi
388if [ "$WITH_KAFKA" == "yes" ]; then
389 KAFKA_PREFIX="voltha-"
390fi
391
David K. Bainbridgeda33d652020-03-06 10:31:23 -0800392# Check for prerequiste tools
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700393TOOLS="curl sed jq $EXTRA_TOOLS"
David Bainbridged18f4942020-04-14 16:46:13 -0700394if [ "$DEPLOY_K8S" == "yes" ]; then
David K. Bainbridgeda33d652020-03-06 10:31:23 -0800395 TOOLS+=" docker"
396fi
397NOT_FOUND=""
398for T in $TOOLS; do
David Bainbridged18f4942020-04-14 16:46:13 -0700399 if [ -z "$(command -v "$T")" ]; then
David K. Bainbridgeda33d652020-03-06 10:31:23 -0800400 NOT_FOUND+=" $T"
401 fi
402done
403
David Bainbridged18f4942020-04-14 16:46:13 -0700404if [ -n "$NOT_FOUND" ]; then
David K. Bainbridgeda33d652020-03-06 10:31:23 -0800405 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} The following required tools where not found, please install them:$NOT_FOUND"
406 exit 1
407fi
408
David Bainbridged18f4942020-04-14 16:46:13 -0700409TIMEOUT_SECONDS="$(parseDuration "$WAIT_TIMEOUT")"
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700410
David Bainbridge0774b232019-08-02 06:37:19 +0000411mkdir -p .voltha
412touch .voltha/ports
David Bainbridged18f4942020-04-14 16:46:13 -0700413HAVE="$(grep "$NAME" .voltha/ports)"
David Bainbridge0774b232019-08-02 06:37:19 +0000414if [ "$HAVE X" == " X" ]; then
415 # Find free port prefix
416 START=81
417 while true; do
David Bainbridged18f4942020-04-14 16:46:13 -0700418 if [ "$(grep -c $START .voltha/ports)" -eq 0 ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000419 break
420 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700421 START="$((START + 1))"
David Bainbridge0774b232019-08-02 06:37:19 +0000422 done
David Bainbridged18f4942020-04-14 16:46:13 -0700423 DELTA="$((START - 81))"
David Bainbridgea2595422019-10-22 03:54:28 +0000424 ONOS_API_PORT=${ONOS_API_PORT:-${START}81}
425 ONOS_SSH_PORT=${ONOS_SSH_PORT:-${START}01}
David Bainbridged18f4942020-04-14 16:46:13 -0700426 VOLTHA_API_PORT=${VOLTHA_API_PORT:-5$((55 + DELTA))55}
427 VOLTHA_SSH_PORT=${VOLTHA_SSH_PORT:-$((50 + DELTA))22}
428 VOLTHA_ETCD_PORT=${VOLTHA_ETCD_PORT:-$((23 + DELTA))79}
429 VOLTHA_KAFKA_PORT=${VOLTHA_KAFKA_PORT:-$((90 + DELTA))92}
Matteo Scandoloefee0432020-05-05 13:56:20 -0700430 VOLTHA_PPROF_PORT=${VOLTHA_PPROF_PORT:-$((60 + DELTA))60}
431 OPENOLT_PPROF_PORT=${OPENOLT_PPROF_PORT:-$((60 + DELTA))61}
Test User01ed0642019-07-03 20:17:06 +0000432else
David Bainbridged18f4942020-04-14 16:46:13 -0700433 VALUES="$(echo "$HAVE" | sed -e 's/\s//g' | cut -d= -f2)"
434 ONOS_API_PORT=${ONOS_API_PORT:-$(echo "$VALUES" | cut -d, -f1)}
435 ONOS_SSH_PORT=${ONOS_SSH_PORT:-$(echo "$VALUES" | cut -d, -f2)}
436 VOLTHA_API_PORT=${VOLTHA_API_PORT:-$(echo "$VALUES" | cut -d, -f3)}
437 VOLTHA_SSH_PORT=${VOLTHA_SSH_PORT:-$(echo "$VALUES" | cut -d, -f4)}
438 VOLTHA_ETCD_PORT=${VOLTHA_ETCD_PORT:-$(echo "$VALUES" | cut -d, -f5)}
439 VOLTHA_KAFKA_PORT=${VOLTHA_KAFKA_PORT:-$(echo "$VALUES" | cut -d, -f6)}
Matteo Scandoloefee0432020-05-05 13:56:20 -0700440 VOLTHA_PPROF_PORT=${VOLTHA_PPROF_PORT:-$(echo "$VALUES" | cut -d, -f7)}
441 OPENOLT_PPROF_PORT=${OPENOLT_PPROF_PORT:-$(echo "$VALUES" | cut -d, -f8)}
David K. Bainbridge00ecd382020-02-28 12:31:58 -0800442
Matteo Scandoloefee0432020-05-05 13:56:20 -0700443 # Some ports were added after the .voltha/ports files was created.
444 # Calculate the original DELTA from the VOLTHA_SSH_PORT so that it can
445 # be used to set up newer port-forwards.
446 DELTA="$((VOLTHA_SSH_PORT/100-50))"
447
David K. Bainbridge00ecd382020-02-28 12:31:58 -0800448 if [ -z "$VOLTHA_KAFKA_PORT" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -0700449 VOLTHA_KAFKA_PORT=${VOLTHA_KAFKA_PORT:-$((90 + DELTA))92}
David K. Bainbridge00ecd382020-02-28 12:31:58 -0800450 fi
Matteo Scandoloefee0432020-05-05 13:56:20 -0700451
452 if [ -z "$VOLTHA_PPROF_PORT" ]; then
453 VOLTHA_PPROF_PORT=${VOLTHA_PPROF_PORT:-$((60 + DELTA))60}
454 fi
455 if [ -z "$OPENOLT_PPROF_PORT" ]; then
456 OPENOLT_PPROF_PORT=${OPENOLT_PPROF_PORT:-$((60 + DELTA))61}
457 fi
Test User01ed0642019-07-03 20:17:06 +0000458fi
459
David Bainbridged18f4942020-04-14 16:46:13 -0700460PORTTMP="$(mktemp -u)"
461grep -v "$NAME" .voltha/ports > "$PORTTMP"
Matteo Scandoloefee0432020-05-05 13:56:20 -0700462echo "$NAME=$ONOS_API_PORT,$ONOS_SSH_PORT,$VOLTHA_API_PORT,$VOLTHA_SSH_PORT,$VOLTHA_ETCD_PORT,$VOLTHA_KAFKA_PORT,$VOLTHA_PPROF_PORT,$OPENOLT_PPROF_PORT" >> "$PORTTMP"
David Bainbridged18f4942020-04-14 16:46:13 -0700463cp "$PORTTMP" .voltha/ports
464rm -f "$PORTTMP"
David Bainbridge0774b232019-08-02 06:37:19 +0000465
David Bainbridge27790d62019-08-13 22:43:19 +0000466export ONOS_API_PORT ONOS_SSH_PORT
David Bainbridge01294952019-07-30 19:33:45 +0000467
Test Userd87942b2019-07-03 07:20:24 +0000468IDX=1
David Bainbridgee87067b2019-08-12 22:00:12 +0000469CLOCK="TIME:"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000470SPIN_PARTS=
471NOT_VERIFIED=
David Bainbridgef858a022019-08-14 21:25:11 +0000472THEX=
473BUILD=
David Bainbridge38dc1e82019-08-12 15:18:45 +0000474VERIFIED=
475HELM=
476OLD_KEY=
477BIRD=
478HIGH_VOLTAGE=
479PLUG=
David Bainbridge38dc1e82019-08-12 15:18:45 +0000480FORWARD=
David Bainbridge38dc1e82019-08-12 15:18:45 +0000481GO=
482DOWNLOAD=
483GEAR=
484NO_ENTRY=
485LOCK=
486
David Bainbridged18f4942020-04-14 16:46:13 -0700487if [ "$FANCY" -eq 1 ]; then
488 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 +0000489 CLOCK="\xe2\x8f\xb1"
David Bainbridgef858a022019-08-14 21:25:11 +0000490 THEX="${RED}${BOLD}\xe2\x9c\x97\x20${NORMAL}"
David Bainbridgef858a022019-08-14 21:25:11 +0000491 BUILD="${YELLOW}${BOLD}\xf0\x9f\x8f\x97${NORMAL}"
492 NOT_VERIFIED="$BUILD"
493 VERIFIED="${GREEN}${BOLD}\xe2\x9c\x93\x20${NORMAL}"
494 HELM="${BLUE}${BOLD}\xE2\x8E\x88${NORMAL}"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000495 OLD_KEY="\xF0\x9F\x97\x9D"
496 BIRD="\xF0\x9F\x90\xA6"
497 HIGH_VOLTAGE="\xE2\x9A\xA1"
498 PLUG="\xF0\x9F\xa7\xa9"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000499 FORWARD="\xE2\x87\xA8"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000500 GO="\xf0\x9f\x9a\x80"
501 DOWNLOAD="\xf0\x9f\x93\xa5"
502 GEAR="\xe2\x9a\x99"
503 NO_ENTRY="\xe2\x9b\x94"
504 LOCK="\xf0\x9f\x94\x92"
505fi
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700506
David Bainbridge712afb82019-08-14 19:55:58 +0000507duration() {
David Bainbridged18f4942020-04-14 16:46:13 -0700508 local h m s t
509 h="$(($1 / 3600))"
510 m="$(($1 % 3600 / 60))"
511 s="$(($1 % 60))"
512 t=""
David Bainbridgee87067b2019-08-12 22:00:12 +0000513
David Bainbridged18f4942020-04-14 16:46:13 -0700514 if [ "$h" -gt 0 ]; then
David Bainbridgee87067b2019-08-12 22:00:12 +0000515 t="$t${h}h"
516 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700517 if [ "$m" -gt 0 ]; then
David Bainbridgee87067b2019-08-12 22:00:12 +0000518 t="$t${m}m"
519 fi
David Bainbridge712afb82019-08-14 19:55:58 +0000520 echo "$t${s}s"
521}
522
523printtime() {
David Bainbridged18f4942020-04-14 16:46:13 -0700524 local INDENT
David Bainbridge712afb82019-08-14 19:55:58 +0000525 if [ "$1" == "-" ]; then
526 INDENT=" "
527 shift
528 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700529 echo -e "$INDENT $CLOCK $(duration "$1")"
David Bainbridgee87067b2019-08-12 22:00:12 +0000530}
531
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700532bspin() {
Test Userd87942b2019-07-03 07:20:24 +0000533 IDX=1
David Bainbridged18f4942020-04-14 16:46:13 -0700534 local INDENT
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700535 if [ "$1" == "-" ]; then
536 INDENT=" "
537 shift
538 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700539 if [ "$FANCY" -eq 0 ]; then
540 LINE="${*//[[:space:]+-]}"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000541 if [ "$LINE X" == " X" ]; then
542 return
543 fi
544 echo -e "$CIVIS$INDENT$*"
545 else
546 echo -en "$CIVIS$INDENT $*"
547 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700548}
549
550sspin() {
David Bainbridged18f4942020-04-14 16:46:13 -0700551 local INDENT
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700552 if [ "$1" == "-" ]; then
553 INDENT=" "
554 shift
555 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700556 if [ "$FANCY" -eq 0 ]; then
557 LINE="${*//[[:space:]+-]}"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000558 if [ "$LINE X" == " X" ]; then
559 return
560 fi
561 echo -e "$INDENT$*"
562 else
David Bainbridged18f4942020-04-14 16:46:13 -0700563 C="$(echo "$SPIN_PARTS" | cut '-d ' -f "$IDX")"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000564 echo -en "\r$INDENT$C $*"
David Bainbridged18f4942020-04-14 16:46:13 -0700565 IDX="$((IDX + 1))"
566 if [ "$IDX" -gt 8 ]; then
David Bainbridge38dc1e82019-08-12 15:18:45 +0000567 IDX=1
568 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700569 fi
570}
571
572espin() {
David Bainbridged18f4942020-04-14 16:46:13 -0700573 local INDENT
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700574 if [ "$1" == "-" ]; then
575 INDENT=" "
576 shift
577 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700578 if [ "$FANCY" -eq 0 ]; then
579 LINE="${*//[[:space:]+-]}"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000580 if [ "$LINE X" == " X" ]; then
581 return
582 fi
583 echo -e "$INDENT$*"
584 else
585 echo -e "\r$INDENT$*$CNORM"
586 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700587}
588
David Bainbridged18f4942020-04-14 16:46:13 -0700589if [ "$1" == "get" ] && [ "$2" == "voltconfig" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000590 echo "$HOME/.volt/config-$NAME"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000591 exit
592fi
593
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700594if [ $# -ne 1 ] || ! is_in "$1" "up,down,dump"; then
David Bainbridgeac7f8072019-08-01 22:15:33 +0000595 >&2 echo "What wouild you like to do today:"
596 >&2 echo " up - bring up voltha"
597 >&2 echo " down - tear down voltha"
598 >&2 echo " dump - create a debug dump of running system"
599 exit 1
600fi
601
David Bainbridge4f1b5562019-08-19 04:46:52 +0000602push_onos_config() {
David Bainbridged18f4942020-04-14 16:46:13 -0700603 local TYPE MSG RESOURCE DATA CMD_ECHO CMD_OUTPUT SC_OUTPUT WAIT_START NOW
604 TYPE=$1
605 MSG=$2
606 RESOURCE=$3
607 DATA=$4
David Bainbridge4f1b5562019-08-19 04:46:52 +0000608
David K. Bainbridgeb4b163b2020-02-19 15:55:06 -0800609 # Thanks to the latest version of ONOS using the return code 207 this gets a
610 # whole lot nastier. Can't thank them enough for doing this. So in order to
611 # capture the command and the output in the log file as well as capture the
612 # status code to verify it is 200 and not 207 mutltiple files and a bit of
613 # hackery must be used. Thanks again ONOS.
David Bainbridged18f4942020-04-14 16:46:13 -0700614 CMD_ECHO="$(mktemp -u)"
615 CMD_OUTPUT="$(mktemp -u)"
616 SC_OUTPUT="$(mktemp -u)"
617 WAIT_START="$(date +%s)"
David K. Bainbridgeb4b163b2020-02-19 15:55:06 -0800618
David Bainbridge4f1b5562019-08-19 04:46:52 +0000619 bspin - "$MSG $GEAR"
620 while true; do
David Bainbridged18f4942020-04-14 16:46:13 -0700621 NOW="$(date +%s)"
622 if [ "$((NOW - WAIT_START))" -gt "$TIMEOUT_SECONDS" ]; then
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700623 espin - "$THEX"
David Bainbridged18f4942020-04-14 16:46:13 -0700624 rm -f "$CMD_ECHO" "$CMD_OUTPUT" "$SC_OUTPUT"
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700625 doTimeout "waiting for ONOS config push on $RESOURCE"
626 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700627 if [ "$TYPE" == "file" ]; then
628 (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 -0700629 RESULT=$?
Matteo Scandolo78dfee02020-02-13 16:18:03 -0800630 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700631 if [ "$TYPE" == "json" ]; then
632 (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 -0700633 RESULT=$?
Matteo Scandolo78dfee02020-02-13 16:18:03 -0800634 fi
David K. Bainbridgeb4b163b2020-02-19 15:55:06 -0800635 # Dump everything to the log
David Bainbridged18f4942020-04-14 16:46:13 -0700636 cat "$CMD_ECHO" >> "$LOG"
637 test -r "$CMD_OUTPUT" && cat "$CMD_OUTPUT" >> "$LOG"
638 SC="$(cat "$SC_OUTPUT")"
639 echo "RESPONSE CODE: $SC" >> "$LOG"
640 echo "ERROR CODE: $RESULT" >> "$LOG"
David K. Bainbridgeb4b163b2020-02-19 15:55:06 -0800641
642 # clean up temp files
David Bainbridged18f4942020-04-14 16:46:13 -0700643 rm -f "$CMD_ECHO" "$CMD_OUTPUT" "$SC_OUTPUT"
644 if [ "$RESULT" -eq 0 ] && [ "$SC" == "200" ]; then
David Bainbridge4f1b5562019-08-19 04:46:52 +0000645 break
646 fi
Matteo Scandolo9a77a732020-01-09 14:24:12 -0800647 sleep 1
David Bainbridge4f1b5562019-08-19 04:46:52 +0000648 sspin -
649 done
David Bainbridged18f4942020-04-14 16:46:13 -0700650 espin - "$VERIFIED"
David Bainbridge4f1b5562019-08-19 04:46:52 +0000651}
652
Matteo Scandolo9a77a732020-01-09 14:24:12 -0800653check_onos_app_active() {
David Bainbridged18f4942020-04-14 16:46:13 -0700654 local APP_ID WAIT_START RESULT NOW
655 APP_ID=$1
656 WAIT_START="$(date +%s)"
Matteo Scandolo9a77a732020-01-09 14:24:12 -0800657
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700658 bspin - "Checking that $APP_ID is active $CLOCK"
659 while true; do
David Bainbridged18f4942020-04-14 16:46:13 -0700660 NOW="$(date +%s)"
661 if [ "$((NOW - WAIT_START))" -gt "$TIMEOUT_SECONDS" ]; then
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700662 espin - "$THEX"
663 doTimeout "waiting for ONOS application activation '$APP_ID'"
664 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700665 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 -0700666 break
667 fi
668 sleep 1
669 sspin -
670 done
671 sleep 5 # OSGI components take a little longer that the app to activate
David Bainbridged18f4942020-04-14 16:46:13 -0700672 espin - "$VERIFIED"
Matteo Scandolo9a77a732020-01-09 14:24:12 -0800673}
674
David Bainbridge4f1b5562019-08-19 04:46:52 +0000675override_onos_app() {
David Bainbridged18f4942020-04-14 16:46:13 -0700676 local APP NAME WAIT_START NOW
677 APP=$1
678 NAME="$(basename "$APP" | sed -e 's/^[0-9][0-9]*-//g' -e 's/-.*$//g')"
679 WAIT_START="$(date +%s)"
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700680
David Bainbridge4f1b5562019-08-19 04:46:52 +0000681 while true; do
David Bainbridged18f4942020-04-14 16:46:13 -0700682 NOW="$(date +%s)"
683 if [ "$((NOW - WAIT_START))" -gt "$TIMEOUT_SECONDS" ]; then
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700684 espin - "$THEX"
685 doTimeout "waiting to overwrite ONOS application '$APP'"
686 fi
David Bainbridge4f1b5562019-08-19 04:46:52 +0000687 sspin -
688 # Attempt to delete old version (if it exists)
David Bainbridged18f4942020-04-14 16:46:13 -0700689 (set -x; curl --fail -sSL --user karaf:karaf -X DELETE "http://$_ONOS_API_EP/onos/v1/applications/$NAME" >>"$LOG" 2>&1) >>"$LOG" 2>&1
690 RESULT=$?
David Bainbridge4f1b5562019-08-19 04:46:52 +0000691 sspin -
David Bainbridged18f4942020-04-14 16:46:13 -0700692 if [ $RESULT -ne 0 ]; then
David Bainbridge4f1b5562019-08-19 04:46:52 +0000693 continue
694 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700695 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 +0000696 break
697 fi
698 sleep .2
699 done
700}
701
702activate_onos_app() {
David Bainbridged18f4942020-04-14 16:46:13 -0700703 local MSG APP WAIT_START NOW
704 MSG="$1"
705 APP=$2
706 WAIT_START="$(date +%s)"
David Bainbridge4f1b5562019-08-19 04:46:52 +0000707
708 bspin - "$MSG $GO"
709 while true; do
David Bainbridged18f4942020-04-14 16:46:13 -0700710 NOW="$(date +%s)"
711 if [ "$((NOW - WAIT_START))" -gt "$TIMEOUT_SECONDS" ]; then
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700712 espin - "$THEX"
713 doTimeout "waiting to activate ONOS application '$APP'"
714 fi
David Bainbridge4f1b5562019-08-19 04:46:52 +0000715 sspin -
David Bainbridged18f4942020-04-14 16:46:13 -0700716 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 +0000717 break
718 fi
719 sleep .2
720 done
721 espin - "$VERIFIED"
722}
723
724count_pods() {
David Bainbridged18f4942020-04-14 16:46:13 -0700725 local NAMESPACE STATES LABELS CMD PODS
726 NAMESPACE=$1; shift
David Bainbridge4f1b5562019-08-19 04:46:52 +0000727 if [ "$NAMESPACE" == "all-namespaces" ]; then
728 NAMESPACE="--all-namespaces"
729 else
730 NAMESPACE="-n $NAMESPACE"
731 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700732 STATES=$1; shift
733 LABELS=$1; shift
734 CMD=("kubectl get $NAMESPACE $LABELS pod")
735 PODS=$(${CMD[*]} -o go-template="{{range .items}}{{.metadata.name}}/{{.status.phase}}/_{{range .status.containerStatuses}}{{.ready}}_{{end}} {{end}}")
David Bainbridge4f1b5562019-08-19 04:46:52 +0000736 local COUNT=0
737 local PATTERNS="$*"
738 for POD in $PODS; do
David Bainbridged18f4942020-04-14 16:46:13 -0700739 local NAME STATE CONTAINERS TOTAL FOUND
740 NAME="$(echo "$POD" | cut -d/ -f 1)"
741 STATE="$(echo "$POD" | cut -d/ -f 2)"
742 CONTAINERS="$(echo "$POD" | cut -d/ -f 3 | sed -e 's/_/ /g')"
743 if [ "$STATES" == "*" ] || [ "$(echo "$STATES" | grep -c ":$STATE:")" -ne 0 ]; then
744 TOTAL="$(echo "$CONTAINERS" | wc -w)"
745 FOUND="$(echo "$CONTAINERS" | grep -o true | wc -l)"
746 if [ "$TOTAL" -eq "$FOUND" ]; then
David Bainbridge4f1b5562019-08-19 04:46:52 +0000747 for PATTERN in $PATTERNS; do
David Bainbridged18f4942020-04-14 16:46:13 -0700748 if [[ "$NAME" =~ $PATTERN ]]; then
749 COUNT="$((COUNT + 1))"
David Bainbridge4f1b5562019-08-19 04:46:52 +0000750 break
751 fi
752 done
753 fi
754 fi
755 done
David Bainbridge4f1b5562019-08-19 04:46:52 +0000756 echo $COUNT
757}
758
759wait_for_pods() {
David Bainbridged18f4942020-04-14 16:46:13 -0700760 local INDENT NAMESPACE EXPECT TYPE MESSAGE LABELS PATTERNS STATES HAVE ALL WAIT_START NOW
David Bainbridge4f1b5562019-08-19 04:46:52 +0000761 if [ "$1" == "-" ]; then
762 INDENT=$1; shift
763 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700764 NAMESPACE=$1; shift
765 EXPECT=$1; shift
766 TYPE=$1; shift
767 MESSAGE=$1; shift
768 LABELS=$1; shift
769 PATTERNS=("$*")
770 STATES=":Running:"
David Bainbridge99ac7a22019-08-31 02:26:43 +0000771 if [ "$TYPE" == "not" ]; then
772 STATES="*"
773 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700774 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))"
780 WAIT_START="$(date +%s)"
781 bspin "$INDENT" "$MESSAGE"
782 sspin "$INDENT"
783 if [ "$HAVE" -ne "$EXPECT" ] || [ "$ALL" -ne "$HAVE" ]; then
784 while [ "$HAVE" -ne "$EXPECT" ] || [ "$ALL" -ne "$HAVE" ]; do
785 NOW="$(date +%s)"
786 if [ "$((NOW - WAIT_START))" -gt "$TIMEOUT_SECONDS" ]; then
787 espin "$INDENT" "$THEX"
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700788 doTimeout "waiting for PODs to start"
789 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700790 sspin "$INDENT"
791 COUNT="$((COUNT - 1))"
792 if [ "$COUNT" -eq 0 ]; then
793 HAVE="$(count_pods "$NAMESPACE" "$STATES" "$LABELS" "${PATTERNS[@]}")"
794 ALL="$HAVE"
David Bainbridge4f1b5562019-08-19 04:46:52 +0000795 if [ "$TYPE" == "only" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -0700796 ALL="$(count_pods "all-namespaces" "*" ".*")"
David Bainbridge4f1b5562019-08-19 04:46:52 +0000797 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700798 COUNT="$((300 / 15))"
David Bainbridge4f1b5562019-08-19 04:46:52 +0000799 fi
800 sleep .15
801 done
802 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700803 espin "$INDENT" "$VERIFIED"
804 if [ "$HAVE" -ne "$EXPECT" ]; then
David Bainbridge4f1b5562019-08-19 04:46:52 +0000805 return 1
806 fi
807 return 0
808}
809
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800810port_forward() {
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700811 local NS=$1; shift
812 local SVC=$1; shift
813 local PORTS="$*"
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800814 local TAG=$SVC-$NAME
815
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700816 (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 -0800817}
818
819kill_port_forward() {
David Bainbridged18f4942020-04-14 16:46:13 -0700820 local TAG P_IDS PARENTS KIDS UNKNOWN PP_ID
821 TAG="$1-$NAME"
822 # shellcheck disable=SC2009
823 P_IDS="$(ps e -ww -A | grep "_TAG=$TAG" | grep -v grep | awk '{print $1}')"
824 if [ -n "$P_IDS" ]; then
David Bainbridgec6871d22019-11-13 17:10:31 +0000825 for P_ID in $P_IDS; do
David Bainbridged18f4942020-04-14 16:46:13 -0700826 PP_ID="$(ps -o ppid "$P_ID" | tail -n +2)"
827 if [ -n "$PP_ID" ]; then
828 if [ "$PP_ID" -eq 1 ]; then
David Bainbridgec6871d22019-11-13 17:10:31 +0000829 PARENTS="$PARENTS $P_ID"
830 else
831 KIDS="$KIDS $P_ID"
832 fi
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800833 else
David Bainbridgec6871d22019-11-13 17:10:31 +0000834 UNKNOWN="$UNKNOWN $P_ID"
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800835 fi
836 done
David Bainbridged18f4942020-04-14 16:46:13 -0700837 (set -x; kill -9 "$PARENTS" "$KIDS" "$UNKNOWN" >>"$LOG" 2>&1) >>"$LOG" 2>&1
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800838 fi
839}
840
David Bainbridgecf546362020-04-21 23:18:50 -0700841resolve_chart_version() {
842 [ "$2" != "latest" ] && echo "$2" && return
843 helm inspect chart "$1" | grep "^version:" | awk '{print $2}'
844}
845
Jonathan Hart6a91e6c2020-04-16 14:28:33 -0700846# Compares two semver-formatted version strings (e.g. 2.4.3)
847# Returns 0 if $1 == $2, returns 1 if $1 > $2 and returns 2 if $1 < $2
848compare_versions() {
849 [ "$1" == "$2" ] && return 0
Jonathan Hart6a91e6c2020-04-16 14:28:33 -0700850 local lowest
851 lowest=$(echo -e "$1\n$2" | sort -V | head -1)
852 [ "$lowest" == "$1" ] && return 2
853 return 1
854}
855
David Bainbridgeac7f8072019-08-01 22:15:33 +0000856if [ "$1" == "down" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000857 echo "Tearing down voltha cluster $NAME"
858 LOG="down-$NAME.log"
David Bainbridged18f4942020-04-14 16:46:13 -0700859 date -u +"%Y%m%dT%H%M%SZ" >"$LOG"
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700860 if is_in "$WITH_ONOS" "yes,legacy,classic"; then
David Bainbridge696bc632020-04-05 21:49:37 -0700861 bspin "Remove port-forwards: onos-ui-$NAME"
862 kill_port_forward onos-ui
863 sspin "Remove port-forwards: onos-ssh-$NAME$CEOL"
864 kill_port_forward onos-ssh
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700865 bspin "Remove port-forwards: onos-onos-classic-hs-$NAME$CEOL"
866 kill_port_forward onos-onos-classic-hs
David Bainbridge696bc632020-04-05 21:49:37 -0700867 fi
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800868 sspin "Remove port-forwards: voltha-api-$NAME$CEOL"
869 kill_port_forward voltha-api
David Bainbridged18f4942020-04-14 16:46:13 -0700870 if [ "$WITH_ETCD" == "yes" ] || [ "$WITH_ETCD" == "external" ]; then
871 sspin "Remove port-forwards: ${ETCD_PREFIX}etcd-$NAME$CEOL"
872 kill_port_forward "${ETCD_PREFIX}etcd-cluster-client"
David Bainbridge696bc632020-04-05 21:49:37 -0700873 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700874 if [ "$WITH_KAFKA" == "yes" ] || [ "$WITH_KAFKA" == "external" ]; then
875 sspin "Remove port-forwards: ${KAFKA_PREFIX}kafka-$NAME$CEOL"
876 kill_port_forward "${KAFKA_PREFIX}kafka"
David Bainbridge696bc632020-04-05 21:49:37 -0700877 fi
Matteo Scandoloefee0432020-05-05 13:56:20 -0700878
879 if [ "$WITH_PPROF" == "yes" ]; then
880 sspin "Remove port-forwards: *-profiler$CEOL"
881 kill_port_forward voltha-rw-core-profiler
882 if [ "$WITH_OPEN_ADAPTERS" == "yes" ]; then
883 kill_port_forward adapter-open-olt-profiler
884 fi
885 fi
886
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800887 espin "$VERIFIED Remove port-forwards$CEOL"
David Bainbridged18f4942020-04-14 16:46:13 -0700888 if [ "$DEPLOY_K8S" == "yes" ]; then
David Bainbridgeac7f8072019-08-01 22:15:33 +0000889 if [ -x ./bin/kind ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000890 bspin "Delete Kubernetes Kind Cluster"
David Bainbridged18f4942020-04-14 16:46:13 -0700891 (set -x; ./bin/kind delete cluster --name "voltha-$NAME" >>"$LOG" 2>&1) >>"$LOG" 2>&1
892 espin "$VERIFIED"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000893 else
David Bainbridge0774b232019-08-02 06:37:19 +0000894 espin "$NO_ENTRY Delete Kubernetes Kind Cluster: kind command not found"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000895 fi
896 else
David Bainbridge309099c2020-05-05 08:47:29 -0700897 if [ "$CONFIG_SADIS" == "external" ]; then
898 bspin "Remove configmap for BBSIM SADIS server"
899 (set -x; kubectl -n "$BBSIM_NS" delete --ignore-not-found configmap kube-config >>"$LOG" 2>&1) >>"$LOG" 2>&1
900 espin "$VERIFIED"
901 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700902 EXISTS="$(helm list -q)"
David Bainbridge76afd812020-04-06 09:53:52 -0700903 EXPECT="voltha"
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700904 if is_in "$WITH_ONOS" "yes,legacy,classic"; then
David Bainbridge696bc632020-04-05 21:49:37 -0700905 EXPECT+=" onos"
906 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700907 if [ "$WITH_RADIUS" == "yes" ]; then
David Bainbridge696bc632020-04-05 21:49:37 -0700908 EXPECT+=" radius"
909 fi
David Bainbridge309099c2020-05-05 08:47:29 -0700910 if [ "$CONFIG_SADIS" == "external" ]; then
911 EXPECT+=" bbsim-sadis-server"
912 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700913 if [ "$WITH_BBSIM" == "yes" ]; then
David Bainbridge696bc632020-04-05 21:49:37 -0700914 EXPECT+=" bbsim"
915 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700916 if [ "$WITH_OPEN_ADAPTERS" == "yes" ]; then
David Bainbridge696bc632020-04-05 21:49:37 -0700917 EXPECT+=" open-olt open-onu"
918 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700919 if [ "$WITH_SIM_ADAPTERS" == "yes" ]; then
David Bainbridge696bc632020-04-05 21:49:37 -0700920 EXPECT+=" sim"
921 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700922 if [ "$WITH_ETCD" == "external" ]; then
David Bainbridge76afd812020-04-06 09:53:52 -0700923 EXPECT+=" 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 EXPECT+=" 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 EXPECT+=" kafka"
929 fi
David Bainbridge0774b232019-08-02 06:37:19 +0000930 bspin "Remove Helm Deployments"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000931 for i in $EXISTS; do
David K. Bainbridge43422402020-03-06 07:41:22 -0800932 for j in $EXPECT; do
David Bainbridged18f4942020-04-14 16:46:13 -0700933 if [[ "$i" =~ $j ]]; then
David K. Bainbridge43422402020-03-06 07:41:22 -0800934 sspin "Remove Helm Deployments: $i$CEOL"
David Bainbridged18f4942020-04-14 16:46:13 -0700935 (set -x; ./bin/helm delete --no-hooks --purge "$i" >>"$LOG" 2>&1) >>"$LOG" 2>&1
David K. Bainbridge43422402020-03-06 07:41:22 -0800936 fi
937 done
uottrembb16d3982020-02-28 08:34:36 +0100938 done
David Bainbridge0774b232019-08-02 06:37:19 +0000939 espin "$VERIFIED Remove Helm Deployments$CEOL"
David Bainbridge4f1b5562019-08-19 04:46:52 +0000940 if [ "$WAIT_ON_DOWN" == "yes" ]; then
David Bainbridge76afd812020-04-06 09:53:52 -0700941 PODS="voltha-kafka.* voltha-ofagent.* voltha-rw-core.* voltha-etcd.*"
942 INFRA_PODS=
943 ADAPT_PODS=
944 SIM_PODS=
David Bainbridged18f4942020-04-14 16:46:13 -0700945 if [ "$WITH_RADIUS" == "yes" ]; then
David Bainbridge696bc632020-04-05 21:49:37 -0700946 PODS+=" radius.*"
947 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700948 if [ "$WITH_BBSIM" == "yes" ]; then
David Bainbridge76afd812020-04-06 09:53:52 -0700949 SIM_PODS+=" bbsim.*"
David Bainbridge696bc632020-04-05 21:49:37 -0700950 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700951 if [ "$WITH_OPEN_ADAPTERS" ] || [ "$WITH_SIM_ADAPTERS" ]; then
David Bainbridge76afd812020-04-06 09:53:52 -0700952 ADAPT_PODS+=" adapter-*"
David Bainbridge696bc632020-04-05 21:49:37 -0700953 fi
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700954 if is_in "$WITH_ONOS" "yes,legacy,classic"; then
David Bainbridge76afd812020-04-06 09:53:52 -0700955 INFRA_PODS+=" onos-.*"
956 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700957 if [ "$WITH_ETCD" == "external" ]; then
David Bainbridge76afd812020-04-06 09:53:52 -0700958 INFRA_PODS+=" etcd-operator.* etcd-cluster.*"
David Bainbridged18f4942020-04-14 16:46:13 -0700959 elif [ "$WITH_ETCD" == "yes" ]; then
David Bainbridge76afd812020-04-06 09:53:52 -0700960 PODS+=" etcd-operator.*"
961 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700962 if [ "$WITH_KAFKA" == "external" ]; then
David Bainbridge76afd812020-04-06 09:53:52 -0700963 INFRA_PODS+=" kafka.*"
964 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700965 if [ -n "$SIM_PODS" ]; then
966 wait_for_pods "$BBSIM_NS" 0 "not" "Waiting for BBSIM PODs to terminate" "$BBSIM_LABEL" "$SIM_PODS"
David Bainbridge76afd812020-04-06 09:53:52 -0700967 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700968 if [ -n "$INFRA_PODS" ]; then
969 wait_for_pods "$INFRA_NS" 0 "not" "Waiting for infrastructure PODs to terminate" "$NO_LABEL" "$INFRA_PODS"
David Bainbridge76afd812020-04-06 09:53:52 -0700970 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700971 if [ -n "$ADAPT_PODS" ]; then
972 wait_for_pods "$ADAPTER_NS" 0 "not" "Waiting for adapter PODs to terminate" "$NO_LABEL" "$ADAPT_PODS"
David Bainbridge76afd812020-04-06 09:53:52 -0700973 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700974 wait_for_pods "$VOLTHA_NS" 0 "not" "Waiting for VOLTHA PODs to terminate" "$NO_LABEL" "$PODS"
David Bainbridge4f1b5562019-08-19 04:46:52 +0000975 fi
David Bainbridgeac7f8072019-08-01 22:15:33 +0000976 fi
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -0700977 exit
David Bainbridgeac7f8072019-08-01 22:15:33 +0000978fi
979
980if [ "$1" == "dump" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000981 LOG="dump-$NAME.log"
David Bainbridged18f4942020-04-14 16:46:13 -0700982 TS="$(date -u +"%Y%m%dT%H%M%SZ")"
983 if [ -n "$DUMP_FROM" ]; then
984 TS=${DUMP_FROM//[:-]}
David Bainbridge76514a02019-10-08 01:50:35 +0000985 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700986 WORK="$(mktemp -u -d)"
David Bainbridge0774b232019-08-02 06:37:19 +0000987 DATA=$WORK/voltha-debug-dump-$NAME-$TS
David Bainbridged18f4942020-04-14 16:46:13 -0700988 mkdir -p "$DATA"
989 echo "$TS" > "$LOG"
David Bainbridge0774b232019-08-02 06:37:19 +0000990 echo -e "Capturing debug dump to voltha-debug-dump-$NAME-$TS.tgz"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000991 bspin - "Copy install log"
David Bainbridged18f4942020-04-14 16:46:13 -0700992 if [ -f "install-$NAME.log" ]; then
993 (set -x; cp "install-$NAME.log" "$DATA/install-$NAME.log") >>"$LOG" 2>&1
994 espin - "$VERIFIED"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000995 else
David Bainbridge0774b232019-08-02 06:37:19 +0000996 espin - "$NO_ENTRY Copy install log: install-$NAME.log not found"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000997 fi
998 bspin - "Dumping Kubernetes PODs"
David Bainbridged18f4942020-04-14 16:46:13 -0700999 (set -x; kubectl get --all-namespaces pods >> "$DATA/all-pods.txt" 2>&1) >>"$LOG" 2>&1
1000 espin - "$VERIFIED"
David Bainbridgeac7f8072019-08-01 22:15:33 +00001001 bspin - "Dumping Kubernetes SERVICEs"
David Bainbridged18f4942020-04-14 16:46:13 -07001002 (set -x; kubectl get --all-namespaces svc >> "$DATA/all-services.txt" 2>&1) >>"$LOG" 2>&1
1003 espin - "$VERIFIED"
David Bainbridgeac7f8072019-08-01 22:15:33 +00001004 bspin - "Dumping Kubernetes EVENTs"
David Bainbridged18f4942020-04-14 16:46:13 -07001005 (set -x; kubectl get --all-namespaces events >> "$DATA/all-events.txt" 2>&1) >>"$LOG" 2>&1
1006 espin - "$VERIFIED"
David Bainbridgeac7f8072019-08-01 22:15:33 +00001007 bspin - "Dumping VOLTHA POD details"
David Bainbridged18f4942020-04-14 16:46:13 -07001008 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 +00001009 SINCE=
David Bainbridged18f4942020-04-14 16:46:13 -07001010 if [ -n "$DUMP_FROM" ]; then
David Bainbridgecfd7ca12019-10-06 03:31:41 +00001011 SINCE="--since-time=$DUMP_FROM"
1012 fi
David Bainbridgeac7f8072019-08-01 22:15:33 +00001013 for POD in $PODS; do
David Bainbridged18f4942020-04-14 16:46:13 -07001014 NS="$(echo "$POD" | cut -d: -f1)"
1015 POD="$(echo "$POD" | cut -d: -f2)"
David Bainbridgeac7f8072019-08-01 22:15:33 +00001016 sspin - "Dumping VOLTHA POD details: $POD$CEOL"
David Bainbridged18f4942020-04-14 16:46:13 -07001017 mkdir -p "$DATA/$POD"
1018 (set -x; kubectl describe -n "$NS" "$POD" >> "$DATA/$POD/describe.txt" 2>&1) >>"$LOG" 2>&1
David Bainbridgeac7f8072019-08-01 22:15:33 +00001019 sspin - "Dumping VOLTHA POD details: $POD"
David Bainbridged18f4942020-04-14 16:46:13 -07001020 (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 +00001021 sspin - "Dumping VOLTHA POD details: $POD"
David Bainbridged18f4942020-04-14 16:46:13 -07001022 (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 +00001023 sspin - "Dumping VOLTHA POD details: $POD"
1024 done
1025 espin - "$VERIFIED Dumping VOLTHA POD details$CEOL"
1026 bspin - "Dumping ETCD"
David Bainbridged18f4942020-04-14 16:46:13 -07001027 if [ -n "$(command -v etcdctl)" ]; then
1028 (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
1029 espin - "$VERIFIED"
David Bainbridgeac7f8072019-08-01 22:15:33 +00001030 else
1031 espin - "$NO_ENTRY Dumping ETCD: etcdctl command not available"
1032 fi
David Bainbridge0774b232019-08-02 06:37:19 +00001033 bspin - "Creating compressed TAR: voltha-debug-dump-$NAME-$TS.tgz"
David Bainbridged18f4942020-04-14 16:46:13 -07001034 (set -x; tar -C "$WORK" -zcf "voltha-debug-dump-$NAME-$TS.tgz" "./voltha-debug-dump-$NAME-$TS") >>"$LOG" 2>&1
1035 espin - "$VERIFIED"
David Bainbridgeac7f8072019-08-01 22:15:33 +00001036 bspin - "Cleanup"
David Bainbridged18f4942020-04-14 16:46:13 -07001037 (set -x; rm -rf "$WORK") >>"$LOG" 2>&1
1038 espin - "$VERIFIED"
1039 bspin - "$(ls -l "voltha-debug-dump-$NAME-$TS.tgz")"
1040 espin - "$VERIFIED"
David Bainbridgeac7f8072019-08-01 22:15:33 +00001041 exit
1042fi
1043
David Bainbridge0774b232019-08-02 06:37:19 +00001044LOG="install-$NAME.log"
David Bainbridged18f4942020-04-14 16:46:13 -07001045date > "$LOG"
1046echo "PORTS=$ONOS_API_PORT,$ONOS_SSH_PORT,$VOLTHA_API_PORT,$VOLTHA_SSH_PORT,$VOLTHA_ETCD_PORT" >> "$LOG"
David Bainbridgeac7f8072019-08-01 22:15:33 +00001047
1048# Output install options to log
David Bainbridged18f4942020-04-14 16:46:13 -07001049echo "OPTIONS" >> "$LOG"
David Bainbridgeac7f8072019-08-01 22:15:33 +00001050for O in $ALL_OPTIONS; do
David Bainbridged18f4942020-04-14 16:46:13 -07001051 VAL="$(eval echo "\$$O")"
1052 if [ -n "$VAL" ]; then
1053 printf " %-30s = %s\n" "$O" "$VAL" >> "$LOG"
David Bainbridgeac7f8072019-08-01 22:15:33 +00001054 fi
1055done
1056
David Bainbridgefad50732020-05-01 17:00:12 -07001057helm_values() {
1058 local NAMESPACE=$1; shift
1059 local INAME=$1; shift
1060 local CHART=$1; shift
1061 local CHART_VERSION=$1; shift
1062
1063 if [ "$CHART_VERSION X" != " X" ] && [ "$CHART_VERSION" != "latest" ]; then
1064 CHART_VERSION="--version $CHART_VERSION"
1065 else
1066 CHART_VERSION=
1067 fi
1068
1069 local CHART_ARGS=
1070 if [ -r "${INAME}-values.yaml" ]; then
1071 CHART_ARGS="-f ${INAME}-values.yaml"
1072 fi
1073
1074 if [ "$HELM_USE_UPGRADE" == "yes" ]; then
1075 _HELM_COMMAND="upgrade --install"
1076 _HELM_ARGS="xxxdryrunxxx"
1077 else
1078 _HELM_COMMAND="install"
1079 _HELM_ARGS="--name xxxdryrunxxx"
1080 fi
1081 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")
1082 ${CMD[*]} 2>/dev/null | awk 'PRINT==1 {print}; /^USER-SUPPLIED VALUES:/ {PRINT = 1}; /^$/ {PRINT = 0}'
1083}
1084
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001085helm_install() {
David Bainbridged18f4942020-04-14 16:46:13 -07001086 local INDENT NOW
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001087 if [ "$1" == "-" ]; then
1088 INDENT=$1; shift
1089 fi
1090 local NAMESPACE=$1; shift
David Bainbridge0774b232019-08-02 06:37:19 +00001091 local INAME=$1; shift
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001092 local CHART=$1; shift
David Bainbridge90fd8e32019-08-21 23:32:47 +00001093 local CHART_VERSION=$1; shift
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001094 local MESSAGE=$*
1095
David Bainbridged18f4942020-04-14 16:46:13 -07001096 if [ "$CHART_VERSION X" != " X" ] && [ "$CHART_VERSION" != "latest" ]; then
David Bainbridge90fd8e32019-08-21 23:32:47 +00001097 CHART_VERSION="--version $CHART_VERSION"
1098 else
1099 CHART_VERSION=
1100 fi
1101
David Bainbridge99ac7a22019-08-31 02:26:43 +00001102 local CHART_ARGS=
1103 if [ -r "${INAME}-values.yaml" ]; then
1104 CHART_ARGS="-f ${INAME}-values.yaml"
1105 fi
1106
David Bainbridged18f4942020-04-14 16:46:13 -07001107 local WAIT_START CMD
1108 WAIT_START="$(date +%s)"
1109 COUNT="$((300 / 15))"
1110 bspin "$INDENT" "$MESSAGE"
1111 if [ "$HELM_USE_UPGRADE" == "yes" ]; then
David Bainbridge7f8bf992020-04-08 21:53:22 -07001112 _HELM_COMMAND="upgrade --install"
1113 _HELM_ARGS="$INAME"
1114 else
1115 _HELM_COMMAND="install"
1116 _HELM_ARGS="--name $INAME"
1117 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001118 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")
1119 (set -x; ${CMD[*]} >>"$LOG" 2>&1) >>"$LOG" 2>&1
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001120 SUCCESS=$?
David Bainbridged18f4942020-04-14 16:46:13 -07001121 while [ "$SUCCESS" -ne 0 ]; do
1122 NOW="$(date +%s)"
1123 if [ "$((NOW - WAIT_START))" -gt "$TIMEOUT_SECONDS" ]; then
David Bainbridge52e6e9d2020-03-23 13:48:27 -07001124 espin "$THEX"
1125 doTimeout "waiting for helm install $CHART"
1126 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001127 sspin "$INDENT"
1128 COUNT="$((COUNT - 1))"
1129 if [ "$COUNT" -eq 0 ]; then
1130 if [ "$HELM_USE_UPGRADE" == "no" ]; then
1131 (set -x; helm delete --purge "$INAME" >>"$LOG" 2>&1) >>"$LOG" 2>&1
David Bainbridge7f8bf992020-04-08 21:53:22 -07001132 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001133 (set -x; ${CMD[*]} >>"$LOG" 2>&1) >>"$LOG" 2>&1
Andy Baviere22ff252019-12-19 11:40:31 -07001134 SUCCESS=$?
David Bainbridged18f4942020-04-14 16:46:13 -07001135 COUNT="$((300 / 15))"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001136 fi
1137 sleep .15
1138 done
David Bainbridged18f4942020-04-14 16:46:13 -07001139 espin "$INDENT" "$VERIFIED"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001140}
1141
David Bainbridged18f4942020-04-14 16:46:13 -07001142echo "INSTALL TYPE: $TYPE" >> "$LOG"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001143
1144bspin "Verify GOPATH"
David Bainbridged18f4942020-04-14 16:46:13 -07001145GOPATH="$(pwd)"; export GOPATH
1146mkdir -p "$GOPATH/bin"
1147espin "$VERIFIED"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001148
David Bainbridged18f4942020-04-14 16:46:13 -07001149STIME="$(date +%s)"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001150if [ "$INSTALL_KUBECTL" == "no" ]; then
1151 bspin "Skip kubectl install"
1152 espin $NO_ENTRY
Test Userc13bdc92019-07-03 20:57:49 +00001153else
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001154 bspin "Verify kubectl $HELM"
David Bainbridged18f4942020-04-14 16:46:13 -07001155 if [ -x "$GOPATH/bin/kubectl" ]; then
1156 espin "$VERIFIED"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001157 else
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001158 ERR_OUT="$(mktemp)"
David Bainbridged18f4942020-04-14 16:46:13 -07001159 espin "$NOT_VERIFIED"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001160 bspin - "Download and install Kubernetes/kubectl $DOWNLOAD"
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001161 (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
1162 RESULT=$?
1163 if [ "$RESULT" -ne 0 ]; then
1164 espin - "$THEX"
David Bainbridgee3fc0c32020-04-21 15:34:04 -07001165 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR: unable to download kubectl: $(tail "$ERR_OUT")${NORMAL}"
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001166 cat "$ERR_OUT" >> "$LOG"
Zack Williamsded60cb2020-04-13 10:02:20 -07001167 rm -rf "$ERR_OUT" "$GOPATH/bin/kubectl"
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001168 exit 1
1169 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001170 (set -x; chmod 755 "$GOPATH/bin/kubectl" >>"$LOG" 2>&1) >>"$LOG" 2>&1
1171 espin - "$VERIFIED"
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001172 rm -rf "$ERR_OUT"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001173 fi
Test Userc13bdc92019-07-03 20:57:49 +00001174fi
David Bainbridgee87067b2019-08-12 22:00:12 +00001175if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001176 NOW="$(date +%s)"
1177 printtime $((NOW - STIME))
David Bainbridgee87067b2019-08-12 22:00:12 +00001178fi
Test Userc13bdc92019-07-03 20:57:49 +00001179
David Bainbridged18f4942020-04-14 16:46:13 -07001180STIME="$(date +%s)"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001181if [ "$DEPLOY_K8S" == "no" ]; then
1182 bspin "Skip Kubernetes/Kind Deployment"
1183 espin $NO_ENTRY
1184else
Test Userba1e7e72019-07-10 22:27:54 +00001185 bspin "Verify Kubernetes/Kind $HELM"
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -08001186 IS_INSTALLED=0
1187 OP_TYPE="install"
David Bainbridged18f4942020-04-14 16:46:13 -07001188 if [ -x "$GOPATH/bin/kind" ]; then
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -08001189 OP_TYPE="upgrade"
David Bainbridged18f4942020-04-14 16:46:13 -07001190 if [ "$("$GOPATH/bin/kind" --version | grep -c "$KIND_VERSION")" -eq 1 ]; then
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -08001191 IS_INSTALLED=1
David Bainbridged18f4942020-04-14 16:46:13 -07001192 espin "$VERIFIED"
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -08001193 fi
1194 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001195 if [ "$IS_INSTALLED" -eq 0 ]; then
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001196 ERR_OUT="$(mktemp)"
David Bainbridged18f4942020-04-14 16:46:13 -07001197 espin "$NOT_VERIFIED"
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -08001198 bspin - "Download and $OP_TYPE Kubernetes/kind $DOWNLOAD"
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001199 (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
1200 RESULT=$?
1201 if [ $RESULT -ne 0 ]; then
1202 espin - "$THEX"
David Bainbridgee3fc0c32020-04-21 15:34:04 -07001203 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR: unable to download kind: $(tail "$ERR_OUT")${NORMAL}"
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001204 cat "$ERR_OUT" >> "$LOG"
Zack Williamsded60cb2020-04-13 10:02:20 -07001205 rm -rf "$ERR_OUT" "$GOPATH/bin/kind"
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001206 exit 1
1207 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001208 (set -x; chmod 755 "$GOPATH/bin/kind" >>"$LOG" 2>&1) >>"$LOG" 2>&1
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001209 rm -rf "$ERR_OUT"
David Bainbridged18f4942020-04-14 16:46:13 -07001210 espin - "$VERIFIED"
Test Userba1e7e72019-07-10 22:27:54 +00001211 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001212fi
1213
David Bainbridgee87067b2019-08-12 22:00:12 +00001214if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001215 NOW="$(date +%s)"
1216 printtime $((NOW - STIME))
David Bainbridgee87067b2019-08-12 22:00:12 +00001217fi
1218
David Bainbridged18f4942020-04-14 16:46:13 -07001219STIME="$(date +%s)"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001220if [ "$INSTALL_HELM" == "no" ]; then
1221 bspin "Skip Helm Install"
1222 espin $NO_ENTRY
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001223else
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001224 bspin "Verify Helm $HELM"
David Bainbridgea34993d2020-04-01 09:15:42 -07001225 HELM_UPGRADE=0
1226 HELM_UPGRADE_DESC="install"
David Bainbridged18f4942020-04-14 16:46:13 -07001227 if [ -x "$GOPATH/bin/helm" ]; then
1228 HAVE_VER="$("$GOPATH/bin/helm" version -c --template '{{.Client.SemVer}}')"
1229 HELM_UP_DOWN="$(echo -e "$HAVE_VER\n$HELM_VERSION" | sort -V | head -1)"
1230 if [ "$HAVE_VER" != "$HELM_VERSION" ]; then
1231 if [ "$HELM_UP_DOWN" == "$HELM_VERSION" ]; then
David Bainbridgea34993d2020-04-01 09:15:42 -07001232 HELM_UPGRADE_DESC="downgrade"
1233 else
1234 HELM_UPGRADE_DESC="upgrade"
1235 fi
1236 HELM_UPGRADE=1
1237 else
David Bainbridged18f4942020-04-14 16:46:13 -07001238 espin "$VERIFIED"
David Bainbridgea34993d2020-04-01 09:15:42 -07001239 fi
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001240 else
David Bainbridgea34993d2020-04-01 09:15:42 -07001241 HELM_UPGRADE=1
1242 fi
1243
David Bainbridged18f4942020-04-14 16:46:13 -07001244 if [ "$HELM_UPGRADE" -ne 0 ]; then
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001245 ERR_OUT="$(mktemp)"
1246 INSTALL_HELM_BIN=$(mktemp)
David Bainbridged18f4942020-04-14 16:46:13 -07001247 espin "$NOT_VERIFIED"
David Bainbridgea34993d2020-04-01 09:15:42 -07001248 bspin - "Download and $HELM_UPGRADE_DESC Helm $DOWNLOAD"
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001249 (set -x; curl -o "$INSTALL_HELM_BIN" --fail -sSL https://git.io/get_helm.sh >>"$LOG" 2>"$ERR_OUT") >>"$LOG" 2>&1
1250 RESULT=$?
1251 if [ $RESULT -ne 0 ]; then
1252 espin - "$THEX"
David Bainbridgee3fc0c32020-04-21 15:34:04 -07001253 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR: unable to download helm installer: $(tail "$ERR_OUT")${NORMAL}"
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001254 cat "$ERR_OUT" >> "$LOG"
1255 rm -rf "$INSTALL_HELM_BIN" "$ERR_OUT" "$GOPATH/bin/helm" "$GOPATH/bin/tiller"
1256 exit 1
1257 fi
1258 rm -rf "$ERR_OUT"
1259 chmod +x "$INSTALL_HELM_BIN"
1260 (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
1261 RESULT=$?
1262 if [ $RESULT -ne 0 ]; then
1263 espin - "$THEX"
1264 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR: unable to install helm, see install log for details${NORMAL}"
1265 rm -rf "$INSTALL_HELM_BIN" "$ERR_OUT" "$GOPATH/bin/helm" "$GOPATH/bin/tiller"
1266 exit 1
1267 fi
1268 rm -rf "$INSTALL_HELM_BIN" "$ERR_OUT"
David Bainbridged18f4942020-04-14 16:46:13 -07001269 espin - "$VERIFIED"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001270 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001271fi
David Bainbridgee87067b2019-08-12 22:00:12 +00001272if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001273 NOW="$(date +%s)"
1274 printtime $((NOW - STIME))
David Bainbridgee87067b2019-08-12 22:00:12 +00001275fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001276
David Bainbridged18f4942020-04-14 16:46:13 -07001277STIME="$(date +%s)"
Test Userb5712372019-07-03 21:52:17 +00001278bspin "Verify voltctl $HIGH_VOLTAGE"
David Bainbridged2811972019-12-14 01:14:09 +00001279VOK=0
1280VMESSAGE="install"
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001281ERR_OUT=$(mktemp)
David K. Bainbridgeebf38d92020-02-10 10:46:31 -08001282export VC_VERSION="$VOLTCTL_VERSION"
1283if [ "$VC_VERSION" == "latest" ]; then
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001284 set -o pipefail # TODO: would be nice to run all in pipefail mode
1285 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')"
1286 RESULT=$?
1287 set +o pipefail
1288 if [ "$RESULT" -ne 0 ]; then
1289 espin - "$THEX"
1290 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR: unable to determine released version of voltctl: $(cat "$ERR_OUT")${NORMAL}"
1291 rm -rf "$ERR_OUT" "$GOPATH/bin/voltctl"
1292 exit 1
1293 fi
1294 export VC_VERSION
David K. Bainbridgeebf38d92020-02-10 10:46:31 -08001295fi
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001296
David Bainbridged18f4942020-04-14 16:46:13 -07001297if [ -x "$GOPATH/bin/voltctl" ]; then
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001298 VHAVE="$("$GOPATH/bin/voltctl" version --clientonly -o json 2>/dev/null | jq -r .version)"
David Bainbridged18f4942020-04-14 16:46:13 -07001299 RESULT=$?
1300 if [ $RESULT -eq 0 ] && [ "$VHAVE" == "$VC_VERSION" ]; then
David Bainbridged2811972019-12-14 01:14:09 +00001301 VOK=1
David Bainbridged18f4942020-04-14 16:46:13 -07001302 espin "$VERIFIED"
David Bainbridge1ba64f12019-12-18 00:40:13 +00001303 else
David Bainbridged18f4942020-04-14 16:46:13 -07001304 VCHECK="$(echo -e "$VHAVE\n$VC_VERSION" | sort -V | head -1)"
David K. Bainbridgeebf38d92020-02-10 10:46:31 -08001305 if [ "$VCHECK" == "$VHAVE" ]; then
1306 VMESSAGE="upgrade"
1307 else
1308 VMESSAGE="downgrade"
1309 fi
David Bainbridged2811972019-12-14 01:14:09 +00001310 fi
1311fi
1312
David Bainbridged18f4942020-04-14 16:46:13 -07001313if [ "$VOK" -eq 0 ]; then
1314 espin "$NOT_VERIFIED"
David Bainbridged2811972019-12-14 01:14:09 +00001315 bspin - "Download and $VMESSAGE voltctl $DOWNLOAD"
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001316 (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
1317 RESULT=$?
1318 if [ $RESULT -ne 0 ]; then
1319 espin - "$THEX"
1320 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR: unable to download voltctl (version $VC_VERSION): $(cat "$ERR_OUT")${NORMAL}"
1321 rm -rf "$ERR_OUT" "$GOPATH/bin/voltctl"
1322 exit 1
1323 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001324 (set -x; chmod 755 "$GOPATH/bin/voltctl" >>"$LOG" 2>&1) >>"$LOG" 2>&1
1325 espin - "$VERIFIED"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001326fi
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001327rm -rf "$ERR_OUT"
David Bainbridgee87067b2019-08-12 22:00:12 +00001328if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001329 NOW="$(date +%s)"
1330 printtime $((NOW - STIME))
David Bainbridgee87067b2019-08-12 22:00:12 +00001331fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001332
1333bspin "Verify command PATH"
Test Userba1e7e72019-07-10 22:27:54 +00001334export PATH=$GOPATH/bin:$PATH
David Bainbridged18f4942020-04-14 16:46:13 -07001335espin "$VERIFIED"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001336
David Bainbridged18f4942020-04-14 16:46:13 -07001337STIME="$(date +%s)"
Test Userba1e7e72019-07-10 22:27:54 +00001338if [ "$DEPLOY_K8S" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001339 HAVE="$(kind get clusters | grep -c "voltha-$NAME")"
Test Userba1e7e72019-07-10 22:27:54 +00001340 bspin "Verify Kubernetes/Kind Cluster"
1341 sspin
David Bainbridged18f4942020-04-14 16:46:13 -07001342 if [ "$HAVE" -eq 0 ]; then
1343 espin "$NOT_VERIFIED"
David Bainbridge491b1bd2019-07-11 17:53:11 +00001344 bspin - "Verify cluster configuration"
David Bainbridged18f4942020-04-14 16:46:13 -07001345 if [ ! -r "./$NAME-cluster.cfg" ]; then
1346 espin - "$NOT_VERIFIED"
David K. Bainbridge43422402020-03-06 07:41:22 -08001347 bspin - "Download cluster configuration: $TYPE-cluster.cfg to $NAME-cluster.cfg $DOWNLOAD"
David Bainbridged18f4942020-04-14 16:46:13 -07001348 ERR_OUT="$(mktemp)"
serkant.uluderya4d315132020-04-15 16:25:54 -07001349 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 -07001350 espin - "$THEX"
1351 echo -e "${RED}${BOLD}${ERROR}ERROR: $NAME-cluster.cfg${NORMAL}${RED} - $(cat "$ERR_OUT")${NORMAL}"
1352 echo "ERROR: $(cat "$ERR_OUT")" >>"$LOG"
1353 rm -rf "$ERR_OUT" "./$NAME-cluster.cfg"
David K. Bainbridgea00736b2020-01-08 14:33:17 -08001354 exit 1
1355 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001356 rm -rf "$ERR_OUT"
David K. Bainbridgea00736b2020-01-08 14:33:17 -08001357 else
David Bainbridged18f4942020-04-14 16:46:13 -07001358 espin - "$VERIFIED"
David K. Bainbridgea00736b2020-01-08 14:33:17 -08001359 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001360 kind create cluster --name "voltha-$NAME" --config "$NAME-cluster.cfg"
David Bainbridge491b1bd2019-07-11 17:53:11 +00001361 else
David Bainbridged18f4942020-04-14 16:46:13 -07001362 espin "$VERIFIED"
Test Userba1e7e72019-07-10 22:27:54 +00001363 fi
1364
David Bainbridged18f4942020-04-14 16:46:13 -07001365 KUBECONFIG="$(kind get kubeconfig-path --name="voltha-$NAME")"; export KUBECONFIG
Test Userba1e7e72019-07-10 22:27:54 +00001366 P="coredns-.* \
David Bainbridge0774b232019-08-02 06:37:19 +00001367 etcd-voltha-$NAME-control-plane \
Test Userba1e7e72019-07-10 22:27:54 +00001368 kindnet-.* \
David Bainbridge0774b232019-08-02 06:37:19 +00001369 kube-apiserver-voltha-$NAME-control-plane \
1370 kube-controller-manager-voltha-$NAME-control-plane \
Test Userba1e7e72019-07-10 22:27:54 +00001371 kube-proxy-.* \
David Bainbridge0774b232019-08-02 06:37:19 +00001372 kube-scheduler-voltha-$NAME-control-plane"
Test Userba1e7e72019-07-10 22:27:54 +00001373
David Bainbridged18f4942020-04-14 16:46:13 -07001374 EXPECT="$(test "$TYPE" == "minimal" && echo "12" || echo "14")"
1375 wait_for_pods - "kube-system" "$EXPECT" "includes" "Waiting for system PODs to start" "$NO_LABEL" "$P"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001376fi
David Bainbridgee87067b2019-08-12 22:00:12 +00001377if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001378 NOW="$(date +%s)"
1379 printtime $((NOW - STIME))
David Bainbridgee87067b2019-08-12 22:00:12 +00001380fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001381
David Bainbridged18f4942020-04-14 16:46:13 -07001382STIME="$(date +%s)"
1383COUNT="$(count_pods "kube-system" ":Running:" "$NO_LABEL" "tiller-deploy-.*")"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001384bspin "Verify Helm"
David Bainbridged18f4942020-04-14 16:46:13 -07001385if [ "$COUNT" -ne 1 ]; then
1386 espin "$NOT_VERIFIED"
Test Userb5712372019-07-03 21:52:17 +00001387 echo -e "Configuring Helm $GEAR"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001388 if [ "$INSTALL_HELM" == "no" ]; then
1389 bspin - "Skip Helm/Tiller Initialization"
1390 espin - $NO_ENTRY
1391 else
1392 bspin - "Initialize Helm"
David Bainbridged18f4942020-04-14 16:46:13 -07001393 (set -x; helm init --upgrade >>"$LOG" 2>&1) >>"$LOG" 2>&1
1394 espin - "$VERIFIED"
1395 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 -07001396 fi
Test Userb5712372019-07-03 21:52:17 +00001397 bspin - "Add Google Incubator repository to Helm"
David Bainbridged18f4942020-04-14 16:46:13 -07001398 (set -x; helm repo add incubator https://kubernetes-charts-incubator.storage.googleapis.com >>"$LOG" 2>&1) >>"$LOG" 2>&1
1399 espin - "$VERIFIED"
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001400
Test Userba1e7e72019-07-10 22:27:54 +00001401 # HACK (sort-of) - the config for tiller is about to be patched, which will
1402 # cause the tiller pod to be recreated. This can sometimes cause a timing
1403 # issue with the "wait_for_pods" call on tiller as it may incorrectly
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001404 # identify the running/ready tiller pod that is soon to be terminated as
Test Userba1e7e72019-07-10 22:27:54 +00001405 # what it is waiting for. To avoid this issue we do a clean scale down and
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001406 # scale up of the pod so the script controlls when it should be expecting
Test Userba1e7e72019-07-10 22:27:54 +00001407 # things
David Bainbridged18f4942020-04-14 16:46:13 -07001408 (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 -07001409
Test Userb5712372019-07-03 21:52:17 +00001410 bspin - "Add Google Stable repository to Helm"
David Bainbridged18f4942020-04-14 16:46:13 -07001411 (set -x; helm repo add stable https://kubernetes-charts.storage.googleapis.com >>"$LOG" 2>&1) >>"$LOG" 2>&1
1412 espin - "$VERIFIED"
David Bainbridge60ffc0f2020-04-27 22:13:22 -07001413 bspin - "Add ONF VOLTHA repository to Helm"
David Bainbridged18f4942020-04-14 16:46:13 -07001414 (set -x; helm repo add onf https://charts.opencord.org >>"$LOG" 2>&1) >>"$LOG" 2>&1
1415 espin - "$VERIFIED"
David Bainbridge60ffc0f2020-04-27 22:13:22 -07001416 bspin - "Add ONF ONOS repository to Helm"
1417 (set -x; helm repo add onos https://charts.onosproject.org >>"$LOG" 2>&1) >>"$LOG" 2>&1
1418 espin - "$VERIFIED"
1419 bspin - "Add ONF Atomix repository to Helm"
1420 (set -x; helm repo add atomix https://charts.atomix.io >>"$LOG" 2>&1) >>"$LOG" 2>&1
1421 espin - "$VERIFIED"
David Bainbridge309099c2020-05-05 08:47:29 -07001422 bspin - "Add Custom BBSIM SADIS Server repository to Helm"
1423 (set -x; helm repo add bbsim-sadis https://ciena.github.io/bbsim-sadis-server/charts >>"$LOG" 2>&1) >>"$LOG" 2>&1
1424 espin - "$VERIFIED"
Test Userb5712372019-07-03 21:52:17 +00001425 bspin - "Update Helm repository cache"
David Bainbridged18f4942020-04-14 16:46:13 -07001426 (set -x; helm repo update >>"$LOG" 2>&1) >>"$LOG" 2>&1
1427 espin - "$VERIFIED"
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001428
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001429 # Create and k8s service account so that Helm can create pods
Test Userb5712372019-07-03 21:52:17 +00001430 bspin - "Create Tiller ServiceAccount"
David Bainbridged18f4942020-04-14 16:46:13 -07001431 (set -x; kubectl create serviceaccount --namespace kube-system tiller >>"$LOG" 2>&1) >>"$LOG" 2>&1
1432 espin - "$VERIFIED"
Test Userb5712372019-07-03 21:52:17 +00001433 bspin - "Create Tiller ClusterRoleBinding"
David Bainbridged18f4942020-04-14 16:46:13 -07001434 (set -x; kubectl create clusterrolebinding tiller-cluster-rule --clusterrole=cluster-admin --serviceaccount=kube-system:tiller >>"$LOG" 2>&1) >>"$LOG" 2>&1
1435 espin - "$VERIFIED"
Test Userb5712372019-07-03 21:52:17 +00001436 bspin - "Update Tiller Manifest"
David Bainbridged18f4942020-04-14 16:46:13 -07001437 (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 +00001438
1439 # HACK (sort-of) - part to, spin it back up
David Bainbridged18f4942020-04-14 16:46:13 -07001440 (set -x; kubectl -n kube-system scale deploy tiller-deploy --replicas=1 >>"$LOG" 2>&1) >>"$LOG" 2>&1
1441 espin - "$VERIFIED"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001442else
David Bainbridged18f4942020-04-14 16:46:13 -07001443 if [ "$(helm version -s --template '{{.Server.SemVer}}')" != "$HELM_VERSION" ]; then
1444 espin "$NOT_VERIFIED"
David Bainbridgea34993d2020-04-01 09:15:42 -07001445 bspin - "Sync Tiller server version with helm client"
David Bainbridged18f4942020-04-14 16:46:13 -07001446 (set -x; helm init --upgrade --force-upgrade --wait >>"$LOG" 2>&1) >>"$LOG" 2>&1
1447 espin - "$VERIFIED"
David Bainbridgea34993d2020-04-01 09:15:42 -07001448 else
David Bainbridged18f4942020-04-14 16:46:13 -07001449 espin "$VERIFIED"
David Bainbridgea34993d2020-04-01 09:15:42 -07001450 fi
1451
David Bainbridge46505fb2019-10-01 21:13:20 +00001452 if [ "$UPDATE_HELM_REPOS" == "yes" ]; then
1453 bspin - "Update Helm repository cache"
David Bainbridged18f4942020-04-14 16:46:13 -07001454 (set -x; helm repo update >>"$LOG" 2>&1) >>"$LOG" 2>&1
1455 espin - "$VERIFIED"
David Bainbridge46505fb2019-10-01 21:13:20 +00001456 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001457fi
David Bainbridged18f4942020-04-14 16:46:13 -07001458wait_for_pods - "kube-system" 1 "includes" "Waiting for Tiller POD to start" "$NO_LABEL" "tiller-deploy-.*"
David Bainbridgee87067b2019-08-12 22:00:12 +00001459if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001460 NOW="$(date +%s)"
1461 printtime $((NOW - STIME))
David Bainbridgee87067b2019-08-12 22:00:12 +00001462fi
David Bainbridgecf546362020-04-21 23:18:50 -07001463# Resolve chart versions and log them for debug/support
1464RESOLVED_VOLTHA_CHART_VERSION=$(resolve_chart_version "$VOLTHA_CHART" "$VOLTHA_CHART_VERSION")
1465RESOLVED_VOLTHA_BBSIM_CHART_VERSION=$(resolve_chart_version "$VOLTHA_BBSIM_CHART" "$VOLTHA_BBSIM_CHART_VERSION")
1466RESOLVED_VOLTHA_ADAPTER_SIM_CHART_VERSION=$(resolve_chart_version "$VOLTHA_ADAPTER_SIM_CHART" "$VOLTHA_ADAPTER_SIM_CHART_VERSION")
1467RESOLVED_VOLTHA_ADAPTER_OPEN_OLT_CHART_VERSION=$(resolve_chart_version "$VOLTHA_ADAPTER_OPEN_OLT_CHART" "$VOLTHA_ADAPTER_OPEN_OLT_CHART_VERSION")
1468RESOLVED_VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION=$(resolve_chart_version "$VOLTHA_ADAPTER_OPEN_ONU_CHART" "$VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION")
1469RESOLVED_ONOS_CHART_VERSION=$(resolve_chart_version "$ONOS_CHART" "$ONOS_CHART_VERSION")
David Bainbridge60ffc0f2020-04-27 22:13:22 -07001470RESOLVED_ONOS_CLASSIC_CHART_VERSION=$(resolve_chart_version "$ONOS_CLASSIC_CHART" "$ONOS_CLASSIC_CHART_VERSION")
David Bainbridgecf546362020-04-21 23:18:50 -07001471RESOLVED_KAFKA_CHART_VERSION=$(resolve_chart_version "$KAFKA_CHART" "$KAFKA_CHART_VERSION")
1472cat <<EOV >>"$LOG"
1473Resolved helm charts and versions:
1474 $VOLTHA_CHART:$RESOLVED_VOLTHA_CHART_VERSION
1475 $VOLTHA_BBSIM_CHART:$RESOLVED_VOLTHA_BBSIM_CHART_VERSION
1476 $VOLTHA_ADAPTER_SIM_CHART:$RESOLVED_VOLTHA_ADAPTER_SIM_CHART_VERSION
1477 $VOLTHA_ADAPTER_OPEN_OLT_CHART:$RESOLVED_VOLTHA_ADAPTER_OPEN_OLT_CHART_VERSION
1478 $VOLTHA_ADAPTER_OPEN_ONU_CHART:$RESOLVED_VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION
1479 $ONOS_CHART:$RESOLVED_ONOS_CHART_VERSION
David Bainbridge60ffc0f2020-04-27 22:13:22 -07001480 $ONOS_CLASSIC_CHART:$RESOLVED_ONOS_CLASSIC_CHART_VERSION
David Bainbridgecf546362020-04-21 23:18:50 -07001481 $KAFKA_CHART:$RESOLVED_KAFKA_CHART_VERSION
1482EOV
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001483
David Bainbridged18f4942020-04-14 16:46:13 -07001484STIME="$(date +%s)"
David Bainbridge0774b232019-08-02 06:37:19 +00001485bspin "Verify Helm values file: $NAME-values.yaml"
1486if [ ! -r "./$NAME-values.yaml" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001487 espin "$NOT_VERIFIED"
David Bainbridge0774b232019-08-02 06:37:19 +00001488 bspin - "Download Helm values file: $TYPE-values.yaml to $NAME-values.yaml $DOWNLOAD"
David Bainbridged18f4942020-04-14 16:46:13 -07001489 ERR_OUT="$(mktemp)"
serkant.uluderya4d315132020-04-15 16:25:54 -07001490 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 -07001491 espin - "$THEX"
1492 echo -e "${RED}${BOLD}${ERROR}ERROR: $NAME-values.yaml${NORMAL}${RED} - $(cat "$ERR_OUT")${NORMAL}"
1493 echo "ERROR: $(cat "$ERR_OUT")" >>"$LOG"
1494 rm -rf "$ERR_OUT" "./$NAME-values.yaml"
David K. Bainbridgea00736b2020-01-08 14:33:17 -08001495 exit 1
1496 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001497 rm -rf "$ERR_OUT"
1498 espin - "$VERIFIED"
Test Userba1e7e72019-07-10 22:27:54 +00001499else
David Bainbridged18f4942020-04-14 16:46:13 -07001500 espin "$VERIFIED"
Test Userba1e7e72019-07-10 22:27:54 +00001501fi
David Bainbridgee87067b2019-08-12 22:00:12 +00001502if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001503 NOW="$(date +%s)"
1504 printtime $((NOW - STIME))
David Bainbridgee87067b2019-08-12 22:00:12 +00001505fi
Test Userba1e7e72019-07-10 22:27:54 +00001506
David Bainbridged18f4942020-04-14 16:46:13 -07001507STIME="$(date +%s)"
David Bainbridge99ac7a22019-08-31 02:26:43 +00001508bspin "Verify or download chart specific values files $DOWNLOAD"
1509VALUES_FILES="monkey-values.yaml"
David Bainbridged18f4942020-04-14 16:46:13 -07001510ERR_OUT="$(mktemp)"
David Bainbridge99ac7a22019-08-31 02:26:43 +00001511for i in $VALUES_FILES; do
1512 if [ ! -r ./$i ]; then
serkant.uluderya4d315132020-04-15 16:25:54 -07001513 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 -07001514 espin "$THEX"
1515 echo -e "${RED}${BOLD}${ERROR}ERROR: $i${NORMAL}${RED} - $(cat "$ERR_OUT")${NORMAL}"
1516 echo "ERROR: $i - $(cat "$ERR_OUT")" >>"$LOG"
1517 rm -rf "$ERR_OUT" "./$i"
David K. Bainbridgea00736b2020-01-08 14:33:17 -08001518 exit 1
1519 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001520 rm -rf "$ERR_OUT"
David Bainbridge99ac7a22019-08-31 02:26:43 +00001521 fi
1522done
David Bainbridged18f4942020-04-14 16:46:13 -07001523rm -rf "$ERR_OUT"
1524espin "$VERIFIED"
David Bainbridge99ac7a22019-08-31 02:26:43 +00001525if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001526 NOW="$(date +%s)"
1527 printtime $((NOW - STIME))
David Bainbridge99ac7a22019-08-31 02:26:43 +00001528fi
1529
1530if [ "$WITH_CHAOS" == "yes" ]; then
1531 bspin "Verify or clone kube-monkey helm chart $DOWNLOAD"
1532 if [ -r ./kube-monkey ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001533 espin "$VERIFIED"
David Bainbridge99ac7a22019-08-31 02:26:43 +00001534 else
David Bainbridged18f4942020-04-14 16:46:13 -07001535 espin "$NOT_VERIFIED"
David Bainbridge99ac7a22019-08-31 02:26:43 +00001536 bspin - "GIT clone kube-monkey"
David Bainbridged18f4942020-04-14 16:46:13 -07001537 (set -x; git clone https://github.com/asobti/kube-monkey kube-monkey >>"$LOG" 2>&1) >>"$LOG" 2>&1
1538 espin - "$VERIFIED"
David Bainbridge99ac7a22019-08-31 02:26:43 +00001539 fi
1540fi
1541
Test Userba1e7e72019-07-10 22:27:54 +00001542if [ "$JUST_K8S" == "yes" ]; then
1543 echo "Environment deployed, not deploying VOLTHA artifacts as requested. Good bye."
1544 echo ""
David Bainbridged18f4942020-04-14 16:46:13 -07001545 echo "Please issue the following commands in your terminal to ensure that you" | tee -a "$LOG"
1546 echo "are accessing the correct Kubernetes/Kind cluster as well as have the " | tee -a "$LOG"
1547 echo "tools required by VOLTHA in your command path. " | tee -a "$LOG"
1548 echo "" | tee -a "$LOG"
1549 echo -en "$BOLD"
1550 if [ "$DEPLOY_K8S" == "yes" ]; then
1551 echo "export KUBECONFIG=\"\$(./bin/kind get kubeconfig-path --name=\"voltha-$NAME\")\"" | tee -a "$LOG"
Test Userba1e7e72019-07-10 22:27:54 +00001552 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001553 echo "export PATH=$GOPATH/bin:\$PATH" | tee -a "$LOG"
1554 echo -en "$NORMAL"
1555 echo "" | tee -a "$LOG"
1556 echo "Thank you for choosing kind-voltha for you quick cluster needs." | tee -a "$LOG"
Test Userba1e7e72019-07-10 22:27:54 +00001557 exit 0
1558fi
1559
David Bainbridged18f4942020-04-14 16:46:13 -07001560if [ "$WITH_ETCD" != "yes" ] && [ "$WITH_ETCD" != "external" ]; then
David Bainbridge696bc632020-04-05 21:49:37 -07001561 bspin "Skip ETCD Operator Deployment"
1562 espin $NO_ENTRY
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001563else
David Bainbridged18f4942020-04-14 16:46:13 -07001564 STIME="$(date +%s)"
David Bainbridge76afd812020-04-06 09:53:52 -07001565 NS=$VOLTHA_NS
David Bainbridged18f4942020-04-14 16:46:13 -07001566 if [ "$WITH_ETCD" == "external" ]; then
David Bainbridge76afd812020-04-06 09:53:52 -07001567 NS=$INFRA_NS
1568 fi
David Bainbridge696bc632020-04-05 21:49:37 -07001569 bspin "Verify ETCD Operator $OLD_KEY"
David Bainbridged18f4942020-04-14 16:46:13 -07001570 if [ "$HELM_USE_UPGRADE" == "yes" ] || [ "$(helm list --deployed --short --namespace "$NS" "^etcd-operator\$" | wc -l)" -ne 1 ]; then
1571 espin "$NOT_VERIFIED"
1572 helm_install - "$NS" etcd-operator stable/etcd-operator latest "$_HELM_DESC ETCD Operator"
David Bainbridge696bc632020-04-05 21:49:37 -07001573 else
David Bainbridged18f4942020-04-14 16:46:13 -07001574 espin "$VERIFIED"
David Bainbridge696bc632020-04-05 21:49:37 -07001575 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001576 EXPECT="$(test "$TYPE" == "minimal" && echo "1" || echo "3")"
1577 wait_for_pods - "$NS" "$EXPECT" "includes" "Waiting for ETCD Operator to start" "$NO_LABEL" "etcd-operator-.*"
David Bainbridge696bc632020-04-05 21:49:37 -07001578 if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001579 NOW="$(date +%s)"
1580 printtime $((NOW - STIME))
David Bainbridge696bc632020-04-05 21:49:37 -07001581 fi
David Bainbridgee87067b2019-08-12 22:00:12 +00001582fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001583
David Bainbridged18f4942020-04-14 16:46:13 -07001584STIME="$(date +%s)"
David Bainbridge60ffc0f2020-04-27 22:13:22 -07001585if is_in "$WITH_ONOS" "yes,legacy,classic"; then
1586 if is_in "$WITH_ONOS" "legacy"; then
1587 bspin "Verify ONOS LEGACY installed $BIRD"
1588 if [ "$HELM_USE_UPGRADE" == "yes" ] || [ "$(helm list --deployed --short --namespace "$INFRA_NS" "^onos\$" | wc -l)" -ne 1 ]; then
1589 espin "$NOT_VERIFIED"
1590 INTERNAL_EXTRA_HELM_INSTALL_ARGS="$SET_TAG $EXTRA_HELM_FLAGS" helm_install - "$INFRA_NS" onos "$ONOS_CHART" "$ONOS_CHART_VERSION" "$_HELM_DESC ONOS LEGACY"
1591 INTERNAL_EXTRA_HELM_INSTALL_ARGS=
1592 else
1593 espin "$VERIFIED"
1594 fi
1595 wait_for_pods - "$INFRA_NS" 1 "includes" "Waiting for ONOS to start" "$NO_LABEL" "onos-.*"
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001596
David Bainbridge60ffc0f2020-04-27 22:13:22 -07001597 if [ "$WITH_PORT_FORWARDS" == "yes" ]; then
1598 bspin - "Forward ONOS API port $FORWARD"
1599 kill_port_forward onos-ui
1600 port_forward "$INFRA_NS" onos-ui "$ONOS_API_PORT:8181"
1601 espin - "$VERIFIED"
1602 bspin - "Forward ONOS SSH port $FORWARD"
1603 kill_port_forward onos-ssh
1604 port_forward "$INFRA_NS" onos-ssh "$ONOS_SSH_PORT:8101"
1605 espin - "$VERIFIED"
1606 _ONOS_API_EP="127.0.0.1:$ONOS_API_PORT"
1607 else
1608 _ONOS_API_EP="$(get_service_ep "$INFRA_NS" onos-ui)"
1609 fi
1610 elif is_in "$WITH_ONOS" "yes,classic"; then
1611 bspin "Verify ONOS CLASSIC installed $BIRD"
1612 if [ "$HELM_USE_UPGRADE" == "yes" ] || [ "$(helm list --deployed --short --namespace "$INFRA_NS" "^onos\$" | wc -l)" -ne 1 ]; then
1613 espin "$NOT_VERIFIED"
1614 # ONOS CLASSIC identifies its image repo/tag differently, so yq is used to grab the values from the
1615 # values value
David Bainbridgefad50732020-05-01 17:00:12 -07001616 YAML_VALUES=$(INTERNAL_EXTRA_HELM_INSTALL_ARGS="--set replicas=$NUM_OF_ONOS --set atomix.replicas=$NUM_OF_ATOMIX" \
1617 helm_values "$INFRA_NS" onos "$ONOS_CLASSIC_CHART" "$ONOS_CLASSIC_CHART_VERSION")
1618 _ONOS_REPO="$(echo "$YAML_VALUES" | yq read - images.onos.repository)"
1619 _ONOS_TAG="$(echo "$YAML_VALUES" | yq read - images.onos.tag)"
1620 _TAG_DEFAULT="$(echo "$YAML_VALUES" | yq read - defaults.image_tag)"
David Bainbridge60ffc0f2020-04-27 22:13:22 -07001621 if [ -z "$_ONOS_TAG" ]; then
1622 _ONOS_TAG="$_TAG_DEFAULT"
1623 fi
David Bainbridgefad50732020-05-01 17:00:12 -07001624
David Bainbridge60ffc0f2020-04-27 22:13:22 -07001625 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" \
1626 helm_install - "$INFRA_NS" onos "$ONOS_CLASSIC_CHART" "$ONOS_CLASSIC_CHART_VERSION" "$_HELM_DESC ONOS CLASSIC"
1627 INTERNAL_EXTRA_HELM_INSTALL_ARGS=
1628 else
1629 espin "$VERIFIED"
1630 fi
1631 wait_for_pods - "$INFRA_NS" $((NUM_OF_ONOS + NUM_OF_ATOMIX)) "includes" "Waiting for ONOS CLASSIC to start" "$NO_LABEL" "onos-.*"
1632 if [ "$WITH_PORT_FORWARDS" == "yes" ]; then
1633 bspin - "Forward ONOS API port $FORWARD"
1634 kill_port_forward onos-onos-classic-hs
1635 port_forward "$INFRA_NS" onos-onos-classic-hs "$ONOS_API_PORT:8181" "$ONOS_SSH_PORT:8101"
1636 espin - "$VERIFIED"
1637 _ONOS_API_EP="127.0.0.1:$ONOS_API_PORT"
1638 else
1639 _ONOS_API_EP="$(get_service_ep "$INFRA_NS" onos-onos-classic-hs)"
1640 fi
1641 elif [ "$WITH_ONOS" == "micro" ]; then
1642 bspin "Verify micro-ONOS installed $BIRD"
1643 # We should never get here
1644 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} Micro ONOS not currently supported${NORMAL}"
1645 exit 1
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -08001646 fi
David Bainbridged31d6122019-08-13 19:37:59 +00001647 bspin - "Verify or download ONOS configuration support files $DOWNLOAD"
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001648 ONOS_FILES="olt-onos-enableExtraneousRules.json onos-aaa.json \
David Bainbridge696bc632020-04-05 21:49:37 -07001649 onos-dhcpl2relay.json onos-sadis-sample.json"
David Bainbridged18f4942020-04-14 16:46:13 -07001650 (set -x; mkdir -p ./onos-files >>"$LOG" 2>&1) >>"$LOG" 2>&1
1651 ERR_OUT="$(mktemp)"
David Bainbridge2b19e832019-08-16 02:40:53 +00001652 for i in $ONOS_FILES; do
David Bainbridged18f4942020-04-14 16:46:13 -07001653 if [ ! -r "./onos-files/$i" ]; then
serkant.uluderya4d315132020-04-15 16:25:54 -07001654 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 -07001655 espin - "$THEX"
1656 echo -e "${RED}${BOLD}${ERROR}ERROR: $i${NORMAL}${RED} - $(cat "$ERR_OUT")${NORMAL}"
1657 echo "ERROR: $(cat "$ERR_OUT")" >>"$LOG"
1658 rm -rf "$ERR_OUT" "./onos-files/$i"
David K. Bainbridgea00736b2020-01-08 14:33:17 -08001659 exit 1
1660 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001661 rm -rf "$ERR_OUT"
David Bainbridged31d6122019-08-13 19:37:59 +00001662 fi
1663 done
David Bainbridged18f4942020-04-14 16:46:13 -07001664 rm -rf "$ERR_OUT"
1665 espin - "$VERIFIED"
David Bainbridge27790d62019-08-13 22:43:19 +00001666
David Bainbridged18f4942020-04-14 16:46:13 -07001667 if [ "$INSTALL_ONOS_APPS" == "yes" ]; then
David Bainbridge27790d62019-08-13 22:43:19 +00001668 bspin - "Installing custom ONOS applications"
David Bainbridged18f4942020-04-14 16:46:13 -07001669 if [ -x onos-files/onos-apps ] && [ "$(find onos-files/onos-apps -name "*.oar" 2>/dev/null | wc -l)" -gt 0 ]; then
1670 for OAR in onos-files/onos-apps/*.oar; do
David Bainbridge27790d62019-08-13 22:43:19 +00001671 sspin - "Installing custom ONOS applications - $OAR$CEOL"
David Bainbridged18f4942020-04-14 16:46:13 -07001672 override_onos_app "$OAR"
David Bainbridge27790d62019-08-13 22:43:19 +00001673 done
1674 espin - "$VERIFIED Installing custom ONOS applications$CEOL"
1675 else
1676 espin - "$NOT_VERIFIED Installing custom ONOS applications - None Found"
1677 fi
1678 fi
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001679
David Bainbridged18f4942020-04-14 16:46:13 -07001680 if [ "$WITH_KAFKA" != "no" ]; then
David Bainbridge837e8bd2020-04-06 13:17:14 -07001681 check_onos_app_active org.opencord.kafka
David Bainbridge76afd812020-04-06 09:53:52 -07001682 _HOST=voltha-kafka.$INFRA_NS.svc.cluster.local
David Bainbridge837e8bd2020-04-06 13:17:14 -07001683 _PORT=9092
David Bainbridged18f4942020-04-14 16:46:13 -07001684 if [ "$WITH_KAFKA" == "yes" ]; then
David Bainbridge76afd812020-04-06 09:53:52 -07001685 _HOST=voltha-kafka.$VOLTHA_NS.svc.cluster.local
1686 _PORT=9092
David Bainbridged18f4942020-04-14 16:46:13 -07001687 elif [ "$WITH_KAFKA" == "external" ]; then
David Bainbridge76afd812020-04-06 09:53:52 -07001688 _HOST=kafka.$INFRA_NS.svc.cluster.local
1689 _PORT=9092
1690 else
David Bainbridged18f4942020-04-14 16:46:13 -07001691 _HOST="$(echo "$WITH_KAFKA" | cut -d: -f1)"
1692 _PORT="$(echo "$WITH_KAFKA" | cut -s -d: -f2)"
David Bainbridge837e8bd2020-04-06 13:17:14 -07001693 _PORT=${_PORT:-9092}
1694 fi
1695 push_onos_config "json" "Push ONOS Kafka Configuration" "network/configuration/apps/org.opencord.kafka" \
David Bainbridged18f4942020-04-14 16:46:13 -07001696 "$(cat <<EOJ | tr -d '[:space:]'
David Bainbridge696bc632020-04-05 21:49:37 -07001697{
1698 "kafka": {
1699 "bootstrapServers": "$_HOST:$_PORT"
1700 }
1701}
1702EOJ
David Bainbridged18f4942020-04-14 16:46:13 -07001703)"
David Bainbridge837e8bd2020-04-06 13:17:14 -07001704 fi
Matteo Scandolo9a77a732020-01-09 14:24:12 -08001705 check_onos_app_active org.opencord.dhcpl2relay
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001706 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 -08001707 check_onos_app_active org.opencord.olt
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001708 # FIXME use WITH_DHCP and WITH_EAPOL flags to configre OLT App
Hardik Windlassa7501fb2020-02-17 14:28:20 +00001709 # Default value for "enableEapol" is true in OLT App
David Bainbridged18f4942020-04-14 16:46:13 -07001710 if [ "$WITH_EAPOL" == "yes" ]; then
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001711 push_onos_config "json" "Enable VOLTHA ONOS EAPOL provisioning" "configuration/org.opencord.olt.impl.OltFlowService" '{"enableEapol":true}'
David Bainbridged18f4942020-04-14 16:46:13 -07001712 elif [ "$WITH_EAPOL" == "no" ]; then
Hardik Windlassa7501fb2020-02-17 14:28:20 +00001713 push_onos_config "json" "Disable VOLTHA ONOS EAPOL provisioning" "configuration/org.opencord.olt.impl.OltFlowService" '{"enableEapol":false}'
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001714 fi
Hardik Windlassa7501fb2020-02-17 14:28:20 +00001715 # Default value for "enableDhcpOnProvisioning" is false and for "enableDhcpV4" is true in OLT App
David Bainbridged18f4942020-04-14 16:46:13 -07001716 if [ "$WITH_DHCP" == "yes" ]; then
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001717 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 -07001718 elif [ "$WITH_DHCP" == "no" ]; then
Hardik Windlassa7501fb2020-02-17 14:28:20 +00001719 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 -08001720 fi
Hardik Windlassa7501fb2020-02-17 14:28:20 +00001721 # Default value for "enableIgmpOnProvisioning" is false in OLT App
David Bainbridged18f4942020-04-14 16:46:13 -07001722 if [ "$WITH_IGMP" == "yes" ]; then
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001723 push_onos_config "json" "Enable VOLTHA ONOS IGMP provisioning" "configuration/org.opencord.olt.impl.OltFlowService" '{"enableIgmpOnProvisioning":true}'
David Bainbridged18f4942020-04-14 16:46:13 -07001724 elif [ "$WITH_IGMP" == "no" ]; then
Hardik Windlassa7501fb2020-02-17 14:28:20 +00001725 push_onos_config "json" "Disable VOLTHA ONOS IGMP provisioning" "configuration/org.opencord.olt.impl.OltFlowService" '{"enableIgmpOnProvisioning":false}'
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001726 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001727 if [ "$ENABLE_ONOS_EXTRANEOUS_RULES" == "yes" ]; then
David K. Bainbridge484d80c2020-03-05 21:44:34 -08001728 push_onos_config "file" "Enabling extraneous rules for ONOS" "configuration/org.onosproject.net.flow.impl.FlowRuleManager" "onos-files/olt-onos-enableExtraneousRules.json"
1729 fi
David Bainbridge60ffc0f2020-04-27 22:13:22 -07001730 if is_in "$CONFIG_SADIS" "yes,file"; then
Matteo Scandolo9a77a732020-01-09 14:24:12 -08001731 check_onos_app_active org.opencord.sadis
Hardik Windlassb3147602020-03-09 16:59:15 +05301732 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 -07001733 elif [ "$CONFIG_SADIS" == "bbsim" ]; then
1734 push_onos_config "json" \
1735 "[optional] Push ONOS configuration for BBSIM SADIS servers" \
1736 "network/configuration/apps/org.opencord.sadis" \
David Bainbridged18f4942020-04-14 16:46:13 -07001737 "$(cat <<EOJ | tr -d '[:space:]'
David K. Bainbridgeb859e912020-03-13 14:07:52 -07001738{
1739 "sadis": {
1740 "integration": {
David Bainbridge76afd812020-04-06 09:53:52 -07001741 "url": "http://bbsim.$BBSIM_NS.svc.cluster.local:50074/v2/subscribers/%s",
David K. Bainbridgeb859e912020-03-13 14:07:52 -07001742 "cache": {
1743 "enabled": true,
1744 "maxsize": 50,
1745 "ttl": "PT1m"
1746 }
1747 }
1748 },
1749 "bandwidthprofile": {
1750 "integration": {
David Bainbridge76afd812020-04-06 09:53:52 -07001751 "url": "http://bbsim.$BBSIM_NS.svc.cluster.local:50074/v2/bandwidthprofiles/%s",
David K. Bainbridgeb859e912020-03-13 14:07:52 -07001752 "cache": {
1753 "enabled": true,
1754 "maxsize": 50,
1755 "ttl": "PT1m"
1756 }
1757 }
1758 }
1759}
1760EOJ
David Bainbridged18f4942020-04-14 16:46:13 -07001761)"
David Bainbridge309099c2020-05-05 08:47:29 -07001762 elif [ "$CONFIG_SADIS" == "external" ]; then
1763 push_onos_config "json" \
1764 "[optional] Push ONOS configuration for custom SADIS and Bandwidth Profile servers" \
1765 "network/configuration/apps/org.opencord.sadis" \
1766 "$(cat <<EOJ | tr -d '[:space:]'
1767{
1768 "sadis": {
1769 "integration": {
1770 "url": "http://bbsim-sadis-server.$BBSIM_NS.svc:58080/subscribers/%s",
1771 "cache": {
1772 "enabled": true,
1773 "maxsize": 50,
1774 "ttl": "PT1m"
1775 }
1776 }
1777 },
1778 "bandwidthprofile": {
1779 "integration": {
1780 "url": "http://bbsim-sadis-server.$BBSIM_NS.svc:58080/profiles/%s",
1781 "cache": {
1782 "enabled": true,
1783 "maxsize": 50,
1784 "ttl": "PT1m"
1785 }
1786 }
1787 }
1788}
1789EOJ
1790)"
David K. Bainbridgeb859e912020-03-13 14:07:52 -07001791 elif [ "$CONFIG_SADIS" == "url" ]; then
1792 push_onos_config "json" \
1793 "[optional] Push ONOS configuration for custom SADIS and Bandwidth Profile servers" \
1794 "network/configuration/apps/org.opencord.sadis" \
David Bainbridged18f4942020-04-14 16:46:13 -07001795 "$(cat <<EOJ | tr -d '[:space:]'
David K. Bainbridgeb859e912020-03-13 14:07:52 -07001796{
1797 "sadis": {
1798 "integration": {
1799 "url": "$SADIS_SUBSCRIBERS",
1800 "cache": {
1801 "enabled": true,
1802 "maxsize": 50,
1803 "ttl": "PT1m"
1804 }
1805 }
1806 },
1807 "bandwidthprofile": {
1808 "integration": {
1809 "url": "$SADIS_BANDWIDTH_PROFILES",
1810 "cache": {
1811 "enabled": true,
1812 "maxsize": 50,
1813 "ttl": "PT1m"
1814 }
1815 }
1816 }
1817}
1818EOJ
David Bainbridged18f4942020-04-14 16:46:13 -07001819)"
David Bainbridge2b19e832019-08-16 02:40:53 +00001820 fi
Test Userba1e7e72019-07-10 22:27:54 +00001821fi
David Bainbridgee87067b2019-08-12 22:00:12 +00001822if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001823 NOW="$(date +%s)"
1824 printtime $((NOW - STIME))
David Bainbridgee87067b2019-08-12 22:00:12 +00001825fi
Test Userba1e7e72019-07-10 22:27:54 +00001826
David Bainbridged18f4942020-04-14 16:46:13 -07001827if [ "$WITH_ETCD" == "external" ]; then
1828 STIME="$(date +%s)"
David Bainbridge76afd812020-04-06 09:53:52 -07001829 bspin "Verify external ETCD cluster $OLD_KEY"
David Bainbridged18f4942020-04-14 16:46:13 -07001830 EXPECT="$(test "$TYPE" == "minimal" && echo "1" || echo "3")"
1831 if [ "$HELM_USE_UPGRADE" == "yes" ] || [ "$(helm list --deployed --short --namespace "$INFRA_NS" "^etcd-cluster\$" | wc -l)" -ne 1 ]; then
1832 espin "$NOT_VERIFIED"
David Bainbridge76afd812020-04-06 09:53:52 -07001833 INTERNAL_EXTRA_HELM_INSTALL_ARGS+="--set clusterName=etcd-cluster --set autoCompactionRetention=1 --set clusterSize=$EXPECT"
David Bainbridged18f4942020-04-14 16:46:13 -07001834 helm_install - "$INFRA_NS" etcd-cluster onf/voltha-etcd-cluster latest "$_HELM_DESC external ETCD cluster"
David Bainbridge76afd812020-04-06 09:53:52 -07001835 else
David Bainbridged18f4942020-04-14 16:46:13 -07001836 espin "$VERIFIED"
David Bainbridge76afd812020-04-06 09:53:52 -07001837 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001838 wait_for_pods - "$INFRA_NS" "$EXPECT" "includes" "Waiting for ETCD cluster to start" "$NO_LABEL" "etcd-cluster-.*"
David Bainbridge76afd812020-04-06 09:53:52 -07001839 if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001840 NOW="$(date +%s)"
1841 printtime $((NOW - STIME))
David Bainbridge76afd812020-04-06 09:53:52 -07001842 fi
1843fi
1844
David Bainbridged18f4942020-04-14 16:46:13 -07001845if [ "$WITH_KAFKA" == "external" ]; then
1846 _TMP="$(mktemp -u)"
1847 _COUNT="$(test "$TYPE" == "minimal" && echo "1" || echo "3")"
1848 cat << EOC > "$_TMP"
David Bainbridge76afd812020-04-06 09:53:52 -07001849configurationOverrides:
1850 "default.replication.factor": $_COUNT
1851 "offsets.topic.replication.factor": $_COUNT
1852 "log.retention.hours": 4
1853 "log.message.timestamp.type": "LogAppendTime"
1854persistence:
1855 enabled: false
1856zookeeper:
1857 replicaCount: 1
1858 persistence:
1859 enabled: false
1860replicas: $_COUNT
1861EOC
David Bainbridged18f4942020-04-14 16:46:13 -07001862 STIME="$(date +%s)"
David Bainbridge76afd812020-04-06 09:53:52 -07001863 bspin "Verify external Kafka cluster $OLD_KEY"
David Bainbridged18f4942020-04-14 16:46:13 -07001864 EXPECT="$(test "$TYPE" == "minimal" && echo "2" || echo "4")"
1865 if [ "$HELM_USE_UPGRADE" == "yes" ] || [ "$(helm list --deployed --short --namespace "$INFRA_NS" "^kafka\$" | wc -l)" -ne 1 ]; then
1866 espin "$NOT_VERIFIED"
David Bainbridge76afd812020-04-06 09:53:52 -07001867 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" -f $_TMP"
David Bainbridgecf546362020-04-21 23:18:50 -07001868 helm_install - "$INFRA_NS" kafka "$KAFKA_CHART" "$KAFKA_CHART_VERSION" "$_HELM_DESC external Kafka cluster"
David Bainbridge76afd812020-04-06 09:53:52 -07001869 else
David Bainbridged18f4942020-04-14 16:46:13 -07001870 espin "$VERIFIED"
David Bainbridge76afd812020-04-06 09:53:52 -07001871 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001872 wait_for_pods - "$INFRA_NS" "$EXPECT" "includes" "Waiting for Kafka cluster to start" "$NO_LABEL" "kafka-.*"
David Bainbridge76afd812020-04-06 09:53:52 -07001873 if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001874 NOW="$(date +%s)"
1875 printtime $((NOW - STIME))
David Bainbridge76afd812020-04-06 09:53:52 -07001876 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001877 rm -rf "$_TMP"
David Bainbridge76afd812020-04-06 09:53:52 -07001878fi
1879
David Bainbridged18f4942020-04-14 16:46:13 -07001880STIME="$(date +%s)"
David Bainbridge696bc632020-04-05 21:49:37 -07001881EXPECT=1
1882if [ "$ONLY_ONE" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001883 EXPECT="$((EXPECT+1))"
David Bainbridge696bc632020-04-05 21:49:37 -07001884 INTERNAL_EXTRA_HELM_INSTALL_ARGS="--set therecanbeonlyone=true"
1885else
David Bainbridged18f4942020-04-14 16:46:13 -07001886 EXPECT="$((EXPECT+2))"
David Bainbridge696bc632020-04-05 21:49:37 -07001887fi
Matteo Scandolo67335f02020-04-09 11:19:53 -07001888case $WITH_ETCD in
David Bainbridge76afd812020-04-06 09:53:52 -07001889 no)
1890 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set private_etcd_cluster=false"
1891 ;;
1892 yes)
1893 _HOST="voltha-etcd-cluster-client.$VOLTHA_NS.svc.cluster.local"
1894 _PORT=2379
1895 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set services.etcd.service=$_HOST --set services.etcd.port=$_PORT"
David Bainbridged18f4942020-04-14 16:46:13 -07001896 EXPECT="$((EXPECT+$(test "$TYPE" == "minimal" && echo "1" || echo "3")))"
David Bainbridge76afd812020-04-06 09:53:52 -07001897 ;;
1898 external)
1899 _HOST="etcd-cluster-client.$INFRA_NS.svc.cluster.local"
1900 _PORT=2379
1901 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set private_etcd_cluster=false --set services.etcd.service=$_HOST --set services.etcd.port=$_PORT"
1902 ;;
1903 *)
David Bainbridged18f4942020-04-14 16:46:13 -07001904 _HOST="$(echo "$WITH_ETCD" | cut -d: -f1)"
1905 _PORT="$(echo "$WITH_ETCD" | cut -s -d: -f2)"
David Bainbridge696bc632020-04-05 21:49:37 -07001906 _PORT=${_PORT:-2379}
David Bainbridge76afd812020-04-06 09:53:52 -07001907 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set private_etcd_cluster=false --set services.etcd.service=$_HOST --set services.etcd.port=$_PORT"
1908 ;;
1909esac
1910case $WITH_KAFKA in
1911 no)
1912 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set private_kafka_cluster=false"
1913 ;;
1914 yes)
1915 _HOST=voltha-kafka.$VOLTHA_NS.svc.cluster.local
1916 _PORT=9092
1917 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 -07001918 EXPECT="$((EXPECT+$(test "$TYPE" == "minimal" && echo "2" || echo "4")))"
David Bainbridge76afd812020-04-06 09:53:52 -07001919 ;;
1920 external)
1921 _HOST=kafka.$INFRA_NS.svc.cluster.local
1922 _PORT=9092
1923 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"
1924 ;;
1925 *)
David Bainbridged18f4942020-04-14 16:46:13 -07001926 _HOST="$(echo "$WITH_KAFKA" | cut -d: -f1)"
1927 _PORT="$(echo "$WITH_KAFKA" | cut -s -d: -f2)"
David Bainbridge696bc632020-04-05 21:49:37 -07001928 _PORT=${_PORT:-9092}
David Bainbridge76afd812020-04-06 09:53:52 -07001929 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"
1930 ;;
1931esac
1932
David Bainbridge60ffc0f2020-04-27 22:13:22 -07001933if is_in "$WITH_ONOS" "legacy"; then
David Bainbridge76afd812020-04-06 09:53:52 -07001934 _HOST=onos-openflow.$INFRA_NS.svc.cluster.local
1935 _PORT=6653
David Bainbridge60ffc0f2020-04-27 22:13:22 -07001936elif is_in "$WITH_ONOS" "yes,classic"; then
1937 _HOST=onos-onos-classic-hs.$INFRA_NS.svc.cluster.local
1938 _PORT=6653
David Bainbridged18f4942020-04-14 16:46:13 -07001939elif [ "$WITH_ONOS" != "no" ]; then
1940 _HOST="$(echo "$WITH_ONOS" | cut -d: -f1)"
1941 _PORT="$(echo "$WITH_ONOS" | cut -s -d: -f2)"
David Bainbridge76afd812020-04-06 09:53:52 -07001942 _PORT=${_PORT:-6653}
Jonathan Hart6a91e6c2020-04-16 14:28:33 -07001943fi
David Bainbridge60ffc0f2020-04-27 22:13:22 -07001944
David Bainbridgecf546362020-04-21 23:18:50 -07001945compare_versions "$RESOLVED_VOLTHA_CHART_VERSION" 2.4.2
Jonathan Hart6a91e6c2020-04-16 14:28:33 -07001946if [ "$?" == "1" ]; then
1947 # voltha chart > 2.4.2 uses list of controllers
1948 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set services.controller[0].service=$_HOST --set services.controller[0].port=$_PORT"
1949else
1950 # voltha chart <= 2.4.2 uses single controller
David Bainbridge76afd812020-04-06 09:53:52 -07001951 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set services.controller.service=$_HOST --set services.controller.port=$_PORT"
David Bainbridge696bc632020-04-05 21:49:37 -07001952fi
Jonathan Hart6a91e6c2020-04-16 14:28:33 -07001953
Test Userb5712372019-07-03 21:52:17 +00001954bspin "Verify VOLTHA installed $HIGH_VOLTAGE"
David Bainbridged18f4942020-04-14 16:46:13 -07001955if [ "$HELM_USE_UPGRADE" == "yes" ] || [ "$(helm list --deployed --short --namespace "$VOLTHA_NS" "^voltha\$" | wc -l)" -ne 1 ]; then
1956 espin "$NOT_VERIFIED"
1957 helm_install - "$VOLTHA_NS" voltha "$VOLTHA_CHART" "$VOLTHA_CHART_VERSION" "$_HELM_DESC VOLTHA Core"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001958else
David Bainbridged18f4942020-04-14 16:46:13 -07001959 espin "$VERIFIED"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001960fi
David Bainbridge696bc632020-04-05 21:49:37 -07001961INTERNAL_EXTRA_HELM_INSTALL_ARGS=
Test Userba1e7e72019-07-10 22:27:54 +00001962
David Bainbridge90fd8e32019-08-21 23:32:47 +00001963VOLTHA="voltha-ofagent-.* \
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001964 rw-core.* \
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001965 voltha-etcd-cluster-.* \
1966 voltha-kafka-.* \
1967 voltha-zookeeper-.*"
David Bainbridged18f4942020-04-14 16:46:13 -07001968wait_for_pods - "$VOLTHA_NS" "$EXPECT" "includes" "Waiting for VOLTHA Core to start" "$NO_LABEL" "$VOLTHA"
David Bainbridgee87067b2019-08-12 22:00:12 +00001969if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001970 NOW="$(date +%s)"
1971 printtime $((NOW - STIME))
David Bainbridgee87067b2019-08-12 22:00:12 +00001972fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001973
David Bainbridge46505fb2019-10-01 21:13:20 +00001974if [ "$WITH_ADAPTERS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001975 STIME="$(date +%s)"
David Bainbridge46505fb2019-10-01 21:13:20 +00001976 EXPECT=0
David Bainbridged18f4942020-04-14 16:46:13 -07001977 if [ "$WITH_ETCD" == "yes" ]; then
David Bainbridge3517f6c2020-04-08 12:14:08 -07001978 _HOST=voltha-etcd-cluster-client.$VOLTHA_NS.svc.cluster.local
1979 _PORT=2379
1980 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set services.etcd.service=$_HOST --set services.etcd.port=$_PORT"
David Bainbridged18f4942020-04-14 16:46:13 -07001981 elif [ "$WITH_ETCD" == "external" ]; then
David Bainbridge3517f6c2020-04-08 12:14:08 -07001982 _HOST=etcd-cluster-client.$INFRA_NS.svc.cluster.local
1983 _PORT=2379
1984 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set services.etcd.service=$_HOST --set services.etcd.port=$_PORT"
David Bainbridged18f4942020-04-14 16:46:13 -07001985 elif [ "$WITH_ETCD" != "no" ]; then
1986 _HOST="$(echo "$WITH_ETCD" | cut -d: -f1)"
1987 _PORT="$(echo "$WITH_ETCD" | cut -s -d: -f2)"
David Bainbridge3517f6c2020-04-08 12:14:08 -07001988 _PORT=${_PORT:-2379}
1989 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set services.etcd.service=$_HOST --set services.etcd.port=$_PORT"
David Bainbridge696bc632020-04-05 21:49:37 -07001990 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001991 if [ "$WITH_KAFKA" == "yes" ]; then
David Bainbridge3517f6c2020-04-08 12:14:08 -07001992 _HOST=voltha-kafka.$VOLTHA_NS.svc.cluster.local
1993 _PORT=9092
1994 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 -07001995 elif [ "$WITH_KAFKA" == "external" ]; then
David Bainbridge3517f6c2020-04-08 12:14:08 -07001996 _HOST=kafka.$INFRA_NS.svc.cluster.local
1997 _PORT=9092
1998 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 -07001999 elif [ "$WITH_KAFKA" != "no" ]; then
2000 _HOST="$(echo "$WITH_KAFKA" | cut -d: -f1)"
2001 _PORT="$(echo "$WITH_KAFKA" | cut -s -d: -f2)"
David Bainbridge3517f6c2020-04-08 12:14:08 -07002002 _PORT=${_PORT:-9092}
2003 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 -07002004 fi
David Bainbridge46505fb2019-10-01 21:13:20 +00002005 echo -e "Verify Adapters $PLUG"
2006 if [ "$WITH_SIM_ADAPTERS" == "yes" ]; then
2007 bspin - "Verify Simulated Adapters installed"
David Bainbridged18f4942020-04-14 16:46:13 -07002008 if [ "$HELM_USE_UPGRADE" == "yes" ] || [ "$(helm list --deployed --short --namespace "$ADAPTER_NS" "^sim\$" | wc -l)" -ne 1 ]; then
2009 espin - "$NOT_VERIFIED"
2010 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 +00002011 else
David Bainbridged18f4942020-04-14 16:46:13 -07002012 espin - "$VERIFIED"
David Bainbridge46505fb2019-10-01 21:13:20 +00002013 fi
David Bainbridged18f4942020-04-14 16:46:13 -07002014 EXPECT="$((EXPECT + 2))"
David Bainbridge46505fb2019-10-01 21:13:20 +00002015 fi
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07002016
David Bainbridge46505fb2019-10-01 21:13:20 +00002017 if [ "$WITH_OPEN_ADAPTERS" == "yes" ]; then
2018 bspin - "Verify OpenOLT Adapter installed"
David Bainbridged18f4942020-04-14 16:46:13 -07002019 if [ "$HELM_USE_UPGRADE" == "yes" ] || [ "$(helm list --deployed --short --namespace "$ADAPTER_NS" "^open-olt\$" | wc -l)" -ne 1 ]; then
2020 espin - "$NOT_VERIFIED"
2021 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 +00002022 else
David Bainbridged18f4942020-04-14 16:46:13 -07002023 espin - "$VERIFIED"
David Bainbridge46505fb2019-10-01 21:13:20 +00002024 fi
Matteo Scandolo67335f02020-04-09 11:19:53 -07002025 EXPECT="$((EXPECT + 1))"
David Bainbridge46505fb2019-10-01 21:13:20 +00002026 bspin - "Verify OpenONU Adapter installed"
David Bainbridged18f4942020-04-14 16:46:13 -07002027 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 -07002028 _ORIGINAL_EXTRA_HELM_INSTALL_ARGS="$INTERNAL_EXTRA_HELM_INSTALL_ARGS"
2029 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set replicas.adapter_open_onu=$NUM_OF_OPENONU"
David Bainbridged18f4942020-04-14 16:46:13 -07002030 espin - "$NOT_VERIFIED"
Matteo Scandolo67335f02020-04-09 11:19:53 -07002031 helm_install - "$ADAPTER_NS" open-onu "$VOLTHA_ADAPTER_OPEN_ONU_CHART" "$VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION" "$_HELM_DESC OpenONU Adapter"
2032 INTERNAL_EXTRA_HELM_INSTALL_ARGS="$_ORIGINAL_EXTRA_HELM_INSTALL_ARGS"
David Bainbridge46505fb2019-10-01 21:13:20 +00002033 else
David Bainbridged18f4942020-04-14 16:46:13 -07002034 espin - "$VERIFIED"
David Bainbridge46505fb2019-10-01 21:13:20 +00002035 fi
Matteo Scandolo67335f02020-04-09 11:19:53 -07002036 EXPECT=$((EXPECT + NUM_OF_OPENONU))
David Bainbridge46505fb2019-10-01 21:13:20 +00002037 fi
David Bainbridge696bc632020-04-05 21:49:37 -07002038 INTERNAL_EXTRA_HELM_INSTALL_ARGS=
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07002039
David Bainbridge46505fb2019-10-01 21:13:20 +00002040 ADAPTERS="adapter-.*"
David Bainbridged18f4942020-04-14 16:46:13 -07002041 wait_for_pods - "$ADAPTER_NS" "$EXPECT" "includes" "Waiting for adapters to start" "$NO_LABEL" "$ADAPTERS"
David Bainbridge46505fb2019-10-01 21:13:20 +00002042 if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07002043 NOW="$(date +%s)"
2044 printtime $((NOW - STIME))
David Bainbridge46505fb2019-10-01 21:13:20 +00002045 fi
David Bainbridgee87067b2019-08-12 22:00:12 +00002046fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07002047
David Bainbridged18f4942020-04-14 16:46:13 -07002048if [ "$WITH_BBSIM" == "yes" ]; then
2049 STIME="$(date +%s)"
Test User7d866122019-07-09 17:52:35 +00002050 echo -e "Verify BBSIM $PLUG"
David Bainbridge5b7b96b2019-07-25 20:29:13 +00002051 bspin - "Verify BBSIM Installed"
David Bainbridged18f4942020-04-14 16:46:13 -07002052 for instance in $(seq 0 $((NUM_OF_BBSIM-1))); do
Matteo Scandoloc2eb0672020-05-01 14:43:15 -07002053
2054 if [ "$LEGACY_BBSIM_INDEX" == "yes" ]; then
2055 if [ "$instance" -eq 0 ]; then
2056 instance_num=""
2057 else
2058 instance_num=$instance
2059 fi
David K. Bainbridge43422402020-03-06 07:41:22 -08002060 else
2061 instance_num=$instance
2062 fi
Matteo Scandoloc2eb0672020-05-01 14:43:15 -07002063
2064
David Bainbridged18f4942020-04-14 16:46:13 -07002065 if [ "$HELM_USE_UPGRADE" == "yes" ] || [ "$(helm list --deployed --short --namespace "$BBSIM_NS" "^bbsim${instance_num}\$" | wc -l)" -ne 1 ]; then
2066 espin - "$NOT_VERIFIED"
2067 S_TAG="$((900+instance))"
Matteo Scandolo5a149572020-04-01 10:14:57 -07002068 INTERNAL_EXTRA_HELM_INSTALL_ARGS="--set olt_id=$instance,s_tag=$S_TAG"
David Bainbridged9329af2020-05-01 11:58:52 -07002069 if [ "$WITH_EAPOL" == "yes" ]; then
2070 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set auth=true"
2071 else
2072 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set auth=false"
2073 fi
2074 if [ "$WITH_DHCP" == "yes" ]; then
2075 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set dhcp=true"
2076 else
2077 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set dhcp=false"
2078 fi
David Bainbridged18f4942020-04-14 16:46:13 -07002079 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 -07002080 INTERNAL_EXTRA_HELM_INSTALL_ARGS=
David K. Bainbridge43422402020-03-06 07:41:22 -08002081 else
David Bainbridged18f4942020-04-14 16:46:13 -07002082 espin - "$VERIFIED"
David K. Bainbridge43422402020-03-06 07:41:22 -08002083 fi
2084 done
David Bainbridged18f4942020-04-14 16:46:13 -07002085 wait_for_pods - "$BBSIM_NS" "$NUM_OF_BBSIM" "includes" "Waiting for BBSIM to start" "$BBSIM_LABEL" "bbsim*"
David Bainbridgee87067b2019-08-12 22:00:12 +00002086 if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07002087 NOW="$(date +%s)"
2088 printtime $((NOW - STIME))
David Bainbridgee87067b2019-08-12 22:00:12 +00002089 fi
Test User7d866122019-07-09 17:52:35 +00002090fi
2091
David Bainbridge309099c2020-05-05 08:47:29 -07002092if [ "$CONFIG_SADIS" == "external" ]; then
2093 STIME="$(date +%s)"
2094 echo -e "Verify BBSIM SADIS Service $PLUG"
2095 bspin - "Verify required configmap"
2096 (set -x; kubectl -n "$BBSIM_NS" delete --ignore-not-found configmap kube-config >>"$LOG" 2>&1) >>"$LOG" 2>&1
2097 (set -x; kubectl -n "$BBSIM_NS" create configmap kube-config "--from-file=kube_config=$KUBECONFIG" >>"$LOG" 2>&1) >>"$LOG" 2>&1
2098 espin - "$VERIFIED"
2099 bspin - "Verify BBSIM SADIS Service Installed"
2100 if [ "$HELM_USE_UPGRADE" == "yes" ] || [ "$(helm list --deployed --short --namespace "$BBSIM_NS" "^bbsim-sadis-servier\$" | wc -l)" -ne 1 ]; then
2101 espin - "$NOT_VERIFIED"
2102 helm_install - "$BBSIM_NS" bbsim-sadis-server "$BBSIM_SADIS_SERVER_CHART" "$BBSIM_SADIS_SERVER_CHART_VERSION" "$_HELM_DESC BBSIM SADIS Server"
2103 else
2104 espin - "$VERIFIED"
2105 fi
2106 wait_for_pods - "$BBSIM_NS" 1 "includes" "Waiting for BBSIM SADIS Server to start" "$NO_LABEL" "bbsim-sadis-server-.*"
2107 if [ "$WITH_TIMINGS" == "yes" ]; then
2108 NOW="$(date +%s)"
2109 printtime $((NOW - STIME))
2110 fi
2111fi
2112
David Bainbridged18f4942020-04-14 16:46:13 -07002113if [ "$WITH_RADIUS" == "yes" ]; then
2114 STIME="$(date +%s)"
David Bainbridge5b7b96b2019-07-25 20:29:13 +00002115 echo -e "Verify RADIUS $LOCK"
2116 bspin - "Verify RADIUS Installed"
David Bainbridged18f4942020-04-14 16:46:13 -07002117 if [ "$HELM_USE_UPGRADE" == "yes" ] || [ "$(helm list --deployed --short --namespace "$INFRA_NS" "^radius\$" | wc -l)" -ne 1 ]; then
2118 espin - "$NOT_VERIFIED"
2119 helm_install - "$INFRA_NS" radius onf/freeradius latest "$_HELM_DESC RADIUS"
David Bainbridge5b7b96b2019-07-25 20:29:13 +00002120 else
David Bainbridged18f4942020-04-14 16:46:13 -07002121 espin - "$VERIFIED"
David Bainbridge5b7b96b2019-07-25 20:29:13 +00002122 fi
David Bainbridged18f4942020-04-14 16:46:13 -07002123 wait_for_pods - "$INFRA_NS" 1 "includes" "Waiting for RADIUS to start" "$NO_LABEL" "radius-.*"
David Bainbridgee87067b2019-08-12 22:00:12 +00002124 if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07002125 NOW="$(date +%s)"
2126 printtime $((NOW - STIME))
David Bainbridgee87067b2019-08-12 22:00:12 +00002127 fi
David Bainbridge5b7b96b2019-07-25 20:29:13 +00002128fi
2129
David Bainbridged18f4942020-04-14 16:46:13 -07002130if [ "$WITH_PORT_FORWARDS" == "yes" ]; then
2131 STIME="$(date +%s)"
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -08002132 bspin - "Forward VOLTHA API port $FORWARD"
2133 kill_port_forward voltha-api
David Bainbridge60ffc0f2020-04-27 22:13:22 -07002134 port_forward "$VOLTHA_NS" voltha-api "$VOLTHA_API_PORT:55555"
David Bainbridged18f4942020-04-14 16:46:13 -07002135 espin - "$VERIFIED"
2136 if [ "$WITH_ETCD" == "yes" ] || [ "$WITH_ETCD" == "external" ]; then
2137 _NS="$(test "$WITH_ETCD" == "yes" && echo "$VOLTHA_NS" || echo "$INFRA_NS")"
David Bainbridge696bc632020-04-05 21:49:37 -07002138 bspin - "Forward VOLTHA ETCD port $FORWARD"
David Bainbridged18f4942020-04-14 16:46:13 -07002139 kill_port_forward "${ETCD_PREFIX}etcd-cluster-client"
David Bainbridge60ffc0f2020-04-27 22:13:22 -07002140 port_forward "$_NS" "${ETCD_PREFIX}etcd-cluster-client" "$VOLTHA_ETCD_PORT:2379"
David Bainbridged18f4942020-04-14 16:46:13 -07002141 espin - "$VERIFIED"
David Bainbridge696bc632020-04-05 21:49:37 -07002142 fi
David Bainbridged18f4942020-04-14 16:46:13 -07002143 if [ "$WITH_KAFKA" == "yes" ] || [ $WITH_KAFKA == "external" ]; then
2144 _NS="$(test "$WITH_ETCD" == "yes" && echo "$VOLTHA_NS" || echo "$INFRA_NS")"
David Bainbridge696bc632020-04-05 21:49:37 -07002145 bspin - "Forward VOLTHA Kafka port $FORWARD"
David Bainbridged18f4942020-04-14 16:46:13 -07002146 kill_port_forward "${KAFKA_PREFIX}kafka"
David Bainbridge60ffc0f2020-04-27 22:13:22 -07002147 port_forward "$_NS" ${KAFKA_PREFIX}kafka "$VOLTHA_KAFKA_PORT:9092"
David Bainbridged18f4942020-04-14 16:46:13 -07002148 espin - "$VERIFIED"
David Bainbridge696bc632020-04-05 21:49:37 -07002149 fi
Matteo Scandoloefee0432020-05-05 13:56:20 -07002150 if [ "$WITH_PPROF" == "yes" ]; then
2151 bspin - "Forward PProf ports port $FORWARD"
2152 kill_port_forward voltha-rw-core-profiler
2153 kill_port_forward adapter-open-olt-profiler
2154 port_forward "$VOLTHA_NS" voltha-rw-core-profiler "$VOLTHA_PPROF_PORT:6060"
2155 port_forward "$VOLTHA_NS" adapter-open-olt-profiler "$OPENOLT_PPROF_PORT:6060"
2156 espin - "$VERIFIED"
2157 fi
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -08002158 if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07002159 NOW="$(date +%s)"
2160 printtime $((NOW - STIME))
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -08002161 fi
David Bainbridgee87067b2019-08-12 22:00:12 +00002162fi
Test User3d7ad8e2019-07-03 06:15:44 +00002163
David Bainbridge60ffc0f2020-04-27 22:13:22 -07002164if is_in "$WITH_ONOS" "yes,legacy,classic" && [ "$WITH_RADIUS" != "no" ]; then
David Bainbridge76afd812020-04-06 09:53:52 -07002165 _HOST=radius.$INFRA_NS.svc.cluster.local
David Bainbridge696bc632020-04-05 21:49:37 -07002166 _PORT=1812
David Bainbridged18f4942020-04-14 16:46:13 -07002167 if [ "$WITH_RADIUS" != "yes" ]; then
2168 _HOST="$(echo "$WITH_RADIUS" | cut -d: -f1)"
2169 _PORT="$(echo "$WITH_RADIUS" | cut -s -d: -f2)"
David Bainbridge696bc632020-04-05 21:49:37 -07002170 _PORT=${_PORT:-1812}
2171 fi
David Bainbridge5b7b96b2019-07-25 20:29:13 +00002172 bspin "Configure ONOS RADIUS Connection $GEAR"
David Bainbridged18f4942020-04-14 16:46:13 -07002173 (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
2174 espin "$VERIFIED"
David Bainbridge5b7b96b2019-07-25 20:29:13 +00002175fi
2176
David Bainbridge99ac7a22019-08-31 02:26:43 +00002177if [ "$WITH_CHAOS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07002178 STIME="$(date +%s)"
David Bainbridge99ac7a22019-08-31 02:26:43 +00002179 echo -e "Verify kube-monkey $LOCK"
2180 bspin - "Verify kube-monkey Installed"
David Bainbridged18f4942020-04-14 16:46:13 -07002181 if [ "$HELM_USE_UPGRADE" == "yes" ] || [ "$(helm list --deployed --short --namespace kube-monkey "^monkey\$" | wc -l)" -ne 1 ]; then
2182 espin - "$NOT_VERIFIED"
David Bainbridge7f8bf992020-04-08 21:53:22 -07002183 helm_install - kube-monkey monkey ./kube-monkey/helm/kubemonkey latest "$_HELM_DESC Chaos Monkey"
David Bainbridge99ac7a22019-08-31 02:26:43 +00002184 else
David Bainbridged18f4942020-04-14 16:46:13 -07002185 espin - "$VERIFIED"
David Bainbridge99ac7a22019-08-31 02:26:43 +00002186 fi
David Bainbridged18f4942020-04-14 16:46:13 -07002187 wait_for_pods - "kube-monkey" 1 "includes" "Waiting for Chaos to start" "$NO_LABEL" "monkey-.*"
David Bainbridge99ac7a22019-08-31 02:26:43 +00002188 if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07002189 NOW="$(date +%s)"
2190 printtime $((NOW - STIME))
David Bainbridge99ac7a22019-08-31 02:26:43 +00002191 fi
2192fi
2193
David Bainbridge5b7b96b2019-07-25 20:29:13 +00002194bspin "Create voltctl configuration file"
David Bainbridged18f4942020-04-14 16:46:13 -07002195(set -x; mkdir -p "$HOME/.volt" >>"$LOG" 2>&1) >>"$LOG" 2>&1
2196MIN_VC_VERSION="$(echo -e "1.0.15\n$VC_VERSION" | sort -V | head -1)"
2197if [ "$WITH_PORT_FORWARDS" == "yes" ]; then
David K. Bainbridgeb859e912020-03-13 14:07:52 -07002198 KAFKA_FLAG="-k localhost:$VOLTHA_KAFKA_PORT"
2199 SERVER_FLAG="-s localhost:$VOLTHA_API_PORT"
2200 ETCD_FLAG=
2201 if [ "$MIN_VC_VERSION" == "1.0.15" ]; then
2202 ETCD_FLAG="-e localhost:$VOLTHA_ETCD_PORT"
2203 fi
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -08002204else
David Bainbridged18f4942020-04-14 16:46:13 -07002205 KAFKA_FLAG="-k $(get_service_ep "$INFRA_NS" "${KAFKA_PREFIX}kafka")"
2206 SERVER_FLAG="-s $(get_service_ep "$VOLTHA_NS" voltha-api)"
David K. Bainbridgeb859e912020-03-13 14:07:52 -07002207 ETCD_FLAG=
2208 if [ "$MIN_VC_VERSION" == "1.0.15" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07002209 ETCD_FLAG="-e $(get_service_ep "$INFRA_NS" ${ETCD_PREFIX}etcd-client)"
David K. Bainbridgeb859e912020-03-13 14:07:52 -07002210 fi
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -08002211fi
David Bainbridged18f4942020-04-14 16:46:13 -07002212CMD=("voltctl -a v3 $KAFKA_FLAG $SERVER_FLAG $ETCD_FLAG config")
2213(set -x; ${CMD[*]} > "$HOME/.volt/config-$NAME" 2>>"$LOG") >>"$LOG" 2>&1
2214#(set -x; voltctl -a v3 "$KAFKA_FLAG" "$SERVER_FLAG" "$ETCD_FLAG" config > "$HOME/.volt/config-$NAME" 2>>"$LOG") >>"$LOG" 2>&1
2215espin "$VERIFIED"
Test User08ebbd92019-07-03 17:15:39 +00002216
David Bainbridge0774b232019-08-02 06:37:19 +00002217if [ ! -f "$NAME-env.sh" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07002218 touch "$NAME-env.sh"
David Bainbridgeb07fdf72019-07-29 22:51:40 +00002219fi
2220
David Bainbridge596f30d2019-07-30 17:07:59 +00002221for O in $ALL_OPTIONS; do
David Bainbridged18f4942020-04-14 16:46:13 -07002222 VAL="$(eval echo "\$$O")"
2223 if [ -n "$VAL" ] && [ "$(grep -c "^export $O=" "$NAME-env.sh")" -eq 0 ]; then
2224 echo "export $O=\"$(eval echo "\$$O")\"" >> "$NAME-env.sh"
David Bainbridgeb07fdf72019-07-29 22:51:40 +00002225 fi
2226done
2227
David Bainbridged18f4942020-04-14 16:46:13 -07002228if [ "$DEPLOY_K8S" == "yes" ] && [ "$(grep -c "^export KUBECONFIG=" "$NAME-env.sh")" -eq 0 ]; then
2229 echo "export KUBECONFIG=\"$(./bin/kind get kubeconfig-path "--name=voltha-$NAME")\"" >> "$NAME-env.sh"
David Bainbridgeb07fdf72019-07-29 22:51:40 +00002230fi
2231
David Bainbridged18f4942020-04-14 16:46:13 -07002232if [ "$(grep -c "^export VOLTCONFIG=" "$NAME-env.sh")" -eq 0 ]; then
2233 echo "export VOLTCONFIG=\"$HOME/.volt/config-$NAME\"" >> "$NAME-env.sh"
David Bainbridgeb07fdf72019-07-29 22:51:40 +00002234fi
2235
David Bainbridged18f4942020-04-14 16:46:13 -07002236if [ "$(grep -c "^export PATH=" "$NAME-env.sh")" -eq 0 ]; then
2237 echo "export PATH=\"$GOPATH/bin:\$PATH\"" >> "$NAME-env.sh"
David Bainbridgeb07fdf72019-07-29 22:51:40 +00002238fi
2239
Test User7d866122019-07-09 17:52:35 +00002240echo ""
David Bainbridged18f4942020-04-14 16:46:13 -07002241echo "Please issue the following commands in your terminal to ensure that you" | tee -a "$LOG"
2242echo "are accessing the correct Kubernetes/Kind cluster as well as have the " | tee -a "$LOG"
2243echo "tools required by VOLTHA in your command path. " | tee -a "$LOG"
2244echo "" | tee -a "$LOG"
2245echo -en "$BOLD"
2246if [ "$DEPLOY_K8S" == "yes" ]; then
2247 echo "export KUBECONFIG=\"\$(./bin/kind get kubeconfig-path --name=\"voltha-$NAME\")\"" | tee -a "$LOG"
Test Userba1e7e72019-07-10 22:27:54 +00002248fi
David Bainbridged18f4942020-04-14 16:46:13 -07002249echo "export VOLTCONFIG=\"$HOME/.volt/config-$NAME\"" | tee -a "$LOG"
2250echo "export PATH=$GOPATH/bin:\$PATH" | tee -a "$LOG"
2251echo -en "$NORMAL"
2252echo "" | tee -a "$LOG"
2253echo "Thank you for choosing kind-voltha for you quick cluster needs." | tee -a "$LOG"
Test User08ebbd92019-07-03 17:15:39 +00002254
David Bainbridge712afb82019-08-14 19:55:58 +00002255if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07002256 NOW="$(date +%s)"
2257 echo -e "$CLOCK ${BOLD}TOTAL: $(duration $((NOW - TOTAL_START_TIME)))${NORMAL}"
David Bainbridge712afb82019-08-14 19:55:58 +00002258fi