blob: 5efb0fb528440be3843ba6fc0d048b4dc64f316d [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}
Matteo Scandolo57161902021-05-12 15:26:11 -070069IGNORE_WARNINGS=${IGNORE_WARNINGS:-no}
David K. Bainbridge484d80c2020-03-05 21:44:34 -080070ENABLE_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="\
Matteo Scandolo57161902021-05-12 15:26:11 -0700341 IGNORE_WARNINGS \
David K. Bainbridge484d80c2020-03-05 21:44:34 -0800342 ENABLE_ONOS_EXTRANEOUS_RULES \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000343 WITH_TIMINGS \
344 WITH_BBSIM \
divyadesai59f987a2020-05-27 12:11:33 +0000345 WITH_EFK \
Girish Kumarcc5f9172020-06-10 13:34:31 +0000346 WITH_TRACING \
Matteo Scandolo78dfee02020-02-13 16:18:03 -0800347 WITH_EAPOL \
348 WITH_DHCP \
349 WITH_IGMP \
David Bainbridge99ac7a22019-08-31 02:26:43 +0000350 WITH_CHAOS \
David Bainbridge46505fb2019-10-01 21:13:20 +0000351 WITH_ADAPTERS \
352 WITH_SIM_ADAPTERS \
353 WITH_OPEN_ADAPTERS \
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -0800354 WITH_PORT_FORWARDS \
Matteo Scandoloefee0432020-05-05 13:56:20 -0700355 WITH_PPROF \
Girish Gowdra4cc5d8b2020-06-11 17:12:00 -0700356 WITH_INCREMENTAL_EVTO_UPDATE \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000357 JUST_K8S \
Matteo Scandoloe89384a2020-11-06 08:40:25 -0800358 JUST_INFRA \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000359 DEPLOY_K8S \
360 INSTALL_ONOS_APPS \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000361 INSTALL_KUBECTL \
362 INSTALL_HELM \
David Bainbridge7f8bf992020-04-08 21:53:22 -0700363 HELM_USE_UPGRADE \
David Bainbridge46505fb2019-10-01 21:13:20 +0000364 UPDATE_HELM_REPOS \
David Bainbridge4f1b5562019-08-19 04:46:52 +0000365 WAIT_ON_DOWN \
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700366 VOLTHA_DOWN_ON_TIMEOUT \
Matteo Scandoloc2eb0672020-05-01 14:43:15 -0700367 LEGACY_BBSIM_INDEX \
David Bainbridgee4d11ca2020-05-08 10:21:10 -0700368 SCHEDULE_ON_CONTROL_NODES \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000369 "
David Bainbridge5b7b96b2019-07-25 20:29:13 +0000370
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700371OPT_YES_NO="\
372 CONFIG_SADIS \
373 WITH_KAFKA \
374 WITH_RADIUS \
375 WITH_ETCD \
376 WITH_ONOS \
377 "
378
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000379ALL_OPTIONS="\
380 NAME \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000381 $ALL_YES_NO \
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700382 $OPT_YES_NO \
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700383 WAIT_TIMEOUT \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000384 VOLTHA_LOG_LEVEL \
385 VOLTHA_CHART \
David Bainbridge90fd8e32019-08-21 23:32:47 +0000386 VOLTHA_CHART_VERSION \
387 VOLTHA_BBSIM_CHART \
388 VOLTHA_BBSIM_CHART_VERSION \
David Bainbridge879439b2020-06-12 15:59:35 -0700389 BBSIM_SADIS_SERVER_CHART \
390 BBSIM_SADIS_SERVER_CHART_VERSION \
Girish Kumarcc5f9172020-06-10 13:34:31 +0000391 VOLTHA_TRACING_CHART \
392 VOLTHA_TRACING_CHART_VERSION \
uottrembd5a20572020-03-06 09:15:01 +0100393 NUM_OF_BBSIM \
Matteo Scandolo657e13c2020-07-28 11:41:42 -0700394 NUM_OF_WORKER_NODES \
395 NUM_OF_CONTROLLER_NODES \
396 NUM_OF_KAFKA \
397 NUM_OF_ETCD \
divyadesai59f987a2020-05-27 12:11:33 +0000398 ELASTICSEARCH_CHART \
399 ELASTICSEARCH_CHART_VERSION \
400 KIBANA_CHART \
401 KIBANA_CHART_VERSION \
402 FLUENTD_ELASTICSEARCH_CHART \
403 FLUENTD_ELASTICSEARCH_CHART_VERSION \
Matteo Scandolo67335f02020-04-09 11:19:53 -0700404 NUM_OF_OPENONU \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000405 VOLTHA_ADAPTER_SIM_CHART \
David Bainbridge90fd8e32019-08-21 23:32:47 +0000406 VOLTHA_ADAPTER_SIM_CHART_VERSION \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000407 VOLTHA_ADAPTER_OPEN_OLT_CHART \
David Bainbridge90fd8e32019-08-21 23:32:47 +0000408 VOLTHA_ADAPTER_OPEN_OLT_CHART_VERSION \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000409 VOLTHA_ADAPTER_OPEN_ONU_CHART \
David Bainbridge90fd8e32019-08-21 23:32:47 +0000410 VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION \
David K. Bainbridgeda33d652020-03-06 10:31:23 -0800411 ONOS_CHART \
Andrea Campanella21323292019-12-18 11:44:19 -0800412 ONOS_CHART_VERSION \
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700413 ONOS_CLASSIC_CHART \
414 ONOS_CLASSIC_CHART_VERSION \
David Bainbridgecf546362020-04-21 23:18:50 -0700415 KAFKA_CHART \
David Bainbridgeb9093522020-04-15 14:32:44 -0700416 KAFKA_CHART_VERSION \
David Bainbridge879439b2020-06-12 15:59:35 -0700417 ETCD_CHART \
418 ETCD_CHART_VERSION \
419 RADIUS_CHART \
420 RADIUS_CHART_VERSION \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000421 ONOS_API_PORT \
422 ONOS_SSH_PORT \
Hardik Windlassb3147602020-03-09 16:59:15 +0530423 SADIS_CFG \
Matteo Scandolo6402d362020-08-24 12:31:06 -0700424 BBSIM_CFG \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000425 VOLTHA_API_PORT \
426 VOLTHA_SSH_PORT \
427 VOLTHA_ETCD_PORT \
divyadesai59f987a2020-05-27 12:11:33 +0000428 ELASTICSEARCH_PORT \
429 KIBANA_PORT \
David K. Bainbridge00ecd382020-02-28 12:31:58 -0800430 VOLTHA_KAFKA_PORT \
Matteo Scandoloefee0432020-05-05 13:56:20 -0700431 VOLTHA_PPROF_PORT \
432 OPENOLT_PPROF_PORT \
Matteo Scandolo65c35192020-05-13 10:41:21 -0700433 OFAGENT_PPROF_PORT \
Girish Kumarcc5f9172020-06-10 13:34:31 +0000434 TRACING_GUI_PORT \
David K. Bainbridge8f7f30b2020-01-08 13:06:16 -0800435 VK_RELEASE \
436 KIND_VERSION \
437 VOLTCTL_VERSION \
David Bainbridgea34993d2020-04-01 09:15:42 -0700438 HELM_VERSION \
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700439 NUM_OF_ONOS \
440 NUM_OF_ATOMIX \
David Bainbridge6ca40102020-04-08 11:30:40 -0700441 VOLTHA_NS \
442 ADAPTER_NS \
443 INFRA_NS \
444 BBSIM_NS \
David Bainbridge7db44002020-04-09 12:54:29 -0700445 SADIS_BANDWIDTH_PROFILES \
446 SADIS_SUBSCRIBERS \
David Bainbridgeb4bbde12020-06-25 14:46:36 -0700447 PF_ADDRESS \
David K. Bainbridge2aa08da2020-07-31 12:49:45 -0700448 KIND_CFG_FILE \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000449 "
David Bainbridge01294952019-07-30 19:33:45 +0000450
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000451# Iterate over yes/no configuration options and validate
452for VAR in $ALL_YES_NO; do
David Bainbridged18f4942020-04-14 16:46:13 -0700453 eval "$VAR"="$(verify_yes_no "$VAR")"
454 if [ "$(eval echo "\$$VAR")" == "INVALID" ]; then
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000455 exit 1;
456 fi
457done
David Bainbridgeb270c202019-07-26 01:44:42 +0000458
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700459# Iterate over optional yes/no configuration options and
460# normalize values if they are truth values
461for VAR in $OPT_YES_NO; do
462 eval "$VAR"="$(normalize_yes_no "$VAR")"
463done
David Bainbridge15f6f232020-03-30 09:15:43 -0700464
Matteo Scandolo57161902021-05-12 15:26:11 -0700465if [ "$IGNORE_WARNINGS" == "no" ]; then
466 echo -e "${RED}${BOLD}\nAfter the VOLTHA 2.7 release 'kind-voltha' is deprecated and unsupported in favor of helm-charts driven installation.${NORMAL}"
467 echo -e "${RED}${BOLD}To know more about the supported installation procedure please refer to https://github.com/opencord/voltha-helm-charts\n${NORMAL}"
468 while true; do
469 read -r -p "Do you wish to continue at your own risk? (y/n)" yn
470 case $yn in
471 [Yy]* ) break;;
472 [Nn]* ) exit;;
473 * ) echo "Please answer yes or no.";;
474 esac
475 done
476fi
477
Matteo Scandolo657e13c2020-07-28 11:41:42 -0700478# check number (range) of bbsim, max bbsim must not exceed 10 instances!
479# note: instances will be numbered from 0 to 9
480if [ "$1" == "up" ]; then
481 if [ "$NUM_OF_BBSIM" -lt 1 ]; then
482 >&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}"
483 exit 1
484 fi
485 if [ "$NUM_OF_BBSIM" -gt "$MAX_NUM_OF_BBSIM" ]; then
486 >&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}"
487 exit 1
488 fi
489
490 if [ "$NUM_OF_OPENONU" -lt 1 ]; then
491 >&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}"
492 exit 1
493 fi
494 if [ "$NUM_OF_OPENONU" -gt "$MAX_NUM_OF_OPENONU" ]; then
495 >&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}"
496 exit 1
497 fi
498
David K. Bainbridge2aa08da2020-07-31 12:49:45 -0700499 HAVE_CLUSTER="$(kind get clusters 2>/dev/null | grep -c "voltha-$NAME")"
500 if [ "$HAVE_CLUSTER" -eq 0 ]; then
501 # If the user has specified a kind cluster configuration file,
502 # 'KIND_CFG_FILE` then we need to gleem from that file the number
503 # of worker and controller nodes as this overrides any setting of
504 # these values
505 if [ -n "$KIND_CFG_FILE" ]; then
506 NUM_OF_WORKER_NODES="$(sed 's/ //g' "$KIND_CFG_FILE" | grep -c "^-role:worker$")"
507 NUM_OF_CONTROLLER_NODES="$(sed 's/ //g' "$KIND_CFG_FILE" | grep -c "^-role:control-plane$")"
508 fi
Matteo Scandolo657e13c2020-07-28 11:41:42 -0700509
David K. Bainbridge2aa08da2020-07-31 12:49:45 -0700510 # check that NUM_OF_KAFKA, NUM_OF_ONOS, NUM_OF_ATOMIX, NUM_OF_ETCD is:
511 # <= NUM_OF_WORKER_NODES + 1 if SCHEDULE_ON_CONTROL_NODES == y
512 # <= NUM_OF_WORKER_NODES if SCHEDULE_ON_CONTROL_NODES == n
513 SCHEDULABLE_NODES=$NUM_OF_WORKER_NODES
514
515 if [ "$SCHEDULE_ON_CONTROL_NODES" == "yes" ]; then
516 SCHEDULABLE_NODES=$((NUM_OF_CONTROLLER_NODES+NUM_OF_WORKER_NODES))
517 fi
518 else
519 TOTAL_NODES=$(kubectl get --all-namespaces nodes -o name | wc -l)
520 NUM_OF_CONTROLLER_NODES=$(kubectl get --all-namespaces nodes -l node-role.kubernetes.io/master -o name | wc -l)
521 NUM_OF_WORKER_NODES=$((TOTAL_NODES - NUM_OF_CONTROLLER_NODES))
522 # shellcheck disable=SC2016
523 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')
524 rm -f "$TMP_KUBECFG"
Matteo Scandolo657e13c2020-07-28 11:41:42 -0700525 fi
Matteo Scandolo657e13c2020-07-28 11:41:42 -0700526 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"
527
David K. Bainbridge2aa08da2020-07-31 12:49:45 -0700528 if is_in "$WITH_KAFKA" "yes,external" && [ ! "$NUM_OF_KAFKA" -le "$SCHEDULABLE_NODES" ]; then
Matteo Scandolo657e13c2020-07-28 11:41:42 -0700529 >&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}"
530 exit 1
531 fi
532
David K. Bainbridge2aa08da2020-07-31 12:49:45 -0700533 if is_in "$WITH_ETCD" "yes,external" && [ ! "$NUM_OF_ETCD" -le "$SCHEDULABLE_NODES" ]; then
Matteo Scandolo657e13c2020-07-28 11:41:42 -0700534 >&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}"
535 exit 1
536 fi
537
David K. Bainbridge2aa08da2020-07-31 12:49:45 -0700538 if is_in "$WITH_ONOS" "yes,legacy,classic,micro"; then
539 if [ ! "$NUM_OF_ATOMIX" -le "$SCHEDULABLE_NODES" ]; then
540 >&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}"
541 exit 1
542 fi
Matteo Scandolo657e13c2020-07-28 11:41:42 -0700543
David K. Bainbridge2aa08da2020-07-31 12:49:45 -0700544 if [ ! "$NUM_OF_ONOS" -le "$SCHEDULABLE_NODES" ]; then
545 >&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}"
546 exit 1
547 fi
Matteo Scandolo657e13c2020-07-28 11:41:42 -0700548 fi
549fi
550
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700551# normalize non-truth value options
552if is_in "$WITH_KAFKA" "e,external"; then
David Bainbridge76afd812020-04-06 09:53:52 -0700553 WITH_KAFKA="external"
554fi
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700555if is_in "$WITH_ETCD" "e,external"; then
David Bainbridge76afd812020-04-06 09:53:52 -0700556 WITH_ETCD="external"
557fi
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700558if is_in "$WITH_ONOS" "l,legacy"; then
559 WITH_ONOS="legacy"
560elif is_in "$WITH_ONOS" "c,classic"; then
561 WITH_ONOS="classic"
562elif is_in "$WITH_ONOS" "u,m,micro"; then
563 WITH_ONOS="micro"
David Bainbridge29c31cb2020-04-06 09:45:50 -0700564fi
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700565
566if [ "$WITH_ONOS" == "micro" ]; then
567 >&2 echo -e "${YELLOW}${BOLD}${ERROR}WARNING:${NORMAL}${YELLOW} The value specified as WITH_ONOS, '$WITH_ONOS', is not valid.${NORMAL}"
568 exit 1
David Bainbridge29c31cb2020-04-06 09:45:50 -0700569fi
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700570
571if is_in "$WITH_ONOS" "yes,classic"; then
572 # there is an extra utility required if we are using ONOS CLASSIC as
573 # the chart for classic specifies images differently
574 EXTRA_TOOLS+=" yq"
David Bainbridge76afd812020-04-06 09:53:52 -0700575fi
David Bainbridge696bc632020-04-05 21:49:37 -0700576
David Bainbridge22db5dd2020-05-26 12:21:21 -0700577if [ "$LEGACY_BBSIM_INDEX" == "no" ]; then
578 BBSIM_SADIS_SVC="bbsim0"
579else
580 BBSIM_SADIS_SVC="bbsim"
581fi
582
583SADIS_SUBSCRIBERS=${SADIS_SUBSCRIBERS:-http://$BBSIM_SADIS_SVC.$VOLTHA_NS.svc:50074/v2/subscribers/%s}
584SADIS_BANDWIDTH_PROFILES=${SADIS_BANDWIDTH_PROFILES:-http://$BBSIM_SADIS_SVC.$VOLTHA_NS.svc:50074/v2/bandwidthprofiles/%s}
585
David Bainbridged18f4942020-04-14 16:46:13 -0700586if [ "$HELM_USE_UPGRADE" == "yes" ]; then
David Bainbridge7f8bf992020-04-08 21:53:22 -0700587 _HELM_DESC="Upgrade/Install"
588else
589 _HELM_DESC="Install"
590fi
591
David K. Bainbridgeda33d652020-03-06 10:31:23 -0800592# Check for prerequiste tools
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700593TOOLS="curl sed jq $EXTRA_TOOLS"
David Bainbridged18f4942020-04-14 16:46:13 -0700594if [ "$DEPLOY_K8S" == "yes" ]; then
David K. Bainbridgeda33d652020-03-06 10:31:23 -0800595 TOOLS+=" docker"
596fi
597NOT_FOUND=""
598for T in $TOOLS; do
David Bainbridged18f4942020-04-14 16:46:13 -0700599 if [ -z "$(command -v "$T")" ]; then
David K. Bainbridgeda33d652020-03-06 10:31:23 -0800600 NOT_FOUND+=" $T"
601 fi
602done
603
David Bainbridged18f4942020-04-14 16:46:13 -0700604if [ -n "$NOT_FOUND" ]; then
David K. Bainbridgeda33d652020-03-06 10:31:23 -0800605 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} The following required tools where not found, please install them:$NOT_FOUND"
606 exit 1
607fi
608
David Bainbridged18f4942020-04-14 16:46:13 -0700609TIMEOUT_SECONDS="$(parseDuration "$WAIT_TIMEOUT")"
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700610
David Bainbridge0774b232019-08-02 06:37:19 +0000611mkdir -p .voltha
612touch .voltha/ports
David K. Bainbridge00ecd382020-02-28 12:31:58 -0800613
Matteo Scandoloe89384a2020-11-06 08:40:25 -0800614# check if the stack deployed with $NAME already exists
615STACK_EXISTS=false
616if [ "$(grep -c "$NAME" .voltha/ports)" -eq 1 ]; then
617 STACK_EXISTS=true
618fi
619
620if [ "$STACK_EXISTS" == true ]; then
Matteo Scandolo33703282020-12-11 14:27:49 -0800621 echo "stack exists"
Matteo Scandoloe89384a2020-11-06 08:40:25 -0800622 # if the stack was previously deployed reuse the ports
623 HAVE="$(grep "$NAME" .voltha/ports)"
624 VALUES="$(echo "$HAVE" | sed -e 's/\s//g' | cut -d= -f2)"
625 ONOS_API_PORT=$(echo "$VALUES" | cut -d, -f1)
626 ONOS_SSH_PORT=$(echo "$VALUES" | cut -d, -f2)
627 VOLTHA_API_PORT=$(echo "$VALUES" | cut -d, -f3)
628 VOLTHA_SSH_PORT=$(echo "$VALUES" | cut -d, -f4)
629 VOLTHA_ETCD_PORT=$(echo "$VALUES" | cut -d, -f5)
630 VOLTHA_KAFKA_PORT=$(echo "$VALUES" | cut -d, -f6)
631 VOLTHA_PPROF_PORT=$(echo "$VALUES" | cut -d, -f7)
632 OPENOLT_PPROF_PORT=$(echo "$VALUES" | cut -d, -f8)
633 OFAGENT_PPROF_PORT=$(echo "$VALUES" | cut -d, -f9)
634 ELASTICSEARCH_PORT=$(echo "$VALUES" | cut -d, -f10)
635 KIBANA_PORT=$(echo "$VALUES" | cut -d, -f11)
636 TRACING_GUI_PORT=$(echo "$VALUES" | cut -d, -f12)
637
638 # Some ports were added after the .voltha/ports files was created.
639 # Calculate the original DELTA from the VOLTHA_SSH_PORT so that it can
640 # be used to set up newer port-forwards.
641 DELTA="$((VOLTHA_SSH_PORT/100-50))"
642 if [ -z "$VOLTHA_KAFKA_PORT" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -0700643 VOLTHA_KAFKA_PORT=${VOLTHA_KAFKA_PORT:-$((90 + DELTA))92}
David K. Bainbridge00ecd382020-02-28 12:31:58 -0800644 fi
Matteo Scandoloefee0432020-05-05 13:56:20 -0700645
646 if [ -z "$VOLTHA_PPROF_PORT" ]; then
divyadesai59f987a2020-05-27 12:11:33 +0000647 VOLTHA_PPROF_PORT=${VOLTHA_PPROF_PORT:-$((60 + DELTA))60}
Matteo Scandoloefee0432020-05-05 13:56:20 -0700648 fi
649 if [ -z "$OPENOLT_PPROF_PORT" ]; then
divyadesai59f987a2020-05-27 12:11:33 +0000650 OPENOLT_PPROF_PORT=${OPENOLT_PPROF_PORT:-$((60 + DELTA))61}
Matteo Scandoloefee0432020-05-05 13:56:20 -0700651 fi
Matteo Scandolo65c35192020-05-13 10:41:21 -0700652 if [ -z "$OFAGENT_PPROF_PORT" ]; then
divyadesai59f987a2020-05-27 12:11:33 +0000653 OFAGENT_PPROF_PORT=${OFAGENT_PPROF_PORT:-$((60 + DELTA))62}
654 fi
655
656 if [ -z "$ELASTICSEARCH_PORT" ]; then
657 ELASTICSEARCH_PORT=${ELASTICSEARCH_PORT:-$((92 + DELTA))00}
658 fi
divyadesai59f987a2020-05-27 12:11:33 +0000659 if [ -z "$KIBANA_PORT" ]; then
660 KIBANA_PORT=${KIBANA_PORT:-$((56 + DELTA))01}
Matteo Scandolo65c35192020-05-13 10:41:21 -0700661 fi
Girish Kumarcc5f9172020-06-10 13:34:31 +0000662
663 if [ -z "$TRACING_GUI_PORT" ]; then
664 TRACING_GUI_PORT=${TRACING_GUI_PORT:-1$((66 + DELTA))86}
665 fi
Matteo Scandoloe89384a2020-11-06 08:40:25 -0800666else
667 # Find free port prefix
Matteo Scandolo33703282020-12-11 14:27:49 -0800668 START=81
669 while true; do
670 if [ "$(grep -c $START .voltha/ports)" -eq 0 ]; then
671 break
672 fi
673 START="$((START + 1))"
674 done
Matteo Scandoloe89384a2020-11-06 08:40:25 -0800675
Matteo Scandolo33703282020-12-11 14:27:49 -0800676 # create new ports starting from the first available
677 DELTA="$((START - 81))"
678 ONOS_API_PORT=${ONOS_API_PORT:-${START}81}
679 ONOS_SSH_PORT=${ONOS_SSH_PORT:-${START}01}
680 VOLTHA_API_PORT=${VOLTHA_API_PORT:-5$((55 + DELTA))55}
681 VOLTHA_SSH_PORT=${VOLTHA_SSH_PORT:-$((50 + DELTA))22}
682 VOLTHA_ETCD_PORT=${VOLTHA_ETCD_PORT:-$((23 + DELTA))79}
683 VOLTHA_KAFKA_PORT=${VOLTHA_KAFKA_PORT:-$((90 + DELTA))92}
684 VOLTHA_PPROF_PORT=${VOLTHA_PPROF_PORT:-$((60 + DELTA))60}
685 OPENOLT_PPROF_PORT=${OPENOLT_PPROF_PORT:-$((60 + DELTA))61}
686 OFAGENT_PPROF_PORT=${OFAGENT_PPROF_PORT:-$((60 + DELTA))62}
687 ELASTICSEARCH_PORT=${ELASTICSEARCH_PORT:-$((92 + DELTA))00}
688 KIBANA_PORT=${KIBANA_PORT:-$((56 + DELTA))01}
689 TRACING_GUI_PORT=${TRACING_GUI_PORT:-1$((66 + DELTA))86}
Test User01ed0642019-07-03 20:17:06 +0000690fi
691
David Bainbridged18f4942020-04-14 16:46:13 -0700692PORTTMP="$(mktemp -u)"
693grep -v "$NAME" .voltha/ports > "$PORTTMP"
Girish Kumarcc5f9172020-06-10 13:34:31 +0000694echo "$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 -0700695cp "$PORTTMP" .voltha/ports
696rm -f "$PORTTMP"
David Bainbridge0774b232019-08-02 06:37:19 +0000697
David Bainbridge27790d62019-08-13 22:43:19 +0000698export ONOS_API_PORT ONOS_SSH_PORT
David Bainbridge01294952019-07-30 19:33:45 +0000699
Test Userd87942b2019-07-03 07:20:24 +0000700IDX=1
David Bainbridgee87067b2019-08-12 22:00:12 +0000701CLOCK="TIME:"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000702SPIN_PARTS=
703NOT_VERIFIED=
David Bainbridgef858a022019-08-14 21:25:11 +0000704THEX=
705BUILD=
David Bainbridge38dc1e82019-08-12 15:18:45 +0000706VERIFIED=
707HELM=
708OLD_KEY=
709BIRD=
710HIGH_VOLTAGE=
711PLUG=
David Bainbridge38dc1e82019-08-12 15:18:45 +0000712FORWARD=
David Bainbridge38dc1e82019-08-12 15:18:45 +0000713GO=
714DOWNLOAD=
715GEAR=
716NO_ENTRY=
717LOCK=
718
David Bainbridged18f4942020-04-14 16:46:13 -0700719if [ "$FANCY" -eq 1 ]; then
720 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 +0000721 CLOCK="\xe2\x8f\xb1"
David Bainbridgef858a022019-08-14 21:25:11 +0000722 THEX="${RED}${BOLD}\xe2\x9c\x97\x20${NORMAL}"
David Bainbridgef858a022019-08-14 21:25:11 +0000723 BUILD="${YELLOW}${BOLD}\xf0\x9f\x8f\x97${NORMAL}"
724 NOT_VERIFIED="$BUILD"
725 VERIFIED="${GREEN}${BOLD}\xe2\x9c\x93\x20${NORMAL}"
726 HELM="${BLUE}${BOLD}\xE2\x8E\x88${NORMAL}"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000727 OLD_KEY="\xF0\x9F\x97\x9D"
728 BIRD="\xF0\x9F\x90\xA6"
729 HIGH_VOLTAGE="\xE2\x9A\xA1"
730 PLUG="\xF0\x9F\xa7\xa9"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000731 FORWARD="\xE2\x87\xA8"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000732 GO="\xf0\x9f\x9a\x80"
733 DOWNLOAD="\xf0\x9f\x93\xa5"
734 GEAR="\xe2\x9a\x99"
735 NO_ENTRY="\xe2\x9b\x94"
736 LOCK="\xf0\x9f\x94\x92"
737fi
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700738
David Bainbridge712afb82019-08-14 19:55:58 +0000739duration() {
David Bainbridged18f4942020-04-14 16:46:13 -0700740 local h m s t
741 h="$(($1 / 3600))"
742 m="$(($1 % 3600 / 60))"
743 s="$(($1 % 60))"
744 t=""
David Bainbridgee87067b2019-08-12 22:00:12 +0000745
David Bainbridged18f4942020-04-14 16:46:13 -0700746 if [ "$h" -gt 0 ]; then
David Bainbridgee87067b2019-08-12 22:00:12 +0000747 t="$t${h}h"
748 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700749 if [ "$m" -gt 0 ]; then
David Bainbridgee87067b2019-08-12 22:00:12 +0000750 t="$t${m}m"
751 fi
David Bainbridge712afb82019-08-14 19:55:58 +0000752 echo "$t${s}s"
753}
754
755printtime() {
David Bainbridged18f4942020-04-14 16:46:13 -0700756 local INDENT
David Bainbridge712afb82019-08-14 19:55:58 +0000757 if [ "$1" == "-" ]; then
758 INDENT=" "
759 shift
760 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700761 echo -e "$INDENT $CLOCK $(duration "$1")"
David Bainbridgee87067b2019-08-12 22:00:12 +0000762}
763
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700764bspin() {
Test Userd87942b2019-07-03 07:20:24 +0000765 IDX=1
David Bainbridged18f4942020-04-14 16:46:13 -0700766 local INDENT
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700767 if [ "$1" == "-" ]; then
768 INDENT=" "
769 shift
770 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700771 if [ "$FANCY" -eq 0 ]; then
772 LINE="${*//[[:space:]+-]}"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000773 if [ "$LINE X" == " X" ]; then
774 return
775 fi
776 echo -e "$CIVIS$INDENT$*"
777 else
778 echo -en "$CIVIS$INDENT $*"
779 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700780}
781
782sspin() {
David Bainbridged18f4942020-04-14 16:46:13 -0700783 local INDENT
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700784 if [ "$1" == "-" ]; then
785 INDENT=" "
786 shift
787 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700788 if [ "$FANCY" -eq 0 ]; then
789 LINE="${*//[[:space:]+-]}"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000790 if [ "$LINE X" == " X" ]; then
791 return
792 fi
793 echo -e "$INDENT$*"
794 else
David Bainbridged18f4942020-04-14 16:46:13 -0700795 C="$(echo "$SPIN_PARTS" | cut '-d ' -f "$IDX")"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000796 echo -en "\r$INDENT$C $*"
David Bainbridged18f4942020-04-14 16:46:13 -0700797 IDX="$((IDX + 1))"
798 if [ "$IDX" -gt 8 ]; then
David Bainbridge38dc1e82019-08-12 15:18:45 +0000799 IDX=1
800 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700801 fi
802}
803
804espin() {
David Bainbridged18f4942020-04-14 16:46:13 -0700805 local INDENT
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700806 if [ "$1" == "-" ]; then
807 INDENT=" "
808 shift
809 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700810 if [ "$FANCY" -eq 0 ]; then
811 LINE="${*//[[:space:]+-]}"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000812 if [ "$LINE X" == " X" ]; then
813 return
814 fi
815 echo -e "$INDENT$*"
816 else
817 echo -e "\r$INDENT$*$CNORM"
818 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700819}
820
David Bainbridged18f4942020-04-14 16:46:13 -0700821if [ "$1" == "get" ] && [ "$2" == "voltconfig" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000822 echo "$HOME/.volt/config-$NAME"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000823 exit
824fi
825
David Bainbridgee4d11ca2020-05-08 10:21:10 -0700826if [ $# -ne 1 ] || ! is_in "$1" "up,down,dump,clean"; then
David Bainbridgeac7f8072019-08-01 22:15:33 +0000827 >&2 echo "What wouild you like to do today:"
828 >&2 echo " up - bring up voltha"
829 >&2 echo " down - tear down voltha"
Matteo Scandoloe89384a2020-11-06 08:40:25 -0800830 >&2 echo " clean - remove everything that kind-voltha created"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000831 >&2 echo " dump - create a debug dump of running system"
832 exit 1
833fi
834
divyadesai59f987a2020-05-27 12:11:33 +0000835do_curl() {
836 local DATA_ARGS CREDS CMD_ECHO CMD_OUTPUT SC_OUTPUT WAIT_START INDENTA EXTRAA NOW
837 local INDENT=$1
838 local OP=$2
839 local USER=$3
840 local PASS=$4
841 local URL=$5
842 local DATA_TYPE=$6
843 local DATA=$7
844 local MSG=$8
845 local VALID_RESULTS=$9
846 local EXTRA=${10}
847 local ICON=${11}
848
849 # Turn into an array for passing
850 INDENTA=()
851 if [ -n "$INDENT" ]; then
852 INDENTA=("$INDENT")
853 fi
854 IFS=' ' read -r -a EXTRAA <<< "$EXTRA"
David Bainbridge4f1b5562019-08-19 04:46:52 +0000855
David K. Bainbridgeb4b163b2020-02-19 15:55:06 -0800856 # Thanks to the latest version of ONOS using the return code 207 this gets a
857 # whole lot nastier. Can't thank them enough for doing this. So in order to
858 # capture the command and the output in the log file as well as capture the
859 # status code to verify it is 200 and not 207 mutltiple files and a bit of
860 # hackery must be used. Thanks again ONOS.
David Bainbridged18f4942020-04-14 16:46:13 -0700861 CMD_ECHO="$(mktemp -u)"
862 CMD_OUTPUT="$(mktemp -u)"
863 SC_OUTPUT="$(mktemp -u)"
864 WAIT_START="$(date +%s)"
David K. Bainbridgeb4b163b2020-02-19 15:55:06 -0800865
divyadesai59f987a2020-05-27 12:11:33 +0000866 CREDS=()
867 if [ -n "$USER" ]; then
868 CREDS=("--user" "$USER:$PASS")
869 fi
870
871 DATA_ARGS=()
872 if [ -n "$DATA" ]; then
873 if [ "$DATA_TYPE" == "file" ]; then
874 DATA_ARGS=("--data" "@$DATA")
875 elif [ "$DATA_TYPE" == "json" ]; then
876 DATA_ARGS=("--data" "$DATA")
877 fi
878 fi
879
880 bspin "${INDENTA[@]}" "$MSG" "$ICON"
David Bainbridge4f1b5562019-08-19 04:46:52 +0000881 while true; do
David Bainbridged18f4942020-04-14 16:46:13 -0700882 NOW="$(date +%s)"
883 if [ "$((NOW - WAIT_START))" -gt "$TIMEOUT_SECONDS" ]; then
divyadesai59f987a2020-05-27 12:11:33 +0000884 espin "${INDENTA[@]}" "$THEX"
David Bainbridged18f4942020-04-14 16:46:13 -0700885 rm -f "$CMD_ECHO" "$CMD_OUTPUT" "$SC_OUTPUT"
divyadesai59f987a2020-05-27 12:11:33 +0000886 doTimeout "$MSG"
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700887 fi
divyadesai59f987a2020-05-27 12:11:33 +0000888 (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
889 RESULT=$?
David K. Bainbridgeb4b163b2020-02-19 15:55:06 -0800890 # Dump everything to the log
David Bainbridged18f4942020-04-14 16:46:13 -0700891 cat "$CMD_ECHO" >> "$LOG"
892 test -r "$CMD_OUTPUT" && cat "$CMD_OUTPUT" >> "$LOG"
893 SC="$(cat "$SC_OUTPUT")"
894 echo "RESPONSE CODE: $SC" >> "$LOG"
895 echo "ERROR CODE: $RESULT" >> "$LOG"
David K. Bainbridgeb4b163b2020-02-19 15:55:06 -0800896
897 # clean up temp files
David Bainbridged18f4942020-04-14 16:46:13 -0700898 rm -f "$CMD_ECHO" "$CMD_OUTPUT" "$SC_OUTPUT"
divyadesai59f987a2020-05-27 12:11:33 +0000899 if [ "$RESULT" -eq 0 ] && is_in "$SC" "$VALID_RESULTS"; then
David Bainbridge4f1b5562019-08-19 04:46:52 +0000900 break
901 fi
Matteo Scandolo9a77a732020-01-09 14:24:12 -0800902 sleep 1
divyadesai59f987a2020-05-27 12:11:33 +0000903 sspin "${INDENTA[@]}"
David Bainbridge4f1b5562019-08-19 04:46:52 +0000904 done
divyadesai59f987a2020-05-27 12:11:33 +0000905 espin "${INDENTA[@]}" "$VERIFIED"
906}
907
908push_onos_config() {
909 local DATA_TYPE=$1
910 local MSG=$2
911 local RESOURCE=$3
912 local DATA=$4
913
914 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 +0000915}
916
Matteo Scandolo9a77a732020-01-09 14:24:12 -0800917check_onos_app_active() {
David Bainbridged18f4942020-04-14 16:46:13 -0700918 local APP_ID WAIT_START RESULT NOW
919 APP_ID=$1
920 WAIT_START="$(date +%s)"
Matteo Scandolo9a77a732020-01-09 14:24:12 -0800921
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700922 bspin - "Checking that $APP_ID is active $CLOCK"
923 while true; do
David Bainbridged18f4942020-04-14 16:46:13 -0700924 NOW="$(date +%s)"
925 if [ "$((NOW - WAIT_START))" -gt "$TIMEOUT_SECONDS" ]; then
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700926 espin - "$THEX"
927 doTimeout "waiting for ONOS application activation '$APP_ID'"
928 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700929 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 -0700930 break
931 fi
932 sleep 1
933 sspin -
934 done
935 sleep 5 # OSGI components take a little longer that the app to activate
David Bainbridged18f4942020-04-14 16:46:13 -0700936 espin - "$VERIFIED"
Matteo Scandolo9a77a732020-01-09 14:24:12 -0800937}
938
David Bainbridge4f1b5562019-08-19 04:46:52 +0000939override_onos_app() {
David Bainbridged18f4942020-04-14 16:46:13 -0700940 local APP NAME WAIT_START NOW
941 APP=$1
942 NAME="$(basename "$APP" | sed -e 's/^[0-9][0-9]*-//g' -e 's/-.*$//g')"
943 WAIT_START="$(date +%s)"
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700944
David Bainbridge4f1b5562019-08-19 04:46:52 +0000945 while true; do
David Bainbridged18f4942020-04-14 16:46:13 -0700946 NOW="$(date +%s)"
947 if [ "$((NOW - WAIT_START))" -gt "$TIMEOUT_SECONDS" ]; then
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700948 espin - "$THEX"
949 doTimeout "waiting to overwrite ONOS application '$APP'"
950 fi
David Bainbridge4f1b5562019-08-19 04:46:52 +0000951 sspin -
952 # Attempt to delete old version (if it exists)
David Bainbridged18f4942020-04-14 16:46:13 -0700953 (set -x; curl --fail -sSL --user karaf:karaf -X DELETE "http://$_ONOS_API_EP/onos/v1/applications/$NAME" >>"$LOG" 2>&1) >>"$LOG" 2>&1
954 RESULT=$?
David Bainbridge4f1b5562019-08-19 04:46:52 +0000955 sspin -
David Bainbridged18f4942020-04-14 16:46:13 -0700956 if [ $RESULT -ne 0 ]; then
David Bainbridge4f1b5562019-08-19 04:46:52 +0000957 continue
958 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700959 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 +0000960 break
961 fi
962 sleep .2
963 done
964}
965
966activate_onos_app() {
David Bainbridged18f4942020-04-14 16:46:13 -0700967 local MSG APP WAIT_START NOW
968 MSG="$1"
969 APP=$2
970 WAIT_START="$(date +%s)"
David Bainbridge4f1b5562019-08-19 04:46:52 +0000971
972 bspin - "$MSG $GO"
973 while true; do
David Bainbridged18f4942020-04-14 16:46:13 -0700974 NOW="$(date +%s)"
975 if [ "$((NOW - WAIT_START))" -gt "$TIMEOUT_SECONDS" ]; then
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700976 espin - "$THEX"
977 doTimeout "waiting to activate ONOS application '$APP'"
978 fi
David Bainbridge4f1b5562019-08-19 04:46:52 +0000979 sspin -
David Bainbridged18f4942020-04-14 16:46:13 -0700980 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 +0000981 break
982 fi
983 sleep .2
984 done
985 espin - "$VERIFIED"
986}
987
988count_pods() {
David Bainbridged18f4942020-04-14 16:46:13 -0700989 local NAMESPACE STATES LABELS CMD PODS
990 NAMESPACE=$1; shift
David Bainbridge4f1b5562019-08-19 04:46:52 +0000991 if [ "$NAMESPACE" == "all-namespaces" ]; then
992 NAMESPACE="--all-namespaces"
993 else
994 NAMESPACE="-n $NAMESPACE"
995 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700996 STATES=$1; shift
997 LABELS=$1; shift
998 CMD=("kubectl get $NAMESPACE $LABELS pod")
999 PODS=$(${CMD[*]} -o go-template="{{range .items}}{{.metadata.name}}/{{.status.phase}}/_{{range .status.containerStatuses}}{{.ready}}_{{end}} {{end}}")
David Bainbridge4f1b5562019-08-19 04:46:52 +00001000 local COUNT=0
1001 local PATTERNS="$*"
1002 for POD in $PODS; do
David Bainbridged18f4942020-04-14 16:46:13 -07001003 local NAME STATE CONTAINERS TOTAL FOUND
1004 NAME="$(echo "$POD" | cut -d/ -f 1)"
1005 STATE="$(echo "$POD" | cut -d/ -f 2)"
1006 CONTAINERS="$(echo "$POD" | cut -d/ -f 3 | sed -e 's/_/ /g')"
1007 if [ "$STATES" == "*" ] || [ "$(echo "$STATES" | grep -c ":$STATE:")" -ne 0 ]; then
1008 TOTAL="$(echo "$CONTAINERS" | wc -w)"
1009 FOUND="$(echo "$CONTAINERS" | grep -o true | wc -l)"
1010 if [ "$TOTAL" -eq "$FOUND" ]; then
David Bainbridge4f1b5562019-08-19 04:46:52 +00001011 for PATTERN in $PATTERNS; do
David Bainbridged18f4942020-04-14 16:46:13 -07001012 if [[ "$NAME" =~ $PATTERN ]]; then
1013 COUNT="$((COUNT + 1))"
David Bainbridge4f1b5562019-08-19 04:46:52 +00001014 break
1015 fi
1016 done
1017 fi
1018 fi
1019 done
David Bainbridge4f1b5562019-08-19 04:46:52 +00001020 echo $COUNT
1021}
1022
1023wait_for_pods() {
David Bainbridged18f4942020-04-14 16:46:13 -07001024 local INDENT NAMESPACE EXPECT TYPE MESSAGE LABELS PATTERNS STATES HAVE ALL WAIT_START NOW
David Bainbridge4f1b5562019-08-19 04:46:52 +00001025 if [ "$1" == "-" ]; then
1026 INDENT=$1; shift
1027 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001028 NAMESPACE=$1; shift
1029 EXPECT=$1; shift
1030 TYPE=$1; shift
1031 MESSAGE=$1; shift
1032 LABELS=$1; shift
1033 PATTERNS=("$*")
1034 STATES=":Running:"
David Bainbridge99ac7a22019-08-31 02:26:43 +00001035 if [ "$TYPE" == "not" ]; then
1036 STATES="*"
1037 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001038 HAVE="$(count_pods "$NAMESPACE" "$STATES" "$LABELS" "${PATTERNS[@]}")"
1039 ALL=$HAVE
David Bainbridge4f1b5562019-08-19 04:46:52 +00001040 if [ "$TYPE" == "only" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001041 ALL="$(count_pods "all-namespaces" "*" ".*")"
David Bainbridge4f1b5562019-08-19 04:46:52 +00001042 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001043 COUNT="$((300 / 15))"
1044 WAIT_START="$(date +%s)"
1045 bspin "$INDENT" "$MESSAGE"
1046 sspin "$INDENT"
1047 if [ "$HAVE" -ne "$EXPECT" ] || [ "$ALL" -ne "$HAVE" ]; then
1048 while [ "$HAVE" -ne "$EXPECT" ] || [ "$ALL" -ne "$HAVE" ]; do
1049 NOW="$(date +%s)"
1050 if [ "$((NOW - WAIT_START))" -gt "$TIMEOUT_SECONDS" ]; then
1051 espin "$INDENT" "$THEX"
David Bainbridge52e6e9d2020-03-23 13:48:27 -07001052 doTimeout "waiting for PODs to start"
1053 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001054 sspin "$INDENT"
1055 COUNT="$((COUNT - 1))"
1056 if [ "$COUNT" -eq 0 ]; then
1057 HAVE="$(count_pods "$NAMESPACE" "$STATES" "$LABELS" "${PATTERNS[@]}")"
1058 ALL="$HAVE"
David Bainbridge4f1b5562019-08-19 04:46:52 +00001059 if [ "$TYPE" == "only" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001060 ALL="$(count_pods "all-namespaces" "*" ".*")"
David Bainbridge4f1b5562019-08-19 04:46:52 +00001061 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001062 COUNT="$((300 / 15))"
David Bainbridge4f1b5562019-08-19 04:46:52 +00001063 fi
1064 sleep .15
1065 done
1066 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001067 espin "$INDENT" "$VERIFIED"
1068 if [ "$HAVE" -ne "$EXPECT" ]; then
David Bainbridge4f1b5562019-08-19 04:46:52 +00001069 return 1
1070 fi
1071 return 0
1072}
1073
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -08001074port_forward() {
David Bainbridge60ffc0f2020-04-27 22:13:22 -07001075 local NS=$1; shift
1076 local SVC=$1; shift
1077 local PORTS="$*"
Matteo Scandoloe89384a2020-11-06 08:40:25 -08001078 local TAG=$SVC-$NS-$NAME
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -08001079
David Bainbridgeb4bbde12020-06-25 14:46:36 -07001080 (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 -08001081}
1082
1083kill_port_forward() {
Matteo Scandolod9789122020-12-04 15:09:06 -08001084 local TAG P_IDS PARENTS KIDS UNKNOWN PP_ID NS
David Bainbridge1d2c5842020-06-03 15:29:07 -07001085
Matteo Scandolod9789122020-12-04 15:09:06 -08001086 NS=$1; shift
1087 SVC=$1; shift
1088
1089 TAG=
1090 if [ "$SVC" != "__ALL__" ]; then
1091 TAG=$SVC-$NS-$NAME
1092 fi
1093 PARENTS=
1094 KIDS=
1095 UNKNOWN=
1096 # shellcheck disable=SC2009
1097 P_IDS="$(ps e -ww -A | grep "_TAG=$TAG" | grep -v grep | awk '{print $1}')"
1098 if [ -n "$P_IDS" ]; then
1099 for P_ID in $P_IDS; do
1100 PP_ID="$(ps -o ppid "$P_ID" | tail -n +2)"
1101 if [ -n "$PP_ID" ]; then
1102 if [ "$PP_ID" -eq 1 ]; then
1103 PARENTS="$PARENTS $P_ID"
David Bainbridgec6871d22019-11-13 17:10:31 +00001104 else
Matteo Scandolod9789122020-12-04 15:09:06 -08001105 KIDS="$KIDS $P_ID"
David Bainbridgec6871d22019-11-13 17:10:31 +00001106 fi
Matteo Scandolod9789122020-12-04 15:09:06 -08001107 else
1108 UNKNOWN="$UNKNOWN $P_ID"
1109 fi
1110 done
1111 if [ -n "$PARENTS" ]; then
1112 # shellcheck disable=SC2086
1113 while ps -h $PARENTS >/dev/null 2>&1; do
1114 (set -x; eval "kill -9 $PARENTS" >>"$LOG" 2>&1) >>"$LOG" 2>&1
David Bainbridge1d2c5842020-06-03 15:29:07 -07001115 done
David Bainbridge1d2c5842020-06-03 15:29:07 -07001116 fi
Matteo Scandolod9789122020-12-04 15:09:06 -08001117 if [ -n "$KIDS" ]; then
1118 # shellcheck disable=SC2086
1119 while ps -h $KIDS >/dev/null 2>&1; do
1120 (set -x; eval "kill -9 $KIDS" >>"$LOG" 2>&1) >>"$LOG" 2>&1
1121 done
1122 fi
1123 if [ -n "$UNKNOWN" ]; then
1124 # shellcheck disable=SC2086
1125 while ps -h $UNKNOWN >/dev/null 2>&1; do
1126 (set -x; eval "kill -9 $UNKNOWN" >>"$LOG" 2>&1) >>"$LOG" 2>&1
1127 done
1128 fi
1129 fi
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -08001130}
1131
Girish Kumarcc5f9172020-06-10 13:34:31 +00001132resolve_chart_name() {
1133 helm inspect chart "$1" | grep "^name:" | awk '{print $2}'
1134}
1135
David Bainbridgecf546362020-04-21 23:18:50 -07001136resolve_chart_version() {
1137 [ "$2" != "latest" ] && echo "$2" && return
1138 helm inspect chart "$1" | grep "^version:" | awk '{print $2}'
1139}
1140
Jonathan Hart6a91e6c2020-04-16 14:28:33 -07001141# Compares two semver-formatted version strings (e.g. 2.4.3)
1142# Returns 0 if $1 == $2, returns 1 if $1 > $2 and returns 2 if $1 < $2
1143compare_versions() {
1144 [ "$1" == "$2" ] && return 0
Jonathan Hart6a91e6c2020-04-16 14:28:33 -07001145 local lowest
1146 lowest=$(echo -e "$1\n$2" | sort -V | head -1)
1147 [ "$lowest" == "$1" ] && return 2
1148 return 1
1149}
1150
David Bainbridgeac7f8072019-08-01 22:15:33 +00001151if [ "$1" == "down" ]; then
Matteo Scandoloe89384a2020-11-06 08:40:25 -08001152 # NOTE ./voltha down tears down all the stacks, it should only remove components in the specified namespaces
David Bainbridge0774b232019-08-02 06:37:19 +00001153 echo "Tearing down voltha cluster $NAME"
Matteo Scandoloe89384a2020-11-06 08:40:25 -08001154
David Bainbridge0774b232019-08-02 06:37:19 +00001155 LOG="down-$NAME.log"
David Bainbridged18f4942020-04-14 16:46:13 -07001156 date -u +"%Y%m%dT%H%M%SZ" >"$LOG"
David Bainbridgeb4bbde12020-06-25 14:46:36 -07001157 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 -07001158 if is_in "$WITH_ONOS" "yes,legacy,classic"; then
David Bainbridge696bc632020-04-05 21:49:37 -07001159 bspin "Remove port-forwards: onos-ui-$NAME"
Matteo Scandoloe89384a2020-11-06 08:40:25 -08001160 kill_port_forward "$INFRA_NS" onos-ui
David Bainbridge696bc632020-04-05 21:49:37 -07001161 sspin "Remove port-forwards: onos-ssh-$NAME$CEOL"
Matteo Scandoloe89384a2020-11-06 08:40:25 -08001162 kill_port_forward "$INFRA_NS" onos-ssh
David K. Bainbridge2aa08da2020-07-31 12:49:45 -07001163 sspin "Remove port-forwards: onos-onos-classic-hs-$NAME$CEOL"
Matteo Scandoloe89384a2020-11-06 08:40:25 -08001164 kill_port_forward "$INFRA_NS" onos-onos-classic-hs
David Bainbridge696bc632020-04-05 21:49:37 -07001165 fi
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -08001166 sspin "Remove port-forwards: voltha-api-$NAME$CEOL"
Matteo Scandoloe89384a2020-11-06 08:40:25 -08001167 kill_port_forward "$VOLTHA_NS" voltha-api
1168 kill_port_forward "$VOLTHA_NS" voltha-voltha-api
David Bainbridgec7220622020-05-28 12:31:47 -07001169 if is_in "$WITH_ETCD" "yes,external"; then
1170 sspin "Remove port-forwards: etcd-$NAME$CEOL"
Matteo Scandoloe89384a2020-11-06 08:40:25 -08001171 kill_port_forward "$INFRA_NS" "etcd"
David Bainbridge696bc632020-04-05 21:49:37 -07001172 fi
David Bainbridgec7220622020-05-28 12:31:47 -07001173 if is_in "$WITH_KAFKA" "yes,external"; then
1174 sspin "Remove port-forwards: kafka-$NAME$CEOL"
Matteo Scandoloe89384a2020-11-06 08:40:25 -08001175 kill_port_forward "$INFRA_NS" "kafka"
David Bainbridge696bc632020-04-05 21:49:37 -07001176 fi
Matteo Scandoloefee0432020-05-05 13:56:20 -07001177
Andrea Campanellaeacf7f42020-10-15 14:46:33 +02001178 if is_in "$WITH_BBSIM" "yes"; then
1179 sspin "Remove port-forwards: bbsim$CEOL"
Matteo Scandoloe89384a2020-11-06 08:40:25 -08001180 kill_port_forward "$VOLTHA_NS" bbsim
Andrea Campanellaeacf7f42020-10-15 14:46:33 +02001181 fi
1182
Matteo Scandoloefee0432020-05-05 13:56:20 -07001183 if [ "$WITH_PPROF" == "yes" ]; then
David Bainbridgec7220622020-05-28 12:31:47 -07001184 sspin "Remove port-forwards: *-profiler$CEOL"
Matteo Scandoloe89384a2020-11-06 08:40:25 -08001185 kill_port_forward "$VOLTHA_NS" voltha-rw-core-profiler
1186 kill_port_forward "$VOLTHA_NS" voltha-voltha-rw-core-profiler
1187 kill_port_forward "$VOLTHA_NS" voltha-of-agent-profiler
1188 kill_port_forward "$VOLTHA_NS" voltha-voltha-of-agent-profiler
David Bainbridgec7220622020-05-28 12:31:47 -07001189 if [ "$WITH_OPEN_ADAPTERS" == "yes" ]; then
Matteo Scandoloe89384a2020-11-06 08:40:25 -08001190 kill_port_forward "$VOLTHA_NS" adapter-open-olt-profiler
1191 kill_port_forward "$VOLTHA_NS" open-olt-adapter-open-olt-profiler
David Bainbridgec7220622020-05-28 12:31:47 -07001192 fi
Matteo Scandoloefee0432020-05-05 13:56:20 -07001193 fi
1194
Girish Kumarcc5f9172020-06-10 13:34:31 +00001195 if [ "$WITH_TRACING" == "yes" ]; then
1196 sspin "Remove port-forwards: tracing-$NAME$CEOL"
1197 VOLTHA_TRACING_CHART_NAME=$(resolve_chart_name "$VOLTHA_TRACING_CHART")
Matteo Scandoloe89384a2020-11-06 08:40:25 -08001198 kill_port_forward "$INFRA_NS" "tracing-${VOLTHA_TRACING_CHART_NAME}-jaeger-gui"
Girish Kumarcc5f9172020-06-10 13:34:31 +00001199 fi
1200
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -08001201 espin "$VERIFIED Remove port-forwards$CEOL"
David Bainbridged18f4942020-04-14 16:46:13 -07001202 if [ "$DEPLOY_K8S" == "yes" ]; then
David Bainbridgeac7f8072019-08-01 22:15:33 +00001203 if [ -x ./bin/kind ]; then
David Bainbridge0774b232019-08-02 06:37:19 +00001204 bspin "Delete Kubernetes Kind Cluster"
David Bainbridged18f4942020-04-14 16:46:13 -07001205 (set -x; ./bin/kind delete cluster --name "voltha-$NAME" >>"$LOG" 2>&1) >>"$LOG" 2>&1
1206 espin "$VERIFIED"
David Bainbridgeac7f8072019-08-01 22:15:33 +00001207 else
David Bainbridge0774b232019-08-02 06:37:19 +00001208 espin "$NO_ENTRY Delete Kubernetes Kind Cluster: kind command not found"
David Bainbridgeac7f8072019-08-01 22:15:33 +00001209 fi
1210 else
David Bainbridge309099c2020-05-05 08:47:29 -07001211 if [ "$CONFIG_SADIS" == "external" ]; then
1212 bspin "Remove configmap for BBSIM SADIS server"
1213 (set -x; kubectl -n "$BBSIM_NS" delete --ignore-not-found configmap kube-config >>"$LOG" 2>&1) >>"$LOG" 2>&1
1214 espin "$VERIFIED"
1215 fi
David Bainbridgeb4bbde12020-06-25 14:46:36 -07001216
1217 if [ "$HELM_MAJOR" -le 2 ]; then
1218 EXISTS=$(helm list --output json 2>/dev/null | jq -r '.Releases | .[] | .Name + "," + .Namespace')
1219 else
1220 EXISTS=$(helm list --all-namespaces --output json 2>/dev/null | jq -r '.[] | .name + "," + .namespace')
1221 fi
David Bainbridge76afd812020-04-06 09:53:52 -07001222 EXPECT="voltha"
David Bainbridge60ffc0f2020-04-27 22:13:22 -07001223 if is_in "$WITH_ONOS" "yes,legacy,classic"; then
David Bainbridge696bc632020-04-05 21:49:37 -07001224 EXPECT+=" onos"
1225 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001226 if [ "$WITH_RADIUS" == "yes" ]; then
David Bainbridge696bc632020-04-05 21:49:37 -07001227 EXPECT+=" radius"
1228 fi
David Bainbridge309099c2020-05-05 08:47:29 -07001229 if [ "$CONFIG_SADIS" == "external" ]; then
1230 EXPECT+=" bbsim-sadis-server"
1231 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001232 if [ "$WITH_BBSIM" == "yes" ]; then
David Bainbridge696bc632020-04-05 21:49:37 -07001233 EXPECT+=" bbsim"
1234 fi
divyadesai59f987a2020-05-27 12:11:33 +00001235 if [ "$WITH_EFK" == "yes" ]; then
1236 EXPECT+=" elasticsearch kibana fluentd"
1237 fi
Girish Kumarcc5f9172020-06-10 13:34:31 +00001238 if [ "$WITH_TRACING" == "yes" ]; then
1239 EXPECT+=" tracing"
1240 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001241 if [ "$WITH_OPEN_ADAPTERS" == "yes" ]; then
David Bainbridge696bc632020-04-05 21:49:37 -07001242 EXPECT+=" open-olt open-onu"
1243 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001244 if [ "$WITH_SIM_ADAPTERS" == "yes" ]; then
David Bainbridge696bc632020-04-05 21:49:37 -07001245 EXPECT+=" sim"
1246 fi
David Bainbridgec7220622020-05-28 12:31:47 -07001247 if is_in "$WITH_ETCD" "yes,external"; then
1248 EXPECT+=" etcd"
David Bainbridge76afd812020-04-06 09:53:52 -07001249 fi
David Bainbridgec7220622020-05-28 12:31:47 -07001250 if is_in "$WITH_KAFKA" "yes,external"; then
David Bainbridge76afd812020-04-06 09:53:52 -07001251 EXPECT+=" kafka"
1252 fi
David Bainbridge0774b232019-08-02 06:37:19 +00001253 bspin "Remove Helm Deployments"
David Bainbridgeac7f8072019-08-01 22:15:33 +00001254 for i in $EXISTS; do
David K. Bainbridge43422402020-03-06 07:41:22 -08001255 for j in $EXPECT; do
David Bainbridged18f4942020-04-14 16:46:13 -07001256 if [[ "$i" =~ $j ]]; then
David Bainbridgeb4bbde12020-06-25 14:46:36 -07001257 __NAME=$(echo "$i" | cut -d, -f1)
1258 __NS=$(echo "$i" | cut -d, -f2)
1259 sspin "Remove Helm Deployments: $__NS:$__NAME$CEOL"
1260 if [ "$HELM_MAJOR" -le 2 ]; then
1261 (set -x; helm delete --no-hooks --purge "$__NAME" >>"$LOG" 2>&1) >>"$LOG" 2>&1
1262 else
1263 (set -x; helm uninstall --no-hooks --namespace "$__NS" "$__NAME" >>"$LOG" 2>&1) >>"$LOG" 2>&1
1264 fi
David K. Bainbridge43422402020-03-06 07:41:22 -08001265 fi
1266 done
uottrembb16d3982020-02-28 08:34:36 +01001267 done
David Bainbridge0774b232019-08-02 06:37:19 +00001268 espin "$VERIFIED Remove Helm Deployments$CEOL"
David Bainbridge4f1b5562019-08-19 04:46:52 +00001269 if [ "$WAIT_ON_DOWN" == "yes" ]; then
Matteo Scandoloe93c9eb2020-06-03 12:08:51 -07001270 PODS="voltha-ofagent.* voltha-rw-core.*"
David Bainbridge76afd812020-04-06 09:53:52 -07001271 INFRA_PODS=
1272 ADAPT_PODS=
1273 SIM_PODS=
divyadesai59f987a2020-05-27 12:11:33 +00001274 EFK_PODS=
David Bainbridged18f4942020-04-14 16:46:13 -07001275 if [ "$WITH_RADIUS" == "yes" ]; then
David Bainbridge696bc632020-04-05 21:49:37 -07001276 PODS+=" radius.*"
1277 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001278 if [ "$WITH_BBSIM" == "yes" ]; then
David Bainbridge76afd812020-04-06 09:53:52 -07001279 SIM_PODS+=" bbsim.*"
David Bainbridge696bc632020-04-05 21:49:37 -07001280 fi
divyadesai59f987a2020-05-27 12:11:33 +00001281 if [ "$WITH_EFK" == "yes" ]; then
1282 EFK_PODS+=" kibana-* elasticsearch-* fluentd-*"
1283 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001284 if [ "$WITH_OPEN_ADAPTERS" ] || [ "$WITH_SIM_ADAPTERS" ]; then
David Bainbridge76afd812020-04-06 09:53:52 -07001285 ADAPT_PODS+=" adapter-*"
David Bainbridge696bc632020-04-05 21:49:37 -07001286 fi
Girish Kumarcc5f9172020-06-10 13:34:31 +00001287 if [ "$WITH_TRACING" == "yes" ]; then
1288 INFRA_PODS+=" jaeger.*"
1289 fi
David Bainbridge60ffc0f2020-04-27 22:13:22 -07001290 if is_in "$WITH_ONOS" "yes,legacy,classic"; then
David Bainbridge76afd812020-04-06 09:53:52 -07001291 INFRA_PODS+=" onos-.*"
1292 fi
David Bainbridgec7220622020-05-28 12:31:47 -07001293 if is_in "$WITH_ETCD" "yes,external"; then
1294 INFRA_PODS+=" etcd.*"
David Bainbridge76afd812020-04-06 09:53:52 -07001295 fi
David Bainbridgec7220622020-05-28 12:31:47 -07001296 if is_in "$WITH_KAFKA" "yes,external"; then
David Bainbridge76afd812020-04-06 09:53:52 -07001297 INFRA_PODS+=" kafka.*"
1298 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001299 if [ -n "$SIM_PODS" ]; then
1300 wait_for_pods "$BBSIM_NS" 0 "not" "Waiting for BBSIM PODs to terminate" "$BBSIM_LABEL" "$SIM_PODS"
David Bainbridge76afd812020-04-06 09:53:52 -07001301 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001302 if [ -n "$INFRA_PODS" ]; then
1303 wait_for_pods "$INFRA_NS" 0 "not" "Waiting for infrastructure PODs to terminate" "$NO_LABEL" "$INFRA_PODS"
David Bainbridge76afd812020-04-06 09:53:52 -07001304 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001305 if [ -n "$ADAPT_PODS" ]; then
1306 wait_for_pods "$ADAPTER_NS" 0 "not" "Waiting for adapter PODs to terminate" "$NO_LABEL" "$ADAPT_PODS"
David Bainbridge76afd812020-04-06 09:53:52 -07001307 fi
divyadesai59f987a2020-05-27 12:11:33 +00001308 if [ -n "$EFK_PODS" ]; then
1309 wait_for_pods "$INFRA_NS" 0 "not" "Waiting for EFK PODs to terminate" "$NO_LABEL" "$EFK_PODS"
1310 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001311 wait_for_pods "$VOLTHA_NS" 0 "not" "Waiting for VOLTHA PODs to terminate" "$NO_LABEL" "$PODS"
David Bainbridge4f1b5562019-08-19 04:46:52 +00001312 fi
David Bainbridgeac7f8072019-08-01 22:15:33 +00001313 fi
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001314 exit
David Bainbridgeac7f8072019-08-01 22:15:33 +00001315fi
1316
1317if [ "$1" == "dump" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +00001318 LOG="dump-$NAME.log"
David Bainbridged18f4942020-04-14 16:46:13 -07001319 TS="$(date -u +"%Y%m%dT%H%M%SZ")"
1320 if [ -n "$DUMP_FROM" ]; then
1321 TS=${DUMP_FROM//[:-]}
David Bainbridge76514a02019-10-08 01:50:35 +00001322 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001323 WORK="$(mktemp -u -d)"
David Bainbridge0774b232019-08-02 06:37:19 +00001324 DATA=$WORK/voltha-debug-dump-$NAME-$TS
David Bainbridged18f4942020-04-14 16:46:13 -07001325 mkdir -p "$DATA"
1326 echo "$TS" > "$LOG"
David Bainbridge0774b232019-08-02 06:37:19 +00001327 echo -e "Capturing debug dump to voltha-debug-dump-$NAME-$TS.tgz"
David Bainbridgeac7f8072019-08-01 22:15:33 +00001328 bspin - "Copy install log"
David Bainbridged18f4942020-04-14 16:46:13 -07001329 if [ -f "install-$NAME.log" ]; then
1330 (set -x; cp "install-$NAME.log" "$DATA/install-$NAME.log") >>"$LOG" 2>&1
1331 espin - "$VERIFIED"
David Bainbridgeac7f8072019-08-01 22:15:33 +00001332 else
David Bainbridge0774b232019-08-02 06:37:19 +00001333 espin - "$NO_ENTRY Copy install log: install-$NAME.log not found"
David Bainbridgeac7f8072019-08-01 22:15:33 +00001334 fi
1335 bspin - "Dumping Kubernetes PODs"
David Bainbridged18f4942020-04-14 16:46:13 -07001336 (set -x; kubectl get --all-namespaces pods >> "$DATA/all-pods.txt" 2>&1) >>"$LOG" 2>&1
1337 espin - "$VERIFIED"
David Bainbridgeac7f8072019-08-01 22:15:33 +00001338 bspin - "Dumping Kubernetes SERVICEs"
David Bainbridged18f4942020-04-14 16:46:13 -07001339 (set -x; kubectl get --all-namespaces svc >> "$DATA/all-services.txt" 2>&1) >>"$LOG" 2>&1
1340 espin - "$VERIFIED"
David Bainbridgeac7f8072019-08-01 22:15:33 +00001341 bspin - "Dumping Kubernetes EVENTs"
David Bainbridged18f4942020-04-14 16:46:13 -07001342 (set -x; kubectl get --all-namespaces events >> "$DATA/all-events.txt" 2>&1) >>"$LOG" 2>&1
1343 espin - "$VERIFIED"
David Bainbridgeac7f8072019-08-01 22:15:33 +00001344 bspin - "Dumping VOLTHA POD details"
David Bainbridged18f4942020-04-14 16:46:13 -07001345 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 +00001346 SINCE=
David Bainbridged18f4942020-04-14 16:46:13 -07001347 if [ -n "$DUMP_FROM" ]; then
David Bainbridgecfd7ca12019-10-06 03:31:41 +00001348 SINCE="--since-time=$DUMP_FROM"
1349 fi
David Bainbridgeac7f8072019-08-01 22:15:33 +00001350 for POD in $PODS; do
David Bainbridged18f4942020-04-14 16:46:13 -07001351 NS="$(echo "$POD" | cut -d: -f1)"
1352 POD="$(echo "$POD" | cut -d: -f2)"
David Bainbridgeac7f8072019-08-01 22:15:33 +00001353 sspin - "Dumping VOLTHA POD details: $POD$CEOL"
David Bainbridged18f4942020-04-14 16:46:13 -07001354 mkdir -p "$DATA/$POD"
1355 (set -x; kubectl describe -n "$NS" "$POD" >> "$DATA/$POD/describe.txt" 2>&1) >>"$LOG" 2>&1
David Bainbridgeac7f8072019-08-01 22:15:33 +00001356 sspin - "Dumping VOLTHA POD details: $POD"
David Bainbridged18f4942020-04-14 16:46:13 -07001357 (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 +00001358 sspin - "Dumping VOLTHA POD details: $POD"
David Bainbridged18f4942020-04-14 16:46:13 -07001359 (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 +00001360 sspin - "Dumping VOLTHA POD details: $POD"
1361 done
1362 espin - "$VERIFIED Dumping VOLTHA POD details$CEOL"
1363 bspin - "Dumping ETCD"
David Bainbridged18f4942020-04-14 16:46:13 -07001364 if [ -n "$(command -v etcdctl)" ]; then
1365 (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
1366 espin - "$VERIFIED"
David Bainbridgeac7f8072019-08-01 22:15:33 +00001367 else
1368 espin - "$NO_ENTRY Dumping ETCD: etcdctl command not available"
1369 fi
David Bainbridge0774b232019-08-02 06:37:19 +00001370 bspin - "Creating compressed TAR: voltha-debug-dump-$NAME-$TS.tgz"
David Bainbridged18f4942020-04-14 16:46:13 -07001371 (set -x; tar -C "$WORK" -zcf "voltha-debug-dump-$NAME-$TS.tgz" "./voltha-debug-dump-$NAME-$TS") >>"$LOG" 2>&1
1372 espin - "$VERIFIED"
David Bainbridgeac7f8072019-08-01 22:15:33 +00001373 bspin - "Cleanup"
David Bainbridged18f4942020-04-14 16:46:13 -07001374 (set -x; rm -rf "$WORK") >>"$LOG" 2>&1
1375 espin - "$VERIFIED"
1376 bspin - "$(ls -l "voltha-debug-dump-$NAME-$TS.tgz")"
1377 espin - "$VERIFIED"
David Bainbridgeac7f8072019-08-01 22:15:33 +00001378 exit
1379fi
1380
David Bainbridge0774b232019-08-02 06:37:19 +00001381LOG="install-$NAME.log"
David Bainbridge1d2c5842020-06-03 15:29:07 -07001382PFLOG="port-forward-$NAME.log"
David Bainbridged18f4942020-04-14 16:46:13 -07001383date > "$LOG"
Girish Kumarcc5f9172020-06-10 13:34:31 +00001384echo "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 +00001385
1386# Output install options to log
David Bainbridged18f4942020-04-14 16:46:13 -07001387echo "OPTIONS" >> "$LOG"
David Bainbridgeac7f8072019-08-01 22:15:33 +00001388for O in $ALL_OPTIONS; do
David Bainbridged18f4942020-04-14 16:46:13 -07001389 VAL="$(eval echo "\$$O")"
1390 if [ -n "$VAL" ]; then
1391 printf " %-30s = %s\n" "$O" "$VAL" >> "$LOG"
David Bainbridgeac7f8072019-08-01 22:15:33 +00001392 fi
1393done
1394
Matteo Scandoloe89384a2020-11-06 08:40:25 -08001395# Remove everything we created and set
David Bainbridgee4d11ca2020-05-08 10:21:10 -07001396if [ "$1" == "clean" ]; then
Matteo Scandoloe89384a2020-11-06 08:40:25 -08001397 echo "Cleaning up the system"
1398 kill_port_forward all-namespaces __ALL__
David Bainbridgee4d11ca2020-05-08 10:21:10 -07001399 exit
1400fi
1401
David Bainbridgefad50732020-05-01 17:00:12 -07001402helm_values() {
1403 local NAMESPACE=$1; shift
1404 local INAME=$1; shift
1405 local CHART=$1; shift
1406 local CHART_VERSION=$1; shift
1407
1408 if [ "$CHART_VERSION X" != " X" ] && [ "$CHART_VERSION" != "latest" ]; then
1409 CHART_VERSION="--version $CHART_VERSION"
1410 else
1411 CHART_VERSION=
1412 fi
1413
1414 local CHART_ARGS=
1415 if [ -r "${INAME}-values.yaml" ]; then
1416 CHART_ARGS="-f ${INAME}-values.yaml"
1417 fi
1418
1419 if [ "$HELM_USE_UPGRADE" == "yes" ]; then
1420 _HELM_COMMAND="upgrade --install"
1421 _HELM_ARGS="xxxdryrunxxx"
1422 else
1423 _HELM_COMMAND="install"
Matteo Scandolof2d080b2020-07-23 13:59:29 -07001424 if [ "$HELM_MAJOR" -le 2 ]; then
1425 _HELM_NAME_ARG="--name xxxdryrunxxx"
1426 _HELM_ARGS=
1427 else
1428 _HELM_NAME_ARG="xxxdryrunxxx"
1429 _HELM_ARGS="--create-namespace"
1430 fi
David Bainbridgefad50732020-05-01 17:00:12 -07001431 fi
Andrea Campanella8cb166d2021-01-22 11:51:42 +01001432
1433 CMD=("helm $_HELM_COMMAND --debug --dry-run -f values.yaml $CHART_ARGS $INTERNAL_EXTRA_HELM_INSTALL_ARGS $EXTRA_HELM_INSTALL_ARGS --namespace $NAMESPACE $_HELM_ARGS $CHART_VERSION $EXTRA_HELM_FLAGS $_HELM_NAME_ARG $CHART")
David Bainbridgefad50732020-05-01 17:00:12 -07001434 ${CMD[*]} 2>/dev/null | awk 'PRINT==1 {print}; /^USER-SUPPLIED VALUES:/ {PRINT = 1}; /^$/ {PRINT = 0}'
1435}
1436
David Bainbridgeb4bbde12020-06-25 14:46:36 -07001437helm_is_deployed() {
1438 local NAMESPACE=$1; shift
1439 local NAME=$1; shift
1440
1441 if [ "$HELM_MAJOR" -le 2 ]; then
1442 helm list --deployed --short --namespace "$NAMESPACE" "$NAME" 2>/dev/null | wc -l
1443 else
1444 helm list --deployed --short --namespace "$NAMESPACE" --filter "$NAME" 2>/dev/null | wc -l
1445 fi
1446}
1447
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001448helm_install() {
David Bainbridgec7220622020-05-28 12:31:47 -07001449 local INDENT NOW VALUES_FILE PPROF_ARG
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001450 if [ "$1" == "-" ]; then
1451 INDENT=$1; shift
1452 fi
1453 local NAMESPACE=$1; shift
David Bainbridge0774b232019-08-02 06:37:19 +00001454 local INAME=$1; shift
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001455 local CHART=$1; shift
David Bainbridge90fd8e32019-08-21 23:32:47 +00001456 local CHART_VERSION=$1; shift
David Bainbridgec7220622020-05-28 12:31:47 -07001457 local FILTER=$1; shift
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001458 local MESSAGE=$*
1459
David Bainbridged18f4942020-04-14 16:46:13 -07001460 if [ "$CHART_VERSION X" != " X" ] && [ "$CHART_VERSION" != "latest" ]; then
David Bainbridge90fd8e32019-08-21 23:32:47 +00001461 CHART_VERSION="--version $CHART_VERSION"
1462 else
1463 CHART_VERSION=
1464 fi
1465
David Bainbridge99ac7a22019-08-31 02:26:43 +00001466 local CHART_ARGS=
1467 if [ -r "${INAME}-values.yaml" ]; then
1468 CHART_ARGS="-f ${INAME}-values.yaml"
1469 fi
1470
David Bainbridged18f4942020-04-14 16:46:13 -07001471 local WAIT_START CMD
1472 WAIT_START="$(date +%s)"
1473 COUNT="$((300 / 15))"
1474 bspin "$INDENT" "$MESSAGE"
1475 if [ "$HELM_USE_UPGRADE" == "yes" ]; then
David Bainbridge7f8bf992020-04-08 21:53:22 -07001476 _HELM_COMMAND="upgrade --install"
David Bainbridgeb4bbde12020-06-25 14:46:36 -07001477 _HELM_NAME_ARG="$INAME"
David Bainbridge7f8bf992020-04-08 21:53:22 -07001478 else
1479 _HELM_COMMAND="install"
David Bainbridgeb4bbde12020-06-25 14:46:36 -07001480 if [ "$HELM_MAJOR" -le 2 ]; then
1481 _HELM_NAME_ARG="--name $INAME"
1482 _HELM_ARGS=
1483 else
1484 _HELM_NAME_ARG="$INAME"
1485 _HELM_ARGS="--create-namespace"
1486 fi
David Bainbridge7f8bf992020-04-08 21:53:22 -07001487 fi
David Bainbridgec7220622020-05-28 12:31:47 -07001488
1489 VALUES_FILE="$(mktemp)"
1490 if [ "$FILTER" == "-" ]; then
Matteo Scandolo657e13c2020-07-28 11:41:42 -07001491 cp "values.yaml" "$VALUES_FILE"
David Bainbridgea965ca22020-06-09 17:45:04 -07001492 elif [ "${FILTER:0:1}" == "+" ]; then
Matteo Scandolo657e13c2020-07-28 11:41:42 -07001493 cp "values.yaml" "$VALUES_FILE"
1494 yq r - "${FILTER:1}" <"values.yaml" >>"$VALUES_FILE"
David Bainbridge33e56c72020-06-11 11:39:56 -07001495 cat "$VALUES_FILE" >>"$LOG"
David Bainbridgec7220622020-05-28 12:31:47 -07001496 else
Matteo Scandolo657e13c2020-07-28 11:41:42 -07001497 yq r - "$FILTER" <"values.yaml" >"$VALUES_FILE"
David Bainbridgec7220622020-05-28 12:31:47 -07001498 fi
1499 if [ "$WITH_PPROF" == "yes" ]; then
1500 PPROF_ARG="--set profiler.enabled=true"
1501 fi
Andrea Campanella8cb166d2021-01-22 11:51:42 +01001502
1503 # older charts use "defaults", newer charts use "global"
1504 KEY="global"
1505
1506 if [[ $CHART == "onf/voltha" ]] && [[ $(semver_lesser "$CHART_VERSION" "2.8.1") == "true" ]]; then
1507 KEY="defaults"
1508 fi
1509
1510 if [[ $CHART == "onf/voltha-adapter-openolt" ]] && [[ $(semver_lesser "$CHART_VERSION" "2.8.1") == "true" ]]; then
1511 KEY="defaults"
1512 fi
1513
1514 if [[ $CHART == "onf/voltha-adapter-openonu" ]] && [[ $(semver_lesser "$CHART_VERSION" "2.7.2") == "true" ]]; then
1515 KEY="defaults"
1516 fi
1517
1518 CMD=("helm $_HELM_COMMAND -f $VALUES_FILE $_HELM_ARGS $CHART_ARGS $PPROF_ARG $INTERNAL_EXTRA_HELM_INSTALL_ARGS $EXTRA_HELM_INSTALL_ARGS --set $KEY.log_level=$VOLTHA_LOG_LEVEL --namespace $NAMESPACE $CHART_VERSION $EXTRA_HELM_FLAGS $_HELM_NAME_ARG $CHART")
David Bainbridged18f4942020-04-14 16:46:13 -07001519 (set -x; ${CMD[*]} >>"$LOG" 2>&1) >>"$LOG" 2>&1
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001520 SUCCESS=$?
David Bainbridged18f4942020-04-14 16:46:13 -07001521 while [ "$SUCCESS" -ne 0 ]; do
1522 NOW="$(date +%s)"
1523 if [ "$((NOW - WAIT_START))" -gt "$TIMEOUT_SECONDS" ]; then
David Bainbridge52e6e9d2020-03-23 13:48:27 -07001524 espin "$THEX"
David Bainbridgec7220622020-05-28 12:31:47 -07001525 rm -f "$VALUES_FILE"
David Bainbridge52e6e9d2020-03-23 13:48:27 -07001526 doTimeout "waiting for helm install $CHART"
1527 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001528 sspin "$INDENT"
1529 COUNT="$((COUNT - 1))"
1530 if [ "$COUNT" -eq 0 ]; then
1531 if [ "$HELM_USE_UPGRADE" == "no" ]; then
David Bainbridgeb4bbde12020-06-25 14:46:36 -07001532 if [ "$HELM_MAJOR" -le 2 ]; then
1533 (set -x; helm delete --purge "$INAME" >>"$LOG" 2>&1) >>"$LOG" 2>&1
1534 else
1535 (set -x; helm uninstall "$INAME" >>"$LOG" 2>&1) >>"$LOG" 2>&1
1536 fi
David Bainbridge7f8bf992020-04-08 21:53:22 -07001537 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001538 (set -x; ${CMD[*]} >>"$LOG" 2>&1) >>"$LOG" 2>&1
Andy Baviere22ff252019-12-19 11:40:31 -07001539 SUCCESS=$?
David Bainbridged18f4942020-04-14 16:46:13 -07001540 COUNT="$((300 / 15))"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001541 fi
1542 sleep .15
1543 done
David Bainbridgec7220622020-05-28 12:31:47 -07001544 rm -f "$VALUES_FILE"
David Bainbridged18f4942020-04-14 16:46:13 -07001545 espin "$INDENT" "$VERIFIED"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001546}
1547
Matteo Scandoloe89384a2020-11-06 08:40:25 -08001548bspin "Installing VOLTHA: $NAME $GEAR"
1549espin "$VERIFIED"
Matteo Scandolo657e13c2020-07-28 11:41:42 -07001550echo "INSTALL NAME: $NAME" >> "$LOG"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001551
David Bainbridged18f4942020-04-14 16:46:13 -07001552STIME="$(date +%s)"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001553if [ "$INSTALL_KUBECTL" == "no" ]; then
1554 bspin "Skip kubectl install"
1555 espin $NO_ENTRY
Test Userc13bdc92019-07-03 20:57:49 +00001556else
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001557 bspin "Verify kubectl $HELM"
David Bainbridged18f4942020-04-14 16:46:13 -07001558 if [ -x "$GOPATH/bin/kubectl" ]; then
1559 espin "$VERIFIED"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001560 else
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001561 ERR_OUT="$(mktemp)"
David Bainbridged18f4942020-04-14 16:46:13 -07001562 espin "$NOT_VERIFIED"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001563 bspin - "Download and install Kubernetes/kubectl $DOWNLOAD"
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001564 (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
1565 RESULT=$?
1566 if [ "$RESULT" -ne 0 ]; then
1567 espin - "$THEX"
David Bainbridgee3fc0c32020-04-21 15:34:04 -07001568 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR: unable to download kubectl: $(tail "$ERR_OUT")${NORMAL}"
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001569 cat "$ERR_OUT" >> "$LOG"
Zack Williamsded60cb2020-04-13 10:02:20 -07001570 rm -rf "$ERR_OUT" "$GOPATH/bin/kubectl"
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001571 exit 1
1572 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001573 (set -x; chmod 755 "$GOPATH/bin/kubectl" >>"$LOG" 2>&1) >>"$LOG" 2>&1
1574 espin - "$VERIFIED"
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001575 rm -rf "$ERR_OUT"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001576 fi
Test Userc13bdc92019-07-03 20:57:49 +00001577fi
David Bainbridgee87067b2019-08-12 22:00:12 +00001578if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001579 NOW="$(date +%s)"
1580 printtime $((NOW - STIME))
David Bainbridgee87067b2019-08-12 22:00:12 +00001581fi
Test Userc13bdc92019-07-03 20:57:49 +00001582
David Bainbridged18f4942020-04-14 16:46:13 -07001583STIME="$(date +%s)"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001584if [ "$DEPLOY_K8S" == "no" ]; then
1585 bspin "Skip Kubernetes/Kind Deployment"
1586 espin $NO_ENTRY
1587else
Test Userba1e7e72019-07-10 22:27:54 +00001588 bspin "Verify Kubernetes/Kind $HELM"
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -08001589 IS_INSTALLED=0
1590 OP_TYPE="install"
David Bainbridged18f4942020-04-14 16:46:13 -07001591 if [ -x "$GOPATH/bin/kind" ]; then
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -08001592 OP_TYPE="upgrade"
David Bainbridgeb4bbde12020-06-25 14:46:36 -07001593 if [ "$("$GOPATH/bin/kind" version | grep -c "$KIND_VERSION")" -eq 1 ]; then
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -08001594 IS_INSTALLED=1
David Bainbridged18f4942020-04-14 16:46:13 -07001595 espin "$VERIFIED"
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -08001596 fi
1597 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001598 if [ "$IS_INSTALLED" -eq 0 ]; then
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001599 ERR_OUT="$(mktemp)"
David Bainbridged18f4942020-04-14 16:46:13 -07001600 espin "$NOT_VERIFIED"
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -08001601 bspin - "Download and $OP_TYPE Kubernetes/kind $DOWNLOAD"
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001602 (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
1603 RESULT=$?
1604 if [ $RESULT -ne 0 ]; then
1605 espin - "$THEX"
David Bainbridgee3fc0c32020-04-21 15:34:04 -07001606 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR: unable to download kind: $(tail "$ERR_OUT")${NORMAL}"
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001607 cat "$ERR_OUT" >> "$LOG"
Zack Williamsded60cb2020-04-13 10:02:20 -07001608 rm -rf "$ERR_OUT" "$GOPATH/bin/kind"
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001609 exit 1
1610 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001611 (set -x; chmod 755 "$GOPATH/bin/kind" >>"$LOG" 2>&1) >>"$LOG" 2>&1
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001612 rm -rf "$ERR_OUT"
David Bainbridged18f4942020-04-14 16:46:13 -07001613 espin - "$VERIFIED"
Test Userba1e7e72019-07-10 22:27:54 +00001614 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001615fi
1616
David Bainbridgee87067b2019-08-12 22:00:12 +00001617if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001618 NOW="$(date +%s)"
1619 printtime $((NOW - STIME))
David Bainbridgee87067b2019-08-12 22:00:12 +00001620fi
1621
David Bainbridged18f4942020-04-14 16:46:13 -07001622STIME="$(date +%s)"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001623if [ "$INSTALL_HELM" == "no" ]; then
1624 bspin "Skip Helm Install"
1625 espin $NO_ENTRY
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001626else
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001627 bspin "Verify Helm $HELM"
David Bainbridgea34993d2020-04-01 09:15:42 -07001628 HELM_UPGRADE=0
1629 HELM_UPGRADE_DESC="install"
David Bainbridged18f4942020-04-14 16:46:13 -07001630 if [ -x "$GOPATH/bin/helm" ]; then
David Bainbridgeb4bbde12020-06-25 14:46:36 -07001631 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 -07001632 HELM_UP_DOWN="$(echo -e "$HAVE_VER\n$HELM_VERSION" | sort -V | head -1)"
1633 if [ "$HAVE_VER" != "$HELM_VERSION" ]; then
1634 if [ "$HELM_UP_DOWN" == "$HELM_VERSION" ]; then
David Bainbridgea34993d2020-04-01 09:15:42 -07001635 HELM_UPGRADE_DESC="downgrade"
1636 else
1637 HELM_UPGRADE_DESC="upgrade"
1638 fi
1639 HELM_UPGRADE=1
1640 else
David Bainbridged18f4942020-04-14 16:46:13 -07001641 espin "$VERIFIED"
David Bainbridgea34993d2020-04-01 09:15:42 -07001642 fi
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001643 else
David Bainbridgea34993d2020-04-01 09:15:42 -07001644 HELM_UPGRADE=1
1645 fi
1646
David Bainbridged18f4942020-04-14 16:46:13 -07001647 if [ "$HELM_UPGRADE" -ne 0 ]; then
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001648 ERR_OUT="$(mktemp)"
1649 INSTALL_HELM_BIN=$(mktemp)
David Bainbridged18f4942020-04-14 16:46:13 -07001650 espin "$NOT_VERIFIED"
David Bainbridgea34993d2020-04-01 09:15:42 -07001651 bspin - "Download and $HELM_UPGRADE_DESC Helm $DOWNLOAD"
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001652 (set -x; curl -o "$INSTALL_HELM_BIN" --fail -sSL https://git.io/get_helm.sh >>"$LOG" 2>"$ERR_OUT") >>"$LOG" 2>&1
1653 RESULT=$?
1654 if [ $RESULT -ne 0 ]; then
1655 espin - "$THEX"
David Bainbridgee3fc0c32020-04-21 15:34:04 -07001656 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR: unable to download helm installer: $(tail "$ERR_OUT")${NORMAL}"
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001657 cat "$ERR_OUT" >> "$LOG"
1658 rm -rf "$INSTALL_HELM_BIN" "$ERR_OUT" "$GOPATH/bin/helm" "$GOPATH/bin/tiller"
1659 exit 1
1660 fi
1661 rm -rf "$ERR_OUT"
1662 chmod +x "$INSTALL_HELM_BIN"
1663 (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
1664 RESULT=$?
1665 if [ $RESULT -ne 0 ]; then
1666 espin - "$THEX"
1667 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR: unable to install helm, see install log for details${NORMAL}"
1668 rm -rf "$INSTALL_HELM_BIN" "$ERR_OUT" "$GOPATH/bin/helm" "$GOPATH/bin/tiller"
1669 exit 1
1670 fi
1671 rm -rf "$INSTALL_HELM_BIN" "$ERR_OUT"
David Bainbridged18f4942020-04-14 16:46:13 -07001672 espin - "$VERIFIED"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001673 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001674fi
David Bainbridgee87067b2019-08-12 22:00:12 +00001675if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001676 NOW="$(date +%s)"
1677 printtime $((NOW - STIME))
David Bainbridgee87067b2019-08-12 22:00:12 +00001678fi
David Bainbridgeb4bbde12020-06-25 14:46:36 -07001679HELM_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 -07001680
David Bainbridged18f4942020-04-14 16:46:13 -07001681STIME="$(date +%s)"
Test Userb5712372019-07-03 21:52:17 +00001682bspin "Verify voltctl $HIGH_VOLTAGE"
David Bainbridged2811972019-12-14 01:14:09 +00001683VOK=0
1684VMESSAGE="install"
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001685ERR_OUT=$(mktemp)
David K. Bainbridgeebf38d92020-02-10 10:46:31 -08001686export VC_VERSION="$VOLTCTL_VERSION"
1687if [ "$VC_VERSION" == "latest" ]; then
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001688 set -o pipefail # TODO: would be nice to run all in pipefail mode
1689 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')"
1690 RESULT=$?
1691 set +o pipefail
1692 if [ "$RESULT" -ne 0 ]; then
1693 espin - "$THEX"
1694 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR: unable to determine released version of voltctl: $(cat "$ERR_OUT")${NORMAL}"
1695 rm -rf "$ERR_OUT" "$GOPATH/bin/voltctl"
1696 exit 1
1697 fi
1698 export VC_VERSION
David K. Bainbridgeebf38d92020-02-10 10:46:31 -08001699fi
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001700
David Bainbridged18f4942020-04-14 16:46:13 -07001701if [ -x "$GOPATH/bin/voltctl" ]; then
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001702 VHAVE="$("$GOPATH/bin/voltctl" version --clientonly -o json 2>/dev/null | jq -r .version)"
David Bainbridged18f4942020-04-14 16:46:13 -07001703 RESULT=$?
1704 if [ $RESULT -eq 0 ] && [ "$VHAVE" == "$VC_VERSION" ]; then
David Bainbridged2811972019-12-14 01:14:09 +00001705 VOK=1
David Bainbridged18f4942020-04-14 16:46:13 -07001706 espin "$VERIFIED"
David Bainbridge1ba64f12019-12-18 00:40:13 +00001707 else
David Bainbridged18f4942020-04-14 16:46:13 -07001708 VCHECK="$(echo -e "$VHAVE\n$VC_VERSION" | sort -V | head -1)"
David K. Bainbridgeebf38d92020-02-10 10:46:31 -08001709 if [ "$VCHECK" == "$VHAVE" ]; then
1710 VMESSAGE="upgrade"
1711 else
1712 VMESSAGE="downgrade"
1713 fi
David Bainbridged2811972019-12-14 01:14:09 +00001714 fi
1715fi
1716
David Bainbridged18f4942020-04-14 16:46:13 -07001717if [ "$VOK" -eq 0 ]; then
1718 espin "$NOT_VERIFIED"
David Bainbridged2811972019-12-14 01:14:09 +00001719 bspin - "Download and $VMESSAGE voltctl $DOWNLOAD"
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001720 (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
1721 RESULT=$?
1722 if [ $RESULT -ne 0 ]; then
1723 espin - "$THEX"
1724 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR: unable to download voltctl (version $VC_VERSION): $(cat "$ERR_OUT")${NORMAL}"
1725 rm -rf "$ERR_OUT" "$GOPATH/bin/voltctl"
1726 exit 1
1727 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001728 (set -x; chmod 755 "$GOPATH/bin/voltctl" >>"$LOG" 2>&1) >>"$LOG" 2>&1
1729 espin - "$VERIFIED"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001730fi
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001731rm -rf "$ERR_OUT"
David Bainbridgee87067b2019-08-12 22:00:12 +00001732if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001733 NOW="$(date +%s)"
1734 printtime $((NOW - STIME))
David Bainbridgee87067b2019-08-12 22:00:12 +00001735fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001736
1737bspin "Verify command PATH"
David Bainbridged18f4942020-04-14 16:46:13 -07001738espin "$VERIFIED"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001739
David Bainbridged18f4942020-04-14 16:46:13 -07001740STIME="$(date +%s)"
Test Userba1e7e72019-07-10 22:27:54 +00001741if [ "$DEPLOY_K8S" == "yes" ]; then
David Bainbridgeb4bbde12020-06-25 14:46:36 -07001742 HAVE="$(kind get clusters 2>/dev/null | grep -c "voltha-$NAME")"
Test Userba1e7e72019-07-10 22:27:54 +00001743 bspin "Verify Kubernetes/Kind Cluster"
1744 sspin
David Bainbridged18f4942020-04-14 16:46:13 -07001745 if [ "$HAVE" -eq 0 ];