blob: 2a54df54c5073d212f6ac67b3655255173863272 [file] [log] [blame]
Test User01ed0642019-07-03 20:17:06 +00001#!/bin/bash
David K. Bainbridgeb7285432019-07-02 22:05:24 -07002# Copyright 2019 Ciena Corporation
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
David Bainbridged049a612020-03-16 17:22:54 -070015set -f
David Bainbridged18f4942020-04-14 16:46:13 -070016unalias -a
David Bainbridge60ffc0f2020-04-27 22:13:22 -070017shopt -s extglob
David Bainbridged18f4942020-04-14 16:46:13 -070018TOTAL_START_TIME="$(date +%s)"
David Bainbridgeb4bbde12020-06-25 14:46:36 -070019mkdir -p "$(pwd)/bin"
20PATH="$(pwd)/bin:$PATH"; export PATH
21GOPATH="$(pwd)"; export GOPATH
David K. Bainbridgeb7285432019-07-02 22:05:24 -070022
David Bainbridge38dc1e82019-08-12 15:18:45 +000023FANCY=${FANCY:-1}
24if [ "$TERM X" == " X" ]; then
25 FANCY=0
26fi
27
David K. Bainbridgeb7285432019-07-02 22:05:24 -070028# trap ctrl-c and call ctrl_c()
29trap ctrl_c INT
30
31function ctrl_c() {
David Bainbridged18f4942020-04-14 16:46:13 -070032 echo -en "$CNORM"
David K. Bainbridgeb7285432019-07-02 22:05:24 -070033 echo ""
34 echo "ctrl-c trapped"
David Bainbridgec6a6eb62019-10-18 22:50:07 +000035 echo "Thank you for trying 'voltha up'"
David K. Bainbridgeb7285432019-07-02 22:05:24 -070036 exit
37}
38
Andrea Campanella40e48b72020-07-21 20:32:52 +020039HELM_VERSION=${HELM_VERSION:-v3.2.4}
David K. Bainbridgeebf38d92020-02-10 10:46:31 -080040VOLTCTL_VERSION=${VOLTCTL_VERSION:-latest}
David K. Bainbridge88a7a792020-07-27 17:01:14 +000041KIND_VERSION=${KIND_VERSION:-v0.8.1}
David K. Bainbridgeb3a99372020-01-08 14:39:06 -080042VK_RELEASE=${VK_RELEASE:-master}
David Bainbridge60ffc0f2020-04-27 22:13:22 -070043EXTRA_TOOLS=
Test User08ebbd92019-07-03 17:15:39 +000044
David Bainbridge38dc1e82019-08-12 15:18:45 +000045RED=
46GREEN=
47YELLOW=
48BLUE=
David Bainbridge38dc1e82019-08-12 15:18:45 +000049BOLD=
50NORMAL=
51ERROR=
52CEOL=
53CNORM=
54CIVIS=
David Bainbridged18f4942020-04-14 16:46:13 -070055if [ "$FANCY" -eq 1 ]; then
56 RED="$(tput setaf 1)"
57 GREEN="$(tput setaf 2)"
58 YELLOW="$(tput setaf 3)"
59 BLUE="$(tput setaf 4)"
60 BOLD="$(tput bold)"
61 NORMAL="$(tput sgr0)"
David Bainbridge38dc1e82019-08-12 15:18:45 +000062 ERROR="\xe2\x9c\x97\x20"
David Bainbridged18f4942020-04-14 16:46:13 -070063 CEOL="$(tput el)"
64 CNORM="$(tput cnorm)"
65 CIVIS="$(tput civis)"
David Bainbridge38dc1e82019-08-12 15:18:45 +000066fi
Test User7d866122019-07-09 17:52:35 +000067
Matteo Scandolo657e13c2020-07-28 11:41:42 -070068NAME=${NAME:-minimal}
David K. Bainbridge484d80c2020-03-05 21:44:34 -080069
70ENABLE_ONOS_EXTRANEOUS_RULES=${ENABLE_ONOS_EXTRANEOUS_RULES:-no}
David Bainbridge76afd812020-04-06 09:53:52 -070071INFRA_NS=${INFRA_NS:-default}
72VOLTHA_NS=${VOLTHA_NS:-voltha}
73BBSIM_NS=${BBSIM_NS:-voltha}
74ADAPTER_NS=${ADAPTER_NS:-voltha}
David Bainbridgee87067b2019-08-12 22:00:12 +000075WITH_TIMINGS=${WITH_TIMINGS:-no}
Test User7d866122019-07-09 17:52:35 +000076WITH_BBSIM=${WITH_BBSIM:-no}
divyadesai59f987a2020-05-27 12:11:33 +000077WITH_EFK=${WITH_EFK:-no}
Girish Kumarcc5f9172020-06-10 13:34:31 +000078WITH_TRACING=${WITH_TRACING:-no}
David Bainbridge5b7b96b2019-07-25 20:29:13 +000079WITH_RADIUS=${WITH_RADIUS:-no}
Matteo Scandolo78dfee02020-02-13 16:18:03 -080080WITH_EAPOL=${WITH_EAPOL:-yes}
81WITH_DHCP=${WITH_DHCP:-yes}
82WITH_IGMP=${WITH_IGMP:-no}
David Bainbridgeb270c202019-07-26 01:44:42 +000083WITH_ONOS=${WITH_ONOS:-yes}
David Bainbridge60ffc0f2020-04-27 22:13:22 -070084NUM_OF_ONOS=${NUM_OF_ONOS:-1}
85NUM_OF_ATOMIX=${NUM_OF_ATOMIX:-0}
David Bainbridge99ac7a22019-08-31 02:26:43 +000086WITH_CHAOS=${WITH_CHAOS:-no}
David Bainbridge46505fb2019-10-01 21:13:20 +000087WITH_ADAPTERS=${WITH_ADAPTERS:-yes}
David K. Bainbridgeda33d652020-03-06 10:31:23 -080088WITH_SIM_ADAPTERS=${WITH_SIM_ADAPTERS:-no}
David Bainbridge46505fb2019-10-01 21:13:20 +000089WITH_OPEN_ADAPTERS=${WITH_OPEN_ADAPTERS:-yes}
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -080090WITH_PORT_FORWARDS=${WITH_PORT_FORWARDS:-yes}
David Bainbridge696bc632020-04-05 21:49:37 -070091WITH_KAFKA=${WITH_KAFKA:-yes}
92WITH_ETCD=${WITH_ETCD:-yes}
Matteo Scandoloefee0432020-05-05 13:56:20 -070093WITH_PPROF=${WITH_PPROF:-no}
Girish Gowdra4cc5d8b2020-06-11 17:12:00 -070094WITH_INCREMENTAL_EVTO_UPDATE=${WITH_INCREMENTAL_EVTO_UPDATE:-no}
David Bainbridgee4d11ca2020-05-08 10:21:10 -070095SCHEDULE_ON_CONTROL_NODES=${SCHEDULE_ON_CONTROL_NODES:-no}
David Bainbridge309099c2020-05-05 08:47:29 -070096CONFIG_SADIS=${CONFIG_SADIS:-no} # yes | no | file | bbsim | external | URL
Hardik Windlassb3147602020-03-09 16:59:15 +053097SADIS_CFG=${SADIS_CFG:-onos-files/onos-sadis-sample.json}
Matteo Scandolo6402d362020-08-24 12:31:06 -070098BBSIM_CFG=${BBSIM_CFG:-configs/bbsim-sadis-att.yaml}
David Bainbridge27790d62019-08-13 22:43:19 +000099INSTALL_ONOS_APPS=${INSTALL_ONOS_APPS:-no}
Test Userba1e7e72019-07-10 22:27:54 +0000100JUST_K8S=${JUST_K8S:-no}
Matteo Scandoloe89384a2020-11-06 08:40:25 -0800101JUST_INFRA=${JUST_INFRA:-no}
Test Userba1e7e72019-07-10 22:27:54 +0000102DEPLOY_K8S=${DEPLOY_K8S:-yes}
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700103INSTALL_KUBECTL=${INSTALL_KUBECTL:-yes}
104INSTALL_HELM=${INSTALL_HELM:-yes}
David Bainbridge7f8bf992020-04-08 21:53:22 -0700105HELM_USE_UPGRADE=${HELM_USE_UPGRADE:-no}
David Bainbridge46505fb2019-10-01 21:13:20 +0000106UPDATE_HELM_REPOS=${UPDATE_HELM_REPOS:-yes}
Matteo Scandolofab98622020-01-28 15:17:20 -0800107WAIT_ON_DOWN=${WAIT_ON_DOWN:-yes}
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700108WAIT_TIMEOUT=${WAIT_TIMEOUT:-30m}
109VOLTHA_DOWN_ON_TIMEOUT=${VOLTHA_DOWN_ON_TIMEOUT:-no}
David Bainbridge5b7b96b2019-07-25 20:29:13 +0000110VOLTHA_LOG_LEVEL=${VOLTHA_LOG_LEVEL:-WARN}
David Bainbridge90fd8e32019-08-21 23:32:47 +0000111VOLTHA_CHART=${VOLTHA_CHART:-onf/voltha}
112VOLTHA_CHART_VERSION=${VOLTHA_CHART_VERSION:-latest}
113VOLTHA_BBSIM_CHART=${VOLTHA_BBSIM_CHART:-onf/bbsim}
Matteo Scandolocdfb4e22020-09-11 19:46:59 -0700114VOLTHA_BBSIM_CHART_VERSION=${VOLTHA_BBSIM_CHART_VERSION:-latest}
divyadesai59f987a2020-05-27 12:11:33 +0000115ELASTICSEARCH_CHART=${ELASTICSEARCH_CHART:-elastic/elasticsearch}
116ELASTICSEARCH_CHART_VERSION=${ELASTICSEARCH_CHART_VERSION:-latest}
117KIBANA_CHART=${KIBANA_CHART:-elastic/kibana}
118KIBANA_CHART_VERSION=${KIBANA_CHART_VERSION:-latest}
119FLUENTD_ELASTICSEARCH_CHART=${FLUENTD_ELASTICSEARCH_CHART:-kiwigrid/fluentd-elasticsearch}
120FLUENTD_ELASTICSEARCH_CHART_VERSION=${FLUENTD_ELASTICSEARCH_CHART_VERSION:-latest}
Girish Kumarcc5f9172020-06-10 13:34:31 +0000121VOLTHA_TRACING_CHART=${VOLTHA_TRACING_CHART:-onf/voltha-tracing}
122VOLTHA_TRACING_CHART_VERSION=${VOLTHA_TRACING_CHART_VERSION:-latest}
David Bainbridgee10f6d52019-07-25 00:28:13 +0000123VOLTHA_ADAPTER_SIM_CHART=${VOLTHA_ADAPTER_SIM_CHART:-onf/voltha-adapter-simulated}
David Bainbridge90fd8e32019-08-21 23:32:47 +0000124VOLTHA_ADAPTER_SIM_CHART_VERSION=${VOLTHA_ADAPTER_SIM_CHART_VERSION:-latest}
David Bainbridgee10f6d52019-07-25 00:28:13 +0000125VOLTHA_ADAPTER_OPEN_OLT_CHART=${VOLTHA_ADAPTER_OPEN_OLT_CHART:-onf/voltha-adapter-openolt}
David Bainbridge90fd8e32019-08-21 23:32:47 +0000126VOLTHA_ADAPTER_OPEN_OLT_CHART_VERSION=${VOLTHA_ADAPTER_OPEN_OLT_CHART_VERSION:-latest}
David Bainbridgee10f6d52019-07-25 00:28:13 +0000127VOLTHA_ADAPTER_OPEN_ONU_CHART=${VOLTHA_ADAPTER_OPEN_ONU_CHART:-onf/voltha-adapter-openonu}
David Bainbridge90fd8e32019-08-21 23:32:47 +0000128VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION=${VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION:-latest}
David K. Bainbridgeda33d652020-03-06 10:31:23 -0800129ONOS_CHART=${ONOS_CHART:-onf/onos}
Andrea Campanella21323292019-12-18 11:44:19 -0800130ONOS_CHART_VERSION=${ONOS_CHART_VERSION:-latest}
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700131ONOS_CLASSIC_CHART=${ONOS_CLASSIC_CHART:-onos/onos-classic}
Andrea Campanella26c8c992020-08-24 15:43:26 +0000132ONOS_CLASSIC_CHART_VERSION=${ONOS_CLASSIC_CHART_VERSION:-latest}
Matteo Scandolo8f8609a2020-11-13 10:20:44 -0800133KAFKA_CHART=${KAFKA_CHART:-bitnami/kafka}
David Bainbridgeb4bbde12020-06-25 14:46:36 -0700134KAFKA_CHART_VERSION=${KAFKA_CHART_VERSION:=latest}
Matteo Scandoloe89384a2020-11-06 08:40:25 -0800135BBSIM_SADIS_SERVER_CHART=${BBSIM_SADIS_SERVER_CHART:-onf/bbsim-sadis-server}
David Bainbridge309099c2020-05-05 08:47:29 -0700136BBSIM_SADIS_SERVER_CHART_VERSION=${BBSIM_SADIS_SERVER_CHART_VERSION:-latest}
Matteo Scandolo8f8609a2020-11-13 10:20:44 -0800137ETCD_CHART=${ETCD_CHART:-bitnami/etcd}
David Bainbridgec7220622020-05-28 12:31:47 -0700138ETCD_CHART_VERSION=${ETCD_CHART_VERSION:-latest}
David Bainbridge879439b2020-06-12 15:59:35 -0700139RADIUS_CHART=${RADIUS_CHART:-onf/freeradius}
140RADIUS_CHART_VERSION=${RADIUS_CHART_VERSION:-latest}
David Bainbridge2eaf2cf2020-03-18 12:54:08 -0700141EXTRA_HELM_INSTALL_ARGS=${EXTRA_HELM_INSTALL_ARGS:-}
142INTERNAL_EXTRA_HELM_INSTALL_ARGS=
uottrembb16d3982020-02-28 08:34:36 +0100143NUM_OF_BBSIM=${NUM_OF_BBSIM:-1}
Matteo Scandoloe89384a2020-11-06 08:40:25 -0800144BBSIM_BASE_INDEX=${BBSIM_BASE_INDEX:-1}
Matteo Scandolo657e13c2020-07-28 11:41:42 -0700145NUM_OF_WORKER_NODES=${NUM_OF_WORKER_NODES:-2}
146NUM_OF_CONTROLLER_NODES=${NUM_OF_CONTROLLER_NODES:-1}
Matteo Scandolo67335f02020-04-09 11:19:53 -0700147NUM_OF_OPENONU=${NUM_OF_OPENONU:-1}
Matteo Scandolo657e13c2020-07-28 11:41:42 -0700148NUM_OF_KAFKA=${NUM_OF_KAFKA:-1}
149NUM_OF_ETCD=${NUM_OF_ETCD:-1}
uottrembb16d3982020-02-28 08:34:36 +0100150MAX_NUM_OF_BBSIM=10
Matteo Scandolo67335f02020-04-09 11:19:53 -0700151MAX_NUM_OF_OPENONU=10
Matteo Scandoloc2eb0672020-05-01 14:43:15 -0700152LEGACY_BBSIM_INDEX=${LEGACY_BBSIM_INDEX:-no}
David Bainbridgeb4bbde12020-06-25 14:46:36 -0700153PF_ADDRESS=${PF_ADDRESS:-0.0.0.0}
David K. Bainbridge2aa08da2020-07-31 12:49:45 -0700154KIND_CFG_FILE=${KIND_CFG_FILE:-}
Test Userba1e7e72019-07-10 22:27:54 +0000155
David Bainbridged18f4942020-04-14 16:46:13 -0700156HOSTOS="$(uname -s | tr "[:upper:]" "[:lower:"])"
157HOSTARCH="$(uname -m | tr "[:upper:]" "[:lower:"])"
158if [ "$HOSTARCH" == "x86_64" ]; then
Test Userba1e7e72019-07-10 22:27:54 +0000159 HOSTARCH="amd64"
160fi
David Bainbridge7db44002020-04-09 12:54:29 -0700161BBSIM_LABEL="-l app=bbsim"
David Bainbridged18f4942020-04-14 16:46:13 -0700162NO_LABEL=
Test User7d866122019-07-09 17:52:35 +0000163
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700164# checks to see if a given WORD is in the given LIST of words
165function is_in() {
166 local WORD LIST
167 WORD="$1"; shift
168 LIST="$*"
169 LIST=${LIST//+([[:space:],|])/:}
170
171 [ "$(echo ":$LIST:" | grep -ic ":$WORD:")" -ne 0 ]
172}
173
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700174function parseDuration() {
David Bainbridged18f4942020-04-14 16:46:13 -0700175 local DUR RESULT TERM TERMS VALUE UNIT
176 DUR=$1
177 RESULT=0
178 TERMS="$(echo "$DUR" | sed -Ee 's/([sSmMhHdD])/\1 /g' -e 's/,$//g')"
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700179 for TERM in $TERMS; do
David Bainbridged18f4942020-04-14 16:46:13 -0700180 VALUE="$(echo "$TERM" | sed -Ee 's/([0-9]+)[sSmMhHdD]/\1/')"
181 UNIT="$(echo "$TERM" | sed -Ee 's/[0-9]+([sSmMhHdD])/\1/')"
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700182 case $UNIT in
183 s|S)
David Bainbridged18f4942020-04-14 16:46:13 -0700184 RESULT=$((RESULT + VALUE)) ;;
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700185 m|M)
David Bainbridged18f4942020-04-14 16:46:13 -0700186 RESULT=$((RESULT + (VALUE * 60))) ;;
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700187 h|H)
David Bainbridged18f4942020-04-14 16:46:13 -0700188 RESULT=$((RESULT + (VALUE * 3600))) ;;
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700189 d|D)
David Bainbridged18f4942020-04-14 16:46:13 -0700190 RESULT=$((RESULT + (VALUE * 86400))) ;;
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700191 *) ;;
192 esac
193 done
194 echo $RESULT
195}
196
197function doTimeout() {
198 local MSG=$1
199 2>&1 echo -e "\n${RED}${BOLD}${ERROR}TIMEOUT:${NORMAL}${RED} Operation timed out after '$WAIT_TIMEOUT': $MSG"
200 exit 125
201}
202
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -0800203function get_service_ep() {
204 local NS=$1
205 local NAME=$2
David Bainbridged18f4942020-04-14 16:46:13 -0700206 kubectl -n "$NS" get service "$NAME" -o json | jq -r '.spec.clusterIP + ":" + (.spec.ports[0].port|tostring)'
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -0800207}
208
Matteo Scandolo6402d362020-08-24 12:31:06 -0700209# returns the greater version (0 if equal)
Matteo Scandolo734fe962020-09-02 17:47:16 -0700210# inspired by https://stackoverflow.com/questions/4023830/how-to-compare-two-strings-in-dot-separated-version-format-in-bash
Matteo Scandolo6402d362020-08-24 12:31:06 -0700211function semvercompare() {
212 if [[ "$1" == "$2" ]]
213 then
214 echo 0
215 return
216 fi
217
218 local tmp1 tmp2
219 tmp1=$(echo "${1//v/}" | awk -F'-' '{print $1}')
220 tmp2=$(echo "${2//v/}" | awk -F'-' '{print $1}')
221
222 local IFS=.
223 # shellcheck disable=SC2206
224 local i ver1=($tmp1) ver2=($tmp2)
225
226 # fill empty fields in ver1 with zeros
227 for ((i=${#ver1[@]}; i<${#ver2[@]}; i++))
228 do
229 ver1[i]=0
230 done
231 for ((i=0; i<${#ver1[@]}; i++))
232 do
233 if [[ -z ${ver2[i]} ]]
234 then
235 # fill empty fields in ver2 with zeros
236 ver2[i]=0
237 fi
238 if ((10#${ver1[i]} > 10#${ver2[i]}))
239 then
240 echo 1
241 return
242 fi
243 if ((10#${ver1[i]} < 10#${ver2[i]}))
244 then
245 echo 2
246 return
247 fi
248 done
249 echo 0
250 return
251}
252
Matteo Scandolo99dbed32020-09-03 14:11:27 -0700253# returns true if v1 is greater than v2 (false if they are the same)
Matteo Scandolo6402d362020-08-24 12:31:06 -0700254function semver_greater() {
255 local v1
256 local v2
Matteo Scandolo99dbed32020-09-03 14:11:27 -0700257 v1="$1" v2="$2"
Matteo Scandolo6402d362020-08-24 12:31:06 -0700258
259 # shellcheck disable=SC2128
Matteo Scandolo48890712020-09-11 15:48:24 -0700260 if [[ ! "$v1" =~ ^([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then
261 # if the version is custom, we assume it's newer than master
Matteo Scandolo6402d362020-08-24 12:31:06 -0700262 echo "true"
263 return
264 fi
265
266 # shellcheck disable=SC2128
267 res=$(semvercompare "$v1" "$v2")
268 if [[ $res == 1 ]]; then
269 echo "true"
270 else
271 echo "false"
272 fi
273}
274
Matteo Scandolo99dbed32020-09-03 14:11:27 -0700275# returns true if v1 is lesser than v2 (false if they are the same)
Matteo Scandolo6402d362020-08-24 12:31:06 -0700276function semver_lesser() {
277 local v1
278 local v2
Matteo Scandolo99dbed32020-09-03 14:11:27 -0700279 v1="$1" v2="$2"
Matteo Scandolo6402d362020-08-24 12:31:06 -0700280
281 # shellcheck disable=SC2128
Matteo Scandolo48890712020-09-11 15:48:24 -0700282 if [[ ! "$v1" =~ ^([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then
283 # if the version is custom, we assume it's newer than master
Matteo Scandolo6402d362020-08-24 12:31:06 -0700284 echo "false"
285 return
286 fi
287
288 # shellcheck disable=SC2128
289 res=$(semvercompare "$v1" "$v2")
290 if [[ $res == 2 ]]; then
291 echo "true"
292 else
293 echo "false"
294 fi
295}
296
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000297# Used to verify configuration values are set to "yes" or "no" value or convert
298# equivalents to "yes" or "no"
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700299YES="y,yes,t,true,1"
300NO="n,no,f,false,0"
301YES_OR_NO="$YES,$NO"
302
303# If the given VAR matches a truth value then normalize that
304# value, else return original value
305function normalize_yes_no() {
306 local VAR VAL
307 VAR=$1
308 VAL="$(eval echo "\$$VAR")"
309 if ! is_in "$VAL" "$YES_OR_NO"; then
310 echo "$VAL"
311 return 1
312 fi
313 if is_in "$VAL" "$YES"; then
314 echo "yes"
315 else
316 echo "no"
317 fi
318 return 0
319}
320
321# If the given VAR matches a truth value then normalize that
322# value, else display an error
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000323function verify_yes_no() {
David Bainbridged18f4942020-04-14 16:46:13 -0700324 local VAR VAL
325 VAR=$1
326 VAL="$(eval echo "\$$VAR")"
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700327 if ! is_in "$VAL" "$YES_OR_NO"; then
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000328 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} Invalid '$VAR' value of '$VAL'. Should be 'yes' or 'no'${NORMAL}"
329 echo "INVALID"
330 return 1
331 fi
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700332 if is_in "$VAL" "$YES"; then
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000333 echo "yes"
334 else
335 echo "no"
336 fi
337 return 0
338}
Test User7d866122019-07-09 17:52:35 +0000339
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000340ALL_YES_NO="\
David K. Bainbridge484d80c2020-03-05 21:44:34 -0800341 ENABLE_ONOS_EXTRANEOUS_RULES \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000342 WITH_TIMINGS \
343 WITH_BBSIM \
divyadesai59f987a2020-05-27 12:11:33 +0000344 WITH_EFK \
Girish Kumarcc5f9172020-06-10 13:34:31 +0000345 WITH_TRACING \
Matteo Scandolo78dfee02020-02-13 16:18:03 -0800346 WITH_EAPOL \
347 WITH_DHCP \
348 WITH_IGMP \
David Bainbridge99ac7a22019-08-31 02:26:43 +0000349 WITH_CHAOS \
David Bainbridge46505fb2019-10-01 21:13:20 +0000350 WITH_ADAPTERS \
351 WITH_SIM_ADAPTERS \
352 WITH_OPEN_ADAPTERS \
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -0800353 WITH_PORT_FORWARDS \
Matteo Scandoloefee0432020-05-05 13:56:20 -0700354 WITH_PPROF \
Girish Gowdra4cc5d8b2020-06-11 17:12:00 -0700355 WITH_INCREMENTAL_EVTO_UPDATE \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000356 JUST_K8S \
Matteo Scandoloe89384a2020-11-06 08:40:25 -0800357 JUST_INFRA \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000358 DEPLOY_K8S \
359 INSTALL_ONOS_APPS \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000360 INSTALL_KUBECTL \
361 INSTALL_HELM \
David Bainbridge7f8bf992020-04-08 21:53:22 -0700362 HELM_USE_UPGRADE \
David Bainbridge46505fb2019-10-01 21:13:20 +0000363 UPDATE_HELM_REPOS \
David Bainbridge4f1b5562019-08-19 04:46:52 +0000364 WAIT_ON_DOWN \
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700365 VOLTHA_DOWN_ON_TIMEOUT \
Matteo Scandoloc2eb0672020-05-01 14:43:15 -0700366 LEGACY_BBSIM_INDEX \
David Bainbridgee4d11ca2020-05-08 10:21:10 -0700367 SCHEDULE_ON_CONTROL_NODES \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000368 "
David Bainbridge5b7b96b2019-07-25 20:29:13 +0000369
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700370OPT_YES_NO="\
371 CONFIG_SADIS \
372 WITH_KAFKA \
373 WITH_RADIUS \
374 WITH_ETCD \
375 WITH_ONOS \
376 "
377
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000378ALL_OPTIONS="\
379 NAME \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000380 $ALL_YES_NO \
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700381 $OPT_YES_NO \
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700382 WAIT_TIMEOUT \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000383 VOLTHA_LOG_LEVEL \
384 VOLTHA_CHART \
David Bainbridge90fd8e32019-08-21 23:32:47 +0000385 VOLTHA_CHART_VERSION \
386 VOLTHA_BBSIM_CHART \
387 VOLTHA_BBSIM_CHART_VERSION \
David Bainbridge879439b2020-06-12 15:59:35 -0700388 BBSIM_SADIS_SERVER_CHART \
389 BBSIM_SADIS_SERVER_CHART_VERSION \
Girish Kumarcc5f9172020-06-10 13:34:31 +0000390 VOLTHA_TRACING_CHART \
391 VOLTHA_TRACING_CHART_VERSION \
uottrembd5a20572020-03-06 09:15:01 +0100392 NUM_OF_BBSIM \
Matteo Scandolo657e13c2020-07-28 11:41:42 -0700393 NUM_OF_WORKER_NODES \
394 NUM_OF_CONTROLLER_NODES \
395 NUM_OF_KAFKA \
396 NUM_OF_ETCD \
divyadesai59f987a2020-05-27 12:11:33 +0000397 ELASTICSEARCH_CHART \
398 ELASTICSEARCH_CHART_VERSION \
399 KIBANA_CHART \
400 KIBANA_CHART_VERSION \
401 FLUENTD_ELASTICSEARCH_CHART \
402 FLUENTD_ELASTICSEARCH_CHART_VERSION \
Matteo Scandolo67335f02020-04-09 11:19:53 -0700403 NUM_OF_OPENONU \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000404 VOLTHA_ADAPTER_SIM_CHART \
David Bainbridge90fd8e32019-08-21 23:32:47 +0000405 VOLTHA_ADAPTER_SIM_CHART_VERSION \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000406 VOLTHA_ADAPTER_OPEN_OLT_CHART \
David Bainbridge90fd8e32019-08-21 23:32:47 +0000407 VOLTHA_ADAPTER_OPEN_OLT_CHART_VERSION \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000408 VOLTHA_ADAPTER_OPEN_ONU_CHART \
David Bainbridge90fd8e32019-08-21 23:32:47 +0000409 VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION \
David K. Bainbridgeda33d652020-03-06 10:31:23 -0800410 ONOS_CHART \
Andrea Campanella21323292019-12-18 11:44:19 -0800411 ONOS_CHART_VERSION \
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700412 ONOS_CLASSIC_CHART \
413 ONOS_CLASSIC_CHART_VERSION \
David Bainbridgecf546362020-04-21 23:18:50 -0700414 KAFKA_CHART \
David Bainbridgeb9093522020-04-15 14:32:44 -0700415 KAFKA_CHART_VERSION \
David Bainbridge879439b2020-06-12 15:59:35 -0700416 ETCD_CHART \
417 ETCD_CHART_VERSION \
418 RADIUS_CHART \
419 RADIUS_CHART_VERSION \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000420 ONOS_API_PORT \
421 ONOS_SSH_PORT \
Hardik Windlassb3147602020-03-09 16:59:15 +0530422 SADIS_CFG \
Matteo Scandolo6402d362020-08-24 12:31:06 -0700423 BBSIM_CFG \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000424 VOLTHA_API_PORT \
425 VOLTHA_SSH_PORT \
426 VOLTHA_ETCD_PORT \
divyadesai59f987a2020-05-27 12:11:33 +0000427 ELASTICSEARCH_PORT \
428 KIBANA_PORT \
David K. Bainbridge00ecd382020-02-28 12:31:58 -0800429 VOLTHA_KAFKA_PORT \
Matteo Scandoloefee0432020-05-05 13:56:20 -0700430 VOLTHA_PPROF_PORT \
431 OPENOLT_PPROF_PORT \
Matteo Scandolo65c35192020-05-13 10:41:21 -0700432 OFAGENT_PPROF_PORT \
Girish Kumarcc5f9172020-06-10 13:34:31 +0000433 TRACING_GUI_PORT \
David K. Bainbridge8f7f30b2020-01-08 13:06:16 -0800434 VK_RELEASE \
435 KIND_VERSION \
436 VOLTCTL_VERSION \
David Bainbridgea34993d2020-04-01 09:15:42 -0700437 HELM_VERSION \
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700438 NUM_OF_ONOS \
439 NUM_OF_ATOMIX \
David Bainbridge6ca40102020-04-08 11:30:40 -0700440 VOLTHA_NS \
441 ADAPTER_NS \
442 INFRA_NS \
443 BBSIM_NS \
David Bainbridge7db44002020-04-09 12:54:29 -0700444 SADIS_BANDWIDTH_PROFILES \
445 SADIS_SUBSCRIBERS \
David Bainbridgeb4bbde12020-06-25 14:46:36 -0700446 PF_ADDRESS \
David K. Bainbridge2aa08da2020-07-31 12:49:45 -0700447 KIND_CFG_FILE \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000448 "
David Bainbridge01294952019-07-30 19:33:45 +0000449
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000450# Iterate over yes/no configuration options and validate
451for VAR in $ALL_YES_NO; do
David Bainbridged18f4942020-04-14 16:46:13 -0700452 eval "$VAR"="$(verify_yes_no "$VAR")"
453 if [ "$(eval echo "\$$VAR")" == "INVALID" ]; then
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000454 exit 1;
455 fi
456done
David Bainbridgeb270c202019-07-26 01:44:42 +0000457
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700458# Iterate over optional yes/no configuration options and
459# normalize values if they are truth values
460for VAR in $OPT_YES_NO; do
461 eval "$VAR"="$(normalize_yes_no "$VAR")"
462done
David Bainbridge15f6f232020-03-30 09:15:43 -0700463
Matteo Scandolo657e13c2020-07-28 11:41:42 -0700464# check number (range) of bbsim, max bbsim must not exceed 10 instances!
465# note: instances will be numbered from 0 to 9
466if [ "$1" == "up" ]; then
467 if [ "$NUM_OF_BBSIM" -lt 1 ]; then
468 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} Invalid setting of BBSIM instances. NUM_OF_BBSIM (${NUM_OF_BBSIM}) is less than 1${NORMAL}"
469 exit 1
470 fi
471 if [ "$NUM_OF_BBSIM" -gt "$MAX_NUM_OF_BBSIM" ]; then
472 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} Invalid setting of BBSIM instances. NUM_OF_BBSIM (${NUM_OF_BBSIM}) is greater than $MAX_NUM_OF_BBSIM${NORMAL}"
473 exit 1
474 fi
475
476 if [ "$NUM_OF_OPENONU" -lt 1 ]; then
477 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} Invalid setting of OPENONU instances. NUM_OF_OPENONU (${NUM_OF_OPENONU}) is less than 1${NORMAL}"
478 exit 1
479 fi
480 if [ "$NUM_OF_OPENONU" -gt "$MAX_NUM_OF_OPENONU" ]; then
481 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} Invalid setting of OPENONU instances. NUM_OF_OPENONU (${NUM_OF_OPENONU}) is greater than $MAX_NUM_OF_OPENONU${NORMAL}"
482 exit 1
483 fi
484
David K. Bainbridge2aa08da2020-07-31 12:49:45 -0700485 HAVE_CLUSTER="$(kind get clusters 2>/dev/null | grep -c "voltha-$NAME")"
486 if [ "$HAVE_CLUSTER" -eq 0 ]; then
487 # If the user has specified a kind cluster configuration file,
488 # 'KIND_CFG_FILE` then we need to gleem from that file the number
489 # of worker and controller nodes as this overrides any setting of
490 # these values
491 if [ -n "$KIND_CFG_FILE" ]; then
492 NUM_OF_WORKER_NODES="$(sed 's/ //g' "$KIND_CFG_FILE" | grep -c "^-role:worker$")"
493 NUM_OF_CONTROLLER_NODES="$(sed 's/ //g' "$KIND_CFG_FILE" | grep -c "^-role:control-plane$")"
494 fi
Matteo Scandolo657e13c2020-07-28 11:41:42 -0700495
David K. Bainbridge2aa08da2020-07-31 12:49:45 -0700496 # check that NUM_OF_KAFKA, NUM_OF_ONOS, NUM_OF_ATOMIX, NUM_OF_ETCD is:
497 # <= NUM_OF_WORKER_NODES + 1 if SCHEDULE_ON_CONTROL_NODES == y
498 # <= NUM_OF_WORKER_NODES if SCHEDULE_ON_CONTROL_NODES == n
499 SCHEDULABLE_NODES=$NUM_OF_WORKER_NODES
500
501 if [ "$SCHEDULE_ON_CONTROL_NODES" == "yes" ]; then
502 SCHEDULABLE_NODES=$((NUM_OF_CONTROLLER_NODES+NUM_OF_WORKER_NODES))
503 fi
504 else
505 TOTAL_NODES=$(kubectl get --all-namespaces nodes -o name | wc -l)
506 NUM_OF_CONTROLLER_NODES=$(kubectl get --all-namespaces nodes -l node-role.kubernetes.io/master -o name | wc -l)
507 NUM_OF_WORKER_NODES=$((TOTAL_NODES - NUM_OF_CONTROLLER_NODES))
508 # shellcheck disable=SC2016
509 SCHEDULABLE_NODES=$(kubectl get no -o 'go-template={{range .items}}{{$taints:=""}}{{range .spec.taints}}{{if eq .effect "NoSchedule"}}{{$taints = print $taints .key ","}}{{end}}{{end}}{{if not $taints}}{{.metadata.name}}{{ "\n"}}{{end}}{{end}}' | wc -l | sed -e 's/ //g')
510 rm -f "$TMP_KUBECFG"
Matteo Scandolo657e13c2020-07-28 11:41:42 -0700511 fi
Matteo Scandolo657e13c2020-07-28 11:41:42 -0700512 NODES="SCHEDULE_ON_CONTROL_NODES: $SCHEDULE_ON_CONTROL_NODES, SCHEDULABLE_NODES: $SCHEDULABLE_NODES, NUM_OF_CONTROLLER_NODES: $NUM_OF_CONTROLLER_NODES, NUM_OF_WORKER_NODES: $NUM_OF_WORKER_NODES"
513
David K. Bainbridge2aa08da2020-07-31 12:49:45 -0700514 if is_in "$WITH_KAFKA" "yes,external" && [ ! "$NUM_OF_KAFKA" -le "$SCHEDULABLE_NODES" ]; then
Matteo Scandolo657e13c2020-07-28 11:41:42 -0700515 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} Invalid setting of KAFKA replicas. NUM_OF_KAFKA (${NUM_OF_KAFKA}) is greater than the available nodes ($NODES)${NORMAL}"
516 exit 1
517 fi
518
David K. Bainbridge2aa08da2020-07-31 12:49:45 -0700519 if is_in "$WITH_ETCD" "yes,external" && [ ! "$NUM_OF_ETCD" -le "$SCHEDULABLE_NODES" ]; then
Matteo Scandolo657e13c2020-07-28 11:41:42 -0700520 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} Invalid setting of ETCD replicas. NUM_OF_ETCD (${NUM_OF_ETCD}) is greater than the available nodes ($NODES)${NORMAL}"
521 exit 1
522 fi
523
David K. Bainbridge2aa08da2020-07-31 12:49:45 -0700524 if is_in "$WITH_ONOS" "yes,legacy,classic,micro"; then
525 if [ ! "$NUM_OF_ATOMIX" -le "$SCHEDULABLE_NODES" ]; then
526 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} Invalid setting of ATOMIX replicas. NUM_OF_ATOMIX (${NUM_OF_ATOMIX}) is greater than the available nodes ($NODES)${NORMAL}"
527 exit 1
528 fi
Matteo Scandolo657e13c2020-07-28 11:41:42 -0700529
David K. Bainbridge2aa08da2020-07-31 12:49:45 -0700530 if [ ! "$NUM_OF_ONOS" -le "$SCHEDULABLE_NODES" ]; then
531 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} Invalid setting of ONOS replicas. NUM_OF_ONOS (${NUM_OF_ONOS}) is greater than the available nodes ($NODES)${NORMAL}"
532 exit 1
533 fi
Matteo Scandolo657e13c2020-07-28 11:41:42 -0700534 fi
535fi
536
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700537# normalize non-truth value options
538if is_in "$WITH_KAFKA" "e,external"; then
David Bainbridge76afd812020-04-06 09:53:52 -0700539 WITH_KAFKA="external"
540fi
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700541if is_in "$WITH_ETCD" "e,external"; then
David Bainbridge76afd812020-04-06 09:53:52 -0700542 WITH_ETCD="external"
543fi
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700544if is_in "$WITH_ONOS" "l,legacy"; then
545 WITH_ONOS="legacy"
546elif is_in "$WITH_ONOS" "c,classic"; then
547 WITH_ONOS="classic"
548elif is_in "$WITH_ONOS" "u,m,micro"; then
549 WITH_ONOS="micro"
David Bainbridge29c31cb2020-04-06 09:45:50 -0700550fi
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700551
552if [ "$WITH_ONOS" == "micro" ]; then
553 >&2 echo -e "${YELLOW}${BOLD}${ERROR}WARNING:${NORMAL}${YELLOW} The value specified as WITH_ONOS, '$WITH_ONOS', is not valid.${NORMAL}"
554 exit 1
David Bainbridge29c31cb2020-04-06 09:45:50 -0700555fi
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700556
557if is_in "$WITH_ONOS" "yes,classic"; then
558 # there is an extra utility required if we are using ONOS CLASSIC as
559 # the chart for classic specifies images differently
560 EXTRA_TOOLS+=" yq"
David Bainbridge76afd812020-04-06 09:53:52 -0700561fi
David Bainbridge696bc632020-04-05 21:49:37 -0700562
David Bainbridge22db5dd2020-05-26 12:21:21 -0700563if [ "$LEGACY_BBSIM_INDEX" == "no" ]; then
564 BBSIM_SADIS_SVC="bbsim0"
565else
566 BBSIM_SADIS_SVC="bbsim"
567fi
568
569SADIS_SUBSCRIBERS=${SADIS_SUBSCRIBERS:-http://$BBSIM_SADIS_SVC.$VOLTHA_NS.svc:50074/v2/subscribers/%s}
570SADIS_BANDWIDTH_PROFILES=${SADIS_BANDWIDTH_PROFILES:-http://$BBSIM_SADIS_SVC.$VOLTHA_NS.svc:50074/v2/bandwidthprofiles/%s}
571
David Bainbridged18f4942020-04-14 16:46:13 -0700572if [ "$HELM_USE_UPGRADE" == "yes" ]; then
David Bainbridge7f8bf992020-04-08 21:53:22 -0700573 _HELM_DESC="Upgrade/Install"
574else
575 _HELM_DESC="Install"
576fi
577
David K. Bainbridgeda33d652020-03-06 10:31:23 -0800578# Check for prerequiste tools
David Bainbridge60ffc0f2020-04-27 22:13:22 -0700579TOOLS="curl sed jq $EXTRA_TOOLS"
David Bainbridged18f4942020-04-14 16:46:13 -0700580if [ "$DEPLOY_K8S" == "yes" ]; then
David K. Bainbridgeda33d652020-03-06 10:31:23 -0800581 TOOLS+=" docker"
582fi
583NOT_FOUND=""
584for T in $TOOLS; do
David Bainbridged18f4942020-04-14 16:46:13 -0700585 if [ -z "$(command -v "$T")" ]; then
David K. Bainbridgeda33d652020-03-06 10:31:23 -0800586 NOT_FOUND+=" $T"
587 fi
588done
589
David Bainbridged18f4942020-04-14 16:46:13 -0700590if [ -n "$NOT_FOUND" ]; then
David K. Bainbridgeda33d652020-03-06 10:31:23 -0800591 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} The following required tools where not found, please install them:$NOT_FOUND"
592 exit 1
593fi
594
David Bainbridged18f4942020-04-14 16:46:13 -0700595TIMEOUT_SECONDS="$(parseDuration "$WAIT_TIMEOUT")"
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700596
David Bainbridge0774b232019-08-02 06:37:19 +0000597mkdir -p .voltha
598touch .voltha/ports
David K. Bainbridge00ecd382020-02-28 12:31:58 -0800599
Matteo Scandoloe89384a2020-11-06 08:40:25 -0800600# check if the stack deployed with $NAME already exists
601STACK_EXISTS=false
602if [ "$(grep -c "$NAME" .voltha/ports)" -eq 1 ]; then
603 STACK_EXISTS=true
604fi
605
606if [ "$STACK_EXISTS" == true ]; then
Matteo Scandolo33703282020-12-11 14:27:49 -0800607 echo "stack exists"
Matteo Scandoloe89384a2020-11-06 08:40:25 -0800608 # if the stack was previously deployed reuse the ports
609 HAVE="$(grep "$NAME" .voltha/ports)"
610 VALUES="$(echo "$HAVE" | sed -e 's/\s//g' | cut -d= -f2)"
611 ONOS_API_PORT=$(echo "$VALUES" | cut -d, -f1)
612 ONOS_SSH_PORT=$(echo "$VALUES" | cut -d, -f2)
613 VOLTHA_API_PORT=$(echo "$VALUES" | cut -d, -f3)
614 VOLTHA_SSH_PORT=$(echo "$VALUES" | cut -d, -f4)
615 VOLTHA_ETCD_PORT=$(echo "$VALUES" | cut -d, -f5)
616 VOLTHA_KAFKA_PORT=$(echo "$VALUES" | cut -d, -f6)
617 VOLTHA_PPROF_PORT=$(echo "$VALUES" | cut -d, -f7)
618 OPENOLT_PPROF_PORT=$(echo "$VALUES" | cut -d, -f8)
619 OFAGENT_PPROF_PORT=$(echo "$VALUES" | cut -d, -f9)
620 ELASTICSEARCH_PORT=$(echo "$VALUES" | cut -d, -f10)
621 KIBANA_PORT=$(echo "$VALUES" | cut -d, -f11)
622 TRACING_GUI_PORT=$(echo "$VALUES" | cut -d, -f12)
623
624 # Some ports were added after the .voltha/ports files was created.
625 # Calculate the original DELTA from the VOLTHA_SSH_PORT so that it can
626 # be used to set up newer port-forwards.
627 DELTA="$((VOLTHA_SSH_PORT/100-50))"
628 if [ -z "$VOLTHA_KAFKA_PORT" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -0700629 VOLTHA_KAFKA_PORT=${VOLTHA_KAFKA_PORT:-$((90 + DELTA))92}
David K. Bainbridge00ecd382020-02-28 12:31:58 -0800630 fi
Matteo Scandoloefee0432020-05-05 13:56:20 -0700631
632 if [ -z "$VOLTHA_PPROF_PORT" ]; then
divyadesai59f987a2020-05-27 12:11:33 +0000633 VOLTHA_PPROF_PORT=${VOLTHA_PPROF_PORT:-$((60 + DELTA))60}
Matteo Scandoloefee0432020-05-05 13:56:20 -0700634 fi
635 if [ -z "$OPENOLT_PPROF_PORT" ]; then
divyadesai59f987a2020-05-27 12:11:33 +0000636 OPENOLT_PPROF_PORT=${OPENOLT_PPROF_PORT:-$((60 + DELTA))61}
Matteo Scandoloefee0432020-05-05 13:56:20 -0700637 fi
Matteo Scandolo65c35192020-05-13 10:41:21 -0700638 if [ -z "$OFAGENT_PPROF_PORT" ]; then
divyadesai59f987a2020-05-27 12:11:33 +0000639 OFAGENT_PPROF_PORT=${OFAGENT_PPROF_PORT:-$((60 + DELTA))62}
640 fi
641
642 if [ -z "$ELASTICSEARCH_PORT" ]; then
643 ELASTICSEARCH_PORT=${ELASTICSEARCH_PORT:-$((92 + DELTA))00}
644 fi
divyadesai59f987a2020-05-27 12:11:33 +0000645 if [ -z "$KIBANA_PORT" ]; then
646 KIBANA_PORT=${KIBANA_PORT:-$((56 + DELTA))01}
Matteo Scandolo65c35192020-05-13 10:41:21 -0700647 fi
Girish Kumarcc5f9172020-06-10 13:34:31 +0000648
649 if [ -z "$TRACING_GUI_PORT" ]; then
650 TRACING_GUI_PORT=${TRACING_GUI_PORT:-1$((66 + DELTA))86}
651 fi
Matteo Scandoloe89384a2020-11-06 08:40:25 -0800652else
653 # Find free port prefix
Matteo Scandolo33703282020-12-11 14:27:49 -0800654 START=81
655 while true; do
656 if [ "$(grep -c $START .voltha/ports)" -eq 0 ]; then
657 break
658 fi
659 START="$((START + 1))"
660 done
Matteo Scandoloe89384a2020-11-06 08:40:25 -0800661
Matteo Scandolo33703282020-12-11 14:27:49 -0800662 # create new ports starting from the first available
663 DELTA="$((START - 81))"
664 ONOS_API_PORT=${ONOS_API_PORT:-${START}81}
665 ONOS_SSH_PORT=${ONOS_SSH_PORT:-${START}01}
666 VOLTHA_API_PORT=${VOLTHA_API_PORT:-5$((55 + DELTA))55}
667 VOLTHA_SSH_PORT=${VOLTHA_SSH_PORT:-$((50 + DELTA))22}
668 VOLTHA_ETCD_PORT=${VOLTHA_ETCD_PORT:-$((23 + DELTA))79}
669 VOLTHA_KAFKA_PORT=${VOLTHA_KAFKA_PORT:-$((90 + DELTA))92}
670 VOLTHA_PPROF_PORT=${VOLTHA_PPROF_PORT:-$((60 + DELTA))60}
671 OPENOLT_PPROF_PORT=${OPENOLT_PPROF_PORT:-$((60 + DELTA))61}
672 OFAGENT_PPROF_PORT=${OFAGENT_PPROF_PORT:-$((60 + DELTA))62}
673 ELASTICSEARCH_PORT=${ELASTICSEARCH_PORT:-$((92 + DELTA))00}
674 KIBANA_PORT=${KIBANA_PORT:-$((56 + DELTA))01}
675 TRACING_GUI_PORT=${TRACING_GUI_PORT:-1$((66 + DELTA))86}
Test User01ed0642019-07-03 20:17:06 +0000676fi
677
David Bainbridged18f4942020-04-14 16:46:13 -0700678PORTTMP="$(mktemp -u)"
679grep -v "$NAME" .voltha/ports > "$PORTTMP"
Girish Kumarcc5f9172020-06-10 13:34:31 +0000680echo "$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 -0700681cp "$PORTTMP" .voltha/ports
682rm -f "$PORTTMP"
David Bainbridge0774b232019-08-02 06:37:19 +0000683
David Bainbridge27790d62019-08-13 22:43:19 +0000684export ONOS_API_PORT ONOS_SSH_PORT
David Bainbridge01294952019-07-30 19:33:45 +0000685
Test Userd87942b2019-07-03 07:20:24 +0000686IDX=1
David Bainbridgee87067b2019-08-12 22:00:12 +0000687CLOCK="TIME:"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000688SPIN_PARTS=
689NOT_VERIFIED=
David Bainbridgef858a022019-08-14 21:25:11 +0000690THEX=
691BUILD=
David Bainbridge38dc1e82019-08-12 15:18:45 +0000692VERIFIED=
693HELM=
694OLD_KEY=
695BIRD=
696HIGH_VOLTAGE=
697PLUG=
David Bainbridge38dc1e82019-08-12 15:18:45 +0000698FORWARD=
David Bainbridge38dc1e82019-08-12 15:18:45 +0000699GO=
700DOWNLOAD=
701GEAR=
702NO_ENTRY=
703LOCK=
704
David Bainbridged18f4942020-04-14 16:46:13 -0700705if [ "$FANCY" -eq 1 ]; then
706 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 +0000707 CLOCK="\xe2\x8f\xb1"
David Bainbridgef858a022019-08-14 21:25:11 +0000708 THEX="${RED}${BOLD}\xe2\x9c\x97\x20${NORMAL}"
David Bainbridgef858a022019-08-14 21:25:11 +0000709 BUILD="${YELLOW}${BOLD}\xf0\x9f\x8f\x97${NORMAL}"
710 NOT_VERIFIED="$BUILD"
711 VERIFIED="${GREEN}${BOLD}\xe2\x9c\x93\x20${NORMAL}"
712 HELM="${BLUE}${BOLD}\xE2\x8E\x88${NORMAL}"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000713 OLD_KEY="\xF0\x9F\x97\x9D"
714 BIRD="\xF0\x9F\x90\xA6"
715 HIGH_VOLTAGE="\xE2\x9A\xA1"
716 PLUG="\xF0\x9F\xa7\xa9"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000717 FORWARD="\xE2\x87\xA8"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000718 GO="\xf0\x9f\x9a\x80"
719 DOWNLOAD="\xf0\x9f\x93\xa5"
720 GEAR="\xe2\x9a\x99"
721 NO_ENTRY="\xe2\x9b\x94"
722 LOCK="\xf0\x9f\x94\x92"
723fi
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700724
David Bainbridge712afb82019-08-14 19:55:58 +0000725duration() {
David Bainbridged18f4942020-04-14 16:46:13 -0700726 local h m s t
727 h="$(($1 / 3600))"
728 m="$(($1 % 3600 / 60))"
729 s="$(($1 % 60))"
730 t=""
David Bainbridgee87067b2019-08-12 22:00:12 +0000731
David Bainbridged18f4942020-04-14 16:46:13 -0700732 if [ "$h" -gt 0 ]; then
David Bainbridgee87067b2019-08-12 22:00:12 +0000733 t="$t${h}h"
734 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700735 if [ "$m" -gt 0 ]; then
David Bainbridgee87067b2019-08-12 22:00:12 +0000736 t="$t${m}m"
737 fi
David Bainbridge712afb82019-08-14 19:55:58 +0000738 echo "$t${s}s"
739}
740
741printtime() {
David Bainbridged18f4942020-04-14 16:46:13 -0700742 local INDENT
David Bainbridge712afb82019-08-14 19:55:58 +0000743 if [ "$1" == "-" ]; then
744 INDENT=" "
745 shift
746 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700747 echo -e "$INDENT $CLOCK $(duration "$1")"
David Bainbridgee87067b2019-08-12 22:00:12 +0000748}
749
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700750bspin() {
Test Userd87942b2019-07-03 07:20:24 +0000751 IDX=1
David Bainbridged18f4942020-04-14 16:46:13 -0700752 local INDENT
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700753 if [ "$1" == "-" ]; then
754 INDENT=" "
755 shift
756 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700757 if [ "$FANCY" -eq 0 ]; then
758 LINE="${*//[[:space:]+-]}"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000759 if [ "$LINE X" == " X" ]; then
760 return
761 fi
762 echo -e "$CIVIS$INDENT$*"
763 else
764 echo -en "$CIVIS$INDENT $*"
765 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700766}
767
768sspin() {
David Bainbridged18f4942020-04-14 16:46:13 -0700769 local INDENT
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700770 if [ "$1" == "-" ]; then
771 INDENT=" "
772 shift
773 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700774 if [ "$FANCY" -eq 0 ]; then
775 LINE="${*//[[:space:]+-]}"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000776 if [ "$LINE X" == " X" ]; then
777 return
778 fi
779 echo -e "$INDENT$*"
780 else
David Bainbridged18f4942020-04-14 16:46:13 -0700781 C="$(echo "$SPIN_PARTS" | cut '-d ' -f "$IDX")"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000782 echo -en "\r$INDENT$C $*"
David Bainbridged18f4942020-04-14 16:46:13 -0700783 IDX="$((IDX + 1))"
784 if [ "$IDX" -gt 8 ]; then
David Bainbridge38dc1e82019-08-12 15:18:45 +0000785 IDX=1
786 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700787 fi
788}
789
790espin() {
David Bainbridged18f4942020-04-14 16:46:13 -0700791 local INDENT
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700792 if [ "$1" == "-" ]; then
793 INDENT=" "
794 shift
795 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700796 if [ "$FANCY" -eq 0 ]; then
797 LINE="${*//[[:space:]+-]}"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000798 if [ "$LINE X" == " X" ]; then
799 return
800 fi
801 echo -e "$INDENT$*"
802 else
803 echo -e "\r$INDENT$*$CNORM"
804 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700805}
806
David Bainbridged18f4942020-04-14 16:46:13 -0700807if [ "$1" == "get" ] && [ "$2" == "voltconfig" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000808 echo "$HOME/.volt/config-$NAME"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000809 exit
810fi
811
David Bainbridgee4d11ca2020-05-08 10:21:10 -0700812if [ $# -ne 1 ] || ! is_in "$1" "up,down,dump,clean"; then
David Bainbridgeac7f8072019-08-01 22:15:33 +0000813 >&2 echo "What wouild you like to do today:"
814 >&2 echo " up - bring up voltha"
815 >&2 echo " down - tear down voltha"
Matteo Scandoloe89384a2020-11-06 08:40:25 -0800816 >&2 echo " clean - remove everything that kind-voltha created"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000817 >&2 echo " dump - create a debug dump of running system"
818 exit 1
819fi
820
divyadesai59f987a2020-05-27 12:11:33 +0000821do_curl() {
822 local DATA_ARGS CREDS CMD_ECHO CMD_OUTPUT SC_OUTPUT WAIT_START INDENTA EXTRAA NOW
823 local INDENT=$1
824 local OP=$2
825 local USER=$3
826 local PASS=$4
827 local URL=$5
828 local DATA_TYPE=$6
829 local DATA=$7
830 local MSG=$8
831 local VALID_RESULTS=$9
832 local EXTRA=${10}
833 local ICON=${11}
834
835 # Turn into an array for passing
836 INDENTA=()
837 if [ -n "$INDENT" ]; then
838 INDENTA=("$INDENT")
839 fi
840 IFS=' ' read -r -a EXTRAA <<< "$EXTRA"
David Bainbridge4f1b5562019-08-19 04:46:52 +0000841
David K. Bainbridgeb4b163b2020-02-19 15:55:06 -0800842 # Thanks to the latest version of ONOS using the return code 207 this gets a
843 # whole lot nastier. Can't thank them enough for doing this. So in order to
844 # capture the command and the output in the log file as well as capture the
845 # status code to verify it is 200 and not 207 mutltiple files and a bit of
846 # hackery must be used. Thanks again ONOS.
David Bainbridged18f4942020-04-14 16:46:13 -0700847 CMD_ECHO="$(mktemp -u)"
848 CMD_OUTPUT="$(mktemp -u)"
849 SC_OUTPUT="$(mktemp -u)"
850 WAIT_START="$(date +%s)"
David K. Bainbridgeb4b163b2020-02-19 15:55:06 -0800851
divyadesai59f987a2020-05-27 12:11:33 +0000852 CREDS=()
853 if [ -n "$USER" ]; then
854 CREDS=("--user" "$USER:$PASS")
855 fi
856
857 DATA_ARGS=()
858 if [ -n "$DATA" ]; then
859 if [ "$DATA_TYPE" == "file" ]; then
860 DATA_ARGS=("--data" "@$DATA")
861 elif [ "$DATA_TYPE" == "json" ]; then
862 DATA_ARGS=("--data" "$DATA")
863 fi
864 fi
865
866 bspin "${INDENTA[@]}" "$MSG" "$ICON"
David Bainbridge4f1b5562019-08-19 04:46:52 +0000867 while true; do
David Bainbridged18f4942020-04-14 16:46:13 -0700868 NOW="$(date +%s)"
869 if [ "$((NOW - WAIT_START))" -gt "$TIMEOUT_SECONDS" ]; then
divyadesai59f987a2020-05-27 12:11:33 +0000870 espin "${INDENTA[@]}" "$THEX"
David Bainbridged18f4942020-04-14 16:46:13 -0700871 rm -f "$CMD_ECHO" "$CMD_OUTPUT" "$SC_OUTPUT"
divyadesai59f987a2020-05-27 12:11:33 +0000872 doTimeout "$MSG"
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700873 fi
divyadesai59f987a2020-05-27 12:11:33 +0000874 (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
875 RESULT=$?
David K. Bainbridgeb4b163b2020-02-19 15:55:06 -0800876 # Dump everything to the log
David Bainbridged18f4942020-04-14 16:46:13 -0700877 cat "$CMD_ECHO" >> "$LOG"
878 test -r "$CMD_OUTPUT" && cat "$CMD_OUTPUT" >> "$LOG"
879 SC="$(cat "$SC_OUTPUT")"
880 echo "RESPONSE CODE: $SC" >> "$LOG"
881 echo "ERROR CODE: $RESULT" >> "$LOG"
David K. Bainbridgeb4b163b2020-02-19 15:55:06 -0800882
883 # clean up temp files
David Bainbridged18f4942020-04-14 16:46:13 -0700884 rm -f "$CMD_ECHO" "$CMD_OUTPUT" "$SC_OUTPUT"
divyadesai59f987a2020-05-27 12:11:33 +0000885 if [ "$RESULT" -eq 0 ] && is_in "$SC" "$VALID_RESULTS"; then
David Bainbridge4f1b5562019-08-19 04:46:52 +0000886 break
887 fi
Matteo Scandolo9a77a732020-01-09 14:24:12 -0800888 sleep 1
divyadesai59f987a2020-05-27 12:11:33 +0000889 sspin "${INDENTA[@]}"
David Bainbridge4f1b5562019-08-19 04:46:52 +0000890 done
divyadesai59f987a2020-05-27 12:11:33 +0000891 espin "${INDENTA[@]}" "$VERIFIED"
892}
893
894push_onos_config() {
895 local DATA_TYPE=$1
896 local MSG=$2
897 local RESOURCE=$3
898 local DATA=$4
899
900 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 +0000901}
902
Matteo Scandolo9a77a732020-01-09 14:24:12 -0800903check_onos_app_active() {
David Bainbridged18f4942020-04-14 16:46:13 -0700904 local APP_ID WAIT_START RESULT NOW
905 APP_ID=$1
906 WAIT_START="$(date +%s)"
Matteo Scandolo9a77a732020-01-09 14:24:12 -0800907
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700908 bspin - "Checking that $APP_ID is active $CLOCK"
909 while true; do
David Bainbridged18f4942020-04-14 16:46:13 -0700910 NOW="$(date +%s)"
911 if [ "$((NOW - WAIT_START))" -gt "$TIMEOUT_SECONDS" ]; then
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700912 espin - "$THEX"
913 doTimeout "waiting for ONOS application activation '$APP_ID'"
914 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700915 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 -0700916 break
917 fi
918 sleep 1
919 sspin -
920 done
921 sleep 5 # OSGI components take a little longer that the app to activate
David Bainbridged18f4942020-04-14 16:46:13 -0700922 espin - "$VERIFIED"
Matteo Scandolo9a77a732020-01-09 14:24:12 -0800923}
924
David Bainbridge4f1b5562019-08-19 04:46:52 +0000925override_onos_app() {
David Bainbridged18f4942020-04-14 16:46:13 -0700926 local APP NAME WAIT_START NOW
927 APP=$1
928 NAME="$(basename "$APP" | sed -e 's/^[0-9][0-9]*-//g' -e 's/-.*$//g')"
929 WAIT_START="$(date +%s)"
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700930
David Bainbridge4f1b5562019-08-19 04:46:52 +0000931 while true; do
David Bainbridged18f4942020-04-14 16:46:13 -0700932 NOW="$(date +%s)"
933 if [ "$((NOW - WAIT_START))" -gt "$TIMEOUT_SECONDS" ]; then
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700934 espin - "$THEX"
935 doTimeout "waiting to overwrite ONOS application '$APP'"
936 fi
David Bainbridge4f1b5562019-08-19 04:46:52 +0000937 sspin -
938 # Attempt to delete old version (if it exists)
David Bainbridged18f4942020-04-14 16:46:13 -0700939 (set -x; curl --fail -sSL --user karaf:karaf -X DELETE "http://$_ONOS_API_EP/onos/v1/applications/$NAME" >>"$LOG" 2>&1) >>"$LOG" 2>&1
940 RESULT=$?
David Bainbridge4f1b5562019-08-19 04:46:52 +0000941 sspin -
David Bainbridged18f4942020-04-14 16:46:13 -0700942 if [ $RESULT -ne 0 ]; then
David Bainbridge4f1b5562019-08-19 04:46:52 +0000943 continue
944 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700945 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 +0000946 break
947 fi
948 sleep .2
949 done
950}
951
952activate_onos_app() {
David Bainbridged18f4942020-04-14 16:46:13 -0700953 local MSG APP WAIT_START NOW
954 MSG="$1"
955 APP=$2
956 WAIT_START="$(date +%s)"
David Bainbridge4f1b5562019-08-19 04:46:52 +0000957
958 bspin - "$MSG $GO"
959 while true; do
David Bainbridged18f4942020-04-14 16:46:13 -0700960 NOW="$(date +%s)"
961 if [ "$((NOW - WAIT_START))" -gt "$TIMEOUT_SECONDS" ]; then
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700962 espin - "$THEX"
963 doTimeout "waiting to activate ONOS application '$APP'"
964 fi
David Bainbridge4f1b5562019-08-19 04:46:52 +0000965 sspin -
David Bainbridged18f4942020-04-14 16:46:13 -0700966 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 +0000967 break
968 fi
969 sleep .2
970 done
971 espin - "$VERIFIED"
972}
973
974count_pods() {
David Bainbridged18f4942020-04-14 16:46:13 -0700975 local NAMESPACE STATES LABELS CMD PODS
976 NAMESPACE=$1; shift
David Bainbridge4f1b5562019-08-19 04:46:52 +0000977 if [ "$NAMESPACE" == "all-namespaces" ]; then
978 NAMESPACE="--all-namespaces"
979 else
980 NAMESPACE="-n $NAMESPACE"
981 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700982 STATES=$1; shift
983 LABELS=$1; shift
984 CMD=("kubectl get $NAMESPACE $LABELS pod")
985 PODS=$(${CMD[*]} -o go-template="{{range .items}}{{.metadata.name}}/{{.status.phase}}/_{{range .status.containerStatuses}}{{.ready}}_{{end}} {{end}}")
David Bainbridge4f1b5562019-08-19 04:46:52 +0000986 local COUNT=0
987 local PATTERNS="$*"
988 for POD in $PODS; do
David Bainbridged18f4942020-04-14 16:46:13 -0700989 local NAME STATE CONTAINERS TOTAL FOUND
990 NAME="$(echo "$POD" | cut -d/ -f 1)"
991 STATE="$(echo "$POD" | cut -d/ -f 2)"
992 CONTAINERS="$(echo "$POD" | cut -d/ -f 3 | sed -e 's/_/ /g')"
993 if [ "$STATES" == "*" ] || [ "$(echo "$STATES" | grep -c ":$STATE:")" -ne 0 ]; then
994 TOTAL="$(echo "$CONTAINERS" | wc -w)"
995 FOUND="$(echo "$CONTAINERS" | grep -o true | wc -l)"
996 if [ "$TOTAL" -eq "$FOUND" ]; then
David Bainbridge4f1b5562019-08-19 04:46:52 +0000997 for PATTERN in $PATTERNS; do
David Bainbridged18f4942020-04-14 16:46:13 -0700998 if [[ "$NAME" =~ $PATTERN ]]; then
999 COUNT="$((COUNT + 1))"
David Bainbridge4f1b5562019-08-19 04:46:52 +00001000 break
1001 fi
1002 done
1003 fi
1004 fi
1005 done
David Bainbridge4f1b5562019-08-19 04:46:52 +00001006 echo $COUNT
1007}
1008
1009wait_for_pods() {
David Bainbridged18f4942020-04-14 16:46:13 -07001010 local INDENT NAMESPACE EXPECT TYPE MESSAGE LABELS PATTERNS STATES HAVE ALL WAIT_START NOW
David Bainbridge4f1b5562019-08-19 04:46:52 +00001011 if [ "$1" == "-" ]; then
1012 INDENT=$1; shift
1013 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001014 NAMESPACE=$1; shift
1015 EXPECT=$1; shift
1016 TYPE=$1; shift
1017 MESSAGE=$1; shift
1018 LABELS=$1; shift
1019 PATTERNS=("$*")
1020 STATES=":Running:"
David Bainbridge99ac7a22019-08-31 02:26:43 +00001021 if [ "$TYPE" == "not" ]; then
1022 STATES="*"
1023 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001024 HAVE="$(count_pods "$NAMESPACE" "$STATES" "$LABELS" "${PATTERNS[@]}")"
1025 ALL=$HAVE
David Bainbridge4f1b5562019-08-19 04:46:52 +00001026 if [ "$TYPE" == "only" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001027 ALL="$(count_pods "all-namespaces" "*" ".*")"
David Bainbridge4f1b5562019-08-19 04:46:52 +00001028 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001029 COUNT="$((300 / 15))"
1030 WAIT_START="$(date +%s)"
1031 bspin "$INDENT" "$MESSAGE"
1032 sspin "$INDENT"
1033 if [ "$HAVE" -ne "$EXPECT" ] || [ "$ALL" -ne "$HAVE" ]; then
1034 while [ "$HAVE" -ne "$EXPECT" ] || [ "$ALL" -ne "$HAVE" ]; do
1035 NOW="$(date +%s)"
1036 if [ "$((NOW - WAIT_START))" -gt "$TIMEOUT_SECONDS" ]; then
1037 espin "$INDENT" "$THEX"
David Bainbridge52e6e9d2020-03-23 13:48:27 -07001038 doTimeout "waiting for PODs to start"
1039 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001040 sspin "$INDENT"
1041 COUNT="$((COUNT - 1))"
1042 if [ "$COUNT" -eq 0 ]; then
1043 HAVE="$(count_pods "$NAMESPACE" "$STATES" "$LABELS" "${PATTERNS[@]}")"
1044 ALL="$HAVE"
David Bainbridge4f1b5562019-08-19 04:46:52 +00001045 if [ "$TYPE" == "only" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001046 ALL="$(count_pods "all-namespaces" "*" ".*")"
David Bainbridge4f1b5562019-08-19 04:46:52 +00001047 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001048 COUNT="$((300 / 15))"
David Bainbridge4f1b5562019-08-19 04:46:52 +00001049 fi
1050 sleep .15
1051 done
1052 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001053 espin "$INDENT" "$VERIFIED"
1054 if [ "$HAVE" -ne "$EXPECT" ]; then
David Bainbridge4f1b5562019-08-19 04:46:52 +00001055 return 1
1056 fi
1057 return 0
1058}
1059
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -08001060port_forward() {
David Bainbridge60ffc0f2020-04-27 22:13:22 -07001061 local NS=$1; shift
1062 local SVC=$1; shift
1063 local PORTS="$*"
Matteo Scandoloe89384a2020-11-06 08:40:25 -08001064 local TAG=$SVC-$NS-$NAME
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -08001065
David Bainbridgeb4bbde12020-06-25 14:46:36 -07001066 (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 -08001067}
1068
1069kill_port_forward() {
Matteo Scandolod9789122020-12-04 15:09:06 -08001070 local TAG P_IDS PARENTS KIDS UNKNOWN PP_ID NS
David Bainbridge1d2c5842020-06-03 15:29:07 -07001071
Matteo Scandolod9789122020-12-04 15:09:06 -08001072 NS=$1; shift
1073 SVC=$1; shift
1074
1075 TAG=
1076 if [ "$SVC" != "__ALL__" ]; then
1077 TAG=$SVC-$NS-$NAME
1078 fi
1079 PARENTS=
1080 KIDS=
1081 UNKNOWN=
1082 # shellcheck disable=SC2009
1083 P_IDS="$(ps e -ww -A | grep "_TAG=$TAG" | grep -v grep | awk '{print $1}')"
1084 if [ -n "$P_IDS" ]; then
1085 for P_ID in $P_IDS; do
1086 PP_ID="$(ps -o ppid "$P_ID" | tail -n +2)"
1087 if [ -n "$PP_ID" ]; then
1088 if [ "$PP_ID" -eq 1 ]; then
1089 PARENTS="$PARENTS $P_ID"
David Bainbridgec6871d22019-11-13 17:10:31 +00001090 else
Matteo Scandolod9789122020-12-04 15:09:06 -08001091 KIDS="$KIDS $P_ID"
David Bainbridgec6871d22019-11-13 17:10:31 +00001092 fi
Matteo Scandolod9789122020-12-04 15:09:06 -08001093 else
1094 UNKNOWN="$UNKNOWN $P_ID"
1095 fi
1096 done
1097 if [ -n "$PARENTS" ]; then
1098 # shellcheck disable=SC2086
1099 while ps -h $PARENTS >/dev/null 2>&1; do
1100 (set -x; eval "kill -9 $PARENTS" >>"$LOG" 2>&1) >>"$LOG" 2>&1
David Bainbridge1d2c5842020-06-03 15:29:07 -07001101 done
David Bainbridge1d2c5842020-06-03 15:29:07 -07001102 fi
Matteo Scandolod9789122020-12-04 15:09:06 -08001103 if [ -n "$KIDS" ]; then
1104 # shellcheck disable=SC2086
1105 while ps -h $KIDS >/dev/null 2>&1; do
1106 (set -x; eval "kill -9 $KIDS" >>"$LOG" 2>&1) >>"$LOG" 2>&1
1107 done
1108 fi
1109 if [ -n "$UNKNOWN" ]; then
1110 # shellcheck disable=SC2086
1111 while ps -h $UNKNOWN >/dev/null 2>&1; do
1112 (set -x; eval "kill -9 $UNKNOWN" >>"$LOG" 2>&1) >>"$LOG" 2>&1
1113 done
1114 fi
1115 fi
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -08001116}
1117
Girish Kumarcc5f9172020-06-10 13:34:31 +00001118resolve_chart_name() {
1119 helm inspect chart "$1" | grep "^name:" | awk '{print $2}'
1120}
1121
David Bainbridgecf546362020-04-21 23:18:50 -07001122resolve_chart_version() {
1123 [ "$2" != "latest" ] && echo "$2" && return
1124 helm inspect chart "$1" | grep "^version:" | awk '{print $2}'
1125}
1126
Jonathan Hart6a91e6c2020-04-16 14:28:33 -07001127# Compares two semver-formatted version strings (e.g. 2.4.3)
1128# Returns 0 if $1 == $2, returns 1 if $1 > $2 and returns 2 if $1 < $2
1129compare_versions() {
1130 [ "$1" == "$2" ] && return 0
Jonathan Hart6a91e6c2020-04-16 14:28:33 -07001131 local lowest
1132 lowest=$(echo -e "$1\n$2" | sort -V | head -1)
1133 [ "$lowest" == "$1" ] && return 2
1134 return 1
1135}
1136
David Bainbridgeac7f8072019-08-01 22:15:33 +00001137if [ "$1" == "down" ]; then
Matteo Scandoloe89384a2020-11-06 08:40:25 -08001138 # NOTE ./voltha down tears down all the stacks, it should only remove components in the specified namespaces
David Bainbridge0774b232019-08-02 06:37:19 +00001139 echo "Tearing down voltha cluster $NAME"
Matteo Scandoloe89384a2020-11-06 08:40:25 -08001140
David Bainbridge0774b232019-08-02 06:37:19 +00001141 LOG="down-$NAME.log"
David Bainbridged18f4942020-04-14 16:46:13 -07001142 date -u +"%Y%m%dT%H%M%SZ" >"$LOG"
David Bainbridgeb4bbde12020-06-25 14:46:36 -07001143 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 -07001144 if is_in "$WITH_ONOS" "yes,legacy,classic"; then
David Bainbridge696bc632020-04-05 21:49:37 -07001145 bspin "Remove port-forwards: onos-ui-$NAME"
Matteo Scandoloe89384a2020-11-06 08:40:25 -08001146 kill_port_forward "$INFRA_NS" onos-ui
David Bainbridge696bc632020-04-05 21:49:37 -07001147 sspin "Remove port-forwards: onos-ssh-$NAME$CEOL"
Matteo Scandoloe89384a2020-11-06 08:40:25 -08001148 kill_port_forward "$INFRA_NS" onos-ssh
David K. Bainbridge2aa08da2020-07-31 12:49:45 -07001149 sspin "Remove port-forwards: onos-onos-classic-hs-$NAME$CEOL"
Matteo Scandoloe89384a2020-11-06 08:40:25 -08001150 kill_port_forward "$INFRA_NS" onos-onos-classic-hs
David Bainbridge696bc632020-04-05 21:49:37 -07001151 fi
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -08001152 sspin "Remove port-forwards: voltha-api-$NAME$CEOL"
Matteo Scandoloe89384a2020-11-06 08:40:25 -08001153 kill_port_forward "$VOLTHA_NS" voltha-api
1154 kill_port_forward "$VOLTHA_NS" voltha-voltha-api
David Bainbridgec7220622020-05-28 12:31:47 -07001155 if is_in "$WITH_ETCD" "yes,external"; then
1156 sspin "Remove port-forwards: etcd-$NAME$CEOL"
Matteo Scandoloe89384a2020-11-06 08:40:25 -08001157 kill_port_forward "$INFRA_NS" "etcd"
David Bainbridge696bc632020-04-05 21:49:37 -07001158 fi
David Bainbridgec7220622020-05-28 12:31:47 -07001159 if is_in "$WITH_KAFKA" "yes,external"; then
1160 sspin "Remove port-forwards: kafka-$NAME$CEOL"
Matteo Scandoloe89384a2020-11-06 08:40:25 -08001161 kill_port_forward "$INFRA_NS" "kafka"
David Bainbridge696bc632020-04-05 21:49:37 -07001162 fi
Matteo Scandoloefee0432020-05-05 13:56:20 -07001163
Andrea Campanellaeacf7f42020-10-15 14:46:33 +02001164 if is_in "$WITH_BBSIM" "yes"; then
1165 sspin "Remove port-forwards: bbsim$CEOL"
Matteo Scandoloe89384a2020-11-06 08:40:25 -08001166 kill_port_forward "$VOLTHA_NS" bbsim
Andrea Campanellaeacf7f42020-10-15 14:46:33 +02001167 fi
1168
Matteo Scandoloefee0432020-05-05 13:56:20 -07001169 if [ "$WITH_PPROF" == "yes" ]; then
David Bainbridgec7220622020-05-28 12:31:47 -07001170 sspin "Remove port-forwards: *-profiler$CEOL"
Matteo Scandoloe89384a2020-11-06 08:40:25 -08001171 kill_port_forward "$VOLTHA_NS" voltha-rw-core-profiler
1172 kill_port_forward "$VOLTHA_NS" voltha-voltha-rw-core-profiler
1173 kill_port_forward "$VOLTHA_NS" voltha-of-agent-profiler
1174 kill_port_forward "$VOLTHA_NS" voltha-voltha-of-agent-profiler
David Bainbridgec7220622020-05-28 12:31:47 -07001175 if [ "$WITH_OPEN_ADAPTERS" == "yes" ]; then
Matteo Scandoloe89384a2020-11-06 08:40:25 -08001176 kill_port_forward "$VOLTHA_NS" adapter-open-olt-profiler
1177 kill_port_forward "$VOLTHA_NS" open-olt-adapter-open-olt-profiler
David Bainbridgec7220622020-05-28 12:31:47 -07001178 fi
Matteo Scandoloefee0432020-05-05 13:56:20 -07001179 fi
1180
Girish Kumarcc5f9172020-06-10 13:34:31 +00001181 if [ "$WITH_TRACING" == "yes" ]; then
1182 sspin "Remove port-forwards: tracing-$NAME$CEOL"
1183 VOLTHA_TRACING_CHART_NAME=$(resolve_chart_name "$VOLTHA_TRACING_CHART")
Matteo Scandoloe89384a2020-11-06 08:40:25 -08001184 kill_port_forward "$INFRA_NS" "tracing-${VOLTHA_TRACING_CHART_NAME}-jaeger-gui"
Girish Kumarcc5f9172020-06-10 13:34:31 +00001185 fi
1186
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -08001187 espin "$VERIFIED Remove port-forwards$CEOL"
David Bainbridged18f4942020-04-14 16:46:13 -07001188 if [ "$DEPLOY_K8S" == "yes" ]; then
David Bainbridgeac7f8072019-08-01 22:15:33 +00001189 if [ -x ./bin/kind ]; then
David Bainbridge0774b232019-08-02 06:37:19 +00001190 bspin "Delete Kubernetes Kind Cluster"
David Bainbridged18f4942020-04-14 16:46:13 -07001191 (set -x; ./bin/kind delete cluster --name "voltha-$NAME" >>"$LOG" 2>&1) >>"$LOG" 2>&1
1192 espin "$VERIFIED"
David Bainbridgeac7f8072019-08-01 22:15:33 +00001193 else
David Bainbridge0774b232019-08-02 06:37:19 +00001194 espin "$NO_ENTRY Delete Kubernetes Kind Cluster: kind command not found"
David Bainbridgeac7f8072019-08-01 22:15:33 +00001195 fi
1196 else
David Bainbridge309099c2020-05-05 08:47:29 -07001197 if [ "$CONFIG_SADIS" == "external" ]; then
1198 bspin "Remove configmap for BBSIM SADIS server"
1199 (set -x; kubectl -n "$BBSIM_NS" delete --ignore-not-found configmap kube-config >>"$LOG" 2>&1) >>"$LOG" 2>&1
1200 espin "$VERIFIED"
1201 fi
David Bainbridgeb4bbde12020-06-25 14:46:36 -07001202
1203 if [ "$HELM_MAJOR" -le 2 ]; then
1204 EXISTS=$(helm list --output json 2>/dev/null | jq -r '.Releases | .[] | .Name + "," + .Namespace')
1205 else
1206 EXISTS=$(helm list --all-namespaces --output json 2>/dev/null | jq -r '.[] | .name + "," + .namespace')
1207 fi
David Bainbridge76afd812020-04-06 09:53:52 -07001208 EXPECT="voltha"
David Bainbridge60ffc0f2020-04-27 22:13:22 -07001209 if is_in "$WITH_ONOS" "yes,legacy,classic"; then
David Bainbridge696bc632020-04-05 21:49:37 -07001210 EXPECT+=" onos"
1211 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001212 if [ "$WITH_RADIUS" == "yes" ]; then
David Bainbridge696bc632020-04-05 21:49:37 -07001213 EXPECT+=" radius"
1214 fi
David Bainbridge309099c2020-05-05 08:47:29 -07001215 if [ "$CONFIG_SADIS" == "external" ]; then
1216 EXPECT+=" bbsim-sadis-server"
1217 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001218 if [ "$WITH_BBSIM" == "yes" ]; then
David Bainbridge696bc632020-04-05 21:49:37 -07001219 EXPECT+=" bbsim"
1220 fi
divyadesai59f987a2020-05-27 12:11:33 +00001221 if [ "$WITH_EFK" == "yes" ]; then
1222 EXPECT+=" elasticsearch kibana fluentd"
1223 fi
Girish Kumarcc5f9172020-06-10 13:34:31 +00001224 if [ "$WITH_TRACING" == "yes" ]; then
1225 EXPECT+=" tracing"
1226 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001227 if [ "$WITH_OPEN_ADAPTERS" == "yes" ]; then
David Bainbridge696bc632020-04-05 21:49:37 -07001228 EXPECT+=" open-olt open-onu"
1229 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001230 if [ "$WITH_SIM_ADAPTERS" == "yes" ]; then
David Bainbridge696bc632020-04-05 21:49:37 -07001231 EXPECT+=" sim"
1232 fi
David Bainbridgec7220622020-05-28 12:31:47 -07001233 if is_in "$WITH_ETCD" "yes,external"; then
1234 EXPECT+=" etcd"
David Bainbridge76afd812020-04-06 09:53:52 -07001235 fi
David Bainbridgec7220622020-05-28 12:31:47 -07001236 if is_in "$WITH_KAFKA" "yes,external"; then
David Bainbridge76afd812020-04-06 09:53:52 -07001237 EXPECT+=" kafka"
1238 fi
David Bainbridge0774b232019-08-02 06:37:19 +00001239 bspin "Remove Helm Deployments"
David Bainbridgeac7f8072019-08-01 22:15:33 +00001240 for i in $EXISTS; do
David K. Bainbridge43422402020-03-06 07:41:22 -08001241 for j in $EXPECT; do
David Bainbridged18f4942020-04-14 16:46:13 -07001242 if [[ "$i" =~ $j ]]; then
David Bainbridgeb4bbde12020-06-25 14:46:36 -07001243 __NAME=$(echo "$i" | cut -d, -f1)
1244 __NS=$(echo "$i" | cut -d, -f2)
1245 sspin "Remove Helm Deployments: $__NS:$__NAME$CEOL"
1246 if [ "$HELM_MAJOR" -le 2 ]; then
1247 (set -x; helm delete --no-hooks --purge "$__NAME" >>"$LOG" 2>&1) >>"$LOG" 2>&1
1248 else
1249 (set -x; helm uninstall --no-hooks --namespace "$__NS" "$__NAME" >>"$LOG" 2>&1) >>"$LOG" 2>&1
1250 fi
David K. Bainbridge43422402020-03-06 07:41:22 -08001251 fi
1252 done
uottrembb16d3982020-02-28 08:34:36 +01001253 done
David Bainbridge0774b232019-08-02 06:37:19 +00001254 espin "$VERIFIED Remove Helm Deployments$CEOL"
David Bainbridge4f1b5562019-08-19 04:46:52 +00001255 if [ "$WAIT_ON_DOWN" == "yes" ]; then
Matteo Scandoloe93c9eb2020-06-03 12:08:51 -07001256 PODS="voltha-ofagent.* voltha-rw-core.*"
David Bainbridge76afd812020-04-06 09:53:52 -07001257 INFRA_PODS=
1258 ADAPT_PODS=
1259 SIM_PODS=
divyadesai59f987a2020-05-27 12:11:33 +00001260 EFK_PODS=
David Bainbridged18f4942020-04-14 16:46:13 -07001261 if [ "$WITH_RADIUS" == "yes" ]; then
David Bainbridge696bc632020-04-05 21:49:37 -07001262 PODS+=" radius.*"
1263 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001264 if [ "$WITH_BBSIM" == "yes" ]; then
David Bainbridge76afd812020-04-06 09:53:52 -07001265 SIM_PODS+=" bbsim.*"
David Bainbridge696bc632020-04-05 21:49:37 -07001266 fi
divyadesai59f987a2020-05-27 12:11:33 +00001267 if [ "$WITH_EFK" == "yes" ]; then
1268 EFK_PODS+=" kibana-* elasticsearch-* fluentd-*"
1269 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001270 if [ "$WITH_OPEN_ADAPTERS" ] || [ "$WITH_SIM_ADAPTERS" ]; then
David Bainbridge76afd812020-04-06 09:53:52 -07001271 ADAPT_PODS+=" adapter-*"
David Bainbridge696bc632020-04-05 21:49:37 -07001272 fi
Girish Kumarcc5f9172020-06-10 13:34:31 +00001273 if [ "$WITH_TRACING" == "yes" ]; then
1274 INFRA_PODS+=" jaeger.*"
1275 fi
David Bainbridge60ffc0f2020-04-27 22:13:22 -07001276 if is_in "$WITH_ONOS" "yes,legacy,classic"; then
David Bainbridge76afd812020-04-06 09:53:52 -07001277 INFRA_PODS+=" onos-.*"
1278 fi
David Bainbridgec7220622020-05-28 12:31:47 -07001279 if is_in "$WITH_ETCD" "yes,external"; then
1280 INFRA_PODS+=" etcd.*"
David Bainbridge76afd812020-04-06 09:53:52 -07001281 fi
David Bainbridgec7220622020-05-28 12:31:47 -07001282 if is_in "$WITH_KAFKA" "yes,external"; then
David Bainbridge76afd812020-04-06 09:53:52 -07001283 INFRA_PODS+=" kafka.*"
1284 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001285 if [ -n "$SIM_PODS" ]; then
1286 wait_for_pods "$BBSIM_NS" 0 "not" "Waiting for BBSIM PODs to terminate" "$BBSIM_LABEL" "$SIM_PODS"
David Bainbridge76afd812020-04-06 09:53:52 -07001287 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001288 if [ -n "$INFRA_PODS" ]; then
1289 wait_for_pods "$INFRA_NS" 0 "not" "Waiting for infrastructure PODs to terminate" "$NO_LABEL" "$INFRA_PODS"
David Bainbridge76afd812020-04-06 09:53:52 -07001290 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001291 if [ -n "$ADAPT_PODS" ]; then
1292 wait_for_pods "$ADAPTER_NS" 0 "not" "Waiting for adapter PODs to terminate" "$NO_LABEL" "$ADAPT_PODS"
David Bainbridge76afd812020-04-06 09:53:52 -07001293 fi
divyadesai59f987a2020-05-27 12:11:33 +00001294 if [ -n "$EFK_PODS" ]; then
1295 wait_for_pods "$INFRA_NS" 0 "not" "Waiting for EFK PODs to terminate" "$NO_LABEL" "$EFK_PODS"
1296 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001297 wait_for_pods "$VOLTHA_NS" 0 "not" "Waiting for VOLTHA PODs to terminate" "$NO_LABEL" "$PODS"
David Bainbridge4f1b5562019-08-19 04:46:52 +00001298 fi
David Bainbridgeac7f8072019-08-01 22:15:33 +00001299 fi
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001300 exit
David Bainbridgeac7f8072019-08-01 22:15:33 +00001301fi
1302
1303if [ "$1" == "dump" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +00001304 LOG="dump-$NAME.log"
David Bainbridged18f4942020-04-14 16:46:13 -07001305 TS="$(date -u +"%Y%m%dT%H%M%SZ")"
1306 if [ -n "$DUMP_FROM" ]; then
1307 TS=${DUMP_FROM//[:-]}
David Bainbridge76514a02019-10-08 01:50:35 +00001308 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001309 WORK="$(mktemp -u -d)"
David Bainbridge0774b232019-08-02 06:37:19 +00001310 DATA=$WORK/voltha-debug-dump-$NAME-$TS
David Bainbridged18f4942020-04-14 16:46:13 -07001311 mkdir -p "$DATA"
1312 echo "$TS" > "$LOG"
David Bainbridge0774b232019-08-02 06:37:19 +00001313 echo -e "Capturing debug dump to voltha-debug-dump-$NAME-$TS.tgz"
David Bainbridgeac7f8072019-08-01 22:15:33 +00001314 bspin - "Copy install log"
David Bainbridged18f4942020-04-14 16:46:13 -07001315 if [ -f "install-$NAME.log" ]; then
1316 (set -x; cp "install-$NAME.log" "$DATA/install-$NAME.log") >>"$LOG" 2>&1
1317 espin - "$VERIFIED"
David Bainbridgeac7f8072019-08-01 22:15:33 +00001318 else
David Bainbridge0774b232019-08-02 06:37:19 +00001319 espin - "$NO_ENTRY Copy install log: install-$NAME.log not found"
David Bainbridgeac7f8072019-08-01 22:15:33 +00001320 fi
1321 bspin - "Dumping Kubernetes PODs"
David Bainbridged18f4942020-04-14 16:46:13 -07001322 (set -x; kubectl get --all-namespaces pods >> "$DATA/all-pods.txt" 2>&1) >>"$LOG" 2>&1
1323 espin - "$VERIFIED"
David Bainbridgeac7f8072019-08-01 22:15:33 +00001324 bspin - "Dumping Kubernetes SERVICEs"
David Bainbridged18f4942020-04-14 16:46:13 -07001325 (set -x; kubectl get --all-namespaces svc >> "$DATA/all-services.txt" 2>&1) >>"$LOG" 2>&1
1326 espin - "$VERIFIED"
David Bainbridgeac7f8072019-08-01 22:15:33 +00001327 bspin - "Dumping Kubernetes EVENTs"
David Bainbridged18f4942020-04-14 16:46:13 -07001328 (set -x; kubectl get --all-namespaces events >> "$DATA/all-events.txt" 2>&1) >>"$LOG" 2>&1
1329 espin - "$VERIFIED"
David Bainbridgeac7f8072019-08-01 22:15:33 +00001330 bspin - "Dumping VOLTHA POD details"
David Bainbridged18f4942020-04-14 16:46:13 -07001331 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 +00001332 SINCE=
David Bainbridged18f4942020-04-14 16:46:13 -07001333 if [ -n "$DUMP_FROM" ]; then
David Bainbridgecfd7ca12019-10-06 03:31:41 +00001334 SINCE="--since-time=$DUMP_FROM"
1335 fi
David Bainbridgeac7f8072019-08-01 22:15:33 +00001336 for POD in $PODS; do
David Bainbridged18f4942020-04-14 16:46:13 -07001337 NS="$(echo "$POD" | cut -d: -f1)"
1338 POD="$(echo "$POD" | cut -d: -f2)"
David Bainbridgeac7f8072019-08-01 22:15:33 +00001339 sspin - "Dumping VOLTHA POD details: $POD$CEOL"
David Bainbridged18f4942020-04-14 16:46:13 -07001340 mkdir -p "$DATA/$POD"
1341 (set -x; kubectl describe -n "$NS" "$POD" >> "$DATA/$POD/describe.txt" 2>&1) >>"$LOG" 2>&1
David Bainbridgeac7f8072019-08-01 22:15:33 +00001342 sspin - "Dumping VOLTHA POD details: $POD"
David Bainbridged18f4942020-04-14 16:46:13 -07001343 (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 +00001344 sspin - "Dumping VOLTHA POD details: $POD"
David Bainbridged18f4942020-04-14 16:46:13 -07001345 (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 +00001346 sspin - "Dumping VOLTHA POD details: $POD"
1347 done
1348 espin - "$VERIFIED Dumping VOLTHA POD details$CEOL"
1349 bspin - "Dumping ETCD"
David Bainbridged18f4942020-04-14 16:46:13 -07001350 if [ -n "$(command -v etcdctl)" ]; then
1351 (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
1352 espin - "$VERIFIED"
David Bainbridgeac7f8072019-08-01 22:15:33 +00001353 else
1354 espin - "$NO_ENTRY Dumping ETCD: etcdctl command not available"
1355 fi
David Bainbridge0774b232019-08-02 06:37:19 +00001356 bspin - "Creating compressed TAR: voltha-debug-dump-$NAME-$TS.tgz"
David Bainbridged18f4942020-04-14 16:46:13 -07001357 (set -x; tar -C "$WORK" -zcf "voltha-debug-dump-$NAME-$TS.tgz" "./voltha-debug-dump-$NAME-$TS") >>"$LOG" 2>&1
1358 espin - "$VERIFIED"
David Bainbridgeac7f8072019-08-01 22:15:33 +00001359 bspin - "Cleanup"
David Bainbridged18f4942020-04-14 16:46:13 -07001360 (set -x; rm -rf "$WORK") >>"$LOG" 2>&1
1361 espin - "$VERIFIED"
1362 bspin - "$(ls -l "voltha-debug-dump-$NAME-$TS.tgz")"
1363 espin - "$VERIFIED"
David Bainbridgeac7f8072019-08-01 22:15:33 +00001364 exit
1365fi
1366
David Bainbridge0774b232019-08-02 06:37:19 +00001367LOG="install-$NAME.log"
David Bainbridge1d2c5842020-06-03 15:29:07 -07001368PFLOG="port-forward-$NAME.log"
David Bainbridged18f4942020-04-14 16:46:13 -07001369date > "$LOG"
Girish Kumarcc5f9172020-06-10 13:34:31 +00001370echo "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 +00001371
1372# Output install options to log
David Bainbridged18f4942020-04-14 16:46:13 -07001373echo "OPTIONS" >> "$LOG"
David Bainbridgeac7f8072019-08-01 22:15:33 +00001374for O in $ALL_OPTIONS; do
David Bainbridged18f4942020-04-14 16:46:13 -07001375 VAL="$(eval echo "\$$O")"
1376 if [ -n "$VAL" ]; then
1377 printf " %-30s = %s\n" "$O" "$VAL" >> "$LOG"
David Bainbridgeac7f8072019-08-01 22:15:33 +00001378 fi
1379done
1380
Matteo Scandoloe89384a2020-11-06 08:40:25 -08001381# Remove everything we created and set
David Bainbridgee4d11ca2020-05-08 10:21:10 -07001382if [ "$1" == "clean" ]; then
Matteo Scandoloe89384a2020-11-06 08:40:25 -08001383 echo "Cleaning up the system"
1384 kill_port_forward all-namespaces __ALL__
David Bainbridgee4d11ca2020-05-08 10:21:10 -07001385 exit
1386fi
1387
David Bainbridgefad50732020-05-01 17:00:12 -07001388helm_values() {
1389 local NAMESPACE=$1; shift
1390 local INAME=$1; shift
1391 local CHART=$1; shift
1392 local CHART_VERSION=$1; shift
1393
1394 if [ "$CHART_VERSION X" != " X" ] && [ "$CHART_VERSION" != "latest" ]; then
1395 CHART_VERSION="--version $CHART_VERSION"
1396 else
1397 CHART_VERSION=
1398 fi
1399
1400 local CHART_ARGS=
1401 if [ -r "${INAME}-values.yaml" ]; then
1402 CHART_ARGS="-f ${INAME}-values.yaml"
1403 fi
1404
1405 if [ "$HELM_USE_UPGRADE" == "yes" ]; then
1406 _HELM_COMMAND="upgrade --install"
1407 _HELM_ARGS="xxxdryrunxxx"
1408 else
1409 _HELM_COMMAND="install"
Matteo Scandolof2d080b2020-07-23 13:59:29 -07001410 if [ "$HELM_MAJOR" -le 2 ]; then
1411 _HELM_NAME_ARG="--name xxxdryrunxxx"
1412 _HELM_ARGS=
1413 else
1414 _HELM_NAME_ARG="xxxdryrunxxx"
1415 _HELM_ARGS="--create-namespace"
1416 fi
David Bainbridgefad50732020-05-01 17:00:12 -07001417 fi
Matteo Scandolo657e13c2020-07-28 11:41:42 -07001418 CMD=("helm $_HELM_COMMAND --debug --dry-run -f values.yaml $CHART_ARGS $INTERNAL_EXTRA_HELM_INSTALL_ARGS $EXTRA_HELM_INSTALL_ARGS --set defaults.log_level=$VOLTHA_LOG_LEVEL --namespace $NAMESPACE $_HELM_ARGS $CHART_VERSION $EXTRA_HELM_FLAGS $_HELM_NAME_ARG $CHART")
David Bainbridgefad50732020-05-01 17:00:12 -07001419 ${CMD[*]} 2>/dev/null | awk 'PRINT==1 {print}; /^USER-SUPPLIED VALUES:/ {PRINT = 1}; /^$/ {PRINT = 0}'
1420}
1421
David Bainbridgeb4bbde12020-06-25 14:46:36 -07001422helm_is_deployed() {
1423 local NAMESPACE=$1; shift
1424 local NAME=$1; shift
1425
1426 if [ "$HELM_MAJOR" -le 2 ]; then
1427 helm list --deployed --short --namespace "$NAMESPACE" "$NAME" 2>/dev/null | wc -l
1428 else
1429 helm list --deployed --short --namespace "$NAMESPACE" --filter "$NAME" 2>/dev/null | wc -l
1430 fi
1431}
1432
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001433helm_install() {
David Bainbridgec7220622020-05-28 12:31:47 -07001434 local INDENT NOW VALUES_FILE PPROF_ARG
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001435 if [ "$1" == "-" ]; then
1436 INDENT=$1; shift
1437 fi
1438 local NAMESPACE=$1; shift
David Bainbridge0774b232019-08-02 06:37:19 +00001439 local INAME=$1; shift
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001440 local CHART=$1; shift
David Bainbridge90fd8e32019-08-21 23:32:47 +00001441 local CHART_VERSION=$1; shift
David Bainbridgec7220622020-05-28 12:31:47 -07001442 local FILTER=$1; shift
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001443 local MESSAGE=$*
1444
David Bainbridged18f4942020-04-14 16:46:13 -07001445 if [ "$CHART_VERSION X" != " X" ] && [ "$CHART_VERSION" != "latest" ]; then
David Bainbridge90fd8e32019-08-21 23:32:47 +00001446 CHART_VERSION="--version $CHART_VERSION"
1447 else
1448 CHART_VERSION=
1449 fi
1450
David Bainbridge99ac7a22019-08-31 02:26:43 +00001451 local CHART_ARGS=
1452 if [ -r "${INAME}-values.yaml" ]; then
1453 CHART_ARGS="-f ${INAME}-values.yaml"
1454 fi
1455
David Bainbridged18f4942020-04-14 16:46:13 -07001456 local WAIT_START CMD
1457 WAIT_START="$(date +%s)"
1458 COUNT="$((300 / 15))"
1459 bspin "$INDENT" "$MESSAGE"
1460 if [ "$HELM_USE_UPGRADE" == "yes" ]; then
David Bainbridge7f8bf992020-04-08 21:53:22 -07001461 _HELM_COMMAND="upgrade --install"
David Bainbridgeb4bbde12020-06-25 14:46:36 -07001462 _HELM_NAME_ARG="$INAME"
David Bainbridge7f8bf992020-04-08 21:53:22 -07001463 else
1464 _HELM_COMMAND="install"
David Bainbridgeb4bbde12020-06-25 14:46:36 -07001465 if [ "$HELM_MAJOR" -le 2 ]; then
1466 _HELM_NAME_ARG="--name $INAME"
1467 _HELM_ARGS=
1468 else
1469 _HELM_NAME_ARG="$INAME"
1470 _HELM_ARGS="--create-namespace"
1471 fi
David Bainbridge7f8bf992020-04-08 21:53:22 -07001472 fi
David Bainbridgec7220622020-05-28 12:31:47 -07001473
1474 VALUES_FILE="$(mktemp)"
1475 if [ "$FILTER" == "-" ]; then
Matteo Scandolo657e13c2020-07-28 11:41:42 -07001476 cp "values.yaml" "$VALUES_FILE"
David Bainbridgea965ca22020-06-09 17:45:04 -07001477 elif [ "${FILTER:0:1}" == "+" ]; then
Matteo Scandolo657e13c2020-07-28 11:41:42 -07001478 cp "values.yaml" "$VALUES_FILE"
1479 yq r - "${FILTER:1}" <"values.yaml" >>"$VALUES_FILE"
David Bainbridge33e56c72020-06-11 11:39:56 -07001480 cat "$VALUES_FILE" >>"$LOG"
David Bainbridgec7220622020-05-28 12:31:47 -07001481 else
Matteo Scandolo657e13c2020-07-28 11:41:42 -07001482 yq r - "$FILTER" <"values.yaml" >"$VALUES_FILE"
David Bainbridgec7220622020-05-28 12:31:47 -07001483 fi
1484 if [ "$WITH_PPROF" == "yes" ]; then
1485 PPROF_ARG="--set profiler.enabled=true"
1486 fi
David Bainbridgeb4bbde12020-06-25 14:46:36 -07001487 CMD=("helm $_HELM_COMMAND -f $VALUES_FILE $_HELM_ARGS $CHART_ARGS $PPROF_ARG $INTERNAL_EXTRA_HELM_INSTALL_ARGS $EXTRA_HELM_INSTALL_ARGS --set defaults.log_level=$VOLTHA_LOG_LEVEL --namespace $NAMESPACE $CHART_VERSION $EXTRA_HELM_FLAGS $_HELM_NAME_ARG $CHART")
David Bainbridged18f4942020-04-14 16:46:13 -07001488 (set -x; ${CMD[*]} >>"$LOG" 2>&1) >>"$LOG" 2>&1
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001489 SUCCESS=$?
David Bainbridged18f4942020-04-14 16:46:13 -07001490 while [ "$SUCCESS" -ne 0 ]; do
1491 NOW="$(date +%s)"
1492 if [ "$((NOW - WAIT_START))" -gt "$TIMEOUT_SECONDS" ]; then
David Bainbridge52e6e9d2020-03-23 13:48:27 -07001493 espin "$THEX"
David Bainbridgec7220622020-05-28 12:31:47 -07001494 rm -f "$VALUES_FILE"
David Bainbridge52e6e9d2020-03-23 13:48:27 -07001495 doTimeout "waiting for helm install $CHART"
1496 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001497 sspin "$INDENT"
1498 COUNT="$((COUNT - 1))"
1499 if [ "$COUNT" -eq 0 ]; then
1500 if [ "$HELM_USE_UPGRADE" == "no" ]; then
David Bainbridgeb4bbde12020-06-25 14:46:36 -07001501 if [ "$HELM_MAJOR" -le 2 ]; then
1502 (set -x; helm delete --purge "$INAME" >>"$LOG" 2>&1) >>"$LOG" 2>&1
1503 else
1504 (set -x; helm uninstall "$INAME" >>"$LOG" 2>&1) >>"$LOG" 2>&1
1505 fi
David Bainbridge7f8bf992020-04-08 21:53:22 -07001506 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001507 (set -x; ${CMD[*]} >>"$LOG" 2>&1) >>"$LOG" 2>&1
Andy Baviere22ff252019-12-19 11:40:31 -07001508 SUCCESS=$?
David Bainbridged18f4942020-04-14 16:46:13 -07001509 COUNT="$((300 / 15))"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001510 fi
1511 sleep .15
1512 done
David Bainbridgec7220622020-05-28 12:31:47 -07001513 rm -f "$VALUES_FILE"
David Bainbridged18f4942020-04-14 16:46:13 -07001514 espin "$INDENT" "$VERIFIED"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001515}
1516
Matteo Scandoloe89384a2020-11-06 08:40:25 -08001517bspin "Installing VOLTHA: $NAME $GEAR"
1518espin "$VERIFIED"
Matteo Scandolo657e13c2020-07-28 11:41:42 -07001519echo "INSTALL NAME: $NAME" >> "$LOG"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001520
David Bainbridged18f4942020-04-14 16:46:13 -07001521STIME="$(date +%s)"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001522if [ "$INSTALL_KUBECTL" == "no" ]; then
1523 bspin "Skip kubectl install"
1524 espin $NO_ENTRY
Test Userc13bdc92019-07-03 20:57:49 +00001525else
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001526 bspin "Verify kubectl $HELM"
David Bainbridged18f4942020-04-14 16:46:13 -07001527 if [ -x "$GOPATH/bin/kubectl" ]; then
1528 espin "$VERIFIED"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001529 else
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001530 ERR_OUT="$(mktemp)"
David Bainbridged18f4942020-04-14 16:46:13 -07001531 espin "$NOT_VERIFIED"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001532 bspin - "Download and install Kubernetes/kubectl $DOWNLOAD"
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001533 (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
1534 RESULT=$?
1535 if [ "$RESULT" -ne 0 ]; then
1536 espin - "$THEX"
David Bainbridgee3fc0c32020-04-21 15:34:04 -07001537 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR: unable to download kubectl: $(tail "$ERR_OUT")${NORMAL}"
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001538 cat "$ERR_OUT" >> "$LOG"
Zack Williamsded60cb2020-04-13 10:02:20 -07001539 rm -rf "$ERR_OUT" "$GOPATH/bin/kubectl"
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001540 exit 1
1541 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001542 (set -x; chmod 755 "$GOPATH/bin/kubectl" >>"$LOG" 2>&1) >>"$LOG" 2>&1
1543 espin - "$VERIFIED"
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001544 rm -rf "$ERR_OUT"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001545 fi
Test Userc13bdc92019-07-03 20:57:49 +00001546fi
David Bainbridgee87067b2019-08-12 22:00:12 +00001547if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001548 NOW="$(date +%s)"
1549 printtime $((NOW - STIME))
David Bainbridgee87067b2019-08-12 22:00:12 +00001550fi
Test Userc13bdc92019-07-03 20:57:49 +00001551
David Bainbridged18f4942020-04-14 16:46:13 -07001552STIME="$(date +%s)"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001553if [ "$DEPLOY_K8S" == "no" ]; then
1554 bspin "Skip Kubernetes/Kind Deployment"
1555 espin $NO_ENTRY
1556else
Test Userba1e7e72019-07-10 22:27:54 +00001557 bspin "Verify Kubernetes/Kind $HELM"
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -08001558 IS_INSTALLED=0
1559 OP_TYPE="install"
David Bainbridged18f4942020-04-14 16:46:13 -07001560 if [ -x "$GOPATH/bin/kind" ]; then
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -08001561 OP_TYPE="upgrade"
David Bainbridgeb4bbde12020-06-25 14:46:36 -07001562 if [ "$("$GOPATH/bin/kind" version | grep -c "$KIND_VERSION")" -eq 1 ]; then
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -08001563 IS_INSTALLED=1
David Bainbridged18f4942020-04-14 16:46:13 -07001564 espin "$VERIFIED"
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -08001565 fi
1566 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001567 if [ "$IS_INSTALLED" -eq 0 ]; then
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001568 ERR_OUT="$(mktemp)"
David Bainbridged18f4942020-04-14 16:46:13 -07001569 espin "$NOT_VERIFIED"
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -08001570 bspin - "Download and $OP_TYPE Kubernetes/kind $DOWNLOAD"
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001571 (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
1572 RESULT=$?
1573 if [ $RESULT -ne 0 ]; then
1574 espin - "$THEX"
David Bainbridgee3fc0c32020-04-21 15:34:04 -07001575 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR: unable to download kind: $(tail "$ERR_OUT")${NORMAL}"
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001576 cat "$ERR_OUT" >> "$LOG"
Zack Williamsded60cb2020-04-13 10:02:20 -07001577 rm -rf "$ERR_OUT" "$GOPATH/bin/kind"
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001578 exit 1
1579 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001580 (set -x; chmod 755 "$GOPATH/bin/kind" >>"$LOG" 2>&1) >>"$LOG" 2>&1
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001581 rm -rf "$ERR_OUT"
David Bainbridged18f4942020-04-14 16:46:13 -07001582 espin - "$VERIFIED"
Test Userba1e7e72019-07-10 22:27:54 +00001583 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001584fi
1585
David Bainbridgee87067b2019-08-12 22:00:12 +00001586if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001587 NOW="$(date +%s)"
1588 printtime $((NOW - STIME))
David Bainbridgee87067b2019-08-12 22:00:12 +00001589fi
1590
David Bainbridged18f4942020-04-14 16:46:13 -07001591STIME="$(date +%s)"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001592if [ "$INSTALL_HELM" == "no" ]; then
1593 bspin "Skip Helm Install"
1594 espin $NO_ENTRY
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001595else
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001596 bspin "Verify Helm $HELM"
David Bainbridgea34993d2020-04-01 09:15:42 -07001597 HELM_UPGRADE=0
1598 HELM_UPGRADE_DESC="install"
David Bainbridged18f4942020-04-14 16:46:13 -07001599 if [ -x "$GOPATH/bin/helm" ]; then
David Bainbridgeb4bbde12020-06-25 14:46:36 -07001600 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 -07001601 HELM_UP_DOWN="$(echo -e "$HAVE_VER\n$HELM_VERSION" | sort -V | head -1)"
1602 if [ "$HAVE_VER" != "$HELM_VERSION" ]; then
1603 if [ "$HELM_UP_DOWN" == "$HELM_VERSION" ]; then
David Bainbridgea34993d2020-04-01 09:15:42 -07001604 HELM_UPGRADE_DESC="downgrade"
1605 else
1606 HELM_UPGRADE_DESC="upgrade"
1607 fi
1608 HELM_UPGRADE=1
1609 else
David Bainbridged18f4942020-04-14 16:46:13 -07001610 espin "$VERIFIED"
David Bainbridgea34993d2020-04-01 09:15:42 -07001611 fi
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001612 else
David Bainbridgea34993d2020-04-01 09:15:42 -07001613 HELM_UPGRADE=1
1614 fi
1615
David Bainbridged18f4942020-04-14 16:46:13 -07001616 if [ "$HELM_UPGRADE" -ne 0 ]; then
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001617 ERR_OUT="$(mktemp)"
1618 INSTALL_HELM_BIN=$(mktemp)
David Bainbridged18f4942020-04-14 16:46:13 -07001619 espin "$NOT_VERIFIED"
David Bainbridgea34993d2020-04-01 09:15:42 -07001620 bspin - "Download and $HELM_UPGRADE_DESC Helm $DOWNLOAD"
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001621 (set -x; curl -o "$INSTALL_HELM_BIN" --fail -sSL https://git.io/get_helm.sh >>"$LOG" 2>"$ERR_OUT") >>"$LOG" 2>&1
1622 RESULT=$?
1623 if [ $RESULT -ne 0 ]; then
1624 espin - "$THEX"
David Bainbridgee3fc0c32020-04-21 15:34:04 -07001625 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR: unable to download helm installer: $(tail "$ERR_OUT")${NORMAL}"
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001626 cat "$ERR_OUT" >> "$LOG"
1627 rm -rf "$INSTALL_HELM_BIN" "$ERR_OUT" "$GOPATH/bin/helm" "$GOPATH/bin/tiller"
1628 exit 1
1629 fi
1630 rm -rf "$ERR_OUT"
1631 chmod +x "$INSTALL_HELM_BIN"
1632 (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
1633 RESULT=$?
1634 if [ $RESULT -ne 0 ]; then
1635 espin - "$THEX"
1636 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR: unable to install helm, see install log for details${NORMAL}"
1637 rm -rf "$INSTALL_HELM_BIN" "$ERR_OUT" "$GOPATH/bin/helm" "$GOPATH/bin/tiller"
1638 exit 1
1639 fi
1640 rm -rf "$INSTALL_HELM_BIN" "$ERR_OUT"
David Bainbridged18f4942020-04-14 16:46:13 -07001641 espin - "$VERIFIED"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001642 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001643fi
David Bainbridgee87067b2019-08-12 22:00:12 +00001644if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001645 NOW="$(date +%s)"
1646 printtime $((NOW - STIME))
David Bainbridgee87067b2019-08-12 22:00:12 +00001647fi
David Bainbridgeb4bbde12020-06-25 14:46:36 -07001648HELM_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 -07001649
David Bainbridged18f4942020-04-14 16:46:13 -07001650STIME="$(date +%s)"
Test Userb5712372019-07-03 21:52:17 +00001651bspin "Verify voltctl $HIGH_VOLTAGE"
David Bainbridged2811972019-12-14 01:14:09 +00001652VOK=0
1653VMESSAGE="install"
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001654ERR_OUT=$(mktemp)
David K. Bainbridgeebf38d92020-02-10 10:46:31 -08001655export VC_VERSION="$VOLTCTL_VERSION"
1656if [ "$VC_VERSION" == "latest" ]; then
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001657 set -o pipefail # TODO: would be nice to run all in pipefail mode
1658 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')"
1659 RESULT=$?
1660 set +o pipefail
1661 if [ "$RESULT" -ne 0 ]; then
1662 espin - "$THEX"
1663 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR: unable to determine released version of voltctl: $(cat "$ERR_OUT")${NORMAL}"
1664 rm -rf "$ERR_OUT" "$GOPATH/bin/voltctl"
1665 exit 1
1666 fi
1667 export VC_VERSION
David K. Bainbridgeebf38d92020-02-10 10:46:31 -08001668fi
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001669
David Bainbridged18f4942020-04-14 16:46:13 -07001670if [ -x "$GOPATH/bin/voltctl" ]; then
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001671 VHAVE="$("$GOPATH/bin/voltctl" version --clientonly -o json 2>/dev/null | jq -r .version)"
David Bainbridged18f4942020-04-14 16:46:13 -07001672 RESULT=$?
1673 if [ $RESULT -eq 0 ] && [ "$VHAVE" == "$VC_VERSION" ]; then
David Bainbridged2811972019-12-14 01:14:09 +00001674 VOK=1
David Bainbridged18f4942020-04-14 16:46:13 -07001675 espin "$VERIFIED"
David Bainbridge1ba64f12019-12-18 00:40:13 +00001676 else
David Bainbridged18f4942020-04-14 16:46:13 -07001677 VCHECK="$(echo -e "$VHAVE\n$VC_VERSION" | sort -V | head -1)"
David K. Bainbridgeebf38d92020-02-10 10:46:31 -08001678 if [ "$VCHECK" == "$VHAVE" ]; then
1679 VMESSAGE="upgrade"
1680 else
1681 VMESSAGE="downgrade"
1682 fi
David Bainbridged2811972019-12-14 01:14:09 +00001683 fi
1684fi
1685
David Bainbridged18f4942020-04-14 16:46:13 -07001686if [ "$VOK" -eq 0 ]; then
1687 espin "$NOT_VERIFIED"
David Bainbridged2811972019-12-14 01:14:09 +00001688 bspin - "Download and $VMESSAGE voltctl $DOWNLOAD"
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001689 (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
1690 RESULT=$?
1691 if [ $RESULT -ne 0 ]; then
1692 espin - "$THEX"
1693 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR: unable to download voltctl (version $VC_VERSION): $(cat "$ERR_OUT")${NORMAL}"
1694 rm -rf "$ERR_OUT" "$GOPATH/bin/voltctl"
1695 exit 1
1696 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001697 (set -x; chmod 755 "$GOPATH/bin/voltctl" >>"$LOG" 2>&1) >>"$LOG" 2>&1
1698 espin - "$VERIFIED"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001699fi
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001700rm -rf "$ERR_OUT"
David Bainbridgee87067b2019-08-12 22:00:12 +00001701if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001702 NOW="$(date +%s)"
1703 printtime $((NOW - STIME))
David Bainbridgee87067b2019-08-12 22:00:12 +00001704fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001705
1706bspin "Verify command PATH"
David Bainbridged18f4942020-04-14 16:46:13 -07001707espin "$VERIFIED"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001708
David Bainbridged18f4942020-04-14 16:46:13 -07001709STIME="$(date +%s)"
Test Userba1e7e72019-07-10 22:27:54 +00001710if [ "$DEPLOY_K8S" == "yes" ]; then
David Bainbridgeb4bbde12020-06-25 14:46:36 -07001711 HAVE="$(kind get clusters 2>/dev/null | grep -c "voltha-$NAME")"
Test Userba1e7e72019-07-10 22:27:54 +00001712 bspin "Verify Kubernetes/Kind Cluster"
1713 sspin
David Bainbridged18f4942020-04-14 16:46:13 -07001714 if [ "$HAVE" -eq 0 ]; then
1715 espin "$NOT_VERIFIED"
Andrea Campanella8a149192020-07-31 17:19:45 +02001716 FILE="$NAME-cluster.cfg"
David K. Bainbridge2aa08da2020-07-31 12:49:45 -07001717 if [ -n "$KIND_CFG_FILE" ]; then
1718 FILE="$KIND_CFG_FILE"
1719 else
1720 bspin - "Generating cluster configuration"
Andrea Campanelladd946472020-07-31 11:03:44 +02001721
David K. Bainbridge2aa08da2020-07-31 12:49:45 -07001722 if [ -f "$FILE" ] ; then
1723 rm "$FILE"
1724 fi
1725
1726 touch "$FILE"
1727
1728 yq w -i "$FILE" kind Cluster
1729 yq w -i "$FILE" apiVersion "kind.sigs.k8s.io/v1alpha3"
1730
1731 if [ ! "$NUM_OF_CONTROLLER_NODES" -eq 0 ]; then
1732 for instance in $(seq 1 "$NUM_OF_CONTROLLER_NODES"); do
1733 yq w -i "$FILE" "nodes[+].role" "control-plane"
1734 done
1735 fi
1736
1737 if [ ! "$NUM_OF_WORKER_NODES" -eq 0 ]; then
1738 for instance in $(seq 1 "$NUM_OF_WORKER_NODES"); do
1739 yq w -i "$FILE" "nodes[+].role" worker
1740 done
1741 fi
1742 espin - "$VERIFIED"
Andrea Campanelladd946472020-07-31 11:03:44 +02001743 fi
1744
Andrea Campanella8a149192020-07-31 17:19:45 +0200