blob: 581022db84dfe1d0f60cb99e71bb793d627477b4 [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
17TOTAL_START_TIME="$(date +%s)"
David K. Bainbridgeb7285432019-07-02 22:05:24 -070018
David Bainbridge38dc1e82019-08-12 15:18:45 +000019FANCY=${FANCY:-1}
20if [ "$TERM X" == " X" ]; then
21 FANCY=0
22fi
23
David K. Bainbridgeb7285432019-07-02 22:05:24 -070024# trap ctrl-c and call ctrl_c()
25trap ctrl_c INT
26
27function ctrl_c() {
David Bainbridged18f4942020-04-14 16:46:13 -070028 echo -en "$CNORM"
David K. Bainbridgeb7285432019-07-02 22:05:24 -070029 echo ""
30 echo "ctrl-c trapped"
David Bainbridgec6a6eb62019-10-18 22:50:07 +000031 echo "Thank you for trying 'voltha up'"
David K. Bainbridgeb7285432019-07-02 22:05:24 -070032 exit
33}
34
David Bainbridgea34993d2020-04-01 09:15:42 -070035HELM_VERSION=${HELM_VERSION:-v2.14.3}
David K. Bainbridgeebf38d92020-02-10 10:46:31 -080036VOLTCTL_VERSION=${VOLTCTL_VERSION:-latest}
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -080037KIND_VERSION=${KIND_VERSION:-v0.5.1}
David K. Bainbridgeb3a99372020-01-08 14:39:06 -080038VK_RELEASE=${VK_RELEASE:-master}
Test User08ebbd92019-07-03 17:15:39 +000039
David Bainbridge38dc1e82019-08-12 15:18:45 +000040RED=
41GREEN=
42YELLOW=
43BLUE=
David Bainbridge38dc1e82019-08-12 15:18:45 +000044BOLD=
45NORMAL=
46ERROR=
47CEOL=
48CNORM=
49CIVIS=
David Bainbridged18f4942020-04-14 16:46:13 -070050if [ "$FANCY" -eq 1 ]; then
51 RED="$(tput setaf 1)"
52 GREEN="$(tput setaf 2)"
53 YELLOW="$(tput setaf 3)"
54 BLUE="$(tput setaf 4)"
55 BOLD="$(tput bold)"
56 NORMAL="$(tput sgr0)"
David Bainbridge38dc1e82019-08-12 15:18:45 +000057 ERROR="\xe2\x9c\x97\x20"
David Bainbridged18f4942020-04-14 16:46:13 -070058 CEOL="$(tput el)"
59 CNORM="$(tput cnorm)"
60 CIVIS="$(tput civis)"
David Bainbridge38dc1e82019-08-12 15:18:45 +000061fi
Test User7d866122019-07-09 17:52:35 +000062
Test User3d7ad8e2019-07-03 06:15:44 +000063TYPE=${TYPE:-minimal}
David Bainbridge0774b232019-08-02 06:37:19 +000064NAME=${NAME:-$TYPE}
David K. Bainbridge484d80c2020-03-05 21:44:34 -080065
66ENABLE_ONOS_EXTRANEOUS_RULES=${ENABLE_ONOS_EXTRANEOUS_RULES:-no}
David Bainbridge76afd812020-04-06 09:53:52 -070067INFRA_NS=${INFRA_NS:-default}
68VOLTHA_NS=${VOLTHA_NS:-voltha}
69BBSIM_NS=${BBSIM_NS:-voltha}
70ADAPTER_NS=${ADAPTER_NS:-voltha}
David Bainbridgee87067b2019-08-12 22:00:12 +000071WITH_TIMINGS=${WITH_TIMINGS:-no}
Test User7d866122019-07-09 17:52:35 +000072WITH_BBSIM=${WITH_BBSIM:-no}
David Bainbridge5b7b96b2019-07-25 20:29:13 +000073WITH_RADIUS=${WITH_RADIUS:-no}
Matteo Scandolo78dfee02020-02-13 16:18:03 -080074WITH_EAPOL=${WITH_EAPOL:-yes}
75WITH_DHCP=${WITH_DHCP:-yes}
76WITH_IGMP=${WITH_IGMP:-no}
David Bainbridgeb270c202019-07-26 01:44:42 +000077WITH_ONOS=${WITH_ONOS:-yes}
David Bainbridge99ac7a22019-08-31 02:26:43 +000078WITH_CHAOS=${WITH_CHAOS:-no}
David Bainbridge46505fb2019-10-01 21:13:20 +000079WITH_ADAPTERS=${WITH_ADAPTERS:-yes}
David K. Bainbridgeda33d652020-03-06 10:31:23 -080080WITH_SIM_ADAPTERS=${WITH_SIM_ADAPTERS:-no}
David Bainbridge46505fb2019-10-01 21:13:20 +000081WITH_OPEN_ADAPTERS=${WITH_OPEN_ADAPTERS:-yes}
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -080082WITH_PORT_FORWARDS=${WITH_PORT_FORWARDS:-yes}
David Bainbridge696bc632020-04-05 21:49:37 -070083WITH_KAFKA=${WITH_KAFKA:-yes}
84WITH_ETCD=${WITH_ETCD:-yes}
David Bainbridge05cd8822019-11-19 17:43:53 +000085ONLY_ONE=${ONLY_ONE:-yes}
David K. Bainbridgeb859e912020-03-13 14:07:52 -070086CONFIG_SADIS=${CONFIG_SADIS:-no} # yes | no | file | bbsim | URL
David Bainbridge76afd812020-04-06 09:53:52 -070087SADIS_SUBSCRIBERS=${SADIS_SUBSCRIBERS:-http://bbsim.$VOLTHA_NS.svc:50074/v2/subscribers/%s}
88SADIS_BANDWIDTH_PROFILES=${SADIS_BANDWIDTH_PROFILES:-http://bbsim.$VOLTHA_NS.svc:50074/v2/bandwidthprofiles/%s}
Hardik Windlassb3147602020-03-09 16:59:15 +053089SADIS_CFG=${SADIS_CFG:-onos-files/onos-sadis-sample.json}
David Bainbridge27790d62019-08-13 22:43:19 +000090INSTALL_ONOS_APPS=${INSTALL_ONOS_APPS:-no}
Test Userba1e7e72019-07-10 22:27:54 +000091JUST_K8S=${JUST_K8S:-no}
92DEPLOY_K8S=${DEPLOY_K8S:-yes}
David K. Bainbridge0e89cb92019-07-17 11:30:10 -070093INSTALL_KUBECTL=${INSTALL_KUBECTL:-yes}
94INSTALL_HELM=${INSTALL_HELM:-yes}
David Bainbridge7f8bf992020-04-08 21:53:22 -070095HELM_USE_UPGRADE=${HELM_USE_UPGRADE:-no}
David Bainbridge46505fb2019-10-01 21:13:20 +000096UPDATE_HELM_REPOS=${UPDATE_HELM_REPOS:-yes}
Matteo Scandolofab98622020-01-28 15:17:20 -080097WAIT_ON_DOWN=${WAIT_ON_DOWN:-yes}
David Bainbridge52e6e9d2020-03-23 13:48:27 -070098WAIT_TIMEOUT=${WAIT_TIMEOUT:-30m}
99VOLTHA_DOWN_ON_TIMEOUT=${VOLTHA_DOWN_ON_TIMEOUT:-no}
David Bainbridge5b7b96b2019-07-25 20:29:13 +0000100VOLTHA_LOG_LEVEL=${VOLTHA_LOG_LEVEL:-WARN}
David Bainbridge90fd8e32019-08-21 23:32:47 +0000101VOLTHA_CHART=${VOLTHA_CHART:-onf/voltha}
102VOLTHA_CHART_VERSION=${VOLTHA_CHART_VERSION:-latest}
103VOLTHA_BBSIM_CHART=${VOLTHA_BBSIM_CHART:-onf/bbsim}
Matteo Scandolodcd29f52019-10-07 15:42:42 -0700104VOLTHA_BBSIM_CHART_VERSION=${VOLTHA_BBSIM_CHART_VERSION:-latest}
David Bainbridgee10f6d52019-07-25 00:28:13 +0000105VOLTHA_ADAPTER_SIM_CHART=${VOLTHA_ADAPTER_SIM_CHART:-onf/voltha-adapter-simulated}
David Bainbridge90fd8e32019-08-21 23:32:47 +0000106VOLTHA_ADAPTER_SIM_CHART_VERSION=${VOLTHA_ADAPTER_SIM_CHART_VERSION:-latest}
David Bainbridgee10f6d52019-07-25 00:28:13 +0000107VOLTHA_ADAPTER_OPEN_OLT_CHART=${VOLTHA_ADAPTER_OPEN_OLT_CHART:-onf/voltha-adapter-openolt}
David Bainbridge90fd8e32019-08-21 23:32:47 +0000108VOLTHA_ADAPTER_OPEN_OLT_CHART_VERSION=${VOLTHA_ADAPTER_OPEN_OLT_CHART_VERSION:-latest}
David Bainbridgee10f6d52019-07-25 00:28:13 +0000109VOLTHA_ADAPTER_OPEN_ONU_CHART=${VOLTHA_ADAPTER_OPEN_ONU_CHART:-onf/voltha-adapter-openonu}
David Bainbridge90fd8e32019-08-21 23:32:47 +0000110VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION=${VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION:-latest}
David K. Bainbridgeda33d652020-03-06 10:31:23 -0800111ONOS_CHART=${ONOS_CHART:-onf/onos}
Andrea Campanella21323292019-12-18 11:44:19 -0800112ONOS_CHART_VERSION=${ONOS_CHART_VERSION:-latest}
David Bainbridgecf546362020-04-21 23:18:50 -0700113KAFKA_CHART=${KAFKA_CHART:-incubator/kafka}
David Bainbridgeb9093522020-04-15 14:32:44 -0700114KAFKA_CHART_VERSION=${KAFKA_CHART_VERSION:=0.15.3}
David Bainbridge2eaf2cf2020-03-18 12:54:08 -0700115EXTRA_HELM_INSTALL_ARGS=${EXTRA_HELM_INSTALL_ARGS:-}
116INTERNAL_EXTRA_HELM_INSTALL_ARGS=
uottrembb16d3982020-02-28 08:34:36 +0100117NUM_OF_BBSIM=${NUM_OF_BBSIM:-1}
Matteo Scandolo67335f02020-04-09 11:19:53 -0700118NUM_OF_OPENONU=${NUM_OF_OPENONU:-1}
uottrembb16d3982020-02-28 08:34:36 +0100119MAX_NUM_OF_BBSIM=10
Matteo Scandolo67335f02020-04-09 11:19:53 -0700120MAX_NUM_OF_OPENONU=10
Test Userba1e7e72019-07-10 22:27:54 +0000121
David Bainbridged18f4942020-04-14 16:46:13 -0700122HOSTOS="$(uname -s | tr "[:upper:]" "[:lower:"])"
123HOSTARCH="$(uname -m | tr "[:upper:]" "[:lower:"])"
124if [ "$HOSTARCH" == "x86_64" ]; then
Test Userba1e7e72019-07-10 22:27:54 +0000125 HOSTARCH="amd64"
126fi
David Bainbridge7db44002020-04-09 12:54:29 -0700127BBSIM_LABEL="-l app=bbsim"
David Bainbridged18f4942020-04-14 16:46:13 -0700128NO_LABEL=
Test User7d866122019-07-09 17:52:35 +0000129
uottrembb16d3982020-02-28 08:34:36 +0100130# check number (range) of bbsim, max bbsim must not exceed 10 instances!
131# note: instances will be numbered from 0 to 9
132if [ "$1" == "up" ]; then
David K. Bainbridge43422402020-03-06 07:41:22 -0800133 if [ "$NUM_OF_BBSIM" -lt 1 ]; then
Matteo Scandolo67335f02020-04-09 11:19:53 -0700134 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} Invalid setting of BBSIM instances. NUM_OF_BBSIM (${NUM_OF_BBSIM}) is less than 1${NORMAL}"
David K. Bainbridge43422402020-03-06 07:41:22 -0800135 exit 1
136 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700137 if [ "$NUM_OF_BBSIM" -gt "$MAX_NUM_OF_BBSIM" ]; then
Matteo Scandolo67335f02020-04-09 11:19:53 -0700138 >&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}"
139 exit 1
140 fi
141
142 if [ "$NUM_OF_OPENONU" -lt 1 ]; then
143 >&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}"
144 exit 1
145 fi
146 if [ "$NUM_OF_OPENONU" -gt "$MAX_NUM_OF_OPENONU" ]; then
147 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} Invalid setting of OPENONU instances. NUM_OF_OPENONU (${NUM_OF_OPENONU}) is greater than $MAX_NUM_OF_OPENONU${NORMAL}"
David K. Bainbridge43422402020-03-06 07:41:22 -0800148 exit 1
149 fi
uottrembb16d3982020-02-28 08:34:36 +0100150fi
Test User7d866122019-07-09 17:52:35 +0000151# Verify TYPE setting
David Bainbridged18f4942020-04-14 16:46:13 -0700152if [ "$(echo ":minimal:full:" | grep -ic ":$TYPE:")" -eq 0 ]; then
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700153 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} Invalid \$TYPE value of '$TYPE'. Should be 'minimal' or 'full'${NORMAL}"
Test User7d866122019-07-09 17:52:35 +0000154 exit 1
155fi
156
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700157function parseDuration() {
David Bainbridged18f4942020-04-14 16:46:13 -0700158 local DUR RESULT TERM TERMS VALUE UNIT
159 DUR=$1
160 RESULT=0
161 TERMS="$(echo "$DUR" | sed -Ee 's/([sSmMhHdD])/\1 /g' -e 's/,$//g')"
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700162 for TERM in $TERMS; do
David Bainbridged18f4942020-04-14 16:46:13 -0700163 VALUE="$(echo "$TERM" | sed -Ee 's/([0-9]+)[sSmMhHdD]/\1/')"
164 UNIT="$(echo "$TERM" | sed -Ee 's/[0-9]+([sSmMhHdD])/\1/')"
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700165 case $UNIT in
166 s|S)
David Bainbridged18f4942020-04-14 16:46:13 -0700167 RESULT=$((RESULT + VALUE)) ;;
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700168 m|M)
David Bainbridged18f4942020-04-14 16:46:13 -0700169 RESULT=$((RESULT + (VALUE * 60))) ;;
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700170 h|H)
David Bainbridged18f4942020-04-14 16:46:13 -0700171 RESULT=$((RESULT + (VALUE * 3600))) ;;
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700172 d|D)
David Bainbridged18f4942020-04-14 16:46:13 -0700173 RESULT=$((RESULT + (VALUE * 86400))) ;;
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700174 *) ;;
175 esac
176 done
177 echo $RESULT
178}
179
180function doTimeout() {
181 local MSG=$1
182 2>&1 echo -e "\n${RED}${BOLD}${ERROR}TIMEOUT:${NORMAL}${RED} Operation timed out after '$WAIT_TIMEOUT': $MSG"
183 exit 125
184}
185
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -0800186function get_service_ep() {
187 local NS=$1
188 local NAME=$2
David Bainbridged18f4942020-04-14 16:46:13 -0700189 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 -0800190}
191
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000192# Used to verify configuration values are set to "yes" or "no" value or convert
193# equivalents to "yes" or "no"
194function verify_yes_no() {
David Bainbridged18f4942020-04-14 16:46:13 -0700195 local VAR VAL
196 VAR=$1
197 VAL="$(eval echo "\$$VAR")"
198 if [ "$(echo ":y:yes:true:n:no:false:1:0:" | grep -ic ":$VAL:")" -eq 0 ]; then
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000199 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} Invalid '$VAR' value of '$VAL'. Should be 'yes' or 'no'${NORMAL}"
200 echo "INVALID"
201 return 1
202 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700203 if [ "$(echo ":y:yes:true:1:" | grep -ic ":$VAL:")" -eq 1 ]; then
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000204 echo "yes"
205 else
206 echo "no"
207 fi
208 return 0
209}
Test User7d866122019-07-09 17:52:35 +0000210
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000211ALL_YES_NO="\
David K. Bainbridge484d80c2020-03-05 21:44:34 -0800212 ENABLE_ONOS_EXTRANEOUS_RULES \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000213 WITH_TIMINGS \
214 WITH_BBSIM \
Matteo Scandolo78dfee02020-02-13 16:18:03 -0800215 WITH_EAPOL \
216 WITH_DHCP \
217 WITH_IGMP \
David Bainbridge99ac7a22019-08-31 02:26:43 +0000218 WITH_CHAOS \
David Bainbridge46505fb2019-10-01 21:13:20 +0000219 WITH_ADAPTERS \
220 WITH_SIM_ADAPTERS \
221 WITH_OPEN_ADAPTERS \
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -0800222 WITH_PORT_FORWARDS \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000223 JUST_K8S \
224 DEPLOY_K8S \
225 INSTALL_ONOS_APPS \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000226 INSTALL_KUBECTL \
227 INSTALL_HELM \
David Bainbridge7f8bf992020-04-08 21:53:22 -0700228 HELM_USE_UPGRADE \
David Bainbridge46505fb2019-10-01 21:13:20 +0000229 UPDATE_HELM_REPOS \
David Bainbridge4f1b5562019-08-19 04:46:52 +0000230 WAIT_ON_DOWN \
David Bainbridge70c0ea82019-11-14 23:25:26 +0000231 ONLY_ONE \
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700232 VOLTHA_DOWN_ON_TIMEOUT \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000233 "
David Bainbridge5b7b96b2019-07-25 20:29:13 +0000234
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000235ALL_OPTIONS="\
236 NAME \
237 TYPE \
238 $ALL_YES_NO \
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700239 WAIT_TIMEOUT \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000240 VOLTHA_LOG_LEVEL \
241 VOLTHA_CHART \
David Bainbridge90fd8e32019-08-21 23:32:47 +0000242 VOLTHA_CHART_VERSION \
243 VOLTHA_BBSIM_CHART \
244 VOLTHA_BBSIM_CHART_VERSION \
uottrembd5a20572020-03-06 09:15:01 +0100245 NUM_OF_BBSIM \
Matteo Scandolo67335f02020-04-09 11:19:53 -0700246 NUM_OF_OPENONU \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000247 VOLTHA_ADAPTER_SIM_CHART \
David Bainbridge90fd8e32019-08-21 23:32:47 +0000248 VOLTHA_ADAPTER_SIM_CHART_VERSION \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000249 VOLTHA_ADAPTER_OPEN_OLT_CHART \
David Bainbridge90fd8e32019-08-21 23:32:47 +0000250 VOLTHA_ADAPTER_OPEN_OLT_CHART_VERSION \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000251 VOLTHA_ADAPTER_OPEN_ONU_CHART \
David Bainbridge90fd8e32019-08-21 23:32:47 +0000252 VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION \
David K. Bainbridgeda33d652020-03-06 10:31:23 -0800253 ONOS_CHART \
Andrea Campanella21323292019-12-18 11:44:19 -0800254 ONOS_CHART_VERSION \
David Bainbridgecf546362020-04-21 23:18:50 -0700255 KAFKA_CHART \
David Bainbridgeb9093522020-04-15 14:32:44 -0700256 KAFKA_CHART_VERSION \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000257 ONOS_API_PORT \
258 ONOS_SSH_PORT \
David K. Bainbridgeb859e912020-03-13 14:07:52 -0700259 CONFIG_SADIS \
Hardik Windlassb3147602020-03-09 16:59:15 +0530260 SADIS_CFG \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000261 VOLTHA_API_PORT \
262 VOLTHA_SSH_PORT \
263 VOLTHA_ETCD_PORT \
David K. Bainbridge00ecd382020-02-28 12:31:58 -0800264 VOLTHA_KAFKA_PORT \
David K. Bainbridge8f7f30b2020-01-08 13:06:16 -0800265 VK_RELEASE \
266 KIND_VERSION \
267 VOLTCTL_VERSION \
David Bainbridgea34993d2020-04-01 09:15:42 -0700268 HELM_VERSION \
David Bainbridge696bc632020-04-05 21:49:37 -0700269 WITH_RADIUS \
270 WITH_KAFKA \
271 WITH_ETCD \
David Bainbridge76afd812020-04-06 09:53:52 -0700272 WITH_ONOS \
David Bainbridge6ca40102020-04-08 11:30:40 -0700273 VOLTHA_NS \
274 ADAPTER_NS \
275 INFRA_NS \
276 BBSIM_NS \
David Bainbridge7db44002020-04-09 12:54:29 -0700277 SADIS_BANDWIDTH_PROFILES \
278 SADIS_SUBSCRIBERS \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000279 "
David Bainbridge01294952019-07-30 19:33:45 +0000280
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000281# Iterate over yes/no configuration options and validate
282for VAR in $ALL_YES_NO; do
David Bainbridged18f4942020-04-14 16:46:13 -0700283 eval "$VAR"="$(verify_yes_no "$VAR")"
284 if [ "$(eval echo "\$$VAR")" == "INVALID" ]; then
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000285 exit 1;
286 fi
287done
David Bainbridgeb270c202019-07-26 01:44:42 +0000288
David Bainbridge15f6f232020-03-30 09:15:43 -0700289# Special case for CONFIG_SADIS
David Bainbridged18f4942020-04-14 16:46:13 -0700290if [ "$(echo ":y:yes:true:1:" | grep -ic ":$CONFIG_SADIS:")" -eq 1 ]; then
David Bainbridge15f6f232020-03-30 09:15:43 -0700291 CONFIG_SADIS="yes"
292fi
David Bainbridged18f4942020-04-14 16:46:13 -0700293if [ "$(echo ":n:no:false:0:" | grep -ic ":$CONFIG_SADIS:")" -eq 1 ]; then
David Bainbridge15f6f232020-03-30 09:15:43 -0700294 CONFIG_SADIS="no"
295fi
296
David Bainbridge76afd812020-04-06 09:53:52 -0700297# Special case for WITH_ONOS, WITH_RADIUS, WITH_KAFKA, and WITH_ETCD
David Bainbridged18f4942020-04-14 16:46:13 -0700298if [ "$(echo ":y:yes:true:1:" | grep -ic ":$WITH_KAFKA:")" -eq 1 ]; then
David Bainbridge696bc632020-04-05 21:49:37 -0700299 WITH_KAFKA="yes"
300fi
David Bainbridged18f4942020-04-14 16:46:13 -0700301if [ "$(echo ":n:no:false:0:" | grep -ic ":$WITH_KAFKA:")" -eq 1 ]; then
David Bainbridge696bc632020-04-05 21:49:37 -0700302 WITH_KAFKA="no"
303fi
David Bainbridged18f4942020-04-14 16:46:13 -0700304if [ "$(echo ":external:" | grep -ic ":$WITH_KAFKA:")" -eq 1 ]; then
David Bainbridge76afd812020-04-06 09:53:52 -0700305 WITH_KAFKA="external"
306fi
David Bainbridged18f4942020-04-14 16:46:13 -0700307if [ "$(echo ":y:yes:true:1:" | grep -ic ":$WITH_ETCD:")" -eq 1 ]; then
David Bainbridge696bc632020-04-05 21:49:37 -0700308 WITH_ETCD="yes"
309fi
David Bainbridged18f4942020-04-14 16:46:13 -0700310if [ "$(echo ":n:no:false:0:" | grep -ic ":$WITH_ETCD:")" -eq 1 ]; then
David Bainbridge696bc632020-04-05 21:49:37 -0700311 WITH_ETCD="no"
312fi
David Bainbridged18f4942020-04-14 16:46:13 -0700313if [ "$(echo ":external:" | grep -ic ":$WITH_ETCD:")" -eq 1 ]; then
David Bainbridge76afd812020-04-06 09:53:52 -0700314 WITH_ETCD="external"
315fi
David Bainbridged18f4942020-04-14 16:46:13 -0700316if [ "$(echo ":y:yes:true:1:" | grep -ic ":$WITH_RADIUS:")" -eq 1 ]; then
David Bainbridge29c31cb2020-04-06 09:45:50 -0700317 WITH_RADIUS="yes"
318fi
David Bainbridged18f4942020-04-14 16:46:13 -0700319if [ "$(echo ":n:no:false:0:" | grep -ic ":$WITH_RADIUS:")" -eq 1 ]; then
David Bainbridge29c31cb2020-04-06 09:45:50 -0700320 WITH_RADIUS="no"
321fi
David Bainbridged18f4942020-04-14 16:46:13 -0700322if [ "$(echo ":y:yes:true:1:" | grep -ic ":$WITH_ONOS:")" -eq 1 ]; then
David Bainbridge76afd812020-04-06 09:53:52 -0700323 WITH_ONOS="yes"
324fi
David Bainbridged18f4942020-04-14 16:46:13 -0700325if [ "$(echo ":n:no:false:0:" | grep -ic ":$WITH_ONOS:")" -eq 1 ]; then
David Bainbridge76afd812020-04-06 09:53:52 -0700326 WITH_ONOS="no"
327fi
David Bainbridge696bc632020-04-05 21:49:37 -0700328
David Bainbridged18f4942020-04-14 16:46:13 -0700329if [ "$HELM_USE_UPGRADE" == "yes" ]; then
David Bainbridge7f8bf992020-04-08 21:53:22 -0700330 _HELM_DESC="Upgrade/Install"
331else
332 _HELM_DESC="Install"
333fi
334
David Bainbridged18f4942020-04-14 16:46:13 -0700335ETCD_PREFIX=
336KAFKA_PREFIX=
337if [ "$WITH_ETCD" == "yes" ]; then
338 ETCD_PREFIX="voltha-"
339fi
340if [ "$WITH_KAFKA" == "yes" ]; then
341 KAFKA_PREFIX="voltha-"
342fi
343
David K. Bainbridgeda33d652020-03-06 10:31:23 -0800344# Check for prerequiste tools
David K. Bainbridge726ff6a2020-03-06 11:09:50 -0800345TOOLS="curl sed jq"
David Bainbridged18f4942020-04-14 16:46:13 -0700346if [ "$DEPLOY_K8S" == "yes" ]; then
David K. Bainbridgeda33d652020-03-06 10:31:23 -0800347 TOOLS+=" docker"
348fi
349NOT_FOUND=""
350for T in $TOOLS; do
David Bainbridged18f4942020-04-14 16:46:13 -0700351 if [ -z "$(command -v "$T")" ]; then
David K. Bainbridgeda33d652020-03-06 10:31:23 -0800352 NOT_FOUND+=" $T"
353 fi
354done
355
David Bainbridged18f4942020-04-14 16:46:13 -0700356if [ -n "$NOT_FOUND" ]; then
David K. Bainbridgeda33d652020-03-06 10:31:23 -0800357 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} The following required tools where not found, please install them:$NOT_FOUND"
358 exit 1
359fi
360
David Bainbridged18f4942020-04-14 16:46:13 -0700361TIMEOUT_SECONDS="$(parseDuration "$WAIT_TIMEOUT")"
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700362
David Bainbridge0774b232019-08-02 06:37:19 +0000363mkdir -p .voltha
364touch .voltha/ports
David Bainbridged18f4942020-04-14 16:46:13 -0700365HAVE="$(grep "$NAME" .voltha/ports)"
David Bainbridge0774b232019-08-02 06:37:19 +0000366if [ "$HAVE X" == " X" ]; then
367 # Find free port prefix
368 START=81
369 while true; do
David Bainbridged18f4942020-04-14 16:46:13 -0700370 if [ "$(grep -c $START .voltha/ports)" -eq 0 ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000371 break
372 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700373 START="$((START + 1))"
David Bainbridge0774b232019-08-02 06:37:19 +0000374 done
David Bainbridged18f4942020-04-14 16:46:13 -0700375 DELTA="$((START - 81))"
David Bainbridgea2595422019-10-22 03:54:28 +0000376 ONOS_API_PORT=${ONOS_API_PORT:-${START}81}
377 ONOS_SSH_PORT=${ONOS_SSH_PORT:-${START}01}
David Bainbridged18f4942020-04-14 16:46:13 -0700378 VOLTHA_API_PORT=${VOLTHA_API_PORT:-5$((55 + DELTA))55}
379 VOLTHA_SSH_PORT=${VOLTHA_SSH_PORT:-$((50 + DELTA))22}
380 VOLTHA_ETCD_PORT=${VOLTHA_ETCD_PORT:-$((23 + DELTA))79}
381 VOLTHA_KAFKA_PORT=${VOLTHA_KAFKA_PORT:-$((90 + DELTA))92}
Test User01ed0642019-07-03 20:17:06 +0000382else
David Bainbridged18f4942020-04-14 16:46:13 -0700383 VALUES="$(echo "$HAVE" | sed -e 's/\s//g' | cut -d= -f2)"
384 ONOS_API_PORT=${ONOS_API_PORT:-$(echo "$VALUES" | cut -d, -f1)}
385 ONOS_SSH_PORT=${ONOS_SSH_PORT:-$(echo "$VALUES" | cut -d, -f2)}
386 VOLTHA_API_PORT=${VOLTHA_API_PORT:-$(echo "$VALUES" | cut -d, -f3)}
387 VOLTHA_SSH_PORT=${VOLTHA_SSH_PORT:-$(echo "$VALUES" | cut -d, -f4)}
388 VOLTHA_ETCD_PORT=${VOLTHA_ETCD_PORT:-$(echo "$VALUES" | cut -d, -f5)}
389 VOLTHA_KAFKA_PORT=${VOLTHA_KAFKA_PORT:-$(echo "$VALUES" | cut -d, -f6)}
David K. Bainbridge00ecd382020-02-28 12:31:58 -0800390
David K. Bainbridge00ecd382020-02-28 12:31:58 -0800391 # A bit of a hueristic required here as the KAFKA port forward was
392 # added after the .voltha/ports files was created. Basically, if
393 # the VOLTHA_KAFKA_PORT isn't in the file then calculate the original
394 # DELTA from the VOLTHA_SSH_PORT and apply it to the VOLTHA_KAFKA_PORT
395 if [ -z "$VOLTHA_KAFKA_PORT" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -0700396 DELTA="$((VOLTHA_SSH_PORT/100-50))"
397 VOLTHA_KAFKA_PORT=${VOLTHA_KAFKA_PORT:-$((90 + DELTA))92}
David K. Bainbridge00ecd382020-02-28 12:31:58 -0800398 fi
Test User01ed0642019-07-03 20:17:06 +0000399fi
400
David Bainbridged18f4942020-04-14 16:46:13 -0700401PORTTMP="$(mktemp -u)"
402grep -v "$NAME" .voltha/ports > "$PORTTMP"
403echo "$NAME=$ONOS_API_PORT,$ONOS_SSH_PORT,$VOLTHA_API_PORT,$VOLTHA_SSH_PORT,$VOLTHA_ETCD_PORT,$VOLTHA_KAFKA_PORT" >> "$PORTTMP"
404cp "$PORTTMP" .voltha/ports
405rm -f "$PORTTMP"
David Bainbridge0774b232019-08-02 06:37:19 +0000406
David Bainbridge27790d62019-08-13 22:43:19 +0000407export ONOS_API_PORT ONOS_SSH_PORT
David Bainbridge01294952019-07-30 19:33:45 +0000408
Test Userd87942b2019-07-03 07:20:24 +0000409IDX=1
David Bainbridgee87067b2019-08-12 22:00:12 +0000410CLOCK="TIME:"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000411SPIN_PARTS=
412NOT_VERIFIED=
David Bainbridgef858a022019-08-14 21:25:11 +0000413THEX=
414BUILD=
David Bainbridge38dc1e82019-08-12 15:18:45 +0000415VERIFIED=
416HELM=
417OLD_KEY=
418BIRD=
419HIGH_VOLTAGE=
420PLUG=
David Bainbridge38dc1e82019-08-12 15:18:45 +0000421FORWARD=
David Bainbridge38dc1e82019-08-12 15:18:45 +0000422GO=
423DOWNLOAD=
424GEAR=
425NO_ENTRY=
426LOCK=
427
David Bainbridged18f4942020-04-14 16:46:13 -0700428if [ "$FANCY" -eq 1 ]; then
429 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 +0000430 CLOCK="\xe2\x8f\xb1"
David Bainbridgef858a022019-08-14 21:25:11 +0000431 THEX="${RED}${BOLD}\xe2\x9c\x97\x20${NORMAL}"
David Bainbridgef858a022019-08-14 21:25:11 +0000432 BUILD="${YELLOW}${BOLD}\xf0\x9f\x8f\x97${NORMAL}"
433 NOT_VERIFIED="$BUILD"
434 VERIFIED="${GREEN}${BOLD}\xe2\x9c\x93\x20${NORMAL}"
435 HELM="${BLUE}${BOLD}\xE2\x8E\x88${NORMAL}"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000436 OLD_KEY="\xF0\x9F\x97\x9D"
437 BIRD="\xF0\x9F\x90\xA6"
438 HIGH_VOLTAGE="\xE2\x9A\xA1"
439 PLUG="\xF0\x9F\xa7\xa9"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000440 FORWARD="\xE2\x87\xA8"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000441 GO="\xf0\x9f\x9a\x80"
442 DOWNLOAD="\xf0\x9f\x93\xa5"
443 GEAR="\xe2\x9a\x99"
444 NO_ENTRY="\xe2\x9b\x94"
445 LOCK="\xf0\x9f\x94\x92"
446fi
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700447
David Bainbridge712afb82019-08-14 19:55:58 +0000448duration() {
David Bainbridged18f4942020-04-14 16:46:13 -0700449 local h m s t
450 h="$(($1 / 3600))"
451 m="$(($1 % 3600 / 60))"
452 s="$(($1 % 60))"
453 t=""
David Bainbridgee87067b2019-08-12 22:00:12 +0000454
David Bainbridged18f4942020-04-14 16:46:13 -0700455 if [ "$h" -gt 0 ]; then
David Bainbridgee87067b2019-08-12 22:00:12 +0000456 t="$t${h}h"
457 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700458 if [ "$m" -gt 0 ]; then
David Bainbridgee87067b2019-08-12 22:00:12 +0000459 t="$t${m}m"
460 fi
David Bainbridge712afb82019-08-14 19:55:58 +0000461 echo "$t${s}s"
462}
463
464printtime() {
David Bainbridged18f4942020-04-14 16:46:13 -0700465 local INDENT
David Bainbridge712afb82019-08-14 19:55:58 +0000466 if [ "$1" == "-" ]; then
467 INDENT=" "
468 shift
469 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700470 echo -e "$INDENT $CLOCK $(duration "$1")"
David Bainbridgee87067b2019-08-12 22:00:12 +0000471}
472
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700473bspin() {
Test Userd87942b2019-07-03 07:20:24 +0000474 IDX=1
David Bainbridged18f4942020-04-14 16:46:13 -0700475 local INDENT
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700476 if [ "$1" == "-" ]; then
477 INDENT=" "
478 shift
479 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700480 if [ "$FANCY" -eq 0 ]; then
481 LINE="${*//[[:space:]+-]}"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000482 if [ "$LINE X" == " X" ]; then
483 return
484 fi
485 echo -e "$CIVIS$INDENT$*"
486 else
487 echo -en "$CIVIS$INDENT $*"
488 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700489}
490
491sspin() {
David Bainbridged18f4942020-04-14 16:46:13 -0700492 local INDENT
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700493 if [ "$1" == "-" ]; then
494 INDENT=" "
495 shift
496 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700497 if [ "$FANCY" -eq 0 ]; then
498 LINE="${*//[[:space:]+-]}"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000499 if [ "$LINE X" == " X" ]; then
500 return
501 fi
502 echo -e "$INDENT$*"
503 else
David Bainbridged18f4942020-04-14 16:46:13 -0700504 C="$(echo "$SPIN_PARTS" | cut '-d ' -f "$IDX")"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000505 echo -en "\r$INDENT$C $*"
David Bainbridged18f4942020-04-14 16:46:13 -0700506 IDX="$((IDX + 1))"
507 if [ "$IDX" -gt 8 ]; then
David Bainbridge38dc1e82019-08-12 15:18:45 +0000508 IDX=1
509 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700510 fi
511}
512
513espin() {
David Bainbridged18f4942020-04-14 16:46:13 -0700514 local INDENT
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700515 if [ "$1" == "-" ]; then
516 INDENT=" "
517 shift
518 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700519 if [ "$FANCY" -eq 0 ]; then
520 LINE="${*//[[:space:]+-]}"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000521 if [ "$LINE X" == " X" ]; then
522 return
523 fi
524 echo -e "$INDENT$*"
525 else
526 echo -e "\r$INDENT$*$CNORM"
527 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700528}
529
David Bainbridged18f4942020-04-14 16:46:13 -0700530if [ "$1" == "get" ] && [ "$2" == "voltconfig" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000531 echo "$HOME/.volt/config-$NAME"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000532 exit
533fi
534
David Bainbridged18f4942020-04-14 16:46:13 -0700535if [ $# -ne 1 ] || [ "$(echo ":up:down:dump:" | grep -c ":$1:")" -ne 1 ]; then
David Bainbridgeac7f8072019-08-01 22:15:33 +0000536 >&2 echo "What wouild you like to do today:"
537 >&2 echo " up - bring up voltha"
538 >&2 echo " down - tear down voltha"
539 >&2 echo " dump - create a debug dump of running system"
540 exit 1
541fi
542
David Bainbridge4f1b5562019-08-19 04:46:52 +0000543push_onos_config() {
David Bainbridged18f4942020-04-14 16:46:13 -0700544 local TYPE MSG RESOURCE DATA CMD_ECHO CMD_OUTPUT SC_OUTPUT WAIT_START NOW
545 TYPE=$1
546 MSG=$2
547 RESOURCE=$3
548 DATA=$4
David Bainbridge4f1b5562019-08-19 04:46:52 +0000549
David K. Bainbridgeb4b163b2020-02-19 15:55:06 -0800550 # Thanks to the latest version of ONOS using the return code 207 this gets a
551 # whole lot nastier. Can't thank them enough for doing this. So in order to
552 # capture the command and the output in the log file as well as capture the
553 # status code to verify it is 200 and not 207 mutltiple files and a bit of
554 # hackery must be used. Thanks again ONOS.
David Bainbridged18f4942020-04-14 16:46:13 -0700555 CMD_ECHO="$(mktemp -u)"
556 CMD_OUTPUT="$(mktemp -u)"
557 SC_OUTPUT="$(mktemp -u)"
558 WAIT_START="$(date +%s)"
David K. Bainbridgeb4b163b2020-02-19 15:55:06 -0800559
David Bainbridge4f1b5562019-08-19 04:46:52 +0000560 bspin - "$MSG $GEAR"
561 while true; do
David Bainbridged18f4942020-04-14 16:46:13 -0700562 NOW="$(date +%s)"
563 if [ "$((NOW - WAIT_START))" -gt "$TIMEOUT_SECONDS" ]; then
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700564 espin - "$THEX"
David Bainbridged18f4942020-04-14 16:46:13 -0700565 rm -f "$CMD_ECHO" "$CMD_OUTPUT" "$SC_OUTPUT"
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700566 doTimeout "waiting for ONOS config push on $RESOURCE"
567 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700568 if [ "$TYPE" == "file" ]; then
569 (set -x; curl --fail -sSL --user karaf:karaf -w "%{http_code}" -o "$CMD_OUTPUT" -X POST -H Content-Type:application/json "http://$_ONOS_API_EP/onos/v1/$RESOURCE" --data "@$DATA" >"$SC_OUTPUT" 2>/dev/null) >>"$CMD_ECHO" 2>&1
David K. Bainbridgeb859e912020-03-13 14:07:52 -0700570 RESULT=$?
Matteo Scandolo78dfee02020-02-13 16:18:03 -0800571 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700572 if [ "$TYPE" == "json" ]; then
573 (set -x; curl --fail -sSL --user karaf:karaf -w "%{http_code}" -o "$CMD_OUTPUT" -X POST -H Content-Type:application/json "http://$_ONOS_API_EP/onos/v1/$RESOURCE" --data "$DATA" >"$SC_OUTPUT" 2>/dev/null) >>"$CMD_ECHO" 2>&1
David K. Bainbridgeb859e912020-03-13 14:07:52 -0700574 RESULT=$?
Matteo Scandolo78dfee02020-02-13 16:18:03 -0800575 fi
David K. Bainbridgeb4b163b2020-02-19 15:55:06 -0800576 # Dump everything to the log
David Bainbridged18f4942020-04-14 16:46:13 -0700577 cat "$CMD_ECHO" >> "$LOG"
578 test -r "$CMD_OUTPUT" && cat "$CMD_OUTPUT" >> "$LOG"
579 SC="$(cat "$SC_OUTPUT")"
580 echo "RESPONSE CODE: $SC" >> "$LOG"
581 echo "ERROR CODE: $RESULT" >> "$LOG"
David K. Bainbridgeb4b163b2020-02-19 15:55:06 -0800582
583 # clean up temp files
David Bainbridged18f4942020-04-14 16:46:13 -0700584 rm -f "$CMD_ECHO" "$CMD_OUTPUT" "$SC_OUTPUT"
585 if [ "$RESULT" -eq 0 ] && [ "$SC" == "200" ]; then
David Bainbridge4f1b5562019-08-19 04:46:52 +0000586 break
587 fi
Matteo Scandolo9a77a732020-01-09 14:24:12 -0800588 sleep 1
David Bainbridge4f1b5562019-08-19 04:46:52 +0000589 sspin -
590 done
David Bainbridged18f4942020-04-14 16:46:13 -0700591 espin - "$VERIFIED"
David Bainbridge4f1b5562019-08-19 04:46:52 +0000592}
593
Matteo Scandolo9a77a732020-01-09 14:24:12 -0800594check_onos_app_active() {
David Bainbridged18f4942020-04-14 16:46:13 -0700595 local APP_ID WAIT_START RESULT NOW
596 APP_ID=$1
597 WAIT_START="$(date +%s)"
Matteo Scandolo9a77a732020-01-09 14:24:12 -0800598
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700599 bspin - "Checking that $APP_ID is active $CLOCK"
600 while true; do
David Bainbridged18f4942020-04-14 16:46:13 -0700601 NOW="$(date +%s)"
602 if [ "$((NOW - WAIT_START))" -gt "$TIMEOUT_SECONDS" ]; then
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700603 espin - "$THEX"
604 doTimeout "waiting for ONOS application activation '$APP_ID'"
605 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700606 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 -0700607 break
608 fi
609 sleep 1
610 sspin -
611 done
612 sleep 5 # OSGI components take a little longer that the app to activate
David Bainbridged18f4942020-04-14 16:46:13 -0700613 espin - "$VERIFIED"
Matteo Scandolo9a77a732020-01-09 14:24:12 -0800614}
615
David Bainbridge4f1b5562019-08-19 04:46:52 +0000616override_onos_app() {
David Bainbridged18f4942020-04-14 16:46:13 -0700617 local APP NAME WAIT_START NOW
618 APP=$1
619 NAME="$(basename "$APP" | sed -e 's/^[0-9][0-9]*-//g' -e 's/-.*$//g')"
620 WAIT_START="$(date +%s)"
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700621
David Bainbridge4f1b5562019-08-19 04:46:52 +0000622 while true; do
David Bainbridged18f4942020-04-14 16:46:13 -0700623 NOW="$(date +%s)"
624 if [ "$((NOW - WAIT_START))" -gt "$TIMEOUT_SECONDS" ]; then
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700625 espin - "$THEX"
626 doTimeout "waiting to overwrite ONOS application '$APP'"
627 fi
David Bainbridge4f1b5562019-08-19 04:46:52 +0000628 sspin -
629 # Attempt to delete old version (if it exists)
David Bainbridged18f4942020-04-14 16:46:13 -0700630 (set -x; curl --fail -sSL --user karaf:karaf -X DELETE "http://$_ONOS_API_EP/onos/v1/applications/$NAME" >>"$LOG" 2>&1) >>"$LOG" 2>&1
631 RESULT=$?
David Bainbridge4f1b5562019-08-19 04:46:52 +0000632 sspin -
David Bainbridged18f4942020-04-14 16:46:13 -0700633 if [ $RESULT -ne 0 ]; then
David Bainbridge4f1b5562019-08-19 04:46:52 +0000634 continue
635 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700636 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 +0000637 break
638 fi
639 sleep .2
640 done
641}
642
643activate_onos_app() {
David Bainbridged18f4942020-04-14 16:46:13 -0700644 local MSG APP WAIT_START NOW
645 MSG="$1"
646 APP=$2
647 WAIT_START="$(date +%s)"
David Bainbridge4f1b5562019-08-19 04:46:52 +0000648
649 bspin - "$MSG $GO"
650 while true; do
David Bainbridged18f4942020-04-14 16:46:13 -0700651 NOW="$(date +%s)"
652 if [ "$((NOW - WAIT_START))" -gt "$TIMEOUT_SECONDS" ]; then
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700653 espin - "$THEX"
654 doTimeout "waiting to activate ONOS application '$APP'"
655 fi
David Bainbridge4f1b5562019-08-19 04:46:52 +0000656 sspin -
David Bainbridged18f4942020-04-14 16:46:13 -0700657 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 +0000658 break
659 fi
660 sleep .2
661 done
662 espin - "$VERIFIED"
663}
664
665count_pods() {
David Bainbridged18f4942020-04-14 16:46:13 -0700666 local NAMESPACE STATES LABELS CMD PODS
667 NAMESPACE=$1; shift
David Bainbridge4f1b5562019-08-19 04:46:52 +0000668 if [ "$NAMESPACE" == "all-namespaces" ]; then
669 NAMESPACE="--all-namespaces"
670 else
671 NAMESPACE="-n $NAMESPACE"
672 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700673 STATES=$1; shift
674 LABELS=$1; shift
675 CMD=("kubectl get $NAMESPACE $LABELS pod")
676 PODS=$(${CMD[*]} -o go-template="{{range .items}}{{.metadata.name}}/{{.status.phase}}/_{{range .status.containerStatuses}}{{.ready}}_{{end}} {{end}}")
David Bainbridge4f1b5562019-08-19 04:46:52 +0000677 local COUNT=0
678 local PATTERNS="$*"
679 for POD in $PODS; do
David Bainbridged18f4942020-04-14 16:46:13 -0700680 local NAME STATE CONTAINERS TOTAL FOUND
681 NAME="$(echo "$POD" | cut -d/ -f 1)"
682 STATE="$(echo "$POD" | cut -d/ -f 2)"
683 CONTAINERS="$(echo "$POD" | cut -d/ -f 3 | sed -e 's/_/ /g')"
684 if [ "$STATES" == "*" ] || [ "$(echo "$STATES" | grep -c ":$STATE:")" -ne 0 ]; then
685 TOTAL="$(echo "$CONTAINERS" | wc -w)"
686 FOUND="$(echo "$CONTAINERS" | grep -o true | wc -l)"
687 if [ "$TOTAL" -eq "$FOUND" ]; then
David Bainbridge4f1b5562019-08-19 04:46:52 +0000688 for PATTERN in $PATTERNS; do
David Bainbridged18f4942020-04-14 16:46:13 -0700689 if [[ "$NAME" =~ $PATTERN ]]; then
690 COUNT="$((COUNT + 1))"
David Bainbridge4f1b5562019-08-19 04:46:52 +0000691 break
692 fi
693 done
694 fi
695 fi
696 done
David Bainbridge4f1b5562019-08-19 04:46:52 +0000697 echo $COUNT
698}
699
700wait_for_pods() {
David Bainbridged18f4942020-04-14 16:46:13 -0700701 local INDENT NAMESPACE EXPECT TYPE MESSAGE LABELS PATTERNS STATES HAVE ALL WAIT_START NOW
David Bainbridge4f1b5562019-08-19 04:46:52 +0000702 if [ "$1" == "-" ]; then
703 INDENT=$1; shift
704 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700705 NAMESPACE=$1; shift
706 EXPECT=$1; shift
707 TYPE=$1; shift
708 MESSAGE=$1; shift
709 LABELS=$1; shift
710 PATTERNS=("$*")
711 STATES=":Running:"
David Bainbridge99ac7a22019-08-31 02:26:43 +0000712 if [ "$TYPE" == "not" ]; then
713 STATES="*"
714 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700715 HAVE="$(count_pods "$NAMESPACE" "$STATES" "$LABELS" "${PATTERNS[@]}")"
716 ALL=$HAVE
David Bainbridge4f1b5562019-08-19 04:46:52 +0000717 if [ "$TYPE" == "only" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -0700718 ALL="$(count_pods "all-namespaces" "*" ".*")"
David Bainbridge4f1b5562019-08-19 04:46:52 +0000719 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700720 COUNT="$((300 / 15))"
721 WAIT_START="$(date +%s)"
722 bspin "$INDENT" "$MESSAGE"
723 sspin "$INDENT"
724 if [ "$HAVE" -ne "$EXPECT" ] || [ "$ALL" -ne "$HAVE" ]; then
725 while [ "$HAVE" -ne "$EXPECT" ] || [ "$ALL" -ne "$HAVE" ]; do
726 NOW="$(date +%s)"
727 if [ "$((NOW - WAIT_START))" -gt "$TIMEOUT_SECONDS" ]; then
728 espin "$INDENT" "$THEX"
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700729 doTimeout "waiting for PODs to start"
730 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700731 sspin "$INDENT"
732 COUNT="$((COUNT - 1))"
733 if [ "$COUNT" -eq 0 ]; then
734 HAVE="$(count_pods "$NAMESPACE" "$STATES" "$LABELS" "${PATTERNS[@]}")"
735 ALL="$HAVE"
David Bainbridge4f1b5562019-08-19 04:46:52 +0000736 if [ "$TYPE" == "only" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -0700737 ALL="$(count_pods "all-namespaces" "*" ".*")"
David Bainbridge4f1b5562019-08-19 04:46:52 +0000738 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700739 COUNT="$((300 / 15))"
David Bainbridge4f1b5562019-08-19 04:46:52 +0000740 fi
741 sleep .15
742 done
743 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700744 espin "$INDENT" "$VERIFIED"
745 if [ "$HAVE" -ne "$EXPECT" ]; then
David Bainbridge4f1b5562019-08-19 04:46:52 +0000746 return 1
747 fi
748 return 0
749}
750
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800751port_forward() {
752 local NS=$1
753 local SVC=$2
754 local FROM_PORT=$3
755 local TO_PORT=$4
756 local TAG=$SVC-$NAME
757
David Bainbridged18f4942020-04-14 16:46:13 -0700758 (set -x; _TAG="$TAG" bash -c "while true; do kubectl port-forward --address 0.0.0.0 -n $NS service/$SVC $FROM_PORT:$TO_PORT; done" >>"$LOG" 2>&1 &) >>"$LOG" 2>&1
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800759}
760
761kill_port_forward() {
David Bainbridged18f4942020-04-14 16:46:13 -0700762 local TAG P_IDS PARENTS KIDS UNKNOWN PP_ID
763 TAG="$1-$NAME"
764 # shellcheck disable=SC2009
765 P_IDS="$(ps e -ww -A | grep "_TAG=$TAG" | grep -v grep | awk '{print $1}')"
766 if [ -n "$P_IDS" ]; then
David Bainbridgec6871d22019-11-13 17:10:31 +0000767 for P_ID in $P_IDS; do
David Bainbridged18f4942020-04-14 16:46:13 -0700768 PP_ID="$(ps -o ppid "$P_ID" | tail -n +2)"
769 if [ -n "$PP_ID" ]; then
770 if [ "$PP_ID" -eq 1 ]; then
David Bainbridgec6871d22019-11-13 17:10:31 +0000771 PARENTS="$PARENTS $P_ID"
772 else
773 KIDS="$KIDS $P_ID"
774 fi
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800775 else
David Bainbridgec6871d22019-11-13 17:10:31 +0000776 UNKNOWN="$UNKNOWN $P_ID"
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800777 fi
778 done
David Bainbridged18f4942020-04-14 16:46:13 -0700779 (set -x; kill -9 "$PARENTS" "$KIDS" "$UNKNOWN" >>"$LOG" 2>&1) >>"$LOG" 2>&1
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800780 fi
781}
782
David Bainbridgecf546362020-04-21 23:18:50 -0700783resolve_chart_version() {
784 [ "$2" != "latest" ] && echo "$2" && return
785 helm inspect chart "$1" | grep "^version:" | awk '{print $2}'
786}
787
Jonathan Hart6a91e6c2020-04-16 14:28:33 -0700788# Compares two semver-formatted version strings (e.g. 2.4.3)
789# Returns 0 if $1 == $2, returns 1 if $1 > $2 and returns 2 if $1 < $2
790compare_versions() {
791 [ "$1" == "$2" ] && return 0
Jonathan Hart6a91e6c2020-04-16 14:28:33 -0700792 local lowest
793 lowest=$(echo -e "$1\n$2" | sort -V | head -1)
794 [ "$lowest" == "$1" ] && return 2
795 return 1
796}
797
David Bainbridgeac7f8072019-08-01 22:15:33 +0000798if [ "$1" == "down" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000799 echo "Tearing down voltha cluster $NAME"
800 LOG="down-$NAME.log"
David Bainbridged18f4942020-04-14 16:46:13 -0700801 date -u +"%Y%m%dT%H%M%SZ" >"$LOG"
802 if [ "$WITH_ONOS" == "yes" ]; then
David Bainbridge696bc632020-04-05 21:49:37 -0700803 bspin "Remove port-forwards: onos-ui-$NAME"
804 kill_port_forward onos-ui
805 sspin "Remove port-forwards: onos-ssh-$NAME$CEOL"
806 kill_port_forward onos-ssh
807 fi
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800808 sspin "Remove port-forwards: voltha-api-$NAME$CEOL"
809 kill_port_forward voltha-api
David Bainbridged18f4942020-04-14 16:46:13 -0700810 if [ "$WITH_ETCD" == "yes" ] || [ "$WITH_ETCD" == "external" ]; then
811 sspin "Remove port-forwards: ${ETCD_PREFIX}etcd-$NAME$CEOL"
812 kill_port_forward "${ETCD_PREFIX}etcd-cluster-client"
David Bainbridge696bc632020-04-05 21:49:37 -0700813 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700814 if [ "$WITH_KAFKA" == "yes" ] || [ "$WITH_KAFKA" == "external" ]; then
815 sspin "Remove port-forwards: ${KAFKA_PREFIX}kafka-$NAME$CEOL"
816 kill_port_forward "${KAFKA_PREFIX}kafka"
David Bainbridge696bc632020-04-05 21:49:37 -0700817 fi
818
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800819 espin "$VERIFIED Remove port-forwards$CEOL"
David Bainbridged18f4942020-04-14 16:46:13 -0700820 if [ "$DEPLOY_K8S" == "yes" ]; then
David Bainbridgeac7f8072019-08-01 22:15:33 +0000821 if [ -x ./bin/kind ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000822 bspin "Delete Kubernetes Kind Cluster"
David Bainbridged18f4942020-04-14 16:46:13 -0700823 (set -x; ./bin/kind delete cluster --name "voltha-$NAME" >>"$LOG" 2>&1) >>"$LOG" 2>&1
824 espin "$VERIFIED"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000825 else
David Bainbridge0774b232019-08-02 06:37:19 +0000826 espin "$NO_ENTRY Delete Kubernetes Kind Cluster: kind command not found"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000827 fi
828 else
David Bainbridged18f4942020-04-14 16:46:13 -0700829 EXISTS="$(helm list -q)"
David Bainbridge76afd812020-04-06 09:53:52 -0700830 EXPECT="voltha"
David Bainbridged18f4942020-04-14 16:46:13 -0700831 if [ "$WITH_ONOS" == yes ]; then
David Bainbridge696bc632020-04-05 21:49:37 -0700832 EXPECT+=" onos"
833 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700834 if [ "$WITH_RADIUS" == "yes" ]; then
David Bainbridge696bc632020-04-05 21:49:37 -0700835 EXPECT+=" radius"
836 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700837 if [ "$WITH_BBSIM" == "yes" ]; then
David Bainbridge696bc632020-04-05 21:49:37 -0700838 EXPECT+=" bbsim"
839 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700840 if [ "$WITH_OPEN_ADAPTERS" == "yes" ]; then
David Bainbridge696bc632020-04-05 21:49:37 -0700841 EXPECT+=" open-olt open-onu"
842 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700843 if [ "$WITH_SIM_ADAPTERS" == "yes" ]; then
David Bainbridge696bc632020-04-05 21:49:37 -0700844 EXPECT+=" sim"
845 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700846 if [ "$WITH_ETCD" == "external" ]; then
David Bainbridge76afd812020-04-06 09:53:52 -0700847 EXPECT+=" etcd-operator etcd-cluster"
David Bainbridged18f4942020-04-14 16:46:13 -0700848 elif [ "$WITH_ETCD" == "yes" ]; then
David Bainbridge76afd812020-04-06 09:53:52 -0700849 EXPECT+=" etcd-operator"
850 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700851 if [ "$WITH_KAFKA" == "external" ]; then
David Bainbridge76afd812020-04-06 09:53:52 -0700852 EXPECT+=" kafka"
853 fi
David Bainbridge0774b232019-08-02 06:37:19 +0000854 bspin "Remove Helm Deployments"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000855 for i in $EXISTS; do
David K. Bainbridge43422402020-03-06 07:41:22 -0800856 for j in $EXPECT; do
David Bainbridged18f4942020-04-14 16:46:13 -0700857 if [[ "$i" =~ $j ]]; then
David K. Bainbridge43422402020-03-06 07:41:22 -0800858 sspin "Remove Helm Deployments: $i$CEOL"
David Bainbridged18f4942020-04-14 16:46:13 -0700859 (set -x; ./bin/helm delete --no-hooks --purge "$i" >>"$LOG" 2>&1) >>"$LOG" 2>&1
David K. Bainbridge43422402020-03-06 07:41:22 -0800860 fi
861 done
uottrembb16d3982020-02-28 08:34:36 +0100862 done
David Bainbridge0774b232019-08-02 06:37:19 +0000863 espin "$VERIFIED Remove Helm Deployments$CEOL"
David Bainbridge4f1b5562019-08-19 04:46:52 +0000864 if [ "$WAIT_ON_DOWN" == "yes" ]; then
David Bainbridge76afd812020-04-06 09:53:52 -0700865 PODS="voltha-kafka.* voltha-ofagent.* voltha-rw-core.* voltha-etcd.*"
866 INFRA_PODS=
867 ADAPT_PODS=
868 SIM_PODS=
David Bainbridged18f4942020-04-14 16:46:13 -0700869 if [ "$WITH_RADIUS" == "yes" ]; then
David Bainbridge696bc632020-04-05 21:49:37 -0700870 PODS+=" radius.*"
871 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700872 if [ "$WITH_BBSIM" == "yes" ]; then
David Bainbridge76afd812020-04-06 09:53:52 -0700873 SIM_PODS+=" bbsim.*"
David Bainbridge696bc632020-04-05 21:49:37 -0700874 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700875 if [ "$WITH_OPEN_ADAPTERS" ] || [ "$WITH_SIM_ADAPTERS" ]; then
David Bainbridge76afd812020-04-06 09:53:52 -0700876 ADAPT_PODS+=" adapter-*"
David Bainbridge696bc632020-04-05 21:49:37 -0700877 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700878 if [ "$WITH_ONOS" == "yes" ]; then
David Bainbridge76afd812020-04-06 09:53:52 -0700879 INFRA_PODS+=" onos-.*"
880 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700881 if [ "$WITH_ETCD" == "external" ]; then
David Bainbridge76afd812020-04-06 09:53:52 -0700882 INFRA_PODS+=" etcd-operator.* etcd-cluster.*"
David Bainbridged18f4942020-04-14 16:46:13 -0700883 elif [ "$WITH_ETCD" == "yes" ]; then
David Bainbridge76afd812020-04-06 09:53:52 -0700884 PODS+=" etcd-operator.*"
885 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700886 if [ "$WITH_KAFKA" == "external" ]; then
David Bainbridge76afd812020-04-06 09:53:52 -0700887 INFRA_PODS+=" kafka.*"
888 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700889 if [ -n "$SIM_PODS" ]; then
890 wait_for_pods "$BBSIM_NS" 0 "not" "Waiting for BBSIM PODs to terminate" "$BBSIM_LABEL" "$SIM_PODS"
David Bainbridge76afd812020-04-06 09:53:52 -0700891 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700892 if [ -n "$INFRA_PODS" ]; then
893 wait_for_pods "$INFRA_NS" 0 "not" "Waiting for infrastructure PODs to terminate" "$NO_LABEL" "$INFRA_PODS"
David Bainbridge76afd812020-04-06 09:53:52 -0700894 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700895 if [ -n "$ADAPT_PODS" ]; then
896 wait_for_pods "$ADAPTER_NS" 0 "not" "Waiting for adapter PODs to terminate" "$NO_LABEL" "$ADAPT_PODS"
David Bainbridge76afd812020-04-06 09:53:52 -0700897 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700898 wait_for_pods "$VOLTHA_NS" 0 "not" "Waiting for VOLTHA PODs to terminate" "$NO_LABEL" "$PODS"
David Bainbridge4f1b5562019-08-19 04:46:52 +0000899 fi
David Bainbridgeac7f8072019-08-01 22:15:33 +0000900 fi
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -0700901 exit
David Bainbridgeac7f8072019-08-01 22:15:33 +0000902fi
903
904if [ "$1" == "dump" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000905 LOG="dump-$NAME.log"
David Bainbridged18f4942020-04-14 16:46:13 -0700906 TS="$(date -u +"%Y%m%dT%H%M%SZ")"
907 if [ -n "$DUMP_FROM" ]; then
908 TS=${DUMP_FROM//[:-]}
David Bainbridge76514a02019-10-08 01:50:35 +0000909 fi
David Bainbridged18f4942020-04-14 16:46:13 -0700910 WORK="$(mktemp -u -d)"
David Bainbridge0774b232019-08-02 06:37:19 +0000911 DATA=$WORK/voltha-debug-dump-$NAME-$TS
David Bainbridged18f4942020-04-14 16:46:13 -0700912 mkdir -p "$DATA"
913 echo "$TS" > "$LOG"
David Bainbridge0774b232019-08-02 06:37:19 +0000914 echo -e "Capturing debug dump to voltha-debug-dump-$NAME-$TS.tgz"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000915 bspin - "Copy install log"
David Bainbridged18f4942020-04-14 16:46:13 -0700916 if [ -f "install-$NAME.log" ]; then
917 (set -x; cp "install-$NAME.log" "$DATA/install-$NAME.log") >>"$LOG" 2>&1
918 espin - "$VERIFIED"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000919 else
David Bainbridge0774b232019-08-02 06:37:19 +0000920 espin - "$NO_ENTRY Copy install log: install-$NAME.log not found"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000921 fi
922 bspin - "Dumping Kubernetes PODs"
David Bainbridged18f4942020-04-14 16:46:13 -0700923 (set -x; kubectl get --all-namespaces pods >> "$DATA/all-pods.txt" 2>&1) >>"$LOG" 2>&1
924 espin - "$VERIFIED"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000925 bspin - "Dumping Kubernetes SERVICEs"
David Bainbridged18f4942020-04-14 16:46:13 -0700926 (set -x; kubectl get --all-namespaces svc >> "$DATA/all-services.txt" 2>&1) >>"$LOG" 2>&1
927 espin - "$VERIFIED"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000928 bspin - "Dumping Kubernetes EVENTs"
David Bainbridged18f4942020-04-14 16:46:13 -0700929 (set -x; kubectl get --all-namespaces events >> "$DATA/all-events.txt" 2>&1) >>"$LOG" 2>&1
930 espin - "$VERIFIED"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000931 bspin - "Dumping VOLTHA POD details"
David Bainbridged18f4942020-04-14 16:46:13 -0700932 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 +0000933 SINCE=
David Bainbridged18f4942020-04-14 16:46:13 -0700934 if [ -n "$DUMP_FROM" ]; then
David Bainbridgecfd7ca12019-10-06 03:31:41 +0000935 SINCE="--since-time=$DUMP_FROM"
936 fi
David Bainbridgeac7f8072019-08-01 22:15:33 +0000937 for POD in $PODS; do
David Bainbridged18f4942020-04-14 16:46:13 -0700938 NS="$(echo "$POD" | cut -d: -f1)"
939 POD="$(echo "$POD" | cut -d: -f2)"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000940 sspin - "Dumping VOLTHA POD details: $POD$CEOL"
David Bainbridged18f4942020-04-14 16:46:13 -0700941 mkdir -p "$DATA/$POD"
942 (set -x; kubectl describe -n "$NS" "$POD" >> "$DATA/$POD/describe.txt" 2>&1) >>"$LOG" 2>&1
David Bainbridgeac7f8072019-08-01 22:15:33 +0000943 sspin - "Dumping VOLTHA POD details: $POD"
David Bainbridged18f4942020-04-14 16:46:13 -0700944 (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 +0000945 sspin - "Dumping VOLTHA POD details: $POD"
David Bainbridged18f4942020-04-14 16:46:13 -0700946 (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 +0000947 sspin - "Dumping VOLTHA POD details: $POD"
948 done
949 espin - "$VERIFIED Dumping VOLTHA POD details$CEOL"
950 bspin - "Dumping ETCD"
David Bainbridged18f4942020-04-14 16:46:13 -0700951 if [ -n "$(command -v etcdctl)" ]; then
952 (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
953 espin - "$VERIFIED"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000954 else
955 espin - "$NO_ENTRY Dumping ETCD: etcdctl command not available"
956 fi
David Bainbridge0774b232019-08-02 06:37:19 +0000957 bspin - "Creating compressed TAR: voltha-debug-dump-$NAME-$TS.tgz"
David Bainbridged18f4942020-04-14 16:46:13 -0700958 (set -x; tar -C "$WORK" -zcf "voltha-debug-dump-$NAME-$TS.tgz" "./voltha-debug-dump-$NAME-$TS") >>"$LOG" 2>&1
959 espin - "$VERIFIED"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000960 bspin - "Cleanup"
David Bainbridged18f4942020-04-14 16:46:13 -0700961 (set -x; rm -rf "$WORK") >>"$LOG" 2>&1
962 espin - "$VERIFIED"
963 bspin - "$(ls -l "voltha-debug-dump-$NAME-$TS.tgz")"
964 espin - "$VERIFIED"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000965 exit
966fi
967
David Bainbridge0774b232019-08-02 06:37:19 +0000968LOG="install-$NAME.log"
David Bainbridged18f4942020-04-14 16:46:13 -0700969date > "$LOG"
970echo "PORTS=$ONOS_API_PORT,$ONOS_SSH_PORT,$VOLTHA_API_PORT,$VOLTHA_SSH_PORT,$VOLTHA_ETCD_PORT" >> "$LOG"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000971
972# Output install options to log
David Bainbridged18f4942020-04-14 16:46:13 -0700973echo "OPTIONS" >> "$LOG"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000974for O in $ALL_OPTIONS; do
David Bainbridged18f4942020-04-14 16:46:13 -0700975 VAL="$(eval echo "\$$O")"
976 if [ -n "$VAL" ]; then
977 printf " %-30s = %s\n" "$O" "$VAL" >> "$LOG"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000978 fi
979done
980
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -0700981helm_install() {
David Bainbridged18f4942020-04-14 16:46:13 -0700982 local INDENT NOW
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700983 if [ "$1" == "-" ]; then
984 INDENT=$1; shift
985 fi
986 local NAMESPACE=$1; shift
David Bainbridge0774b232019-08-02 06:37:19 +0000987 local INAME=$1; shift
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700988 local CHART=$1; shift
David Bainbridge90fd8e32019-08-21 23:32:47 +0000989 local CHART_VERSION=$1; shift
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700990 local MESSAGE=$*
991
David Bainbridged18f4942020-04-14 16:46:13 -0700992 if [ "$CHART_VERSION X" != " X" ] && [ "$CHART_VERSION" != "latest" ]; then
David Bainbridge90fd8e32019-08-21 23:32:47 +0000993 CHART_VERSION="--version $CHART_VERSION"
994 else
995 CHART_VERSION=
996 fi
997
David Bainbridge99ac7a22019-08-31 02:26:43 +0000998 local CHART_ARGS=
999 if [ -r "${INAME}-values.yaml" ]; then
1000 CHART_ARGS="-f ${INAME}-values.yaml"
1001 fi
1002
David Bainbridged18f4942020-04-14 16:46:13 -07001003 local WAIT_START CMD
1004 WAIT_START="$(date +%s)"
1005 COUNT="$((300 / 15))"
1006 bspin "$INDENT" "$MESSAGE"
1007 if [ "$HELM_USE_UPGRADE" == "yes" ]; then
David Bainbridge7f8bf992020-04-08 21:53:22 -07001008 _HELM_COMMAND="upgrade --install"
1009 _HELM_ARGS="$INAME"
1010 else
1011 _HELM_COMMAND="install"
1012 _HELM_ARGS="--name $INAME"
1013 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001014 CMD=("helm $_HELM_COMMAND -f $NAME-values.yaml $CHART_ARGS $INTERNAL_EXTRA_HELM_INSTALL_ARGS $EXTRA_HELM_INSTALL_ARGS --set defaults.log_level=$VOLTHA_LOG_LEVEL --namespace $NAMESPACE $_HELM_ARGS $CHART_VERSION $EXTRA_HELM_FLAGS $CHART")
1015 (set -x; ${CMD[*]} >>"$LOG" 2>&1) >>"$LOG" 2>&1
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001016 SUCCESS=$?
David Bainbridged18f4942020-04-14 16:46:13 -07001017 while [ "$SUCCESS" -ne 0 ]; do
1018 NOW="$(date +%s)"
1019 if [ "$((NOW - WAIT_START))" -gt "$TIMEOUT_SECONDS" ]; then
David Bainbridge52e6e9d2020-03-23 13:48:27 -07001020 espin "$THEX"
1021 doTimeout "waiting for helm install $CHART"
1022 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001023 sspin "$INDENT"
1024 COUNT="$((COUNT - 1))"
1025 if [ "$COUNT" -eq 0 ]; then
1026 if [ "$HELM_USE_UPGRADE" == "no" ]; then
1027 (set -x; helm delete --purge "$INAME" >>"$LOG" 2>&1) >>"$LOG" 2>&1
David Bainbridge7f8bf992020-04-08 21:53:22 -07001028 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001029 (set -x; ${CMD[*]} >>"$LOG" 2>&1) >>"$LOG" 2>&1
Andy Baviere22ff252019-12-19 11:40:31 -07001030 SUCCESS=$?
David Bainbridged18f4942020-04-14 16:46:13 -07001031 COUNT="$((300 / 15))"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001032 fi
1033 sleep .15
1034 done
David Bainbridged18f4942020-04-14 16:46:13 -07001035 espin "$INDENT" "$VERIFIED"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001036}
1037
David Bainbridged18f4942020-04-14 16:46:13 -07001038echo "INSTALL TYPE: $TYPE" >> "$LOG"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001039
1040bspin "Verify GOPATH"
David Bainbridged18f4942020-04-14 16:46:13 -07001041GOPATH="$(pwd)"; export GOPATH
1042mkdir -p "$GOPATH/bin"
1043espin "$VERIFIED"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001044
David Bainbridged18f4942020-04-14 16:46:13 -07001045STIME="$(date +%s)"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001046if [ "$INSTALL_KUBECTL" == "no" ]; then
1047 bspin "Skip kubectl install"
1048 espin $NO_ENTRY
Test Userc13bdc92019-07-03 20:57:49 +00001049else
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001050 bspin "Verify kubectl $HELM"
David Bainbridged18f4942020-04-14 16:46:13 -07001051 if [ -x "$GOPATH/bin/kubectl" ]; then
1052 espin "$VERIFIED"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001053 else
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001054 ERR_OUT="$(mktemp)"
David Bainbridged18f4942020-04-14 16:46:13 -07001055 espin "$NOT_VERIFIED"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001056 bspin - "Download and install Kubernetes/kubectl $DOWNLOAD"
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001057 (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
1058 RESULT=$?
1059 if [ "$RESULT" -ne 0 ]; then
1060 espin - "$THEX"
David Bainbridgee3fc0c32020-04-21 15:34:04 -07001061 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR: unable to download kubectl: $(tail "$ERR_OUT")${NORMAL}"
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001062 cat "$ERR_OUT" >> "$LOG"
1063 rm -rf $"ERR_OUT" "$GOPATH/bin/kubectl"
1064 exit 1
1065 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001066 (set -x; chmod 755 "$GOPATH/bin/kubectl" >>"$LOG" 2>&1) >>"$LOG" 2>&1
1067 espin - "$VERIFIED"
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001068 rm -rf "$ERR_OUT"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001069 fi
Test Userc13bdc92019-07-03 20:57:49 +00001070fi
David Bainbridgee87067b2019-08-12 22:00:12 +00001071if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001072 NOW="$(date +%s)"
1073 printtime $((NOW - STIME))
David Bainbridgee87067b2019-08-12 22:00:12 +00001074fi
Test Userc13bdc92019-07-03 20:57:49 +00001075
David Bainbridged18f4942020-04-14 16:46:13 -07001076STIME="$(date +%s)"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001077if [ "$DEPLOY_K8S" == "no" ]; then
1078 bspin "Skip Kubernetes/Kind Deployment"
1079 espin $NO_ENTRY
1080else
Test Userba1e7e72019-07-10 22:27:54 +00001081 bspin "Verify Kubernetes/Kind $HELM"
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -08001082 IS_INSTALLED=0
1083 OP_TYPE="install"
David Bainbridged18f4942020-04-14 16:46:13 -07001084 if [ -x "$GOPATH/bin/kind" ]; then
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -08001085 OP_TYPE="upgrade"
David Bainbridged18f4942020-04-14 16:46:13 -07001086 if [ "$("$GOPATH/bin/kind" --version | grep -c "$KIND_VERSION")" -eq 1 ]; then
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -08001087 IS_INSTALLED=1
David Bainbridged18f4942020-04-14 16:46:13 -07001088 espin "$VERIFIED"
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -08001089 fi
1090 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001091 if [ "$IS_INSTALLED" -eq 0 ]; then
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001092 ERR_OUT="$(mktemp)"
David Bainbridged18f4942020-04-14 16:46:13 -07001093 espin "$NOT_VERIFIED"
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -08001094 bspin - "Download and $OP_TYPE Kubernetes/kind $DOWNLOAD"
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001095 (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
1096 RESULT=$?
1097 if [ $RESULT -ne 0 ]; then
1098 espin - "$THEX"
David Bainbridgee3fc0c32020-04-21 15:34:04 -07001099 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR: unable to download kind: $(tail "$ERR_OUT")${NORMAL}"
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001100 cat "$ERR_OUT" >> "$LOG"
1101 rm -rf $"ERR_OUT" "$GOPATH/bin/kind"
1102 exit 1
1103 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001104 (set -x; chmod 755 "$GOPATH/bin/kind" >>"$LOG" 2>&1) >>"$LOG" 2>&1
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001105 rm -rf "$ERR_OUT"
David Bainbridged18f4942020-04-14 16:46:13 -07001106 espin - "$VERIFIED"
Test Userba1e7e72019-07-10 22:27:54 +00001107 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001108fi
1109
David Bainbridgee87067b2019-08-12 22:00:12 +00001110if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001111 NOW="$(date +%s)"
1112 printtime $((NOW - STIME))
David Bainbridgee87067b2019-08-12 22:00:12 +00001113fi
1114
David Bainbridged18f4942020-04-14 16:46:13 -07001115STIME="$(date +%s)"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001116if [ "$INSTALL_HELM" == "no" ]; then
1117 bspin "Skip Helm Install"
1118 espin $NO_ENTRY
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001119else
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001120 bspin "Verify Helm $HELM"
David Bainbridgea34993d2020-04-01 09:15:42 -07001121 HELM_UPGRADE=0
1122 HELM_UPGRADE_DESC="install"
David Bainbridged18f4942020-04-14 16:46:13 -07001123 if [ -x "$GOPATH/bin/helm" ]; then
1124 HAVE_VER="$("$GOPATH/bin/helm" version -c --template '{{.Client.SemVer}}')"
1125 HELM_UP_DOWN="$(echo -e "$HAVE_VER\n$HELM_VERSION" | sort -V | head -1)"
1126 if [ "$HAVE_VER" != "$HELM_VERSION" ]; then
1127 if [ "$HELM_UP_DOWN" == "$HELM_VERSION" ]; then
David Bainbridgea34993d2020-04-01 09:15:42 -07001128 HELM_UPGRADE_DESC="downgrade"
1129 else
1130 HELM_UPGRADE_DESC="upgrade"
1131 fi
1132 HELM_UPGRADE=1
1133 else
David Bainbridged18f4942020-04-14 16:46:13 -07001134 espin "$VERIFIED"
David Bainbridgea34993d2020-04-01 09:15:42 -07001135 fi
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001136 else
David Bainbridgea34993d2020-04-01 09:15:42 -07001137 HELM_UPGRADE=1
1138 fi
1139
David Bainbridged18f4942020-04-14 16:46:13 -07001140 if [ "$HELM_UPGRADE" -ne 0 ]; then
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001141 ERR_OUT="$(mktemp)"
1142 INSTALL_HELM_BIN=$(mktemp)
David Bainbridged18f4942020-04-14 16:46:13 -07001143 espin "$NOT_VERIFIED"
David Bainbridgea34993d2020-04-01 09:15:42 -07001144 bspin - "Download and $HELM_UPGRADE_DESC Helm $DOWNLOAD"
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001145 (set -x; curl -o "$INSTALL_HELM_BIN" --fail -sSL https://git.io/get_helm.sh >>"$LOG" 2>"$ERR_OUT") >>"$LOG" 2>&1
1146 RESULT=$?
1147 if [ $RESULT -ne 0 ]; then
1148 espin - "$THEX"
David Bainbridgee3fc0c32020-04-21 15:34:04 -07001149 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR: unable to download helm installer: $(tail "$ERR_OUT")${NORMAL}"
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001150 cat "$ERR_OUT" >> "$LOG"
1151 rm -rf "$INSTALL_HELM_BIN" "$ERR_OUT" "$GOPATH/bin/helm" "$GOPATH/bin/tiller"
1152 exit 1
1153 fi
1154 rm -rf "$ERR_OUT"
1155 chmod +x "$INSTALL_HELM_BIN"
1156 (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
1157 RESULT=$?
1158 if [ $RESULT -ne 0 ]; then
1159 espin - "$THEX"
1160 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR: unable to install helm, see install log for details${NORMAL}"
1161 rm -rf "$INSTALL_HELM_BIN" "$ERR_OUT" "$GOPATH/bin/helm" "$GOPATH/bin/tiller"
1162 exit 1
1163 fi
1164 rm -rf "$INSTALL_HELM_BIN" "$ERR_OUT"
David Bainbridged18f4942020-04-14 16:46:13 -07001165 espin - "$VERIFIED"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001166 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001167fi
David Bainbridgee87067b2019-08-12 22:00:12 +00001168if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001169 NOW="$(date +%s)"
1170 printtime $((NOW - STIME))
David Bainbridgee87067b2019-08-12 22:00:12 +00001171fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001172
David Bainbridged18f4942020-04-14 16:46:13 -07001173STIME="$(date +%s)"
Test Userb5712372019-07-03 21:52:17 +00001174bspin "Verify voltctl $HIGH_VOLTAGE"
David Bainbridged2811972019-12-14 01:14:09 +00001175VOK=0
1176VMESSAGE="install"
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001177ERR_OUT=$(mktemp)
David K. Bainbridgeebf38d92020-02-10 10:46:31 -08001178export VC_VERSION="$VOLTCTL_VERSION"
1179if [ "$VC_VERSION" == "latest" ]; then
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001180 set -o pipefail # TODO: would be nice to run all in pipefail mode
1181 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')"
1182 RESULT=$?
1183 set +o pipefail
1184 if [ "$RESULT" -ne 0 ]; then
1185 espin - "$THEX"
1186 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR: unable to determine released version of voltctl: $(cat "$ERR_OUT")${NORMAL}"
1187 rm -rf "$ERR_OUT" "$GOPATH/bin/voltctl"
1188 exit 1
1189 fi
1190 export VC_VERSION
David K. Bainbridgeebf38d92020-02-10 10:46:31 -08001191fi
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001192
David Bainbridged18f4942020-04-14 16:46:13 -07001193if [ -x "$GOPATH/bin/voltctl" ]; then
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001194 VHAVE="$("$GOPATH/bin/voltctl" version --clientonly -o json 2>/dev/null | jq -r .version)"
David Bainbridged18f4942020-04-14 16:46:13 -07001195 RESULT=$?
1196 if [ $RESULT -eq 0 ] && [ "$VHAVE" == "$VC_VERSION" ]; then
David Bainbridged2811972019-12-14 01:14:09 +00001197 VOK=1
David Bainbridged18f4942020-04-14 16:46:13 -07001198 espin "$VERIFIED"
David Bainbridge1ba64f12019-12-18 00:40:13 +00001199 else
David Bainbridged18f4942020-04-14 16:46:13 -07001200 VCHECK="$(echo -e "$VHAVE\n$VC_VERSION" | sort -V | head -1)"
David K. Bainbridgeebf38d92020-02-10 10:46:31 -08001201 if [ "$VCHECK" == "$VHAVE" ]; then
1202 VMESSAGE="upgrade"
1203 else
1204 VMESSAGE="downgrade"
1205 fi
David Bainbridged2811972019-12-14 01:14:09 +00001206 fi
1207fi
1208
David Bainbridged18f4942020-04-14 16:46:13 -07001209if [ "$VOK" -eq 0 ]; then
1210 espin "$NOT_VERIFIED"
David Bainbridged2811972019-12-14 01:14:09 +00001211 bspin - "Download and $VMESSAGE voltctl $DOWNLOAD"
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001212 (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
1213 RESULT=$?
1214 if [ $RESULT -ne 0 ]; then
1215 espin - "$THEX"
1216 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR: unable to download voltctl (version $VC_VERSION): $(cat "$ERR_OUT")${NORMAL}"
1217 rm -rf "$ERR_OUT" "$GOPATH/bin/voltctl"
1218 exit 1
1219 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001220 (set -x; chmod 755 "$GOPATH/bin/voltctl" >>"$LOG" 2>&1) >>"$LOG" 2>&1
1221 espin - "$VERIFIED"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001222fi
David Bainbridgee40e6ef2020-04-21 13:15:58 -07001223rm -rf "$ERR_OUT"
David Bainbridgee87067b2019-08-12 22:00:12 +00001224if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001225 NOW="$(date +%s)"
1226 printtime $((NOW - STIME))
David Bainbridgee87067b2019-08-12 22:00:12 +00001227fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001228
1229bspin "Verify command PATH"
Test Userba1e7e72019-07-10 22:27:54 +00001230export PATH=$GOPATH/bin:$PATH
David Bainbridged18f4942020-04-14 16:46:13 -07001231espin "$VERIFIED"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001232
David Bainbridged18f4942020-04-14 16:46:13 -07001233STIME="$(date +%s)"
Test Userba1e7e72019-07-10 22:27:54 +00001234if [ "$DEPLOY_K8S" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001235 HAVE="$(kind get clusters | grep -c "voltha-$NAME")"
Test Userba1e7e72019-07-10 22:27:54 +00001236 bspin "Verify Kubernetes/Kind Cluster"
1237 sspin
David Bainbridged18f4942020-04-14 16:46:13 -07001238 if [ "$HAVE" -eq 0 ]; then
1239 espin "$NOT_VERIFIED"
David Bainbridge491b1bd2019-07-11 17:53:11 +00001240 bspin - "Verify cluster configuration"
David Bainbridged18f4942020-04-14 16:46:13 -07001241 if [ ! -r "./$NAME-cluster.cfg" ]; then
1242 espin - "$NOT_VERIFIED"
David K. Bainbridge43422402020-03-06 07:41:22 -08001243 bspin - "Download cluster configuration: $TYPE-cluster.cfg to $NAME-cluster.cfg $DOWNLOAD"
David Bainbridged18f4942020-04-14 16:46:13 -07001244 ERR_OUT="$(mktemp)"
serkant.uluderya4d315132020-04-15 16:25:54 -07001245 if ! (set -x; curl --fail -o "./$NAME-cluster.cfg" -sSL "https://raw.githubusercontent.com/opencord/kind-voltha/$VK_RELEASE/$TYPE-cluster.cfg" >>"$LOG" 2>>"$ERR_OUT") >>"$LOG" 2>&1; then
David Bainbridged18f4942020-04-14 16:46:13 -07001246 espin - "$THEX"
1247 echo -e "${RED}${BOLD}${ERROR}ERROR: $NAME-cluster.cfg${NORMAL}${RED} - $(cat "$ERR_OUT")${NORMAL}"
1248 echo "ERROR: $(cat "$ERR_OUT")" >>"$LOG"
1249 rm -rf "$ERR_OUT" "./$NAME-cluster.cfg"
David K. Bainbridgea00736b2020-01-08 14:33:17 -08001250 exit 1
1251 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001252 rm -rf "$ERR_OUT"
David K. Bainbridgea00736b2020-01-08 14:33:17 -08001253 else
David Bainbridged18f4942020-04-14 16:46:13 -07001254 espin - "$VERIFIED"
David K. Bainbridgea00736b2020-01-08 14:33:17 -08001255 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001256 kind create cluster --name "voltha-$NAME" --config "$NAME-cluster.cfg"
David Bainbridge491b1bd2019-07-11 17:53:11 +00001257 else
David Bainbridged18f4942020-04-14 16:46:13 -07001258 espin "$VERIFIED"
Test Userba1e7e72019-07-10 22:27:54 +00001259 fi
1260
David Bainbridged18f4942020-04-14 16:46:13 -07001261 KUBECONFIG="$(kind get kubeconfig-path --name="voltha-$NAME")"; export KUBECONFIG
Test Userba1e7e72019-07-10 22:27:54 +00001262 P="coredns-.* \
David Bainbridge0774b232019-08-02 06:37:19 +00001263 etcd-voltha-$NAME-control-plane \
Test Userba1e7e72019-07-10 22:27:54 +00001264 kindnet-.* \
David Bainbridge0774b232019-08-02 06:37:19 +00001265 kube-apiserver-voltha-$NAME-control-plane \
1266 kube-controller-manager-voltha-$NAME-control-plane \
Test Userba1e7e72019-07-10 22:27:54 +00001267 kube-proxy-.* \
David Bainbridge0774b232019-08-02 06:37:19 +00001268 kube-scheduler-voltha-$NAME-control-plane"
Test Userba1e7e72019-07-10 22:27:54 +00001269
David Bainbridged18f4942020-04-14 16:46:13 -07001270 EXPECT="$(test "$TYPE" == "minimal" && echo "12" || echo "14")"
1271 wait_for_pods - "kube-system" "$EXPECT" "includes" "Waiting for system PODs to start" "$NO_LABEL" "$P"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001272fi
David Bainbridgee87067b2019-08-12 22:00:12 +00001273if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001274 NOW="$(date +%s)"
1275 printtime $((NOW - STIME))
David Bainbridgee87067b2019-08-12 22:00:12 +00001276fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001277
David Bainbridged18f4942020-04-14 16:46:13 -07001278STIME="$(date +%s)"
1279COUNT="$(count_pods "kube-system" ":Running:" "$NO_LABEL" "tiller-deploy-.*")"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001280bspin "Verify Helm"
David Bainbridged18f4942020-04-14 16:46:13 -07001281if [ "$COUNT" -ne 1 ]; then
1282 espin "$NOT_VERIFIED"
Test Userb5712372019-07-03 21:52:17 +00001283 echo -e "Configuring Helm $GEAR"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001284 if [ "$INSTALL_HELM" == "no" ]; then
1285 bspin - "Skip Helm/Tiller Initialization"
1286 espin - $NO_ENTRY
1287 else
1288 bspin - "Initialize Helm"
David Bainbridged18f4942020-04-14 16:46:13 -07001289 (set -x; helm init --upgrade >>"$LOG" 2>&1) >>"$LOG" 2>&1
1290 espin - "$VERIFIED"
1291 wait_for_pods - "kube-system" 1 "includes" "Waiting for Tiller POD to start" "$NO_LABEL" "tiller-deploy-.*"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001292 fi
Test Userb5712372019-07-03 21:52:17 +00001293 bspin - "Add Google Incubator repository to Helm"
David Bainbridged18f4942020-04-14 16:46:13 -07001294 (set -x; helm repo add incubator https://kubernetes-charts-incubator.storage.googleapis.com >>"$LOG" 2>&1) >>"$LOG" 2>&1
1295 espin - "$VERIFIED"
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001296
Test Userba1e7e72019-07-10 22:27:54 +00001297 # HACK (sort-of) - the config for tiller is about to be patched, which will
1298 # cause the tiller pod to be recreated. This can sometimes cause a timing
1299 # issue with the "wait_for_pods" call on tiller as it may incorrectly
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001300 # identify the running/ready tiller pod that is soon to be terminated as
Test Userba1e7e72019-07-10 22:27:54 +00001301 # what it is waiting for. To avoid this issue we do a clean scale down and
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001302 # scale up of the pod so the script controlls when it should be expecting
Test Userba1e7e72019-07-10 22:27:54 +00001303 # things
David Bainbridged18f4942020-04-14 16:46:13 -07001304 (set -x; kubectl -n kube-system scale deploy tiller-deploy --replicas=0 >>"$LOG" 2>&1) >>"$LOG" 2>&1
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001305
Test Userb5712372019-07-03 21:52:17 +00001306 bspin - "Add Google Stable repository to Helm"
David Bainbridged18f4942020-04-14 16:46:13 -07001307 (set -x; helm repo add stable https://kubernetes-charts.storage.googleapis.com >>"$LOG" 2>&1) >>"$LOG" 2>&1
1308 espin - "$VERIFIED"
Test Userb5712372019-07-03 21:52:17 +00001309 bspin - "Add ONF repository to Helm"
David Bainbridged18f4942020-04-14 16:46:13 -07001310 (set -x; helm repo add onf https://charts.opencord.org >>"$LOG" 2>&1) >>"$LOG" 2>&1
1311 espin - "$VERIFIED"
Test Userb5712372019-07-03 21:52:17 +00001312 bspin - "Update Helm repository cache"
David Bainbridged18f4942020-04-14 16:46:13 -07001313 (set -x; helm repo update >>"$LOG" 2>&1) >>"$LOG" 2>&1
1314 espin - "$VERIFIED"
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001315
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001316 # Create and k8s service account so that Helm can create pods
Test Userb5712372019-07-03 21:52:17 +00001317 bspin - "Create Tiller ServiceAccount"
David Bainbridged18f4942020-04-14 16:46:13 -07001318 (set -x; kubectl create serviceaccount --namespace kube-system tiller >>"$LOG" 2>&1) >>"$LOG" 2>&1
1319 espin - "$VERIFIED"
Test Userb5712372019-07-03 21:52:17 +00001320 bspin - "Create Tiller ClusterRoleBinding"
David Bainbridged18f4942020-04-14 16:46:13 -07001321 (set -x; kubectl create clusterrolebinding tiller-cluster-rule --clusterrole=cluster-admin --serviceaccount=kube-system:tiller >>"$LOG" 2>&1) >>"$LOG" 2>&1
1322 espin - "$VERIFIED"
Test Userb5712372019-07-03 21:52:17 +00001323 bspin - "Update Tiller Manifest"
David Bainbridged18f4942020-04-14 16:46:13 -07001324 (set -x; kubectl patch deploy --namespace kube-system tiller-deploy -p '{"spec":{"template":{"spec":{"serviceAccount":"tiller"}}}}' >>"$LOG" 2>&1) >>"$LOG" 2>&1
Test Userba1e7e72019-07-10 22:27:54 +00001325
1326 # HACK (sort-of) - part to, spin it back up
David Bainbridged18f4942020-04-14 16:46:13 -07001327 (set -x; kubectl -n kube-system scale deploy tiller-deploy --replicas=1 >>"$LOG" 2>&1) >>"$LOG" 2>&1
1328 espin - "$VERIFIED"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001329else
David Bainbridged18f4942020-04-14 16:46:13 -07001330 if [ "$(helm version -s --template '{{.Server.SemVer}}')" != "$HELM_VERSION" ]; then
1331 espin "$NOT_VERIFIED"
David Bainbridgea34993d2020-04-01 09:15:42 -07001332 bspin - "Sync Tiller server version with helm client"
David Bainbridged18f4942020-04-14 16:46:13 -07001333 (set -x; helm init --upgrade --force-upgrade --wait >>"$LOG" 2>&1) >>"$LOG" 2>&1
1334 espin - "$VERIFIED"
David Bainbridgea34993d2020-04-01 09:15:42 -07001335 else
David Bainbridged18f4942020-04-14 16:46:13 -07001336 espin "$VERIFIED"
David Bainbridgea34993d2020-04-01 09:15:42 -07001337 fi
1338
David Bainbridge46505fb2019-10-01 21:13:20 +00001339 if [ "$UPDATE_HELM_REPOS" == "yes" ]; then
1340 bspin - "Update Helm repository cache"
David Bainbridged18f4942020-04-14 16:46:13 -07001341 (set -x; helm repo update >>"$LOG" 2>&1) >>"$LOG" 2>&1
1342 espin - "$VERIFIED"
David Bainbridge46505fb2019-10-01 21:13:20 +00001343 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001344fi
David Bainbridged18f4942020-04-14 16:46:13 -07001345wait_for_pods - "kube-system" 1 "includes" "Waiting for Tiller POD to start" "$NO_LABEL" "tiller-deploy-.*"
David Bainbridgee87067b2019-08-12 22:00:12 +00001346if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001347 NOW="$(date +%s)"
1348 printtime $((NOW - STIME))
David Bainbridgee87067b2019-08-12 22:00:12 +00001349fi
David Bainbridgecf546362020-04-21 23:18:50 -07001350# Resolve chart versions and log them for debug/support
1351RESOLVED_VOLTHA_CHART_VERSION=$(resolve_chart_version "$VOLTHA_CHART" "$VOLTHA_CHART_VERSION")
1352RESOLVED_VOLTHA_BBSIM_CHART_VERSION=$(resolve_chart_version "$VOLTHA_BBSIM_CHART" "$VOLTHA_BBSIM_CHART_VERSION")
1353RESOLVED_VOLTHA_ADAPTER_SIM_CHART_VERSION=$(resolve_chart_version "$VOLTHA_ADAPTER_SIM_CHART" "$VOLTHA_ADAPTER_SIM_CHART_VERSION")
1354RESOLVED_VOLTHA_ADAPTER_OPEN_OLT_CHART_VERSION=$(resolve_chart_version "$VOLTHA_ADAPTER_OPEN_OLT_CHART" "$VOLTHA_ADAPTER_OPEN_OLT_CHART_VERSION")
1355RESOLVED_VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION=$(resolve_chart_version "$VOLTHA_ADAPTER_OPEN_ONU_CHART" "$VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION")
1356RESOLVED_ONOS_CHART_VERSION=$(resolve_chart_version "$ONOS_CHART" "$ONOS_CHART_VERSION")
1357RESOLVED_KAFKA_CHART_VERSION=$(resolve_chart_version "$KAFKA_CHART" "$KAFKA_CHART_VERSION")
1358cat <<EOV >>"$LOG"
1359Resolved helm charts and versions:
1360 $VOLTHA_CHART:$RESOLVED_VOLTHA_CHART_VERSION
1361 $VOLTHA_BBSIM_CHART:$RESOLVED_VOLTHA_BBSIM_CHART_VERSION
1362 $VOLTHA_ADAPTER_SIM_CHART:$RESOLVED_VOLTHA_ADAPTER_SIM_CHART_VERSION
1363 $VOLTHA_ADAPTER_OPEN_OLT_CHART:$RESOLVED_VOLTHA_ADAPTER_OPEN_OLT_CHART_VERSION
1364 $VOLTHA_ADAPTER_OPEN_ONU_CHART:$RESOLVED_VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION
1365 $ONOS_CHART:$RESOLVED_ONOS_CHART_VERSION
1366 $KAFKA_CHART:$RESOLVED_KAFKA_CHART_VERSION
1367EOV
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001368
David Bainbridged18f4942020-04-14 16:46:13 -07001369STIME="$(date +%s)"
David Bainbridge0774b232019-08-02 06:37:19 +00001370bspin "Verify Helm values file: $NAME-values.yaml"
1371if [ ! -r "./$NAME-values.yaml" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001372 espin "$NOT_VERIFIED"
David Bainbridge0774b232019-08-02 06:37:19 +00001373 bspin - "Download Helm values file: $TYPE-values.yaml to $NAME-values.yaml $DOWNLOAD"
David Bainbridged18f4942020-04-14 16:46:13 -07001374 ERR_OUT="$(mktemp)"
serkant.uluderya4d315132020-04-15 16:25:54 -07001375 if ! (set -x; curl --fail -o "./$NAME-values.yaml" -sSL "https://raw.githubusercontent.com/opencord/kind-voltha/$VK_RELEASE/$TYPE-values.yaml" >>"$LOG" 2>"$ERR_OUT") >>"$LOG" 2>&1; then
David Bainbridged18f4942020-04-14 16:46:13 -07001376 espin - "$THEX"
1377 echo -e "${RED}${BOLD}${ERROR}ERROR: $NAME-values.yaml${NORMAL}${RED} - $(cat "$ERR_OUT")${NORMAL}"
1378 echo "ERROR: $(cat "$ERR_OUT")" >>"$LOG"
1379 rm -rf "$ERR_OUT" "./$NAME-values.yaml"
David K. Bainbridgea00736b2020-01-08 14:33:17 -08001380 exit 1
1381 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001382 rm -rf "$ERR_OUT"
1383 espin - "$VERIFIED"
Test Userba1e7e72019-07-10 22:27:54 +00001384else
David Bainbridged18f4942020-04-14 16:46:13 -07001385 espin "$VERIFIED"
Test Userba1e7e72019-07-10 22:27:54 +00001386fi
David Bainbridgee87067b2019-08-12 22:00:12 +00001387if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001388 NOW="$(date +%s)"
1389 printtime $((NOW - STIME))
David Bainbridgee87067b2019-08-12 22:00:12 +00001390fi
Test Userba1e7e72019-07-10 22:27:54 +00001391
David Bainbridged18f4942020-04-14 16:46:13 -07001392STIME="$(date +%s)"
David Bainbridge99ac7a22019-08-31 02:26:43 +00001393bspin "Verify or download chart specific values files $DOWNLOAD"
1394VALUES_FILES="monkey-values.yaml"
David Bainbridged18f4942020-04-14 16:46:13 -07001395ERR_OUT="$(mktemp)"
David Bainbridge99ac7a22019-08-31 02:26:43 +00001396for i in $VALUES_FILES; do
1397 if [ ! -r ./$i ]; then
serkant.uluderya4d315132020-04-15 16:25:54 -07001398 if ! (set -x; curl --fail -o "./$i" -sSL "https://raw.githubusercontent.com/opencord/kind-voltha/$VK_RELEASE/$i" >>"$LOG" 2>"$ERR_OUT") >>"$LOG" 2>&1; then
David Bainbridged18f4942020-04-14 16:46:13 -07001399 espin "$THEX"
1400 echo -e "${RED}${BOLD}${ERROR}ERROR: $i${NORMAL}${RED} - $(cat "$ERR_OUT")${NORMAL}"
1401 echo "ERROR: $i - $(cat "$ERR_OUT")" >>"$LOG"
1402 rm -rf "$ERR_OUT" "./$i"
David K. Bainbridgea00736b2020-01-08 14:33:17 -08001403 exit 1
1404 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001405 rm -rf "$ERR_OUT"
David Bainbridge99ac7a22019-08-31 02:26:43 +00001406 fi
1407done
David Bainbridged18f4942020-04-14 16:46:13 -07001408rm -rf "$ERR_OUT"
1409espin "$VERIFIED"
David Bainbridge99ac7a22019-08-31 02:26:43 +00001410if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001411 NOW="$(date +%s)"
1412 printtime $((NOW - STIME))
David Bainbridge99ac7a22019-08-31 02:26:43 +00001413fi
1414
1415if [ "$WITH_CHAOS" == "yes" ]; then
1416 bspin "Verify or clone kube-monkey helm chart $DOWNLOAD"
1417 if [ -r ./kube-monkey ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001418 espin "$VERIFIED"
David Bainbridge99ac7a22019-08-31 02:26:43 +00001419 else
David Bainbridged18f4942020-04-14 16:46:13 -07001420 espin "$NOT_VERIFIED"
David Bainbridge99ac7a22019-08-31 02:26:43 +00001421 bspin - "GIT clone kube-monkey"
David Bainbridged18f4942020-04-14 16:46:13 -07001422 (set -x; git clone https://github.com/asobti/kube-monkey kube-monkey >>"$LOG" 2>&1) >>"$LOG" 2>&1
1423 espin - "$VERIFIED"
David Bainbridge99ac7a22019-08-31 02:26:43 +00001424 fi
1425fi
1426
Test Userba1e7e72019-07-10 22:27:54 +00001427if [ "$JUST_K8S" == "yes" ]; then
1428 echo "Environment deployed, not deploying VOLTHA artifacts as requested. Good bye."
1429 echo ""
David Bainbridged18f4942020-04-14 16:46:13 -07001430 echo "Please issue the following commands in your terminal to ensure that you" | tee -a "$LOG"
1431 echo "are accessing the correct Kubernetes/Kind cluster as well as have the " | tee -a "$LOG"
1432 echo "tools required by VOLTHA in your command path. " | tee -a "$LOG"
1433 echo "" | tee -a "$LOG"
1434 echo -en "$BOLD"
1435 if [ "$DEPLOY_K8S" == "yes" ]; then
1436 echo "export KUBECONFIG=\"\$(./bin/kind get kubeconfig-path --name=\"voltha-$NAME\")\"" | tee -a "$LOG"
Test Userba1e7e72019-07-10 22:27:54 +00001437 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001438 echo "export PATH=$GOPATH/bin:\$PATH" | tee -a "$LOG"
1439 echo -en "$NORMAL"
1440 echo "" | tee -a "$LOG"
1441 echo "Thank you for choosing kind-voltha for you quick cluster needs." | tee -a "$LOG"
Test Userba1e7e72019-07-10 22:27:54 +00001442 exit 0
1443fi
1444
David Bainbridged18f4942020-04-14 16:46:13 -07001445if [ "$WITH_ETCD" != "yes" ] && [ "$WITH_ETCD" != "external" ]; then
David Bainbridge696bc632020-04-05 21:49:37 -07001446 bspin "Skip ETCD Operator Deployment"
1447 espin $NO_ENTRY
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001448else
David Bainbridged18f4942020-04-14 16:46:13 -07001449 STIME="$(date +%s)"
David Bainbridge76afd812020-04-06 09:53:52 -07001450 NS=$VOLTHA_NS
David Bainbridged18f4942020-04-14 16:46:13 -07001451 if [ "$WITH_ETCD" == "external" ]; then
David Bainbridge76afd812020-04-06 09:53:52 -07001452 NS=$INFRA_NS
1453 fi
David Bainbridge696bc632020-04-05 21:49:37 -07001454 bspin "Verify ETCD Operator $OLD_KEY"
David Bainbridged18f4942020-04-14 16:46:13 -07001455 if [ "$HELM_USE_UPGRADE" == "yes" ] || [ "$(helm list --deployed --short --namespace "$NS" "^etcd-operator\$" | wc -l)" -ne 1 ]; then
1456 espin "$NOT_VERIFIED"
1457 helm_install - "$NS" etcd-operator stable/etcd-operator latest "$_HELM_DESC ETCD Operator"
David Bainbridge696bc632020-04-05 21:49:37 -07001458 else
David Bainbridged18f4942020-04-14 16:46:13 -07001459 espin "$VERIFIED"
David Bainbridge696bc632020-04-05 21:49:37 -07001460 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001461 EXPECT="$(test "$TYPE" == "minimal" && echo "1" || echo "3")"
1462 wait_for_pods - "$NS" "$EXPECT" "includes" "Waiting for ETCD Operator to start" "$NO_LABEL" "etcd-operator-.*"
David Bainbridge696bc632020-04-05 21:49:37 -07001463 if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridged18f4942020-04-14 16:46:13 -07001464 NOW="$(date +%s)"
1465 printtime $((NOW - STIME))
David Bainbridge696bc632020-04-05 21:49:37 -07001466 fi
David Bainbridgee87067b2019-08-12 22:00:12 +00001467fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001468
David Bainbridged18f4942020-04-14 16:46:13 -07001469STIME="$(date +%s)"
1470if [ "$WITH_ONOS" == "yes" ]; then
David Bainbridgeb270c202019-07-26 01:44:42 +00001471 bspin "Verify ONOS installed $BIRD"
David Bainbridged18f4942020-04-14 16:46:13 -07001472 if [ "$HELM_USE_UPGRADE" == "yes" ] || [ "$(helm list --deployed --short --namespace "$INFRA_NS" "^onos\$" | wc -l)" -ne 1 ]; then
1473 espin "$NOT_VERIFIED"
1474 EXTRA_HELM_FLAGS="$SET_TAG $EXTRA_HELM_FLAGS" helm_install - "$INFRA_NS" onos "$ONOS_CHART" "$ONOS_CHART_VERSION" "$_HELM_DESC ONOS"
David Bainbridgeb270c202019-07-26 01:44:42 +00001475 else
David Bainbridged18f4942020-04-14 16:46:13 -07001476 espin "$VERIFIED"
David Bainbridgeb270c202019-07-26 01:44:42 +00001477 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001478 wait_for_pods - "$INFRA_NS" 1 "includes" "Waiting for ONOS to start" "$NO_LABEL" "onos-.*"
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001479
David Bainbridged18f4942020-04-14 16:46:13 -07001480 if [ "$WITH_PORT_FORWARDS" == "yes" ]; then
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -08001481 bspin - "Forward ONOS API port $FORWARD"
1482 kill_port_forward onos-ui
David Bainbridged18f4942020-04-14 16:46:13 -07001483 port_forward "$INFRA_NS" onos-ui "$ONOS_API_PORT" 8181
1484 espin - "$VERIFIED"
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -08001485 bspin - "Forward ONOS SSH port $FORWARD"
1486 kill_port_forward onos-ssh
David Bainbridged18f4942020-04-14 16:46:13 -07001487 port_forward "$INFRA_NS" onos-ssh "$ONOS_SSH_PORT" 8101
1488 espin - "$VERIFIED"
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -08001489 _ONOS_API_EP="127.0.0.1:$ONOS_API_PORT"
1490 else
David Bainbridged18f4942020-04-14 16:46:13 -07001491 _ONOS_API_EP="$(get_service_ep "$INFRA_NS" onos-ui)"
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -08001492 fi
David Bainbridged31d6122019-08-13 19:37:59 +00001493 bspin - "Verify or download ONOS configuration support files $DOWNLOAD"
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001494 ONOS_FILES="olt-onos-enableExtraneousRules.json onos-aaa.json \
David Bainbridge696bc632020-04-05 21:49:37 -07001495 onos-dhcpl2relay.json onos-sadis-sample.json"
David Bainbridged18f4942020-04-14 16:46:13 -07001496 (set -x; mkdir -p ./onos-files >>"$LOG" 2>&1) >>"$LOG" 2>&1
1497 ERR_OUT="$(mktemp)"
David Bainbridge2b19e832019-08-16 02:40:53 +00001498 for i in $ONOS_FILES; do
David Bainbridged18f4942020-04-14 16:46:13 -07001499 if [ ! -r "./onos-files/$i" ]; then
serkant.uluderya4d315132020-04-15 16:25:54 -07001500 if ! (set -x; curl --fail -o "./onos-files/$i" -sSL "https://raw.githubusercontent.com/opencord/kind-voltha/$VK_RELEASE/onos-files/$i" >>"$LOG" 2>"$ERR_OUT") >>"$LOG" 2>&1; then
David Bainbridged18f4942020-04-14 16:46:13 -07001501 espin - "$THEX"
1502 echo -e "${RED}${BOLD}${ERROR}ERROR: $i${NORMAL}${RED} - $(cat "$ERR_OUT")${NORMAL}"
1503 echo "ERROR: $(cat "$ERR_OUT")" >>"$LOG"
1504 rm -rf "$ERR_OUT" "./onos-files/$i"
David K. Bainbridgea00736b2020-01-08 14:33:17 -08001505 exit 1
1506 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001507 rm -rf "$ERR_OUT"
David Bainbridged31d6122019-08-13 19:37:59 +00001508 fi
1509 done
David Bainbridged18f4942020-04-14 16:46:13 -07001510 rm -rf "$ERR_OUT"
1511 espin - "$VERIFIED"
David Bainbridge27790d62019-08-13 22:43:19 +00001512
David Bainbridged18f4942020-04-14 16:46:13 -07001513 if [ "$INSTALL_ONOS_APPS" == "yes" ]; then
David Bainbridge27790d62019-08-13 22:43:19 +00001514 bspin - "Installing custom ONOS applications"
David Bainbridged18f4942020-04-14 16:46:13 -07001515 if [ -x onos-files/onos-apps ] && [ "$(find onos-files/onos-apps -name "*.oar" 2>/dev/null | wc -l)" -gt 0 ]; then
1516 for OAR in onos-files/onos-apps/*.oar; do
David Bainbridge27790d62019-08-13 22:43:19 +00001517 sspin - "Installing custom ONOS applications - $OAR$CEOL"
David Bainbridged18f4942020-04-14 16:46:13 -07001518 override_onos_app "$OAR"
David Bainbridge27790d62019-08-13 22:43:19 +00001519 done
1520 espin - "$VERIFIED Installing custom ONOS applications$CEOL"
1521 else
1522 espin - "$NOT_VERIFIED Installing custom ONOS applications - None Found"
1523 fi
1524 fi
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001525
David Bainbridged18f4942020-04-14 16:46:13 -07001526 if [ "$WITH_KAFKA" != "no" ]; then
David Bainbridge837e8bd2020-04-06 13:17:14 -07001527 check_onos_app_active org.opencord.kafka
David Bainbridge76afd812020-04-06 09:53:52 -07001528 _HOST=voltha-kafka.$INFRA_NS.svc.cluster.local
David Bainbridge837e8bd2020-04-06 13:17:14 -07001529 _PORT=9092
David Bainbridged18f4942020-04-14 16:46:13 -07001530 if [ "$WITH_KAFKA" == "yes" ]; then
David Bainbridge76afd812020-04-06 09:53:52 -07001531 _HOST=voltha-kafka.$VOLTHA_NS.svc.cluster.local
1532 _PORT=9092
David Bainbridged18f4942020-04-14 16:46:13 -07001533 elif [ "$WITH_KAFKA" == "external" ]; then
David Bainbridge76afd812020-04-06 09:53:52 -07001534 _HOST=kafka.$INFRA_NS.svc.cluster.local
1535 _PORT=9092
1536 else
David Bainbridged18f4942020-04-14 16:46:13 -07001537 _HOST="$(echo "$WITH_KAFKA" | cut -d: -f1)"
1538 _PORT="$(echo "$WITH_KAFKA" | cut -s -d: -f2)"
David Bainbridge837e8bd2020-04-06 13:17:14 -07001539 _PORT=${_PORT:-9092}
1540 fi
1541 push_onos_config "json" "Push ONOS Kafka Configuration" "network/configuration/apps/org.opencord.kafka" \
David Bainbridged18f4942020-04-14 16:46:13 -07001542 "$(cat <<EOJ | tr -d '[:space:]'
David Bainbridge696bc632020-04-05 21:49:37 -07001543{
1544 "kafka": {
1545 "bootstrapServers": "$_HOST:$_PORT"
1546 }
1547}
1548EOJ
David Bainbridged18f4942020-04-14 16:46:13 -07001549)"
David Bainbridge837e8bd2020-04-06 13:17:14 -07001550 fi
Matteo Scandolo9a77a732020-01-09 14:24:12 -08001551 check_onos_app_active org.opencord.dhcpl2relay
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001552 push_onos_config "file" "Push ONOS DHCP L2 Relay Configuration" "network/configuration/apps/org.opencord.dhcpl2relay" "onos-files/onos-dhcpl2relay.json"
Matteo Scandolo9a77a732020-01-09 14:24:12 -08001553 check_onos_app_active org.opencord.olt
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001554 # FIXME use WITH_DHCP and WITH_EAPOL flags to configre OLT App
Hardik Windlassa7501fb2020-02-17 14:28:20 +00001555 # Default value for "enableEapol" is true in OLT App
David Bainbridged18f4942020-04-14 16:46:13 -07001556 if [ "$WITH_EAPOL" == "yes" ]; then
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001557 push_onos_config "json" "Enable VOLTHA ONOS EAPOL provisioning" "configuration/org.opencord.olt.impl.OltFlowService" '{"enableEapol":true}'
David Bainbridged18f4942020-04-14 16:46:13 -07001558 elif [ "$WITH_EAPOL" == "no" ]; then
Hardik Windlassa7501fb2020-02-17 14:28:20 +00001559 push_onos_config "json" "Disable VOLTHA ONOS EAPOL provisioning" "configuration/org.opencord.olt.impl.OltFlowService" '{"enableEapol":false}'
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001560 fi
Hardik Windlassa7501fb2020-02-17 14:28:20 +00001561 # Default value for "enableDhcpOnProvisioning" is false and for "enableDhcpV4" is true in OLT App
David Bainbridged18f4942020-04-14 16:46:13 -07001562 if [ "$WITH_DHCP" == "yes" ]; then
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001563 push_onos_config "json" "Enable VOLTHA ONOS DHCP provisioning" "configuration/org.opencord.olt.impl.OltFlowService" '{"enableDhcpOnProvisioning":true,"enableDhcpV4":true}'
David Bainbridged18f4942020-04-14 16:46:13 -07001564 elif [ "$WITH_DHCP" == "no" ]; then
Hardik Windlassa7501fb2020-02-17 14:28:20 +00001565 push_onos_config "json" "Disable VOLTHA ONOS DHCP provisioning" "configuration/org.opencord.olt.impl.OltFlowService" '{"enableDhcpOnProvisioning":false,"enableDhcpV4":false}'
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001566 fi
Hardik Windlassa7501fb2020-02-17 14:28:20 +00001567 # Default value for "enableIgmpOnProvisioning" is false in OLT App
David Bainbridged18f4942020-04-14 16:46:13 -07001568 if [ "$WITH_IGMP" == "yes" ]; then
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001569 push_onos_config "json" "Enable VOLTHA ONOS IGMP provisioning" "configuration/org.opencord.olt.impl.OltFlowService" '{"enableIgmpOnProvisioning":true}'
David Bainbridged18f4942020-04-14 16:46:13 -07001570 elif [ "$WITH_IGMP" == "no" ]; then
Hardik Windlassa7501fb2020-02-17 14:28:20 +00001571 push_onos_config "json" "Disable VOLTHA ONOS IGMP provisioning" "configuration/org.opencord.olt.impl.OltFlowService" '{"enableIgmpOnProvisioning":false}'
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001572 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001573 if [ "$ENABLE_ONOS_EXTRANEOUS_RULES" == "yes" ]; then
David K. Bainbridge484d80c2020-03-05 21:44:34 -08001574 push_onos_config "file" "Enabling extraneous rules for ONOS" "configuration/org.onosproject.net.flow.impl.FlowRuleManager" "onos-files/olt-onos-enableExtraneousRules.json"
1575 fi
David Bainbridged18f4942020-04-14 16:46:13 -07001576 if [ "$(echo ":yes:file:" | grep -c ":$CONFIG_SADIS:")" -eq 1 ]; then
Matteo Scandolo9a77a732020-01-09 14:24:12 -08001577 check_onos_app_active org.opencord.sadis
Hardik Windlassb3147602020-03-09 16:59:15 +05301578 push_onos_config "file" "[optional] Push ONOS SADIS Configuration: $SADIS_CFG" "network/configuration/apps/org.opencord.sadis" "$SADIS_CFG"
David K. Bainbridgeb859e912020-03-13 14:07:52 -07001579 elif [ "$CONFIG_SADIS" == "bbsim" ]; then
1580 push_onos_config "json" \
1581 "[optional] Push ONOS configuration for BBSIM SADIS servers" \
1582 "network/configuration/apps/org.opencord.sadis" \
David Bainbridged18f4942020-04-14 16:46:13 -07001583 "$(cat <<EOJ | tr -d '[:space:]'
David K. Bainbridgeb859e912020-03-13 14:07:52 -07001584{
1585 "sadis": {
1586