blob: cdc559dd975ee03a2033a8467db7603459d0180b [file] [log] [blame]
Test User01ed0642019-07-03 20:17:06 +00001#!/bin/bash
David K. Bainbridgeb7285432019-07-02 22:05:24 -07002# Copyright 2019 Ciena Corporation
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
David Bainbridged049a612020-03-16 17:22:54 -070015set -f
David Bainbridged18f4942020-04-14 16:46:13 -070016unalias -a
David Bainbridge60ffc0f2020-04-27 22:13:22 -070017shopt -s extglob
David Bainbridged18f4942020-04-14 16:46:13 -070018TOTAL_START_TIME="$(date +%s)"
David K. Bainbridgeb7285432019-07-02 22:05:24 -070019
David Bainbridge38dc1e82019-08-12 15:18:45 +000020FANCY=${FANCY:-1}
21if [ "$TERM X" == " X" ]; then
22 FANCY=0
23fi
24
David K. Bainbridgeb7285432019-07-02 22:05:24 -070025# trap ctrl-c and call ctrl_c()
26trap ctrl_c INT
27
28function ctrl_c() {
David Bainbridged18f4942020-04-14 16:46:13 -070029 echo -en "$CNORM"
David K. Bainbridgeb7285432019-07-02 22:05:24 -070030 echo ""
31 echo "ctrl-c trapped"
David Bainbridgec6a6eb62019-10-18 22:50:07 +000032 echo "Thank you for trying 'voltha up'"
David K. Bainbridgeb7285432019-07-02 22:05:24 -070033 exit
34}
35
David Bainbridgea34993d2020-04-01 09:15:42 -070036HELM_VERSION=${HELM_VERSION:-v2.14.3}
David K. Bainbridgeebf38d92020-02-10 10:46:31 -080037VOLTCTL_VERSION=${VOLTCTL_VERSION:-latest}
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -080038KIND_VERSION=${KIND_VERSION:-v0.5.1}
David K. Bainbridgeb3a99372020-01-08 14:39:06 -080039VK_RELEASE=${VK_RELEASE:-master}
David Bainbridge60ffc0f2020-04-27 22:13:22 -070040EXTRA_TOOLS=
Test User08ebbd92019-07-03 17:15:39 +000041
David Bainbridge38dc1e82019-08-12 15:18:45 +000042RED=
43GREEN=
44YELLOW=
45BLUE=
David Bainbridge38dc1e82019-08-12 15:18:45 +000046BOLD=
47NORMAL=
48ERROR=
49CEOL=
50CNORM=
51CIVIS=
David Bainbridged18f4942020-04-14 16:46:13 -070052if [ "$FANCY" -eq 1 ]; then
53 RED="$(tput setaf 1)"
54 GREEN="$(tput setaf 2)"
55 YELLOW="$(tput setaf 3)"
56 BLUE="$(tput setaf 4)"
57 BOLD="$(tput bold)"
58 NORMAL="$(tput sgr0)"
David Bainbridge38dc1e82019-08-12 15:18:45 +000059 ERROR="\xe2\x9c\x97\x20"
David Bainbridged18f4942020-04-14 16:46:13 -070060 CEOL="$(tput el)"
61 CNORM="$(tput cnorm)"
62 CIVIS="$(tput civis)"
David Bainbridge38dc1e82019-08-12 15:18:45 +000063fi
Test User7d866122019-07-09 17:52:35 +000064
Test User3d7ad8e2019-07-03 06:15:44 +000065TYPE=${TYPE:-minimal}
David Bainbridge0774b232019-08-02 06:37:19 +000066NAME=${NAME:-$TYPE}
David K. Bainbridge484d80c2020-03-05 21:44:34 -080067
68ENABLE_ONOS_EXTRANEOUS_RULES=${ENABLE_ONOS_EXTRANEOUS_RULES:-no}
David Bainbridge76afd812020-04-06 09:53:52 -070069INFRA_NS=${INFRA_NS:-default}
70VOLTHA_NS=${VOLTHA_NS:-voltha}
71BBSIM_NS=${BBSIM_NS:-voltha}
72ADAPTER_NS=${ADAPTER_NS:-voltha}
David Bainbridgee87067b2019-08-12 22:00:12 +000073WITH_TIMINGS=${WITH_TIMINGS:-no}
Test User7d866122019-07-09 17:52:35 +000074WITH_BBSIM=${WITH_BBSIM:-no}
David Bainbridge5b7b96b2019-07-25 20:29:13 +000075WITH_RADIUS=${WITH_RADIUS:-no}
Matteo Scandolo78dfee02020-02-13 16:18:03 -080076WITH_EAPOL=${WITH_EAPOL:-yes}
77WITH_DHCP=${WITH_DHCP:-yes}
78WITH_IGMP=${WITH_IGMP:-no}
David Bainbridgeb270c202019-07-26 01:44:42 +000079WITH_ONOS=${WITH_ONOS:-yes}
David Bainbridge60ffc0f2020-04-27 22:13:22 -070080NUM_OF_ONOS=${NUM_OF_ONOS:-1}
81NUM_OF_ATOMIX=${NUM_OF_ATOMIX:-0}
David Bainbridge99ac7a22019-08-31 02:26:43 +000082WITH_CHAOS=${WITH_CHAOS:-no}
David Bainbridge46505fb2019-10-01 21:13:20 +000083WITH_ADAPTERS=${WITH_ADAPTERS:-yes}
David K. Bainbridgeda33d652020-03-06 10:31:23 -080084WITH_SIM_ADAPTERS=${WITH_SIM_ADAPTERS:-no}
David Bainbridge46505fb2019-10-01 21:13:20 +000085WITH_OPEN_ADAPTERS=${WITH_OPEN_ADAPTERS:-yes}
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -080086WITH_PORT_FORWARDS=${WITH_PORT_FORWARDS:-yes}
David Bainbridge696bc632020-04-05 21:49:37 -070087WITH_KAFKA=${WITH_KAFKA:-yes}
88WITH_ETCD=${WITH_ETCD:-yes}
David Bainbridge05cd8822019-11-19 17:43:53 +000089ONLY_ONE=${ONLY_ONE:-yes}
David Bainbridge309099c2020-05-05 08:47:29 -070090CONFIG_SADIS=${CONFIG_SADIS:-no} # yes | no | file | bbsim | external | URL
David Bainbridge76afd812020-04-06 09:53:52 -070091SADIS_SUBSCRIBERS=${SADIS_SUBSCRIBERS:-http://bbsim.$VOLTHA_NS.svc:50074/v2/subscribers/%s}
92SADIS_BANDWIDTH_PROFILES=${SADIS_BANDWIDTH_PROFILES:-http://bbsim.$VOLTHA_NS.svc:50074/v2/bandwidthprofiles/%s}
Hardik Windlassb3147602020-03-09 16:59:15 +053093SADIS_CFG=${SADIS_CFG:-onos-files/onos-sadis-sample.json}
David Bainbridge27790d62019-08-13 22:43:19 +000094INSTALL_ONOS_APPS=${INSTALL_ONOS_APPS:-no}
Test Userba1e7e72019-07-10 22:27:54 +000095JUST_K8S=${JUST_K8S:-no}
96DEPLOY_K8S=${DEPLOY_K8S:-yes}
David K. Bainbridge0e89cb92019-07-17 11:30:10 -070097INSTALL_KUBECTL=${INSTALL_KUBECTL:-yes}
98INSTALL_HELM=${INSTALL_HELM:-yes}
David Bainbridge7f8bf992020-04-08 21:53:22 -070099HELM_USE_UPGRADE=${HELM_USE_UPGRADE:-no}
David Bainbridge46505fb2019-10-01 21:13:20 +0000100UPDATE_HELM_REPOS=${UPDATE_HELM_REPOS:-yes}
Matteo Scandolofab98622020-01-28 15:17:20 -0800101WAIT_ON_DOWN=${WAIT_ON_DOWN:-yes}
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700102WAIT_TIMEOUT=${WAIT_TIMEOUT:-30m}
103VOLTHA_DOWN_ON_TIMEOUT=${VOLTHA_DOWN_ON_TIMEOUT:-no}
David Bainbridge5b7b96b2019-07-25 20:29:13 +0000104VOLTHA_LOG_LEVEL=${VOLTHA_LOG_LEVEL:-WARN}
David Bainbridge90fd8e32019-08-21 23:32:47 +0000105VOLTHA_CHART=${VOLTHA_CHART:-onf/voltha}
106VOLTHA_CHART_VERSION=${VOLTHA_CHART_VERSION:-latest}
107VOLTHA_BBSIM_CHART=${VOLTHA_BBSIM_CHART:-onf/bbsim}
Matteo Scandolodcd29f52019-10-07 15:42:42 -0700108VOLTHA_BBSIM_CHART_VERSION=${VOLTHA_BBSIM_CHART_VERSION:-latest}
David Bainbridgee10f6d52019-07-25 00:28:13 +0000109VOLTHA_ADAPTER_SIM_CHART=${VOLTHA_ADAPTER_SIM_CHART:-onf/voltha-adapter-simulated}
David Bainbridge90fd8e32019-08-21 23:32:47 +0000110VOLTHA_ADAPTER_SIM_CHART_VERSION=${VOLTHA_ADAPTER_SIM_CHART_VERSION:-latest}
David Bainbridgee10f6d52019-07-25 00:28:13 +0000111VOLTHA_ADAPTER_OPEN_OLT_CHART=${VOLTHA_ADAPTER_OPEN_OLT_CHART:-onf/voltha-adapter-openolt}
David Bainbridge90fd8e32019-08-21 23:32:47 +0000112VOLTHA_ADAPTER_OPEN_OLT_CHART_VERSION=${VOLTHA_ADAPTER_OPEN_OLT_CHART_VERSION:-latest}
David Bainbridgee10f6d52019-07-25 00:28:13 +0000113VOLTHA_ADAPTER_OPEN_ONU_CHART=${VOLTHA_ADAPTER_OPEN_ONU_CHART:-onf/voltha-adapter-openonu}
David Bainbridge90fd8e32019-08-21 23:32:47 +0000114VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION=${VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION:-latest}
David K. Bainbridgeda33d652020-03-06 10:31:23 -0800115ONOS_CHART=${ONOS_CHART:-onf/onos}
Andrea Campanella21323292019-12-18 11:44:19 -0800116ONOS_CHART_VERSION=${ONOS_CHART_VERSION:-latest}
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700117ONOS_CLASSIC_CHART=${ONOS_CLASSIC_CHART:-onos/onos-classic}
118ONOS_CLASSIC_CHART_VERSION=${ONOS_CHART_VERSION:-latest}
David Bainbridgecf546362020-04-21 23:18:50 -0700119KAFKA_CHART=${KAFKA_CHART:-incubator/kafka}
David Bainbridgeb9093522020-04-15 14:32:44 -0700120KAFKA_CHART_VERSION=${KAFKA_CHART_VERSION:=0.15.3}
David Bainbridge309099c2020-05-05 08:47:29 -0700121BBSIM_SADIS_SERVER_CHART=${BBSIM_SADIS_SERVER_CHART:-bbsim-sadis/bbsim-sadis-server}
122BBSIM_SADIS_SERVER_CHART_VERSION=${BBSIM_SADIS_SERVER_CHART_VERSION:-latest}
David Bainbridge2eaf2cf2020-03-18 12:54:08 -0700123EXTRA_HELM_INSTALL_ARGS=${EXTRA_HELM_INSTALL_ARGS:-}
124INTERNAL_EXTRA_HELM_INSTALL_ARGS=
uottrembb16d3982020-02-28 08:34:36 +0100125NUM_OF_BBSIM=${NUM_OF_BBSIM:-1}
Matteo Scandolo67335f02020-04-09 11:19:53 -0700126NUM_OF_OPENONU=${NUM_OF_OPENONU:-1}
uottrembb16d3982020-02-28 08:34:36 +0100127MAX_NUM_OF_BBSIM=10
Matteo Scandolo67335f02020-04-09 11:19:53 -0700128MAX_NUM_OF_OPENONU=10
Matteo Scandoloc2eb0672020-05-01 14:43:15 -0700129LEGACY_BBSIM_INDEX=${LEGACY_BBSIM_INDEX:-no}
Test Userba1e7e72019-07-10 22:27:54 +0000130
David Bainbridged18f4942020-04-14 16:46:13 -0700131HOSTOS="$(uname -s | tr "[:upper:]" "[:lower:"])"
132HOSTARCH="$(uname -m | tr "[:upper:]" "[:lower:"])"
133if [ "$HOSTARCH" == "x86_64" ]; then
Test Userba1e7e72019-07-10 22:27:54 +0000134 HOSTARCH="amd64"
135fi
David Bainbridge7db44002020-04-09 12:54:29 -0700136BBSIM_LABEL="-l app=bbsim"
David Bainbridged18f4942020-04-14 16:46:13 -0700137NO_LABEL=
Test User7d866122019-07-09 17:52:35 +0000138
uottrembb16d3982020-02-28 08:34:36 +0100139# check number (range) of bbsim, max bbsim must not exceed 10 instances!
140# note: instances will be numbered from 0 to 9
141if [ "$1" == "up" ]; then
David K. Bainbridge43422402020-03-06 07:41:22 -0800142 if [ "$NUM_OF_BBSIM" -lt 1 ]; then
Matteo Scandolo67335f02020-04-09 11:19:53 -0700143 >&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 -0800144 exit 1
145 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700146 if [ "$NUM_OF_BBSIM" -gt "$MAX_NUM_OF_BBSIM" ]; then
Matteo Scandolo67335f02020-04-09 11:19:53 -0700147 >&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}"
148 exit 1
149 fi
150
151 if [ "$NUM_OF_OPENONU" -lt 1 ]; then
152 >&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}"
153 exit 1
154 fi
155 if [ "$NUM_OF_OPENONU" -gt "$MAX_NUM_OF_OPENONU" ]; then
156 >&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 -0800157 exit 1
158 fi
uottrembb16d3982020-02-28 08:34:36 +0100159fi
Test User7d866122019-07-09 17:52:35 +0000160# Verify TYPE setting
David Bainbridged18f4942020-04-14 16:46:13 -0700161if [ "$(echo ":minimal:full:" | grep -ic ":$TYPE:")" -eq 0 ]; then
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700162 >&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 +0000163 exit 1
164fi
165
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700166# checks to see if a given WORD is in the given LIST of words
167function is_in() {
168 local WORD LIST
169 WORD="$1"; shift
170 LIST="$*"
171 LIST=${LIST//+([[:space:],|])/:}
172
173 [ "$(echo ":$LIST:" | grep -ic ":$WORD:")" -ne 0 ]
174}
175
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700176function parseDuration() {
David Bainbridged18f4942020-04-14 16:46:13 -0700177 local DUR RESULT TERM TERMS VALUE UNIT
178 DUR=$1
179 RESULT=0
180 TERMS="$(echo "$DUR" | sed -Ee 's/([sSmMhHdD])/\1 /g' -e 's/,$//g')"
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700181 for TERM in $TERMS; do
David Bainbridged18f4942020-04-14 16:46:13 -0700182 VALUE="$(echo "$TERM" | sed -Ee 's/([0-9]+)[sSmMhHdD]/\1/')"
183 UNIT="$(echo "$TERM" | sed -Ee 's/[0-9]+([sSmMhHdD])/\1/')"
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700184 case $UNIT in
185 s|S)
David Bainbridged18f4942020-04-14 16:46:13 -0700186 RESULT=$((RESULT + VALUE)) ;;
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700187 m|M)
David Bainbridged18f4942020-04-14 16:46:13 -0700188 RESULT=$((RESULT + (VALUE * 60))) ;;
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700189 h|H)
David Bainbridged18f4942020-04-14 16:46:13 -0700190 RESULT=$((RESULT + (VALUE * 3600))) ;;
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700191 d|D)
David Bainbridged18f4942020-04-14 16:46:13 -0700192 RESULT=$((RESULT + (VALUE * 86400))) ;;
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700193 *) ;;
194 esac
195 done
196 echo $RESULT
197}
198
199function doTimeout() {
200 local MSG=$1
201 2>&1 echo -e "\n${RED}${BOLD}${ERROR}TIMEOUT:${NORMAL}${RED} Operation timed out after '$WAIT_TIMEOUT': $MSG"
202 exit 125
203}
204
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -0800205function get_service_ep() {
206 local NS=$1
207 local NAME=$2
David Bainbridged18f4942020-04-14 16:46:13 -0700208 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 -0800209}
210
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000211# Used to verify configuration values are set to "yes" or "no" value or convert
212# equivalents to "yes" or "no"
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700213YES="y,yes,t,true,1"
214NO="n,no,f,false,0"
215YES_OR_NO="$YES,$NO"
216
217# If the given VAR matches a truth value then normalize that
218# value, else return original value
219function normalize_yes_no() {
220 local VAR VAL
221 VAR=$1
222 VAL="$(eval echo "\$$VAR")"
223 if ! is_in "$VAL" "$YES_OR_NO"; then
224 echo "$VAL"
225 return 1
226 fi
227 if is_in "$VAL" "$YES"; then
228 echo "yes"
229 else
230 echo "no"
231 fi
232 return 0
233}
234
235# If the given VAR matches a truth value then normalize that
236# value, else display an error
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000237function verify_yes_no() {
David Bainbridged18f4942020-04-14 16:46:13 -0700238 local VAR VAL
239 VAR=$1
240 VAL="$(eval echo "\$$VAR")"
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700241 if ! is_in "$VAL" "$YES_OR_NO"; then
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000242 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} Invalid '$VAR' value of '$VAL'. Should be 'yes' or 'no'${NORMAL}"
243 echo "INVALID"
244 return 1
245 fi
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700246 if is_in "$VAL" "$YES"; then
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000247 echo "yes"
248 else
249 echo "no"
250 fi
251 return 0
252}
Test User7d866122019-07-09 17:52:35 +0000253
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000254ALL_YES_NO="\
David K. Bainbridge484d80c2020-03-05 21:44:34 -0800255 ENABLE_ONOS_EXTRANEOUS_RULES \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000256 WITH_TIMINGS \
257 WITH_BBSIM \
Matteo Scandolo78dfee02020-02-13 16:18:03 -0800258 WITH_EAPOL \
259 WITH_DHCP \
260 WITH_IGMP \
David Bainbridge99ac7a22019-08-31 02:26:43 +0000261 WITH_CHAOS \
David Bainbridge46505fb2019-10-01 21:13:20 +0000262 WITH_ADAPTERS \
263 WITH_SIM_ADAPTERS \
264 WITH_OPEN_ADAPTERS \
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -0800265 WITH_PORT_FORWARDS \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000266 JUST_K8S \
267 DEPLOY_K8S \
268 INSTALL_ONOS_APPS \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000269 INSTALL_KUBECTL \
270 INSTALL_HELM \
David Bainbridge7f8bf992020-04-08 21:53:22 -0700271 HELM_USE_UPGRADE \
David Bainbridge46505fb2019-10-01 21:13:20 +0000272 UPDATE_HELM_REPOS \
David Bainbridge4f1b5562019-08-19 04:46:52 +0000273 WAIT_ON_DOWN \
David Bainbridge70c0ea82019-11-14 23:25:26 +0000274 ONLY_ONE \
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700275 VOLTHA_DOWN_ON_TIMEOUT \
Matteo Scandoloc2eb0672020-05-01 14:43:15 -0700276 LEGACY_BBSIM_INDEX \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000277 "
David Bainbridge5b7b96b2019-07-25 20:29:13 +0000278
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700279OPT_YES_NO="\
280 CONFIG_SADIS \
281 WITH_KAFKA \
282 WITH_RADIUS \
283 WITH_ETCD \
284 WITH_ONOS \
285 "
286
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000287ALL_OPTIONS="\
288 NAME \
289 TYPE \
290 $ALL_YES_NO \
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700291 $OPT_YES_NO \
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700292 WAIT_TIMEOUT \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000293 VOLTHA_LOG_LEVEL \
294 VOLTHA_CHART \
David Bainbridge90fd8e32019-08-21 23:32:47 +0000295 VOLTHA_CHART_VERSION \
296 VOLTHA_BBSIM_CHART \
297 VOLTHA_BBSIM_CHART_VERSION \
uottrembd5a20572020-03-06 09:15:01 +0100298 NUM_OF_BBSIM \
Matteo Scandolo67335f02020-04-09 11:19:53 -0700299 NUM_OF_OPENONU \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000300 VOLTHA_ADAPTER_SIM_CHART \
David Bainbridge90fd8e32019-08-21 23:32:47 +0000301 VOLTHA_ADAPTER_SIM_CHART_VERSION \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000302 VOLTHA_ADAPTER_OPEN_OLT_CHART \
David Bainbridge90fd8e32019-08-21 23:32:47 +0000303 VOLTHA_ADAPTER_OPEN_OLT_CHART_VERSION \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000304 VOLTHA_ADAPTER_OPEN_ONU_CHART \
David Bainbridge90fd8e32019-08-21 23:32:47 +0000305 VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION \
David K. Bainbridgeda33d652020-03-06 10:31:23 -0800306 ONOS_CHART \
Andrea Campanella21323292019-12-18 11:44:19 -0800307 ONOS_CHART_VERSION \
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700308 ONOS_CLASSIC_CHART \
309 ONOS_CLASSIC_CHART_VERSION \
David Bainbridgecf546362020-04-21 23:18:50 -0700310 KAFKA_CHART \
David Bainbridgeb9093522020-04-15 14:32:44 -0700311 KAFKA_CHART_VERSION \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000312 ONOS_API_PORT \
313 ONOS_SSH_PORT \
Hardik Windlassb3147602020-03-09 16:59:15 +0530314 SADIS_CFG \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000315 VOLTHA_API_PORT \
316 VOLTHA_SSH_PORT \
317 VOLTHA_ETCD_PORT \
David K. Bainbridge00ecd382020-02-28 12:31:58 -0800318 VOLTHA_KAFKA_PORT \
David K. Bainbridge8f7f30b2020-01-08 13:06:16 -0800319 VK_RELEASE \
320 KIND_VERSION \
321 VOLTCTL_VERSION \
David Bainbridgea34993d2020-04-01 09:15:42 -0700322 HELM_VERSION \
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700323 NUM_OF_ONOS \
324 NUM_OF_ATOMIX \
David Bainbridge6ca40102020-04-08 11:30:40 -0700325 VOLTHA_NS \
326 ADAPTER_NS \
327 INFRA_NS \
328 BBSIM_NS \
David Bainbridge7db44002020-04-09 12:54:29 -0700329 SADIS_BANDWIDTH_PROFILES \
330 SADIS_SUBSCRIBERS \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000331 "
David Bainbridge01294952019-07-30 19:33:45 +0000332
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000333# Iterate over yes/no configuration options and validate
334for VAR in $ALL_YES_NO; do
David Bainbridged18f4942020-04-14 16:46:13 -0700335 eval "$VAR"="$(verify_yes_no "$VAR")"
336 if [ "$(eval echo "\$$VAR")" == "INVALID" ]; then
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000337 exit 1;
338 fi
339done
David Bainbridgeb270c202019-07-26 01:44:42 +0000340
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700341# Iterate over optional yes/no configuration options and
342# normalize values if they are truth values
343for VAR in $OPT_YES_NO; do
344 eval "$VAR"="$(normalize_yes_no "$VAR")"
345done
David Bainbridge15f6f232020-03-30 09:15:43 -0700346
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700347# normalize non-truth value options
348if is_in "$WITH_KAFKA" "e,external"; then
David Bainbridge76afd812020-04-06 09:53:52 -0700349 WITH_KAFKA="external"
350fi
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700351if is_in "$WITH_ETCD" "e,external"; then
David Bainbridge76afd812020-04-06 09:53:52 -0700352 WITH_ETCD="external"
353fi
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700354if is_in "$WITH_ONOS" "l,legacy"; then
355 WITH_ONOS="legacy"
356elif is_in "$WITH_ONOS" "c,classic"; then
357 WITH_ONOS="classic"
358elif is_in "$WITH_ONOS" "u,m,micro"; then
359 WITH_ONOS="micro"
David Bainbridge29c31cb2020-04-06 09:45:50 -0700360fi
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700361
362if [ "$WITH_ONOS" == "micro" ]; then
363 >&2 echo -e "${YELLOW}${BOLD}${ERROR}WARNING:${NORMAL}${YELLOW} The value specified as WITH_ONOS, '$WITH_ONOS', is not valid.${NORMAL}"
364 exit 1
David Bainbridge29c31cb2020-04-06 09:45:50 -0700365fi
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700366
367if is_in "$WITH_ONOS" "yes,classic"; then
368 # there is an extra utility required if we are using ONOS CLASSIC as
369 # the chart for classic specifies images differently
370 EXTRA_TOOLS+=" yq"
David Bainbridge76afd812020-04-06 09:53:52 -0700371fi
David Bainbridge696bc632020-04-05 21:49:37 -0700372
David Bainbridged18f4942020-04-14 16:46:13 -0700373if [ "$HELM_USE_UPGRADE" == "yes" ]; then
David Bainbridge7f8bf992020-04-08 21:53:22 -0700374 _HELM_DESC="Upgrade/Install"
375else
376 _HELM_DESC="Install"
377fi
378
David Bainbridged18f4942020-04-14 16:46:13 -0700379ETCD_PREFIX=
380KAFKA_PREFIX=
381if [ "$WITH_ETCD" == "yes" ]; then
382 ETCD_PREFIX="voltha-"
383fi
384if [ "$WITH_KAFKA" == "yes" ]; then
385 KAFKA_PREFIX="voltha-"
386fi
387
David K. Bainbridgeda33d652020-03-06 10:31:23 -0800388# Check for prerequiste tools
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700389TOOLS="curl sed jq $EXTRA_TOOLS"
David Bainbridged18f4942020-04-14 16:46:13 -0700390if [ "$DEPLOY_K8S" == "yes" ]; then
David K. Bainbridgeda33d652020-03-06 10:31:23 -0800391 TOOLS+=" docker"
392fi
393NOT_FOUND=""
394for T in $TOOLS; do
David Bainbridged18f4942020-04-14 16:46:13 -0700395 if [ -z "$(command -v "$T")" ]; then
David K. Bainbridgeda33d652020-03-06 10:31:23 -0800396 NOT_FOUND+=" $T"
397 fi
398done
399
David Bainbridged18f4942020-04-14 16:46:13 -0700400if [ -n "$NOT_FOUND" ]; then
David K. Bainbridgeda33d652020-03-06 10:31:23 -0800401 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} The following required tools where not found, please install them:$NOT_FOUND"
402 exit 1
403fi
404
David Bainbridged18f4942020-04-14 16:46:13 -0700405TIMEOUT_SECONDS="$(parseDuration "$WAIT_TIMEOUT")"
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700406
David Bainbridge0774b232019-08-02 06:37:19 +0000407mkdir -p .voltha
408touch .voltha/ports
David Bainbridged18f4942020-04-14 16:46:13 -0700409HAVE="$(grep "$NAME" .voltha/ports)"
David Bainbridge0774b232019-08-02 06:37:19 +0000410if [ "$HAVE X" == " X" ]; then
411 # Find free port prefix
412 START=81
413 while true; do
David Bainbridged18f4942020-04-14 16:46:13 -0700414 if [ "$(grep -c $START .voltha/ports)" -eq 0 ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000415 break
416 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700417 START="$((START + 1))"
David Bainbridge0774b232019-08-02 06:37:19 +0000418 done
David Bainbridged18f4942020-04-14 16:46:13 -0700419 DELTA="$((START - 81))"
David Bainbridgea2595422019-10-22 03:54:28 +0000420 ONOS_API_PORT=${ONOS_API_PORT:-${START}81}
421 ONOS_SSH_PORT=${ONOS_SSH_PORT:-${START}01}
David Bainbridged18f4942020-04-14 16:46:13 -0700422 VOLTHA_API_PORT=${VOLTHA_API_PORT:-5$((55 + DELTA))55}
423 VOLTHA_SSH_PORT=${VOLTHA_SSH_PORT:-$((50 + DELTA))22}
424 VOLTHA_ETCD_PORT=${VOLTHA_ETCD_PORT:-$((23 + DELTA))79}
425 VOLTHA_KAFKA_PORT=${VOLTHA_KAFKA_PORT:-$((90 + DELTA))92}
Test User01ed0642019-07-03 20:17:06 +0000426else
David Bainbridged18f4942020-04-14 16:46:13 -0700427 VALUES="$(echo "$HAVE" | sed -e 's/\s//g' | cut -d= -f2)"
428 ONOS_API_PORT=${ONOS_API_PORT:-$(echo "$VALUES" | cut -d, -f1)}
429 ONOS_SSH_PORT=${ONOS_SSH_PORT:-$(echo "$VALUES" | cut -d, -f2)}
430 VOLTHA_API_PORT=${VOLTHA_API_PORT:-$(echo "$VALUES" | cut -d, -f3)}
431 VOLTHA_SSH_PORT=${VOLTHA_SSH_PORT:-$(echo "$VALUES" | cut -d, -f4)}
432 VOLTHA_ETCD_PORT=${VOLTHA_ETCD_PORT:-$(echo "$VALUES" | cut -d, -f5)}
433 VOLTHA_KAFKA_PORT=${VOLTHA_KAFKA_PORT:-$(echo "$VALUES" | cut -d, -f6)}
David K. Bainbridge00ecd382020-02-28 12:31:58 -0800434
David K. Bainbridge00ecd382020-02-28 12:31:58 -0800435 # A bit of a hueristic required here as the KAFKA port forward was
436 # added after the .voltha/ports files was created. Basically, if
437 # the VOLTHA_KAFKA_PORT isn't in the file then calculate the original
438 # DELTA from the VOLTHA_SSH_PORT and apply it to the VOLTHA_KAFKA_PORT
439 if [ -z "$VOLTHA_KAFKA_PORT" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -0700440 DELTA="$((VOLTHA_SSH_PORT/100-50))"
441 VOLTHA_KAFKA_PORT=${VOLTHA_KAFKA_PORT:-$((90 + DELTA))92}
David K. Bainbridge00ecd382020-02-28 12:31:58 -0800442 fi
Test User01ed0642019-07-03 20:17:06 +0000443fi
444
David Bainbridged18f4942020-04-14 16:46:13 -0700445PORTTMP="$(mktemp -u)"
446grep -v "$NAME" .voltha/ports > "$PORTTMP"
447echo "$NAME=$ONOS_API_PORT,$ONOS_SSH_PORT,$VOLTHA_API_PORT,$VOLTHA_SSH_PORT,$VOLTHA_ETCD_PORT,$VOLTHA_KAFKA_PORT" >> "$PORTTMP"
448cp "$PORTTMP" .voltha/ports
449rm -f "$PORTTMP"
David Bainbridge0774b232019-08-02 06:37:19 +0000450
David Bainbridge27790d62019-08-13 22:43:19 +0000451export ONOS_API_PORT ONOS_SSH_PORT
David Bainbridge01294952019-07-30 19:33:45 +0000452
Test Userd87942b2019-07-03 07:20:24 +0000453IDX=1
David Bainbridgee87067b2019-08-12 22:00:12 +0000454CLOCK="TIME:"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000455SPIN_PARTS=
456NOT_VERIFIED=
David Bainbridgef858a022019-08-14 21:25:11 +0000457THEX=
458BUILD=
David Bainbridge38dc1e82019-08-12 15:18:45 +0000459VERIFIED=
460HELM=
461OLD_KEY=
462BIRD=
463HIGH_VOLTAGE=
464PLUG=
David Bainbridge38dc1e82019-08-12 15:18:45 +0000465FORWARD=
David Bainbridge38dc1e82019-08-12 15:18:45 +0000466GO=
467DOWNLOAD=
468GEAR=
469NO_ENTRY=
470LOCK=
471
David Bainbridged18f4942020-04-14 16:46:13 -0700472if [ "$FANCY" -eq 1 ]; then
473 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 +0000474 CLOCK="\xe2\x8f\xb1"
David Bainbridgef858a022019-08-14 21:25:11 +0000475 THEX="${RED}${BOLD}\xe2\x9c\x97\x20${NORMAL}"
David Bainbridgef858a022019-08-14 21:25:11 +0000476 BUILD="${YELLOW}${BOLD}\xf0\x9f\x8f\x97${NORMAL}"
477 NOT_VERIFIED="$BUILD"
478 VERIFIED="${GREEN}${BOLD}\xe2\x9c\x93\x20${NORMAL}"
479 HELM="${BLUE}${BOLD}\xE2\x8E\x88${NORMAL}"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000480 OLD_KEY="\xF0\x9F\x97\x9D"
481 BIRD="\xF0\x9F\x90\xA6"
482 HIGH_VOLTAGE="\xE2\x9A\xA1"
483 PLUG="\xF0\x9F\xa7\xa9"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000484 FORWARD="\xE2\x87\xA8"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000485 GO="\xf0\x9f\x9a\x80"
486 DOWNLOAD="\xf0\x9f\x93\xa5"
487 GEAR="\xe2\x9a\x99"
488 NO_ENTRY="\xe2\x9b\x94"
489 LOCK="\xf0\x9f\x94\x92"
490fi
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700491
David Bainbridge712afb82019-08-14 19:55:58 +0000492duration() {
David Bainbridged18f4942020-04-14 16:46:13 -0700493 local h m s t
494 h="$(($1 / 3600))"
495 m="$(($1 % 3600 / 60))"
496 s="$(($1 % 60))"
497 t=""
David Bainbridgee87067b2019-08-12 22:00:12 +0000498
David Bainbridged18f4942020-04-14 16:46:13 -0700499 if [ "$h" -gt 0 ]; then
David Bainbridgee87067b2019-08-12 22:00:12 +0000500 t="$t${h}h"
501 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700502 if [ "$m" -gt 0 ]; then
David Bainbridgee87067b2019-08-12 22:00:12 +0000503 t="$t${m}m"
504 fi
David Bainbridge712afb82019-08-14 19:55:58 +0000505 echo "$t${s}s"
506}
507
508printtime() {
David Bainbridged18f4942020-04-14 16:46:13 -0700509 local INDENT
David Bainbridge712afb82019-08-14 19:55:58 +0000510 if [ "$1" == "-" ]; then
511 INDENT=" "
512 shift
513 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700514 echo -e "$INDENT $CLOCK $(duration "$1")"
David Bainbridgee87067b2019-08-12 22:00:12 +0000515}
516
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700517bspin() {
Test Userd87942b2019-07-03 07:20:24 +0000518 IDX=1
David Bainbridged18f4942020-04-14 16:46:13 -0700519 local INDENT
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700520 if [ "$1" == "-" ]; then
521 INDENT=" "
522 shift
523 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700524 if [ "$FANCY" -eq 0 ]; then
525 LINE="${*//[[:space:]+-]}"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000526 if [ "$LINE X" == " X" ]; then
527 return
528 fi
529 echo -e "$CIVIS$INDENT$*"
530 else
531 echo -en "$CIVIS$INDENT $*"
532 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700533}
534
535sspin() {
David Bainbridged18f4942020-04-14 16:46:13 -0700536 local INDENT
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700537 if [ "$1" == "-" ]; then
538 INDENT=" "
539 shift
540 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700541 if [ "$FANCY" -eq 0 ]; then
542 LINE="${*//[[:space:]+-]}"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000543 if [ "$LINE X" == " X" ]; then
544 return
545 fi
546 echo -e "$INDENT$*"
547 else
David Bainbridged18f4942020-04-14 16:46:13 -0700548 C="$(echo "$SPIN_PARTS" | cut '-d ' -f "$IDX")"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000549 echo -en "\r$INDENT$C $*"
David Bainbridged18f4942020-04-14 16:46:13 -0700550 IDX="$((IDX + 1))"
551 if [ "$IDX" -gt 8 ]; then
David Bainbridge38dc1e82019-08-12 15:18:45 +0000552 IDX=1
553 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700554 fi
555}
556
557espin() {
David Bainbridged18f4942020-04-14 16:46:13 -0700558 local INDENT
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700559 if [ "$1" == "-" ]; then
560 INDENT=" "
561 shift
562 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700563 if [ "$FANCY" -eq 0 ]; then
564 LINE="${*//[[:space:]+-]}"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000565 if [ "$LINE X" == " X" ]; then
566 return
567 fi
568 echo -e "$INDENT$*"
569 else
570 echo -e "\r$INDENT$*$CNORM"
571 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700572}
573
David Bainbridged18f4942020-04-14 16:46:13 -0700574if [ "$1" == "get" ] && [ "$2" == "voltconfig" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000575 echo "$HOME/.volt/config-$NAME"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000576 exit
577fi
578
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700579if [ $# -ne 1 ] || ! is_in "$1" "up,down,dump"; then
David Bainbridgeac7f8072019-08-01 22:15:33 +0000580 >&2 echo "What wouild you like to do today:"
581 >&2 echo " up - bring up voltha"
582 >&2 echo " down - tear down voltha"
583 >&2 echo " dump - create a debug dump of running system"
584 exit 1
585fi
586
David Bainbridge4f1b5562019-08-19 04:46:52 +0000587push_onos_config() {
David Bainbridged18f4942020-04-14 16:46:13 -0700588 local TYPE MSG RESOURCE DATA CMD_ECHO CMD_OUTPUT SC_OUTPUT WAIT_START NOW
589 TYPE=$1
590 MSG=$2
591 RESOURCE=$3
592 DATA=$4
David Bainbridge4f1b5562019-08-19 04:46:52 +0000593
David K. Bainbridgeb4b163b2020-02-19 15:55:06 -0800594 # Thanks to the latest version of ONOS using the return code 207 this gets a
595 # whole lot nastier. Can't thank them enough for doing this. So in order to
596 # capture the command and the output in the log file as well as capture the
597 # status code to verify it is 200 and not 207 mutltiple files and a bit of
598 # hackery must be used. Thanks again ONOS.
David Bainbridged18f4942020-04-14 16:46:13 -0700599 CMD_ECHO="$(mktemp -u)"
600 CMD_OUTPUT="$(mktemp -u)"
601 SC_OUTPUT="$(mktemp -u)"
602 WAIT_START="$(date +%s)"
David K. Bainbridgeb4b163b2020-02-19 15:55:06 -0800603
David Bainbridge4f1b5562019-08-19 04:46:52 +0000604 bspin - "$MSG $GEAR"
605 while true; do
David Bainbridged18f4942020-04-14 16:46:13 -0700606 NOW="$(date +%s)"
607 if [ "$((NOW - WAIT_START))" -gt "$TIMEOUT_SECONDS" ]; then
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700608 espin - "$THEX"
David Bainbridged18f4942020-04-14 16:46:13 -0700609 rm -f "$CMD_ECHO" "$CMD_OUTPUT" "$SC_OUTPUT"
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700610 doTimeout "waiting for ONOS config push on $RESOURCE"
611 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700612 if [ "$TYPE" == "file" ]; then
613 (set -x; curl --fail -sSL --user karaf:karaf -w "%{http_code}" -o "$CMD_OUTPUT" -X POST -H Content-Type:application/json "http://$_ONOS_API_EP/onos/v1/$RESOURCE" --data "@$DATA" >"$SC_OUTPUT" 2>/dev/null) >>"$CMD_ECHO" 2>&1
David K. Bainbridgeb859e912020-03-13 14:07:52 -0700614 RESULT=$?
Matteo Scandolo78dfee02020-02-13 16:18:03 -0800615 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700616 if [ "$TYPE" == "json" ]; then
617 (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 -0700618 RESULT=$?
Matteo Scandolo78dfee02020-02-13 16:18:03 -0800619 fi
David K. Bainbridgeb4b163b2020-02-19 15:55:06 -0800620 # Dump everything to the log
David Bainbridged18f4942020-04-14 16:46:13 -0700621 cat "$CMD_ECHO" >> "$LOG"
622 test -r "$CMD_OUTPUT" && cat "$CMD_OUTPUT" >> "$LOG"
623 SC="$(cat "$SC_OUTPUT")"
624 echo "RESPONSE CODE: $SC" >> "$LOG"
625 echo "ERROR CODE: $RESULT" >> "$LOG"
David K. Bainbridgeb4b163b2020-02-19 15:55:06 -0800626
627 # clean up temp files
David Bainbridged18f4942020-04-14 16:46:13 -0700628 rm -f "$CMD_ECHO" "$CMD_OUTPUT" "$SC_OUTPUT"
629 if [ "$RESULT" -eq 0 ] && [ "$SC" == "200" ]; then
David Bainbridge4f1b5562019-08-19 04:46:52 +0000630 break
631 fi
Matteo Scandolo9a77a732020-01-09 14:24:12 -0800632 sleep 1
David Bainbridge4f1b5562019-08-19 04:46:52 +0000633 sspin -
634 done
David Bainbridged18f4942020-04-14 16:46:13 -0700635 espin - "$VERIFIED"
David Bainbridge4f1b5562019-08-19 04:46:52 +0000636}
637
Matteo Scandolo9a77a732020-01-09 14:24:12 -0800638check_onos_app_active() {
David Bainbridged18f4942020-04-14 16:46:13 -0700639 local APP_ID WAIT_START RESULT NOW
640 APP_ID=$1
641 WAIT_START="$(date +%s)"
Matteo Scandolo9a77a732020-01-09 14:24:12 -0800642
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700643 bspin - "Checking that $APP_ID is active $CLOCK"
644 while true; do
David Bainbridged18f4942020-04-14 16:46:13 -0700645 NOW="$(date +%s)"
646 if [ "$((NOW - WAIT_START))" -gt "$TIMEOUT_SECONDS" ]; then
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700647 espin - "$THEX"
648 doTimeout "waiting for ONOS application activation '$APP_ID'"
649 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700650 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 -0700651 break
652 fi
653 sleep 1
654 sspin -
655 done
656 sleep 5 # OSGI components take a little longer that the app to activate
David Bainbridged18f4942020-04-14 16:46:13 -0700657 espin - "$VERIFIED"
Matteo Scandolo9a77a732020-01-09 14:24:12 -0800658}
659
David Bainbridge4f1b5562019-08-19 04:46:52 +0000660override_onos_app() {
David Bainbridged18f4942020-04-14 16:46:13 -0700661 local APP NAME WAIT_START NOW
662 APP=$1
663 NAME="$(basename "$APP" | sed -e 's/^[0-9][0-9]*-//g' -e 's/-.*$//g')"
664 WAIT_START="$(date +%s)"
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700665
David Bainbridge4f1b5562019-08-19 04:46:52 +0000666 while true; do
David Bainbridged18f4942020-04-14 16:46:13 -0700667 NOW="$(date +%s)"
668 if [ "$((NOW - WAIT_START))" -gt "$TIMEOUT_SECONDS" ]; then
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700669 espin - "$THEX"
670 doTimeout "waiting to overwrite ONOS application '$APP'"
671 fi
David Bainbridge4f1b5562019-08-19 04:46:52 +0000672 sspin -
673 # Attempt to delete old version (if it exists)
David Bainbridged18f4942020-04-14 16:46:13 -0700674 (set -x; curl --fail -sSL --user karaf:karaf -X DELETE "http://$_ONOS_API_EP/onos/v1/applications/$NAME" >>"$LOG" 2>&1) >>"$LOG" 2>&1
675 RESULT=$?
David Bainbridge4f1b5562019-08-19 04:46:52 +0000676 sspin -
David Bainbridged18f4942020-04-14 16:46:13 -0700677 if [ $RESULT -ne 0 ]; then
David Bainbridge4f1b5562019-08-19 04:46:52 +0000678 continue
679 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700680 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 +0000681 break
682 fi
683 sleep .2
684 done
685}
686
687activate_onos_app() {
David Bainbridged18f4942020-04-14 16:46:13 -0700688 local MSG APP WAIT_START NOW
689 MSG="$1"
690 APP=$2
691 WAIT_START="$(date +%s)"
David Bainbridge4f1b5562019-08-19 04:46:52 +0000692
693 bspin - "$MSG $GO"
694 while true; do
David Bainbridged18f4942020-04-14 16:46:13 -0700695 NOW="$(date +%s)"
696 if [ "$((NOW - WAIT_START))" -gt "$TIMEOUT_SECONDS" ]; then
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700697 espin - "$THEX"
698 doTimeout "waiting to activate ONOS application '$APP'"
699 fi
David Bainbridge4f1b5562019-08-19 04:46:52 +0000700 sspin -
David Bainbridged18f4942020-04-14 16:46:13 -0700701 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 +0000702 break
703 fi
704 sleep .2
705 done
706 espin - "$VERIFIED"
707}
708
709count_pods() {
David Bainbridged18f4942020-04-14 16:46:13 -0700710 local NAMESPACE STATES LABELS CMD PODS
711 NAMESPACE=$1; shift
David Bainbridge4f1b5562019-08-19 04:46:52 +0000712 if [ "$NAMESPACE" == "all-namespaces" ]; then
713 NAMESPACE="--all-namespaces"
714 else
715 NAMESPACE="-n $NAMESPACE"
716 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700717 STATES=$1; shift
718 LABELS=$1; shift
719 CMD=("kubectl get $NAMESPACE $LABELS pod")
720 PODS=$(${CMD[*]} -o go-template="{{range .items}}{{.metadata.name}}/{{.status.phase}}/_{{range .status.containerStatuses}}{{.ready}}_{{end}} {{end}}")
David Bainbridge4f1b5562019-08-19 04:46:52 +0000721 local COUNT=0
722 local PATTERNS="$*"
723 for POD in $PODS; do
David Bainbridged18f4942020-04-14 16:46:13 -0700724 local NAME STATE CONTAINERS TOTAL FOUND
725 NAME="$(echo "$POD" | cut -d/ -f 1)"
726 STATE="$(echo "$POD" | cut -d/ -f 2)"
727 CONTAINERS="$(echo "$POD" | cut -d/ -f 3 | sed -e 's/_/ /g')"
728 if [ "$STATES" == "*" ] || [ "$(echo "$STATES" | grep -c ":$STATE:")" -ne 0 ]; then
729 TOTAL="$(echo "$CONTAINERS" | wc -w)"
730 FOUND="$(echo "$CONTAINERS" | grep -o true | wc -l)"
731 if [ "$TOTAL" -eq "$FOUND" ]; then
David Bainbridge4f1b5562019-08-19 04:46:52 +0000732 for PATTERN in $PATTERNS; do
David Bainbridged18f4942020-04-14 16:46:13 -0700733 if [[ "$NAME" =~ $PATTERN ]]; then
734 COUNT="$((COUNT + 1))"
David Bainbridge4f1b5562019-08-19 04:46:52 +0000735 break
736 fi
737 done
738 fi
739 fi
740 done
David Bainbridge4f1b5562019-08-19 04:46:52 +0000741 echo $COUNT
742}
743
744wait_for_pods() {
David Bainbridged18f4942020-04-14 16:46:13 -0700745 local INDENT NAMESPACE EXPECT TYPE MESSAGE LABELS PATTERNS STATES HAVE ALL WAIT_START NOW
David Bainbridge4f1b5562019-08-19 04:46:52 +0000746 if [ "$1" == "-" ]; then
747 INDENT=$1; shift
748 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700749 NAMESPACE=$1; shift
750 EXPECT=$1; shift
751 TYPE=$1; shift
752 MESSAGE=$1; shift
753 LABELS=$1; shift
754 PATTERNS=("$*")
755 STATES=":Running:"
David Bainbridge99ac7a22019-08-31 02:26:43 +0000756 if [ "$TYPE" == "not" ]; then
757 STATES="*"
758 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700759 HAVE="$(count_pods "$NAMESPACE" "$STATES" "$LABELS" "${PATTERNS[@]}")"
760 ALL=$HAVE
David Bainbridge4f1b5562019-08-19 04:46:52 +0000761 if [ "$TYPE" == "only" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -0700762 ALL="$(count_pods "all-namespaces" "*" ".*")"
David Bainbridge4f1b5562019-08-19 04:46:52 +0000763 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700764 COUNT="$((300 / 15))"
765 WAIT_START="$(date +%s)"
766 bspin "$INDENT" "$MESSAGE"
767 sspin "$INDENT"
768 if [ "$HAVE" -ne "$EXPECT" ] || [ "$ALL" -ne "$HAVE" ]; then
769 while [ "$HAVE" -ne "$EXPECT" ] || [ "$ALL" -ne "$HAVE" ]; do
770 NOW="$(date +%s)"
771 if [ "$((NOW - WAIT_START))" -gt "$TIMEOUT_SECONDS" ]; then
772 espin "$INDENT" "$THEX"
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700773 doTimeout "waiting for PODs to start"
774 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700775 sspin "$INDENT"
776 COUNT="$((COUNT - 1))"
777 if [ "$COUNT" -eq 0 ]; then
778 HAVE="$(count_pods "$NAMESPACE" "$STATES" "$LABELS" "${PATTERNS[@]}")"
779 ALL="$HAVE"
David Bainbridge4f1b5562019-08-19 04:46:52 +0000780 if [ "$TYPE" == "only" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -0700781 ALL="$(count_pods "all-namespaces" "*" ".*")"
David Bainbridge4f1b5562019-08-19 04:46:52 +0000782 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700783 COUNT="$((300 / 15))"
David Bainbridge4f1b5562019-08-19 04:46:52 +0000784 fi
785 sleep .15
786 done
787 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700788 espin "$INDENT" "$VERIFIED"
789 if [ "$HAVE" -ne "$EXPECT" ]; then
David Bainbridge4f1b5562019-08-19 04:46:52 +0000790 return 1
791 fi
792 return 0
793}
794
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800795port_forward() {
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700796 local NS=$1; shift
797 local SVC=$1; shift
798 local PORTS="$*"
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800799 local TAG=$SVC-$NAME
800
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700801 (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 -0800802}
803
804kill_port_forward() {
David Bainbridged18f4942020-04-14 16:46:13 -0700805 local TAG P_IDS PARENTS KIDS UNKNOWN PP_ID
806 TAG="$1-$NAME"
807 # shellcheck disable=SC2009
808 P_IDS="$(ps e -ww -A | grep "_TAG=$TAG" | grep -v grep | awk '{print $1}')"
809 if [ -n "$P_IDS" ]; then
David Bainbridgec6871d22019-11-13 17:10:31 +0000810 for P_ID in $P_IDS; do
David Bainbridged18f4942020-04-14 16:46:13 -0700811 PP_ID="$(ps -o ppid "$P_ID" | tail -n +2)"
812 if [ -n "$PP_ID" ]; then
813 if [ "$PP_ID" -eq 1 ]; then
David Bainbridgec6871d22019-11-13 17:10:31 +0000814 PARENTS="$PARENTS $P_ID"
815 else
816 KIDS="$KIDS $P_ID"
817 fi
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800818 else
David Bainbridgec6871d22019-11-13 17:10:31 +0000819 UNKNOWN="$UNKNOWN $P_ID"
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800820 fi
821 done
David Bainbridged18f4942020-04-14 16:46:13 -0700822 (set -x; kill -9 "$PARENTS" "$KIDS" "$UNKNOWN" >>"$LOG" 2>&1) >>"$LOG" 2>&1
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800823 fi
824}
825
David Bainbridgecf546362020-04-21 23:18:50 -0700826resolve_chart_version() {
827 [ "$2" != "latest" ] && echo "$2" && return
828 helm inspect chart "$1" | grep "^version:" | awk '{print $2}'
829}
830
Jonathan Hart6a91e6c2020-04-16 14:28:33 -0700831# Compares two semver-formatted version strings (e.g. 2.4.3)
832# Returns 0 if $1 == $2, returns 1 if $1 > $2 and returns 2 if $1 < $2
833compare_versions() {
834 [ "$1" == "$2" ] && return 0
Jonathan Hart6a91e6c2020-04-16 14:28:33 -0700835 local lowest
836 lowest=$(echo -e "$1\n$2" | sort -V | head -1)
837 [ "$lowest" == "$1" ] && return 2
838 return 1
839}
840
David Bainbridgeac7f8072019-08-01 22:15:33 +0000841if [ "$1" == "down" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000842 echo "Tearing down voltha cluster $NAME"
843 LOG="down-$NAME.log"
David Bainbridged18f4942020-04-14 16:46:13 -0700844 date -u +"%Y%m%dT%H%M%SZ" >"$LOG"
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700845 if is_in "$WITH_ONOS" "yes,legacy,classic"; then
David Bainbridge696bc632020-04-05 21:49:37 -0700846 bspin "Remove port-forwards: onos-ui-$NAME"
847 kill_port_forward onos-ui
848 sspin "Remove port-forwards: onos-ssh-$NAME$CEOL"
849 kill_port_forward onos-ssh
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700850 bspin "Remove port-forwards: onos-onos-classic-hs-$NAME$CEOL"
851 kill_port_forward onos-onos-classic-hs
David Bainbridge696bc632020-04-05 21:49:37 -0700852 fi
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800853 sspin "Remove port-forwards: voltha-api-$NAME$CEOL"
854 kill_port_forward voltha-api
David Bainbridged18f4942020-04-14 16:46:13 -0700855 if [ "$WITH_ETCD" == "yes" ] || [ "$WITH_ETCD" == "external" ]; then
856 sspin "Remove port-forwards: ${ETCD_PREFIX}etcd-$NAME$CEOL"
857 kill_port_forward "${ETCD_PREFIX}etcd-cluster-client"
David Bainbridge696bc632020-04-05 21:49:37 -0700858 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700859 if [ "$WITH_KAFKA" == "yes" ] || [ "$WITH_KAFKA" == "external" ]; then
860 sspin "Remove port-forwards: ${KAFKA_PREFIX}kafka-$NAME$CEOL"
861 kill_port_forward "${KAFKA_PREFIX}kafka"
David Bainbridge696bc632020-04-05 21:49:37 -0700862 fi
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800863 espin "$VERIFIED Remove port-forwards$CEOL"
David Bainbridged18f4942020-04-14 16:46:13 -0700864 if [ "$DEPLOY_K8S" == "yes" ]; then
David Bainbridgeac7f8072019-08-01 22:15:33 +0000865 if [ -x ./bin/kind ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000866 bspin "Delete Kubernetes Kind Cluster"
David Bainbridged18f4942020-04-14 16:46:13 -0700867 (set -x; ./bin/kind delete cluster --name "voltha-$NAME" >>"$LOG" 2>&1) >>"$LOG" 2>&1
868 espin "$VERIFIED"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000869 else
David Bainbridge0774b232019-08-02 06:37:19 +0000870 espin "$NO_ENTRY Delete Kubernetes Kind Cluster: kind command not found"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000871 fi
872 else
David Bainbridge309099c2020-05-05 08:47:29 -0700873 if [ "$CONFIG_SADIS" == "external" ]; then
874 bspin "Remove configmap for BBSIM SADIS server"
875 (set -x; kubectl -n "$BBSIM_NS" delete --ignore-not-found configmap kube-config >>"$LOG" 2>&1) >>"$LOG" 2>&1
876 espin "$VERIFIED"
877 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700878 EXISTS="$(helm list -q)"
David Bainbridge76afd812020-04-06 09:53:52 -0700879 EXPECT="voltha"
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700880 if is_in "$WITH_ONOS" "yes,legacy,classic"; then
David Bainbridge696bc632020-04-05 21:49:37 -0700881 EXPECT+=" onos"
882 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700883 if [ "$WITH_RADIUS" == "yes" ]; then
David Bainbridge696bc632020-04-05 21:49:37 -0700884 EXPECT+=" radius"
885 fi
David Bainbridge309099c2020-05-05 08:47:29 -0700886 if [ "$CONFIG_SADIS" == "external" ]; then
887 EXPECT+=" bbsim-sadis-server"
888 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700889 if [ "$WITH_BBSIM" == "yes" ]; then
David Bainbridge696bc632020-04-05 21:49:37 -0700890 EXPECT+=" bbsim"
891 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700892 if [ "$WITH_OPEN_ADAPTERS" == "yes" ]; then
David Bainbridge696bc632020-04-05 21:49:37 -0700893 EXPECT+=" open-olt open-onu"
894 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700895 if [ "$WITH_SIM_ADAPTERS" == "yes" ]; then
David Bainbridge696bc632020-04-05 21:49:37 -0700896 EXPECT+=" sim"
897 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700898 if [ "$WITH_ETCD" == "external" ]; then
David Bainbridge76afd812020-04-06 09:53:52 -0700899 EXPECT+=" etcd-operator etcd-cluster"
David Bainbridged18f4942020-04-14 16:46:13 -0700900 elif [ "$WITH_ETCD" == "yes" ]; then
David Bainbridge76afd812020-04-06 09:53:52 -0700901 EXPECT+=" etcd-operator"
902 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700903 if [ "$WITH_KAFKA" == "external" ]; then
David Bainbridge76afd812020-04-06 09:53:52 -0700904 EXPECT+=" kafka"
905 fi
David Bainbridge0774b232019-08-02 06:37:19 +0000906 bspin "Remove Helm Deployments"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000907 for i in $EXISTS; do
David K. Bainbridge43422402020-03-06 07:41:22 -0800908 for j in $EXPECT; do
David Bainbridged18f4942020-04-14 16:46:13 -0700909 if [[ "$i" =~ $j ]]; then
David K. Bainbridge43422402020-03-06 07:41:22 -0800910 sspin "Remove Helm Deployments: $i$CEOL"
David Bainbridged18f4942020-04-14 16:46:13 -0700911 (set -x; ./bin/helm delete --no-hooks --purge "$i" >>"$LOG" 2>&1) >>"$LOG" 2>&1
David K. Bainbridge43422402020-03-06 07:41:22 -0800912 fi
913 done
uottrembb16d3982020-02-28 08:34:36 +0100914 done
David Bainbridge0774b232019-08-02 06:37:19 +0000915 espin "$VERIFIED Remove Helm Deployments$CEOL"
David Bainbridge4f1b5562019-08-19 04:46:52 +0000916 if [ "$WAIT_ON_DOWN" == "yes" ]; then
David Bainbridge76afd812020-04-06 09:53:52 -0700917 PODS="voltha-kafka.* voltha-ofagent.* voltha-rw-core.* voltha-etcd.*"
918 INFRA_PODS=
919 ADAPT_PODS=
920 SIM_PODS=
David Bainbridged18f4942020-04-14 16:46:13 -0700921 if [ "$WITH_RADIUS" == "yes" ]; then
David Bainbridge696bc632020-04-05 21:49:37 -0700922 PODS+=" radius.*"
923 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700924 if [ "$WITH_BBSIM" == "yes" ]; then
David Bainbridge76afd812020-04-06 09:53:52 -0700925 SIM_PODS+=" bbsim.*"
David Bainbridge696bc632020-04-05 21:49:37 -0700926 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700927 if [ "$WITH_OPEN_ADAPTERS" ] || [ "$WITH_SIM_ADAPTERS" ]; then
David Bainbridge76afd812020-04-06 09:53:52 -0700928 ADAPT_PODS+=" adapter-*"
David Bainbridge696bc632020-04-05 21:49:37 -0700929 fi
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700930 if is_in "$WITH_ONOS" "yes,legacy,classic"; then
David Bainbridge76afd812020-04-06 09:53:52 -0700931 INFRA_PODS+=" onos-.*"
932 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700933 if [ "$WITH_ETCD" == "external" ]; then
David Bainbridge76afd812020-04-06 09:53:52 -0700934 INFRA_PODS+=" etcd-operator.* etcd-cluster.*"
David Bainbridged18f4942020-04-14 16:46:13 -0700935 elif [ "$WITH_ETCD" == "yes" ]; then
David Bainbridge76afd812020-04-06 09:53:52 -0700936 PODS+=" etcd-operator.*"
937 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700938 if [ "$WITH_KAFKA" == "external" ]; then
David Bainbridge76afd812020-04-06 09:53:52 -0700939 INFRA_PODS+=" kafka.*"
940 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700941 if [ -n "$SIM_PODS" ]; then
942 wait_for_pods "$BBSIM_NS" 0 "not" "Waiting for BBSIM PODs to terminate" "$BBSIM_LABEL" "$SIM_PODS"
David Bainbridge76afd812020-04-06 09:53:52 -0700943 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700944 if [ -n "$INFRA_PODS" ]; then
945 wait_for_pods "$INFRA_NS" 0 "not" "Waiting for infrastructure PODs to terminate" "$NO_LABEL" "$INFRA_PODS"
David Bainbridge76afd812020-04-06 09:53:52 -0700946 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700947 if [ -n "$ADAPT_PODS" ]; then
948 wait_for_pods "$ADAPTER_NS" 0 "not" "Waiting for adapter PODs to terminate" "$NO_LABEL" "$ADAPT_PODS"
David Bainbridge76afd812020-04-06 09:53:52 -0700949 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700950 wait_for_pods "$VOLTHA_NS" 0 "not" "Waiting for VOLTHA PODs to terminate" "$NO_LABEL" "$PODS"
David Bainbridge4f1b5562019-08-19 04:46:52 +0000951 fi
David Bainbridgeac7f8072019-08-01 22:15:33 +0000952 fi
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -0700953 exit
David Bainbridgeac7f8072019-08-01 22:15:33 +0000954fi
955
956if [ "$1" == "dump" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000957 LOG="dump-$NAME.log"
David Bainbridged18f4942020-04-14 16:46:13 -0700958 TS="$(date -u +"%Y%m%dT%H%M%SZ")"
959 if [ -n "$DUMP_FROM" ]; then
960 TS=${DUMP_FROM//[:-]}
David Bainbridge76514a02019-10-08 01:50:35 +0000961 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700962 WORK="$(mktemp -u -d)"
David Bainbridge0774b232019-08-02 06:37:19 +0000963 DATA=$WORK/voltha-debug-dump-$NAME-$TS
David Bainbridged18f4942020-04-14 16:46:13 -0700964 mkdir -p "$DATA"
965 echo "$TS" > "$LOG"
David Bainbridge0774b232019-08-02 06:37:19 +0000966 echo -e "Capturing debug dump to voltha-debug-dump-$NAME-$TS.tgz"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000967 bspin - "Copy install log"
David Bainbridged18f4942020-04-14 16:46:13 -0700968 if [ -f "install-$NAME.log" ]; then
969 (set -x; cp "install-$NAME.log" "$DATA/install-$NAME.log") >>"$LOG" 2>&1
970 espin - "$VERIFIED"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000971 else
David Bainbridge0774b232019-08-02 06:37:19 +0000972 espin - "$NO_ENTRY Copy install log: install-$NAME.log not found"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000973 fi
974 bspin - "Dumping Kubernetes PODs"
David Bainbridged18f4942020-04-14 16:46:13 -0700975 (set -x; kubectl get --all-namespaces pods >> "$DATA/all-pods.txt" 2>&1) >>"$LOG" 2>&1
976 espin - "$VERIFIED"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000977 bspin - "Dumping Kubernetes SERVICEs"
David Bainbridged18f4942020-04-14 16:46:13 -0700978 (set -x; kubectl get --all-namespaces svc >> "$DATA/all-services.txt" 2>&1) >>"$LOG" 2>&1
979 espin - "$VERIFIED"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000980 bspin - "Dumping Kubernetes EVENTs"
David Bainbridged18f4942020-04-14 16:46:13 -0700981 (set -x; kubectl get --all-namespaces events >> "$DATA/all-events.txt" 2>&1) >>"$LOG" 2>&1
982 espin - "$VERIFIED"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000983 bspin - "Dumping VOLTHA POD details"
David Bainbridged18f4942020-04-14 16:46:13 -0700984 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 +0000985 SINCE=
David Bainbridged18f4942020-04-14 16:46:13 -0700986 if [ -n "$DUMP_FROM" ]; then
David Bainbridgecfd7ca12019-10-06 03:31:41 +0000987 SINCE="--since-time=$DUMP_FROM"
988 fi
David Bainbridgeac7f8072019-08-01 22:15:33 +0000989 for POD in $PODS; do
David Bainbridged18f4942020-04-14 16:46:13 -0700990 NS="$(echo "$POD" | cut -d: -f1)"
991 POD="$(echo "$POD" | cut -d: -f2)"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000992 sspin - "Dumping VOLTHA POD details: $POD$CEOL"
David Bainbridged18f4942020-04-14 16:46:13 -0700993 mkdir -p "$DATA/$POD"
994 (set -x; kubectl describe -n "$NS" "$POD" >> "$DATA/$POD/describe.txt" 2>&1) >>"$LOG" 2>&1
David Bainbridgeac7f8072019-08-01 22:15:33 +0000995 sspin - "Dumping VOLTHA POD details: $POD"
David Bainbridged18f4942020-04-14 16:46:13 -0700996 (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 +0000997 sspin - "Dumping VOLTHA POD details: $POD"
David Bainbridged18f4942020-04-14 16:46:13 -0700998 (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 +0000999 sspin - "Dumping VOLTHA POD details: $POD"
1000 done
1001 espin - "$VERIFIED Dumping VOLTHA POD details$CEOL"
1002 bspin - "Dumping ETCD"
David Bainbridged18f4942020-04-14 16:46:13 -07001003 if [ -n "$(command -v etcdctl)" ]; then
1004 (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
1005 espin - "$VERIFIED"
David Bainbridgeac7f8072019-08-01 22:15:33 +00001006 else
1007 espin - "$NO_ENTRY Dumping ETCD: etcdctl command not available"
1008 fi
David Bainbridge0774b232019-08-02 06:37:19 +00001009 bspin - "Creating compressed TAR: voltha-debug-dump-$NAME-$TS.tgz"
David Bainbridged18f4942020-04-14 16:46:13 -07001010 (set -x; tar -C "$WORK" -zcf "voltha-debug-dump-$NAME-$TS.tgz" "./voltha-debug-dump-$NAME-$TS") >>"$LOG" 2>&1
1011 espin - "$VERIFIED"
David Bainbridgeac7f8072019-08-01 22:15:33 +00001012 bspin - "Cleanup"
David Bainbridged18f4942020-04-14 16:46:13 -07001013 (set -x; rm -rf "$WORK") >>"$LOG" 2>&1
1014 espin - "$VERIFIED"
1015 bspin - "$(ls -l "voltha-debug-dump-$NAME-$TS.tgz")"
1016 espin - "$VERIFIED"
David Bainbridgeac7f8072019-08-01 22:15:33 +00001017 exit
1018fi
1019
David Bainbridge0774b232019-08-02 06:37:19 +00001020LOG="install-$NAME.log"
David Bainbridged18f4942020-04-14 16:46:13 -07001021date > "$LOG"
1022echo "PORTS=$ONOS_API_PORT,$ONOS_SSH_PORT,$VOLTHA_API_PORT,$VOLTHA_SSH_PORT,$VOLTHA_ETCD_PORT" >> "$LOG"
David Bainbridgeac7f8072019-08-01 22:15:33 +00001023
1024# Output install options to log
David Bainbridged18f4942020-04-14 16:46:13 -07001025echo "OPTIONS" >> "$LOG"
David Bainbridgeac7f8072019-08-01 22:15:33 +00001026for O in $ALL_OPTIONS; do
David Bainbridged18f4942020-04-14 16:46:13 -07001027 VAL="$(eval echo "\$$O")"
1028 if [ -n "$VAL" ]; then
1029 printf " %-30s = %s\n" "$O" "$VAL" >> "$LOG"
David Bainbridgeac7f8072019-08-01 22:15:33 +00001030 fi
1031done
1032
David Bainbridgefad50732020-05-01 17:00:12 -07001033helm_values() {
1034 local NAMESPACE=$1; shift
1035 local INAME=$1; shift
1036 local CHART=$1; shift
1037 local CHART_VERSION=$1; shift
1038
1039 if [ "$CHART_VERSION X" != " X" ] && [ "$CHART_VERSION" != "latest" ]; then
1040 CHART_VERSION="--version $CHART_VERSION"
1041 else
1042 CHART_VERSION=
1043 fi
1044
1045 local CHART_ARGS=
1046 if [ -r "${INAME}-values.yaml" ]; then
1047 CHART_ARGS="-f ${INAME}-values.yaml"
1048 fi
1049
1050 if [ "$HELM_USE_UPGRADE" == "yes" ]; then
1051 _HELM_COMMAND="upgrade --install"
1052 _HELM_ARGS="xxxdryrunxxx"
1053 else
1054 _HELM_COMMAND="install"
1055 _HELM_ARGS="--name xxxdryrunxxx"
1056 fi
1057 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")
1058 ${CMD[*]} 2>/dev/null | awk 'PRINT==1 {print}; /^USER-SUPPLIED VALUES:/ {PRINT = 1}; /^$/ {PRINT = 0}'
1059}
1060
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001061helm_install() {
David Bainbridged18f4942020-04-14 16:46:13 -07001062 local INDENT NOW
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001063 if [ "$1" == "-" ]; then
1064 INDENT=$1; shift
1065 fi
1066 local NAMESPACE=$1; shift
David Bainbridge0774b232019-08-02 06:37:19 +00001067 local INAME=$1; shift
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001068 local CHART=$1; shift
David Bainbridge90fd8e32019-08-21 23:32:47 +00001069 local CHART_VERSION=$1; shift
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001070 local MESSAGE=$*
1071
David Bainbridged18f4942020-04-14 16:46:13 -07001072 if [ "$CHART_VERSION X" != " X" ] && [ "$CHART_VERSION" != "latest" ]; then
David Bainbridge90fd8e32019-08-21 23:32:47 +00001073 CHART_VERSION="--version $CHART_VERSION"
1074 else
1075 CHART_VERSION=
1076 fi
1077
David Bainbridge99ac7a22019-08-31 02:26:43 +00001078 local CHART_ARGS=
1079 if [ -r "${INAME}-values.yaml" ]; then
1080 CHART_ARGS="-f ${INAME}-values.yaml"
1081 fi
1082
David Bainbridged18f4942020-04-14 16:46:13 -07001083 local WAIT_START CMD
1084 WAIT_START="$(date +%s)"
1085 COUNT="$((300 / 15))"
1086 bspin "$INDENT" "$MESSAGE"
1087 if [ "$HELM_USE_UPGRADE" == "yes" ]; then
David Bainbridge7f8bf992020-04-08 21:53:22 -07001088 _HELM_COMMAND="upgrade --install"
1089 _HELM_ARGS="$INAME"
1090 else
1091 _HELM_COMMAND="install"
1092 _HELM_ARGS="--name $INAME"
1093 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001094 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")
1095 (set -x; ${CMD[*]} >>"$LOG" 2>&1) >>"$LOG" 2>&1
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001096 SUCCESS=$?
David Bainbridged18f4942020-04-14 16:46:13 -07001097 while [ "$SUCCESS" -ne 0 ]; do
1098 NOW="$(date +%s)"
1099 if [ "$((NOW - WAIT_START))" -gt "$TIMEOUT_SECONDS" ]; then
David Bainbridge52e6e9d2020-03-23 13:48:27 -07001100 espin "$THEX"
1101 doTimeout "waiting for helm install $CHART"
1102 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001103 sspin "$INDENT"
1104 COUNT="$((COUNT - 1))"
1105 if [ "$COUNT" -eq 0 ]; then
1106 if [ "$HELM_USE_UPGRADE" == "no" ]; then
1107 (set -x; helm delete --purge "$INAME" >>"$LOG" 2>&1) >>"$LOG" 2>&1
David Bainbridge7f8bf992020-04-08 21:53:22 -07001108 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001109 (set -x; ${CMD[*]} >>"$LOG" 2>&1) >>"$LOG" 2>&1
Andy Baviere22ff252019-12-19 11:40:31 -07001110 SUCCESS=$?
David Bainbridged18f4942020-04-14 16:46:13 -07001111 COUNT="$((300 / 15))"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001112 fi
1113 sleep .15
1114 done
David Bainbridged18f4942020-04-14 16:46:13 -07001115 espin "$INDENT" "$VERIFIED"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001116}
1117
David Bainbridged18f4942020-04-14 16:46:13 -07001118echo "INSTALL TYPE: $TYPE" >> "$LOG"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001119
1120bspin "Verify GOPATH"
David Bainbridged18f4942020-04-14 16:46:13 -07001121GOPATH="$(pwd)"; export GOPATH
1122mkdir -p "$GOPATH/bin"
1123espin "$VERIFIED"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001124
David Bainbridged18f4942020-04-14 16:46:13 -07001125STIME="$(date +%s)"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001126if [ "$INSTALL_KUBECTL" == "no" ]; then
1127 bspin "Skip kubectl install"
1128 espin $NO_ENTRY
Test Userc13bdc92019-07-03 20:57:49 +00001129else
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001130 bspin "Verify kubectl $HELM"
David Bainbridged18f4942020-04-14 16:46:13 -07001131 if [ -x "$GOPATH/bin/kubectl" ]; then
1132 espin "$VERIFIED"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001133 else
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001134 ERR_OUT="$(mktemp)"
David Bainbridged18f4942020-04-14 16:46:13 -07001135 espin "$NOT_VERIFIED"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001136 bspin - "Download and install Kubernetes/kubectl $DOWNLOAD"
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001137 (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
1138 RESULT=$?
1139 if [ "$RESULT" -ne 0 ]; then
1140 espin - "$THEX"
David Bainbridgee3fc0c32020-04-21 15:34:04 -07001141 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR: unable to download kubectl: $(tail "$ERR_OUT")${NORMAL}"
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001142 cat "$ERR_OUT" >> "$LOG"
Zack Williamsded60cb2020-04-13 10:02:20 -07001143 rm -rf "$ERR_OUT" "$GOPATH/bin/kubectl"
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001144 exit 1
1145 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001146 (set -x; chmod 755 "$GOPATH/bin/kubectl" >>"$LOG" 2>&1) >>"$LOG" 2>&1
1147 espin - "$VERIFIED"
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001148 rm -rf "$ERR_OUT"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001149 fi
Test Userc13bdc92019-07-03 20:57:49 +00001150fi
David Bainbridgee87067b2019-08-12 22:00:12 +00001151if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001152 NOW="$(date +%s)"
1153 printtime $((NOW - STIME))
David Bainbridgee87067b2019-08-12 22:00:12 +00001154fi
Test Userc13bdc92019-07-03 20:57:49 +00001155
David Bainbridged18f4942020-04-14 16:46:13 -07001156STIME="$(date +%s)"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001157if [ "$DEPLOY_K8S" == "no" ]; then
1158 bspin "Skip Kubernetes/Kind Deployment"
1159 espin $NO_ENTRY
1160else
Test Userba1e7e72019-07-10 22:27:54 +00001161 bspin "Verify Kubernetes/Kind $HELM"
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -08001162 IS_INSTALLED=0
1163 OP_TYPE="install"
David Bainbridged18f4942020-04-14 16:46:13 -07001164 if [ -x "$GOPATH/bin/kind" ]; then
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -08001165 OP_TYPE="upgrade"
David Bainbridged18f4942020-04-14 16:46:13 -07001166 if [ "$("$GOPATH/bin/kind" --version | grep -c "$KIND_VERSION")" -eq 1 ]; then
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -08001167 IS_INSTALLED=1
David Bainbridged18f4942020-04-14 16:46:13 -07001168 espin "$VERIFIED"
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -08001169 fi
1170 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001171 if [ "$IS_INSTALLED" -eq 0 ]; then
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001172 ERR_OUT="$(mktemp)"
David Bainbridged18f4942020-04-14 16:46:13 -07001173 espin "$NOT_VERIFIED"
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -08001174 bspin - "Download and $OP_TYPE Kubernetes/kind $DOWNLOAD"
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001175 (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
1176 RESULT=$?
1177 if [ $RESULT -ne 0 ]; then
1178 espin - "$THEX"
David Bainbridgee3fc0c32020-04-21 15:34:04 -07001179 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR: unable to download kind: $(tail "$ERR_OUT")${NORMAL}"
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001180 cat "$ERR_OUT" >> "$LOG"
Zack Williamsded60cb2020-04-13 10:02:20 -07001181 rm -rf "$ERR_OUT" "$GOPATH/bin/kind"
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001182 exit 1
1183 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001184 (set -x; chmod 755 "$GOPATH/bin/kind" >>"$LOG" 2>&1) >>"$LOG" 2>&1
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001185 rm -rf "$ERR_OUT"
David Bainbridged18f4942020-04-14 16:46:13 -07001186 espin - "$VERIFIED"
Test Userba1e7e72019-07-10 22:27:54 +00001187 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001188fi
1189
David Bainbridgee87067b2019-08-12 22:00:12 +00001190if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001191 NOW="$(date +%s)"
1192 printtime $((NOW - STIME))
David Bainbridgee87067b2019-08-12 22:00:12 +00001193fi
1194
David Bainbridged18f4942020-04-14 16:46:13 -07001195STIME="$(date +%s)"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001196if [ "$INSTALL_HELM" == "no" ]; then
1197 bspin "Skip Helm Install"
1198 espin $NO_ENTRY
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001199else
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001200 bspin "Verify Helm $HELM"
David Bainbridgea34993d2020-04-01 09:15:42 -07001201 HELM_UPGRADE=0
1202 HELM_UPGRADE_DESC="install"
David Bainbridged18f4942020-04-14 16:46:13 -07001203 if [ -x "$GOPATH/bin/helm" ]; then
1204 HAVE_VER="$("$GOPATH/bin/helm" version -c --template '{{.Client.SemVer}}')"
1205 HELM_UP_DOWN="$(echo -e "$HAVE_VER\n$HELM_VERSION" | sort -V | head -1)"
1206 if [ "$HAVE_VER" != "$HELM_VERSION" ]; then
1207 if [ "$HELM_UP_DOWN" == "$HELM_VERSION" ]; then
David Bainbridgea34993d2020-04-01 09:15:42 -07001208 HELM_UPGRADE_DESC="downgrade"
1209 else
1210 HELM_UPGRADE_DESC="upgrade"
1211 fi
1212 HELM_UPGRADE=1
1213 else
David Bainbridged18f4942020-04-14 16:46:13 -07001214 espin "$VERIFIED"
David Bainbridgea34993d2020-04-01 09:15:42 -07001215 fi
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001216 else
David Bainbridgea34993d2020-04-01 09:15:42 -07001217 HELM_UPGRADE=1
1218 fi
1219
David Bainbridged18f4942020-04-14 16:46:13 -07001220 if [ "$HELM_UPGRADE" -ne 0 ]; then
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001221 ERR_OUT="$(mktemp)"
1222 INSTALL_HELM_BIN=$(mktemp)
David Bainbridged18f4942020-04-14 16:46:13 -07001223 espin "$NOT_VERIFIED"
David Bainbridgea34993d2020-04-01 09:15:42 -07001224 bspin - "Download and $HELM_UPGRADE_DESC Helm $DOWNLOAD"
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001225 (set -x; curl -o "$INSTALL_HELM_BIN" --fail -sSL https://git.io/get_helm.sh >>"$LOG" 2>"$ERR_OUT") >>"$LOG" 2>&1
1226 RESULT=$?
1227 if [ $RESULT -ne 0 ]; then
1228 espin - "$THEX"
David Bainbridgee3fc0c32020-04-21 15:34:04 -07001229 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR: unable to download helm installer: $(tail "$ERR_OUT")${NORMAL}"
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001230 cat "$ERR_OUT" >> "$LOG"
1231 rm -rf "$INSTALL_HELM_BIN" "$ERR_OUT" "$GOPATH/bin/helm" "$GOPATH/bin/tiller"
1232 exit 1
1233 fi
1234 rm -rf "$ERR_OUT"
1235 chmod +x "$INSTALL_HELM_BIN"
1236 (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
1237 RESULT=$?
1238 if [ $RESULT -ne 0 ]; then
1239 espin - "$THEX"
1240 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR: unable to install helm, see install log for details${NORMAL}"
1241 rm -rf "$INSTALL_HELM_BIN" "$ERR_OUT" "$GOPATH/bin/helm" "$GOPATH/bin/tiller"
1242 exit 1
1243 fi
1244 rm -rf "$INSTALL_HELM_BIN" "$ERR_OUT"
David Bainbridged18f4942020-04-14 16:46:13 -07001245 espin - "$VERIFIED"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001246 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001247fi
David Bainbridgee87067b2019-08-12 22:00:12 +00001248if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001249 NOW="$(date +%s)"
1250 printtime $((NOW - STIME))
David Bainbridgee87067b2019-08-12 22:00:12 +00001251fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001252
David Bainbridged18f4942020-04-14 16:46:13 -07001253STIME="$(date +%s)"
Test Userb5712372019-07-03 21:52:17 +00001254bspin "Verify voltctl $HIGH_VOLTAGE"
David Bainbridged2811972019-12-14 01:14:09 +00001255VOK=0
1256VMESSAGE="install"
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001257ERR_OUT=$(mktemp)
David K. Bainbridgeebf38d92020-02-10 10:46:31 -08001258export VC_VERSION="$VOLTCTL_VERSION"
1259if [ "$VC_VERSION" == "latest" ]; then
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001260 set -o pipefail # TODO: would be nice to run all in pipefail mode
1261 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')"
1262 RESULT=$?
1263 set +o pipefail
1264 if [ "$RESULT" -ne 0 ]; then
1265 espin - "$THEX"
1266 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR: unable to determine released version of voltctl: $(cat "$ERR_OUT")${NORMAL}"
1267 rm -rf "$ERR_OUT" "$GOPATH/bin/voltctl"
1268 exit 1
1269 fi
1270 export VC_VERSION
David K. Bainbridgeebf38d92020-02-10 10:46:31 -08001271fi
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001272
David Bainbridged18f4942020-04-14 16:46:13 -07001273if [ -x "$GOPATH/bin/voltctl" ]; then
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001274 VHAVE="$("$GOPATH/bin/voltctl" version --clientonly -o json 2>/dev/null | jq -r .version)"
David Bainbridged18f4942020-04-14 16:46:13 -07001275 RESULT=$?
1276 if [ $RESULT -eq 0 ] && [ "$VHAVE" == "$VC_VERSION" ]; then
David Bainbridged2811972019-12-14 01:14:09 +00001277 VOK=1
David Bainbridged18f4942020-04-14 16:46:13 -07001278 espin "$VERIFIED"
David Bainbridge1ba64f12019-12-18 00:40:13 +00001279 else
David Bainbridged18f4942020-04-14 16:46:13 -07001280 VCHECK="$(echo -e "$VHAVE\n$VC_VERSION" | sort -V | head -1)"
David K. Bainbridgeebf38d92020-02-10 10:46:31 -08001281 if [ "$VCHECK" == "$VHAVE" ]; then
1282 VMESSAGE="upgrade"
1283 else
1284 VMESSAGE="downgrade"
1285 fi
David Bainbridged2811972019-12-14 01:14:09 +00001286 fi
1287fi
1288
David Bainbridged18f4942020-04-14 16:46:13 -07001289if [ "$VOK" -eq 0 ]; then
1290 espin "$NOT_VERIFIED"
David Bainbridged2811972019-12-14 01:14:09 +00001291 bspin - "Download and $VMESSAGE voltctl $DOWNLOAD"
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001292 (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
1293 RESULT=$?
1294 if [ $RESULT -ne 0 ]; then
1295 espin - "$THEX"
1296 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR: unable to download voltctl (version $VC_VERSION): $(cat "$ERR_OUT")${NORMAL}"
1297 rm -rf "$ERR_OUT" "$GOPATH/bin/voltctl"
1298 exit 1
1299 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001300 (set -x; chmod 755 "$GOPATH/bin/voltctl" >>"$LOG" 2>&1) >>"$LOG" 2>&1
1301 espin - "$VERIFIED"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001302fi
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001303rm -rf "$ERR_OUT"
David Bainbridgee87067b2019-08-12 22:00:12 +00001304if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001305 NOW="$(date +%s)"
1306 printtime $((NOW - STIME))
David Bainbridgee87067b2019-08-12 22:00:12 +00001307fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001308
1309bspin "Verify command PATH"
Test Userba1e7e72019-07-10 22:27:54 +00001310export PATH=$GOPATH/bin:$PATH
David Bainbridged18f4942020-04-14 16:46:13 -07001311espin "$VERIFIED"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001312
David Bainbridged18f4942020-04-14 16:46:13 -07001313STIME="$(date +%s)"
Test Userba1e7e72019-07-10 22:27:54 +00001314if [ "$DEPLOY_K8S" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001315 HAVE="$(kind get clusters | grep -c "voltha-$NAME")"
Test Userba1e7e72019-07-10 22:27:54 +00001316 bspin "Verify Kubernetes/Kind Cluster"
1317 sspin
David Bainbridged18f4942020-04-14 16:46:13 -07001318 if [ "$HAVE" -eq 0 ]; then
1319 espin "$NOT_VERIFIED"
David Bainbridge491b1bd2019-07-11 17:53:11 +00001320 bspin - "Verify cluster configuration"
David Bainbridged18f4942020-04-14 16:46:13 -07001321 if [ ! -r "./$NAME-cluster.cfg" ]; then
1322 espin - "$NOT_VERIFIED"
David K. Bainbridge43422402020-03-06 07:41:22 -08001323 bspin - "Download cluster configuration: $TYPE-cluster.cfg to $NAME-cluster.cfg $DOWNLOAD"
David Bainbridged18f4942020-04-14 16:46:13 -07001324 ERR_OUT="$(mktemp)"
serkant.uluderya4d315132020-04-15 16:25:54 -07001325 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 -07001326 espin - "$THEX"
1327 echo -e "${RED}${BOLD}${ERROR}ERROR: $NAME-cluster.cfg${NORMAL}${RED} - $(cat "$ERR_OUT")${NORMAL}"
1328 echo "ERROR: $(cat "$ERR_OUT")" >>"$LOG"
1329 rm -rf "$ERR_OUT" "./$NAME-cluster.cfg"
David K. Bainbridgea00736b2020-01-08 14:33:17 -08001330 exit 1
1331 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001332 rm -rf "$ERR_OUT"
David K. Bainbridgea00736b2020-01-08 14:33:17 -08001333 else
David Bainbridged18f4942020-04-14 16:46:13 -07001334 espin - "$VERIFIED"
David K. Bainbridgea00736b2020-01-08 14:33:17 -08001335 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001336 kind create cluster --name "voltha-$NAME" --config "$NAME-cluster.cfg"
David Bainbridge491b1bd2019-07-11 17:53:11 +00001337 else
David Bainbridged18f4942020-04-14 16:46:13 -07001338 espin "$VERIFIED"
Test Userba1e7e72019-07-10 22:27:54 +00001339 fi
1340
David Bainbridged18f4942020-04-14 16:46:13 -07001341 KUBECONFIG="$(kind get kubeconfig-path --name="voltha-$NAME")"; export KUBECONFIG
Test Userba1e7e72019-07-10 22:27:54 +00001342 P="coredns-.* \
David Bainbridge0774b232019-08-02 06:37:19 +00001343 etcd-voltha-$NAME-control-plane \
Test Userba1e7e72019-07-10 22:27:54 +00001344 kindnet-.* \
David Bainbridge0774b232019-08-02 06:37:19 +00001345 kube-apiserver-voltha-$NAME-control-plane \
1346 kube-controller-manager-voltha-$NAME-control-plane \
Test Userba1e7e72019-07-10 22:27:54 +00001347 kube-proxy-.* \
David Bainbridge0774b232019-08-02 06:37:19 +00001348 kube-scheduler-voltha-$NAME-control-plane"
Test Userba1e7e72019-07-10 22:27:54 +00001349
David Bainbridged18f4942020-04-14 16:46:13 -07001350 EXPECT="$(test "$TYPE" == "minimal" && echo "12" || echo "14")"
1351 wait_for_pods - "kube-system" "$EXPECT" "includes" "Waiting for system PODs to start" "$NO_LABEL" "$P"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001352fi
David Bainbridgee87067b2019-08-12 22:00:12 +00001353if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001354 NOW="$(date +%s)"
1355 printtime $((NOW - STIME))
David Bainbridgee87067b2019-08-12 22:00:12 +00001356fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001357
David Bainbridged18f4942020-04-14 16:46:13 -07001358STIME="$(date +%s)"
1359COUNT="$(count_pods "kube-system" ":Running:" "$NO_LABEL" "tiller-deploy-.*")"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001360bspin "Verify Helm"
David Bainbridged18f4942020-04-14 16:46:13 -07001361if [ "$COUNT" -ne 1 ]; then
1362 espin "$NOT_VERIFIED"
Test Userb5712372019-07-03 21:52:17 +00001363 echo -e "Configuring Helm $GEAR"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001364 if [ "$INSTALL_HELM" == "no" ]; then
1365 bspin - "Skip Helm/Tiller Initialization"
1366 espin - $NO_ENTRY
1367 else
1368 bspin - "Initialize Helm"
David Bainbridged18f4942020-04-14 16:46:13 -07001369 (set -x; helm init --upgrade >>"$LOG" 2>&1) >>"$LOG" 2>&1
1370 espin - "$VERIFIED"
1371 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 -07001372 fi
Test Userb5712372019-07-03 21:52:17 +00001373 bspin - "Add Google Incubator repository to Helm"
David Bainbridged18f4942020-04-14 16:46:13 -07001374 (set -x; helm repo add incubator https://kubernetes-charts-incubator.storage.googleapis.com >>"$LOG" 2>&1) >>"$LOG" 2>&1
1375 espin - "$VERIFIED"
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001376
Test Userba1e7e72019-07-10 22:27:54 +00001377 # HACK (sort-of) - the config for tiller is about to be patched, which will
1378 # cause the tiller pod to be recreated. This can sometimes cause a timing
1379 # issue with the "wait_for_pods" call on tiller as it may incorrectly
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001380 # identify the running/ready tiller pod that is soon to be terminated as
Test Userba1e7e72019-07-10 22:27:54 +00001381 # what it is waiting for. To avoid this issue we do a clean scale down and
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001382 # scale up of the pod so the script controlls when it should be expecting
Test Userba1e7e72019-07-10 22:27:54 +00001383 # things
David Bainbridged18f4942020-04-14 16:46:13 -07001384 (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 -07001385
Test Userb5712372019-07-03 21:52:17 +00001386 bspin - "Add Google Stable repository to Helm"
David Bainbridged18f4942020-04-14 16:46:13 -07001387 (set -x; helm repo add stable https://kubernetes-charts.storage.googleapis.com >>"$LOG" 2>&1) >>"$LOG" 2>&1
1388 espin - "$VERIFIED"
David Bainbridge60ffc0f2020-04-27 22:13:22 -07001389 bspin - "Add ONF VOLTHA repository to Helm"
David Bainbridged18f4942020-04-14 16:46:13 -07001390 (set -x; helm repo add onf https://charts.opencord.org >>"$LOG" 2>&1) >>"$LOG" 2>&1
1391 espin - "$VERIFIED"
David Bainbridge60ffc0f2020-04-27 22:13:22 -07001392 bspin - "Add ONF ONOS repository to Helm"
1393 (set -x; helm repo add onos https://charts.onosproject.org >>"$LOG" 2>&1) >>"$LOG" 2>&1
1394 espin - "$VERIFIED"
1395 bspin - "Add ONF Atomix repository to Helm"
1396 (set -x; helm repo add atomix https://charts.atomix.io >>"$LOG" 2>&1) >>"$LOG" 2>&1
1397 espin - "$VERIFIED"
David Bainbridge309099c2020-05-05 08:47:29 -07001398 bspin - "Add Custom BBSIM SADIS Server repository to Helm"
1399 (set -x; helm repo add bbsim-sadis https://ciena.github.io/bbsim-sadis-server/charts >>"$LOG" 2>&1) >>"$LOG" 2>&1
1400 espin - "$VERIFIED"
Test Userb5712372019-07-03 21:52:17 +00001401 bspin - "Update Helm repository cache"
David Bainbridged18f4942020-04-14 16:46:13 -07001402 (set -x; helm repo update >>"$LOG" 2>&1) >>"$LOG" 2>&1
1403 espin - "$VERIFIED"
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001404
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001405 # Create and k8s service account so that Helm can create pods
Test Userb5712372019-07-03 21:52:17 +00001406 bspin - "Create Tiller ServiceAccount"
David Bainbridged18f4942020-04-14 16:46:13 -07001407 (set -x; kubectl create serviceaccount --namespace kube-system tiller >>"$LOG" 2>&1) >>"$LOG" 2>&1
1408 espin - "$VERIFIED"
Test Userb5712372019-07-03 21:52:17 +00001409 bspin - "Create Tiller ClusterRoleBinding"
David Bainbridged18f4942020-04-14 16:46:13 -07001410 (set -x; kubectl create clusterrolebinding tiller-cluster-rule --clusterrole=cluster-admin --serviceaccount=kube-system:tiller >>"$LOG" 2>&1) >>"$LOG" 2>&1
1411 espin - "$VERIFIED"
Test Userb5712372019-07-03 21:52:17 +00001412 bspin - "Update Tiller Manifest"
David Bainbridged18f4942020-04-14 16:46:13 -07001413 (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 +00001414
1415 # HACK (sort-of) - part to, spin it back up
David Bainbridged18f4942020-04-14 16:46:13 -07001416 (set -x; kubectl -n kube-system scale deploy tiller-deploy --replicas=1 >>"$LOG" 2>&1) >>"$LOG" 2>&1
1417 espin - "$VERIFIED"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001418else
David Bainbridged18f4942020-04-14 16:46:13 -07001419 if [ "$(helm version -s --template '{{.Server.SemVer}}')" != "$HELM_VERSION" ]; then
1420 espin "$NOT_VERIFIED"
David Bainbridgea34993d2020-04-01 09:15:42 -07001421 bspin - "Sync Tiller server version with helm client"
David Bainbridged18f4942020-04-14 16:46:13 -07001422 (set -x; helm init --upgrade --force-upgrade --wait >>"$LOG" 2>&1) >>"$LOG" 2>&1
1423 espin - "$VERIFIED"
David Bainbridgea34993d2020-04-01 09:15:42 -07001424 else
David Bainbridged18f4942020-04-14 16:46:13 -07001425 espin "$VERIFIED"
David Bainbridgea34993d2020-04-01 09:15:42 -07001426 fi
1427
David Bainbridge46505fb2019-10-01 21:13:20 +00001428 if [ "$UPDATE_HELM_REPOS" == "yes" ]; then
1429 bspin - "Update Helm repository cache"
David Bainbridged18f4942020-04-14 16:46:13 -07001430 (set -x; helm repo update >>"$LOG" 2>&1) >>"$LOG" 2>&1
1431 espin - "$VERIFIED"
David Bainbridge46505fb2019-10-01 21:13:20 +00001432 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001433fi
David Bainbridged18f4942020-04-14 16:46:13 -07001434wait_for_pods - "kube-system" 1 "includes" "Waiting for Tiller POD to start" "$NO_LABEL" "tiller-deploy-.*"
David Bainbridgee87067b2019-08-12 22:00:12 +00001435if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001436 NOW="$(date +%s)"
1437 printtime $((NOW - STIME))
David Bainbridgee87067b2019-08-12 22:00:12 +00001438fi
David Bainbridgecf546362020-04-21 23:18:50 -07001439# Resolve chart versions and log them for debug/support
1440RESOLVED_VOLTHA_CHART_VERSION=$(resolve_chart_version "$VOLTHA_CHART" "$VOLTHA_CHART_VERSION")
1441RESOLVED_VOLTHA_BBSIM_CHART_VERSION=$(resolve_chart_version "$VOLTHA_BBSIM_CHART" "$VOLTHA_BBSIM_CHART_VERSION")
1442RESOLVED_VOLTHA_ADAPTER_SIM_CHART_VERSION=$(resolve_chart_version "$VOLTHA_ADAPTER_SIM_CHART" "$VOLTHA_ADAPTER_SIM_CHART_VERSION")
1443RESOLVED_VOLTHA_ADAPTER_OPEN_OLT_CHART_VERSION=$(resolve_chart_version "$VOLTHA_ADAPTER_OPEN_OLT_CHART" "$VOLTHA_ADAPTER_OPEN_OLT_CHART_VERSION")
1444RESOLVED_VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION=$(resolve_chart_version "$VOLTHA_ADAPTER_OPEN_ONU_CHART" "$VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION")
1445RESOLVED_ONOS_CHART_VERSION=$(resolve_chart_version "$ONOS_CHART" "$ONOS_CHART_VERSION")
David Bainbridge60ffc0f2020-04-27 22:13:22 -07001446RESOLVED_ONOS_CLASSIC_CHART_VERSION=$(resolve_chart_version "$ONOS_CLASSIC_CHART" "$ONOS_CLASSIC_CHART_VERSION")
David Bainbridgecf546362020-04-21 23:18:50 -07001447RESOLVED_KAFKA_CHART_VERSION=$(resolve_chart_version "$KAFKA_CHART" "$KAFKA_CHART_VERSION")
1448cat <<EOV >>"$LOG"
1449Resolved helm charts and versions:
1450 $VOLTHA_CHART:$RESOLVED_VOLTHA_CHART_VERSION
1451 $VOLTHA_BBSIM_CHART:$RESOLVED_VOLTHA_BBSIM_CHART_VERSION
1452 $VOLTHA_ADAPTER_SIM_CHART:$RESOLVED_VOLTHA_ADAPTER_SIM_CHART_VERSION
1453 $VOLTHA_ADAPTER_OPEN_OLT_CHART:$RESOLVED_VOLTHA_ADAPTER_OPEN_OLT_CHART_VERSION
1454 $VOLTHA_ADAPTER_OPEN_ONU_CHART:$RESOLVED_VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION
1455 $ONOS_CHART:$RESOLVED_ONOS_CHART_VERSION
David Bainbridge60ffc0f2020-04-27 22:13:22 -07001456 $ONOS_CLASSIC_CHART:$RESOLVED_ONOS_CLASSIC_CHART_VERSION
David Bainbridgecf546362020-04-21 23:18:50 -07001457 $KAFKA_CHART:$RESOLVED_KAFKA_CHART_VERSION
1458EOV
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001459
David Bainbridged18f4942020-04-14 16:46:13 -07001460STIME="$(date +%s)"
David Bainbridge0774b232019-08-02 06:37:19 +00001461bspin "Verify Helm values file: $NAME-values.yaml"
1462if [ ! -r "./$NAME-values.yaml" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001463 espin "$NOT_VERIFIED"
David Bainbridge0774b232019-08-02 06:37:19 +00001464 bspin - "Download Helm values file: $TYPE-values.yaml to $NAME-values.yaml $DOWNLOAD"
David Bainbridged18f4942020-04-14 16:46:13 -07001465 ERR_OUT="$(mktemp)"
serkant.uluderya4d315132020-04-15 16:25:54 -07001466 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 -07001467 espin - "$THEX"
1468 echo -e "${RED}${BOLD}${ERROR}ERROR: $NAME-values.yaml${NORMAL}${RED} - $(cat "$ERR_OUT")${NORMAL}"
1469 echo "ERROR: $(cat "$ERR_OUT")" >>"$LOG"
1470 rm -rf "$ERR_OUT" "./$NAME-values.yaml"
David K. Bainbridgea00736b2020-01-08 14:33:17 -08001471 exit 1
1472 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001473 rm -rf "$ERR_OUT"
1474 espin - "$VERIFIED"
Test Userba1e7e72019-07-10 22:27:54 +00001475else
David Bainbridged18f4942020-04-14 16:46:13 -07001476 espin "$VERIFIED"
Test Userba1e7e72019-07-10 22:27:54 +00001477fi
David Bainbridgee87067b2019-08-12 22:00:12 +00001478if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001479 NOW="$(date +%s)"
1480 printtime $((NOW - STIME))
David Bainbridgee87067b2019-08-12 22:00:12 +00001481fi
Test Userba1e7e72019-07-10 22:27:54 +00001482
David Bainbridged18f4942020-04-14 16:46:13 -07001483STIME="$(date +%s)"
David Bainbridge99ac7a22019-08-31 02:26:43 +00001484bspin "Verify or download chart specific values files $DOWNLOAD"
1485VALUES_FILES="monkey-values.yaml"
David Bainbridged18f4942020-04-14 16:46:13 -07001486ERR_OUT="$(mktemp)"
David Bainbridge99ac7a22019-08-31 02:26:43 +00001487for i in $VALUES_FILES; do
1488 if [ ! -r ./$i ]; then
serkant.uluderya4d315132020-04-15 16:25:54 -07001489 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 -07001490 espin "$THEX"
1491 echo -e "${RED}${BOLD}${ERROR}ERROR: $i${NORMAL}${RED} - $(cat "$ERR_OUT")${NORMAL}"
1492 echo "ERROR: $i - $(cat "$ERR_OUT")" >>"$LOG"
1493 rm -rf "$ERR_OUT" "./$i"
David K. Bainbridgea00736b2020-01-08 14:33:17 -08001494 exit 1
1495 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001496 rm -rf "$ERR_OUT"
David Bainbridge99ac7a22019-08-31 02:26:43 +00001497 fi
1498done
David Bainbridged18f4942020-04-14 16:46:13 -07001499rm -rf "$ERR_OUT"
1500espin "$VERIFIED"
David Bainbridge99ac7a22019-08-31 02:26:43 +00001501if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001502 NOW="$(date +%s)"
1503 printtime $((NOW - STIME))
David Bainbridge99ac7a22019-08-31 02:26:43 +00001504fi
1505
1506if [ "$WITH_CHAOS" == "yes" ]; then
1507 bspin "Verify or clone kube-monkey helm chart $DOWNLOAD"
1508 if [ -r ./kube-monkey ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001509 espin "$VERIFIED"
David Bainbridge99ac7a22019-08-31 02:26:43 +00001510 else
David Bainbridged18f4942020-04-14 16:46:13 -07001511 espin "$NOT_VERIFIED"
David Bainbridge99ac7a22019-08-31 02:26:43 +00001512 bspin - "GIT clone kube-monkey"
David Bainbridged18f4942020-04-14 16:46:13 -07001513 (set -x; git clone https://github.com/asobti/kube-monkey kube-monkey >>"$LOG" 2>&1) >>"$LOG" 2>&1
1514 espin - "$VERIFIED"
David Bainbridge99ac7a22019-08-31 02:26:43 +00001515 fi
1516fi
1517
Test Userba1e7e72019-07-10 22:27:54 +00001518if [ "$JUST_K8S" == "yes" ]; then
1519 echo "Environment deployed, not deploying VOLTHA artifacts as requested. Good bye."
1520 echo ""
David Bainbridged18f4942020-04-14 16:46:13 -07001521 echo "Please issue the following commands in your terminal to ensure that you" | tee -a "$LOG"
1522 echo "are accessing the correct Kubernetes/Kind cluster as well as have the " | tee -a "$LOG"
1523 echo "tools required by VOLTHA in your command path. " | tee -a "$LOG"
1524 echo "" | tee -a "$LOG"
1525 echo -en "$BOLD"
1526 if [ "$DEPLOY_K8S" == "yes" ]; then
1527 echo "export KUBECONFIG=\"\$(./bin/kind get kubeconfig-path --name=\"voltha-$NAME\")\"" | tee -a "$LOG"
Test Userba1e7e72019-07-10 22:27:54 +00001528 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001529 echo "export PATH=$GOPATH/bin:\$PATH" | tee -a "$LOG"
1530 echo -en "$NORMAL"
1531 echo "" | tee -a "$LOG"
1532 echo "Thank you for choosing kind-voltha for you quick cluster needs." | tee -a "$LOG"
Test Userba1e7e72019-07-10 22:27:54 +00001533 exit 0
1534fi
1535
David Bainbridged18f4942020-04-14 16:46:13 -07001536if [ "$WITH_ETCD" != "yes" ] && [ "$WITH_ETCD" != "external" ]; then
David Bainbridge696bc632020-04-05 21:49:37 -07001537 bspin "Skip ETCD Operator Deployment"
1538 espin $NO_ENTRY
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001539else
David Bainbridged18f4942020-04-14 16:46:13 -07001540 STIME="$(date +%s)"
David Bainbridge76afd812020-04-06 09:53:52 -07001541 NS=$VOLTHA_NS
David Bainbridged18f4942020-04-14 16:46:13 -07001542 if [ "$WITH_ETCD" == "external" ]; then
David Bainbridge76afd812020-04-06 09:53:52 -07001543 NS=$INFRA_NS
1544 fi
David Bainbridge696bc632020-04-05 21:49:37 -07001545 bspin "Verify ETCD Operator $OLD_KEY"
David Bainbridged18f4942020-04-14 16:46:13 -07001546 if [ "$HELM_USE_UPGRADE" == "yes" ] || [ "$(helm list --deployed --short --namespace "$NS" "^etcd-operator\$" | wc -l)" -ne 1 ]; then
1547 espin "$NOT_VERIFIED"
1548 helm_install - "$NS" etcd-operator stable/etcd-operator latest "$_HELM_DESC ETCD Operator"
David Bainbridge696bc632020-04-05 21:49:37 -07001549 else
David Bainbridged18f4942020-04-14 16:46:13 -07001550 espin "$VERIFIED"
David Bainbridge696bc632020-04-05 21:49:37 -07001551 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001552 EXPECT="$(test "$TYPE" == "minimal" && echo "1" || echo "3")"
1553 wait_for_pods - "$NS" "$EXPECT" "includes" "Waiting for ETCD Operator to start" "$NO_LABEL" "etcd-operator-.*"
David Bainbridge696bc632020-04-05 21:49:37 -07001554 if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001555 NOW="$(date +%s)"
1556 printtime $((NOW - STIME))
David Bainbridge696bc632020-04-05 21:49:37 -07001557 fi
David Bainbridgee87067b2019-08-12 22:00:12 +00001558fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001559
David Bainbridged18f4942020-04-14 16:46:13 -07001560STIME="$(date +%s)"
David Bainbridge60ffc0f2020-04-27 22:13:22 -07001561if is_in "$WITH_ONOS" "yes,legacy,classic"; then
1562 if is_in "$WITH_ONOS" "legacy"; then
1563 bspin "Verify ONOS LEGACY installed $BIRD"
1564 if [ "$HELM_USE_UPGRADE" == "yes" ] || [ "$(helm list --deployed --short --namespace "$INFRA_NS" "^onos\$" | wc -l)" -ne 1 ]; then
1565 espin "$NOT_VERIFIED"
1566 INTERNAL_EXTRA_HELM_INSTALL_ARGS="$SET_TAG $EXTRA_HELM_FLAGS" helm_install - "$INFRA_NS" onos "$ONOS_CHART" "$ONOS_CHART_VERSION" "$_HELM_DESC ONOS LEGACY"
1567 INTERNAL_EXTRA_HELM_INSTALL_ARGS=
1568 else
1569 espin "$VERIFIED"
1570 fi
1571 wait_for_pods - "$INFRA_NS" 1 "includes" "Waiting for ONOS to start" "$NO_LABEL" "onos-.*"
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001572
David Bainbridge60ffc0f2020-04-27 22:13:22 -07001573 if [ "$WITH_PORT_FORWARDS" == "yes" ]; then
1574 bspin - "Forward ONOS API port $FORWARD"
1575 kill_port_forward onos-ui
1576 port_forward "$INFRA_NS" onos-ui "$ONOS_API_PORT:8181"
1577 espin - "$VERIFIED"
1578 bspin - "Forward ONOS SSH port $FORWARD"
1579 kill_port_forward onos-ssh
1580 port_forward "$INFRA_NS" onos-ssh "$ONOS_SSH_PORT:8101"
1581 espin - "$VERIFIED"
1582 _ONOS_API_EP="127.0.0.1:$ONOS_API_PORT"
1583 else
1584 _ONOS_API_EP="$(get_service_ep "$INFRA_NS" onos-ui)"
1585 fi
1586 elif is_in "$WITH_ONOS" "yes,classic"; then
1587 bspin "Verify ONOS CLASSIC 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 # ONOS CLASSIC identifies its image repo/tag differently, so yq is used to grab the values from the
1591 # values value
David Bainbridgefad50732020-05-01 17:00:12 -07001592 YAML_VALUES=$(INTERNAL_EXTRA_HELM_INSTALL_ARGS="--set replicas=$NUM_OF_ONOS --set atomix.replicas=$NUM_OF_ATOMIX" \
1593 helm_values "$INFRA_NS" onos "$ONOS_CLASSIC_CHART" "$ONOS_CLASSIC_CHART_VERSION")
1594 _ONOS_REPO="$(echo "$YAML_VALUES" | yq read - images.onos.repository)"
1595 _ONOS_TAG="$(echo "$YAML_VALUES" | yq read - images.onos.tag)"
1596 _TAG_DEFAULT="$(echo "$YAML_VALUES" | yq read - defaults.image_tag)"
David Bainbridge60ffc0f2020-04-27 22:13:22 -07001597 if [ -z "$_ONOS_TAG" ]; then
1598 _ONOS_TAG="$_TAG_DEFAULT"
1599 fi
David Bainbridgefad50732020-05-01 17:00:12 -07001600
David Bainbridge60ffc0f2020-04-27 22:13:22 -07001601 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" \
1602 helm_install - "$INFRA_NS" onos "$ONOS_CLASSIC_CHART" "$ONOS_CLASSIC_CHART_VERSION" "$_HELM_DESC ONOS CLASSIC"
1603 INTERNAL_EXTRA_HELM_INSTALL_ARGS=
1604 else
1605 espin "$VERIFIED"
1606 fi
1607 wait_for_pods - "$INFRA_NS" $((NUM_OF_ONOS + NUM_OF_ATOMIX)) "includes" "Waiting for ONOS CLASSIC to start" "$NO_LABEL" "onos-.*"
1608 if [ "$WITH_PORT_FORWARDS" == "yes" ]; then
1609 bspin - "Forward ONOS API port $FORWARD"
1610 kill_port_forward onos-onos-classic-hs
1611 port_forward "$INFRA_NS" onos-onos-classic-hs "$ONOS_API_PORT:8181" "$ONOS_SSH_PORT:8101"
1612 espin - "$VERIFIED"
1613 _ONOS_API_EP="127.0.0.1:$ONOS_API_PORT"
1614 else
1615 _ONOS_API_EP="$(get_service_ep "$INFRA_NS" onos-onos-classic-hs)"
1616 fi
1617 elif [ "$WITH_ONOS" == "micro" ]; then
1618 bspin "Verify micro-ONOS installed $BIRD"
1619 # We should never get here
1620 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} Micro ONOS not currently supported${NORMAL}"
1621 exit 1
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -08001622 fi
David Bainbridged31d6122019-08-13 19:37:59 +00001623 bspin - "Verify or download ONOS configuration support files $DOWNLOAD"
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001624 ONOS_FILES="olt-onos-enableExtraneousRules.json onos-aaa.json \
David Bainbridge696bc632020-04-05 21:49:37 -07001625 onos-dhcpl2relay.json onos-sadis-sample.json"
David Bainbridged18f4942020-04-14 16:46:13 -07001626 (set -x; mkdir -p ./onos-files >>"$LOG" 2>&1) >>"$LOG" 2>&1
1627 ERR_OUT="$(mktemp)"
David Bainbridge2b19e832019-08-16 02:40:53 +00001628 for i in $ONOS_FILES; do
David Bainbridged18f4942020-04-14 16:46:13 -07001629 if [ ! -r "./onos-files/$i" ]; then
serkant.uluderya4d315132020-04-15 16:25:54 -07001630 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 -07001631 espin - "$THEX"
1632 echo -e "${RED}${BOLD}${ERROR}ERROR: $i${NORMAL}${RED} - $(cat "$ERR_OUT")${NORMAL}"
1633 echo "ERROR: $(cat "$ERR_OUT")" >>"$LOG"
1634 rm -rf "$ERR_OUT" "./onos-files/$i"
David K. Bainbridgea00736b2020-01-08 14:33:17 -08001635 exit 1
1636 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001637 rm -rf "$ERR_OUT"
David Bainbridged31d6122019-08-13 19:37:59 +00001638 fi
1639 done
David Bainbridged18f4942020-04-14 16:46:13 -07001640 rm -rf "$ERR_OUT"
1641 espin - "$VERIFIED"
David Bainbridge27790d62019-08-13 22:43:19 +00001642
David Bainbridged18f4942020-04-14 16:46:13 -07001643 if [ "$INSTALL_ONOS_APPS" == "yes" ]; then
David Bainbridge27790d62019-08-13 22:43:19 +00001644 bspin - "Installing custom ONOS applications"
David Bainbridged18f4942020-04-14 16:46:13 -07001645 if [ -x onos-files/onos-apps ] && [ "$(find onos-files/onos-apps -name "*.oar" 2>/dev/null | wc -l)" -gt 0 ]; then
1646 for OAR in onos-files/onos-apps/*.oar; do
David Bainbridge27790d62019-08-13 22:43:19 +00001647 sspin - "Installing custom ONOS applications - $OAR$CEOL"
David Bainbridged18f4942020-04-14 16:46:13 -07001648 override_onos_app "$OAR"
David Bainbridge27790d62019-08-13 22:43:19 +00001649 done
1650 espin - "$VERIFIED Installing custom ONOS applications$CEOL"
1651 else
1652 espin - "$NOT_VERIFIED Installing custom ONOS applications - None Found"
1653 fi
1654 fi
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001655
David Bainbridged18f4942020-04-14 16:46:13 -07001656 if [ "$WITH_KAFKA" != "no" ]; then
David Bainbridge837e8bd2020-04-06 13:17:14 -07001657 check_onos_app_active org.opencord.kafka
David Bainbridge76afd812020-04-06 09:53:52 -07001658 _HOST=voltha-kafka.$INFRA_NS.svc.cluster.local
David Bainbridge837e8bd2020-04-06 13:17:14 -07001659 _PORT=9092
David Bainbridged18f4942020-04-14 16:46:13 -07001660 if [ "$WITH_KAFKA" == "yes" ]; then
David Bainbridge76afd812020-04-06 09:53:52 -07001661 _HOST=voltha-kafka.$VOLTHA_NS.svc.cluster.local
1662 _PORT=9092
David Bainbridged18f4942020-04-14 16:46:13 -07001663 elif [ "$WITH_KAFKA" == "external" ]; then
David Bainbridge76afd812020-04-06 09:53:52 -07001664 _HOST=kafka.$INFRA_NS.svc.cluster.local
1665 _PORT=9092
1666 else
David Bainbridged18f4942020-04-14 16:46:13 -07001667 _HOST="$(echo "$WITH_KAFKA" | cut -d: -f1)"
1668 _PORT="$(echo "$WITH_KAFKA" | cut -s -d: -f2)"
David Bainbridge837e8bd2020-04-06 13:17:14 -07001669 _PORT=${_PORT:-9092}
1670 fi
1671 push_onos_config "json" "Push ONOS Kafka Configuration" "network/configuration/apps/org.opencord.kafka" \
David Bainbridged18f4942020-04-14 16:46:13 -07001672 "$(cat <<EOJ | tr -d '[:space:]'
David Bainbridge696bc632020-04-05 21:49:37 -07001673{
1674 "kafka": {
1675 "bootstrapServers": "$_HOST:$_PORT"
1676 }
1677}
1678EOJ
David Bainbridged18f4942020-04-14 16:46:13 -07001679)"
David Bainbridge837e8bd2020-04-06 13:17:14 -07001680 fi
Matteo Scandolo9a77a732020-01-09 14:24:12 -08001681 check_onos_app_active org.opencord.dhcpl2relay
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001682 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 -08001683 check_onos_app_active org.opencord.olt
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001684 # FIXME use WITH_DHCP and WITH_EAPOL flags to configre OLT App
Hardik Windlassa7501fb2020-02-17 14:28:20 +00001685 # Default value for "enableEapol" is true in OLT App
David Bainbridged18f4942020-04-14 16:46:13 -07001686 if [ "$WITH_EAPOL" == "yes" ]; then
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001687 push_onos_config "json" "Enable VOLTHA ONOS EAPOL provisioning" "configuration/org.opencord.olt.impl.OltFlowService" '{"enableEapol":true}'
David Bainbridged18f4942020-04-14 16:46:13 -07001688 elif [ "$WITH_EAPOL" == "no" ]; then
Hardik Windlassa7501fb2020-02-17 14:28:20 +00001689 push_onos_config "json" "Disable VOLTHA ONOS EAPOL provisioning" "configuration/org.opencord.olt.impl.OltFlowService" '{"enableEapol":false}'
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001690 fi
Hardik Windlassa7501fb2020-02-17 14:28:20 +00001691 # Default value for "enableDhcpOnProvisioning" is false and for "enableDhcpV4" is true in OLT App
David Bainbridged18f4942020-04-14 16:46:13 -07001692 if [ "$WITH_DHCP" == "yes" ]; then
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001693 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 -07001694 elif [ "$WITH_DHCP" == "no" ]; then
Hardik Windlassa7501fb2020-02-17 14:28:20 +00001695 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 -08001696 fi
Hardik Windlassa7501fb2020-02-17 14:28:20 +00001697 # Default value for "enableIgmpOnProvisioning" is false in OLT App
David Bainbridged18f4942020-04-14 16:46:13 -07001698 if [ "$WITH_IGMP" == "yes" ]; then
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001699 push_onos_config "json" "Enable VOLTHA ONOS IGMP provisioning" "configuration/org.opencord.olt.impl.OltFlowService" '{"enableIgmpOnProvisioning":true}'
David Bainbridged18f4942020-04-14 16:46:13 -07001700 elif [ "$WITH_IGMP" == "no" ]; then
Hardik Windlassa7501fb2020-02-17 14:28:20 +00001701 push_onos_config "json" "Disable VOLTHA ONOS IGMP provisioning" "configuration/org.opencord.olt.impl.OltFlowService" '{"enableIgmpOnProvisioning":false}'
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001702 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001703 if [ "$ENABLE_ONOS_EXTRANEOUS_RULES" == "yes" ]; then
David K. Bainbridge484d80c2020-03-05 21:44:34 -08001704 push_onos_config "file" "Enabling extraneous rules for ONOS" "configuration/org.onosproject.net.flow.impl.FlowRuleManager" "onos-files/olt-onos-enableExtraneousRules.json"
1705 fi
David Bainbridge60ffc0f2020-04-27 22:13:22 -07001706 if is_in "$CONFIG_SADIS" "yes,file"; then
Matteo Scandolo9a77a732020-01-09 14:24:12 -08001707 check_onos_app_active org.opencord.sadis
Hardik Windlassb3147602020-03-09 16:59:15 +05301708 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 -07001709 elif [ "$CONFIG_SADIS" == "bbsim" ]; then
1710 push_onos_config "json" \
1711 "[optional] Push ONOS configuration for BBSIM SADIS servers" \
1712 "network/configuration/apps/org.opencord.sadis" \
David Bainbridged18f4942020-04-14 16:46:13 -07001713 "$(cat <<EOJ | tr -d '[:space:]'
David K. Bainbridgeb859e912020-03-13 14:07:52 -07001714{
1715 "sadis": {
1716 "integration": {
David Bainbridge76afd812020-04-06 09:53:52 -07001717 "url": "http://bbsim.$BBSIM_NS.svc.cluster.local:50074/v2/subscribers/%s",
David K. Bainbridgeb859e912020-03-13 14:07:52 -07001718 "cache": {
1719 "enabled": true,
1720 "maxsize": 50,
1721 "ttl": "PT1m"
1722 }
1723 }
1724 },
1725 "bandwidthprofile": {
1726 "integration": {
David Bainbridge76afd812020-04-06 09:53:52 -07001727 "url": "http://bbsim.$BBSIM_NS.svc.cluster.local:50074/v2/bandwidthprofiles/%s",
David K. Bainbridgeb859e912020-03-13 14:07:52 -07001728 "cache": {
1729 "enabled": true,
1730 "maxsize": 50,
1731 "ttl": "PT1m"
1732 }
1733 }
1734 }
1735}
1736EOJ
David Bainbridged18f4942020-04-14 16:46:13 -07001737)"
David Bainbridge309099c2020-05-05 08:47:29 -07001738 elif [ "$CONFIG_SADIS" == "external" ]; then
1739 push_onos_config "json" \
1740 "[optional] Push ONOS configuration for custom SADIS and Bandwidth Profile servers" \
1741 "network/configuration/apps/org.opencord.sadis" \
1742 "$(cat <<EOJ | tr -d '[:space:]'
1743{
1744 "sadis": {
1745 "integration": {
1746 "url": "http://bbsim-sadis-server.$BBSIM_NS.svc:58080/subscribers/%s",
1747 "cache": {
1748 "enabled": true,
1749 "maxsize": 50,
1750 "ttl": "PT1m"
1751 }
1752 }
1753 },
1754 "bandwidthprofile": {
1755 "integration": {
1756 "url": "http://bbsim-sadis-server.$BBSIM_NS.svc:58080/profiles/%s",
1757 "cache": {
1758 "enabled": true,
1759 "maxsize": 50,
1760 "ttl": "PT1m"
1761 }
1762 }
1763 }
1764}
1765EOJ
1766)"
David K. Bainbridgeb859e912020-03-13 14:07:52 -07001767 elif [ "$CONFIG_SADIS" == "url" ]; then
1768 push_onos_config "json" \
1769 "[optional] Push ONOS configuration for custom SADIS and Bandwidth Profile servers" \
1770 "network/configuration/apps/org.opencord.sadis" \
David Bainbridged18f4942020-04-14 16:46:13 -07001771 "$(cat <<EOJ | tr -d '[:space:]'
David K. Bainbridgeb859e912020-03-13 14:07:52 -07001772{
1773 "sadis": {
1774 "integration": {
1775 "url": "$SADIS_SUBSCRIBERS",
1776 "cache": {
1777 "enabled": true,
1778 "maxsize": 50,
1779 "ttl": "PT1m"
1780 }
1781 }
1782 },
1783 "bandwidthprofile": {
1784 "integration": {
1785 "url": "$SADIS_BANDWIDTH_PROFILES",
1786 "cache": {
1787 "enabled": true,
1788 "maxsize": 50,
1789 "ttl": "PT1m"
1790 }
1791 }
1792 }
1793}
1794EOJ
David Bainbridged18f4942020-04-14 16:46:13 -07001795)"
David Bainbridge2b19e832019-08-16 02:40:53 +00001796 fi
Test Userba1e7e72019-07-10 22:27:54 +00001797fi
David Bainbridgee87067b2019-08-12 22:00:12 +00001798if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001799 NOW="$(date +%s)"
1800 printtime $((NOW - STIME))
David Bainbridgee87067b2019-08-12 22:00:12 +00001801fi
Test Userba1e7e72019-07-10 22:27:54 +00001802
David Bainbridged18f4942020-04-14 16:46:13 -07001803if [ "$WITH_ETCD" == "external" ]; then
1804 STIME="$(date +%s)"
David Bainbridge76afd812020-04-06 09:53:52 -07001805 bspin "Verify external ETCD cluster $OLD_KEY"
David Bainbridged18f4942020-04-14 16:46:13 -07001806 EXPECT="$(test "$TYPE" == "minimal" && echo "1" || echo "3")"
1807 if [ "$HELM_USE_UPGRADE" == "yes" ] || [ "$(helm list --deployed --short --namespace "$INFRA_NS" "^etcd-cluster\$" | wc -l)" -ne 1 ]; then
1808 espin "$NOT_VERIFIED"
David Bainbridge76afd812020-04-06 09:53:52 -07001809 INTERNAL_EXTRA_HELM_INSTALL_ARGS+="--set clusterName=etcd-cluster --set autoCompactionRetention=1 --set clusterSize=$EXPECT"
David Bainbridged18f4942020-04-14 16:46:13 -07001810 helm_install - "$INFRA_NS" etcd-cluster onf/voltha-etcd-cluster latest "$_HELM_DESC external ETCD cluster"
David Bainbridge76afd812020-04-06 09:53:52 -07001811 else
David Bainbridged18f4942020-04-14 16:46:13 -07001812 espin "$VERIFIED"
David Bainbridge76afd812020-04-06 09:53:52 -07001813 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001814 wait_for_pods - "$INFRA_NS" "$EXPECT" "includes" "Waiting for ETCD cluster to start" "$NO_LABEL" "etcd-cluster-.*"
David Bainbridge76afd812020-04-06 09:53:52 -07001815 if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001816 NOW="$(date +%s)"
1817 printtime $((NOW - STIME))
David Bainbridge76afd812020-04-06 09:53:52 -07001818 fi
1819fi
1820
David Bainbridged18f4942020-04-14 16:46:13 -07001821if [ "$WITH_KAFKA" == "external" ]; then
1822 _TMP="$(mktemp -u)"
1823 _COUNT="$(test "$TYPE" == "minimal" && echo "1" || echo "3")"
1824 cat << EOC > "$_TMP"
David Bainbridge76afd812020-04-06 09:53:52 -07001825configurationOverrides:
1826 "default.replication.factor": $_COUNT
1827 "offsets.topic.replication.factor": $_COUNT
1828 "log.retention.hours": 4
1829 "log.message.timestamp.type": "LogAppendTime"
1830persistence:
1831 enabled: false
1832zookeeper:
1833 replicaCount: 1
1834 persistence:
1835 enabled: false
1836replicas: $_COUNT
1837EOC
David Bainbridged18f4942020-04-14 16:46:13 -07001838 STIME="$(date +%s)"
David Bainbridge76afd812020-04-06 09:53:52 -07001839 bspin "Verify external Kafka cluster $OLD_KEY"
David Bainbridged18f4942020-04-14 16:46:13 -07001840 EXPECT="$(test "$TYPE" == "minimal" && echo "2" || echo "4")"
1841 if [ "$HELM_USE_UPGRADE" == "yes" ] || [ "$(helm list --deployed --short --namespace "$INFRA_NS" "^kafka\$" | wc -l)" -ne 1 ]; then
1842 espin "$NOT_VERIFIED"
David Bainbridge76afd812020-04-06 09:53:52 -07001843 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" -f $_TMP"
David Bainbridgecf546362020-04-21 23:18:50 -07001844 helm_install - "$INFRA_NS" kafka "$KAFKA_CHART" "$KAFKA_CHART_VERSION" "$_HELM_DESC external Kafka cluster"
David Bainbridge76afd812020-04-06 09:53:52 -07001845 else
David Bainbridged18f4942020-04-14 16:46:13 -07001846 espin "$VERIFIED"
David Bainbridge76afd812020-04-06 09:53:52 -07001847 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001848 wait_for_pods - "$INFRA_NS" "$EXPECT" "includes" "Waiting for Kafka cluster to start" "$NO_LABEL" "kafka-.*"
David Bainbridge76afd812020-04-06 09:53:52 -07001849 if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001850 NOW="$(date +%s)"
1851 printtime $((NOW - STIME))
David Bainbridge76afd812020-04-06 09:53:52 -07001852 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001853 rm -rf "$_TMP"
David Bainbridge76afd812020-04-06 09:53:52 -07001854fi
1855
David Bainbridged18f4942020-04-14 16:46:13 -07001856STIME="$(date +%s)"
David Bainbridge696bc632020-04-05 21:49:37 -07001857EXPECT=1
1858if [ "$ONLY_ONE" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001859 EXPECT="$((EXPECT+1))"
David Bainbridge696bc632020-04-05 21:49:37 -07001860 INTERNAL_EXTRA_HELM_INSTALL_ARGS="--set therecanbeonlyone=true"
1861else
David Bainbridged18f4942020-04-14 16:46:13 -07001862 EXPECT="$((EXPECT+2))"
David Bainbridge696bc632020-04-05 21:49:37 -07001863fi
Matteo Scandolo67335f02020-04-09 11:19:53 -07001864case $WITH_ETCD in
David Bainbridge76afd812020-04-06 09:53:52 -07001865 no)
1866 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set private_etcd_cluster=false"
1867 ;;
1868 yes)
1869 _HOST="voltha-etcd-cluster-client.$VOLTHA_NS.svc.cluster.local"
1870 _PORT=2379
1871 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set services.etcd.service=$_HOST --set services.etcd.port=$_PORT"
David Bainbridged18f4942020-04-14 16:46:13 -07001872 EXPECT="$((EXPECT+$(test "$TYPE" == "minimal" && echo "1" || echo "3")))"
David Bainbridge76afd812020-04-06 09:53:52 -07001873 ;;
1874 external)
1875 _HOST="etcd-cluster-client.$INFRA_NS.svc.cluster.local"
1876 _PORT=2379
1877 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set private_etcd_cluster=false --set services.etcd.service=$_HOST --set services.etcd.port=$_PORT"
1878 ;;
1879 *)
David Bainbridged18f4942020-04-14 16:46:13 -07001880 _HOST="$(echo "$WITH_ETCD" | cut -d: -f1)"
1881 _PORT="$(echo "$WITH_ETCD" | cut -s -d: -f2)"
David Bainbridge696bc632020-04-05 21:49:37 -07001882 _PORT=${_PORT:-2379}
David Bainbridge76afd812020-04-06 09:53:52 -07001883 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set private_etcd_cluster=false --set services.etcd.service=$_HOST --set services.etcd.port=$_PORT"
1884 ;;
1885esac
1886case $WITH_KAFKA in
1887 no)
1888 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set private_kafka_cluster=false"
1889 ;;
1890 yes)
1891 _HOST=voltha-kafka.$VOLTHA_NS.svc.cluster.local
1892 _PORT=9092
1893 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 -07001894 EXPECT="$((EXPECT+$(test "$TYPE" == "minimal" && echo "2" || echo "4")))"
David Bainbridge76afd812020-04-06 09:53:52 -07001895 ;;
1896 external)
1897 _HOST=kafka.$INFRA_NS.svc.cluster.local
1898 _PORT=9092
1899 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"
1900 ;;
1901 *)
David Bainbridged18f4942020-04-14 16:46:13 -07001902 _HOST="$(echo "$WITH_KAFKA" | cut -d: -f1)"
1903 _PORT="$(echo "$WITH_KAFKA" | cut -s -d: -f2)"
David Bainbridge696bc632020-04-05 21:49:37 -07001904 _PORT=${_PORT:-9092}
David Bainbridge76afd812020-04-06 09:53:52 -07001905 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"
1906 ;;
1907esac
1908
David Bainbridge60ffc0f2020-04-27 22:13:22 -07001909if is_in "$WITH_ONOS" "legacy"; then
David Bainbridge76afd812020-04-06 09:53:52 -07001910 _HOST=onos-openflow.$INFRA_NS.svc.cluster.local
1911 _PORT=6653
David Bainbridge60ffc0f2020-04-27 22:13:22 -07001912elif is_in "$WITH_ONOS" "yes,classic"; then
1913 _HOST=onos-onos-classic-hs.$INFRA_NS.svc.cluster.local
1914 _PORT=6653
David Bainbridged18f4942020-04-14 16:46:13 -07001915elif [ "$WITH_ONOS" != "no" ]; then
1916 _HOST="$(echo "$WITH_ONOS" | cut -d: -f1)"
1917 _PORT="$(echo "$WITH_ONOS" | cut -s -d: -f2)"
David Bainbridge76afd812020-04-06 09:53:52 -07001918 _PORT=${_PORT:-6653}
Jonathan Hart6a91e6c2020-04-16 14:28:33 -07001919fi
David Bainbridge60ffc0f2020-04-27 22:13:22 -07001920
David Bainbridgecf546362020-04-21 23:18:50 -07001921compare_versions "$RESOLVED_VOLTHA_CHART_VERSION" 2.4.2
Jonathan Hart6a91e6c2020-04-16 14:28:33 -07001922if [ "$?" == "1" ]; then
1923 # voltha chart > 2.4.2 uses list of controllers
1924 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set services.controller[0].service=$_HOST --set services.controller[0].port=$_PORT"
1925else
1926 # voltha chart <= 2.4.2 uses single controller
David Bainbridge76afd812020-04-06 09:53:52 -07001927 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set services.controller.service=$_HOST --set services.controller.port=$_PORT"
David Bainbridge696bc632020-04-05 21:49:37 -07001928fi
Jonathan Hart6a91e6c2020-04-16 14:28:33 -07001929
Test Userb5712372019-07-03 21:52:17 +00001930bspin "Verify VOLTHA installed $HIGH_VOLTAGE"
David Bainbridged18f4942020-04-14 16:46:13 -07001931if [ "$HELM_USE_UPGRADE" == "yes" ] || [ "$(helm list --deployed --short --namespace "$VOLTHA_NS" "^voltha\$" | wc -l)" -ne 1 ]; then
1932 espin "$NOT_VERIFIED"
1933 helm_install - "$VOLTHA_NS" voltha "$VOLTHA_CHART" "$VOLTHA_CHART_VERSION" "$_HELM_DESC VOLTHA Core"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001934else
David Bainbridged18f4942020-04-14 16:46:13 -07001935 espin "$VERIFIED"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001936fi
David Bainbridge696bc632020-04-05 21:49:37 -07001937INTERNAL_EXTRA_HELM_INSTALL_ARGS=
Test Userba1e7e72019-07-10 22:27:54 +00001938
David Bainbridge90fd8e32019-08-21 23:32:47 +00001939VOLTHA="voltha-ofagent-.* \
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001940 rw-core.* \
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001941 voltha-etcd-cluster-.* \
1942 voltha-kafka-.* \
1943 voltha-zookeeper-.*"
David Bainbridged18f4942020-04-14 16:46:13 -07001944wait_for_pods - "$VOLTHA_NS" "$EXPECT" "includes" "Waiting for VOLTHA Core to start" "$NO_LABEL" "$VOLTHA"
David Bainbridgee87067b2019-08-12 22:00:12 +00001945if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001946 NOW="$(date +%s)"
1947 printtime $((NOW - STIME))
David Bainbridgee87067b2019-08-12 22:00:12 +00001948fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001949
David Bainbridge46505fb2019-10-01 21:13:20 +00001950if [ "$WITH_ADAPTERS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001951 STIME="$(date +%s)"
David Bainbridge46505fb2019-10-01 21:13:20 +00001952 EXPECT=0
David Bainbridged18f4942020-04-14 16:46:13 -07001953 if [ "$WITH_ETCD" == "yes" ]; then
David Bainbridge3517f6c2020-04-08 12:14:08 -07001954 _HOST=voltha-etcd-cluster-client.$VOLTHA_NS.svc.cluster.local
1955 _PORT=2379
1956 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set services.etcd.service=$_HOST --set services.etcd.port=$_PORT"
David Bainbridged18f4942020-04-14 16:46:13 -07001957 elif [ "$WITH_ETCD" == "external" ]; then
David Bainbridge3517f6c2020-04-08 12:14:08 -07001958 _HOST=etcd-cluster-client.$INFRA_NS.svc.cluster.local
1959 _PORT=2379
1960 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set services.etcd.service=$_HOST --set services.etcd.port=$_PORT"
David Bainbridged18f4942020-04-14 16:46:13 -07001961 elif [ "$WITH_ETCD" != "no" ]; then
1962 _HOST="$(echo "$WITH_ETCD" | cut -d: -f1)"
1963 _PORT="$(echo "$WITH_ETCD" | cut -s -d: -f2)"
David Bainbridge3517f6c2020-04-08 12:14:08 -07001964 _PORT=${_PORT:-2379}
1965 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set services.etcd.service=$_HOST --set services.etcd.port=$_PORT"
David Bainbridge696bc632020-04-05 21:49:37 -07001966 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001967 if [ "$WITH_KAFKA" == "yes" ]; then
David Bainbridge3517f6c2020-04-08 12:14:08 -07001968 _HOST=voltha-kafka.$VOLTHA_NS.svc.cluster.local
1969 _PORT=9092
1970 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 -07001971 elif [ "$WITH_KAFKA" == "external" ]; then
David Bainbridge3517f6c2020-04-08 12:14:08 -07001972 _HOST=kafka.$INFRA_NS.svc.cluster.local
1973 _PORT=9092
1974 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 -07001975 elif [ "$WITH_KAFKA" != "no" ]; then
1976 _HOST="$(echo "$WITH_KAFKA" | cut -d: -f1)"
1977 _PORT="$(echo "$WITH_KAFKA" | cut -s -d: -f2)"
David Bainbridge3517f6c2020-04-08 12:14:08 -07001978 _PORT=${_PORT:-9092}
1979 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 -07001980 fi
David Bainbridge46505fb2019-10-01 21:13:20 +00001981 echo -e "Verify Adapters $PLUG"
1982 if [ "$WITH_SIM_ADAPTERS" == "yes" ]; then
1983 bspin - "Verify Simulated Adapters installed"
David Bainbridged18f4942020-04-14 16:46:13 -07001984 if [ "$HELM_USE_UPGRADE" == "yes" ] || [ "$(helm list --deployed --short --namespace "$ADAPTER_NS" "^sim\$" | wc -l)" -ne 1 ]; then
1985 espin - "$NOT_VERIFIED"
1986 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 +00001987 else
David Bainbridged18f4942020-04-14 16:46:13 -07001988 espin - "$VERIFIED"
David Bainbridge46505fb2019-10-01 21:13:20 +00001989 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001990 EXPECT="$((EXPECT + 2))"
David Bainbridge46505fb2019-10-01 21:13:20 +00001991 fi
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001992
David Bainbridge46505fb2019-10-01 21:13:20 +00001993 if [ "$WITH_OPEN_ADAPTERS" == "yes" ]; then
1994 bspin - "Verify OpenOLT Adapter installed"
David Bainbridged18f4942020-04-14 16:46:13 -07001995 if [ "$HELM_USE_UPGRADE" == "yes" ] || [ "$(helm list --deployed --short --namespace "$ADAPTER_NS" "^open-olt\$" | wc -l)" -ne 1 ]; then
1996 espin - "$NOT_VERIFIED"
1997 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 +00001998 else
David Bainbridged18f4942020-04-14 16:46:13 -07001999 espin - "$VERIFIED"
David Bainbridge46505fb2019-10-01 21:13:20 +00002000 fi
Matteo Scandolo67335f02020-04-09 11:19:53 -07002001 EXPECT="$((EXPECT + 1))"
David Bainbridge46505fb2019-10-01 21:13:20 +00002002 bspin - "Verify OpenONU Adapter installed"
David Bainbridged18f4942020-04-14 16:46:13 -07002003 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 -07002004 _ORIGINAL_EXTRA_HELM_INSTALL_ARGS="$INTERNAL_EXTRA_HELM_INSTALL_ARGS"
2005 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set replicas.adapter_open_onu=$NUM_OF_OPENONU"
David Bainbridged18f4942020-04-14 16:46:13 -07002006 espin - "$NOT_VERIFIED"
Matteo Scandolo67335f02020-04-09 11:19:53 -07002007 helm_install - "$ADAPTER_NS" open-onu "$VOLTHA_ADAPTER_OPEN_ONU_CHART" "$VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION" "$_HELM_DESC OpenONU Adapter"
2008 INTERNAL_EXTRA_HELM_INSTALL_ARGS="$_ORIGINAL_EXTRA_HELM_INSTALL_ARGS"
David Bainbridge46505fb2019-10-01 21:13:20 +00002009 else
David Bainbridged18f4942020-04-14 16:46:13 -07002010 espin - "$VERIFIED"
David Bainbridge46505fb2019-10-01 21:13:20 +00002011 fi
Matteo Scandolo67335f02020-04-09 11:19:53 -07002012 EXPECT=$((EXPECT + NUM_OF_OPENONU))
David Bainbridge46505fb2019-10-01 21:13:20 +00002013 fi
David Bainbridge696bc632020-04-05 21:49:37 -07002014 INTERNAL_EXTRA_HELM_INSTALL_ARGS=
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07002015
David Bainbridge46505fb2019-10-01 21:13:20 +00002016 ADAPTERS="adapter-.*"
David Bainbridged18f4942020-04-14 16:46:13 -07002017 wait_for_pods - "$ADAPTER_NS" "$EXPECT" "includes" "Waiting for adapters to start" "$NO_LABEL" "$ADAPTERS"
David Bainbridge46505fb2019-10-01 21:13:20 +00002018 if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07002019 NOW="$(date +%s)"
2020 printtime $((NOW - STIME))
David Bainbridge46505fb2019-10-01 21:13:20 +00002021 fi
David Bainbridgee87067b2019-08-12 22:00:12 +00002022fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07002023
David Bainbridged18f4942020-04-14 16:46:13 -07002024if [ "$WITH_BBSIM" == "yes" ]; then
2025 STIME="$(date +%s)"
Test User7d866122019-07-09 17:52:35 +00002026 echo -e "Verify BBSIM $PLUG"
David Bainbridge5b7b96b2019-07-25 20:29:13 +00002027 bspin - "Verify BBSIM Installed"
David Bainbridged18f4942020-04-14 16:46:13 -07002028 for instance in $(seq 0 $((NUM_OF_BBSIM-1))); do
Matteo Scandoloc2eb0672020-05-01 14:43:15 -07002029
2030 if [ "$LEGACY_BBSIM_INDEX" == "yes" ]; then
2031 if [ "$instance" -eq 0 ]; then
2032 instance_num=""
2033 else
2034 instance_num=$instance
2035 fi
David K. Bainbridge43422402020-03-06 07:41:22 -08002036 else
2037 instance_num=$instance
2038 fi
Matteo Scandoloc2eb0672020-05-01 14:43:15 -07002039
2040
David Bainbridged18f4942020-04-14 16:46:13 -07002041 if [ "$HELM_USE_UPGRADE" == "yes" ] || [ "$(helm list --deployed --short --namespace "$BBSIM_NS" "^bbsim${instance_num}\$" | wc -l)" -ne 1 ]; then
2042 espin - "$NOT_VERIFIED"
2043 S_TAG="$((900+instance))"
Matteo Scandolo5a149572020-04-01 10:14:57 -07002044 INTERNAL_EXTRA_HELM_INSTALL_ARGS="--set olt_id=$instance,s_tag=$S_TAG"
David Bainbridged9329af2020-05-01 11:58:52 -07002045 if [ "$WITH_EAPOL" == "yes" ]; then
2046 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set auth=true"
2047 else
2048 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set auth=false"
2049 fi
2050 if [ "$WITH_DHCP" == "yes" ]; then
2051 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set dhcp=true"
2052 else
2053 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set dhcp=false"
2054 fi
David Bainbridged18f4942020-04-14 16:46:13 -07002055 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 -07002056 INTERNAL_EXTRA_HELM_INSTALL_ARGS=
David K. Bainbridge43422402020-03-06 07:41:22 -08002057 else
David Bainbridged18f4942020-04-14 16:46:13 -07002058 espin - "$VERIFIED"
David K. Bainbridge43422402020-03-06 07:41:22 -08002059 fi
2060 done
David Bainbridged18f4942020-04-14 16:46:13 -07002061 wait_for_pods - "$BBSIM_NS" "$NUM_OF_BBSIM" "includes" "Waiting for BBSIM to start" "$BBSIM_LABEL" "bbsim*"
David Bainbridgee87067b2019-08-12 22:00:12 +00002062 if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07002063 NOW="$(date +%s)"
2064 printtime $((NOW - STIME))
David Bainbridgee87067b2019-08-12 22:00:12 +00002065 fi
Test User7d866122019-07-09 17:52:35 +00002066fi
2067
David Bainbridge309099c2020-05-05 08:47:29 -07002068if [ "$CONFIG_SADIS" == "external" ]; then
2069 STIME="$(date +%s)"
2070 echo -e "Verify BBSIM SADIS Service $PLUG"
2071 bspin - "Verify required configmap"
2072 (set -x; kubectl -n "$BBSIM_NS" delete --ignore-not-found configmap kube-config >>"$LOG" 2>&1) >>"$LOG" 2>&1
2073 (set -x; kubectl -n "$BBSIM_NS" create configmap kube-config "--from-file=kube_config=$KUBECONFIG" >>"$LOG" 2>&1) >>"$LOG" 2>&1
2074 espin - "$VERIFIED"
2075 bspin - "Verify BBSIM SADIS Service Installed"
2076 if [ "$HELM_USE_UPGRADE" == "yes" ] || [ "$(helm list --deployed --short --namespace "$BBSIM_NS" "^bbsim-sadis-servier\$" | wc -l)" -ne 1 ]; then
2077 espin - "$NOT_VERIFIED"
2078 helm_install - "$BBSIM_NS" bbsim-sadis-server "$BBSIM_SADIS_SERVER_CHART" "$BBSIM_SADIS_SERVER_CHART_VERSION" "$_HELM_DESC BBSIM SADIS Server"
2079 else
2080 espin - "$VERIFIED"
2081 fi
2082 wait_for_pods - "$BBSIM_NS" 1 "includes" "Waiting for BBSIM SADIS Server to start" "$NO_LABEL" "bbsim-sadis-server-.*"
2083 if [ "$WITH_TIMINGS" == "yes" ]; then
2084 NOW="$(date +%s)"
2085 printtime $((NOW - STIME))
2086 fi
2087fi
2088
David Bainbridged18f4942020-04-14 16:46:13 -07002089if [ "$WITH_RADIUS" == "yes" ]; then
2090 STIME="$(date +%s)"
David Bainbridge5b7b96b2019-07-25 20:29:13 +00002091 echo -e "Verify RADIUS $LOCK"
2092 bspin - "Verify RADIUS Installed"
David Bainbridged18f4942020-04-14 16:46:13 -07002093 if [ "$HELM_USE_UPGRADE" == "yes" ] || [ "$(helm list --deployed --short --namespace "$INFRA_NS" "^radius\$" | wc -l)" -ne 1 ]; then
2094 espin - "$NOT_VERIFIED"
2095 helm_install - "$INFRA_NS" radius onf/freeradius latest "$_HELM_DESC RADIUS"
David Bainbridge5b7b96b2019-07-25 20:29:13 +00002096 else
David Bainbridged18f4942020-04-14 16:46:13 -07002097 espin - "$VERIFIED"
David Bainbridge5b7b96b2019-07-25 20:29:13 +00002098 fi
David Bainbridged18f4942020-04-14 16:46:13 -07002099 wait_for_pods - "$INFRA_NS" 1 "includes" "Waiting for RADIUS to start" "$NO_LABEL" "radius-.*"
David Bainbridgee87067b2019-08-12 22:00:12 +00002100 if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07002101 NOW="$(date +%s)"
2102 printtime $((NOW - STIME))
David Bainbridgee87067b2019-08-12 22:00:12 +00002103 fi
David Bainbridge5b7b96b2019-07-25 20:29:13 +00002104fi
2105
David Bainbridged18f4942020-04-14 16:46:13 -07002106if [ "$WITH_PORT_FORWARDS" == "yes" ]; then
2107 STIME="$(date +%s)"
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -08002108 bspin - "Forward VOLTHA API port $FORWARD"
2109 kill_port_forward voltha-api
David Bainbridge60ffc0f2020-04-27 22:13:22 -07002110 port_forward "$VOLTHA_NS" voltha-api "$VOLTHA_API_PORT:55555"
David Bainbridged18f4942020-04-14 16:46:13 -07002111 espin - "$VERIFIED"
2112 if [ "$WITH_ETCD" == "yes" ] || [ "$WITH_ETCD" == "external" ]; then
2113 _NS="$(test "$WITH_ETCD" == "yes" && echo "$VOLTHA_NS" || echo "$INFRA_NS")"
David Bainbridge696bc632020-04-05 21:49:37 -07002114 bspin - "Forward VOLTHA ETCD port $FORWARD"
David Bainbridged18f4942020-04-14 16:46:13 -07002115 kill_port_forward "${ETCD_PREFIX}etcd-cluster-client"
David Bainbridge60ffc0f2020-04-27 22:13:22 -07002116 port_forward "$_NS" "${ETCD_PREFIX}etcd-cluster-client" "$VOLTHA_ETCD_PORT:2379"
David Bainbridged18f4942020-04-14 16:46:13 -07002117 espin - "$VERIFIED"
David Bainbridge696bc632020-04-05 21:49:37 -07002118 fi
David Bainbridged18f4942020-04-14 16:46:13 -07002119 if [ "$WITH_KAFKA" == "yes" ] || [ $WITH_KAFKA == "external" ]; then
2120 _NS="$(test "$WITH_ETCD" == "yes" && echo "$VOLTHA_NS" || echo "$INFRA_NS")"
David Bainbridge696bc632020-04-05 21:49:37 -07002121 bspin - "Forward VOLTHA Kafka port $FORWARD"
David Bainbridged18f4942020-04-14 16:46:13 -07002122 kill_port_forward "${KAFKA_PREFIX}kafka"
David Bainbridge60ffc0f2020-04-27 22:13:22 -07002123 port_forward "$_NS" ${KAFKA_PREFIX}kafka "$VOLTHA_KAFKA_PORT:9092"
David Bainbridged18f4942020-04-14 16:46:13 -07002124 espin - "$VERIFIED"
David Bainbridge696bc632020-04-05 21:49:37 -07002125 fi
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -08002126 if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07002127 NOW="$(date +%s)"
2128 printtime $((NOW - STIME))
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -08002129 fi
David Bainbridgee87067b2019-08-12 22:00:12 +00002130fi
Test User3d7ad8e2019-07-03 06:15:44 +00002131
David Bainbridge60ffc0f2020-04-27 22:13:22 -07002132if is_in "$WITH_ONOS" "yes,legacy,classic" && [ "$WITH_RADIUS" != "no" ]; then
David Bainbridge76afd812020-04-06 09:53:52 -07002133 _HOST=radius.$INFRA_NS.svc.cluster.local
David Bainbridge696bc632020-04-05 21:49:37 -07002134 _PORT=1812
David Bainbridged18f4942020-04-14 16:46:13 -07002135 if [ "$WITH_RADIUS" != "yes" ]; then
2136 _HOST="$(echo "$WITH_RADIUS" | cut -d: -f1)"
2137 _PORT="$(echo "$WITH_RADIUS" | cut -s -d: -f2)"
David Bainbridge696bc632020-04-05 21:49:37 -07002138 _PORT=${_PORT:-1812}
2139 fi
David Bainbridge5b7b96b2019-07-25 20:29:13 +00002140 bspin "Configure ONOS RADIUS Connection $GEAR"
David Bainbridged18f4942020-04-14 16:46:13 -07002141 (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
2142 espin "$VERIFIED"
David Bainbridge5b7b96b2019-07-25 20:29:13 +00002143fi
2144
David Bainbridge99ac7a22019-08-31 02:26:43 +00002145if [ "$WITH_CHAOS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07002146 STIME="$(date +%s)"
David Bainbridge99ac7a22019-08-31 02:26:43 +00002147 echo -e "Verify kube-monkey $LOCK"
2148 bspin - "Verify kube-monkey Installed"
David Bainbridged18f4942020-04-14 16:46:13 -07002149 if [ "$HELM_USE_UPGRADE" == "yes" ] || [ "$(helm list --deployed --short --namespace kube-monkey "^monkey\$" | wc -l)" -ne 1 ]; then
2150 espin - "$NOT_VERIFIED"
David Bainbridge7f8bf992020-04-08 21:53:22 -07002151 helm_install - kube-monkey monkey ./kube-monkey/helm/kubemonkey latest "$_HELM_DESC Chaos Monkey"
David Bainbridge99ac7a22019-08-31 02:26:43 +00002152 else
David Bainbridged18f4942020-04-14 16:46:13 -07002153 espin - "$VERIFIED"
David Bainbridge99ac7a22019-08-31 02:26:43 +00002154 fi
David Bainbridged18f4942020-04-14 16:46:13 -07002155 wait_for_pods - "kube-monkey" 1 "includes" "Waiting for Chaos to start" "$NO_LABEL" "monkey-.*"
David Bainbridge99ac7a22019-08-31 02:26:43 +00002156 if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07002157 NOW="$(date +%s)"
2158 printtime $((NOW - STIME))
David Bainbridge99ac7a22019-08-31 02:26:43 +00002159 fi
2160fi
2161
David Bainbridge5b7b96b2019-07-25 20:29:13 +00002162bspin "Create voltctl configuration file"
David Bainbridged18f4942020-04-14 16:46:13 -07002163(set -x; mkdir -p "$HOME/.volt" >>"$LOG" 2>&1) >>"$LOG" 2>&1
2164MIN_VC_VERSION="$(echo -e "1.0.15\n$VC_VERSION" | sort -V | head -1)"
2165if [ "$WITH_PORT_FORWARDS" == "yes" ]; then
David K. Bainbridgeb859e912020-03-13 14:07:52 -07002166 KAFKA_FLAG="-k localhost:$VOLTHA_KAFKA_PORT"
2167 SERVER_FLAG="-s localhost:$VOLTHA_API_PORT"
2168 ETCD_FLAG=
2169 if [ "$MIN_VC_VERSION" == "1.0.15" ]; then
2170 ETCD_FLAG="-e localhost:$VOLTHA_ETCD_PORT"
2171 fi
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -08002172else
David Bainbridged18f4942020-04-14 16:46:13 -07002173 KAFKA_FLAG="-k $(get_service_ep "$INFRA_NS" "${KAFKA_PREFIX}kafka")"
2174 SERVER_FLAG="-s $(get_service_ep "$VOLTHA_NS" voltha-api)"
David K. Bainbridgeb859e912020-03-13 14:07:52 -07002175 ETCD_FLAG=
2176 if [ "$MIN_VC_VERSION" == "1.0.15" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07002177 ETCD_FLAG="-e $(get_service_ep "$INFRA_NS" ${ETCD_PREFIX}etcd-client)"
David K. Bainbridgeb859e912020-03-13 14:07:52 -07002178 fi
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -08002179fi
David Bainbridged18f4942020-04-14 16:46:13 -07002180CMD=("voltctl -a v3 $KAFKA_FLAG $SERVER_FLAG $ETCD_FLAG config")
2181(set -x; ${CMD[*]} > "$HOME/.volt/config-$NAME" 2>>"$LOG") >>"$LOG" 2>&1
2182#(set -x; voltctl -a v3 "$KAFKA_FLAG" "$SERVER_FLAG" "$ETCD_FLAG" config > "$HOME/.volt/config-$NAME" 2>>"$LOG") >>"$LOG" 2>&1
2183espin "$VERIFIED"
Test User08ebbd92019-07-03 17:15:39 +00002184
David Bainbridge0774b232019-08-02 06:37:19 +00002185if [ ! -f "$NAME-env.sh" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07002186 touch "$NAME-env.sh"
David Bainbridgeb07fdf72019-07-29 22:51:40 +00002187fi
2188
David Bainbridge596f30d2019-07-30 17:07:59 +00002189for O in $ALL_OPTIONS; do
David Bainbridged18f4942020-04-14 16:46:13 -07002190 VAL="$(eval echo "\$$O")"
2191 if [ -n "$VAL" ] && [ "$(grep -c "^export $O=" "$NAME-env.sh")" -eq 0 ]; then
2192 echo "export $O=\"$(eval echo "\$$O")\"" >> "$NAME-env.sh"
David Bainbridgeb07fdf72019-07-29 22:51:40 +00002193 fi
2194done
2195
David Bainbridged18f4942020-04-14 16:46:13 -07002196if [ "$DEPLOY_K8S" == "yes" ] && [ "$(grep -c "^export KUBECONFIG=" "$NAME-env.sh")" -eq 0 ]; then
2197 echo "export KUBECONFIG=\"$(./bin/kind get kubeconfig-path "--name=voltha-$NAME")\"" >> "$NAME-env.sh"
David Bainbridgeb07fdf72019-07-29 22:51:40 +00002198fi
2199
David Bainbridged18f4942020-04-14 16:46:13 -07002200if [ "$(grep -c "^export VOLTCONFIG=" "$NAME-env.sh")" -eq 0 ]; then
2201 echo "export VOLTCONFIG=\"$HOME/.volt/config-$NAME\"" >> "$NAME-env.sh"
David Bainbridgeb07fdf72019-07-29 22:51:40 +00002202fi
2203
David Bainbridged18f4942020-04-14 16:46:13 -07002204if [ "$(grep -c "^export PATH=" "$NAME-env.sh")" -eq 0 ]; then
2205 echo "export PATH=\"$GOPATH/bin:\$PATH\"" >> "$NAME-env.sh"
David Bainbridgeb07fdf72019-07-29 22:51:40 +00002206fi
2207
Test User7d866122019-07-09 17:52:35 +00002208echo ""
David Bainbridged18f4942020-04-14 16:46:13 -07002209echo "Please issue the following commands in your terminal to ensure that you" | tee -a "$LOG"
2210echo "are accessing the correct Kubernetes/Kind cluster as well as have the " | tee -a "$LOG"
2211echo "tools required by VOLTHA in your command path. " | tee -a "$LOG"
2212echo "" | tee -a "$LOG"
2213echo -en "$BOLD"
2214if [ "$DEPLOY_K8S" == "yes" ]; then
2215 echo "export KUBECONFIG=\"\$(./bin/kind get kubeconfig-path --name=\"voltha-$NAME\")\"" | tee -a "$LOG"
Test Userba1e7e72019-07-10 22:27:54 +00002216fi
David Bainbridged18f4942020-04-14 16:46:13 -07002217echo "export VOLTCONFIG=\"$HOME/.volt/config-$NAME\"" | tee -a "$LOG"
2218echo "export PATH=$GOPATH/bin:\$PATH" | tee -a "$LOG"
2219echo -en "$NORMAL"
2220echo "" | tee -a "$LOG"
2221echo "Thank you for choosing kind-voltha for you quick cluster needs." | tee -a "$LOG"
Test User08ebbd92019-07-03 17:15:39 +00002222
David Bainbridge712afb82019-08-14 19:55:58 +00002223if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07002224 NOW="$(date +%s)"
2225 echo -e "$CLOCK ${BOLD}TOTAL: $(duration $((NOW - TOTAL_START_TIME)))${NORMAL}"
David Bainbridge712afb82019-08-14 19:55:58 +00002226fi