blob: 4fe8e4ccb6f36b514cb9a071b3c0a6e6e3ba808e [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 Bainbridgeb4bbde12020-06-25 14:46:36 -070019mkdir -p "$(pwd)/bin"
20PATH="$(pwd)/bin:$PATH"; export PATH
21GOPATH="$(pwd)"; export GOPATH
David K. Bainbridgeb7285432019-07-02 22:05:24 -070022
David Bainbridge38dc1e82019-08-12 15:18:45 +000023FANCY=${FANCY:-1}
24if [ "$TERM X" == " X" ]; then
25 FANCY=0
26fi
27
David K. Bainbridgeb7285432019-07-02 22:05:24 -070028# trap ctrl-c and call ctrl_c()
29trap ctrl_c INT
30
31function ctrl_c() {
David Bainbridged18f4942020-04-14 16:46:13 -070032 echo -en "$CNORM"
David K. Bainbridgeb7285432019-07-02 22:05:24 -070033 echo ""
34 echo "ctrl-c trapped"
David Bainbridgec6a6eb62019-10-18 22:50:07 +000035 echo "Thank you for trying 'voltha up'"
David K. Bainbridgeb7285432019-07-02 22:05:24 -070036 exit
37}
38
Andrea Campanella40e48b72020-07-21 20:32:52 +020039HELM_VERSION=${HELM_VERSION:-v3.2.4}
David K. Bainbridgeebf38d92020-02-10 10:46:31 -080040VOLTCTL_VERSION=${VOLTCTL_VERSION:-latest}
David K. Bainbridge88a7a792020-07-27 17:01:14 +000041KIND_VERSION=${KIND_VERSION:-v0.8.1}
David K. Bainbridgeb3a99372020-01-08 14:39:06 -080042VK_RELEASE=${VK_RELEASE:-master}
David Bainbridge60ffc0f2020-04-27 22:13:22 -070043EXTRA_TOOLS=
Test User08ebbd92019-07-03 17:15:39 +000044
David Bainbridge38dc1e82019-08-12 15:18:45 +000045RED=
46GREEN=
47YELLOW=
48BLUE=
David Bainbridge38dc1e82019-08-12 15:18:45 +000049BOLD=
50NORMAL=
51ERROR=
52CEOL=
53CNORM=
54CIVIS=
David Bainbridged18f4942020-04-14 16:46:13 -070055if [ "$FANCY" -eq 1 ]; then
56 RED="$(tput setaf 1)"
57 GREEN="$(tput setaf 2)"
58 YELLOW="$(tput setaf 3)"
59 BLUE="$(tput setaf 4)"
60 BOLD="$(tput bold)"
61 NORMAL="$(tput sgr0)"
David Bainbridge38dc1e82019-08-12 15:18:45 +000062 ERROR="\xe2\x9c\x97\x20"
David Bainbridged18f4942020-04-14 16:46:13 -070063 CEOL="$(tput el)"
64 CNORM="$(tput cnorm)"
65 CIVIS="$(tput civis)"
David Bainbridge38dc1e82019-08-12 15:18:45 +000066fi
Test User7d866122019-07-09 17:52:35 +000067
Matteo Scandolo657e13c2020-07-28 11:41:42 -070068NAME=${NAME:-minimal}
David K. Bainbridge484d80c2020-03-05 21:44:34 -080069
70ENABLE_ONOS_EXTRANEOUS_RULES=${ENABLE_ONOS_EXTRANEOUS_RULES:-no}
David Bainbridge76afd812020-04-06 09:53:52 -070071INFRA_NS=${INFRA_NS:-default}
72VOLTHA_NS=${VOLTHA_NS:-voltha}
73BBSIM_NS=${BBSIM_NS:-voltha}
74ADAPTER_NS=${ADAPTER_NS:-voltha}
David Bainbridgee87067b2019-08-12 22:00:12 +000075WITH_TIMINGS=${WITH_TIMINGS:-no}
Test User7d866122019-07-09 17:52:35 +000076WITH_BBSIM=${WITH_BBSIM:-no}
divyadesai59f987a2020-05-27 12:11:33 +000077WITH_EFK=${WITH_EFK:-no}
Girish Kumarcc5f9172020-06-10 13:34:31 +000078WITH_TRACING=${WITH_TRACING:-no}
David Bainbridge5b7b96b2019-07-25 20:29:13 +000079WITH_RADIUS=${WITH_RADIUS:-no}
Matteo Scandolo78dfee02020-02-13 16:18:03 -080080WITH_EAPOL=${WITH_EAPOL:-yes}
81WITH_DHCP=${WITH_DHCP:-yes}
82WITH_IGMP=${WITH_IGMP:-no}
David Bainbridgeb270c202019-07-26 01:44:42 +000083WITH_ONOS=${WITH_ONOS:-yes}
David Bainbridge60ffc0f2020-04-27 22:13:22 -070084NUM_OF_ONOS=${NUM_OF_ONOS:-1}
85NUM_OF_ATOMIX=${NUM_OF_ATOMIX:-0}
David Bainbridge99ac7a22019-08-31 02:26:43 +000086WITH_CHAOS=${WITH_CHAOS:-no}
David Bainbridge46505fb2019-10-01 21:13:20 +000087WITH_ADAPTERS=${WITH_ADAPTERS:-yes}
David K. Bainbridgeda33d652020-03-06 10:31:23 -080088WITH_SIM_ADAPTERS=${WITH_SIM_ADAPTERS:-no}
David Bainbridge46505fb2019-10-01 21:13:20 +000089WITH_OPEN_ADAPTERS=${WITH_OPEN_ADAPTERS:-yes}
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -080090WITH_PORT_FORWARDS=${WITH_PORT_FORWARDS:-yes}
David Bainbridge696bc632020-04-05 21:49:37 -070091WITH_KAFKA=${WITH_KAFKA:-yes}
92WITH_ETCD=${WITH_ETCD:-yes}
Matteo Scandoloefee0432020-05-05 13:56:20 -070093WITH_PPROF=${WITH_PPROF:-no}
Girish Gowdra4cc5d8b2020-06-11 17:12:00 -070094WITH_INCREMENTAL_EVTO_UPDATE=${WITH_INCREMENTAL_EVTO_UPDATE:-no}
David Bainbridgee4d11ca2020-05-08 10:21:10 -070095SCHEDULE_ON_CONTROL_NODES=${SCHEDULE_ON_CONTROL_NODES:-no}
David Bainbridge309099c2020-05-05 08:47:29 -070096CONFIG_SADIS=${CONFIG_SADIS:-no} # yes | no | file | bbsim | external | URL
Hardik Windlassb3147602020-03-09 16:59:15 +053097SADIS_CFG=${SADIS_CFG:-onos-files/onos-sadis-sample.json}
Matteo Scandolo6402d362020-08-24 12:31:06 -070098BBSIM_CFG=${BBSIM_CFG:-configs/bbsim-sadis-att.yaml}
David Bainbridge27790d62019-08-13 22:43:19 +000099INSTALL_ONOS_APPS=${INSTALL_ONOS_APPS:-no}
Test Userba1e7e72019-07-10 22:27:54 +0000100JUST_K8S=${JUST_K8S:-no}
Matteo Scandoloe89384a2020-11-06 08:40:25 -0800101JUST_INFRA=${JUST_INFRA:-no}
Test Userba1e7e72019-07-10 22:27:54 +0000102DEPLOY_K8S=${DEPLOY_K8S:-yes}
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700103INSTALL_KUBECTL=${INSTALL_KUBECTL:-yes}
104INSTALL_HELM=${INSTALL_HELM:-yes}
David Bainbridge7f8bf992020-04-08 21:53:22 -0700105HELM_USE_UPGRADE=${HELM_USE_UPGRADE:-no}
David Bainbridge46505fb2019-10-01 21:13:20 +0000106UPDATE_HELM_REPOS=${UPDATE_HELM_REPOS:-yes}
Matteo Scandolofab98622020-01-28 15:17:20 -0800107WAIT_ON_DOWN=${WAIT_ON_DOWN:-yes}
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700108WAIT_TIMEOUT=${WAIT_TIMEOUT:-30m}
109VOLTHA_DOWN_ON_TIMEOUT=${VOLTHA_DOWN_ON_TIMEOUT:-no}
David Bainbridge5b7b96b2019-07-25 20:29:13 +0000110VOLTHA_LOG_LEVEL=${VOLTHA_LOG_LEVEL:-WARN}
David Bainbridge90fd8e32019-08-21 23:32:47 +0000111VOLTHA_CHART=${VOLTHA_CHART:-onf/voltha}
112VOLTHA_CHART_VERSION=${VOLTHA_CHART_VERSION:-latest}
113VOLTHA_BBSIM_CHART=${VOLTHA_BBSIM_CHART:-onf/bbsim}
Matteo Scandolocdfb4e22020-09-11 19:46:59 -0700114VOLTHA_BBSIM_CHART_VERSION=${VOLTHA_BBSIM_CHART_VERSION:-latest}
divyadesai59f987a2020-05-27 12:11:33 +0000115ELASTICSEARCH_CHART=${ELASTICSEARCH_CHART:-elastic/elasticsearch}
116ELASTICSEARCH_CHART_VERSION=${ELASTICSEARCH_CHART_VERSION:-latest}
117KIBANA_CHART=${KIBANA_CHART:-elastic/kibana}
118KIBANA_CHART_VERSION=${KIBANA_CHART_VERSION:-latest}
119FLUENTD_ELASTICSEARCH_CHART=${FLUENTD_ELASTICSEARCH_CHART:-kiwigrid/fluentd-elasticsearch}
120FLUENTD_ELASTICSEARCH_CHART_VERSION=${FLUENTD_ELASTICSEARCH_CHART_VERSION:-latest}
Girish Kumarcc5f9172020-06-10 13:34:31 +0000121VOLTHA_TRACING_CHART=${VOLTHA_TRACING_CHART:-onf/voltha-tracing}
122VOLTHA_TRACING_CHART_VERSION=${VOLTHA_TRACING_CHART_VERSION:-latest}
David Bainbridgee10f6d52019-07-25 00:28:13 +0000123VOLTHA_ADAPTER_SIM_CHART=${VOLTHA_ADAPTER_SIM_CHART:-onf/voltha-adapter-simulated}
David Bainbridge90fd8e32019-08-21 23:32:47 +0000124VOLTHA_ADAPTER_SIM_CHART_VERSION=${VOLTHA_ADAPTER_SIM_CHART_VERSION:-latest}
David Bainbridgee10f6d52019-07-25 00:28:13 +0000125VOLTHA_ADAPTER_OPEN_OLT_CHART=${VOLTHA_ADAPTER_OPEN_OLT_CHART:-onf/voltha-adapter-openolt}
David Bainbridge90fd8e32019-08-21 23:32:47 +0000126VOLTHA_ADAPTER_OPEN_OLT_CHART_VERSION=${VOLTHA_ADAPTER_OPEN_OLT_CHART_VERSION:-latest}
David Bainbridgee10f6d52019-07-25 00:28:13 +0000127VOLTHA_ADAPTER_OPEN_ONU_CHART=${VOLTHA_ADAPTER_OPEN_ONU_CHART:-onf/voltha-adapter-openonu}
David Bainbridge90fd8e32019-08-21 23:32:47 +0000128VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION=${VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION:-latest}
David K. Bainbridgeda33d652020-03-06 10:31:23 -0800129ONOS_CHART=${ONOS_CHART:-onf/onos}
Andrea Campanella21323292019-12-18 11:44:19 -0800130ONOS_CHART_VERSION=${ONOS_CHART_VERSION:-latest}
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700131ONOS_CLASSIC_CHART=${ONOS_CLASSIC_CHART:-onos/onos-classic}
Andrea Campanella26c8c992020-08-24 15:43:26 +0000132ONOS_CLASSIC_CHART_VERSION=${ONOS_CLASSIC_CHART_VERSION:-latest}
Matteo Scandolo8f8609a2020-11-13 10:20:44 -0800133KAFKA_CHART=${KAFKA_CHART:-bitnami/kafka}
David Bainbridgeb4bbde12020-06-25 14:46:36 -0700134KAFKA_CHART_VERSION=${KAFKA_CHART_VERSION:=latest}
Matteo Scandoloe89384a2020-11-06 08:40:25 -0800135BBSIM_SADIS_SERVER_CHART=${BBSIM_SADIS_SERVER_CHART:-onf/bbsim-sadis-server}
David Bainbridge309099c2020-05-05 08:47:29 -0700136BBSIM_SADIS_SERVER_CHART_VERSION=${BBSIM_SADIS_SERVER_CHART_VERSION:-latest}
Matteo Scandolo8f8609a2020-11-13 10:20:44 -0800137ETCD_CHART=${ETCD_CHART:-bitnami/etcd}
David Bainbridgec7220622020-05-28 12:31:47 -0700138ETCD_CHART_VERSION=${ETCD_CHART_VERSION:-latest}
David Bainbridge879439b2020-06-12 15:59:35 -0700139RADIUS_CHART=${RADIUS_CHART:-onf/freeradius}
140RADIUS_CHART_VERSION=${RADIUS_CHART_VERSION:-latest}
David Bainbridge2eaf2cf2020-03-18 12:54:08 -0700141EXTRA_HELM_INSTALL_ARGS=${EXTRA_HELM_INSTALL_ARGS:-}
142INTERNAL_EXTRA_HELM_INSTALL_ARGS=
uottrembb16d3982020-02-28 08:34:36 +0100143NUM_OF_BBSIM=${NUM_OF_BBSIM:-1}
Matteo Scandoloe89384a2020-11-06 08:40:25 -0800144BBSIM_BASE_INDEX=${BBSIM_BASE_INDEX:-1}
Matteo Scandolo657e13c2020-07-28 11:41:42 -0700145NUM_OF_WORKER_NODES=${NUM_OF_WORKER_NODES:-2}
146NUM_OF_CONTROLLER_NODES=${NUM_OF_CONTROLLER_NODES:-1}
Matteo Scandolo67335f02020-04-09 11:19:53 -0700147NUM_OF_OPENONU=${NUM_OF_OPENONU:-1}
Matteo Scandolo657e13c2020-07-28 11:41:42 -0700148NUM_OF_KAFKA=${NUM_OF_KAFKA:-1}
149NUM_OF_ETCD=${NUM_OF_ETCD:-1}
uottrembb16d3982020-02-28 08:34:36 +0100150MAX_NUM_OF_BBSIM=10
Matteo Scandolo67335f02020-04-09 11:19:53 -0700151MAX_NUM_OF_OPENONU=10
Matteo Scandoloc2eb0672020-05-01 14:43:15 -0700152LEGACY_BBSIM_INDEX=${LEGACY_BBSIM_INDEX:-no}
David Bainbridgeb4bbde12020-06-25 14:46:36 -0700153PF_ADDRESS=${PF_ADDRESS:-0.0.0.0}
David K. Bainbridge2aa08da2020-07-31 12:49:45 -0700154KIND_CFG_FILE=${KIND_CFG_FILE:-}
Test Userba1e7e72019-07-10 22:27:54 +0000155
David Bainbridged18f4942020-04-14 16:46:13 -0700156HOSTOS="$(uname -s | tr "[:upper:]" "[:lower:"])"
157HOSTARCH="$(uname -m | tr "[:upper:]" "[:lower:"])"
158if [ "$HOSTARCH" == "x86_64" ]; then
Test Userba1e7e72019-07-10 22:27:54 +0000159 HOSTARCH="amd64"
160fi
David Bainbridge7db44002020-04-09 12:54:29 -0700161BBSIM_LABEL="-l app=bbsim"
David Bainbridged18f4942020-04-14 16:46:13 -0700162NO_LABEL=
Test User7d866122019-07-09 17:52:35 +0000163
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700164# checks to see if a given WORD is in the given LIST of words
165function is_in() {
166 local WORD LIST
167 WORD="$1"; shift
168 LIST="$*"
169 LIST=${LIST//+([[:space:],|])/:}
170
171 [ "$(echo ":$LIST:" | grep -ic ":$WORD:")" -ne 0 ]
172}
173
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700174function parseDuration() {
David Bainbridged18f4942020-04-14 16:46:13 -0700175 local DUR RESULT TERM TERMS VALUE UNIT
176 DUR=$1
177 RESULT=0
178 TERMS="$(echo "$DUR" | sed -Ee 's/([sSmMhHdD])/\1 /g' -e 's/,$//g')"
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700179 for TERM in $TERMS; do
David Bainbridged18f4942020-04-14 16:46:13 -0700180 VALUE="$(echo "$TERM" | sed -Ee 's/([0-9]+)[sSmMhHdD]/\1/')"
181 UNIT="$(echo "$TERM" | sed -Ee 's/[0-9]+([sSmMhHdD])/\1/')"
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700182 case $UNIT in
183 s|S)
David Bainbridged18f4942020-04-14 16:46:13 -0700184 RESULT=$((RESULT + VALUE)) ;;
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700185 m|M)
David Bainbridged18f4942020-04-14 16:46:13 -0700186 RESULT=$((RESULT + (VALUE * 60))) ;;
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700187 h|H)
David Bainbridged18f4942020-04-14 16:46:13 -0700188 RESULT=$((RESULT + (VALUE * 3600))) ;;
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700189 d|D)
David Bainbridged18f4942020-04-14 16:46:13 -0700190 RESULT=$((RESULT + (VALUE * 86400))) ;;
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700191 *) ;;
192 esac
193 done
194 echo $RESULT
195}
196
197function doTimeout() {
198 local MSG=$1
199 2>&1 echo -e "\n${RED}${BOLD}${ERROR}TIMEOUT:${NORMAL}${RED} Operation timed out after '$WAIT_TIMEOUT': $MSG"
200 exit 125
201}
202
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -0800203function get_service_ep() {
204 local NS=$1
205 local NAME=$2
David Bainbridged18f4942020-04-14 16:46:13 -0700206 kubectl -n "$NS" get service "$NAME" -o json | jq -r '.spec.clusterIP + ":" + (.spec.ports[0].port|tostring)'
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -0800207}
208
Matteo Scandolo6402d362020-08-24 12:31:06 -0700209# returns the greater version (0 if equal)
Matteo Scandolo734fe962020-09-02 17:47:16 -0700210# inspired by https://stackoverflow.com/questions/4023830/how-to-compare-two-strings-in-dot-separated-version-format-in-bash
Matteo Scandolo6402d362020-08-24 12:31:06 -0700211function semvercompare() {
212 if [[ "$1" == "$2" ]]
213 then
214 echo 0
215 return
216 fi
217
218 local tmp1 tmp2
219 tmp1=$(echo "${1//v/}" | awk -F'-' '{print $1}')
220 tmp2=$(echo "${2//v/}" | awk -F'-' '{print $1}')
221
222 local IFS=.
223 # shellcheck disable=SC2206
224 local i ver1=($tmp1) ver2=($tmp2)
225
226 # fill empty fields in ver1 with zeros
227 for ((i=${#ver1[@]}; i<${#ver2[@]}; i++))
228 do
229 ver1[i]=0
230 done
231 for ((i=0; i<${#ver1[@]}; i++))
232 do
233 if [[ -z ${ver2[i]} ]]
234 then
235 # fill empty fields in ver2 with zeros
236 ver2[i]=0
237 fi
238 if ((10#${ver1[i]} > 10#${ver2[i]}))
239 then
240 echo 1
241 return
242 fi
243 if ((10#${ver1[i]} < 10#${ver2[i]}))
244 then
245 echo 2
246 return
247 fi
248 done
249 echo 0
250 return
251}
252
Matteo Scandolo99dbed32020-09-03 14:11:27 -0700253# returns true if v1 is greater than v2 (false if they are the same)
Matteo Scandolo6402d362020-08-24 12:31:06 -0700254function semver_greater() {
255 local v1
256 local v2
Matteo Scandolo99dbed32020-09-03 14:11:27 -0700257 v1="$1" v2="$2"
Matteo Scandolo6402d362020-08-24 12:31:06 -0700258
259 # shellcheck disable=SC2128
Matteo Scandolo48890712020-09-11 15:48:24 -0700260 if [[ ! "$v1" =~ ^([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then
261 # if the version is custom, we assume it's newer than master
Matteo Scandolo6402d362020-08-24 12:31:06 -0700262 echo "true"
263 return
264 fi
265
266 # shellcheck disable=SC2128
267 res=$(semvercompare "$v1" "$v2")
268 if [[ $res == 1 ]]; then
269 echo "true"
270 else
271 echo "false"
272 fi
273}
274
Matteo Scandolo99dbed32020-09-03 14:11:27 -0700275# returns true if v1 is lesser than v2 (false if they are the same)
Matteo Scandolo6402d362020-08-24 12:31:06 -0700276function semver_lesser() {
277 local v1
278 local v2
Matteo Scandolo99dbed32020-09-03 14:11:27 -0700279 v1="$1" v2="$2"
Matteo Scandolo6402d362020-08-24 12:31:06 -0700280
281 # shellcheck disable=SC2128
Matteo Scandolo48890712020-09-11 15:48:24 -0700282 if [[ ! "$v1" =~ ^([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then
283 # if the version is custom, we assume it's newer than master
Matteo Scandolo6402d362020-08-24 12:31:06 -0700284 echo "false"
285 return
286 fi
287
288 # shellcheck disable=SC2128
289 res=$(semvercompare "$v1" "$v2")
290 if [[ $res == 2 ]]; then
291 echo "true"
292 else
293 echo "false"
294 fi
295}
296
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000297# Used to verify configuration values are set to "yes" or "no" value or convert
298# equivalents to "yes" or "no"
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700299YES="y,yes,t,true,1"
300NO="n,no,f,false,0"
301YES_OR_NO="$YES,$NO"
302
303# If the given VAR matches a truth value then normalize that
304# value, else return original value
305function normalize_yes_no() {
306 local VAR VAL
307 VAR=$1
308 VAL="$(eval echo "\$$VAR")"
309 if ! is_in "$VAL" "$YES_OR_NO"; then
310 echo "$VAL"
311 return 1
312 fi
313 if is_in "$VAL" "$YES"; then
314 echo "yes"
315 else
316 echo "no"
317 fi
318 return 0
319}
320
321# If the given VAR matches a truth value then normalize that
322# value, else display an error
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000323function verify_yes_no() {
David Bainbridged18f4942020-04-14 16:46:13 -0700324 local VAR VAL
325 VAR=$1
326 VAL="$(eval echo "\$$VAR")"
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700327 if ! is_in "$VAL" "$YES_OR_NO"; then
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000328 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} Invalid '$VAR' value of '$VAL'. Should be 'yes' or 'no'${NORMAL}"
329 echo "INVALID"
330 return 1
331 fi
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700332 if is_in "$VAL" "$YES"; then
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000333 echo "yes"
334 else
335 echo "no"
336 fi
337 return 0
338}
Test User7d866122019-07-09 17:52:35 +0000339
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000340ALL_YES_NO="\
David K. Bainbridge484d80c2020-03-05 21:44:34 -0800341 ENABLE_ONOS_EXTRANEOUS_RULES \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000342 WITH_TIMINGS \
343 WITH_BBSIM \
divyadesai59f987a2020-05-27 12:11:33 +0000344 WITH_EFK \
Girish Kumarcc5f9172020-06-10 13:34:31 +0000345 WITH_TRACING \
Matteo Scandolo78dfee02020-02-13 16:18:03 -0800346 WITH_EAPOL \
347 WITH_DHCP \
348 WITH_IGMP \
David Bainbridge99ac7a22019-08-31 02:26:43 +0000349 WITH_CHAOS \
David Bainbridge46505fb2019-10-01 21:13:20 +0000350 WITH_ADAPTERS \
351 WITH_SIM_ADAPTERS \
352 WITH_OPEN_ADAPTERS \
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -0800353 WITH_PORT_FORWARDS \
Matteo Scandoloefee0432020-05-05 13:56:20 -0700354 WITH_PPROF \
Girish Gowdra4cc5d8b2020-06-11 17:12:00 -0700355 WITH_INCREMENTAL_EVTO_UPDATE \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000356 JUST_K8S \
Matteo Scandoloe89384a2020-11-06 08:40:25 -0800357 JUST_INFRA \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000358 DEPLOY_K8S \
359 INSTALL_ONOS_APPS \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000360 INSTALL_KUBECTL \
361 INSTALL_HELM \
David Bainbridge7f8bf992020-04-08 21:53:22 -0700362 HELM_USE_UPGRADE \
David Bainbridge46505fb2019-10-01 21:13:20 +0000363 UPDATE_HELM_REPOS \
David Bainbridge4f1b5562019-08-19 04:46:52 +0000364 WAIT_ON_DOWN \
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700365 VOLTHA_DOWN_ON_TIMEOUT \
Matteo Scandoloc2eb0672020-05-01 14:43:15 -0700366 LEGACY_BBSIM_INDEX \
David Bainbridgee4d11ca2020-05-08 10:21:10 -0700367 SCHEDULE_ON_CONTROL_NODES \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000368 "
David Bainbridge5b7b96b2019-07-25 20:29:13 +0000369
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700370OPT_YES_NO="\
371 CONFIG_SADIS \
372 WITH_KAFKA \
373 WITH_RADIUS \
374 WITH_ETCD \
375 WITH_ONOS \
376 "
377
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000378ALL_OPTIONS="\
379 NAME \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000380 $ALL_YES_NO \
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700381 $OPT_YES_NO \
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700382 WAIT_TIMEOUT \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000383 VOLTHA_LOG_LEVEL \
384 VOLTHA_CHART \
David Bainbridge90fd8e32019-08-21 23:32:47 +0000385 VOLTHA_CHART_VERSION \
386 VOLTHA_BBSIM_CHART \
387 VOLTHA_BBSIM_CHART_VERSION \
David Bainbridge879439b2020-06-12 15:59:35 -0700388 BBSIM_SADIS_SERVER_CHART \
389 BBSIM_SADIS_SERVER_CHART_VERSION \
Girish Kumarcc5f9172020-06-10 13:34:31 +0000390 VOLTHA_TRACING_CHART \
391 VOLTHA_TRACING_CHART_VERSION \
uottrembd5a20572020-03-06 09:15:01 +0100392 NUM_OF_BBSIM \
Matteo Scandolo657e13c2020-07-28 11:41:42 -0700393 NUM_OF_WORKER_NODES \
394 NUM_OF_CONTROLLER_NODES \
395 NUM_OF_KAFKA \
396 NUM_OF_ETCD \
divyadesai59f987a2020-05-27 12:11:33 +0000397 ELASTICSEARCH_CHART \
398 ELASTICSEARCH_CHART_VERSION \
399 KIBANA_CHART \
400 KIBANA_CHART_VERSION \
401 FLUENTD_ELASTICSEARCH_CHART \
402 FLUENTD_ELASTICSEARCH_CHART_VERSION \
Matteo Scandolo67335f02020-04-09 11:19:53 -0700403 NUM_OF_OPENONU \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000404 VOLTHA_ADAPTER_SIM_CHART \
David Bainbridge90fd8e32019-08-21 23:32:47 +0000405 VOLTHA_ADAPTER_SIM_CHART_VERSION \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000406 VOLTHA_ADAPTER_OPEN_OLT_CHART \
David Bainbridge90fd8e32019-08-21 23:32:47 +0000407 VOLTHA_ADAPTER_OPEN_OLT_CHART_VERSION \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000408 VOLTHA_ADAPTER_OPEN_ONU_CHART \
David Bainbridge90fd8e32019-08-21 23:32:47 +0000409 VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION \
David K. Bainbridgeda33d652020-03-06 10:31:23 -0800410 ONOS_CHART \
Andrea Campanella21323292019-12-18 11:44:19 -0800411 ONOS_CHART_VERSION \
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700412 ONOS_CLASSIC_CHART \
413 ONOS_CLASSIC_CHART_VERSION \
David Bainbridgecf546362020-04-21 23:18:50 -0700414 KAFKA_CHART \
David Bainbridgeb9093522020-04-15 14:32:44 -0700415 KAFKA_CHART_VERSION \
David Bainbridge879439b2020-06-12 15:59:35 -0700416 ETCD_CHART \
417 ETCD_CHART_VERSION \
418 RADIUS_CHART \
419 RADIUS_CHART_VERSION \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000420 ONOS_API_PORT \
421 ONOS_SSH_PORT \
Hardik Windlassb3147602020-03-09 16:59:15 +0530422 SADIS_CFG \
Matteo Scandolo6402d362020-08-24 12:31:06 -0700423 BBSIM_CFG \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000424 VOLTHA_API_PORT \
425 VOLTHA_SSH_PORT \
426 VOLTHA_ETCD_PORT \
divyadesai59f987a2020-05-27 12:11:33 +0000427 ELASTICSEARCH_PORT \
428 KIBANA_PORT \
David K. Bainbridge00ecd382020-02-28 12:31:58 -0800429 VOLTHA_KAFKA_PORT \
Matteo Scandoloefee0432020-05-05 13:56:20 -0700430 VOLTHA_PPROF_PORT \
431 OPENOLT_PPROF_PORT \
Matteo Scandolo65c35192020-05-13 10:41:21 -0700432 OFAGENT_PPROF_PORT \
Girish Kumarcc5f9172020-06-10 13:34:31 +0000433 TRACING_GUI_PORT \
David K. Bainbridge8f7f30b2020-01-08 13:06:16 -0800434 VK_RELEASE \
435 KIND_VERSION \
436 VOLTCTL_VERSION \
David Bainbridgea34993d2020-04-01 09:15:42 -0700437 HELM_VERSION \
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700438 NUM_OF_ONOS \
439 NUM_OF_ATOMIX \
David Bainbridge6ca40102020-04-08 11:30:40 -0700440 VOLTHA_NS \
441 ADAPTER_NS \
442 INFRA_NS \
443 BBSIM_NS \
David Bainbridge7db44002020-04-09 12:54:29 -0700444 SADIS_BANDWIDTH_PROFILES \
445 SADIS_SUBSCRIBERS \
David Bainbridgeb4bbde12020-06-25 14:46:36 -0700446 PF_ADDRESS \
David K. Bainbridge2aa08da2020-07-31 12:49:45 -0700447 KIND_CFG_FILE \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000448 "
David Bainbridge01294952019-07-30 19:33:45 +0000449
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000450# Iterate over yes/no configuration options and validate
451for VAR in $ALL_YES_NO; do
David Bainbridged18f4942020-04-14 16:46:13 -0700452 eval "$VAR"="$(verify_yes_no "$VAR")"
453 if [ "$(eval echo "\$$VAR")" == "INVALID" ]; then
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000454 exit 1;
455 fi
456done
David Bainbridgeb270c202019-07-26 01:44:42 +0000457
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700458# Iterate over optional yes/no configuration options and
459# normalize values if they are truth values
460for VAR in $OPT_YES_NO; do
461 eval "$VAR"="$(normalize_yes_no "$VAR")"
462done
David Bainbridge15f6f232020-03-30 09:15:43 -0700463
Matteo Scandolo657e13c2020-07-28 11:41:42 -0700464# check number (range) of bbsim, max bbsim must not exceed 10 instances!
465# note: instances will be numbered from 0 to 9
466if [ "$1" == "up" ]; then
467 if [ "$NUM_OF_BBSIM" -lt 1 ]; then
468 >&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}"
469 exit 1
470 fi
471 if [ "$NUM_OF_BBSIM" -gt "$MAX_NUM_OF_BBSIM" ]; then
472 >&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}"
473 exit 1
474 fi
475
476 if [ "$NUM_OF_OPENONU" -lt 1 ]; then
477 >&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}"
478 exit 1
479 fi
480 if [ "$NUM_OF_OPENONU" -gt "$MAX_NUM_OF_OPENONU" ]; then
481 >&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}"
482 exit 1
483 fi
484
David K. Bainbridge2aa08da2020-07-31 12:49:45 -0700485 HAVE_CLUSTER="$(kind get clusters 2>/dev/null | grep -c "voltha-$NAME")"
486 if [ "$HAVE_CLUSTER" -eq 0 ]; then
487 # If the user has specified a kind cluster configuration file,
488 # 'KIND_CFG_FILE` then we need to gleem from that file the number
489 # of worker and controller nodes as this overrides any setting of
490 # these values
491 if [ -n "$KIND_CFG_FILE" ]; then
492 NUM_OF_WORKER_NODES="$(sed 's/ //g' "$KIND_CFG_FILE" | grep -c "^-role:worker$")"
493 NUM_OF_CONTROLLER_NODES="$(sed 's/ //g' "$KIND_CFG_FILE" | grep -c "^-role:control-plane$")"
494 fi
Matteo Scandolo657e13c2020-07-28 11:41:42 -0700495
David K. Bainbridge2aa08da2020-07-31 12:49:45 -0700496 # check that NUM_OF_KAFKA, NUM_OF_ONOS, NUM_OF_ATOMIX, NUM_OF_ETCD is:
497 # <= NUM_OF_WORKER_NODES + 1 if SCHEDULE_ON_CONTROL_NODES == y
498 # <= NUM_OF_WORKER_NODES if SCHEDULE_ON_CONTROL_NODES == n
499 SCHEDULABLE_NODES=$NUM_OF_WORKER_NODES
500
501 if [ "$SCHEDULE_ON_CONTROL_NODES" == "yes" ]; then
502 SCHEDULABLE_NODES=$((NUM_OF_CONTROLLER_NODES+NUM_OF_WORKER_NODES))
503 fi
504 else
505 TOTAL_NODES=$(kubectl get --all-namespaces nodes -o name | wc -l)
506 NUM_OF_CONTROLLER_NODES=$(kubectl get --all-namespaces nodes -l node-role.kubernetes.io/master -o name | wc -l)
507 NUM_OF_WORKER_NODES=$((TOTAL_NODES - NUM_OF_CONTROLLER_NODES))
508 # shellcheck disable=SC2016
509 SCHEDULABLE_NODES=$(kubectl get no -o 'go-template={{range .items}}{{$taints:=""}}{{range .spec.taints}}{{if eq .effect "NoSchedule"}}{{$taints = print $taints .key ","}}{{end}}{{end}}{{if not $taints}}{{.metadata.name}}{{ "\n"}}{{end}}{{end}}' | wc -l | sed -e 's/ //g')
510 rm -f "$TMP_KUBECFG"
Matteo Scandolo657e13c2020-07-28 11:41:42 -0700511 fi
Matteo Scandolo657e13c2020-07-28 11:41:42 -0700512 NODES="SCHEDULE_ON_CONTROL_NODES: $SCHEDULE_ON_CONTROL_NODES, SCHEDULABLE_NODES: $SCHEDULABLE_NODES, NUM_OF_CONTROLLER_NODES: $NUM_OF_CONTROLLER_NODES, NUM_OF_WORKER_NODES: $NUM_OF_WORKER_NODES"
513
David K. Bainbridge2aa08da2020-07-31 12:49:45 -0700514 if is_in "$WITH_KAFKA" "yes,external" && [ ! "$NUM_OF_KAFKA" -le "$SCHEDULABLE_NODES" ]; then
Matteo Scandolo657e13c2020-07-28 11:41:42 -0700515 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} Invalid setting of KAFKA replicas. NUM_OF_KAFKA (${NUM_OF_KAFKA}) is greater than the available nodes ($NODES)${NORMAL}"
516 exit 1
517 fi
518
David K. Bainbridge2aa08da2020-07-31 12:49:45 -0700519 if is_in "$WITH_ETCD" "yes,external" && [ ! "$NUM_OF_ETCD" -le "$SCHEDULABLE_NODES" ]; then
Matteo Scandolo657e13c2020-07-28 11:41:42 -0700520 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} Invalid setting of ETCD replicas. NUM_OF_ETCD (${NUM_OF_ETCD}) is greater than the available nodes ($NODES)${NORMAL}"
521 exit 1
522 fi
523
David K. Bainbridge2aa08da2020-07-31 12:49:45 -0700524 if is_in "$WITH_ONOS" "yes,legacy,classic,micro"; then
525 if [ ! "$NUM_OF_ATOMIX" -le "$SCHEDULABLE_NODES" ]; then
526 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} Invalid setting of ATOMIX replicas. NUM_OF_ATOMIX (${NUM_OF_ATOMIX}) is greater than the available nodes ($NODES)${NORMAL}"
527 exit 1
528 fi
Matteo Scandolo657e13c2020-07-28 11:41:42 -0700529
David K. Bainbridge2aa08da2020-07-31 12:49:45 -0700530 if [ ! "$NUM_OF_ONOS" -le "$SCHEDULABLE_NODES" ]; then
531 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} Invalid setting of ONOS replicas. NUM_OF_ONOS (${NUM_OF_ONOS}) is greater than the available nodes ($NODES)${NORMAL}"
532 exit 1
533 fi
Matteo Scandolo657e13c2020-07-28 11:41:42 -0700534 fi
535fi
536
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700537# normalize non-truth value options
538if is_in "$WITH_KAFKA" "e,external"; then
David Bainbridge76afd812020-04-06 09:53:52 -0700539 WITH_KAFKA="external"
540fi
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700541if is_in "$WITH_ETCD" "e,external"; then
David Bainbridge76afd812020-04-06 09:53:52 -0700542 WITH_ETCD="external"
543fi
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700544if is_in "$WITH_ONOS" "l,legacy"; then
545 WITH_ONOS="legacy"
546elif is_in "$WITH_ONOS" "c,classic"; then
547 WITH_ONOS="classic"
548elif is_in "$WITH_ONOS" "u,m,micro"; then
549 WITH_ONOS="micro"
David Bainbridge29c31cb2020-04-06 09:45:50 -0700550fi
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700551
552if [ "$WITH_ONOS" == "micro" ]; then
553 >&2 echo -e "${YELLOW}${BOLD}${ERROR}WARNING:${NORMAL}${YELLOW} The value specified as WITH_ONOS, '$WITH_ONOS', is not valid.${NORMAL}"
554 exit 1
David Bainbridge29c31cb2020-04-06 09:45:50 -0700555fi
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700556
557if is_in "$WITH_ONOS" "yes,classic"; then
558 # there is an extra utility required if we are using ONOS CLASSIC as
559 # the chart for classic specifies images differently
560 EXTRA_TOOLS+=" yq"
David Bainbridge76afd812020-04-06 09:53:52 -0700561fi
David Bainbridge696bc632020-04-05 21:49:37 -0700562
David Bainbridge22db5dd2020-05-26 12:21:21 -0700563if [ "$LEGACY_BBSIM_INDEX" == "no" ]; then
564 BBSIM_SADIS_SVC="bbsim0"
565else
566 BBSIM_SADIS_SVC="bbsim"
567fi
568
569SADIS_SUBSCRIBERS=${SADIS_SUBSCRIBERS:-http://$BBSIM_SADIS_SVC.$VOLTHA_NS.svc:50074/v2/subscribers/%s}
570SADIS_BANDWIDTH_PROFILES=${SADIS_BANDWIDTH_PROFILES:-http://$BBSIM_SADIS_SVC.$VOLTHA_NS.svc:50074/v2/bandwidthprofiles/%s}
571
David Bainbridged18f4942020-04-14 16:46:13 -0700572if [ "$HELM_USE_UPGRADE" == "yes" ]; then
David Bainbridge7f8bf992020-04-08 21:53:22 -0700573 _HELM_DESC="Upgrade/Install"
574else
575 _HELM_DESC="Install"
576fi
577
David K. Bainbridgeda33d652020-03-06 10:31:23 -0800578# Check for prerequiste tools
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700579TOOLS="curl sed jq $EXTRA_TOOLS"
David Bainbridged18f4942020-04-14 16:46:13 -0700580if [ "$DEPLOY_K8S" == "yes" ]; then
David K. Bainbridgeda33d652020-03-06 10:31:23 -0800581 TOOLS+=" docker"
582fi
583NOT_FOUND=""
584for T in $TOOLS; do
David Bainbridged18f4942020-04-14 16:46:13 -0700585 if [ -z "$(command -v "$T")" ]; then
David K. Bainbridgeda33d652020-03-06 10:31:23 -0800586 NOT_FOUND+=" $T"
587 fi
588done
589
David Bainbridged18f4942020-04-14 16:46:13 -0700590if [ -n "$NOT_FOUND" ]; then
David K. Bainbridgeda33d652020-03-06 10:31:23 -0800591 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} The following required tools where not found, please install them:$NOT_FOUND"
592 exit 1
593fi
594
David Bainbridged18f4942020-04-14 16:46:13 -0700595TIMEOUT_SECONDS="$(parseDuration "$WAIT_TIMEOUT")"
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700596
David Bainbridge0774b232019-08-02 06:37:19 +0000597mkdir -p .voltha
598touch .voltha/ports
David K. Bainbridge00ecd382020-02-28 12:31:58 -0800599
Matteo Scandoloe89384a2020-11-06 08:40:25 -0800600VOLTHA_API_PORT=55555
601START=$VOLTHA_API_PORT
Matteo Scandoloefee0432020-05-05 13:56:20 -0700602
Matteo Scandoloe89384a2020-11-06 08:40:25 -0800603# check if the stack deployed with $NAME already exists
604STACK_EXISTS=false
605if [ "$(grep -c "$NAME" .voltha/ports)" -eq 1 ]; then
606 STACK_EXISTS=true
607fi
608
609if [ "$STACK_EXISTS" == true ]; then
610 # if the stack was previously deployed reuse the ports
611 HAVE="$(grep "$NAME" .voltha/ports)"
612 VALUES="$(echo "$HAVE" | sed -e 's/\s//g' | cut -d= -f2)"
613 ONOS_API_PORT=$(echo "$VALUES" | cut -d, -f1)
614 ONOS_SSH_PORT=$(echo "$VALUES" | cut -d, -f2)
615 VOLTHA_API_PORT=$(echo "$VALUES" | cut -d, -f3)
616 VOLTHA_SSH_PORT=$(echo "$VALUES" | cut -d, -f4)
617 VOLTHA_ETCD_PORT=$(echo "$VALUES" | cut -d, -f5)
618 VOLTHA_KAFKA_PORT=$(echo "$VALUES" | cut -d, -f6)
619 VOLTHA_PPROF_PORT=$(echo "$VALUES" | cut -d, -f7)
620 OPENOLT_PPROF_PORT=$(echo "$VALUES" | cut -d, -f8)
621 OFAGENT_PPROF_PORT=$(echo "$VALUES" | cut -d, -f9)
622 ELASTICSEARCH_PORT=$(echo "$VALUES" | cut -d, -f10)
623 KIBANA_PORT=$(echo "$VALUES" | cut -d, -f11)
624 TRACING_GUI_PORT=$(echo "$VALUES" | cut -d, -f12)
625
626 # Some ports were added after the .voltha/ports files was created.
627 # Calculate the original DELTA from the VOLTHA_SSH_PORT so that it can
628 # be used to set up newer port-forwards.
629 DELTA="$((VOLTHA_SSH_PORT/100-50))"
630 if [ -z "$VOLTHA_KAFKA_PORT" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -0700631 VOLTHA_KAFKA_PORT=${VOLTHA_KAFKA_PORT:-$((90 + DELTA))92}
David K. Bainbridge00ecd382020-02-28 12:31:58 -0800632 fi
Matteo Scandoloefee0432020-05-05 13:56:20 -0700633
634 if [ -z "$VOLTHA_PPROF_PORT" ]; then
divyadesai59f987a2020-05-27 12:11:33 +0000635 VOLTHA_PPROF_PORT=${VOLTHA_PPROF_PORT:-$((60 + DELTA))60}
Matteo Scandoloefee0432020-05-05 13:56:20 -0700636 fi
637 if [ -z "$OPENOLT_PPROF_PORT" ]; then
divyadesai59f987a2020-05-27 12:11:33 +0000638 OPENOLT_PPROF_PORT=${OPENOLT_PPROF_PORT:-$((60 + DELTA))61}
Matteo Scandoloefee0432020-05-05 13:56:20 -0700639 fi
Matteo Scandolo65c35192020-05-13 10:41:21 -0700640 if [ -z "$OFAGENT_PPROF_PORT" ]; then
divyadesai59f987a2020-05-27 12:11:33 +0000641 OFAGENT_PPROF_PORT=${OFAGENT_PPROF_PORT:-$((60 + DELTA))62}
642 fi
643
644 if [ -z "$ELASTICSEARCH_PORT" ]; then
645 ELASTICSEARCH_PORT=${ELASTICSEARCH_PORT:-$((92 + DELTA))00}
646 fi
divyadesai59f987a2020-05-27 12:11:33 +0000647 if [ -z "$KIBANA_PORT" ]; then
648 KIBANA_PORT=${KIBANA_PORT:-$((56 + DELTA))01}
Matteo Scandolo65c35192020-05-13 10:41:21 -0700649 fi
Girish Kumarcc5f9172020-06-10 13:34:31 +0000650
651 if [ -z "$TRACING_GUI_PORT" ]; then
652 TRACING_GUI_PORT=${TRACING_GUI_PORT:-1$((66 + DELTA))86}
653 fi
Matteo Scandoloe89384a2020-11-06 08:40:25 -0800654else
655 # Find free port prefix
656 START=81
657 while true; do
658 if [ "$(grep -c $START .voltha/ports)" -eq 0 ]; then
659 break
660 fi
661 START="$((START + 1))"
662 done
663
664 # create new ports starting from the first available
665 DELTA="$((START - 81))"
666 ONOS_API_PORT=${START}81
667 ONOS_SSH_PORT=${START}01
668 VOLTHA_API_PORT=5$((55 + DELTA))55
669 VOLTHA_SSH_PORT=$((50 + DELTA))22
670 VOLTHA_ETCD_PORT=$((23 + DELTA))79
671 VOLTHA_KAFKA_PORT=$((90 + DELTA))92
672 VOLTHA_PPROF_PORT=$((60 + DELTA))60
673 OPENOLT_PPROF_PORT=$((60 + DELTA))61
674 OFAGENT_PPROF_PORT=$((60 + DELTA))62
675 ELASTICSEARCH_PORT=$((92 + DELTA))00
676 KIBANA_PORT=$((56 + DELTA))01
677 TRACING_GUI_PORT=$((66 + DELTA))86
Test User01ed0642019-07-03 20:17:06 +0000678fi
679
David Bainbridged18f4942020-04-14 16:46:13 -0700680PORTTMP="$(mktemp -u)"
681grep -v "$NAME" .voltha/ports > "$PORTTMP"
Girish Kumarcc5f9172020-06-10 13:34:31 +0000682echo "$NAME=$ONOS_API_PORT,$ONOS_SSH_PORT,$VOLTHA_API_PORT,$VOLTHA_SSH_PORT,$VOLTHA_ETCD_PORT,$VOLTHA_KAFKA_PORT,$VOLTHA_PPROF_PORT,$OPENOLT_PPROF_PORT,$OFAGENT_PPROF_PORT,$ELASTICSEARCH_PORT,$KIBANA_PORT,$TRACING_GUI_PORT" >> "$PORTTMP"
David Bainbridged18f4942020-04-14 16:46:13 -0700683cp "$PORTTMP" .voltha/ports
684rm -f "$PORTTMP"
David Bainbridge0774b232019-08-02 06:37:19 +0000685
David Bainbridge27790d62019-08-13 22:43:19 +0000686export ONOS_API_PORT ONOS_SSH_PORT
David Bainbridge01294952019-07-30 19:33:45 +0000687
Test Userd87942b2019-07-03 07:20:24 +0000688IDX=1
David Bainbridgee87067b2019-08-12 22:00:12 +0000689CLOCK="TIME:"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000690SPIN_PARTS=
691NOT_VERIFIED=
David Bainbridgef858a022019-08-14 21:25:11 +0000692THEX=
693BUILD=
David Bainbridge38dc1e82019-08-12 15:18:45 +0000694VERIFIED=
695HELM=
696OLD_KEY=
697BIRD=
698HIGH_VOLTAGE=
699PLUG=
David Bainbridge38dc1e82019-08-12 15:18:45 +0000700FORWARD=
David Bainbridge38dc1e82019-08-12 15:18:45 +0000701GO=
702DOWNLOAD=
703GEAR=
704NO_ENTRY=
705LOCK=
706
David Bainbridged18f4942020-04-14 16:46:13 -0700707if [ "$FANCY" -eq 1 ]; then
708 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 +0000709 CLOCK="\xe2\x8f\xb1"
David Bainbridgef858a022019-08-14 21:25:11 +0000710 THEX="${RED}${BOLD}\xe2\x9c\x97\x20${NORMAL}"
David Bainbridgef858a022019-08-14 21:25:11 +0000711 BUILD="${YELLOW}${BOLD}\xf0\x9f\x8f\x97${NORMAL}"
712 NOT_VERIFIED="$BUILD"
713 VERIFIED="${GREEN}${BOLD}\xe2\x9c\x93\x20${NORMAL}"
714 HELM="${BLUE}${BOLD}\xE2\x8E\x88${NORMAL}"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000715 OLD_KEY="\xF0\x9F\x97\x9D"
716 BIRD="\xF0\x9F\x90\xA6"
717 HIGH_VOLTAGE="\xE2\x9A\xA1"
718 PLUG="\xF0\x9F\xa7\xa9"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000719 FORWARD="\xE2\x87\xA8"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000720 GO="\xf0\x9f\x9a\x80"
721 DOWNLOAD="\xf0\x9f\x93\xa5"
722 GEAR="\xe2\x9a\x99"
723 NO_ENTRY="\xe2\x9b\x94"
724 LOCK="\xf0\x9f\x94\x92"
725fi
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700726
David Bainbridge712afb82019-08-14 19:55:58 +0000727duration() {
David Bainbridged18f4942020-04-14 16:46:13 -0700728 local h m s t
729 h="$(($1 / 3600))"
730 m="$(($1 % 3600 / 60))"
731 s="$(($1 % 60))"
732 t=""
David Bainbridgee87067b2019-08-12 22:00:12 +0000733
David Bainbridged18f4942020-04-14 16:46:13 -0700734 if [ "$h" -gt 0 ]; then
David Bainbridgee87067b2019-08-12 22:00:12 +0000735 t="$t${h}h"
736 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700737 if [ "$m" -gt 0 ]; then
David Bainbridgee87067b2019-08-12 22:00:12 +0000738 t="$t${m}m"
739 fi
David Bainbridge712afb82019-08-14 19:55:58 +0000740 echo "$t${s}s"
741}
742
743printtime() {
David Bainbridged18f4942020-04-14 16:46:13 -0700744 local INDENT
David Bainbridge712afb82019-08-14 19:55:58 +0000745 if [ "$1" == "-" ]; then
746 INDENT=" "
747 shift
748 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700749 echo -e "$INDENT $CLOCK $(duration "$1")"
David Bainbridgee87067b2019-08-12 22:00:12 +0000750}
751
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700752bspin() {
Test Userd87942b2019-07-03 07:20:24 +0000753 IDX=1
David Bainbridged18f4942020-04-14 16:46:13 -0700754 local INDENT
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700755 if [ "$1" == "-" ]; then
756 INDENT=" "
757 shift
758 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700759 if [ "$FANCY" -eq 0 ]; then
760 LINE="${*//[[:space:]+-]}"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000761 if [ "$LINE X" == " X" ]; then
762 return
763 fi
764 echo -e "$CIVIS$INDENT$*"
765 else
766 echo -en "$CIVIS$INDENT $*"
767 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700768}
769
770sspin() {
David Bainbridged18f4942020-04-14 16:46:13 -0700771 local INDENT
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700772 if [ "$1" == "-" ]; then
773 INDENT=" "
774 shift
775 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700776 if [ "$FANCY" -eq 0 ]; then
777 LINE="${*//[[:space:]+-]}"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000778 if [ "$LINE X" == " X" ]; then
779 return
780 fi
781 echo -e "$INDENT$*"
782 else
David Bainbridged18f4942020-04-14 16:46:13 -0700783 C="$(echo "$SPIN_PARTS" | cut '-d ' -f "$IDX")"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000784 echo -en "\r$INDENT$C $*"
David Bainbridged18f4942020-04-14 16:46:13 -0700785 IDX="$((IDX + 1))"
786 if [ "$IDX" -gt 8 ]; then
David Bainbridge38dc1e82019-08-12 15:18:45 +0000787 IDX=1
788 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700789 fi
790}
791
792espin() {
David Bainbridged18f4942020-04-14 16:46:13 -0700793 local INDENT
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700794 if [ "$1" == "-" ]; then
795 INDENT=" "
796 shift
797 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700798 if [ "$FANCY" -eq 0 ]; then
799 LINE="${*//[[:space:]+-]}"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000800 if [ "$LINE X" == " X" ]; then
801 return
802 fi
803 echo -e "$INDENT$*"
804 else
805 echo -e "\r$INDENT$*$CNORM"
806 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700807}
808
David Bainbridged18f4942020-04-14 16:46:13 -0700809if [ "$1" == "get" ] && [ "$2" == "voltconfig" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000810 echo "$HOME/.volt/config-$NAME"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000811 exit
812fi
813
David Bainbridgee4d11ca2020-05-08 10:21:10 -0700814if [ $# -ne 1 ] || ! is_in "$1" "up,down,dump,clean"; then
David Bainbridgeac7f8072019-08-01 22:15:33 +0000815 >&2 echo "What wouild you like to do today:"
816 >&2 echo " up - bring up voltha"
817 >&2 echo " down - tear down voltha"
Matteo Scandoloe89384a2020-11-06 08:40:25 -0800818 >&2 echo " clean - remove everything that kind-voltha created"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000819 >&2 echo " dump - create a debug dump of running system"
820 exit 1
821fi
822
divyadesai59f987a2020-05-27 12:11:33 +0000823do_curl() {
824 local DATA_ARGS CREDS CMD_ECHO CMD_OUTPUT SC_OUTPUT WAIT_START INDENTA EXTRAA NOW
825 local INDENT=$1
826 local OP=$2
827 local USER=$3
828 local PASS=$4
829 local URL=$5
830 local DATA_TYPE=$6
831 local DATA=$7
832 local MSG=$8
833 local VALID_RESULTS=$9
834 local EXTRA=${10}
835 local ICON=${11}
836
837 # Turn into an array for passing
838 INDENTA=()
839 if [ -n "$INDENT" ]; then
840 INDENTA=("$INDENT")
841 fi
842 IFS=' ' read -r -a EXTRAA <<< "$EXTRA"
David Bainbridge4f1b5562019-08-19 04:46:52 +0000843
David K. Bainbridgeb4b163b2020-02-19 15:55:06 -0800844 # Thanks to the latest version of ONOS using the return code 207 this gets a
845 # whole lot nastier. Can't thank them enough for doing this. So in order to
846 # capture the command and the output in the log file as well as capture the
847 # status code to verify it is 200 and not 207 mutltiple files and a bit of
848 # hackery must be used. Thanks again ONOS.
David Bainbridged18f4942020-04-14 16:46:13 -0700849 CMD_ECHO="$(mktemp -u)"
850 CMD_OUTPUT="$(mktemp -u)"
851 SC_OUTPUT="$(mktemp -u)"
852 WAIT_START="$(date +%s)"
David K. Bainbridgeb4b163b2020-02-19 15:55:06 -0800853
divyadesai59f987a2020-05-27 12:11:33 +0000854 CREDS=()
855 if [ -n "$USER" ]; then
856 CREDS=("--user" "$USER:$PASS")
857 fi
858
859 DATA_ARGS=()
860 if [ -n "$DATA" ]; then
861 if [ "$DATA_TYPE" == "file" ]; then
862 DATA_ARGS=("--data" "@$DATA")
863 elif [ "$DATA_TYPE" == "json" ]; then
864 DATA_ARGS=("--data" "$DATA")
865 fi
866 fi
867
868 bspin "${INDENTA[@]}" "$MSG" "$ICON"
David Bainbridge4f1b5562019-08-19 04:46:52 +0000869 while true; do
David Bainbridged18f4942020-04-14 16:46:13 -0700870 NOW="$(date +%s)"
871 if [ "$((NOW - WAIT_START))" -gt "$TIMEOUT_SECONDS" ]; then
divyadesai59f987a2020-05-27 12:11:33 +0000872 espin "${INDENTA[@]}" "$THEX"
David Bainbridged18f4942020-04-14 16:46:13 -0700873 rm -f "$CMD_ECHO" "$CMD_OUTPUT" "$SC_OUTPUT"
divyadesai59f987a2020-05-27 12:11:33 +0000874 doTimeout "$MSG"
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700875 fi
divyadesai59f987a2020-05-27 12:11:33 +0000876 (set -x; curl -sSL "${CREDS[@]}" -w "%{http_code}" -o "$CMD_OUTPUT" -X "$OP" "${EXTRAA[@]}" "$URL" "${DATA_ARGS[@]}" >"$SC_OUTPUT" 2>/dev/null) >>"$CMD_ECHO" 2>&1
877 RESULT=$?
David K. Bainbridgeb4b163b2020-02-19 15:55:06 -0800878 # Dump everything to the log
David Bainbridged18f4942020-04-14 16:46:13 -0700879 cat "$CMD_ECHO" >> "$LOG"
880 test -r "$CMD_OUTPUT" && cat "$CMD_OUTPUT" >> "$LOG"
881 SC="$(cat "$SC_OUTPUT")"
882 echo "RESPONSE CODE: $SC" >> "$LOG"
883 echo "ERROR CODE: $RESULT" >> "$LOG"
David K. Bainbridgeb4b163b2020-02-19 15:55:06 -0800884
885 # clean up temp files
David Bainbridged18f4942020-04-14 16:46:13 -0700886 rm -f "$CMD_ECHO" "$CMD_OUTPUT" "$SC_OUTPUT"
divyadesai59f987a2020-05-27 12:11:33 +0000887 if [ "$RESULT" -eq 0 ] && is_in "$SC" "$VALID_RESULTS"; then
David Bainbridge4f1b5562019-08-19 04:46:52 +0000888 break
889 fi
Matteo Scandolo9a77a732020-01-09 14:24:12 -0800890 sleep 1
divyadesai59f987a2020-05-27 12:11:33 +0000891 sspin "${INDENTA[@]}"
David Bainbridge4f1b5562019-08-19 04:46:52 +0000892 done
divyadesai59f987a2020-05-27 12:11:33 +0000893 espin "${INDENTA[@]}" "$VERIFIED"
894}
895
896push_onos_config() {
897 local DATA_TYPE=$1
898 local MSG=$2
899 local RESOURCE=$3
900 local DATA=$4
901
902 do_curl "-" "POST" "karaf" "karaf" "http://$_ONOS_API_EP/onos/v1/$RESOURCE" "$DATA_TYPE" "$DATA" "$MSG" "200" "--fail -H Content-Type:application/json" "$GEAR"
David Bainbridge4f1b5562019-08-19 04:46:52 +0000903}
904
Matteo Scandolo9a77a732020-01-09 14:24:12 -0800905check_onos_app_active() {
David Bainbridged18f4942020-04-14 16:46:13 -0700906 local APP_ID WAIT_START RESULT NOW
907 APP_ID=$1
908 WAIT_START="$(date +%s)"
Matteo Scandolo9a77a732020-01-09 14:24:12 -0800909
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700910 bspin - "Checking that $APP_ID is active $CLOCK"
911 while true; do
David Bainbridged18f4942020-04-14 16:46:13 -0700912 NOW="$(date +%s)"
913 if [ "$((NOW - WAIT_START))" -gt "$TIMEOUT_SECONDS" ]; then
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700914 espin - "$THEX"
915 doTimeout "waiting for ONOS application activation '$APP_ID'"
916 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700917 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 -0700918 break
919 fi
920 sleep 1
921 sspin -
922 done
923 sleep 5 # OSGI components take a little longer that the app to activate
David Bainbridged18f4942020-04-14 16:46:13 -0700924 espin - "$VERIFIED"
Matteo Scandolo9a77a732020-01-09 14:24:12 -0800925}
926
David Bainbridge4f1b5562019-08-19 04:46:52 +0000927override_onos_app() {
David Bainbridged18f4942020-04-14 16:46:13 -0700928 local APP NAME WAIT_START NOW
929 APP=$1
930 NAME="$(basename "$APP" | sed -e 's/^[0-9][0-9]*-//g' -e 's/-.*$//g')"
931 WAIT_START="$(date +%s)"
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700932
David Bainbridge4f1b5562019-08-19 04:46:52 +0000933 while true; do
David Bainbridged18f4942020-04-14 16:46:13 -0700934 NOW="$(date +%s)"
935 if [ "$((NOW - WAIT_START))" -gt "$TIMEOUT_SECONDS" ]; then
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700936 espin - "$THEX"
937 doTimeout "waiting to overwrite ONOS application '$APP'"
938 fi
David Bainbridge4f1b5562019-08-19 04:46:52 +0000939 sspin -
940 # Attempt to delete old version (if it exists)
David Bainbridged18f4942020-04-14 16:46:13 -0700941 (set -x; curl --fail -sSL --user karaf:karaf -X DELETE "http://$_ONOS_API_EP/onos/v1/applications/$NAME" >>"$LOG" 2>&1) >>"$LOG" 2>&1
942 RESULT=$?
David Bainbridge4f1b5562019-08-19 04:46:52 +0000943 sspin -
David Bainbridged18f4942020-04-14 16:46:13 -0700944 if [ $RESULT -ne 0 ]; then
David Bainbridge4f1b5562019-08-19 04:46:52 +0000945 continue
946 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700947 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 +0000948 break
949 fi
950 sleep .2
951 done
952}
953
954activate_onos_app() {
David Bainbridged18f4942020-04-14 16:46:13 -0700955 local MSG APP WAIT_START NOW
956 MSG="$1"
957 APP=$2
958 WAIT_START="$(date +%s)"
David Bainbridge4f1b5562019-08-19 04:46:52 +0000959
960 bspin - "$MSG $GO"
961 while true; do
David Bainbridged18f4942020-04-14 16:46:13 -0700962 NOW="$(date +%s)"
963 if [ "$((NOW - WAIT_START))" -gt "$TIMEOUT_SECONDS" ]; then
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700964 espin - "$THEX"
965 doTimeout "waiting to activate ONOS application '$APP'"
966 fi
David Bainbridge4f1b5562019-08-19 04:46:52 +0000967 sspin -
David Bainbridged18f4942020-04-14 16:46:13 -0700968 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 +0000969 break
970 fi
971 sleep .2
972 done
973 espin - "$VERIFIED"
974}
975
976count_pods() {
David Bainbridged18f4942020-04-14 16:46:13 -0700977 local NAMESPACE STATES LABELS CMD PODS
978 NAMESPACE=$1; shift
David Bainbridge4f1b5562019-08-19 04:46:52 +0000979 if [ "$NAMESPACE" == "all-namespaces" ]; then
980 NAMESPACE="--all-namespaces"
981 else
982 NAMESPACE="-n $NAMESPACE"
983 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700984 STATES=$1; shift
985 LABELS=$1; shift
986 CMD=("kubectl get $NAMESPACE $LABELS pod")
987 PODS=$(${CMD[*]} -o go-template="{{range .items}}{{.metadata.name}}/{{.status.phase}}/_{{range .status.containerStatuses}}{{.ready}}_{{end}} {{end}}")
David Bainbridge4f1b5562019-08-19 04:46:52 +0000988 local COUNT=0
989 local PATTERNS="$*"
990 for POD in $PODS; do
David Bainbridged18f4942020-04-14 16:46:13 -0700991 local NAME STATE CONTAINERS TOTAL FOUND
992 NAME="$(echo "$POD" | cut -d/ -f 1)"
993 STATE="$(echo "$POD" | cut -d/ -f 2)"
994 CONTAINERS="$(echo "$POD" | cut -d/ -f 3 | sed -e 's/_/ /g')"
995 if [ "$STATES" == "*" ] || [ "$(echo "$STATES" | grep -c ":$STATE:")" -ne 0 ]; then
996 TOTAL="$(echo "$CONTAINERS" | wc -w)"
997 FOUND="$(echo "$CONTAINERS" | grep -o true | wc -l)"
998 if [ "$TOTAL" -eq "$FOUND" ]; then
David Bainbridge4f1b5562019-08-19 04:46:52 +0000999 for PATTERN in $PATTERNS; do
David Bainbridged18f4942020-04-14 16:46:13 -07001000 if [[ "$NAME" =~ $PATTERN ]]; then
1001 COUNT="$((COUNT + 1))"
David Bainbridge4f1b5562019-08-19 04:46:52 +00001002 break
1003 fi
1004 done
1005 fi
1006 fi
1007 done
David Bainbridge4f1b5562019-08-19 04:46:52 +00001008 echo $COUNT
1009}
1010
1011wait_for_pods() {
David Bainbridged18f4942020-04-14 16:46:13 -07001012 local INDENT NAMESPACE EXPECT TYPE MESSAGE LABELS PATTERNS STATES HAVE ALL WAIT_START NOW
David Bainbridge4f1b5562019-08-19 04:46:52 +00001013 if [ "$1" == "-" ]; then
1014 INDENT=$1; shift
1015 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001016 NAMESPACE=$1; shift
1017 EXPECT=$1; shift
1018 TYPE=$1; shift
1019 MESSAGE=$1; shift
1020 LABELS=$1; shift
1021 PATTERNS=("$*")
1022 STATES=":Running:"
David Bainbridge99ac7a22019-08-31 02:26:43 +00001023 if [ "$TYPE" == "not" ]; then
1024 STATES="*"
1025 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001026 HAVE="$(count_pods "$NAMESPACE" "$STATES" "$LABELS" "${PATTERNS[@]}")"
1027 ALL=$HAVE
David Bainbridge4f1b5562019-08-19 04:46:52 +00001028 if [ "$TYPE" == "only" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001029 ALL="$(count_pods "all-namespaces" "*" ".*")"
David Bainbridge4f1b5562019-08-19 04:46:52 +00001030 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001031 COUNT="$((300 / 15))"
1032 WAIT_START="$(date +%s)"
1033 bspin "$INDENT" "$MESSAGE"
1034 sspin "$INDENT"
1035 if [ "$HAVE" -ne "$EXPECT" ] || [ "$ALL" -ne "$HAVE" ]; then
1036 while [ "$HAVE" -ne "$EXPECT" ] || [ "$ALL" -ne "$HAVE" ]; do
1037 NOW="$(date +%s)"
1038 if [ "$((NOW - WAIT_START))" -gt "$TIMEOUT_SECONDS" ]; then
1039 espin "$INDENT" "$THEX"
David Bainbridge52e6e9d2020-03-23 13:48:27 -07001040 doTimeout "waiting for PODs to start"
1041 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001042 sspin "$INDENT"
1043 COUNT="$((COUNT - 1))"
1044 if [ "$COUNT" -eq 0 ]; then
1045 HAVE="$(count_pods "$NAMESPACE" "$STATES" "$LABELS" "${PATTERNS[@]}")"
1046 ALL="$HAVE"
David Bainbridge4f1b5562019-08-19 04:46:52 +00001047 if [ "$TYPE" == "only" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001048 ALL="$(count_pods "all-namespaces" "*" ".*")"
David Bainbridge4f1b5562019-08-19 04:46:52 +00001049 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001050 COUNT="$((300 / 15))"
David Bainbridge4f1b5562019-08-19 04:46:52 +00001051 fi
1052 sleep .15
1053 done
1054 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001055 espin "$INDENT" "$VERIFIED"
1056 if [ "$HAVE" -ne "$EXPECT" ]; then
David Bainbridge4f1b5562019-08-19 04:46:52 +00001057 return 1
1058 fi
1059 return 0
1060}
1061
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -08001062port_forward() {
David Bainbridge60ffc0f2020-04-27 22:13:22 -07001063 local NS=$1; shift
1064 local SVC=$1; shift
1065 local PORTS="$*"
Matteo Scandoloe89384a2020-11-06 08:40:25 -08001066 local TAG=$SVC-$NS-$NAME
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -08001067
David Bainbridgeb4bbde12020-06-25 14:46:36 -07001068 (set -x; _TAG="$TAG" bash -c "while true; do kubectl port-forward --address $PF_ADDRESS -n $NS service/$SVC $PORTS; done" >>"$PFLOG" 2>&1 &) >>"$PFLOG" 2>&1
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -08001069}
1070
1071kill_port_forward() {
Matteo Scandoloe89384a2020-11-06 08:40:25 -08001072 local TAG P_IDS PARENTS KIDS UNKNOWN PP_ID PF NS
David Bainbridge1d2c5842020-06-03 15:29:07 -07001073
1074 while [ $# -gt 0 ]; do
Matteo Scandoloe89384a2020-11-06 08:40:25 -08001075 NS=$1; shift
David Bainbridge1d2c5842020-06-03 15:29:07 -07001076 PF=$1; shift
1077 TAG=
1078 if [ "$PF" != "__ALL__" ]; then
Matteo Scandoloe89384a2020-11-06 08:40:25 -08001079 TAG=$SVC-$NS-$NAME
David Bainbridge1d2c5842020-06-03 15:29:07 -07001080 fi
1081 PARENTS=
1082 KIDS=
1083 UNKNOWN=
1084 # shellcheck disable=SC2009
1085 P_IDS="$(ps e -ww -A | grep "_TAG=$TAG" | grep -v grep | awk '{print $1}')"
1086 if [ -n "$P_IDS" ]; then
1087 for P_ID in $P_IDS; do
1088 PP_ID="$(ps -o ppid "$P_ID" | tail -n +2)"
1089 if [ -n "$PP_ID" ]; then
1090 if [ "$PP_ID" -eq 1 ]; then
1091 PARENTS="$PARENTS $P_ID"
1092 else
1093 KIDS="$KIDS $P_ID"
1094 fi
David Bainbridgec6871d22019-11-13 17:10:31 +00001095 else
David Bainbridge1d2c5842020-06-03 15:29:07 -07001096 UNKNOWN="$UNKNOWN $P_ID"
David Bainbridgec6871d22019-11-13 17:10:31 +00001097 fi
David Bainbridge1d2c5842020-06-03 15:29:07 -07001098 done
1099 if [ -n "$PARENTS" ]; then
1100 # shellcheck disable=SC2086
1101 while ps -h $PARENTS >/dev/null 2>&1; do
1102 (set -x; eval "kill -9 $PARENTS" >>"$LOG" 2>&1) >>"$LOG" 2>&1
1103 done
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -08001104 fi
David Bainbridge1d2c5842020-06-03 15:29:07 -07001105 if [ -n "$KIDS" ]; then
1106 # shellcheck disable=SC2086
1107 while ps -h $KIDS >/dev/null 2>&1; do
1108 (set -x; eval "kill -9 $KIDS" >>"$LOG" 2>&1) >>"$LOG" 2>&1
1109 done
1110 fi
1111 if [ -n "$UNKNOWN" ]; then
1112 # shellcheck disable=SC2086
1113 while ps -h $UNKNOWN >/dev/null 2>&1; do
1114 (set -x; eval "kill -9 $UNKNOWN" >>"$LOG" 2>&1) >>"$LOG" 2>&1
1115 done
1116 fi
1117 fi
1118 done
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -08001119}
1120
Girish Kumarcc5f9172020-06-10 13:34:31 +00001121resolve_chart_name() {
1122 helm inspect chart "$1" | grep "^name:" | awk '{print $2}'
1123}
1124
David Bainbridgecf546362020-04-21 23:18:50 -07001125resolve_chart_version() {
1126 [ "$2" != "latest" ] && echo "$2" && return
1127 helm inspect chart "$1" | grep "^version:" | awk '{print $2}'
1128}
1129
Jonathan Hart6a91e6c2020-04-16 14:28:33 -07001130# Compares two semver-formatted version strings (e.g. 2.4.3)
1131# Returns 0 if $1 == $2, returns 1 if $1 > $2 and returns 2 if $1 < $2
1132compare_versions() {
1133 [ "$1" == "$2" ] && return 0
Jonathan Hart6a91e6c2020-04-16 14:28:33 -07001134 local lowest
1135 lowest=$(echo -e "$1\n$2" | sort -V | head -1)
1136 [ "$lowest" == "$1" ] && return 2
1137 return 1
1138}
1139
David Bainbridgeac7f8072019-08-01 22:15:33 +00001140if [ "$1" == "down" ]; then
Matteo Scandoloe89384a2020-11-06 08:40:25 -08001141 # NOTE ./voltha down tears down all the stacks, it should only remove components in the specified namespaces
David Bainbridge0774b232019-08-02 06:37:19 +00001142 echo "Tearing down voltha cluster $NAME"
Matteo Scandoloe89384a2020-11-06 08:40:25 -08001143
David Bainbridge0774b232019-08-02 06:37:19 +00001144 LOG="down-$NAME.log"
David Bainbridged18f4942020-04-14 16:46:13 -07001145 date -u +"%Y%m%dT%H%M%SZ" >"$LOG"
David Bainbridgeb4bbde12020-06-25 14:46:36 -07001146 HELM_MAJOR=$(helm version --client --short | sed -E -e 's/^.*v([0-9]+)\.[0-9]+\.[0-9]+.*$/\1/')
David Bainbridge60ffc0f2020-04-27 22:13:22 -07001147 if is_in "$WITH_ONOS" "yes,legacy,classic"; then
David Bainbridge696bc632020-04-05 21:49:37 -07001148 bspin "Remove port-forwards: onos-ui-$NAME"
Matteo Scandoloe89384a2020-11-06 08:40:25 -08001149 kill_port_forward "$INFRA_NS" onos-ui
David Bainbridge696bc632020-04-05 21:49:37 -07001150 sspin "Remove port-forwards: onos-ssh-$NAME$CEOL"
Matteo Scandoloe89384a2020-11-06 08:40:25 -08001151 kill_port_forward "$INFRA_NS" onos-ssh
David K. Bainbridge2aa08da2020-07-31 12:49:45 -07001152 sspin "Remove port-forwards: onos-onos-classic-hs-$NAME$CEOL"
Matteo Scandoloe89384a2020-11-06 08:40:25 -08001153 kill_port_forward "$INFRA_NS" onos-onos-classic-hs
David Bainbridge696bc632020-04-05 21:49:37 -07001154 fi
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -08001155 sspin "Remove port-forwards: voltha-api-$NAME$CEOL"
Matteo Scandoloe89384a2020-11-06 08:40:25 -08001156 kill_port_forward "$VOLTHA_NS" voltha-api
1157 kill_port_forward "$VOLTHA_NS" voltha-voltha-api
David Bainbridgec7220622020-05-28 12:31:47 -07001158 if is_in "$WITH_ETCD" "yes,external"; then
1159 sspin "Remove port-forwards: etcd-$NAME$CEOL"
Matteo Scandoloe89384a2020-11-06 08:40:25 -08001160 kill_port_forward "$INFRA_NS" "etcd"
David Bainbridge696bc632020-04-05 21:49:37 -07001161 fi
David Bainbridgec7220622020-05-28 12:31:47 -07001162 if is_in "$WITH_KAFKA" "yes,external"; then
1163 sspin "Remove port-forwards: kafka-$NAME$CEOL"
Matteo Scandoloe89384a2020-11-06 08:40:25 -08001164 kill_port_forward "$INFRA_NS" "kafka"
David Bainbridge696bc632020-04-05 21:49:37 -07001165 fi
Matteo Scandoloefee0432020-05-05 13:56:20 -07001166
Andrea Campanellaeacf7f42020-10-15 14:46:33 +02001167 if is_in "$WITH_BBSIM" "yes"; then
1168 sspin "Remove port-forwards: bbsim$CEOL"
Matteo Scandoloe89384a2020-11-06 08:40:25 -08001169 kill_port_forward "$VOLTHA_NS" bbsim
Andrea Campanellaeacf7f42020-10-15 14:46:33 +02001170 fi
1171
Matteo Scandoloefee0432020-05-05 13:56:20 -07001172 if [ "$WITH_PPROF" == "yes" ]; then
David Bainbridgec7220622020-05-28 12:31:47 -07001173 sspin "Remove port-forwards: *-profiler$CEOL"
Matteo Scandoloe89384a2020-11-06 08:40:25 -08001174 kill_port_forward "$VOLTHA_NS" voltha-rw-core-profiler
1175 kill_port_forward "$VOLTHA_NS" voltha-voltha-rw-core-profiler
1176 kill_port_forward "$VOLTHA_NS" voltha-of-agent-profiler
1177 kill_port_forward "$VOLTHA_NS" voltha-voltha-of-agent-profiler
David Bainbridgec7220622020-05-28 12:31:47 -07001178 if [ "$WITH_OPEN_ADAPTERS" == "yes" ]; then
Matteo Scandoloe89384a2020-11-06 08:40:25 -08001179 kill_port_forward "$VOLTHA_NS" adapter-open-olt-profiler
1180 kill_port_forward "$VOLTHA_NS" open-olt-adapter-open-olt-profiler
David Bainbridgec7220622020-05-28 12:31:47 -07001181 fi
Matteo Scandoloefee0432020-05-05 13:56:20 -07001182 fi
1183
Girish Kumarcc5f9172020-06-10 13:34:31 +00001184 if [ "$WITH_TRACING" == "yes" ]; then
1185 sspin "Remove port-forwards: tracing-$NAME$CEOL"
1186 VOLTHA_TRACING_CHART_NAME=$(resolve_chart_name "$VOLTHA_TRACING_CHART")
Matteo Scandoloe89384a2020-11-06 08:40:25 -08001187 kill_port_forward "$INFRA_NS" "tracing-${VOLTHA_TRACING_CHART_NAME}-jaeger-gui"
Girish Kumarcc5f9172020-06-10 13:34:31 +00001188 fi
1189
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -08001190 espin "$VERIFIED Remove port-forwards$CEOL"
David Bainbridged18f4942020-04-14 16:46:13 -07001191 if [ "$DEPLOY_K8S" == "yes" ]; then
David Bainbridgeac7f8072019-08-01 22:15:33 +00001192 if [ -x ./bin/kind ]; then
David Bainbridge0774b232019-08-02 06:37:19 +00001193 bspin "Delete Kubernetes Kind Cluster"
David Bainbridged18f4942020-04-14 16:46:13 -07001194 (set -x; ./bin/kind delete cluster --name "voltha-$NAME" >>"$LOG" 2>&1) >>"$LOG" 2>&1
1195 espin "$VERIFIED"
David Bainbridgeac7f8072019-08-01 22:15:33 +00001196 else
David Bainbridge0774b232019-08-02 06:37:19 +00001197 espin "$NO_ENTRY Delete Kubernetes Kind Cluster: kind command not found"
David Bainbridgeac7f8072019-08-01 22:15:33 +00001198 fi
1199 else
David Bainbridge309099c2020-05-05 08:47:29 -07001200 if [ "$CONFIG_SADIS" == "external" ]; then
1201 bspin "Remove configmap for BBSIM SADIS server"
1202 (set -x; kubectl -n "$BBSIM_NS" delete --ignore-not-found configmap kube-config >>"$LOG" 2>&1) >>"$LOG" 2>&1
1203 espin "$VERIFIED"
1204 fi
David Bainbridgeb4bbde12020-06-25 14:46:36 -07001205
1206 if [ "$HELM_MAJOR" -le 2 ]; then
1207 EXISTS=$(helm list --output json 2>/dev/null | jq -r '.Releases | .[] | .Name + "," + .Namespace')
1208 else
1209 EXISTS=$(helm list --all-namespaces --output json 2>/dev/null | jq -r '.[] | .name + "," + .namespace')
1210 fi
David Bainbridge76afd812020-04-06 09:53:52 -07001211 EXPECT="voltha"
David Bainbridge60ffc0f2020-04-27 22:13:22 -07001212 if is_in "$WITH_ONOS" "yes,legacy,classic"; then
David Bainbridge696bc632020-04-05 21:49:37 -07001213 EXPECT+=" onos"
1214 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001215 if [ "$WITH_RADIUS" == "yes" ]; then
David Bainbridge696bc632020-04-05 21:49:37 -07001216 EXPECT+=" radius"
1217 fi
David Bainbridge309099c2020-05-05 08:47:29 -07001218 if [ "$CONFIG_SADIS" == "external" ]; then
1219 EXPECT+=" bbsim-sadis-server"
1220 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001221 if [ "$WITH_BBSIM" == "yes" ]; then
David Bainbridge696bc632020-04-05 21:49:37 -07001222 EXPECT+=" bbsim"
1223 fi
divyadesai59f987a2020-05-27 12:11:33 +00001224 if [ "$WITH_EFK" == "yes" ]; then
1225 EXPECT+=" elasticsearch kibana fluentd"
1226 fi
Girish Kumarcc5f9172020-06-10 13:34:31 +00001227 if [ "$WITH_TRACING" == "yes" ]; then
1228 EXPECT+=" tracing"
1229 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001230 if [ "$WITH_OPEN_ADAPTERS" == "yes" ]; then
David Bainbridge696bc632020-04-05 21:49:37 -07001231 EXPECT+=" open-olt open-onu"
1232 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001233 if [ "$WITH_SIM_ADAPTERS" == "yes" ]; then
David Bainbridge696bc632020-04-05 21:49:37 -07001234 EXPECT+=" sim"
1235 fi
David Bainbridgec7220622020-05-28 12:31:47 -07001236 if is_in "$WITH_ETCD" "yes,external"; then
1237 EXPECT+=" etcd"
David Bainbridge76afd812020-04-06 09:53:52 -07001238 fi
David Bainbridgec7220622020-05-28 12:31:47 -07001239 if is_in "$WITH_KAFKA" "yes,external"; then
David Bainbridge76afd812020-04-06 09:53:52 -07001240 EXPECT+=" kafka"
1241 fi
David Bainbridge0774b232019-08-02 06:37:19 +00001242 bspin "Remove Helm Deployments"
David Bainbridgeac7f8072019-08-01 22:15:33 +00001243 for i in $EXISTS; do
David K. Bainbridge43422402020-03-06 07:41:22 -08001244 for j in $EXPECT; do
David Bainbridged18f4942020-04-14 16:46:13 -07001245 if [[ "$i" =~ $j ]]; then
David Bainbridgeb4bbde12020-06-25 14:46:36 -07001246 __NAME=$(echo "$i" | cut -d, -f1)
1247 __NS=$(echo "$i" | cut -d, -f2)
1248 sspin "Remove Helm Deployments: $__NS:$__NAME$CEOL"
1249 if [ "$HELM_MAJOR" -le 2 ]; then
1250 (set -x; helm delete --no-hooks --purge "$__NAME" >>"$LOG" 2>&1) >>"$LOG" 2>&1
1251 else
1252 (set -x; helm uninstall --no-hooks --namespace "$__NS" "$__NAME" >>"$LOG" 2>&1) >>"$LOG" 2>&1
1253 fi
David K. Bainbridge43422402020-03-06 07:41:22 -08001254 fi
1255 done
uottrembb16d3982020-02-28 08:34:36 +01001256 done
David Bainbridge0774b232019-08-02 06:37:19 +00001257 espin "$VERIFIED Remove Helm Deployments$CEOL"
David Bainbridge4f1b5562019-08-19 04:46:52 +00001258 if [ "$WAIT_ON_DOWN" == "yes" ]; then
Matteo Scandoloe93c9eb2020-06-03 12:08:51 -07001259 PODS="voltha-ofagent.* voltha-rw-core.*"
David Bainbridge76afd812020-04-06 09:53:52 -07001260 INFRA_PODS=
1261 ADAPT_PODS=
1262 SIM_PODS=
divyadesai59f987a2020-05-27 12:11:33 +00001263 EFK_PODS=
David Bainbridged18f4942020-04-14 16:46:13 -07001264 if [ "$WITH_RADIUS" == "yes" ]; then
David Bainbridge696bc632020-04-05 21:49:37 -07001265 PODS+=" radius.*"
1266 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001267 if [ "$WITH_BBSIM" == "yes" ]; then
David Bainbridge76afd812020-04-06 09:53:52 -07001268 SIM_PODS+=" bbsim.*"
David Bainbridge696bc632020-04-05 21:49:37 -07001269 fi
divyadesai59f987a2020-05-27 12:11:33 +00001270 if [ "$WITH_EFK" == "yes" ]; then
1271 EFK_PODS+=" kibana-* elasticsearch-* fluentd-*"
1272 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001273 if [ "$WITH_OPEN_ADAPTERS" ] || [ "$WITH_SIM_ADAPTERS" ]; then
David Bainbridge76afd812020-04-06 09:53:52 -07001274 ADAPT_PODS+=" adapter-*"
David Bainbridge696bc632020-04-05 21:49:37 -07001275 fi
Girish Kumarcc5f9172020-06-10 13:34:31 +00001276 if [ "$WITH_TRACING" == "yes" ]; then
1277 INFRA_PODS+=" jaeger.*"
1278 fi
David Bainbridge60ffc0f2020-04-27 22:13:22 -07001279 if is_in "$WITH_ONOS" "yes,legacy,classic"; then
David Bainbridge76afd812020-04-06 09:53:52 -07001280 INFRA_PODS+=" onos-.*"
1281 fi
David Bainbridgec7220622020-05-28 12:31:47 -07001282 if is_in "$WITH_ETCD" "yes,external"; then
1283 INFRA_PODS+=" etcd.*"
David Bainbridge76afd812020-04-06 09:53:52 -07001284 fi
David Bainbridgec7220622020-05-28 12:31:47 -07001285 if is_in "$WITH_KAFKA" "yes,external"; then
David Bainbridge76afd812020-04-06 09:53:52 -07001286 INFRA_PODS+=" kafka.*"
1287 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001288 if [ -n "$SIM_PODS" ]; then
1289 wait_for_pods "$BBSIM_NS" 0 "not" "Waiting for BBSIM PODs to terminate" "$BBSIM_LABEL" "$SIM_PODS"
David Bainbridge76afd812020-04-06 09:53:52 -07001290 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001291 if [ -n "$INFRA_PODS" ]; then
1292 wait_for_pods "$INFRA_NS" 0 "not" "Waiting for infrastructure PODs to terminate" "$NO_LABEL" "$INFRA_PODS"
David Bainbridge76afd812020-04-06 09:53:52 -07001293 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001294 if [ -n "$ADAPT_PODS" ]; then
1295 wait_for_pods "$ADAPTER_NS" 0 "not" "Waiting for adapter PODs to terminate" "$NO_LABEL" "$ADAPT_PODS"
David Bainbridge76afd812020-04-06 09:53:52 -07001296 fi
divyadesai59f987a2020-05-27 12:11:33 +00001297 if [ -n "$EFK_PODS" ]; then
1298 wait_for_pods "$INFRA_NS" 0 "not" "Waiting for EFK PODs to terminate" "$NO_LABEL" "$EFK_PODS"
1299 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001300 wait_for_pods "$VOLTHA_NS" 0 "not" "Waiting for VOLTHA PODs to terminate" "$NO_LABEL" "$PODS"
David Bainbridge4f1b5562019-08-19 04:46:52 +00001301 fi
David Bainbridgeac7f8072019-08-01 22:15:33 +00001302 fi
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001303 exit
David Bainbridgeac7f8072019-08-01 22:15:33 +00001304fi
1305
1306if [ "$1" == "dump" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +00001307 LOG="dump-$NAME.log"
David Bainbridged18f4942020-04-14 16:46:13 -07001308 TS="$(date -u +"%Y%m%dT%H%M%SZ")"
1309 if [ -n "$DUMP_FROM" ]; then
1310 TS=${DUMP_FROM//[:-]}
David Bainbridge76514a02019-10-08 01:50:35 +00001311 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001312 WORK="$(mktemp -u -d)"
David Bainbridge0774b232019-08-02 06:37:19 +00001313 DATA=$WORK/voltha-debug-dump-$NAME-$TS
David Bainbridged18f4942020-04-14 16:46:13 -07001314 mkdir -p "$DATA"
1315 echo "$TS" > "$LOG"
David Bainbridge0774b232019-08-02 06:37:19 +00001316 echo -e "Capturing debug dump to voltha-debug-dump-$NAME-$TS.tgz"
David Bainbridgeac7f8072019-08-01 22:15:33 +00001317 bspin - "Copy install log"
David Bainbridged18f4942020-04-14 16:46:13 -07001318 if [ -f "install-$NAME.log" ]; then
1319 (set -x; cp "install-$NAME.log" "$DATA/install-$NAME.log") >>"$LOG" 2>&1
1320 espin - "$VERIFIED"
David Bainbridgeac7f8072019-08-01 22:15:33 +00001321 else
David Bainbridge0774b232019-08-02 06:37:19 +00001322 espin - "$NO_ENTRY Copy install log: install-$NAME.log not found"
David Bainbridgeac7f8072019-08-01 22:15:33 +00001323 fi
1324 bspin - "Dumping Kubernetes PODs"
David Bainbridged18f4942020-04-14 16:46:13 -07001325 (set -x; kubectl get --all-namespaces pods >> "$DATA/all-pods.txt" 2>&1) >>"$LOG" 2>&1
1326 espin - "$VERIFIED"
David Bainbridgeac7f8072019-08-01 22:15:33 +00001327 bspin - "Dumping Kubernetes SERVICEs"
David Bainbridged18f4942020-04-14 16:46:13 -07001328 (set -x; kubectl get --all-namespaces svc >> "$DATA/all-services.txt" 2>&1) >>"$LOG" 2>&1
1329 espin - "$VERIFIED"
David Bainbridgeac7f8072019-08-01 22:15:33 +00001330 bspin - "Dumping Kubernetes EVENTs"
David Bainbridged18f4942020-04-14 16:46:13 -07001331 (set -x; kubectl get --all-namespaces events >> "$DATA/all-events.txt" 2>&1) >>"$LOG" 2>&1
1332 espin - "$VERIFIED"
David Bainbridgeac7f8072019-08-01 22:15:33 +00001333 bspin - "Dumping VOLTHA POD details"
David Bainbridged18f4942020-04-14 16:46:13 -07001334 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 +00001335 SINCE=
David Bainbridged18f4942020-04-14 16:46:13 -07001336 if [ -n "$DUMP_FROM" ]; then
David Bainbridgecfd7ca12019-10-06 03:31:41 +00001337 SINCE="--since-time=$DUMP_FROM"
1338 fi
David Bainbridgeac7f8072019-08-01 22:15:33 +00001339 for POD in $PODS; do
David Bainbridged18f4942020-04-14 16:46:13 -07001340 NS="$(echo "$POD" | cut -d: -f1)"
1341 POD="$(echo "$POD" | cut -d: -f2)"
David Bainbridgeac7f8072019-08-01 22:15:33 +00001342 sspin - "Dumping VOLTHA POD details: $POD$CEOL"
David Bainbridged18f4942020-04-14 16:46:13 -07001343 mkdir -p "$DATA/$POD"
1344 (set -x; kubectl describe -n "$NS" "$POD" >> "$DATA/$POD/describe.txt" 2>&1) >>"$LOG" 2>&1
David Bainbridgeac7f8072019-08-01 22:15:33 +00001345 sspin - "Dumping VOLTHA POD details: $POD"
David Bainbridged18f4942020-04-14 16:46:13 -07001346 (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 +00001347 sspin - "Dumping VOLTHA POD details: $POD"
David Bainbridged18f4942020-04-14 16:46:13 -07001348 (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 +00001349 sspin - "Dumping VOLTHA POD details: $POD"
1350 done
1351 espin - "$VERIFIED Dumping VOLTHA POD details$CEOL"
1352 bspin - "Dumping ETCD"
David Bainbridged18f4942020-04-14 16:46:13 -07001353 if [ -n "$(command -v etcdctl)" ]; then
1354 (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
1355 espin - "$VERIFIED"
David Bainbridgeac7f8072019-08-01 22:15:33 +00001356 else
1357 espin - "$NO_ENTRY Dumping ETCD: etcdctl command not available"
1358 fi
David Bainbridge0774b232019-08-02 06:37:19 +00001359 bspin - "Creating compressed TAR: voltha-debug-dump-$NAME-$TS.tgz"
David Bainbridged18f4942020-04-14 16:46:13 -07001360 (set -x; tar -C "$WORK" -zcf "voltha-debug-dump-$NAME-$TS.tgz" "./voltha-debug-dump-$NAME-$TS") >>"$LOG" 2>&1
1361 espin - "$VERIFIED"
David Bainbridgeac7f8072019-08-01 22:15:33 +00001362 bspin - "Cleanup"
David Bainbridged18f4942020-04-14 16:46:13 -07001363 (set -x; rm -rf "$WORK") >>"$LOG" 2>&1
1364 espin - "$VERIFIED"
1365 bspin - "$(ls -l "voltha-debug-dump-$NAME-$TS.tgz")"
1366 espin - "$VERIFIED"
David Bainbridgeac7f8072019-08-01 22:15:33 +00001367 exit
1368fi
1369
David Bainbridge0774b232019-08-02 06:37:19 +00001370LOG="install-$NAME.log"
David Bainbridge1d2c5842020-06-03 15:29:07 -07001371PFLOG="port-forward-$NAME.log"
David Bainbridged18f4942020-04-14 16:46:13 -07001372date > "$LOG"
Girish Kumarcc5f9172020-06-10 13:34:31 +00001373echo "PORTS=$ONOS_API_PORT,$ONOS_SSH_PORT,$VOLTHA_API_PORT,$VOLTHA_SSH_PORT,$VOLTHA_ETCD_PORT,$VOLTHA_KAFKA_PORT,$VOLTHA_PPROF_PORT,$OPENOLT_PPROF_PORT,$OFAGENT_PPROF_PORT,$ELASTICSEARCH_PORT,$KIBANA_PORT,$TRACING_GUI_PORT" >> "$LOG"
David Bainbridgeac7f8072019-08-01 22:15:33 +00001374
1375# Output install options to log
David Bainbridged18f4942020-04-14 16:46:13 -07001376echo "OPTIONS" >> "$LOG"
David Bainbridgeac7f8072019-08-01 22:15:33 +00001377for O in $ALL_OPTIONS; do
David Bainbridged18f4942020-04-14 16:46:13 -07001378 VAL="$(eval echo "\$$O")"
1379 if [ -n "$VAL" ]; then
1380 printf " %-30s = %s\n" "$O" "$VAL" >> "$LOG"
David Bainbridgeac7f8072019-08-01 22:15:33 +00001381 fi
1382done
1383
Matteo Scandoloe89384a2020-11-06 08:40:25 -08001384# Remove everything we created and set
David Bainbridgee4d11ca2020-05-08 10:21:10 -07001385if [ "$1" == "clean" ]; then
Matteo Scandoloe89384a2020-11-06 08:40:25 -08001386 echo "Cleaning up the system"
1387 kill_port_forward all-namespaces __ALL__
David Bainbridgee4d11ca2020-05-08 10:21:10 -07001388 exit
1389fi
1390
David Bainbridgefad50732020-05-01 17:00:12 -07001391helm_values() {
1392 local NAMESPACE=$1; shift
1393 local INAME=$1; shift
1394 local CHART=$1; shift
1395 local CHART_VERSION=$1; shift
1396
1397 if [ "$CHART_VERSION X" != " X" ] && [ "$CHART_VERSION" != "latest" ]; then
1398 CHART_VERSION="--version $CHART_VERSION"
1399 else
1400 CHART_VERSION=
1401 fi
1402
1403 local CHART_ARGS=
1404 if [ -r "${INAME}-values.yaml" ]; then
1405 CHART_ARGS="-f ${INAME}-values.yaml"
1406 fi
1407
1408 if [ "$HELM_USE_UPGRADE" == "yes" ]; then
1409 _HELM_COMMAND="upgrade --install"
1410 _HELM_ARGS="xxxdryrunxxx"
1411 else
1412 _HELM_COMMAND="install"
Matteo Scandolof2d080b2020-07-23 13:59:29 -07001413 if [ "$HELM_MAJOR" -le 2 ]; then
1414 _HELM_NAME_ARG="--name xxxdryrunxxx"
1415 _HELM_ARGS=
1416 else
1417 _HELM_NAME_ARG="xxxdryrunxxx"
1418 _HELM_ARGS="--create-namespace"
1419 fi
David Bainbridgefad50732020-05-01 17:00:12 -07001420 fi
Matteo Scandolo657e13c2020-07-28 11:41:42 -07001421 CMD=("helm $_HELM_COMMAND --debug --dry-run -f 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 $_HELM_NAME_ARG $CHART")
David Bainbridgefad50732020-05-01 17:00:12 -07001422 ${CMD[*]} 2>/dev/null | awk 'PRINT==1 {print}; /^USER-SUPPLIED VALUES:/ {PRINT = 1}; /^$/ {PRINT = 0}'
1423}
1424
David Bainbridgeb4bbde12020-06-25 14:46:36 -07001425helm_is_deployed() {
1426 local NAMESPACE=$1; shift
1427 local NAME=$1; shift
1428
1429 if [ "$HELM_MAJOR" -le 2 ]; then
1430 helm list --deployed --short --namespace "$NAMESPACE" "$NAME" 2>/dev/null | wc -l
1431 else
1432 helm list --deployed --short --namespace "$NAMESPACE" --filter "$NAME" 2>/dev/null | wc -l
1433 fi
1434}
1435
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001436helm_install() {
David Bainbridgec7220622020-05-28 12:31:47 -07001437 local INDENT NOW VALUES_FILE PPROF_ARG
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001438 if [ "$1" == "-" ]; then
1439 INDENT=$1; shift
1440 fi
1441 local NAMESPACE=$1; shift
David Bainbridge0774b232019-08-02 06:37:19 +00001442 local INAME=$1; shift
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001443 local CHART=$1; shift
David Bainbridge90fd8e32019-08-21 23:32:47 +00001444 local CHART_VERSION=$1; shift
David Bainbridgec7220622020-05-28 12:31:47 -07001445 local FILTER=$1; shift
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001446 local MESSAGE=$*
1447
David Bainbridged18f4942020-04-14 16:46:13 -07001448 if [ "$CHART_VERSION X" != " X" ] && [ "$CHART_VERSION" != "latest" ]; then
David Bainbridge90fd8e32019-08-21 23:32:47 +00001449 CHART_VERSION="--version $CHART_VERSION"
1450 else
1451 CHART_VERSION=
1452 fi
1453
David Bainbridge99ac7a22019-08-31 02:26:43 +00001454 local CHART_ARGS=
1455 if [ -r "${INAME}-values.yaml" ]; then
1456 CHART_ARGS="-f ${INAME}-values.yaml"
1457 fi
1458
David Bainbridged18f4942020-04-14 16:46:13 -07001459 local WAIT_START CMD
1460 WAIT_START="$(date +%s)"
1461 COUNT="$((300 / 15))"
1462 bspin "$INDENT" "$MESSAGE"
1463 if [ "$HELM_USE_UPGRADE" == "yes" ]; then
David Bainbridge7f8bf992020-04-08 21:53:22 -07001464 _HELM_COMMAND="upgrade --install"
David Bainbridgeb4bbde12020-06-25 14:46:36 -07001465 _HELM_NAME_ARG="$INAME"
David Bainbridge7f8bf992020-04-08 21:53:22 -07001466 else
1467 _HELM_COMMAND="install"
David Bainbridgeb4bbde12020-06-25 14:46:36 -07001468 if [ "$HELM_MAJOR" -le 2 ]; then
1469 _HELM_NAME_ARG="--name $INAME"
1470 _HELM_ARGS=
1471 else
1472 _HELM_NAME_ARG="$INAME"
1473 _HELM_ARGS="--create-namespace"
1474 fi
David Bainbridge7f8bf992020-04-08 21:53:22 -07001475 fi
David Bainbridgec7220622020-05-28 12:31:47 -07001476
1477 VALUES_FILE="$(mktemp)"
1478 if [ "$FILTER" == "-" ]; then
Matteo Scandolo657e13c2020-07-28 11:41:42 -07001479 cp "values.yaml" "$VALUES_FILE"
David Bainbridgea965ca22020-06-09 17:45:04 -07001480 elif [ "${FILTER:0:1}" == "+" ]; then
Matteo Scandolo657e13c2020-07-28 11:41:42 -07001481 cp "values.yaml" "$VALUES_FILE"
1482 yq r - "${FILTER:1}" <"values.yaml" >>"$VALUES_FILE"
David Bainbridge33e56c72020-06-11 11:39:56 -07001483 cat "$VALUES_FILE" >>"$LOG"
David Bainbridgec7220622020-05-28 12:31:47 -07001484 else
Matteo Scandolo657e13c2020-07-28 11:41:42 -07001485 yq r - "$FILTER" <"values.yaml" >"$VALUES_FILE"
David Bainbridgec7220622020-05-28 12:31:47 -07001486 fi
1487 if [ "$WITH_PPROF" == "yes" ]; then
1488 PPROF_ARG="--set profiler.enabled=true"
1489 fi
David Bainbridgeb4bbde12020-06-25 14:46:36 -07001490 CMD=("helm $_HELM_COMMAND -f $VALUES_FILE $_HELM_ARGS $CHART_ARGS $PPROF_ARG $INTERNAL_EXTRA_HELM_INSTALL_ARGS $EXTRA_HELM_INSTALL_ARGS --set defaults.log_level=$VOLTHA_LOG_LEVEL --namespace $NAMESPACE $CHART_VERSION $EXTRA_HELM_FLAGS $_HELM_NAME_ARG $CHART")
David Bainbridged18f4942020-04-14 16:46:13 -07001491 (set -x; ${CMD[*]} >>"$LOG" 2>&1) >>"$LOG" 2>&1
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001492 SUCCESS=$?
David Bainbridged18f4942020-04-14 16:46:13 -07001493 while [ "$SUCCESS" -ne 0 ]; do
1494 NOW="$(date +%s)"
1495 if [ "$((NOW - WAIT_START))" -gt "$TIMEOUT_SECONDS" ]; then
David Bainbridge52e6e9d2020-03-23 13:48:27 -07001496 espin "$THEX"
David Bainbridgec7220622020-05-28 12:31:47 -07001497 rm -f "$VALUES_FILE"
David Bainbridge52e6e9d2020-03-23 13:48:27 -07001498 doTimeout "waiting for helm install $CHART"
1499 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001500 sspin "$INDENT"
1501 COUNT="$((COUNT - 1))"
1502 if [ "$COUNT" -eq 0 ]; then
1503 if [ "$HELM_USE_UPGRADE" == "no" ]; then
David Bainbridgeb4bbde12020-06-25 14:46:36 -07001504 if [ "$HELM_MAJOR" -le 2 ]; then
1505 (set -x; helm delete --purge "$INAME" >>"$LOG" 2>&1) >>"$LOG" 2>&1
1506 else
1507 (set -x; helm uninstall "$INAME" >>"$LOG" 2>&1) >>"$LOG" 2>&1
1508 fi
David Bainbridge7f8bf992020-04-08 21:53:22 -07001509 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001510 (set -x; ${CMD[*]} >>"$LOG" 2>&1) >>"$LOG" 2>&1
Andy Baviere22ff252019-12-19 11:40:31 -07001511 SUCCESS=$?
David Bainbridged18f4942020-04-14 16:46:13 -07001512 COUNT="$((300 / 15))"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001513 fi
1514 sleep .15
1515 done
David Bainbridgec7220622020-05-28 12:31:47 -07001516 rm -f "$VALUES_FILE"
David Bainbridged18f4942020-04-14 16:46:13 -07001517 espin "$INDENT" "$VERIFIED"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001518}
1519
Matteo Scandoloe89384a2020-11-06 08:40:25 -08001520bspin "Installing VOLTHA: $NAME $GEAR"
1521espin "$VERIFIED"
Matteo Scandolo657e13c2020-07-28 11:41:42 -07001522echo "INSTALL NAME: $NAME" >> "$LOG"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001523
David Bainbridged18f4942020-04-14 16:46:13 -07001524STIME="$(date +%s)"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001525if [ "$INSTALL_KUBECTL" == "no" ]; then
1526 bspin "Skip kubectl install"
1527 espin $NO_ENTRY
Test Userc13bdc92019-07-03 20:57:49 +00001528else
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001529 bspin "Verify kubectl $HELM"
David Bainbridged18f4942020-04-14 16:46:13 -07001530 if [ -x "$GOPATH/bin/kubectl" ]; then
1531 espin "$VERIFIED"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001532 else
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001533 ERR_OUT="$(mktemp)"
David Bainbridged18f4942020-04-14 16:46:13 -07001534 espin "$NOT_VERIFIED"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001535 bspin - "Download and install Kubernetes/kubectl $DOWNLOAD"
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001536 (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
1537 RESULT=$?
1538 if [ "$RESULT" -ne 0 ]; then
1539 espin - "$THEX"
David Bainbridgee3fc0c32020-04-21 15:34:04 -07001540 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR: unable to download kubectl: $(tail "$ERR_OUT")${NORMAL}"
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001541 cat "$ERR_OUT" >> "$LOG"
Zack Williamsded60cb2020-04-13 10:02:20 -07001542 rm -rf "$ERR_OUT" "$GOPATH/bin/kubectl"
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001543 exit 1
1544 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001545 (set -x; chmod 755 "$GOPATH/bin/kubectl" >>"$LOG" 2>&1) >>"$LOG" 2>&1
1546 espin - "$VERIFIED"
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001547 rm -rf "$ERR_OUT"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001548 fi
Test Userc13bdc92019-07-03 20:57:49 +00001549fi
David Bainbridgee87067b2019-08-12 22:00:12 +00001550if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001551 NOW="$(date +%s)"
1552 printtime $((NOW - STIME))
David Bainbridgee87067b2019-08-12 22:00:12 +00001553fi
Test Userc13bdc92019-07-03 20:57:49 +00001554
David Bainbridged18f4942020-04-14 16:46:13 -07001555STIME="$(date +%s)"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001556if [ "$DEPLOY_K8S" == "no" ]; then
1557 bspin "Skip Kubernetes/Kind Deployment"
1558 espin $NO_ENTRY
1559else
Test Userba1e7e72019-07-10 22:27:54 +00001560 bspin "Verify Kubernetes/Kind $HELM"
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -08001561 IS_INSTALLED=0
1562 OP_TYPE="install"
David Bainbridged18f4942020-04-14 16:46:13 -07001563 if [ -x "$GOPATH/bin/kind" ]; then
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -08001564 OP_TYPE="upgrade"
David Bainbridgeb4bbde12020-06-25 14:46:36 -07001565 if [ "$("$GOPATH/bin/kind" version | grep -c "$KIND_VERSION")" -eq 1 ]; then
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -08001566 IS_INSTALLED=1
David Bainbridged18f4942020-04-14 16:46:13 -07001567 espin "$VERIFIED"
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -08001568 fi
1569 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001570 if [ "$IS_INSTALLED" -eq 0 ]; then
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001571 ERR_OUT="$(mktemp)"
David Bainbridged18f4942020-04-14 16:46:13 -07001572 espin "$NOT_VERIFIED"
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -08001573 bspin - "Download and $OP_TYPE Kubernetes/kind $DOWNLOAD"
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001574 (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
1575 RESULT=$?
1576 if [ $RESULT -ne 0 ]; then
1577 espin - "$THEX"
David Bainbridgee3fc0c32020-04-21 15:34:04 -07001578 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR: unable to download kind: $(tail "$ERR_OUT")${NORMAL}"
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001579 cat "$ERR_OUT" >> "$LOG"
Zack Williamsded60cb2020-04-13 10:02:20 -07001580 rm -rf "$ERR_OUT" "$GOPATH/bin/kind"
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001581 exit 1
1582 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001583 (set -x; chmod 755 "$GOPATH/bin/kind" >>"$LOG" 2>&1) >>"$LOG" 2>&1
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001584 rm -rf "$ERR_OUT"
David Bainbridged18f4942020-04-14 16:46:13 -07001585 espin - "$VERIFIED"
Test Userba1e7e72019-07-10 22:27:54 +00001586 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001587fi
1588
David Bainbridgee87067b2019-08-12 22:00:12 +00001589if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001590 NOW="$(date +%s)"
1591 printtime $((NOW - STIME))
David Bainbridgee87067b2019-08-12 22:00:12 +00001592fi
1593
David Bainbridged18f4942020-04-14 16:46:13 -07001594STIME="$(date +%s)"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001595if [ "$INSTALL_HELM" == "no" ]; then
1596 bspin "Skip Helm Install"
1597 espin $NO_ENTRY
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001598else
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001599 bspin "Verify Helm $HELM"
David Bainbridgea34993d2020-04-01 09:15:42 -07001600 HELM_UPGRADE=0
1601 HELM_UPGRADE_DESC="install"
David Bainbridged18f4942020-04-14 16:46:13 -07001602 if [ -x "$GOPATH/bin/helm" ]; then
David Bainbridgeb4bbde12020-06-25 14:46:36 -07001603 HAVE_VER=$(helm version --client --short | sed -E -e 's/^.*(v[0-9]+\.[0-9]+\.[0-9]+).*$/\1/')
David Bainbridged18f4942020-04-14 16:46:13 -07001604 HELM_UP_DOWN="$(echo -e "$HAVE_VER\n$HELM_VERSION" | sort -V | head -1)"
1605 if [ "$HAVE_VER" != "$HELM_VERSION" ]; then
1606 if [ "$HELM_UP_DOWN" == "$HELM_VERSION" ]; then
David Bainbridgea34993d2020-04-01 09:15:42 -07001607 HELM_UPGRADE_DESC="downgrade"
1608 else
1609 HELM_UPGRADE_DESC="upgrade"
1610 fi
1611 HELM_UPGRADE=1
1612 else
David Bainbridged18f4942020-04-14 16:46:13 -07001613 espin "$VERIFIED"
David Bainbridgea34993d2020-04-01 09:15:42 -07001614 fi
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001615 else
David Bainbridgea34993d2020-04-01 09:15:42 -07001616 HELM_UPGRADE=1
1617 fi
1618
David Bainbridged18f4942020-04-14 16:46:13 -07001619 if [ "$HELM_UPGRADE" -ne 0 ]; then
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001620 ERR_OUT="$(mktemp)"
1621 INSTALL_HELM_BIN=$(mktemp)
David Bainbridged18f4942020-04-14 16:46:13 -07001622 espin "$NOT_VERIFIED"
David Bainbridgea34993d2020-04-01 09:15:42 -07001623 bspin - "Download and $HELM_UPGRADE_DESC Helm $DOWNLOAD"
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001624 (set -x; curl -o "$INSTALL_HELM_BIN" --fail -sSL https://git.io/get_helm.sh >>"$LOG" 2>"$ERR_OUT") >>"$LOG" 2>&1
1625 RESULT=$?
1626 if [ $RESULT -ne 0 ]; then
1627 espin - "$THEX"
David Bainbridgee3fc0c32020-04-21 15:34:04 -07001628 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR: unable to download helm installer: $(tail "$ERR_OUT")${NORMAL}"
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001629 cat "$ERR_OUT" >> "$LOG"
1630 rm -rf "$INSTALL_HELM_BIN" "$ERR_OUT" "$GOPATH/bin/helm" "$GOPATH/bin/tiller"
1631 exit 1
1632 fi
1633 rm -rf "$ERR_OUT"
1634 chmod +x "$INSTALL_HELM_BIN"
1635 (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
1636 RESULT=$?
1637 if [ $RESULT -ne 0 ]; then
1638 espin - "$THEX"
1639 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR: unable to install helm, see install log for details${NORMAL}"
1640 rm -rf "$INSTALL_HELM_BIN" "$ERR_OUT" "$GOPATH/bin/helm" "$GOPATH/bin/tiller"
1641 exit 1
1642 fi
1643 rm -rf "$INSTALL_HELM_BIN" "$ERR_OUT"
David Bainbridged18f4942020-04-14 16:46:13 -07001644 espin - "$VERIFIED"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001645 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001646fi
David Bainbridgee87067b2019-08-12 22:00:12 +00001647if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001648 NOW="$(date +%s)"
1649 printtime $((NOW - STIME))
David Bainbridgee87067b2019-08-12 22:00:12 +00001650fi
David Bainbridgeb4bbde12020-06-25 14:46:36 -07001651HELM_MAJOR=$(helm version --client --short 2>/dev/null| sed -E -e 's/^.*v([0-9]+)\.[0-9]+\.[0-9]+.*$/\1/')
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001652
David Bainbridged18f4942020-04-14 16:46:13 -07001653STIME="$(date +%s)"
Test Userb5712372019-07-03 21:52:17 +00001654bspin "Verify voltctl $HIGH_VOLTAGE"
David Bainbridged2811972019-12-14 01:14:09 +00001655VOK=0
1656VMESSAGE="install"
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001657ERR_OUT=$(mktemp)
David K. Bainbridgeebf38d92020-02-10 10:46:31 -08001658export VC_VERSION="$VOLTCTL_VERSION"
1659if [ "$VC_VERSION" == "latest" ]; then
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001660 set -o pipefail # TODO: would be nice to run all in pipefail mode
1661 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')"
1662 RESULT=$?
1663 set +o pipefail
1664 if [ "$RESULT" -ne 0 ]; then
1665 espin - "$THEX"
1666 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR: unable to determine released version of voltctl: $(cat "$ERR_OUT")${NORMAL}"
1667 rm -rf "$ERR_OUT" "$GOPATH/bin/voltctl"
1668 exit 1
1669 fi
1670 export VC_VERSION
David K. Bainbridgeebf38d92020-02-10 10:46:31 -08001671fi
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001672
David Bainbridged18f4942020-04-14 16:46:13 -07001673if [ -x "$GOPATH/bin/voltctl" ]; then
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001674 VHAVE="$("$GOPATH/bin/voltctl" version --clientonly -o json 2>/dev/null | jq -r .version)"
David Bainbridged18f4942020-04-14 16:46:13 -07001675 RESULT=$?
1676 if [ $RESULT -eq 0 ] && [ "$VHAVE" == "$VC_VERSION" ]; then
David Bainbridged2811972019-12-14 01:14:09 +00001677 VOK=1
David Bainbridged18f4942020-04-14 16:46:13 -07001678 espin "$VERIFIED"
David Bainbridge1ba64f12019-12-18 00:40:13 +00001679 else
David Bainbridged18f4942020-04-14 16:46:13 -07001680 VCHECK="$(echo -e "$VHAVE\n$VC_VERSION" | sort -V | head -1)"
David K. Bainbridgeebf38d92020-02-10 10:46:31 -08001681 if [ "$VCHECK" == "$VHAVE" ]; then
1682 VMESSAGE="upgrade"
1683 else
1684 VMESSAGE="downgrade"
1685 fi
David Bainbridged2811972019-12-14 01:14:09 +00001686 fi
1687fi
1688
David Bainbridged18f4942020-04-14 16:46:13 -07001689if [ "$VOK" -eq 0 ]; then
1690 espin "$NOT_VERIFIED"
David Bainbridged2811972019-12-14 01:14:09 +00001691 bspin - "Download and $VMESSAGE voltctl $DOWNLOAD"
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001692 (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
1693 RESULT=$?
1694 if [ $RESULT -ne 0 ]; then
1695 espin - "$THEX"
1696 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR: unable to download voltctl (version $VC_VERSION): $(cat "$ERR_OUT")${NORMAL}"
1697 rm -rf "$ERR_OUT" "$GOPATH/bin/voltctl"
1698 exit 1
1699 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001700 (set -x; chmod 755 "$GOPATH/bin/voltctl" >>"$LOG" 2>&1) >>"$LOG" 2>&1
1701 espin - "$VERIFIED"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001702fi
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001703rm -rf "$ERR_OUT"
David Bainbridgee87067b2019-08-12 22:00:12 +00001704if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001705 NOW="$(date +%s)"
1706 printtime $((NOW - STIME))
David Bainbridgee87067b2019-08-12 22:00:12 +00001707fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001708
1709bspin "Verify command PATH"
David Bainbridged18f4942020-04-14 16:46:13 -07001710espin "$VERIFIED"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001711
David Bainbridged18f4942020-04-14 16:46:13 -07001712STIME="$(date +%s)"
Test Userba1e7e72019-07-10 22:27:54 +00001713if [ "$DEPLOY_K8S" == "yes" ]; then
David Bainbridgeb4bbde12020-06-25 14:46:36 -07001714 HAVE="$(kind get clusters 2>/dev/null | grep -c "voltha-$NAME")"
Test Userba1e7e72019-07-10 22:27:54 +00001715 bspin "Verify Kubernetes/Kind Cluster"
1716 sspin
David Bainbridged18f4942020-04-14 16:46:13 -07001717 if [ "$HAVE" -eq 0 ]; then
1718 espin "$NOT_VERIFIED"
Andrea Campanella8a149192020-07-31 17:19:45 +02001719 FILE="$NAME-cluster.cfg"
David K. Bainbridge2aa08da2020-07-31 12:49:45 -07001720 if [ -n "$KIND_CFG_FILE" ]; then
1721 FILE="$KIND_CFG_FILE"
1722 else
1723 bspin - "Generating cluster configuration"
Andrea Campanelladd946472020-07-31 11:03:44 +02001724
David K. Bainbridge2aa08da2020-07-31 12:49:45 -07001725 if [ -f "$FILE" ] ; then
1726 rm "$FILE"
1727 fi
1728
1729 touch "$FILE"
1730
1731 yq w -i "$FILE" kind Cluster
1732 yq w -i "$FILE" apiVersion "kind.sigs.k8s.io/v1alpha3"
1733
1734 if [ ! "$NUM_OF_CONTROLLER_NODES" -eq 0 ]; then
1735 for instance in $(seq 1 "$NUM_OF_CONTROLLER_NODES"); do
1736 yq w -i "$FILE" "nodes[+].role" "control-plane"
1737 done
1738 fi
1739
1740 if [ ! "$NUM_OF_WORKER_NODES" -eq 0 ]; then
1741 for instance in $(seq 1 "$NUM_OF_WORKER_NODES"); do
1742 yq w -i "$FILE" "nodes[+].role" worker
1743 done
1744 fi
1745 espin - "$VERIFIED"
Andrea Campanelladd946472020-07-31 11:03:44 +02001746 fi
1747
Andrea Campanella8a149192020-07-31 17:19:45 +02001748 cat "$FILE" >> "$LOG" 2>&1
Matteo Scandolo657e13c2020-07-28 11:41:42 -07001749
Andrea Campanella8a149192020-07-31 17:19:45 +02001750 kind create cluster --name "voltha-$NAME" --config "$FILE"
David Bainbridge491b1bd2019-07-11 17:53:11 +00001751 else
David Bainbridged18f4942020-04-14 16:46:13 -07001752 espin "$VERIFIED"
Test Userba1e7e72019-07-10 22:27:54 +00001753 fi
1754
David K. Bainbridgec0ec6492020-07-21 17:34:23 +00001755 KUBECONFIG_TMP=$(mktemp)
1756 kind get kubeconfig --name="voltha-$NAME" >"$KUBECONFIG_TMP"
1757 mkdir -p "$HOME/.kube"
1758 KUBECONFIG="$HOME/.kube/kind-config-voltha-$NAME"; export KUBECONFIG
1759 cp "$KUBECONFIG_TMP" "$KUBECONFIG"
1760 rm -rf "$KUBECONFIG_TMP"
David Bainbridge1d2c5842020-06-03 15:29:07 -07001761
Test Userba1e7e72019-07-10 22:27:54 +00001762 P="coredns-.* \
David Bainbridge0774b232019-08-02 06:37:19 +00001763 etcd-voltha-$NAME-control-plane \
Test Userba1e7e72019-07-10 22:27:54 +00001764 kindnet-.* \
David Bainbridge0774b232019-08-02 06:37:19 +00001765 kube-apiserver-voltha-$NAME-control-plane \
1766 kube-controller-manager-voltha-$NAME-control-plane \
Test Userba1e7e72019-07-10 22:27:54 +00001767 kube-proxy-.* \
David Bainbridge0774b232019-08-02 06:37:19 +00001768 kube-scheduler-voltha-$NAME-control-plane"
Test Userba1e7e72019-07-10 22:27:54 +00001769
David K. Bainbridge2aa08da2020-07-31 12:49:45 -07001770 EXPECT=2 # Always 2 DNS instances
1771 EXPECT=$((EXPECT + 4 * NUM_OF_CONTROLLER_NODES)) # etcd, apiserver, controller manager, scheduler
1772 EXPECT=$((EXPECT + 2 * (NUM_OF_CONTROLLER_NODES + NUM_OF_WORKER_NODES))) # kindnet, proxy
David Bainbridged18f4942020-04-14 16:46:13 -07001773 wait_for_pods - "kube-system" "$EXPECT" "includes" "Waiting for system PODs to start" "$NO_LABEL" "$P"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001774fi
Matteo Scandolo657e13c2020-07-28 11:41:42 -07001775
David Bainbridgee87067b2019-08-12 22:00:12 +00001776if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001777 NOW="$(date +%s)"
1778 printtime $((NOW - STIME))
David Bainbridgee87067b2019-08-12 22:00:12 +00001779fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001780
David Bainbridgee4d11ca2020-05-08 10:21:10 -07001781if [ "$SCHEDULE_ON_CONTROL_NODES" == "yes" ]; then
1782 bspin "Untaint control nodes to allow scheduling $LOCK"
1783 for MNODE in $(kubectl get node --selector='node-role.kubernetes.io/master' -o json | jq -r '.items[].metadata.name'); do
1784 (set -x; kubectl taint node "$MNODE" node-role.kubernetes.io/master:NoSchedule- >>"$LOG" 2>&1) >>"$LOG" 2>&1
1785 sspin
1786 done
1787 espin "$VERIFIED"
1788fi
1789
David Bainbridgeb4bbde12020-06-25 14:46:36 -07001790if [ "$HELM_MAJOR" -le 2 ]; then
1791 STIME="$(date +%s)"
1792 COUNT="$(count_pods "kube-system" ":Running:" "$NO_LABEL" "tiller-deploy-.*")"
1793 bspin "Verify Helm"
1794 if [ "$COUNT" -ne 1 ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001795 espin "$NOT_VERIFIED"
David Bainbridgeb4bbde12020-06-25 14:46:36 -07001796 echo -e "Configuring Helm $GEAR"
1797 if [ "$INSTALL_HELM" == "no" ]; then
1798 bspin - "Skip Helm Initialization"
1799 espin - $NO_ENTRY
1800 else
1801 bspin - "Initialize Helm"
1802 (set -x; helm init --upgrade >>"$LOG" 2>&1) >>"$LOG" 2>&1
1803 espin - "$VERIFIED"
1804 wait_for_pods - "kube-system" 1 "includes" "Waiting for Tiller POD to start" "$NO_LABEL" "tiller-deploy-.*"
1805 fi
1806
1807 # HACK (sort-of) - the config for tiller is about to be patched, which will
1808 # cause the tiller pod to be recreated. This can sometimes cause a timing
1809 # issue with the "wait_for_pods" call on tiller as it may incorrectly
1810 # identify the running/ready tiller pod that is soon to be terminated as
1811 # what it is waiting for. To avoid this issue we do a clean scale down and
1812 # scale up of the pod so the script controlls when it should be expecting
1813 # things
1814 (set -x; kubectl -n kube-system scale deploy tiller-deploy --replicas=0 >>"$LOG" 2>&1) >>"$LOG" 2>&1
1815 wait_for_pods - "kube-system" 0 "not" "Waiting for Tiller POD to shutdown" "$NO_LABEL" "tiller-deploy-.*"
1816
1817 # Create and k8s service account so that Helm can create pods
1818 bspin - "Create Tiller ServiceAccount"
1819 (set -x; kubectl create serviceaccount --namespace kube-system tiller >>"$LOG" 2>&1) >>"$LOG" 2>&1
1820 espin - "$VERIFIED"
1821 bspin - "Create Tiller ClusterRoleBinding"
1822 (set -x; kubectl create clusterrolebinding tiller-cluster-rule --clusterrole=cluster-admin --serviceaccount=kube-system:tiller >>"$LOG" 2>&1) >>"$LOG" 2>&1
1823 espin - "$VERIFIED"
1824 bspin - "Update Tiller Manifest"
1825 (set -x; kubectl patch deploy --namespace kube-system tiller-deploy -p '{"spec":{"template":{"spec":{"serviceAccount":"tiller"}}}}' >>"$LOG" 2>&1) >>"$LOG" 2>&1
1826
1827 # HACK (sort-of) - part to, spin it back up
1828 (set -x; kubectl -n kube-system scale deploy tiller-deploy --replicas=1 >>"$LOG" 2>&1) >>"$LOG" 2>&1
David Bainbridged18f4942020-04-14 16:46:13 -07001829 espin - "$VERIFIED"
David Bainbridgea34993d2020-04-01 09:15:42 -07001830 else
David Bainbridgeb4bbde12020-06-25 14:46:36 -07001831 if [ "$(helm version -s --template '{{.Server.SemVer}}')" != "$HELM_VERSION" ]; then
1832 espin "$NOT_VERIFIED"
1833 bspin - "Sync Tiller server version with helm client"
1834 (set -x; helm init --upgrade --force-upgrade --wait >>"$LOG" 2>&1) >>"$LOG" 2>&1
1835 espin - "$VERIFIED"
1836 else
1837 espin "$VERIFIED"
1838 fi
1839
David Bainbridgea34993d2020-04-01 09:15:42 -07001840 fi
David Bainbridgeb4bbde12020-06-25 14:46:36 -07001841 wait_for_pods - "kube-system" 1 "includes" "Waiting for Tiller POD to start" "$NO_LABEL" "tiller-deploy-.*"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001842fi
David Bainbridgeddeab482020-06-24 12:43:40 -07001843
David Bainbridgeb4bbde12020-06-25 14:46:36 -07001844# The `etcd` repo is temporary until `http://github.com/helm/charts/pull/22955` is
1845# merged into the incubator charts
David Bainbridgeddeab482020-06-24 12:43:40 -07001846REPOS="onf|https://charts.opencord.org|ONF_VOLTHA \
1847 stable|https://kubernetes-charts.storage.googleapis.com|Google_Stable \
Ubuntubaab12f2020-06-30 01:08:19 +00001848 incubator|https://kubernetes-charts-incubator.storage.googleapis.com|Google_Incubator \
1849 onos|https://charts.onosproject.org|ONF_ONOS \
1850 atomix|https://charts.atomix.io|ONF_Atomix \
Ubuntubaab12f2020-06-30 01:08:19 +00001851 elastic|https://helm.elastic.co|Elastic \
Matteo Scandolo8f8609a2020-11-13 10:20:44 -08001852 kiwigrid|https://kiwigrid.github.io|Fluentd-ElasticSearch\
1853 bitnami|https://charts.bitnami.com/bitnami|Bitnami"
David Bainbridgeddeab482020-06-24 12:43:40 -07001854
David Bainbridgeb4bbde12020-06-25 14:46:36 -07001855REPO_UPDATE_REQ="no"
David Bainbridgeddeab482020-06-24 12:43:40 -07001856bspin - "Verify Helm Repository"
1857for REPO in $REPOS; do
1858 REPO_NAME="$(echo "$REPO" | cut -d\| -f1)"
1859 REPO_URL="$(echo "$REPO" | cut -d\| -f2)"
1860 REPO_LABEL="$(echo "$REPO" | cut -d\| -f3 | sed -e 's/_/ /g')"
1861
1862 sspin - "Verify Helm Repository: $REPO_LABEL$CEOL"
1863 if [ "$(helm repo list 2>/dev/null | grep -c "$REPO_NAME" 2>/dev/null)" -eq 0 ]; then
1864 sspin - "Add Helm Repository: $REPO_LABEL$CEOL"
1865 (set -x; helm repo add "$REPO_NAME" "$REPO_URL" >>"$LOG" 2>&1) >>"$LOG" 2>&1
1866 REPO_UPDATE_REQ="yes"
1867 fi
1868done
1869sspin - "Verify Helm Repositories$CEOL"
1870espin - "$VERIFIED"
1871
1872if [ "$REPO_UPDATE_REQ" == "yes" ] || [ "$UPDATE_HELM_REPOS" == "yes" ]; then
1873 bspin - "Update Helm repository cache"
1874 (set -x; helm repo update >>"$LOG" 2>&1) >>"$LOG" 2>&1
1875 espin - "$VERIFIED"
1876fi
1877
David Bainbridgee87067b2019-08-12 22:00:12 +00001878if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001879 NOW="$(date +%s)"
1880 printtime $((NOW - STIME))
David Bainbridgee87067b2019-08-12 22:00:12 +00001881fi
David Bainbridgecf546362020-04-21 23:18:50 -07001882# Resolve chart versions and log them for debug/support
1883RESOLVED_VOLTHA_CHART_VERSION=$(resolve_chart_version "$VOLTHA_CHART" "$VOLTHA_CHART_VERSION")
1884RESOLVED_VOLTHA_BBSIM_CHART_VERSION=$(resolve_chart_version "$VOLTHA_BBSIM_CHART" "$VOLTHA_BBSIM_CHART_VERSION")
Girish Kumarcc5f9172020-06-10 13:34:31 +00001885RESOLVED_VOLTHA_TRACING_CHART_VERSION=$(resolve_chart_version "$VOLTHA_TRACING_CHART" "$VOLTHA_TRACING_CHART_VERSION")
David Bainbridgecf546362020-04-21 23:18:50 -07001886RESOLVED_VOLTHA_ADAPTER_SIM_CHART_VERSION=$(resolve_chart_version "$VOLTHA_ADAPTER_SIM_CHART" "$VOLTHA_ADAPTER_SIM_CHART_VERSION")
1887RESOLVED_VOLTHA_ADAPTER_OPEN_OLT_CHART_VERSION=$(resolve_chart_version "$VOLTHA_ADAPTER_OPEN_OLT_CHART" "$VOLTHA_ADAPTER_OPEN_OLT_CHART_VERSION")
1888RESOLVED_VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION=$(resolve_chart_version "$VOLTHA_ADAPTER_OPEN_ONU_CHART" "$VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION")
1889RESOLVED_ONOS_CHART_VERSION=$(resolve_chart_version "$ONOS_CHART" "$ONOS_CHART_VERSION")
David Bainbridge60ffc0f2020-04-27 22:13:22 -07001890RESOLVED_ONOS_CLASSIC_CHART_VERSION=$(resolve_chart_version "$ONOS_CLASSIC_CHART" "$ONOS_CLASSIC_CHART_VERSION")
David Bainbridgecf546362020-04-21 23:18:50 -07001891RESOLVED_KAFKA_CHART_VERSION=$(resolve_chart_version "$KAFKA_CHART" "$KAFKA_CHART_VERSION")
divyadesai59f987a2020-05-27 12:11:33 +00001892RESOLVED_ELASTICSEARCH_CHART_VERSION=$(resolve_chart_version "$ELASTICSEARCH_CHART" "$ELASTICSEARCH_CHART_VERSION")
1893RESOLVED_KIBANA_CHART_VERSION=$(resolve_chart_version "$KIBANA_CHART" "$KIBANA_CHART_VERSION")
1894RESOLVED_FLUENTD_ELASTICSEARCH_CHART_VERSION=$(resolve_chart_version "$FLUENTD_ELASTICSEARCH_CHART" "$FLUENTD_ELASTICSEARCH_CHART_VERSION")
David K. Bainbridge450c15c2020-06-29 10:12:06 -07001895RESOLVED_BBSIM_SADIS_SERVER_CHART_VERSION=$(resolve_chart_version "$BBSIM_SADIS_SERVER_CHART" "$BBSIM_SADIS_SERVER_CHART_VERSION")
1896RESOLVED_RADIUS_CHART_VERSION=$(resolve_chart_version "$RADIUS_CHART" "$RADIUS_CHART_VERSION")
David Bainbridgecf546362020-04-21 23:18:50 -07001897cat <<EOV >>"$LOG"
1898Resolved helm charts and versions:
1899 $VOLTHA_CHART:$RESOLVED_VOLTHA_CHART_VERSION
1900 $VOLTHA_BBSIM_CHART:$RESOLVED_VOLTHA_BBSIM_CHART_VERSION
Girish Kumarcc5f9172020-06-10 13:34:31 +00001901 $VOLTHA_TRACING_CHART:$RESOLVED_VOLTHA_TRACING_CHART_VERSION
David Bainbridgecf546362020-04-21 23:18:50 -07001902 $VOLTHA_ADAPTER_SIM_CHART:$RESOLVED_VOLTHA_ADAPTER_SIM_CHART_VERSION
1903 $VOLTHA_ADAPTER_OPEN_OLT_CHART:$RESOLVED_VOLTHA_ADAPTER_OPEN_OLT_CHART_VERSION
1904 $VOLTHA_ADAPTER_OPEN_ONU_CHART:$RESOLVED_VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION
1905 $ONOS_CHART:$RESOLVED_ONOS_CHART_VERSION
David Bainbridge60ffc0f2020-04-27 22:13:22 -07001906 $ONOS_CLASSIC_CHART:$RESOLVED_ONOS_CLASSIC_CHART_VERSION
David Bainbridgecf546362020-04-21 23:18:50 -07001907 $KAFKA_CHART:$RESOLVED_KAFKA_CHART_VERSION
divyadesai59f987a2020-05-27 12:11:33 +00001908 $ELASTICSEARCH_CHART:$RESOLVED_ELASTICSEARCH_CHART_VERSION
1909 $KIBANA_CHART:$RESOLVED_KIBANA_CHART_VERSION
1910 $FLUENTD_ELASTICSEARCH_CHART:$RESOLVED_FLUENTD_ELASTICSEARCH_CHART_VERSION
David K. Bainbridge450c15c2020-06-29 10:12:06 -07001911 $BBSIM_SADIS_SERVER_CHART:$RESOLVED_BBSIM_SADIS_SERVER_CHART_VERSION
1912 $RADIUS_CHART:$RESOLVED_RADIUS_CHART_VERSION
David Bainbridgecf546362020-04-21 23:18:50 -07001913EOV
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001914
David Bainbridged18f4942020-04-14 16:46:13 -07001915STIME="$(date +%s)"
Matteo Scandolo657e13c2020-07-28 11:41:42 -07001916bspin "Verify Helm values file: values.yaml"
1917if [ ! -r "./values.yaml" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001918 espin "$NOT_VERIFIED"
Matteo Scandolo657e13c2020-07-28 11:41:42 -07001919 bspin - "Download Helm values file: values.yaml to values.yaml $DOWNLOAD"
David Bainbridged18f4942020-04-14 16:46:13 -07001920 ERR_OUT="$(mktemp)"
Matteo Scandolo657e13c2020-07-28 11:41:42 -07001921 if ! (set -x; curl --fail -o "./values.yaml" -sSL "https://raw.githubusercontent.com/opencord/kind-voltha/$VK_RELEASE/values.yaml" >>"$LOG" 2>"$ERR_OUT") >>"$LOG" 2>&1; then
David Bainbridged18f4942020-04-14 16:46:13 -07001922 espin - "$THEX"
Matteo Scandolo657e13c2020-07-28 11:41:42 -07001923 echo -e "${RED}${BOLD}${ERROR}ERROR: values.yaml${NORMAL}${RED} - $(cat "$ERR_OUT")${NORMAL}"
David Bainbridged18f4942020-04-14 16:46:13 -07001924 echo "ERROR: $(cat "$ERR_OUT")" >>"$LOG"
Matteo Scandolo657e13c2020-07-28 11:41:42 -07001925 rm -rf "$ERR_OUT" "./values.yaml"
David K. Bainbridgea00736b2020-01-08 14:33:17 -08001926 exit 1
1927 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001928 rm -rf "$ERR_OUT"
1929 espin - "$VERIFIED"
Test Userba1e7e72019-07-10 22:27:54 +00001930else
David Bainbridged18f4942020-04-14 16:46:13 -07001931 espin "$VERIFIED"
Test Userba1e7e72019-07-10 22:27:54 +00001932fi
David Bainbridgee87067b2019-08-12 22:00:12 +00001933if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001934 NOW="$(date +%s)"
1935 printtime $((NOW - STIME))
David Bainbridgee87067b2019-08-12 22:00:12 +00001936fi
Test Userba1e7e72019-07-10 22:27:54 +00001937
David Bainbridged18f4942020-04-14 16:46:13 -07001938STIME="$(date +%s)"
David Bainbridge99ac7a22019-08-31 02:26:43 +00001939bspin "Verify or download chart specific values files $DOWNLOAD"
1940VALUES_FILES="monkey-values.yaml"
David Bainbridged18f4942020-04-14 16:46:13 -07001941ERR_OUT="$(mktemp)"
David Bainbridge99ac7a22019-08-31 02:26:43 +00001942for i in $VALUES_FILES; do
1943 if [ ! -r ./$i ]; then
serkant.uluderya4d315132020-04-15 16:25:54 -07001944 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 -07001945 espin "$THEX"
1946 echo -e "${RED}${BOLD}${ERROR}ERROR: $i${NORMAL}${RED} - $(cat "$ERR_OUT")${NORMAL}"
1947 echo "ERROR: $i - $(cat "$ERR_OUT")" >>"$LOG"
1948 rm -rf "$ERR_OUT" "./$i"
David K. Bainbridgea00736b2020-01-08 14:33:17 -08001949 exit 1
1950 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001951 rm -rf "$ERR_OUT"
David Bainbridge99ac7a22019-08-31 02:26:43 +00001952 fi
1953done
David Bainbridged18f4942020-04-14 16:46:13 -07001954rm -rf "$ERR_OUT"
1955espin "$VERIFIED"
David Bainbridge99ac7a22019-08-31 02:26:43 +00001956if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001957 NOW="$(date +%s)"
1958 printtime $((NOW - STIME))
David Bainbridge99ac7a22019-08-31 02:26:43 +00001959fi
1960
1961if [ "$WITH_CHAOS" == "yes" ]; then
1962 bspin "Verify or clone kube-monkey helm chart $DOWNLOAD"
1963 if [ -r ./kube-monkey ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001964 espin "$VERIFIED"
David Bainbridge99ac7a22019-08-31 02:26:43 +00001965 else
David Bainbridged18f4942020-04-14 16:46:13 -07001966 espin "$NOT_VERIFIED"
David Bainbridge99ac7a22019-08-31 02:26:43 +00001967 bspin - "GIT clone kube-monkey"
David Bainbridged18f4942020-04-14 16:46:13 -07001968 (set -x; git clone https://github.com/asobti/kube-monkey kube-monkey >>"$LOG" 2>&1) >>"$LOG" 2>&1
1969 espin - "$VERIFIED"
David Bainbridge99ac7a22019-08-31 02:26:43 +00001970 fi
1971fi
1972
Test Userba1e7e72019-07-10 22:27:54 +00001973if [ "$JUST_K8S" == "yes" ]; then
Matteo Scandoloe89384a2020-11-06 08:40:25 -08001974 echo "Environment deployed, not deploying VOLTHA artifacts as requested. Good bye." | tee -a "$LOG"
Test Userba1e7e72019-07-10 22:27:54 +00001975 echo ""
David Bainbridged18f4942020-04-14 16:46:13 -07001976 echo "Please issue the following commands in your terminal to ensure that you" | tee -a "$LOG"
1977 echo "are accessing the correct Kubernetes/Kind cluster as well as have the " | tee -a "$LOG"
1978 echo "tools required by VOLTHA in your command path. " | tee -a "$LOG"
1979 echo "" | tee -a "$LOG"
1980 echo -en "$BOLD"
1981 if [ "$DEPLOY_K8S" == "yes" ]; then
David K. Bainbridge02ae1f32020-07-21 13:25:13 -07001982 KUBECONFIG_TMP=$(mktemp)
1983 kind get kubeconfig --name="voltha-$NAME" >"$KUBECONFIG_TMP"
1984 mkdir -p "$HOME/.kube"
1985 KUBECONFIG="$HOME/.kube/kind-config-voltha-$NAME"; export KUBECONFIG
1986 cp "$KUBECONFIG_TMP" "$KUBECONFIG"
1987 rm -rf "$KUBECONFIG_TMP"
David Bainbridgeb4bbde12020-06-25 14:46:36 -07001988 echo "export KUBECONFIG=\"$KUBECONFIG\"" | tee -a "$LOG"
Test Userba1e7e72019-07-10 22:27:54 +00001989 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001990 echo "export PATH=$GOPATH/bin:\$PATH" | tee -a "$LOG"
1991 echo -en "$NORMAL"
1992 echo "" | tee -a "$LOG"
1993 echo "Thank you for choosing kind-voltha for you quick cluster needs." | tee -a "$LOG"
Test Userba1e7e72019-07-10 22:27:54 +00001994 exit 0
1995fi
1996
David K. Bainbridgecb4b3ab2020-08-31 08:34:14 -07001997if is_in "$WITH_ETCD" "yes,external"; then
1998 STIME="$(date +%s)"
1999 bspin "Verify external ETCD cluster $OLD_KEY"
2000 EXPECT=$NUM_OF_ETCD
2001 if [ "$HELM_USE_UPGRADE" == "yes" ] || [ "$(helm_is_deployed "$INFRA_NS" "^etcd\$")" -ne 1 ]; then
2002 espin "$NOT_VERIFIED"
Matteo Scandolo8f8609a2020-11-13 10:20:44 -08002003 INTERNAL_EXTRA_HELM_INSTALL_ARGS="--set auth.rbac.enabled=false,persistence.enabled=false,statefulset.replicaCount=$NUM_OF_ETCD" helm_install - "$INFRA_NS" etcd "$ETCD_CHART" "$ETCD_CHART_VERSION" etcd "$_HELM_DESC external ETCD cluster"
David K. Bainbridgecb4b3ab2020-08-31 08:34:14 -07002004 INTERNAL_EXTRA_HELM_INSTALL_ARGS=
2005 else
2006 espin "$VERIFIED"
2007 fi
2008 wait_for_pods - "$INFRA_NS" "$EXPECT" "includes" "Waiting for ETCD cluster to start" "$NO_LABEL" "etcd-.*"
2009 if [ "$WITH_TIMINGS" == "yes" ]; then
2010 NOW="$(date +%s)"
2011 printtime $((NOW - STIME))
2012 fi
2013fi
2014
Matteo Scandoloe89384a2020-11-06 08:40:25 -08002015if [ "$WITH_ETCD" == "yes" ] && [ "$WITH_PORT_FORWARDS" == "yes" ]; then
2016 bspin - "Forward VOLTHA ETCD port $FORWARD"
2017 kill_port_forward "$INFRA_NS" "etcd"
2018 port_forward "$INFRA_NS" "etcd" "$VOLTHA_ETCD_PORT:2379"
2019 espin - "$VERIFIED"
2020fi
2021
David K. Bainbridgecb4b3ab2020-08-31 08:34:14 -07002022if is_in "$WITH_KAFKA" "yes,external"; then
2023 _TMP="$(mktemp -u)"
2024 cat << EOC > "$_TMP"
2025configurationOverrides:
2026 "default.replication.factor": $NUM_OF_KAFKA
2027 "offsets.topic.replication.factor": $NUM_OF_KAFKA
2028 "log.retention.hours": 4
2029 "log.message.timestamp.type": "LogAppendTime"
2030persistence:
2031 enabled: false
2032zookeeper:
2033 replicaCount: $NUM_OF_KAFKA
2034 persistence:
2035 enabled: false
2036replicas: $NUM_OF_KAFKA
2037EOC
2038 STIME="$(date +%s)"
2039 bspin "Verify external Kafka cluster $OLD_KEY"
2040 EXPECT=$((NUM_OF_KAFKA*2))
2041 if [ "$HELM_USE_UPGRADE" == "yes" ] || [ "$(helm_is_deployed "$INFRA_NS" "^kafka\$")" -ne 1 ]; then
2042 espin "$NOT_VERIFIED"
2043 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" -f $_TMP"
2044 helm_install - "$INFRA_NS" kafka "$KAFKA_CHART" "$KAFKA_CHART_VERSION" kafka "$_HELM_DESC external Kafka cluster"
2045 else
2046 espin "$VERIFIED"
2047 fi
2048 wait_for_pods - "$INFRA_NS" "$EXPECT" "includes" "Waiting for Kafka cluster to start" "$NO_LABEL" "kafka-.*"
2049 if [ "$WITH_TIMINGS" == "yes" ]; then
2050 NOW="$(date +%s)"
2051 printtime $((NOW - STIME))
2052 fi
2053 rm -rf "$_TMP"
Matteo Scandoloe89384a2020-11-06 08:40:25 -08002054
2055fi
2056
2057if [ "$WITH_KAFKA" == "yes" ] && [ "$WITH_PORT_FORWARDS" == "yes" ]; then
2058 bspin - "Forward VOLTHA Kafka port $FORWARD"
2059 kill_port_forward "$INFRA_NS" "kafka"
2060 port_forward "$INFRA_NS" kafka "$VOLTHA_KAFKA_PORT:9092"
2061 espin - "$VERIFIED"
David K. Bainbridgecb4b3ab2020-08-31 08:34:14 -07002062fi
2063
2064
David Bainbridged18f4942020-04-14 16:46:13 -07002065STIME="$(date +%s)"
David Bainbridge60ffc0f2020-04-27 22:13:22 -07002066if is_in "$WITH_ONOS" "yes,legacy,classic"; then
2067 if is_in "$WITH_ONOS" "legacy"; then
2068 bspin "Verify ONOS LEGACY installed $BIRD"
David Bainbridgeb4bbde12020-06-25 14:46:36 -07002069 if [ "$HELM_USE_UPGRADE" == "yes" ] || [ "$(helm_is_deployed "$INFRA_NS" "^onos\$")" -ne 1 ]; then
David Bainbridge60ffc0f2020-04-27 22:13:22 -07002070 espin "$NOT_VERIFIED"
David Bainbridge33e56c72020-06-11 11:39:56 -07002071 INTERNAL_EXTRA_HELM_INSTALL_ARGS="$SET_TAG $EXTRA_HELM_FLAGS" helm_install - "$INFRA_NS" onos "$ONOS_CHART" "$ONOS_CHART_VERSION" "+onos" "$_HELM_DESC ONOS LEGACY"
David Bainbridge60ffc0f2020-04-27 22:13:22 -07002072 INTERNAL_EXTRA_HELM_INSTALL_ARGS=
2073 else
2074 espin "$VERIFIED"
2075 fi
2076 wait_for_pods - "$INFRA_NS" 1 "includes" "Waiting for ONOS to start" "$NO_LABEL" "onos-.*"
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07002077
David Bainbridge60ffc0f2020-04-27 22:13:22 -07002078 if [ "$WITH_PORT_FORWARDS" == "yes" ]; then
2079 bspin - "Forward ONOS API port $FORWARD"
Matteo Scandoloe89384a2020-11-06 08:40:25 -08002080 kill_port_forward "$INFRA_NS" onos-ui
David Bainbridge60ffc0f2020-04-27 22:13:22 -07002081 port_forward "$INFRA_NS" onos-ui "$ONOS_API_PORT:8181"
2082 espin - "$VERIFIED"
2083 bspin - "Forward ONOS SSH port $FORWARD"
Matteo Scandoloe89384a2020-11-06 08:40:25 -08002084 kill_port_forward "$INFRA_NS" onos-ssh
David Bainbridge60ffc0f2020-04-27 22:13:22 -07002085 port_forward "$INFRA_NS" onos-ssh "$ONOS_SSH_PORT:8101"
2086 espin - "$VERIFIED"
2087 _ONOS_API_EP="127.0.0.1:$ONOS_API_PORT"
2088 else
2089 _ONOS_API_EP="$(get_service_ep "$INFRA_NS" onos-ui)"
2090 fi
2091 elif is_in "$WITH_ONOS" "yes,classic"; then
2092 bspin "Verify ONOS CLASSIC installed $BIRD"
Matteo Scandolo48890712020-09-11 15:48:24 -07002093 # ONOS CLASSIC identifies its image repo/tag/pullPolicy differently, so yq is used to grab the values from the
2094 # values value
2095 YAML_VALUES=$(INTERNAL_EXTRA_HELM_INSTALL_ARGS="--set replicas=$NUM_OF_ONOS --set atomix.replicas=$NUM_OF_ATOMIX" \
2096 helm_values "$INFRA_NS" onos "$ONOS_CLASSIC_CHART" "$ONOS_CLASSIC_CHART_VERSION")
David Bainbridgeb4bbde12020-06-25 14:46:36 -07002097 if [ "$HELM_USE_UPGRADE" == "yes" ] || [ "$(helm_is_deployed "$INFRA_NS" "^onos\$")" -ne 1 ]; then
David Bainbridge60ffc0f2020-04-27 22:13:22 -07002098 espin "$NOT_VERIFIED"
David Bainbridgefad50732020-05-01 17:00:12 -07002099 _ONOS_REPO="$(echo "$YAML_VALUES" | yq read - images.onos.repository)"
David Bainbridgedee3f022020-06-05 07:45:13 -07002100 if [ -z "$_ONOS_REPO" ]; then
2101 _ONOS_REPO="voltha/voltha-onos"
2102 fi
David Bainbridgefad50732020-05-01 17:00:12 -07002103 _ONOS_TAG="$(echo "$YAML_VALUES" | yq read - images.onos.tag)"
David Bainbridge60ffc0f2020-04-27 22:13:22 -07002104 if [ -z "$_ONOS_TAG" ]; then
David Bainbridgedee3f022020-06-05 07:45:13 -07002105 _ONOS_TAG="$(echo "$YAML_VALUES" | yq read - defaults.image_tag)"
2106 fi
2107 if [ -z "$_ONOS_TAG" ]; then
2108 _ONOS_TAG="master"
2109 fi
2110 _ONOS_PULL_POLICY="$(echo "$YAML_VALUES" | yq read - images.onos.pullPolicy)"
2111 if [ -z "$_ONOS_PULL_POLICY" ]; then
2112 _ONOS_PULL_POLICY="$(echo "$YAML_VALUES" | yq read - defaults.image_pullPolicy)"
2113 fi
2114 if [ -z "$_ONOS_PULL_POLICY" ]; then
2115 _ONOS_PULL_POLICY="Always"
David Bainbridge60ffc0f2020-04-27 22:13:22 -07002116 fi
David Bainbridgefad50732020-05-01 17:00:12 -07002117
Matteo Scandoloe0829b52020-05-08 14:23:56 -07002118 INTERNAL_EXTRA_HELM_INSTALL_ARGS="--set image.pullPolicy=$_ONOS_PULL_POLICY,image.repository=$_ONOS_REPO,image.tag=$_ONOS_TAG,replicas=$NUM_OF_ONOS,atomix.replicas=$NUM_OF_ATOMIX" \
David Bainbridge33e56c72020-06-11 11:39:56 -07002119 helm_install - "$INFRA_NS" onos "$ONOS_CLASSIC_CHART" "$ONOS_CLASSIC_CHART_VERSION" "+onos" "$_HELM_DESC ONOS CLASSIC"
David Bainbridge60ffc0f2020-04-27 22:13:22 -07002120 INTERNAL_EXTRA_HELM_INSTALL_ARGS=
2121 else
Matteo Scandolo48890712020-09-11 15:48:24 -07002122 _ONOS_TAG="$(echo "$YAML_VALUES" | yq read - images.onos.tag)"
2123 if [ -z "$_ONOS_TAG" ]; then
2124 _ONOS_TAG="$(echo "$YAML_VALUES" | yq read - defaults.image_tag)"
2125 fi
2126 if [ -z "$_ONOS_TAG" ]; then
2127 _ONOS_TAG="master"
2128 fi
David Bainbridge60ffc0f2020-04-27 22:13:22 -07002129 espin "$VERIFIED"
2130 fi
2131 wait_for_pods - "$INFRA_NS" $((NUM_OF_ONOS + NUM_OF_ATOMIX)) "includes" "Waiting for ONOS CLASSIC to start" "$NO_LABEL" "onos-.*"
David Bainbridge60ffc0f2020-04-27 22:13:22 -07002132 elif [ "$WITH_ONOS" == "micro" ]; then
2133 bspin "Verify micro-ONOS installed $BIRD"
2134 # We should never get here
2135 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} Micro ONOS not currently supported${NORMAL}"
2136 exit 1
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -08002137 fi
Matteo Scandoloe89384a2020-11-06 08:40:25 -08002138
2139 if is_in "$WITH_ONOS" "yes,classic" && [ "$WITH_PORT_FORWARDS" == "yes" ]; then
2140 bspin - "Forward ONOS API port $FORWARD"
2141 SVC=
2142 kill_port_forward "$INFRA_NS" onos-onos-classic-hs
2143 port_forward "$INFRA_NS" onos-onos-classic-hs "$ONOS_API_PORT:8181" "$ONOS_SSH_PORT:8101"
2144 espin - "$VERIFIED"
2145 _ONOS_API_EP="127.0.0.1:$ONOS_API_PORT"
2146 else
2147 _ONOS_API_EP="$(get_service_ep "$INFRA_NS" onos-onos-classic-hs)"
2148 fi
2149
David Bainbridged31d6122019-08-13 19:37:59 +00002150 bspin - "Verify or download ONOS configuration support files $DOWNLOAD"
Matteo Scandolo78dfee02020-02-13 16:18:03 -08002151 ONOS_FILES="olt-onos-enableExtraneousRules.json onos-aaa.json \
David Bainbridge696bc632020-04-05 21:49:37 -07002152 onos-dhcpl2relay.json onos-sadis-sample.json"
David Bainbridged18f4942020-04-14 16:46:13 -07002153 (set -x; mkdir -p ./onos-files >>"$LOG" 2>&1) >>"$LOG" 2>&1
2154 ERR_OUT="$(mktemp)"
David Bainbridge2b19e832019-08-16 02:40:53 +00002155 for i in $ONOS_FILES; do
David Bainbridged18f4942020-04-14 16:46:13 -07002156 if [ ! -r "./onos-files/$i" ]; then
serkant.uluderya4d315132020-04-15 16:25:54 -07002157 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 -07002158 espin - "$THEX"
2159 echo -e "${RED}${BOLD}${ERROR}ERROR: $i${NORMAL}${RED} - $(cat "$ERR_OUT")${NORMAL}"
2160 echo "ERROR: $(cat "$ERR_OUT")" >>"$LOG"
2161 rm -rf "$ERR_OUT" "./onos-files/$i"
David K. Bainbridgea00736b2020-01-08 14:33:17 -08002162 exit 1
2163 fi
David Bainbridged18f4942020-04-14 16:46:13 -07002164 rm -rf "$ERR_OUT"
David Bainbridged31d6122019-08-13 19:37:59 +00002165 fi
2166 done
David Bainbridged18f4942020-04-14 16:46:13 -07002167 rm -rf "$ERR_OUT"
2168 espin - "$VERIFIED"
David Bainbridge27790d62019-08-13 22:43:19 +00002169
David Bainbridged18f4942020-04-14 16:46:13 -07002170 if [ "$INSTALL_ONOS_APPS" == "yes" ]; then
David Bainbridge27790d62019-08-13 22:43:19 +00002171 bspin - "Installing custom ONOS applications"
David Bainbridged18f4942020-04-14 16:46:13 -07002172 if [ -x onos-files/onos-apps ] && [ "$(find onos-files/onos-apps -name "*.oar" 2>/dev/null | wc -l)" -gt 0 ]; then
2173 for OAR in onos-files/onos-apps/*.oar; do
David Bainbridge27790d62019-08-13 22:43:19 +00002174 sspin - "Installing custom ONOS applications - $OAR$CEOL"
David Bainbridged18f4942020-04-14 16:46:13 -07002175 override_onos_app "$OAR"
David Bainbridge27790d62019-08-13 22:43:19 +00002176 done
2177 espin - "$VERIFIED Installing custom ONOS applications$CEOL"
2178 else
2179 espin - "$NOT_VERIFIED Installing custom ONOS applications - None Found"
2180 fi
2181 fi
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07002182
David Bainbridged18f4942020-04-14 16:46:13 -07002183 if [ "$WITH_KAFKA" != "no" ]; then
David Bainbridge837e8bd2020-04-06 13:17:14 -07002184 check_onos_app_active org.opencord.kafka
David Bainbridge879439b2020-06-12 15:59:35 -07002185 if is_in "$WITH_KAFKA" "yes,external"; then
David Bainbridgec7220622020-05-28 12:31:47 -07002186 _HOST=kafka.$INFRA_NS.svc
David Bainbridge76afd812020-04-06 09:53:52 -07002187 _PORT=9092
David Bainbridge879439b2020-06-12 15:59:35 -07002188 elif [ "$WITH_KAFKA" != "no" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07002189 _HOST="$(echo "$WITH_KAFKA" | cut -d: -f1)"
2190 _PORT="$(echo "$WITH_KAFKA" | cut -s -d: -f2)"
David Bainbridge837e8bd2020-04-06 13:17:14 -07002191 _PORT=${_PORT:-9092}
2192 fi
2193 push_onos_config "json" "Push ONOS Kafka Configuration" "network/configuration/apps/org.opencord.kafka" \
David Bainbridged18f4942020-04-14 16:46:13 -07002194 "$(cat <<EOJ | tr -d '[:space:]'
David Bainbridge696bc632020-04-05 21:49:37 -07002195{
2196 "kafka": {
2197 "bootstrapServers": "$_HOST:$_PORT"
2198 }
2199}
2200EOJ
David Bainbridged18f4942020-04-14 16:46:13 -07002201)"
David Bainbridge837e8bd2020-04-06 13:17:14 -07002202 fi
Matteo Scandolo9a77a732020-01-09 14:24:12 -08002203 check_onos_app_active org.opencord.dhcpl2relay
Matteo Scandolo78dfee02020-02-13 16:18:03 -08002204 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 -08002205 check_onos_app_active org.opencord.olt
Hardik Windlassa7501fb2020-02-17 14:28:20 +00002206 # Default value for "enableEapol" is true in OLT App
David Bainbridged18f4942020-04-14 16:46:13 -07002207 if [ "$WITH_EAPOL" == "yes" ]; then
Matteo Scandolo78dfee02020-02-13 16:18:03 -08002208 push_onos_config "json" "Enable VOLTHA ONOS EAPOL provisioning" "configuration/org.opencord.olt.impl.OltFlowService" '{"enableEapol":true}'
David Bainbridged18f4942020-04-14 16:46:13 -07002209 elif [ "$WITH_EAPOL" == "no" ]; then
Hardik Windlassa7501fb2020-02-17 14:28:20 +00002210 push_onos_config "json" "Disable VOLTHA ONOS EAPOL provisioning" "configuration/org.opencord.olt.impl.OltFlowService" '{"enableEapol":false}'
Matteo Scandolo78dfee02020-02-13 16:18:03 -08002211 fi
Saurav Dasf67baf62020-08-27 14:21:58 -07002212 # Enable DHCP via component configs for dhcp programming in the OLT app. Note that sadis config per UNI port/service is also required for dhcp to work.
2213 # Two component configs are "enableDhcpV4" which is true by default, and "enableDhcpV6" which is false by default. These don't need to change until we support v6.
2214 if [[ $(semver_greater "$_ONOS_TAG" "4.1.4") == "true" ]]; then
2215 # newer versions use "enableDhcpOnNni" which is false by default
2216 if [ "$WITH_DHCP" == "yes" ]; then
2217 push_onos_config "json" "Enable VOLTHA ONOS DHCP on NNI port(s)" "configuration/org.opencord.olt.impl.OltFlowService" '{"enableDhcpOnNni":true}'
2218 elif [ "$WITH_DHCP" == "no" ]; then
2219 push_onos_config "json" "Disable VOLTHA ONOS DHCP on NNI port(s)" "configuration/org.opencord.olt.impl.OltFlowService" '{"enableDhcpOnNni":false}'
2220 fi
2221 else
2222 # older versions use "enableDhcpOnProvisioning" which is false by default
2223 if [ "$WITH_DHCP" == "yes" ]; then
2224 push_onos_config "json" "Enable VOLTHA ONOS DHCP on provisioning" "configuration/org.opencord.olt.impl.OltFlowService" '{"enableDhcpOnProvisioning":true}'
2225 elif [ "$WITH_DHCP" == "no" ]; then
2226 push_onos_config "json" "Disable VOLTHA ONOS DHCP on provisioning" "configuration/org.opencord.olt.impl.OltFlowService" '{"enableDhcpOnProvisioning":false}'
2227 fi
Matteo Scandolo78dfee02020-02-13 16:18:03 -08002228 fi
Saurav Dasf67baf62020-08-27 14:21:58 -07002229 # Enable IGMP via component configs for IGMP programming in the OLT app. Note that sadis config on UNI port/service is also required for igmp to work.
2230 # Default value for "enableIgmpOnNni" is false in OLT App
2231 if [[ $(semver_greater "$_ONOS_TAG" "4.1.4") == "true" ]]; then
2232 if [ "$WITH_IGMP" == "yes" ]; then
2233 push_onos_config "json" "Enable VOLTHA ONOS IGMP on NNI port(s)" "configuration/org.opencord.olt.impl.OltFlowService" '{"enableIgmpOnNni":true}'
2234 elif [ "$WITH_IGMP" == "no" ]; then
2235 push_onos_config "json" "Disable VOLTHA ONOS IGMP on NNI port(s)" "configuration/org.opencord.olt.impl.OltFlowService" '{"enableIgmpOnNni":false}'
2236 fi
2237 else
2238 if [ "$WITH_IGMP" == "yes" ]; then
2239 push_onos_config "json" "Enable VOLTHA ONOS IGMP on provisioning" "configuration/org.opencord.olt.impl.OltFlowService" '{"enableIgmpOnProvisioning":true}'
2240 elif [ "$WITH_IGMP" == "no" ]; then
2241 push_onos_config "json" "Disable VOLTHA ONOS IGMP on provisioning" "configuration/org.opencord.olt.impl.OltFlowService" '{"enableIgmpOnProvisioning":false}'
2242 fi
Matteo Scandolo78dfee02020-02-13 16:18:03 -08002243 fi
David Bainbridged18f4942020-04-14 16:46:13 -07002244 if [ "$ENABLE_ONOS_EXTRANEOUS_RULES" == "yes" ]; then
David K. Bainbridge484d80c2020-03-05 21:44:34 -08002245 push_onos_config "file" "Enabling extraneous rules for ONOS" "configuration/org.onosproject.net.flow.impl.FlowRuleManager" "onos-files/olt-onos-enableExtraneousRules.json"
2246 fi
David Bainbridge60ffc0f2020-04-27 22:13:22 -07002247 if is_in "$CONFIG_SADIS" "yes,file"; then
Matteo Scandolo9a77a732020-01-09 14:24:12 -08002248 check_onos_app_active org.opencord.sadis
Hardik Windlassb3147602020-03-09 16:59:15 +05302249 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 -07002250 elif [ "$CONFIG_SADIS" == "bbsim" ]; then
2251 push_onos_config "json" \
2252 "[optional] Push ONOS configuration for BBSIM SADIS servers" \
2253 "network/configuration/apps/org.opencord.sadis" \
David Bainbridged18f4942020-04-14 16:46:13 -07002254 "$(cat <<EOJ | tr -d '[:space:]'
David K. Bainbridgeb859e912020-03-13 14:07:52 -07002255{
2256 "sadis": {
2257 "integration": {
David Bainbridgec7220622020-05-28 12:31:47 -07002258 "url": "http://$BBSIM_SADIS_SVC.$BBSIM_NS.svc:50074/v2/subscribers/%s",
David K. Bainbridgeb859e912020-03-13 14:07:52 -07002259 "cache": {
2260 "enabled": true,
2261 "maxsize": 50,
2262 "ttl": "PT1m"
2263 }
2264 }
2265 },
2266 "bandwidthprofile": {
2267 "integration": {
David Bainbridgec7220622020-05-28 12:31:47 -07002268 "url": "http://$BBSIM_SADIS_SVC.$BBSIM_NS.svc:50074/v2/bandwidthprofiles/%s",
David K. Bainbridgeb859e912020-03-13 14:07:52 -07002269 "cache": {
2270 "enabled": true,
2271 "maxsize": 50,
2272 "ttl": "PT1m"
2273 }
2274 }
2275 }
2276}
2277EOJ
David Bainbridged18f4942020-04-14 16:46:13 -07002278)"
David K. Bainbridgeb859e912020-03-13 14:07:52 -07002279 elif [ "$CONFIG_SADIS" == "url" ]; then
2280 push_onos_config "json" \
2281 "[optional] Push ONOS configuration for custom SADIS and Bandwidth Profile servers" \
2282 "network/configuration/apps/org.opencord.sadis" \
David Bainbridged18f4942020-04-14 16:46:13 -07002283 "$(cat <<EOJ | tr -d '[:space:]'
David K. Bainbridgeb859e912020-03-13 14:07:52 -07002284{
2285 "sadis": {
2286 "integration": {
2287 "url": "$SADIS_SUBSCRIBERS",
2288 "cache": {
2289 "enabled": true,
2290 "maxsize": 50,
2291 "ttl": "PT1m"
2292 }
2293 }
2294 },
2295 "bandwidthprofile": {
2296 "integration": {
2297 "url": "$SADIS_BANDWIDTH_PROFILES",
2298 "cache": {
2299 "enabled": true,
2300 "maxsize": 50,
2301 "ttl": "PT1m"
2302 }
2303 }
2304 }
2305}
2306EOJ
David Bainbridged18f4942020-04-14 16:46:13 -07002307)"
David Bainbridge2b19e832019-08-16 02:40:53 +00002308 fi
Test Userba1e7e72019-07-10 22:27:54 +00002309fi
David Bainbridgee87067b2019-08-12 22:00:12 +00002310if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07002311 NOW="$(date +%s)"
2312 printtime $((NOW - STIME))
David Bainbridgee87067b2019-08-12 22:00:12 +00002313fi
Test Userba1e7e72019-07-10 22:27:54 +00002314
Matteo Scandoloe89384a2020-11-06 08:40:25 -08002315if [ "$WITH_RADIUS" == "yes" ]; then
2316 STIME="$(date +%s)"
2317 echo -e "Verify RADIUS $LOCK"
2318 bspin - "Verify RADIUS Installed"
2319 if [ "$HELM_USE_UPGRADE" == "yes" ] || [ "$(helm_is_deployed "$INFRA_NS" "^radius\$")" -ne 1 ]; then
2320 espin - "$NOT_VERIFIED"
2321 helm_install - "$INFRA_NS" radius "$RADIUS_CHART" "$RADIUS_CHART_VERSION" "+radius" "$_HELM_DESC RADIUS"
2322 else
2323 espin - "$VERIFIED"
2324 fi
2325 wait_for_pods - "$INFRA_NS" 1 "includes" "Waiting for RADIUS to start" "$NO_LABEL" "radius-.*"
2326 if [ "$WITH_TIMINGS" == "yes" ]; then
2327 NOW="$(date +%s)"
2328 printtime $((NOW - STIME))
2329 fi
2330fi
2331
2332if is_in "$WITH_ONOS" "yes,legacy,classic" && [ "$WITH_RADIUS" != "no" ]; then
2333 SVC_NAME=radius
2334 if kubectl get -n "$INFRA_NS" "svc/radius-freeradius" >/dev/null 2>&1; then
2335 SVC_NAME="radius-freeradius"
2336 fi
2337 _HOST="$SVC_NAME.$INFRA_NS.svc"
2338 _PORT=1812
2339 if [ "$WITH_RADIUS" != "yes" ]; then
2340 _HOST="$(echo "$WITH_RADIUS" | cut -d: -f1)"
2341 _PORT="$(echo "$WITH_RADIUS" | cut -s -d: -f2)"
2342 _PORT=${_PORT:-1812}
2343 fi
2344 bspin "Configure ONOS RADIUS Connection $GEAR"
2345 (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
2346 espin "$VERIFIED"
2347fi
2348
2349if [ "$CONFIG_SADIS" == "external" ]; then
2350 STIME="$(date +%s)"
2351 echo -e "Verify BBSIM SADIS Service $PLUG"
2352 bspin - "Verify required configmap"
2353 (set -x; kubectl -n "$INFRA_NS" delete --ignore-not-found configmap kube-config >>"$LOG" 2>&1) >>"$LOG" 2>&1
2354 (set -x; kubectl -n "$INFRA_NS" create configmap kube-config "--from-file=kube_config=$KUBECONFIG" >>"$LOG" 2>&1) >>"$LOG" 2>&1
2355 espin - "$VERIFIED"
2356 bspin - "Verify BBSIM SADIS Service Installed"
2357 if [ "$HELM_USE_UPGRADE" == "yes" ] || [ "$(helm_is_deployed "$INFRA_NS" "^bbsim-sadis-server\$")" -ne 1 ]; then
2358 espin - "$NOT_VERIFIED"
2359 INTERNAL_EXTRA_HELM_INSTALL_ARGS="$EXTRA_HELM_FLAGS" helm_install - "$INFRA_NS" bbsim-sadis-server "$BBSIM_SADIS_SERVER_CHART" "$BBSIM_SADIS_SERVER_CHART_VERSION" "+sadis" "$_HELM_DESC BBSIM SADIS Server"
2360 INTERNAL_EXTRA_HELM_INSTALL_ARGS=
2361 else
2362 espin - "$VERIFIED"
2363 fi
2364 wait_for_pods - "$INFRA_NS" 1 "includes" "Waiting for BBSIM SADIS Server to start" "$NO_LABEL" "bbsim-sadis-server-.*"
2365
2366 if is_in "$WITH_ONOS" "yes,classic,legacy"; then
2367 if kubectl get -n "$INFRA_NS" svc/bbsim-sadis-server-bbsim-sadis-server >/dev/null 2>&1; then
2368 BBSIM_SADIS_SVC="bbsim-sadis-server-bbsim-sadis-server"
2369 else
2370 BBSIM_SADIS_SVC="bbsim-sadis-server"
2371 fi
2372 push_onos_config "json" \
2373 "[optional] Push ONOS configuration for custom SADIS and Bandwidth Profile servers" \
2374 "network/configuration/apps/org.opencord.sadis" \
2375 "$(cat <<EOJ | tr -d '[:space:]'
2376{
2377 "sadis": {
2378 "integration": {
2379 "url": "http://$BBSIM_SADIS_SVC.$INFRA_NS.svc:58080/subscribers/%s",
2380 "cache": {
2381 "enabled": true,
2382 "maxsize": 50,
2383 "ttl": "PT1m"
2384 }
2385 }
2386 },
2387 "bandwidthprofile": {
2388 "integration": {
2389 "url": "http://$BBSIM_SADIS_SVC.$INFRA_NS.svc:58080/profiles/%s",
2390 "cache": {
2391 "enabled": true,
2392 "maxsize": 50,
2393 "ttl": "PT1m"
2394 }
2395 }
2396 }
2397}
2398EOJ
2399)"
2400 fi
2401 if [ "$WITH_TIMINGS" == "yes" ]; then
2402 NOW="$(date +%s)"
2403 printtime $((NOW - STIME))
2404 fi
2405fi
2406
2407if [ "$WITH_EFK" == "yes" ]; then
2408 STIME="$(date +%s)"
2409 echo -e "Verify EFK $PLUG"
2410 bspin - "Verify EFK Installed"
2411 if [ "$HELM_USE_UPGRADE" == "yes" ] || [ "$(helm_is_deployed "$INFRA_NS" "^elasticsearch\$")" -ne 1 ] || [ "$(helm_is_deployed "$INFRA_NS" "^kibana\$")" -ne 1 ] || [ "$(helm_is_deployed "$INFRA_NS" "^fluentd\$")" -ne 1 ]; then
2412 espin - "$NOT_VERIFIED"
2413 if [ "$HELM_USE_UPGRADE" == "yes" ] || [ "$(helm_is_deployed "$INFRA_NS" "^elasticsearch\$")" -ne 1 ]; then
2414 helm_install - "$INFRA_NS" elasticsearch "$ELASTICSEARCH_CHART" "$ELASTICSEARCH_CHART_VERSION" elasticsearch "$_HELM_DESC elasticsearch"
2415 fi
2416 if [ "$HELM_USE_UPGRADE" == "yes" ] || [ "$(helm_is_deployed "$INFRA_NS" "^kibana\$")" -ne 1 ]; then
2417 helm_install - "$INFRA_NS" kibana "$KIBANA_CHART" "$KIBANA_CHART_VERSION" kibana "$_HELM_DESC kibana"
2418 fi
2419 if [ "$HELM_USE_UPGRADE" == "yes" ] || [ "$(helm_is_deployed "$INFRA_NS" "^fluentd\$")" -ne 1 ]; then
2420 helm_install - "$INFRA_NS" fluentd "$FLUENTD_ELASTICSEARCH_CHART" "$FLUENTD_ELASTICSEARCH_CHART_VERSION" fluentd-elasticsearch "$_HELM_DESC fluentd-elasticsearch"
2421 fi
2422 else
2423 espin - "$VERIFIED"
2424 fi
2425 EXPECT=2 # for elastic and kibana
2426 if [ "$TYPE" == "minimal" ]; then
2427 EXPECT=$((EXPECT + 2)) # for fluentd on worker 2 worker nodes
2428 else
2429 EXPECT=$((EXPECT + 3)) # for fluentd on worker 3 worker nodes
2430 fi
2431 if [ "$SCHEDULE_ON_CONTROL_NODES" == "yes" ]; then
2432 EXPECT=$((EXPECT + 1)) # for fluentd on the control plan node
2433 fi
2434
2435 wait_for_pods - "$INFRA_NS" "$EXPECT" "includes" "Waiting for EFK to start" "$NO_LABEL" "fluentd-* elasticsearch-* kibana-*"
2436
2437 if [ "$WITH_PORT_FORWARDS" == "yes" ]; then
2438 bspin - "Forward EFK port $FORWARD"
2439 kill_port_forward "$INFRA_NS" elasticsearch-master
2440 kill_port_forward "$INFRA_NS" kibana-kibana
2441 port_forward "$INFRA_NS" elasticsearch-master "$ELASTICSEARCH_PORT:9200"
2442 port_forward "$INFRA_NS" kibana-kibana "$KIBANA_PORT:5601"
2443 espin - "$VERIFIED"
2444 fi
2445
2446 do_curl "" "POST" "" "" "http://localhost:$KIBANA_PORT/api/saved_objects/index-pattern/logst*" "json" '{"attributes":{"title":"logst*","timeFieldName":"@timestamp"}}' "Verify logging index in EFK" "409,200" "-H Content-type:application/json -H kbn-xsrf:true" "$GEAR"
2447
2448 if [ "$WITH_TIMINGS" == "yes" ]; then
2449 NOW="$(date +%s)"
2450 printtime $((NOW - STIME))
2451 fi
2452fi
2453
Girish Kumarcc5f9172020-06-10 13:34:31 +00002454if [ "$WITH_TRACING" == "yes" ]; then
2455 STIME="$(date +%s)"
2456 echo -e "Verify Jaeger Tracing $PLUG"
2457 bspin - "Verify Jaeger Tracing Installed"
2458 if [ "$HELM_USE_UPGRADE" == "yes" ] || [ "$(helm_is_deployed "$INFRA_NS" "^tracing\$")" -ne 1 ]; then
2459 espin - "$NOT_VERIFIED"
2460 INTERNAL_EXTRA_HELM_INSTALL_ARGS=
2461 helm_install - "$INFRA_NS" tracing "$VOLTHA_TRACING_CHART" "$VOLTHA_TRACING_CHART_VERSION" tracing "$_HELM_DESC Jaeger Tracing"
2462 else
2463 espin - "$VERIFIED"
2464 fi
2465 wait_for_pods - "$INFRA_NS" 1 "includes" "Waiting for Jaeger Tracing to start" "$NO_LABEL" "jaeger*"
Matteo Scandoloe89384a2020-11-06 08:40:25 -08002466
2467 if [ "$WITH_PORT_FORWARDS" == "yes" ]; then
2468 bspin - "Forward VOLTHA Tracing GUI port $FORWARD"
2469 VOLTHA_TRACING_CHART_NAME=$(resolve_chart_name "$VOLTHA_TRACING_CHART")
2470 kill_port_forward "$INFRA_NS" "tracing-${VOLTHA_TRACING_CHART_NAME}-jaeger-gui"
2471 port_forward "$INFRA_NS" "tracing-${VOLTHA_TRACING_CHART_NAME}-jaeger-gui" "$TRACING_GUI_PORT:16686"
2472 espin - "$VERIFIED"
2473 fi
2474
Girish Kumarcc5f9172020-06-10 13:34:31 +00002475 if [ "$WITH_TIMINGS" == "yes" ]; then
2476 NOW="$(date +%s)"
2477 printtime $((NOW - STIME))
2478 fi
2479fi
2480
Matteo Scandoloe89384a2020-11-06 08:40:25 -08002481if [ "$JUST_INFRA" == "yes" ]; then
2482 echo "Infrastructure deployed, not deploying VOLTHA artifacts as requested. Good bye." | tee -a "$LOG"
2483 echo ""
2484 echo "Please issue the following commands in your terminal to ensure that you" | tee -a "$LOG"
2485 echo "are accessing the correct Kubernetes/Kind cluster as well as have the " | tee -a "$LOG"
2486 echo "tools required by VOLTHA in your command path. " | tee -a "$LOG"
2487 echo "" | tee -a "$LOG"
2488
2489 echo -en "$BOLD"
2490 if [ "$DEPLOY_K8S" == "yes" ]; then
2491 echo "export KUBECONFIG=\"$HOME/.kube/kind-config-voltha-$NAME\"" | tee -a "$LOG"
2492 fi
2493 echo "export VOLTCONFIG=\"$HOME/.volt/config-$NAME\"" | tee -a "$LOG"
2494 echo "export PATH=$GOPATH/bin:\$PATH" | tee -a "$LOG"
2495 echo " "
2496 echo -en "$NORMAL"
2497 echo "To configure your VOLTHA stack to use this infrastructure please export these variables:" | tee -a "$LOG"
2498 echo -en "$BOLD"
2499 echo " export INFRA_NS=$INFRA_NS"
2500 echo " export WITH_ETCD=etcd.$INFRA_NS.svc:2379"
2501 echo " export WITH_KAFKA=kafka.$INFRA_NS.svc:9092"
2502 echo " export WITH_ONOS=onos-onos-classic-hs.$INFRA_NS.svc:6653"
2503 echo -en "$NORMAL"
2504 echo " "
2505 echo "Or use:"
2506 echo " "
2507 echo -en "$BOLD"
2508 echo " INFRA_NS=$INFRA_NS WITH_ETCD=etcd.$INFRA_NS.svc:2379 WITH_KAFKA=kafka.$INFRA_NS.svc:9092 WITH_ONOS=onos-onos-classic-hs.$INFRA_NS.svc:6653 ./voltha up"
2509 echo -en "$NORMAL"
2510 echo " "
2511 echo "If you are deploying mutltiple VOLTHA stack, also remember to configure a different NAME, NAMESPACE and BBSIM_BASE_INDEX for each stack:"
2512 echo -en "$BOLD"
2513 echo " export NAME=voltha1"
2514 echo " export VOLTHA_NS=voltha1"
2515 echo " export ADAPTER_NS=voltha1"
2516 echo " export BBSIM_NS=voltha1"
2517 echo " export BBSIM_BASE_INDEX=1"
2518 echo -en "$NORMAL"
2519 echo " "
2520 echo "Or use:"
2521 echo " "
2522 echo -en "$BOLD"
2523 echo " INFRA_NS=$INFRA_NS WITH_ETCD=etcd.$INFRA_NS.svc:2379 WITH_KAFKA=kafka.$INFRA_NS.svc:9092 WITH_ONOS=onos-onos-classic-hs.$INFRA_NS.svc:6653" \
2524 "NAME=voltha1 VOLTHA_NS=voltha1 ADAPTER_NS=voltha1 BBSIM_NS=voltha1 BBSIM_BASE_INDEX=1 ./voltha up"
2525 echo -en "$NORMAL"
2526 exit 0
2527fi
2528
David Bainbridged18f4942020-04-14 16:46:13 -07002529STIME="$(date +%s)"
David Bainbridgeed476572020-06-02 14:05:45 -07002530EXPECT=2
2531# therecanbeonlyone set hardcoded to true for backward compatibility
2532INTERNAL_EXTRA_HELM_INSTALL_ARGS="--set therecanbeonlyone=true"
Matteo Scandoloe89384a2020-11-06 08:40:25 -08002533
2534# customize the topics in case of multiple stacks sharing the same kafka
2535INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set defaults.topics.core_topic=$NAME-rwcore,defaults.kv_store_data_prefix=service/$NAME"
2536
Matteo Scandolo67335f02020-04-09 11:19:53 -07002537case $WITH_ETCD in
David Bainbridge76afd812020-04-06 09:53:52 -07002538 no)
David Bainbridge76afd812020-04-06 09:53:52 -07002539 ;;
David Bainbridgec7220622020-05-28 12:31:47 -07002540 yes|external)
2541 _HOST="etcd.$INFRA_NS.svc"
David Bainbridge76afd812020-04-06 09:53:52 -07002542 _PORT=2379
David K. Bainbridgeec1cdf32020-07-23 15:51:07 +00002543 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set services.etcd.service=$_HOST --set services.etcd.port=$_PORT"
Neha Sharmaa1c92ca2020-06-24 11:50:33 +00002544 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set services.etcd.address=$_HOST:$_PORT"
David Bainbridge76afd812020-04-06 09:53:52 -07002545 ;;
2546 *)
David Bainbridged18f4942020-04-14 16:46:13 -07002547 _HOST="$(echo "$WITH_ETCD" | cut -d: -f1)"
2548 _PORT="$(echo "$WITH_ETCD" | cut -s -d: -f2)"
David Bainbridge696bc632020-04-05 21:49:37 -07002549 _PORT=${_PORT:-2379}
David K. Bainbridgeec1cdf32020-07-23 15:51:07 +00002550 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set services.etcd.service=$_HOST --set services.etcd.port=$_PORT"
Neha Sharmaa1c92ca2020-06-24 11:50:33 +00002551 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set services.etcd.address=$_HOST:$_PORT"
David Bainbridge76afd812020-04-06 09:53:52 -07002552 ;;
2553esac
2554case $WITH_KAFKA in
2555 no)
David Bainbridge76afd812020-04-06 09:53:52 -07002556 ;;
David Bainbridgec7220622020-05-28 12:31:47 -07002557 yes|external)
2558 _HOST=kafka.$INFRA_NS.svc
David Bainbridge76afd812020-04-06 09:53:52 -07002559 _PORT=9092
David K. Bainbridgeec1cdf32020-07-23 15:51:07 +00002560 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"
2561 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set services.kafka.adapter.address=$_HOST:$_PORT --set services.kafka.cluster.address=$_HOST:$_PORT"
David Bainbridge76afd812020-04-06 09:53:52 -07002562 ;;
2563 *)
David Bainbridged18f4942020-04-14 16:46:13 -07002564 _HOST="$(echo "$WITH_KAFKA" | cut -d: -f1)"
2565 _PORT="$(echo "$WITH_KAFKA" | cut -s -d: -f2)"
David Bainbridge696bc632020-04-05 21:49:37 -07002566 _PORT=${_PORT:-9092}
David K. Bainbridgeec1cdf32020-07-23 15:51:07 +00002567 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"
2568 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set services.kafka.adapter.address=$_HOST:$_PORT --set services.kafka.cluster.address=$_HOST:$_PORT"
David Bainbridge76afd812020-04-06 09:53:52 -07002569 ;;
2570esac
2571
David Bainbridge60ffc0f2020-04-27 22:13:22 -07002572if is_in "$WITH_ONOS" "legacy"; then
David Bainbridgec7220622020-05-28 12:31:47 -07002573 _HOST=onos-openflow.$INFRA_NS.svc
David Bainbridge76afd812020-04-06 09:53:52 -07002574 _PORT=6653
David Bainbridge60ffc0f2020-04-27 22:13:22 -07002575elif is_in "$WITH_ONOS" "yes,classic"; then
David Bainbridgec7220622020-05-28 12:31:47 -07002576 _HOST=onos-onos-classic-hs.$INFRA_NS.svc
David Bainbridge60ffc0f2020-04-27 22:13:22 -07002577 _PORT=6653
David Bainbridged18f4942020-04-14 16:46:13 -07002578elif [ "$WITH_ONOS" != "no" ]; then
2579 _HOST="$(echo "$WITH_ONOS" | cut -d: -f1)"
2580 _PORT="$(echo "$WITH_ONOS" | cut -s -d: -f2)"
David Bainbridge76afd812020-04-06 09:53:52 -07002581 _PORT=${_PORT:-6653}
Jonathan Hart6a91e6c2020-04-16 14:28:33 -07002582fi
David Bainbridge60ffc0f2020-04-27 22:13:22 -07002583
David Bainbridgecf546362020-04-21 23:18:50 -07002584compare_versions "$RESOLVED_VOLTHA_CHART_VERSION" 2.4.2
Jonathan Hart6a91e6c2020-04-16 14:28:33 -07002585if [ "$?" == "1" ]; then
2586 # voltha chart > 2.4.2 uses list of controllers
David Bainbridgee4d11ca2020-05-08 10:21:10 -07002587 for NUM in $(seq 0 $((NUM_OF_ONOS-1))); do
David K. Bainbridgeec1cdf32020-07-23 15:51:07 +00002588 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set services.controller[$NUM].service=onos-onos-classic-$NUM.onos-onos-classic-hs.$INFRA_NS.svc --set services.controller[$NUM].port=6653"
Neha Sharmaa1c92ca2020-06-24 11:50:33 +00002589 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set services.controller[$NUM].address=onos-onos-classic-$NUM.onos-onos-classic-hs.$INFRA_NS.svc:6653"
David Bainbridgee4d11ca2020-05-08 10:21:10 -07002590 done
Jonathan Hart6a91e6c2020-04-16 14:28:33 -07002591else
2592 # voltha chart <= 2.4.2 uses single controller
David K. Bainbridgeec1cdf32020-07-23 15:51:07 +00002593 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set services.controller.service=$_HOST --set services.controller.port=$_PORT"
Neha Sharmaa1c92ca2020-06-24 11:50:33 +00002594 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set services.controller.address=$_HOST:$_PORT"
David Bainbridge696bc632020-04-05 21:49:37 -07002595fi
Jonathan Hart6a91e6c2020-04-16 14:28:33 -07002596
Girish Kumarcc5f9172020-06-10 13:34:31 +00002597if [ "$WITH_TRACING" == "yes" ]; then
2598 VOLTHA_TRACING_CHART_NAME=$(resolve_chart_name "$VOLTHA_TRACING_CHART")
2599 _HOST="tracing-${VOLTHA_TRACING_CHART_NAME}-jaeger-agent.$INFRA_NS.svc"
2600 _PORT=6831
2601 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set tracing.enabled=true --set services.tracing_agent.address=$_HOST:$_PORT"
2602fi
2603
Test Userb5712372019-07-03 21:52:17 +00002604bspin "Verify VOLTHA installed $HIGH_VOLTAGE"
David Bainbridgeb4bbde12020-06-25 14:46:36 -07002605if [ "$HELM_USE_UPGRADE" == "yes" ] || [ "$(helm_is_deployed "$VOLTHA_NS" "^voltha\$")" -ne 1 ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07002606 espin "$NOT_VERIFIED"
David Bainbridgea965ca22020-06-09 17:45:04 -07002607 helm_install - "$VOLTHA_NS" voltha "$VOLTHA_CHART" "$VOLTHA_CHART_VERSION" "+voltha" "$_HELM_DESC VOLTHA Core"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07002608else
David Bainbridged18f4942020-04-14 16:46:13 -07002609 espin "$VERIFIED"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07002610fi
David Bainbridge696bc632020-04-05 21:49:37 -07002611INTERNAL_EXTRA_HELM_INSTALL_ARGS=
Test Userba1e7e72019-07-10 22:27:54 +00002612
David Bainbridge90fd8e32019-08-21 23:32:47 +00002613VOLTHA="voltha-ofagent-.* \
David K. Bainbridgeb7285432019-07-02 22:05:24 -07002614 rw-core.* \
David K. Bainbridgeb7285432019-07-02 22:05:24 -07002615 voltha-zookeeper-.*"
David Bainbridged18f4942020-04-14 16:46:13 -07002616wait_for_pods - "$VOLTHA_NS" "$EXPECT" "includes" "Waiting for VOLTHA Core to start" "$NO_LABEL" "$VOLTHA"
David Bainbridgee87067b2019-08-12 22:00:12 +00002617if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07002618 NOW="$(date +%s)"
2619 printtime $((NOW - STIME))
David Bainbridgee87067b2019-08-12 22:00:12 +00002620fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07002621
David Bainbridge46505fb2019-10-01 21:13:20 +00002622if [ "$WITH_ADAPTERS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07002623 STIME="$(date +%s)"
David Bainbridge46505fb2019-10-01 21:13:20 +00002624 EXPECT=0
Matteo Scandoloe89384a2020-11-06 08:40:25 -08002625 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set defaults.topics.core_topic=$NAME-rwcore,defaults.topics.adapter_open_olt_topic=$NAME-openolt,defaults.topics.adapter_open_onu_topic=$NAME-brcm_openomci_onu,defaults.kv_store_data_prefix=service/$NAME"
David Bainbridgec7220622020-05-28 12:31:47 -07002626 if is_in "$WITH_ETCD" "yes,external"; then
2627 _HOST=etcd.$INFRA_NS.svc
David Bainbridge3517f6c2020-04-08 12:14:08 -07002628 _PORT=2379
David K. Bainbridgeec1cdf32020-07-23 15:51:07 +00002629 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set services.etcd.service=$_HOST --set services.etcd.port=$_PORT"
2630 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set services.etcd.address=$_HOST:$_PORT"
David Bainbridged18f4942020-04-14 16:46:13 -07002631 elif [ "$WITH_ETCD" != "no" ]; then
2632 _HOST="$(echo "$WITH_ETCD" | cut -d: -f1)"
2633 _PORT="$(echo "$WITH_ETCD" | cut -s -d: -f2)"
David Bainbridge3517f6c2020-04-08 12:14:08 -07002634 _PORT=${_PORT:-2379}
David K. Bainbridgeec1cdf32020-07-23 15:51:07 +00002635 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set services.etcd.service=$_HOST --set services.etcd.port=$_PORT"
2636 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set services.etcd.address=$_HOST:$_PORT"
David Bainbridge696bc632020-04-05 21:49:37 -07002637 fi
David Bainbridgec7220622020-05-28 12:31:47 -07002638 if is_in "$WITH_KAFKA" "yes,external"; then
2639 _HOST=kafka.$INFRA_NS.svc
David Bainbridge3517f6c2020-04-08 12:14:08 -07002640 _PORT=9092
David K. Bainbridgeec1cdf32020-07-23 15:51:07 +00002641 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"
2642 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set services.kafka.adapter.address=$_HOST:$_PORT --set services.kafka.cluster.address=$_HOST:$_PORT"
David Bainbridged18f4942020-04-14 16:46:13 -07002643 elif [ "$WITH_KAFKA" != "no" ]; then
2644 _HOST="$(echo "$WITH_KAFKA" | cut -d: -f1)"
2645 _PORT="$(echo "$WITH_KAFKA" | cut -s -d: -f2)"
David Bainbridge3517f6c2020-04-08 12:14:08 -07002646 _PORT=${_PORT:-9092}
David K. Bainbridgeec1cdf32020-07-23 15:51:07 +00002647 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"
2648 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set services.kafka.adapter.address=$_HOST:$_PORT --set services.kafka.cluster.address=$_HOST:$_PORT"
David Bainbridge696bc632020-04-05 21:49:37 -07002649 fi
Girish Kumarcc5f9172020-06-10 13:34:31 +00002650 if [ "$WITH_TRACING" == "yes" ]; then
2651 VOLTHA_TRACING_CHART_NAME=$(resolve_chart_name "$VOLTHA_TRACING_CHART")
2652 _HOST="tracing-${VOLTHA_TRACING_CHART_NAME}-jaeger-agent.$INFRA_NS.svc"
2653 _PORT=6831
2654 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set tracing.enabled=true --set services.tracing_agent.address=$_HOST:$_PORT"
2655 fi
David Bainbridge46505fb2019-10-01 21:13:20 +00002656 echo -e "Verify Adapters $PLUG"
2657 if [ "$WITH_SIM_ADAPTERS" == "yes" ]; then
2658 bspin - "Verify Simulated Adapters installed"
David Bainbridgeb4bbde12020-06-25 14:46:36 -07002659 if [ "$HELM_USE_UPGRADE" == "yes" ] || [ "$(helm_is_deployed "$ADAPTER_NS" "^sim\$")" -ne 1 ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07002660 espin - "$NOT_VERIFIED"
David Bainbridgec7220622020-05-28 12:31:47 -07002661 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 +00002662 else
David Bainbridged18f4942020-04-14 16:46:13 -07002663 espin - "$VERIFIED"
David Bainbridge46505fb2019-10-01 21:13:20 +00002664 fi
David Bainbridged18f4942020-04-14 16:46:13 -07002665 EXPECT="$((EXPECT + 2))"
David Bainbridge46505fb2019-10-01 21:13:20 +00002666 fi
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07002667
David Bainbridge46505fb2019-10-01 21:13:20 +00002668 if [ "$WITH_OPEN_ADAPTERS" == "yes" ]; then
2669 bspin - "Verify OpenOLT Adapter installed"
David Bainbridgeb4bbde12020-06-25 14:46:36 -07002670 if [ "$HELM_USE_UPGRADE" == "yes" ] || [ "$(helm_is_deployed "$ADAPTER_NS" "^open-olt\$")" -ne 1 ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07002671 espin - "$NOT_VERIFIED"
David Bainbridgea965ca22020-06-09 17:45:04 -07002672 helm_install - "$ADAPTER_NS" open-olt "$VOLTHA_ADAPTER_OPEN_OLT_CHART" "$VOLTHA_ADAPTER_OPEN_OLT_CHART_VERSION" "+open-olt" "$_HELM_DESC OpenOLT Adapter"
David Bainbridge46505fb2019-10-01 21:13:20 +00002673 else
David Bainbridged18f4942020-04-14 16:46:13 -07002674 espin - "$VERIFIED"
David Bainbridge46505fb2019-10-01 21:13:20 +00002675 fi
Matteo Scandolo67335f02020-04-09 11:19:53 -07002676 EXPECT="$((EXPECT + 1))"
David Bainbridge46505fb2019-10-01 21:13:20 +00002677 bspin - "Verify OpenONU Adapter installed"
David Bainbridgeb4bbde12020-06-25 14:46:36 -07002678 if [ "$HELM_USE_UPGRADE" == "yes" ] || [ "$(helm_is_deployed "$ADAPTER_NS" "^open-onu\$")" -ne 1 ]; then
Matteo Scandolo67335f02020-04-09 11:19:53 -07002679 _ORIGINAL_EXTRA_HELM_INSTALL_ARGS="$INTERNAL_EXTRA_HELM_INSTALL_ARGS"
2680 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set replicas.adapter_open_onu=$NUM_OF_OPENONU"
Girish Gowdra4cc5d8b2020-06-11 17:12:00 -07002681 if [ "$WITH_INCREMENTAL_EVTO_UPDATE" == "yes" ]; then
Girish Gowdra1c7ad4c2020-06-26 13:35:16 -07002682 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set defaults.incremental_evto_update=true"
Girish Gowdra4cc5d8b2020-06-11 17:12:00 -07002683 fi
David Bainbridged18f4942020-04-14 16:46:13 -07002684 espin - "$NOT_VERIFIED"
David Bainbridgea965ca22020-06-09 17:45:04 -07002685 helm_install - "$ADAPTER_NS" open-onu "$VOLTHA_ADAPTER_OPEN_ONU_CHART" "$VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION" "+open-onu" "$_HELM_DESC OpenONU Adapter"
Matteo Scandolo67335f02020-04-09 11:19:53 -07002686 INTERNAL_EXTRA_HELM_INSTALL_ARGS="$_ORIGINAL_EXTRA_HELM_INSTALL_ARGS"
David Bainbridge46505fb2019-10-01 21:13:20 +00002687 else
David Bainbridged18f4942020-04-14 16:46:13 -07002688 espin - "$VERIFIED"
David Bainbridge46505fb2019-10-01 21:13:20 +00002689 fi
Matteo Scandolo67335f02020-04-09 11:19:53 -07002690 EXPECT=$((EXPECT + NUM_OF_OPENONU))
David Bainbridge46505fb2019-10-01 21:13:20 +00002691 fi
David Bainbridge696bc632020-04-05 21:49:37 -07002692 INTERNAL_EXTRA_HELM_INSTALL_ARGS=
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07002693
David Bainbridge46505fb2019-10-01 21:13:20 +00002694 ADAPTERS="adapter-.*"
David Bainbridged18f4942020-04-14 16:46:13 -07002695 wait_for_pods - "$ADAPTER_NS" "$EXPECT" "includes" "Waiting for adapters to start" "$NO_LABEL" "$ADAPTERS"
David Bainbridge46505fb2019-10-01 21:13:20 +00002696 if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07002697 NOW="$(date +%s)"
2698 printtime $((NOW - STIME))
David Bainbridge46505fb2019-10-01 21:13:20 +00002699 fi
David Bainbridgee87067b2019-08-12 22:00:12 +00002700fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07002701
David Bainbridged18f4942020-04-14 16:46:13 -07002702if [ "$WITH_BBSIM" == "yes" ]; then
2703 STIME="$(date +%s)"
Test User7d866122019-07-09 17:52:35 +00002704 echo -e "Verify BBSIM $PLUG"
David Bainbridge5b7b96b2019-07-25 20:29:13 +00002705 bspin - "Verify BBSIM Installed"
Matteo Scandoloe89384a2020-11-06 08:40:25 -08002706
David Bainbridged18f4942020-04-14 16:46:13 -07002707 for instance in $(seq 0 $((NUM_OF_BBSIM-1))); do
Matteo Scandoloc2eb0672020-05-01 14:43:15 -07002708
2709 if [ "$LEGACY_BBSIM_INDEX" == "yes" ]; then
2710 if [ "$instance" -eq 0 ]; then
2711 instance_num=""
2712 else
2713 instance_num=$instance
2714 fi
David K. Bainbridge43422402020-03-06 07:41:22 -08002715 else
2716 instance_num=$instance
2717 fi
Matteo Scandoloc2eb0672020-05-01 14:43:15 -07002718
2719
David Bainbridgeb4bbde12020-06-25 14:46:36 -07002720 if [ "$HELM_USE_UPGRADE" == "yes" ] || [ "$(helm_is_deployed "$BBSIM_NS" "^bbsim${instance_num}\$")" -ne 1 ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07002721 espin - "$NOT_VERIFIED"
Matteo Scandolo6402d362020-08-24 12:31:06 -07002722
2723 if [[ $(semver_greater "$VOLTHA_BBSIM_CHART_VERSION" "3.1.0") == "true" ]]; then
2724 # this is the latest BBSim with support for TT
2725 # when we deploy multiple BBSims we need to update the configuration
2726 # to avoid overlapping tags.
2727 _TAG="$((900+instance))"
2728 BBSIM_TMP="$(mktemp -u)"
2729 sed -e "s/\":TAG:\"/$_TAG/g" "$BBSIM_CFG" > "$BBSIM_TMP"
Matteo Scandoloe89384a2020-11-06 08:40:25 -08002730 INTERNAL_EXTRA_HELM_INSTALL_ARGS="--set olt_id=$BBSIM_BASE_INDEX$instance -f $BBSIM_TMP"
David Bainbridged9329af2020-05-01 11:58:52 -07002731 else
Matteo Scandolo6402d362020-08-24 12:31:06 -07002732 # these are older versio of BBSim
2733 S_TAG="$((900+instance))"
2734 INTERNAL_EXTRA_HELM_INSTALL_ARGS="--set olt_id=$instance,s_tag=$S_TAG"
2735 if [ "$WITH_EAPOL" == "yes" ]; then
2736 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set auth=true"
2737 else
2738 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set auth=false"
2739 fi
2740 if [ "$WITH_DHCP" == "yes" ]; then
2741 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set dhcp=true"
2742 else
2743 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set dhcp=false"
2744 fi
David Bainbridged9329af2020-05-01 11:58:52 -07002745 fi
Matteo Scandolo6402d362020-08-24 12:31:06 -07002746
David Bainbridge33e56c72020-06-11 11:39:56 -07002747 if is_in "$WITH_KAFKA" "yes,external"; then
2748 _HOST=kafka.$INFRA_NS.svc
2749 _PORT=9092
2750 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set kafkaAddress=$_HOST:$_PORT"
2751 elif [ "$WITH_KAFKA" != "no" ]; then
2752 _HOST="$(echo "$WITH_KAFKA" | cut -d: -f1)"
2753 _PORT="$(echo "$WITH_KAFKA" | cut -s -d: -f2)"
2754 _PORT=${_PORT:-9092}
2755 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set kafkaAddress=$_HOST:$_PORT"
2756 fi
2757 helm_install - "$BBSIM_NS" "bbsim${instance_num}" "$VOLTHA_BBSIM_CHART" "$VOLTHA_BBSIM_CHART_VERSION" "+bbsim" "$_HELM_DESC BBSIM${instance_num}"
David Bainbridge2eaf2cf2020-03-18 12:54:08 -07002758 INTERNAL_EXTRA_HELM_INSTALL_ARGS=
Matteo Scandolo6402d362020-08-24 12:31:06 -07002759 rm -f "$BBSIM_TMP"
David K. Bainbridge43422402020-03-06 07:41:22 -08002760 else
David Bainbridged18f4942020-04-14 16:46:13 -07002761 espin - "$VERIFIED"
David K. Bainbridge43422402020-03-06 07:41:22 -08002762 fi
2763 done
David Bainbridged18f4942020-04-14 16:46:13 -07002764 wait_for_pods - "$BBSIM_NS" "$NUM_OF_BBSIM" "includes" "Waiting for BBSIM to start" "$BBSIM_LABEL" "bbsim*"
Andrea Campanella8a75f722020-10-14 14:22:01 +02002765 if [ "$WITH_PORT_FORWARDS" == "yes" ]; then
2766 for instance in $(seq 0 $((NUM_OF_BBSIM-1))); do
2767 bspin - "Forward BBSIM DMI port $FORWARD"
Matteo Scandoloe89384a2020-11-06 08:40:25 -08002768 kill_port_forward "$BBSIM_NS" "bbsim${instance}"
Andrea Campanellaeacf7f42020-10-15 14:46:33 +02002769 _PORT=$((50075+instance))
2770 port_forward "$BBSIM_NS" "bbsim${instance}" "50075:$_PORT"
Andrea Campanella8a75f722020-10-14 14:22:01 +02002771 espin - "$VERIFIED"
2772 done
2773 fi
2774
David Bainbridgee87067b2019-08-12 22:00:12 +00002775 if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07002776 NOW="$(date +%s)"
2777 printtime $((NOW - STIME))
David Bainbridgee87067b2019-08-12 22:00:12 +00002778 fi
Test User7d866122019-07-09 17:52:35 +00002779fi
2780
David Bainbridged18f4942020-04-14 16:46:13 -07002781if [ "$WITH_PORT_FORWARDS" == "yes" ]; then
2782 STIME="$(date +%s)"
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -08002783 bspin - "Forward VOLTHA API port $FORWARD"
Matteo Scandoloe89384a2020-11-06 08:40:25 -08002784 kill_port_forward "$VOLTHA_NS" voltha-api
2785 kill_port_forward "$VOLTHA_NS" voltha-voltha-api
David Bainbridge1d2c5842020-06-03 15:29:07 -07002786 VOLTHA_PREFIX=
2787 if kubectl get -n "$VOLTHA_NS" "svc/voltha-voltha-api" >/dev/null 2>&1; then
2788 VOLTHA_PREFIX="voltha-"
2789 fi
Matteo Scandolo21660442020-07-17 11:05:21 -07002790
David Bainbridge1d2c5842020-06-03 15:29:07 -07002791 port_forward "$VOLTHA_NS" "${VOLTHA_PREFIX}voltha-api" "$VOLTHA_API_PORT:55555"
David Bainbridged18f4942020-04-14 16:46:13 -07002792 espin - "$VERIFIED"
Matteo Scandoloe89384a2020-11-06 08:40:25 -08002793
Matteo Scandoloefee0432020-05-05 13:56:20 -07002794 if [ "$WITH_PPROF" == "yes" ]; then
David Bainbridge1d2c5842020-06-03 15:29:07 -07002795 VOLTHA_OPENOLT_PREFIX=
2796 if kubectl get -n "$ADAPTER_NS" "svc/open-olt-adapter-open-olt-profiler" >/dev/null 2>&1; then
2797 VOLTHA_OPENOLT_PREFIX="open-olt-"
2798 fi
David Bainbridge879439b2020-06-12 15:59:35 -07002799 bspin - "Forward PProf ports port $FORWARD"
Matteo Scandoloe89384a2020-11-06 08:40:25 -08002800 kill_port_forward "$VOLTHA_NS" voltha-rw-core-profiler
2801 kill_port_forward "$VOLTHA_NS" voltha-voltha-rw-core-profiler
2802 kill_port_forward "$VOLTHA_NS" adapter-open-olt-profiler
2803 kill_port_forward "$VOLTHA_NS" open-olt-adapter-open-olt-profiler
2804 kill_port_forward "$VOLTHA_NS" voltha-of-agent-profiler
2805 kill_port_forward "$VOLTHA_NS" voltha-voltha-of-agent-profiler
David Bainbridge879439b2020-06-12 15:59:35 -07002806 port_forward "$VOLTHA_NS" "${VOLTHA_PREFIX}voltha-rw-core-profiler" "$VOLTHA_PPROF_PORT:6060"
2807 port_forward "$ADAPTER_NS" "${VOLTHA_OPENOLT_PREFIX}adapter-open-olt-profiler" "$OPENOLT_PPROF_PORT:6060"
2808 port_forward "$VOLTHA_NS" "${VOLTHA_PREFIX}voltha-of-agent-profiler" "$OFAGENT_PPROF_PORT:6060"
2809 espin - "$VERIFIED"
Matteo Scandoloefee0432020-05-05 13:56:20 -07002810 fi
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -08002811 if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07002812 NOW="$(date +%s)"
2813 printtime $((NOW - STIME))
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -08002814 fi
David Bainbridgee87067b2019-08-12 22:00:12 +00002815fi
Test User3d7ad8e2019-07-03 06:15:44 +00002816
David Bainbridge99ac7a22019-08-31 02:26:43 +00002817if [ "$WITH_CHAOS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07002818 STIME="$(date +%s)"
David Bainbridge99ac7a22019-08-31 02:26:43 +00002819 echo -e "Verify kube-monkey $LOCK"
2820 bspin - "Verify kube-monkey Installed"
David Bainbridgeb4bbde12020-06-25 14:46:36 -07002821 if [ "$HELM_USE_UPGRADE" == "yes" ] || [ "$(helm_is_deployed kube-monkey "^monkey\$")" -ne 1 ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07002822 espin - "$NOT_VERIFIED"
David Bainbridgec7220622020-05-28 12:31:47 -07002823 helm_install - kube-monkey monkey ./kube-monkey/helm/kubemonkey latest - "$_HELM_DESC Chaos Monkey"
David Bainbridge99ac7a22019-08-31 02:26:43 +00002824 else
David Bainbridged18f4942020-04-14 16:46:13 -07002825 espin - "$VERIFIED"
David Bainbridge99ac7a22019-08-31 02:26:43 +00002826 fi
David Bainbridged18f4942020-04-14 16:46:13 -07002827 wait_for_pods - "kube-monkey" 1 "includes" "Waiting for Chaos to start" "$NO_LABEL" "monkey-.*"
David Bainbridge99ac7a22019-08-31 02:26:43 +00002828 if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07002829 NOW="$(date +%s)"
2830 printtime $((NOW - STIME))
David Bainbridge99ac7a22019-08-31 02:26:43 +00002831 fi
2832fi
2833
David Bainbridge5b7b96b2019-07-25 20:29:13 +00002834bspin "Create voltctl configuration file"
David Bainbridged18f4942020-04-14 16:46:13 -07002835(set -x; mkdir -p "$HOME/.volt" >>"$LOG" 2>&1) >>"$LOG" 2>&1
2836MIN_VC_VERSION="$(echo -e "1.0.15\n$VC_VERSION" | sort -V | head -1)"
2837if [ "$WITH_PORT_FORWARDS" == "yes" ]; then
David K. Bainbridgeb859e912020-03-13 14:07:52 -07002838 KAFKA_FLAG="-k localhost:$VOLTHA_KAFKA_PORT"
2839 SERVER_FLAG="-s localhost:$VOLTHA_API_PORT"
2840 ETCD_FLAG=
2841 if [ "$MIN_VC_VERSION" == "1.0.15" ]; then
2842 ETCD_FLAG="-e localhost:$VOLTHA_ETCD_PORT"
2843 fi
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -08002844else
David Bainbridgec7220622020-05-28 12:31:47 -07002845 KAFKA_FLAG="-k $(get_service_ep "$INFRA_NS" kafka)"
David Bainbridged18f4942020-04-14 16:46:13 -07002846 SERVER_FLAG="-s $(get_service_ep "$VOLTHA_NS" voltha-api)"
David K. Bainbridgeb859e912020-03-13 14:07:52 -07002847 ETCD_FLAG=
2848 if [ "$MIN_VC_VERSION" == "1.0.15" ]; then
David Bainbridgec7220622020-05-28 12:31:47 -07002849 ETCD_FLAG="-e $(get_service_ep "$INFRA_NS" etcd)"
David K. Bainbridgeb859e912020-03-13 14:07:52 -07002850 fi
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -08002851fi
David Bainbridgea965ca22020-06-09 17:45:04 -07002852CMD=("voltctl $KAFKA_FLAG $SERVER_FLAG $ETCD_FLAG config")
David Bainbridged18f4942020-04-14 16:46:13 -07002853(set -x; ${CMD[*]} > "$HOME/.volt/config-$NAME" 2>>"$LOG") >>"$LOG" 2>&1
David Bainbridgea965ca22020-06-09 17:45:04 -07002854#(set -x; voltctl "$KAFKA_FLAG" "$SERVER_FLAG" "$ETCD_FLAG" config > "$HOME/.volt/config-$NAME" 2>>"$LOG") >>"$LOG" 2>&1
David Bainbridged18f4942020-04-14 16:46:13 -07002855espin "$VERIFIED"
Test User08ebbd92019-07-03 17:15:39 +00002856
David Bainbridge0774b232019-08-02 06:37:19 +00002857if [ ! -f "$NAME-env.sh" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07002858 touch "$NAME-env.sh"
David Bainbridgeb07fdf72019-07-29 22:51:40 +00002859fi
2860
David Bainbridge596f30d2019-07-30 17:07:59 +00002861for O in $ALL_OPTIONS; do
David Bainbridged18f4942020-04-14 16:46:13 -07002862 VAL="$(eval echo "\$$O")"
2863 if [ -n "$VAL" ] && [ "$(grep -c "^export $O=" "$NAME-env.sh")" -eq 0 ]; then
2864 echo "export $O=\"$(eval echo "\$$O")\"" >> "$NAME-env.sh"
David Bainbridgeb07fdf72019-07-29 22:51:40 +00002865 fi
2866done
2867
David Bainbridged18f4942020-04-14 16:46:13 -07002868if [ "$DEPLOY_K8S" == "yes" ] && [ "$(grep -c "^export KUBECONFIG=" "$NAME-env.sh")" -eq 0 ]; then
David Bainbridgeb4bbde12020-06-25 14:46:36 -07002869 echo "export KUBECONFIG=\"$HOME/.kube/kind-config-voltha-$NAME\"" >> "$NAME-env.sh"
David Bainbridgeb07fdf72019-07-29 22:51:40 +00002870fi
2871
David Bainbridged18f4942020-04-14 16:46:13 -07002872if [ "$(grep -c "^export VOLTCONFIG=" "$NAME-env.sh")" -eq 0 ]; then
2873 echo "export VOLTCONFIG=\"$HOME/.volt/config-$NAME\"" >> "$NAME-env.sh"
David Bainbridgeb07fdf72019-07-29 22:51:40 +00002874fi
2875
David Bainbridged18f4942020-04-14 16:46:13 -07002876if [ "$(grep -c "^export PATH=" "$NAME-env.sh")" -eq 0 ]; then
2877 echo "export PATH=\"$GOPATH/bin:\$PATH\"" >> "$NAME-env.sh"
David Bainbridgeb07fdf72019-07-29 22:51:40 +00002878fi
2879
Test User7d866122019-07-09 17:52:35 +00002880echo ""
David Bainbridged18f4942020-04-14 16:46:13 -07002881echo "Please issue the following commands in your terminal to ensure that you" | tee -a "$LOG"
2882echo "are accessing the correct Kubernetes/Kind cluster as well as have the " | tee -a "$LOG"
2883echo "tools required by VOLTHA in your command path. " | tee -a "$LOG"
2884echo "" | tee -a "$LOG"
2885echo -en "$BOLD"
2886if [ "$DEPLOY_K8S" == "yes" ]; then
David Bainbridgeb4bbde12020-06-25 14:46:36 -07002887 echo "export KUBECONFIG=\"$HOME/.kube/kind-config-voltha-$NAME\"" | tee -a "$LOG"
Test Userba1e7e72019-07-10 22:27:54 +00002888fi
David Bainbridged18f4942020-04-14 16:46:13 -07002889echo "export VOLTCONFIG=\"$HOME/.volt/config-$NAME\"" | tee -a "$LOG"
2890echo "export PATH=$GOPATH/bin:\$PATH" | tee -a "$LOG"
2891echo -en "$NORMAL"
2892echo "" | tee -a "$LOG"
2893echo "Thank you for choosing kind-voltha for you quick cluster needs." | tee -a "$LOG"
Test User08ebbd92019-07-03 17:15:39 +00002894
David Bainbridge712afb82019-08-14 19:55:58 +00002895if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07002896 NOW="$(date +%s)"
2897 echo -e "$CLOCK ${BOLD}TOTAL: $(duration $((NOW - TOTAL_START_TIME)))${NORMAL}"
David Bainbridge712afb82019-08-14 19:55:58 +00002898fi