blob: f4e87d0733e2ecc4a367ef09a25f4a07e1c849ff [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 Bainbridge712afb82019-08-14 19:55:58 +000016TOTAL_START_TIME=$(date +%s)
David K. Bainbridgeb7285432019-07-02 22:05:24 -070017
David Bainbridge38dc1e82019-08-12 15:18:45 +000018FANCY=${FANCY:-1}
19if [ "$TERM X" == " X" ]; then
20 FANCY=0
21fi
22
David K. Bainbridgeb7285432019-07-02 22:05:24 -070023# trap ctrl-c and call ctrl_c()
24trap ctrl_c INT
25
26function ctrl_c() {
David Bainbridge38dc1e82019-08-12 15:18:45 +000027 echo -en $CNORM
David K. Bainbridgeb7285432019-07-02 22:05:24 -070028 echo ""
29 echo "ctrl-c trapped"
David Bainbridgec6a6eb62019-10-18 22:50:07 +000030 echo "Thank you for trying 'voltha up'"
David K. Bainbridgeb7285432019-07-02 22:05:24 -070031 exit
32}
33
David Bainbridgea34993d2020-04-01 09:15:42 -070034HELM_VERSION=${HELM_VERSION:-v2.14.3}
David K. Bainbridgeebf38d92020-02-10 10:46:31 -080035VOLTCTL_VERSION=${VOLTCTL_VERSION:-latest}
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -080036KIND_VERSION=${KIND_VERSION:-v0.5.1}
David K. Bainbridgeb3a99372020-01-08 14:39:06 -080037VK_RELEASE=${VK_RELEASE:-master}
Test User08ebbd92019-07-03 17:15:39 +000038
David Bainbridge38dc1e82019-08-12 15:18:45 +000039BLACK=
40RED=
41GREEN=
42YELLOW=
43BLUE=
44MAGENTA=
45CYAN=
46WHITE=
47BOLD=
48NORMAL=
49ERROR=
50CEOL=
51CNORM=
52CIVIS=
53if [ $FANCY -eq 1 ]; then
54 BLACK=$(tput setaf 0)
55 RED=$(tput setaf 1)
56 GREEN=$(tput setaf 2)
57 YELLOW=$(tput setaf 3)
58 BLUE=$(tput setaf 4)
59 MAGENTA=$(tput setaf 5)
60 CYAN=$(tput setaf 6)
61 WHITE=$(tput setaf 7)
62 BOLD=$(tput bold)
63 NORMAL=$(tput sgr0)
64 ERROR="\xe2\x9c\x97\x20"
65 CEOL=$(tput el)
66 CNORM=$(tput cnorm)
67 CIVIS=$(tput civis)
68fi
Test User7d866122019-07-09 17:52:35 +000069
Test User3d7ad8e2019-07-03 06:15:44 +000070TYPE=${TYPE:-minimal}
David Bainbridge0774b232019-08-02 06:37:19 +000071NAME=${NAME:-$TYPE}
David K. Bainbridge484d80c2020-03-05 21:44:34 -080072
73ENABLE_ONOS_EXTRANEOUS_RULES=${ENABLE_ONOS_EXTRANEOUS_RULES:-no}
David Bainbridge76afd812020-04-06 09:53:52 -070074INFRA_NS=${INFRA_NS:-default}
75VOLTHA_NS=${VOLTHA_NS:-voltha}
76BBSIM_NS=${BBSIM_NS:-voltha}
77ADAPTER_NS=${ADAPTER_NS:-voltha}
David Bainbridgee87067b2019-08-12 22:00:12 +000078WITH_TIMINGS=${WITH_TIMINGS:-no}
Test User7d866122019-07-09 17:52:35 +000079WITH_BBSIM=${WITH_BBSIM:-no}
David Bainbridge5b7b96b2019-07-25 20:29:13 +000080WITH_RADIUS=${WITH_RADIUS:-no}
Matteo Scandolo78dfee02020-02-13 16:18:03 -080081WITH_EAPOL=${WITH_EAPOL:-yes}
82WITH_DHCP=${WITH_DHCP:-yes}
83WITH_IGMP=${WITH_IGMP:-no}
David Bainbridgeb270c202019-07-26 01:44:42 +000084WITH_ONOS=${WITH_ONOS:-yes}
David Bainbridge99ac7a22019-08-31 02:26:43 +000085WITH_CHAOS=${WITH_CHAOS:-no}
David Bainbridge46505fb2019-10-01 21:13:20 +000086WITH_ADAPTERS=${WITH_ADAPTERS:-yes}
David K. Bainbridgeda33d652020-03-06 10:31:23 -080087WITH_SIM_ADAPTERS=${WITH_SIM_ADAPTERS:-no}
David Bainbridge46505fb2019-10-01 21:13:20 +000088WITH_OPEN_ADAPTERS=${WITH_OPEN_ADAPTERS:-yes}
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -080089WITH_PORT_FORWARDS=${WITH_PORT_FORWARDS:-yes}
David Bainbridge696bc632020-04-05 21:49:37 -070090WITH_KAFKA=${WITH_KAFKA:-yes}
91WITH_ETCD=${WITH_ETCD:-yes}
David Bainbridge05cd8822019-11-19 17:43:53 +000092ONLY_ONE=${ONLY_ONE:-yes}
David K. Bainbridgeb859e912020-03-13 14:07:52 -070093CONFIG_SADIS=${CONFIG_SADIS:-no} # yes | no | file | bbsim | URL
David Bainbridge76afd812020-04-06 09:53:52 -070094SADIS_SUBSCRIBERS=${SADIS_SUBSCRIBERS:-http://bbsim.$VOLTHA_NS.svc:50074/v2/subscribers/%s}
95SADIS_BANDWIDTH_PROFILES=${SADIS_BANDWIDTH_PROFILES:-http://bbsim.$VOLTHA_NS.svc:50074/v2/bandwidthprofiles/%s}
Hardik Windlassb3147602020-03-09 16:59:15 +053096SADIS_CFG=${SADIS_CFG:-onos-files/onos-sadis-sample.json}
David Bainbridge27790d62019-08-13 22:43:19 +000097INSTALL_ONOS_APPS=${INSTALL_ONOS_APPS:-no}
Test Userba1e7e72019-07-10 22:27:54 +000098JUST_K8S=${JUST_K8S:-no}
99DEPLOY_K8S=${DEPLOY_K8S:-yes}
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700100INSTALL_KUBECTL=${INSTALL_KUBECTL:-yes}
101INSTALL_HELM=${INSTALL_HELM:-yes}
David Bainbridge7f8bf992020-04-08 21:53:22 -0700102HELM_USE_UPGRADE=${HELM_USE_UPGRADE:-no}
David Bainbridge46505fb2019-10-01 21:13:20 +0000103UPDATE_HELM_REPOS=${UPDATE_HELM_REPOS:-yes}
Matteo Scandolofab98622020-01-28 15:17:20 -0800104WAIT_ON_DOWN=${WAIT_ON_DOWN:-yes}
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700105WAIT_TIMEOUT=${WAIT_TIMEOUT:-30m}
106VOLTHA_DOWN_ON_TIMEOUT=${VOLTHA_DOWN_ON_TIMEOUT:-no}
David Bainbridge5b7b96b2019-07-25 20:29:13 +0000107VOLTHA_LOG_LEVEL=${VOLTHA_LOG_LEVEL:-WARN}
David Bainbridge90fd8e32019-08-21 23:32:47 +0000108VOLTHA_CHART=${VOLTHA_CHART:-onf/voltha}
109VOLTHA_CHART_VERSION=${VOLTHA_CHART_VERSION:-latest}
110VOLTHA_BBSIM_CHART=${VOLTHA_BBSIM_CHART:-onf/bbsim}
Matteo Scandolodcd29f52019-10-07 15:42:42 -0700111VOLTHA_BBSIM_CHART_VERSION=${VOLTHA_BBSIM_CHART_VERSION:-latest}
David Bainbridgee10f6d52019-07-25 00:28:13 +0000112VOLTHA_ADAPTER_SIM_CHART=${VOLTHA_ADAPTER_SIM_CHART:-onf/voltha-adapter-simulated}
David Bainbridge90fd8e32019-08-21 23:32:47 +0000113VOLTHA_ADAPTER_SIM_CHART_VERSION=${VOLTHA_ADAPTER_SIM_CHART_VERSION:-latest}
David Bainbridgee10f6d52019-07-25 00:28:13 +0000114VOLTHA_ADAPTER_OPEN_OLT_CHART=${VOLTHA_ADAPTER_OPEN_OLT_CHART:-onf/voltha-adapter-openolt}
David Bainbridge90fd8e32019-08-21 23:32:47 +0000115VOLTHA_ADAPTER_OPEN_OLT_CHART_VERSION=${VOLTHA_ADAPTER_OPEN_OLT_CHART_VERSION:-latest}
David Bainbridgee10f6d52019-07-25 00:28:13 +0000116VOLTHA_ADAPTER_OPEN_ONU_CHART=${VOLTHA_ADAPTER_OPEN_ONU_CHART:-onf/voltha-adapter-openonu}
David Bainbridge90fd8e32019-08-21 23:32:47 +0000117VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION=${VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION:-latest}
David K. Bainbridgeda33d652020-03-06 10:31:23 -0800118ONOS_CHART=${ONOS_CHART:-onf/onos}
Andrea Campanella21323292019-12-18 11:44:19 -0800119ONOS_CHART_VERSION=${ONOS_CHART_VERSION:-latest}
David Bainbridge2eaf2cf2020-03-18 12:54:08 -0700120EXTRA_HELM_INSTALL_ARGS=${EXTRA_HELM_INSTALL_ARGS:-}
121INTERNAL_EXTRA_HELM_INSTALL_ARGS=
uottrembb16d3982020-02-28 08:34:36 +0100122NUM_OF_BBSIM=${NUM_OF_BBSIM:-1}
123MAX_NUM_OF_BBSIM=10
Test Userba1e7e72019-07-10 22:27:54 +0000124
125HAVE_GO=$(which go >/dev/null 2>&1 && echo "yes" || echo "no")
126HOSTOS=$(uname -s | tr "[:upper:]" "[:lower:"])
127HOSTARCH=$(uname -m | tr "[:upper:]" "[:lower:"])
128if [ $HOSTARCH == "x86_64" ]; then
129 HOSTARCH="amd64"
130fi
Test User7d866122019-07-09 17:52:35 +0000131
uottrembb16d3982020-02-28 08:34:36 +0100132# check number (range) of bbsim, max bbsim must not exceed 10 instances!
133# note: instances will be numbered from 0 to 9
134if [ "$1" == "up" ]; then
David K. Bainbridge43422402020-03-06 07:41:22 -0800135 if [ "$NUM_OF_BBSIM" -lt 1 ]; then
136 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} Invalid setting of BBSIM instances. NUM_OF_BBSIM is less than 1${NORMAL}"
137 exit 1
138 fi
139 if [ "$NUM_OF_BBSIM" -gt $MAX_NUM_OF_BBSIM ]; then
140 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} Invalid setting of BBSIM instances. NUM_OF_BBSIM is greater than $MAX_NUM_OF_BBSIM${NORMAL}"
141 exit 1
142 fi
uottrembb16d3982020-02-28 08:34:36 +0100143fi
Test User7d866122019-07-09 17:52:35 +0000144# Verify TYPE setting
145if [ $(echo ":minimal:full:" | grep -ic ":$TYPE:") -eq 0 ]; then
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700146 >&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 +0000147 exit 1
148fi
149
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700150function parseDuration() {
151 local DUR=$1
152 local RESULT=0
David Bainbridge6cdb6462020-03-25 10:24:38 -0700153 local TERMS=$(echo $DUR | sed -Ee 's/([sSmMhHdD])/\1 /g' -e 's/,$//g')
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700154 for TERM in $TERMS; do
David Bainbridge6cdb6462020-03-25 10:24:38 -0700155 local VALUE=$(echo $TERM | sed -Ee 's/([0-9]+)[sSmMhHdD]/\1/')
156 local UNIT=$(echo $TERM | sed -Ee 's/[0-9]+([sSmMhHdD])/\1/')
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700157 case $UNIT in
158 s|S)
159 RESULT=$(($RESULT + $VALUE)) ;;
160 m|M)
161 RESULT=$(($RESULT + ($VALUE * 60))) ;;
162 h|H)
163 RESULT=$(($RESULT + ($VALUE * 3600))) ;;
164 d|D)
165 RESULT=$(($RESULT + ($VALUE * 86400))) ;;
166 *) ;;
167 esac
168 done
169 echo $RESULT
170}
171
172function doTimeout() {
173 local MSG=$1
174 2>&1 echo -e "\n${RED}${BOLD}${ERROR}TIMEOUT:${NORMAL}${RED} Operation timed out after '$WAIT_TIMEOUT': $MSG"
175 exit 125
176}
177
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -0800178function get_service_ep() {
179 local NS=$1
180 local NAME=$2
181 kubectl -n $NS get service $NAME -o json | jq -r '.spec.clusterIP + ":" + (.spec.ports[0].port|tostring)'
182}
183
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000184# Used to verify configuration values are set to "yes" or "no" value or convert
185# equivalents to "yes" or "no"
186function verify_yes_no() {
187 local VAR=$1
188 local VAL=$(eval echo \$$VAR)
189 if [ $(echo ":y:yes:true:n:no:false:1:0:" | grep -ic ":$VAL:") -eq 0 ]; then
190 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} Invalid '$VAR' value of '$VAL'. Should be 'yes' or 'no'${NORMAL}"
191 echo "INVALID"
192 return 1
193 fi
194 if [ $(echo ":y:yes:true:1:" | grep -ic ":$VAL:") -eq 1 ]; then
195 echo "yes"
196 else
197 echo "no"
198 fi
199 return 0
200}
Test User7d866122019-07-09 17:52:35 +0000201
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000202ALL_YES_NO="\
David K. Bainbridge484d80c2020-03-05 21:44:34 -0800203 ENABLE_ONOS_EXTRANEOUS_RULES \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000204 WITH_TIMINGS \
205 WITH_BBSIM \
Matteo Scandolo78dfee02020-02-13 16:18:03 -0800206 WITH_EAPOL \
207 WITH_DHCP \
208 WITH_IGMP \
David Bainbridge99ac7a22019-08-31 02:26:43 +0000209 WITH_CHAOS \
David Bainbridge46505fb2019-10-01 21:13:20 +0000210 WITH_ADAPTERS \
211 WITH_SIM_ADAPTERS \
212 WITH_OPEN_ADAPTERS \
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -0800213 WITH_PORT_FORWARDS \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000214 JUST_K8S \
215 DEPLOY_K8S \
216 INSTALL_ONOS_APPS \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000217 INSTALL_KUBECTL \
218 INSTALL_HELM \
David Bainbridge7f8bf992020-04-08 21:53:22 -0700219 HELM_USE_UPGRADE \
David Bainbridge46505fb2019-10-01 21:13:20 +0000220 UPDATE_HELM_REPOS \
David Bainbridge4f1b5562019-08-19 04:46:52 +0000221 WAIT_ON_DOWN \
David Bainbridge70c0ea82019-11-14 23:25:26 +0000222 ONLY_ONE \
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700223 VOLTHA_DOWN_ON_TIMEOUT \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000224 "
David Bainbridge5b7b96b2019-07-25 20:29:13 +0000225
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000226ALL_OPTIONS="\
227 NAME \
228 TYPE \
229 $ALL_YES_NO \
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700230 WAIT_TIMEOUT \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000231 VOLTHA_LOG_LEVEL \
232 VOLTHA_CHART \
David Bainbridge90fd8e32019-08-21 23:32:47 +0000233 VOLTHA_CHART_VERSION \
234 VOLTHA_BBSIM_CHART \
235 VOLTHA_BBSIM_CHART_VERSION \
uottrembd5a20572020-03-06 09:15:01 +0100236 NUM_OF_BBSIM \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000237 VOLTHA_ADAPTER_SIM_CHART \
David Bainbridge90fd8e32019-08-21 23:32:47 +0000238 VOLTHA_ADAPTER_SIM_CHART_VERSION \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000239 VOLTHA_ADAPTER_OPEN_OLT_CHART \
David Bainbridge90fd8e32019-08-21 23:32:47 +0000240 VOLTHA_ADAPTER_OPEN_OLT_CHART_VERSION \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000241 VOLTHA_ADAPTER_OPEN_ONU_CHART \
David Bainbridge90fd8e32019-08-21 23:32:47 +0000242 VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION \
David K. Bainbridgeda33d652020-03-06 10:31:23 -0800243 ONOS_CHART \
Andrea Campanella21323292019-12-18 11:44:19 -0800244 ONOS_CHART_VERSION \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000245 ONOS_API_PORT \
246 ONOS_SSH_PORT \
David K. Bainbridgeb859e912020-03-13 14:07:52 -0700247 CONFIG_SADIS \
Hardik Windlassb3147602020-03-09 16:59:15 +0530248 SADIS_CFG \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000249 VOLTHA_API_PORT \
250 VOLTHA_SSH_PORT \
251 VOLTHA_ETCD_PORT \
David K. Bainbridge00ecd382020-02-28 12:31:58 -0800252 VOLTHA_KAFKA_PORT \
David K. Bainbridge8f7f30b2020-01-08 13:06:16 -0800253 VK_RELEASE \
254 KIND_VERSION \
255 VOLTCTL_VERSION \
David Bainbridgea34993d2020-04-01 09:15:42 -0700256 HELM_VERSION \
David Bainbridge696bc632020-04-05 21:49:37 -0700257 WITH_RADIUS \
258 WITH_KAFKA \
259 WITH_ETCD \
David Bainbridge76afd812020-04-06 09:53:52 -0700260 WITH_ONOS \
David Bainbridge6ca40102020-04-08 11:30:40 -0700261 VOLTHA_NS \
262 ADAPTER_NS \
263 INFRA_NS \
264 BBSIM_NS \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000265 "
David Bainbridge01294952019-07-30 19:33:45 +0000266
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000267# Iterate over yes/no configuration options and validate
268for VAR in $ALL_YES_NO; do
269 eval $VAR=$(verify_yes_no $VAR)
270 if [ "$(eval echo \$$VAR)" == "INVALID" ]; then
271 exit 1;
272 fi
273done
David Bainbridgeb270c202019-07-26 01:44:42 +0000274
David Bainbridge15f6f232020-03-30 09:15:43 -0700275# Special case for CONFIG_SADIS
276if [ $(echo ":y:yes:true:1:" | grep -ic ":$CONFIG_SADIS:") -eq 1 ]; then
277 CONFIG_SADIS="yes"
278fi
279if [ $(echo ":n:no:false:0:" | grep -ic ":$CONFIG_SADIS:") -eq 1 ]; then
280 CONFIG_SADIS="no"
281fi
282
David Bainbridge76afd812020-04-06 09:53:52 -0700283# Special case for WITH_ONOS, WITH_RADIUS, WITH_KAFKA, and WITH_ETCD
David Bainbridge696bc632020-04-05 21:49:37 -0700284if [ $(echo ":y:yes:true:1:" | grep -ic ":$WITH_KAFKA:") -eq 1 ]; then
285 WITH_KAFKA="yes"
286fi
287if [ $(echo ":n:no:false:0:" | grep -ic ":$WITH_KAFKA:") -eq 1 ]; then
288 WITH_KAFKA="no"
289fi
David Bainbridge76afd812020-04-06 09:53:52 -0700290if [ $(echo ":external:" | grep -ic ":$WITH_KAFKA:") -eq 1 ]; then
291 WITH_KAFKA="external"
292fi
David Bainbridge696bc632020-04-05 21:49:37 -0700293if [ $(echo ":y:yes:true:1:" | grep -ic ":$WITH_ETCD:") -eq 1 ]; then
294 WITH_ETCD="yes"
295fi
296if [ $(echo ":n:no:false:0:" | grep -ic ":$WITH_ETCD:") -eq 1 ]; then
297 WITH_ETCD="no"
298fi
David Bainbridge76afd812020-04-06 09:53:52 -0700299if [ $(echo ":external:" | grep -ic ":$WITH_ETCD:") -eq 1 ]; then
300 WITH_ETCD="external"
301fi
David Bainbridge29c31cb2020-04-06 09:45:50 -0700302if [ $(echo ":y:yes:true:1:" | grep -ic ":$WITH_RADIUS:") -eq 1 ]; then
303 WITH_RADIUS="yes"
304fi
305if [ $(echo ":n:no:false:0:" | grep -ic ":$WITH_RADIUS:") -eq 1 ]; then
306 WITH_RADIUS="no"
307fi
David Bainbridge76afd812020-04-06 09:53:52 -0700308if [ $(echo ":y:yes:true:1:" | grep -ic ":$WITH_ONOS:") -eq 1 ]; then
309 WITH_ONOS="yes"
310fi
311if [ $(echo ":n:no:false:0:" | grep -ic ":$WITH_ONOS:") -eq 1 ]; then
312 WITH_ONOS="no"
313fi
David Bainbridge696bc632020-04-05 21:49:37 -0700314
David Bainbridge7f8bf992020-04-08 21:53:22 -0700315if [ $HELM_USE_UPGRADE == "yes" ]; then
316 _HELM_DESC="Upgrade/Install"
317else
318 _HELM_DESC="Install"
319fi
320
David K. Bainbridgeda33d652020-03-06 10:31:23 -0800321# Check for prerequiste tools
David K. Bainbridge726ff6a2020-03-06 11:09:50 -0800322TOOLS="curl sed jq"
David K. Bainbridgeda33d652020-03-06 10:31:23 -0800323if [ $DEPLOY_K8S == "yes" ]; then
324 TOOLS+=" docker"
325fi
326NOT_FOUND=""
327for T in $TOOLS; do
328 if [ -z "$(which $T)" ]; then
329 NOT_FOUND+=" $T"
330 fi
331done
332
333if [ ! -z "$NOT_FOUND" ]; then
334 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} The following required tools where not found, please install them:$NOT_FOUND"
335 exit 1
336fi
337
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700338TIMEOUT_SECONDS=$(parseDuration $WAIT_TIMEOUT)
339
David Bainbridge0774b232019-08-02 06:37:19 +0000340mkdir -p .voltha
341touch .voltha/ports
342HAVE=$(grep $NAME .voltha/ports)
343if [ "$HAVE X" == " X" ]; then
344 # Find free port prefix
345 START=81
346 while true; do
347 if [ $(grep -c $START .voltha/ports) -eq 0 ]; then
348 break
349 fi
350 START=$(expr $START + 1)
351 done
352 DELTA=$(expr $START - 81)
David Bainbridgea2595422019-10-22 03:54:28 +0000353 ONOS_API_PORT=${ONOS_API_PORT:-${START}81}
354 ONOS_SSH_PORT=${ONOS_SSH_PORT:-${START}01}
355 VOLTHA_API_PORT=${VOLTHA_API_PORT:-5$(expr 55 + $DELTA)55}
356 VOLTHA_SSH_PORT=${VOLTHA_SSH_PORT:-$(expr 50 + $DELTA)22}
357 VOLTHA_ETCD_PORT=${VOLTHA_ETCD_PORT:-$(expr 23 + $DELTA)79}
David K. Bainbridge00ecd382020-02-28 12:31:58 -0800358 VOLTHA_KAFKA_PORT=${VOLTHA_KAFKA_PORT:-$(expr 90 + $DELTA)92}
Test User01ed0642019-07-03 20:17:06 +0000359else
David Bainbridge0774b232019-08-02 06:37:19 +0000360 VALUES=$(echo $HAVE | sed -e 's/\s//g' | cut -d= -f2)
David Bainbridgea2595422019-10-22 03:54:28 +0000361 ONOS_API_PORT=${ONOS_API_PORT:-$(echo $VALUES | cut -d, -f1)}
362 ONOS_SSH_PORT=${ONOS_SSH_PORT:-$(echo $VALUES | cut -d, -f2)}
363 VOLTHA_API_PORT=${VOLTHA_API_PORT:-$(echo $VALUES | cut -d, -f3)}
364 VOLTHA_SSH_PORT=${VOLTHA_SSH_PORT:-$(echo $VALUES | cut -d, -f4)}
365 VOLTHA_ETCD_PORT=${VOLTHA_ETCD_PORT:-$(echo $VALUES | cut -d, -f5)}
David K. Bainbridge00ecd382020-02-28 12:31:58 -0800366 VOLTHA_KAFKA_PORT=${VOLTHA_KAFKA_PORT:-$(echo $VALUES | cut -d, -f6)}
367
David K. Bainbridge00ecd382020-02-28 12:31:58 -0800368 # A bit of a hueristic required here as the KAFKA port forward was
369 # added after the .voltha/ports files was created. Basically, if
370 # the VOLTHA_KAFKA_PORT isn't in the file then calculate the original
371 # DELTA from the VOLTHA_SSH_PORT and apply it to the VOLTHA_KAFKA_PORT
372 if [ -z "$VOLTHA_KAFKA_PORT" ]; then
373 DELTA=$((VOLTHA_SSH_PORT/100-50))
374 VOLTHA_KAFKA_PORT=${VOLTHA_KAFKA_PORT:-$(expr 90 + $DELTA)92}
375 fi
Test User01ed0642019-07-03 20:17:06 +0000376fi
377
David Bainbridge0774b232019-08-02 06:37:19 +0000378PORTTMP=$(mktemp -u)
379cat .voltha/ports | grep -v $NAME > $PORTTMP
David K. Bainbridge00ecd382020-02-28 12:31:58 -0800380echo "$NAME=$ONOS_API_PORT,$ONOS_SSH_PORT,$VOLTHA_API_PORT,$VOLTHA_SSH_PORT,$VOLTHA_ETCD_PORT,$VOLTHA_KAFKA_PORT" >> $PORTTMP
David Bainbridge0774b232019-08-02 06:37:19 +0000381cp $PORTTMP .voltha/ports
382rm -f $PORTTMP
383
David Bainbridge27790d62019-08-13 22:43:19 +0000384export ONOS_API_PORT ONOS_SSH_PORT
David Bainbridge01294952019-07-30 19:33:45 +0000385
Test Userd87942b2019-07-03 07:20:24 +0000386IDX=1
David Bainbridgee87067b2019-08-12 22:00:12 +0000387CLOCK="TIME:"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000388SPIN_PARTS=
389NOT_VERIFIED=
David Bainbridgef858a022019-08-14 21:25:11 +0000390THEX=
391BUILD=
392CROSS=
393ENTER=
David Bainbridge38dc1e82019-08-12 15:18:45 +0000394VERIFIED=
395HELM=
396OLD_KEY=
397BIRD=
398HIGH_VOLTAGE=
399PLUG=
400RESTART=
401FORWARD=
402INSTALL=
403STOP=
404GO=
405DOWNLOAD=
406GEAR=
407NO_ENTRY=
408LOCK=
409
410if [ $FANCY -eq 1 ]; then
411 SPIN_PARTS="\
412 \xe2\xa2\x8e\xe2\xa1\xb0 \
413 \xe2\xa2\x8e\xe2\xa1\xa1 \
414 \xe2\xa2\x8e\xe2\xa1\x91 \
415 \xe2\xa2\x8e\xe2\xa0\xb1 \
416 \xe2\xa0\x8e\xe2\xa1\xb1 \
417 \xe2\xa2\x8a\xe2\xa1\xb1 \
418 \xe2\xa2\x8c\xe2\xa1\xb1 \
419 \xe2\xa2\x86\xe2\xa1\xb1 \
420 "
David Bainbridgee87067b2019-08-12 22:00:12 +0000421 CLOCK="\xe2\x8f\xb1"
David Bainbridgef858a022019-08-14 21:25:11 +0000422 THEX="${RED}${BOLD}\xe2\x9c\x97\x20${NORMAL}"
423 ENTER="${YELLOW}${BOLD}\xe2\x8e\x86${NORMAL}"
424 CROSS="${YELLOW}${BOLD}\xe2\x9c\x9a${NORMAL}"
425 BUILD="${YELLOW}${BOLD}\xf0\x9f\x8f\x97${NORMAL}"
426 NOT_VERIFIED="$BUILD"
427 VERIFIED="${GREEN}${BOLD}\xe2\x9c\x93\x20${NORMAL}"
428 HELM="${BLUE}${BOLD}\xE2\x8E\x88${NORMAL}"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000429 OLD_KEY="\xF0\x9F\x97\x9D"
430 BIRD="\xF0\x9F\x90\xA6"
431 HIGH_VOLTAGE="\xE2\x9A\xA1"
432 PLUG="\xF0\x9F\xa7\xa9"
433 RESTART="\xf0\x9f\x94\x84"
434 FORWARD="\xE2\x87\xA8"
435 INSTALL="\xF0\x9F\x8F\x97"
436 STOP="\xf0\x9f\x9b\x91"
437 GO="\xf0\x9f\x9a\x80"
438 DOWNLOAD="\xf0\x9f\x93\xa5"
439 GEAR="\xe2\x9a\x99"
440 NO_ENTRY="\xe2\x9b\x94"
441 LOCK="\xf0\x9f\x94\x92"
442fi
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700443
David Bainbridge712afb82019-08-14 19:55:58 +0000444duration() {
David Bainbridgee87067b2019-08-12 22:00:12 +0000445 local h=$(expr $1 / 3600)
446 local m=$(expr $1 % 3600 / 60)
447 local s=$(expr $1 % 60)
448 local t=""
449
450 if [ $h -gt 0 ]; then
451 t="$t${h}h"
452 fi
453 if [ $m -gt 0 ]; then
454 t="$t${m}m"
455 fi
David Bainbridge712afb82019-08-14 19:55:58 +0000456 echo "$t${s}s"
457}
458
459printtime() {
460 local INDENT=
461 if [ "$1" == "-" ]; then
462 INDENT=" "
463 shift
464 fi
465 echo -e "$INDENT $CLOCK $(duration $1)"
David Bainbridgee87067b2019-08-12 22:00:12 +0000466}
467
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700468bspin() {
Test Userd87942b2019-07-03 07:20:24 +0000469 IDX=1
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700470 local INDENT=
471 if [ "$1" == "-" ]; then
472 INDENT=" "
473 shift
474 fi
David Bainbridge38dc1e82019-08-12 15:18:45 +0000475 if [ $FANCY -eq 0 ]; then
476 LINE=$(echo $* | sed -e 's/[\s+-]//g')
477 if [ "$LINE X" == " X" ]; then
478 return
479 fi
480 echo -e "$CIVIS$INDENT$*"
481 else
482 echo -en "$CIVIS$INDENT $*"
483 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700484}
485
486sspin() {
487 local INDENT=
488 if [ "$1" == "-" ]; then
489 INDENT=" "
490 shift
491 fi
David Bainbridge38dc1e82019-08-12 15:18:45 +0000492 if [ $FANCY -eq 0 ]; then
493 LINE=$(echo $* | sed -e 's/[\s+-]//g')
494 if [ "$LINE X" == " X" ]; then
495 return
496 fi
497 echo -e "$INDENT$*"
498 else
499 C=$(echo $SPIN_PARTS | cut '-d ' -f $IDX)
500 echo -en "\r$INDENT$C $*"
501 IDX=$(expr $IDX + 1)
502 if [ $IDX -gt 8 ]; then
503 IDX=1
504 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700505 fi
506}
507
508espin() {
509 local INDENT=
510 if [ "$1" == "-" ]; then
511 INDENT=" "
512 shift
513 fi
David Bainbridge38dc1e82019-08-12 15:18:45 +0000514 if [ $FANCY -eq 0 ]; then
515 LINE=$(echo $* | sed -e 's/[\s+-]//g')
516 if [ "$LINE X" == " X" ]; then
517 return
518 fi
519 echo -e "$INDENT$*"
520 else
521 echo -e "\r$INDENT$*$CNORM"
522 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700523}
524
David Bainbridgeac7f8072019-08-01 22:15:33 +0000525if [ "$1" == "get" -a "$2" == "voltconfig" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000526 echo "$HOME/.volt/config-$NAME"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000527 exit
528fi
529
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -0700530if [ $# -ne 1 -o $(echo ":up:down:dump:" | grep -c ":$1:") -ne 1 ]; then
David Bainbridgeac7f8072019-08-01 22:15:33 +0000531 >&2 echo "What wouild you like to do today:"
532 >&2 echo " up - bring up voltha"
533 >&2 echo " down - tear down voltha"
534 >&2 echo " dump - create a debug dump of running system"
535 exit 1
536fi
537
David Bainbridge4f1b5562019-08-19 04:46:52 +0000538push_onos_config() {
Matteo Scandolo78dfee02020-02-13 16:18:03 -0800539 local TYPE=$1
540 local MSG=$2
541 local RESOURCE=$3
542 local DATA=$4
David Bainbridge4f1b5562019-08-19 04:46:52 +0000543
David K. Bainbridgeb4b163b2020-02-19 15:55:06 -0800544 # Thanks to the latest version of ONOS using the return code 207 this gets a
545 # whole lot nastier. Can't thank them enough for doing this. So in order to
546 # capture the command and the output in the log file as well as capture the
547 # status code to verify it is 200 and not 207 mutltiple files and a bit of
548 # hackery must be used. Thanks again ONOS.
549 local CMD_ECHO=$(mktemp -u)
550 local CMD_OUTPUT=$(mktemp -u)
551 local SC_OUTPUT=$(mktemp -u)
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700552 local WAIT_START=$(date +%s)
David K. Bainbridgeb4b163b2020-02-19 15:55:06 -0800553
David Bainbridge4f1b5562019-08-19 04:46:52 +0000554 bspin - "$MSG $GEAR"
555 while true; do
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700556 if [ $(($(date +%s) - $WAIT_START)) -gt $TIMEOUT_SECONDS ]; then
557 espin - "$THEX"
David Bainbridge1cecba52020-03-30 09:43:10 -0700558 rm -f $CMD_ECHO $CMD_OUTPUT $SC_OUTPUT
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700559 doTimeout "waiting for ONOS config push on $RESOURCE"
560 fi
Matteo Scandolo78dfee02020-02-13 16:18:03 -0800561 if [ $TYPE == "file" ]; then
David K. Bainbridgeb859e912020-03-13 14:07:52 -0700562 (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
563 RESULT=$?
Matteo Scandolo78dfee02020-02-13 16:18:03 -0800564 fi
565 if [ $TYPE == "json" ]; then
David K. Bainbridgeb859e912020-03-13 14:07:52 -0700566 (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
567 RESULT=$?
Matteo Scandolo78dfee02020-02-13 16:18:03 -0800568 fi
David K. Bainbridgeb4b163b2020-02-19 15:55:06 -0800569 # Dump everything to the log
570 cat $CMD_ECHO >> $LOG
David K. Bainbridgeb859e912020-03-13 14:07:52 -0700571 test -r $CMD_OUTPUT && cat $CMD_OUTPUT >> $LOG
David K. Bainbridgeb4b163b2020-02-19 15:55:06 -0800572 SC=$(cat $SC_OUTPUT)
David K. Bainbridgeb859e912020-03-13 14:07:52 -0700573 echo "RESPONSE CODE: $SC" >> $LOG
574 echo "ERROR CODE: $RESULT" >> $LOG
David K. Bainbridgeb4b163b2020-02-19 15:55:06 -0800575
576 # clean up temp files
577 rm -f $CMD_ECHO $CMD_OUTPUT $SC_OUTPUT
578 if [ $RESULT -eq 0 -a "$SC" == "200" ]; then
David Bainbridge4f1b5562019-08-19 04:46:52 +0000579 break
580 fi
Matteo Scandolo9a77a732020-01-09 14:24:12 -0800581 sleep 1
David Bainbridge4f1b5562019-08-19 04:46:52 +0000582 sspin -
583 done
584 espin - $VERIFIED
585}
586
Matteo Scandolo9a77a732020-01-09 14:24:12 -0800587check_onos_app_active() {
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700588 local APP_ID=$1
589 local WAIT_START=$(date +%s)
Matteo Scandolo9a77a732020-01-09 14:24:12 -0800590
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700591 bspin - "Checking that $APP_ID is active $CLOCK"
592 while true; do
593 if [ $(($(date +%s) - $WAIT_START)) -gt $TIMEOUT_SECONDS ]; then
594 espin - "$THEX"
595 doTimeout "waiting for ONOS application activation '$APP_ID'"
596 fi
597 (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
598 if [ $? -eq 0 ]; then
599 break
600 fi
601 sleep 1
602 sspin -
603 done
604 sleep 5 # OSGI components take a little longer that the app to activate
605 espin - $VERIFIED
Matteo Scandolo9a77a732020-01-09 14:24:12 -0800606}
607
David Bainbridge4f1b5562019-08-19 04:46:52 +0000608override_onos_app() {
609 local APP=$1
610 local NAME=$(basename $APP | sed -e 's/^[0-9][0-9]*-//g' -e 's/-.*$//g')
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700611 local WAIT_START=$(date +%s)
612
David Bainbridge4f1b5562019-08-19 04:46:52 +0000613 while true; do
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700614 if [ $(($(date +%s) - $WAIT_START)) -gt $TIMEOUT_SECONDS ]; then
615 espin - "$THEX"
616 doTimeout "waiting to overwrite ONOS application '$APP'"
617 fi
David Bainbridge4f1b5562019-08-19 04:46:52 +0000618 sspin -
619 # Attempt to delete old version (if it exists)
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -0800620 (set -x; curl --fail -sSL --user karaf:karaf -X DELETE http://$_ONOS_API_EP/onos/v1/applications/$NAME >>$LOG 2>&1) >>$LOG 2>&1
David Bainbridge4f1b5562019-08-19 04:46:52 +0000621 sspin -
622 if [ $? -ne 0 ]; then
623 continue
624 fi
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -0800625 (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
David Bainbridge4f1b5562019-08-19 04:46:52 +0000626 if [ $? -eq 0 ]; then
627 break
628 fi
629 sleep .2
630 done
631}
632
633activate_onos_app() {
634 local MSG="$1"
635 local APP=$2
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700636 local WAIT_START=$(date +%s)
David Bainbridge4f1b5562019-08-19 04:46:52 +0000637
638 bspin - "$MSG $GO"
639 while true; do
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700640 if [ $(($(date +%s) - $WAIT_START)) -gt $TIMEOUT_SECONDS ]; then
641 espin - "$THEX"
642 doTimeout "waiting to activate ONOS application '$APP'"
643 fi
David Bainbridge4f1b5562019-08-19 04:46:52 +0000644 sspin -
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -0800645 (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
David Bainbridge4f1b5562019-08-19 04:46:52 +0000646 if [ $? -eq 0 ]; then
647 break
648 fi
649 sleep .2
650 done
651 espin - "$VERIFIED"
652}
653
654count_pods() {
655 local NAMESPACE=$1; shift
656 if [ "$NAMESPACE" == "all-namespaces" ]; then
657 NAMESPACE="--all-namespaces"
658 else
659 NAMESPACE="-n $NAMESPACE"
660 fi
David Bainbridge4f1b5562019-08-19 04:46:52 +0000661 local STATES=$1; shift
David Bainbridge4f1b5562019-08-19 04:46:52 +0000662 local PODS=$(kubectl get $NAMESPACE pod -o go-template="{{range .items}}{{.metadata.name}}/{{.status.phase}}/_{{range .status.containerStatuses}}{{.ready}}_{{end}} {{end}}")
663 local COUNT=0
664 local PATTERNS="$*"
665 for POD in $PODS; do
666 local NAME=$(echo $POD | cut -d/ -f 1)
667 local STATE=$(echo $POD | cut -d/ -f 2)
668 local CONTAINERS=$(echo $POD | cut -d/ -f 3 | sed -e 's/_/ /g')
669 if [ "$STATES" == "*" -o $(echo "$STATES" | grep -c ":$STATE:") -ne 0 ]; then
David Bainbridge4f1b5562019-08-19 04:46:52 +0000670 local TOTAL=$(echo $CONTAINERS | wc -w)
671 local FOUND=$(echo $CONTAINERS | grep -o true | wc -l)
672 if [ $TOTAL -eq $FOUND ]; then
673 for PATTERN in $PATTERNS; do
David Bainbridge4f1b5562019-08-19 04:46:52 +0000674 if [[ $NAME =~ $PATTERN ]]; then
David Bainbridge4f1b5562019-08-19 04:46:52 +0000675 COUNT=$(expr $COUNT + 1)
676 break
677 fi
678 done
679 fi
680 fi
681 done
David Bainbridge4f1b5562019-08-19 04:46:52 +0000682 echo $COUNT
683}
684
685wait_for_pods() {
686 local INDENT=
687 if [ "$1" == "-" ]; then
688 INDENT=$1; shift
689 fi
690 local NAMESPACE=$1; shift
691 local EXPECT=$1; shift
692 local TYPE=$1; shift
693 local RETRY=$1; shift
694 local MESSAGE=$1; shift
695 local PATTERNS=$*
David Bainbridge99ac7a22019-08-31 02:26:43 +0000696 local STATES=":Running:"
697 if [ "$TYPE" == "not" ]; then
698 STATES="*"
699 fi
700 local HAVE=$(count_pods $NAMESPACE "$STATES" $PATTERNS)
David Bainbridge4f1b5562019-08-19 04:46:52 +0000701 local ALL=$HAVE
702 if [ "$TYPE" == "only" ]; then
703 ALL=$(count_pods "all-namespaces" "*" ".*")
704 fi
705 COUNT=$(expr 300 / 15)
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700706 local WAIT_START=$(date +%s)
David Bainbridge4f1b5562019-08-19 04:46:52 +0000707 bspin $INDENT $MESSAGE
708 sspin $INDENT
709 if [ $HAVE -ne $EXPECT -o $ALL -ne $HAVE ]; then
710 while [ $HAVE -ne $EXPECT -o $ALL -ne $HAVE ]; do
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700711 if [ $(($(date +%s) - $WAIT_START)) -gt $TIMEOUT_SECONDS ]; then
712 espin $INDENT "$THEX"
713 doTimeout "waiting for PODs to start"
714 fi
David Bainbridge4f1b5562019-08-19 04:46:52 +0000715 sspin $INDENT
716 COUNT=$(expr $COUNT - 1)
717 if [ $COUNT -eq 0 ]; then
David Bainbridge99ac7a22019-08-31 02:26:43 +0000718 HAVE=$(count_pods $NAMESPACE "$STATES" $PATTERNS)
David Bainbridge4f1b5562019-08-19 04:46:52 +0000719 ALL=$HAVE
720 if [ "$TYPE" == "only" ]; then
721 ALL=$(count_pods "all-namespaces" "*" ".*")
722 fi
723 COUNT=$(expr 300 / 15)
724 fi
725 sleep .15
726 done
727 fi
728 espin $INDENT $VERIFIED
729 if [ $HAVE -ne $EXPECT ]; then
730 return 1
731 fi
732 return 0
733}
734
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800735port_forward() {
736 local NS=$1
737 local SVC=$2
738 local FROM_PORT=$3
739 local TO_PORT=$4
740 local TAG=$SVC-$NAME
741
David Bainbridge70cc33a2020-04-07 11:06:59 -0700742 (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 -0800743}
744
745kill_port_forward() {
746 local TAG=$1-$NAME
David Bainbridgec6871d22019-11-13 17:10:31 +0000747 local P_IDS=$(ps e -ww -A | grep "_TAG=$TAG" | grep -v grep | awk '{print $1}')
David Bainbridgebcf235b2019-11-12 21:33:58 +0000748 local PARENTS=
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800749 local KIDS=
David Bainbridgec6871d22019-11-13 17:10:31 +0000750 local UNKNOWN=
751 if [ ! -z "$P_IDS" ]; then
752 for P_ID in $P_IDS; do
753 local PP_ID=$(ps -o ppid $P_ID | tail -n +2)
754 if [ ! -z "$PP_ID" ]; then
755 if [ $PP_ID -eq 1 ]; then
756 PARENTS="$PARENTS $P_ID"
757 else
758 KIDS="$KIDS $P_ID"
759 fi
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800760 else
David Bainbridgec6871d22019-11-13 17:10:31 +0000761 UNKNOWN="$UNKNOWN $P_ID"
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800762 fi
763 done
David Bainbridgec6871d22019-11-13 17:10:31 +0000764 (set -x; kill -9 $PARENTS $KIDS $UNKNOWN >>$LOG 2>&1) >>$LOG 2>&1
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800765 fi
766}
767
David Bainbridgeac7f8072019-08-01 22:15:33 +0000768if [ "$1" == "down" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000769 echo "Tearing down voltha cluster $NAME"
770 LOG="down-$NAME.log"
771 echo $(date -u +"%Y%m%dT%H%M%SZ") >$LOG
David Bainbridge696bc632020-04-05 21:49:37 -0700772 if [ $WITH_ONOS == "yes" ]; then
773 bspin "Remove port-forwards: onos-ui-$NAME"
774 kill_port_forward onos-ui
775 sspin "Remove port-forwards: onos-ssh-$NAME$CEOL"
776 kill_port_forward onos-ssh
777 fi
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800778 sspin "Remove port-forwards: voltha-api-$NAME$CEOL"
779 kill_port_forward voltha-api
David Bainbridge76afd812020-04-06 09:53:52 -0700780 if [ $WITH_ETCD == "yes" -o $WITH_ETCD == "external" ]; then
David Bainbridge696bc632020-04-05 21:49:37 -0700781 sspin "Remove port-forwards: voltha-etcd-$NAME$CEOL"
782 kill_port_forward voltha-etcd-cluster-client
783 fi
784 if [ $WITH_KAFKA == "yes" ]; then
785 sspin "Remove port-forwards: voltha-kafka-$NAME$CEOL"
786 kill_port_forward voltha-kafka
787 fi
788
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800789 espin "$VERIFIED Remove port-forwards$CEOL"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000790 if [ $DEPLOY_K8S == "yes" ]; then
791 if [ -x ./bin/kind ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000792 bspin "Delete Kubernetes Kind Cluster"
793 (set -x; ./bin/kind delete cluster --name voltha-$NAME >>$LOG 2>&1) >>$LOG 2>&1
794 espin $VERIFIED
David Bainbridgeac7f8072019-08-01 22:15:33 +0000795 else
David Bainbridge0774b232019-08-02 06:37:19 +0000796 espin "$NO_ENTRY Delete Kubernetes Kind Cluster: kind command not found"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000797 fi
798 else
799 EXISTS=$(helm list -q)
David Bainbridge76afd812020-04-06 09:53:52 -0700800 EXPECT="voltha"
David Bainbridge696bc632020-04-05 21:49:37 -0700801 if [ $WITH_ONOS == yes ]; then
802 EXPECT+=" onos"
803 fi
804 if [ $WITH_RADIUS == "yes" ]; then
805 EXPECT+=" radius"
806 fi
807 if [ $WITH_BBSIM == "yes" ]; then
808 EXPECT+=" bbsim"
809 fi
810 if [ $WITH_OPEN_ADAPTERS == "yes" ]; then
811 EXPECT+=" open-olt open-onu"
812 fi
813 if [ $WITH_SIM_ADAPTERS == "yes" ]; then
814 EXPECT+=" sim"
815 fi
David Bainbridge76afd812020-04-06 09:53:52 -0700816 if [ $WITH_ETCD == "external" ]; then
817 EXPECT+=" etcd-operator etcd-cluster"
818 elif [ $WITH_ETCD == "yes" ]; then
819 EXPECT+=" etcd-operator"
820 fi
821 if [ $WITH_KAFKA == "external" ]; then
822 EXPECT+=" kafka"
823 fi
David Bainbridge0774b232019-08-02 06:37:19 +0000824 bspin "Remove Helm Deployments"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000825 for i in $EXISTS; do
David K. Bainbridge43422402020-03-06 07:41:22 -0800826 for j in $EXPECT; do
827 if [[ $i =~ $j ]]; then
828 sspin "Remove Helm Deployments: $i$CEOL"
829 (set -x; ./bin/helm delete --no-hooks --purge $i >>$LOG 2>&1) >>$LOG 2>&1
830 fi
831 done
uottrembb16d3982020-02-28 08:34:36 +0100832 done
David Bainbridge0774b232019-08-02 06:37:19 +0000833 espin "$VERIFIED Remove Helm Deployments$CEOL"
David Bainbridge4f1b5562019-08-19 04:46:52 +0000834 if [ "$WAIT_ON_DOWN" == "yes" ]; then
David Bainbridge76afd812020-04-06 09:53:52 -0700835 PODS="voltha-kafka.* voltha-ofagent.* voltha-rw-core.* voltha-etcd.*"
836 INFRA_PODS=
837 ADAPT_PODS=
838 SIM_PODS=
David Bainbridge696bc632020-04-05 21:49:37 -0700839 if [ $WITH_RADIUS == "yes" ]; then
840 PODS+=" radius.*"
841 fi
842 if [ $WITH_BBSIM == "yes" ]; then
David Bainbridge76afd812020-04-06 09:53:52 -0700843 SIM_PODS+=" bbsim.*"
David Bainbridge696bc632020-04-05 21:49:37 -0700844 fi
845 if [ $WITH_OPEN_ADAPTERS -o $WITH_SIM_ADAPTERS ]; then
David Bainbridge76afd812020-04-06 09:53:52 -0700846 ADAPT_PODS+=" adapter-*"
David Bainbridge696bc632020-04-05 21:49:37 -0700847 fi
David Bainbridge76afd812020-04-06 09:53:52 -0700848 if [ $WITH_ONOS == "yes" ]; then
849 INFRA_PODS+=" onos-.*"
850 fi
851 if [ $WITH_ETCD == "external" ]; then
852 INFRA_PODS+=" etcd-operator.* etcd-cluster.*"
853 elif [ $WITH_ETCD == "yes" ]; then
854 PODS+=" etcd-operator.*"
855 fi
856 if [ $WITH_KAFKA == "external" ]; then
857 INFRA_PODS+=" kafka.*"
858 fi
859 if [ ! -z "$SIM_PODS" ]; then
860 wait_for_pods "$BBSIM_NS" 0 "not" -1 "Waiting for BBSIM PODs to terminate" $SIM_PODS
861 fi
862 if [ ! -z "$INFRA_PODS" ]; then
863 wait_for_pods "$INFRA_NS" 0 "not" -1 "Waiting for infrastructure PODs to terminate" $INFRA_PODS
864 fi
865 if [ ! -z "$ADAPT_PODS" ]; then
866 wait_for_pods "$ADAPTER_NS" 0 "not" -1 "Waiting for adapter PODs to terminate" $ADAPT_PODS
867 fi
868 wait_for_pods "$VOLTHA_NS" 0 "not" -1 "Waiting for VOLTHA PODs to terminate" $PODS
David Bainbridge4f1b5562019-08-19 04:46:52 +0000869 fi
David Bainbridgeac7f8072019-08-01 22:15:33 +0000870 fi
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -0700871 exit
David Bainbridgeac7f8072019-08-01 22:15:33 +0000872fi
873
874if [ "$1" == "dump" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000875 LOG="dump-$NAME.log"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000876 TS=$(date -u +"%Y%m%dT%H%M%SZ")
David Bainbridge76514a02019-10-08 01:50:35 +0000877 if [ ! -z "$DUMP_FROM" ]; then
878 TS=$(echo $DUMP_FROM | sed -e 's/[:-]//g')
879 fi
David Bainbridgeac7f8072019-08-01 22:15:33 +0000880 WORK=$(mktemp -u -d)
David Bainbridge0774b232019-08-02 06:37:19 +0000881 DATA=$WORK/voltha-debug-dump-$NAME-$TS
David Bainbridgeac7f8072019-08-01 22:15:33 +0000882 mkdir -p $DATA
883 echo $TS > $LOG
David Bainbridge0774b232019-08-02 06:37:19 +0000884 echo -e "Capturing debug dump to voltha-debug-dump-$NAME-$TS.tgz"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000885 bspin - "Copy install log"
David Bainbridge0774b232019-08-02 06:37:19 +0000886 if [ -f install-$NAME.log ]; then
887 (set -x; cp install-$NAME.log $DATA/install-$NAME.log) >>$LOG 2>&1
David Bainbridgeac7f8072019-08-01 22:15:33 +0000888 espin - $VERIFIED
889 else
David Bainbridge0774b232019-08-02 06:37:19 +0000890 espin - "$NO_ENTRY Copy install log: install-$NAME.log not found"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000891 fi
892 bspin - "Dumping Kubernetes PODs"
893 (set -x; kubectl get --all-namespaces pods >> $DATA/all-pods.txt 2>&1) >>$LOG 2>&1
894 espin - $VERIFIED
895 bspin - "Dumping Kubernetes SERVICEs"
896 (set -x; kubectl get --all-namespaces svc >> $DATA/all-services.txt 2>&1) >>$LOG 2>&1
897 espin - $VERIFIED
898 bspin - "Dumping Kubernetes EVENTs"
899 (set -x; kubectl get --all-namespaces events >> $DATA/all-events.txt 2>&1) >>$LOG 2>&1
900 espin - $VERIFIED
901 bspin - "Dumping VOLTHA POD details"
David Bainbridge76afd812020-04-06 09:53:52 -0700902 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 +0000903 SINCE=
904 if [ ! -z "$DUMP_FROM" ]; then
905 SINCE="--since-time=$DUMP_FROM"
906 fi
David Bainbridgeac7f8072019-08-01 22:15:33 +0000907 for POD in $PODS; do
David Bainbridge1f0655a2019-10-01 22:08:48 +0000908 NS=$(echo $POD | cut -d: -f1)
909 POD=$(echo $POD | cut -d: -f2)
David Bainbridgeac7f8072019-08-01 22:15:33 +0000910 sspin - "Dumping VOLTHA POD details: $POD$CEOL"
911 mkdir -p $DATA/$POD
David Bainbridge1f0655a2019-10-01 22:08:48 +0000912 (set -x; kubectl describe -n $NS $POD >> $DATA/$POD/describe.txt 2>&1) >>$LOG 2>&1
David Bainbridgeac7f8072019-08-01 22:15:33 +0000913 sspin - "Dumping VOLTHA POD details: $POD"
David Bainbridgecfd7ca12019-10-06 03:31:41 +0000914 (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 +0000915 sspin - "Dumping VOLTHA POD details: $POD"
David Bainbridgecfd7ca12019-10-06 03:31:41 +0000916 (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 +0000917 sspin - "Dumping VOLTHA POD details: $POD"
918 done
919 espin - "$VERIFIED Dumping VOLTHA POD details$CEOL"
920 bspin - "Dumping ETCD"
921 if [ "$(which etcdctl) X" != " X" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000922 (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
David Bainbridgeac7f8072019-08-01 22:15:33 +0000923 espin - $VERIFIED
924 else
925 espin - "$NO_ENTRY Dumping ETCD: etcdctl command not available"
926 fi
David Bainbridge0774b232019-08-02 06:37:19 +0000927 bspin - "Creating compressed TAR: voltha-debug-dump-$NAME-$TS.tgz"
928 (set -x; tar -C $WORK -zcf voltha-debug-dump-$NAME-$TS.tgz ./voltha-debug-dump-$NAME-$TS) >>$LOG 2>&1
David Bainbridgeac7f8072019-08-01 22:15:33 +0000929 espin - $VERIFIED
930 bspin - "Cleanup"
931 (set -x; rm -rf $WORK) >>$LOG 2>&1
932 espin - $VERIFIED
David Bainbridge0774b232019-08-02 06:37:19 +0000933 bspin - "$(ls -l voltha-debug-dump-$NAME-$TS.tgz)"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000934 espin - $VERIFIED
935 exit
936fi
937
David Bainbridge0774b232019-08-02 06:37:19 +0000938LOG="install-$NAME.log"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000939date > $LOG
David Bainbridge0774b232019-08-02 06:37:19 +0000940echo "PORTS=$ONOS_API_PORT,$ONOS_SSH_PORT,$VOLTHA_API_PORT,$VOLTHA_SSH_PORT,$VOLTHA_ETCD_PORT" >> $LOG
David Bainbridgeac7f8072019-08-01 22:15:33 +0000941
942# Output install options to log
943echo "OPTIONS" >> $LOG
David Bainbridgeac7f8072019-08-01 22:15:33 +0000944for O in $ALL_OPTIONS; do
945 VAL=$(eval echo \$$O)
David Bainbridgeac7f8072019-08-01 22:15:33 +0000946 if [ ! -z "$VAL" ]; then
947 printf " %-30s = %s\n" $O $VAL >> $LOG
948 fi
949done
950
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -0700951helm_install() {
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700952 local INDENT=
953 if [ "$1" == "-" ]; then
954 INDENT=$1; shift
955 fi
956 local NAMESPACE=$1; shift
David Bainbridge0774b232019-08-02 06:37:19 +0000957 local INAME=$1; shift
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700958 local CHART=$1; shift
David Bainbridge90fd8e32019-08-21 23:32:47 +0000959 local CHART_VERSION=$1; shift
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700960 local MESSAGE=$*
961
David Bainbridge90fd8e32019-08-21 23:32:47 +0000962 if [ "$CHART_VERSION X" != " X" -a "$CHART_VERSION" != "latest" ]; then
963 CHART_VERSION="--version $CHART_VERSION"
964 else
965 CHART_VERSION=
966 fi
967
David Bainbridge99ac7a22019-08-31 02:26:43 +0000968 local CHART_ARGS=
969 if [ -r "${INAME}-values.yaml" ]; then
970 CHART_ARGS="-f ${INAME}-values.yaml"
971 fi
972
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700973 local WAIT_START=$(date +%s)
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700974 COUNT=$(expr 300 / 15)
975 bspin $INDENT $MESSAGE
David Bainbridge7f8bf992020-04-08 21:53:22 -0700976 if [ $HELM_USE_UPGRADE == "yes" ]; then
977 _HELM_COMMAND="upgrade --install"
978 _HELM_ARGS="$INAME"
979 else
980 _HELM_COMMAND="install"
981 _HELM_ARGS="--name $INAME"
982 fi
983 (set -x; 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 >>$LOG 2>&1) >>$LOG 2>&1
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700984 SUCCESS=$?
985 while [ $SUCCESS -ne 0 ]; do
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700986 if [ $(($(date +%s) - $WAIT_START)) -gt $TIMEOUT_SECONDS ]; then
987 espin "$THEX"
988 doTimeout "waiting for helm install $CHART"
989 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700990 sspin $INDENT
991 COUNT=$(expr $COUNT - 1)
992 if [ $COUNT -eq 0 ]; then
David Bainbridge7f8bf992020-04-08 21:53:22 -0700993 if [ $HELM_USE_UPGRADE == "no" ]; then
994 (set -x; helm delete --purge $INAME >>$LOG 2>&1) >>$LOG 2>&1
995 fi
996 (set -x; 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 >>$LOG 2>&1) >>$LOG 2>&1
Andy Baviere22ff252019-12-19 11:40:31 -0700997 SUCCESS=$?
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700998 COUNT=$(expr 300 / 15)
999 fi
1000 sleep .15
1001 done
1002 espin $INDENT $VERIFIED
1003}
1004
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001005echo "INSTALL TYPE: $TYPE" >> $LOG
1006
1007bspin "Verify GOPATH"
1008export GOPATH=$(pwd)
Test User3d7ad8e2019-07-03 06:15:44 +00001009mkdir -p $GOPATH/bin
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001010espin $VERIFIED
1011
David Bainbridgee87067b2019-08-12 22:00:12 +00001012STIME=$(date +%s)
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001013if [ "$INSTALL_KUBECTL" == "no" ]; then
1014 bspin "Skip kubectl install"
1015 espin $NO_ENTRY
Test Userc13bdc92019-07-03 20:57:49 +00001016else
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001017 bspin "Verify kubectl $HELM"
1018 if [ -x $GOPATH/bin/kubectl ]; then
1019 espin $VERIFIED
1020 else
1021 espin $NOT_VERIFIED
1022 bspin - "Download and install Kubernetes/kubectl $DOWNLOAD"
1023 (set -x; curl -o $GOPATH/bin/kubectl -sSL https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/$HOSTOS/$HOSTARCH/kubectl >>$LOG 2>&1) >>$LOG 2>&1
1024 (set -x; chmod 755 $GOPATH/bin/kubectl >>$LOG 2>&1) >>$LOG 2>&1
1025 espin - $VERIFIED
1026 fi
Test Userc13bdc92019-07-03 20:57:49 +00001027fi
David Bainbridgee87067b2019-08-12 22:00:12 +00001028if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +00001029 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +00001030fi
Test Userc13bdc92019-07-03 20:57:49 +00001031
David Bainbridgee87067b2019-08-12 22:00:12 +00001032STIME=$(date +%s)
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001033if [ "$DEPLOY_K8S" == "no" ]; then
1034 bspin "Skip Kubernetes/Kind Deployment"
1035 espin $NO_ENTRY
1036else
Test Userba1e7e72019-07-10 22:27:54 +00001037 bspin "Verify Kubernetes/Kind $HELM"
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -08001038 IS_INSTALLED=0
1039 OP_TYPE="install"
Test Userba1e7e72019-07-10 22:27:54 +00001040 if [ -x $GOPATH/bin/kind ]; then
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -08001041 OP_TYPE="upgrade"
1042 if [ $($GOPATH/bin/kind --version | grep -c $KIND_VERSION) -eq 1 ]; then
1043 IS_INSTALLED=1
1044 espin $VERIFIED
1045 fi
1046 fi
1047 if [ $IS_INSTALLED -eq 0 ]; then
Test Userba1e7e72019-07-10 22:27:54 +00001048 espin $NOT_VERIFIED
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -08001049 bspin - "Download and $OP_TYPE Kubernetes/kind $DOWNLOAD"
David Bainbridge9e2a6662019-07-11 17:07:57 +00001050 (set -x; curl -o $GOPATH/bin/kind -sSL https://github.com/kubernetes-sigs/kind/releases/download/$KIND_VERSION/kind-$HOSTOS-$HOSTARCH >>$LOG 2>&1) >>$LOG 2>&1
Test Userba1e7e72019-07-10 22:27:54 +00001051 (set -x; chmod 755 $GOPATH/bin/kind >>$LOG 2>&1) >>$LOG 2>&1
1052 espin - $VERIFIED
1053 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001054fi
1055
David Bainbridgee87067b2019-08-12 22:00:12 +00001056if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +00001057 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +00001058fi
1059
1060STIME=$(date +%s)
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001061if [ "$INSTALL_HELM" == "no" ]; then
1062 bspin "Skip Helm Install"
1063 espin $NO_ENTRY
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001064else
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001065 bspin "Verify Helm $HELM"
David Bainbridgea34993d2020-04-01 09:15:42 -07001066 HELM_UPGRADE=0
1067 HELM_UPGRADE_DESC="install"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001068 if [ -x $GOPATH/bin/helm ]; then
David Bainbridgea34993d2020-04-01 09:15:42 -07001069 HAVE_VER=$($GOPATH/bin/helm version -c --template '{{.Client.SemVer}}')
1070 HELM_UP_DOWN=$(echo -e "$HAVE_VER\n$HELM_VERSION" | sort -V | head -1)
1071 if [ $HAVE_VER != $HELM_VERSION ]; then
1072 if [ $HELM_UP_DOWN == $HELM_VERSION ]; then
1073 HELM_UPGRADE_DESC="downgrade"
1074 else
1075 HELM_UPGRADE_DESC="upgrade"
1076 fi
1077 HELM_UPGRADE=1
1078 else
1079 espin $VERIFIED
1080 fi
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001081 else
David Bainbridgea34993d2020-04-01 09:15:42 -07001082 HELM_UPGRADE=1
1083 fi
1084
1085 if [ $HELM_UPGRADE -ne 0 ]; then
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001086 espin $NOT_VERIFIED
David Bainbridgea34993d2020-04-01 09:15:42 -07001087 bspin - "Download and $HELM_UPGRADE_DESC Helm $DOWNLOAD"
1088 (set -x; curl -sSL https://git.io/get_helm.sh | DESIRED_VERSION=$HELM_VERSION USE_SUDO=false HELM_INSTALL_DIR=$GOPATH/bin bash >>$LOG 2>&1) >>$LOG 2>&1
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001089 espin - $VERIFIED
1090 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001091fi
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -08001092
David Bainbridgee87067b2019-08-12 22:00:12 +00001093if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +00001094 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +00001095fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001096
David Bainbridgee87067b2019-08-12 22:00:12 +00001097STIME=$(date +%s)
Test Userb5712372019-07-03 21:52:17 +00001098bspin "Verify voltctl $HIGH_VOLTAGE"
David Bainbridged2811972019-12-14 01:14:09 +00001099VOK=0
1100VMESSAGE="install"
David K. Bainbridgeebf38d92020-02-10 10:46:31 -08001101export VC_VERSION="$VOLTCTL_VERSION"
1102if [ "$VC_VERSION" == "latest" ]; then
1103 export VC_VERSION=$(curl -sSL https://api.github.com/repos/opencord/voltctl/releases/latest | jq -r .tag_name | sed -e 's/^v//g')
1104fi
Test User3d7ad8e2019-07-03 06:15:44 +00001105if [ -x $GOPATH/bin/voltctl ]; then
David Bainbridge1ba64f12019-12-18 00:40:13 +00001106 VHAVE=$($GOPATH/bin/voltctl version --clientonly -o json | jq -r .version)
David K. Bainbridgeebf38d92020-02-10 10:46:31 -08001107 if [ $? -eq 0 -a "$VHAVE" == "$VC_VERSION" ]; then
David Bainbridged2811972019-12-14 01:14:09 +00001108 VOK=1
David Bainbridge1ba64f12019-12-18 00:40:13 +00001109 espin $VERIFIED
1110 else
David K. Bainbridgeebf38d92020-02-10 10:46:31 -08001111 VCHECK=$(echo -e "$VHAVE\n$VC_VERSION" | sort -V | head -1)
1112 if [ "$VCHECK" == "$VHAVE" ]; then
1113 VMESSAGE="upgrade"
1114 else
1115 VMESSAGE="downgrade"
1116 fi
David Bainbridged2811972019-12-14 01:14:09 +00001117 fi
1118fi
1119
David Bainbridge1ba64f12019-12-18 00:40:13 +00001120if [ $VOK -eq 0 ]; then
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001121 espin $NOT_VERIFIED
David Bainbridged2811972019-12-14 01:14:09 +00001122 bspin - "Download and $VMESSAGE voltctl $DOWNLOAD"
David K. Bainbridgeebf38d92020-02-10 10:46:31 -08001123 (set -x; curl -o $GOPATH/bin/voltctl -sSL https://github.com/opencord/voltctl/releases/download/v$VC_VERSION/voltctl-$VC_VERSION-$HOSTOS-$HOSTARCH >>$LOG 2>&1) >>$LOG 2>&1
Test User08ebbd92019-07-03 17:15:39 +00001124 (set -x; chmod 755 $GOPATH/bin/voltctl >>$LOG 2>&1) >>$LOG 2>&1
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001125 espin - $VERIFIED
1126fi
David Bainbridgee87067b2019-08-12 22:00:12 +00001127if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +00001128 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +00001129fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001130
1131bspin "Verify command PATH"
Test Userba1e7e72019-07-10 22:27:54 +00001132export PATH=$GOPATH/bin:$PATH
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001133espin $VERIFIED
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001134
David Bainbridgee87067b2019-08-12 22:00:12 +00001135STIME=$(date +%s)
Test Userba1e7e72019-07-10 22:27:54 +00001136if [ "$DEPLOY_K8S" == "yes" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +00001137 HAVE=$(kind get clusters | grep -c voltha-$NAME)
Test Userba1e7e72019-07-10 22:27:54 +00001138 bspin "Verify Kubernetes/Kind Cluster"
1139 sspin
1140 if [ $HAVE -eq 0 ]; then
David Bainbridge491b1bd2019-07-11 17:53:11 +00001141 espin $NOT_VERIFIED
1142 bspin - "Verify cluster configuration"
David Bainbridge0774b232019-08-02 06:37:19 +00001143 if [ ! -r ./$NAME-cluster.cfg ]; then
David Bainbridge491b1bd2019-07-11 17:53:11 +00001144 espin - $NOT_VERIFIED
David K. Bainbridge43422402020-03-06 07:41:22 -08001145 bspin - "Download cluster configuration: $TYPE-cluster.cfg to $NAME-cluster.cfg $DOWNLOAD"
David K. Bainbridgea00736b2020-01-08 14:33:17 -08001146 ERR_OUT=$(mktemp)
1147 (set -x; curl --fail -o ./$NAME-cluster.cfg -sSL https://raw.githubusercontent.com/ciena/kind-voltha/$VK_RELEASE/$TYPE-cluster.cfg >>$LOG 2>>$ERR_OUT) >>$LOG 2>&1
1148 if [ $? -ne 0 ]; then
1149 espin - $THEX
1150 echo -e "${RED}${BOLD}${ERROR}ERROR: $NAME-cluster.cfg${NORMAL}${RED} - $(cat $ERR_OUT)${NORMAL}"
1151 echo "ERROR: $(cat $ERR_OUT)" >>$LOG
1152 rm -rf $ERR_OUT ./$NAME-cluster.cfg
1153 exit 1
1154 fi
1155 rm -rf $ERR_OUT
1156 else
David K. Bainbridge43422402020-03-06 07:41:22 -08001157 espin - $VERIFIED
David K. Bainbridgea00736b2020-01-08 14:33:17 -08001158 fi
David Bainbridge0774b232019-08-02 06:37:19 +00001159 kind create cluster --name voltha-$NAME --config $NAME-cluster.cfg
David Bainbridge491b1bd2019-07-11 17:53:11 +00001160 else
1161 espin $VERIFIED
Test Userba1e7e72019-07-10 22:27:54 +00001162 fi
1163
David Bainbridge0774b232019-08-02 06:37:19 +00001164 export KUBECONFIG="$(kind get kubeconfig-path --name="voltha-$NAME")"
Test Userba1e7e72019-07-10 22:27:54 +00001165 P="coredns-.* \
David Bainbridge0774b232019-08-02 06:37:19 +00001166 etcd-voltha-$NAME-control-plane \
Test Userba1e7e72019-07-10 22:27:54 +00001167 kindnet-.* \
David Bainbridge0774b232019-08-02 06:37:19 +00001168 kube-apiserver-voltha-$NAME-control-plane \
1169 kube-controller-manager-voltha-$NAME-control-plane \
Test Userba1e7e72019-07-10 22:27:54 +00001170 kube-proxy-.* \
David Bainbridge0774b232019-08-02 06:37:19 +00001171 kube-scheduler-voltha-$NAME-control-plane"
Test Userba1e7e72019-07-10 22:27:54 +00001172
1173 EXPECT=$(test "$TYPE" == "minimal" && echo "12" || echo "14")
David Bainbridge4f1b5562019-08-19 04:46:52 +00001174 wait_for_pods - "kube-system" $EXPECT "includes" -1 "Waiting for system PODs to start" $P
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001175fi
David Bainbridgee87067b2019-08-12 22:00:12 +00001176if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +00001177 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +00001178fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001179
David Bainbridgee87067b2019-08-12 22:00:12 +00001180STIME=$(date +%s)
David Bainbridge4c6289c2019-09-03 21:11:32 +00001181COUNT=$(count_pods "kube-system" ":Running:" "tiller-deploy-.*")
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001182bspin "Verify Helm"
Test Userba1e7e72019-07-10 22:27:54 +00001183if [ $COUNT -ne 1 ]; then
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001184 espin $NOT_VERIFIED
Test Userb5712372019-07-03 21:52:17 +00001185 echo -e "Configuring Helm $GEAR"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001186 if [ "$INSTALL_HELM" == "no" ]; then
1187 bspin - "Skip Helm/Tiller Initialization"
1188 espin - $NO_ENTRY
1189 else
1190 bspin - "Initialize Helm"
1191 (set -x; helm init --upgrade >>$LOG 2>&1) >>$LOG 2>&1
1192 espin - $VERIFIED
David Bainbridge4f1b5562019-08-19 04:46:52 +00001193 wait_for_pods - "kube-system" 1 "includes" -1 "Waiting for Tiller POD to start" "tiller-deploy-.*"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001194 fi
Test Userb5712372019-07-03 21:52:17 +00001195 bspin - "Add Google Incubator repository to Helm"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001196 (set -x; helm repo add incubator https://kubernetes-charts-incubator.storage.googleapis.com >>$LOG 2>&1) >>$LOG 2>&1
1197 espin - $VERIFIED
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001198
Test Userba1e7e72019-07-10 22:27:54 +00001199 # HACK (sort-of) - the config for tiller is about to be patched, which will
1200 # cause the tiller pod to be recreated. This can sometimes cause a timing
1201 # issue with the "wait_for_pods" call on tiller as it may incorrectly
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001202 # identify the running/ready tiller pod that is soon to be terminated as
Test Userba1e7e72019-07-10 22:27:54 +00001203 # what it is waiting for. To avoid this issue we do a clean scale down and
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001204 # scale up of the pod so the script controlls when it should be expecting
Test Userba1e7e72019-07-10 22:27:54 +00001205 # things
1206 (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 -07001207
Test Userb5712372019-07-03 21:52:17 +00001208 bspin - "Add Google Stable repository to Helm"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001209 (set -x; helm repo add stable https://kubernetes-charts.storage.googleapis.com >>$LOG 2>&1) >>$LOG 2>&1
1210 espin - $VERIFIED
Test Userb5712372019-07-03 21:52:17 +00001211 bspin - "Add ONF repository to Helm"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001212 (set -x; helm repo add onf https://charts.opencord.org >>$LOG 2>&1) >>$LOG 2>&1
1213 espin - $VERIFIED
Test Userb5712372019-07-03 21:52:17 +00001214 bspin - "Update Helm repository cache"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001215 (set -x; helm repo update >>$LOG 2>&1) >>$LOG 2>&1
1216 espin - $VERIFIED
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001217
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001218 # Create and k8s service account so that Helm can create pods
Test Userb5712372019-07-03 21:52:17 +00001219 bspin - "Create Tiller ServiceAccount"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001220 (set -x; kubectl create serviceaccount --namespace kube-system tiller >>$LOG 2>&1) >>$LOG 2>&1
1221 espin - $VERIFIED
Test Userb5712372019-07-03 21:52:17 +00001222 bspin - "Create Tiller ClusterRoleBinding"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001223 (set -x; kubectl create clusterrolebinding tiller-cluster-rule --clusterrole=cluster-admin --serviceaccount=kube-system:tiller >>$LOG 2>&1) >>$LOG 2>&1
1224 espin - $VERIFIED
Test Userb5712372019-07-03 21:52:17 +00001225 bspin - "Update Tiller Manifest"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001226 (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 +00001227
1228 # HACK (sort-of) - part to, spin it back up
1229 (set -x; kubectl -n kube-system scale deploy tiller-deploy --replicas=1 >>$LOG 2>&1) >>$LOG 2>&1
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001230 espin - $VERIFIED
1231else
David Bainbridgea34993d2020-04-01 09:15:42 -07001232 if [ $(helm version -s --template '{{.Server.SemVer}}') != $HELM_VERSION ]; then
1233 espin $NOT_VERIFIED
1234 bspin - "Sync Tiller server version with helm client"
1235 (set -x; helm init --upgrade --force-upgrade --wait >>$LOG 2>&1) >>$LOG 2>&1
1236 espin - $VERIFIED
1237 else
1238 espin $VERIFIED
1239 fi
1240
David Bainbridge46505fb2019-10-01 21:13:20 +00001241 if [ "$UPDATE_HELM_REPOS" == "yes" ]; then
1242 bspin - "Update Helm repository cache"
1243 (set -x; helm repo update >>$LOG 2>&1) >>$LOG 2>&1
1244 espin - $VERIFIED
1245 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001246fi
David Bainbridge4f1b5562019-08-19 04:46:52 +00001247wait_for_pods - "kube-system" 1 "includes" -1 "Waiting for Tiller POD to start" "tiller-deploy-.*"
David Bainbridgee87067b2019-08-12 22:00:12 +00001248if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +00001249 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +00001250fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001251
David Bainbridgee87067b2019-08-12 22:00:12 +00001252STIME=$(date +%s)
David Bainbridge0774b232019-08-02 06:37:19 +00001253bspin "Verify Helm values file: $NAME-values.yaml"
1254if [ ! -r "./$NAME-values.yaml" ]; then
Test Userba1e7e72019-07-10 22:27:54 +00001255 espin $NOT_VERIFIED
David Bainbridge0774b232019-08-02 06:37:19 +00001256 bspin - "Download Helm values file: $TYPE-values.yaml to $NAME-values.yaml $DOWNLOAD"
David K. Bainbridgea00736b2020-01-08 14:33:17 -08001257 ERR_OUT=$(mktemp)
1258 (set -x; curl --fail -o ./$NAME-values.yaml -sSL https://raw.githubusercontent.com/ciena/kind-voltha/$VK_RELEASE/$TYPE-values.yaml >>$LOG 2>$ERR_OUT) >>$LOG 2>&1
1259 if [ $? -ne 0 ]; then
1260 espin - $THEX
1261 echo -e "${RED}${BOLD}${ERROR}ERROR: $NAME-values.yaml${NORMAL}${RED} - $(cat $ERR_OUT)${NORMAL}"
1262 echo "ERROR: $(cat $ERR_OUT)" >>$LOG
1263 rm -rf $ERR_OUT ./$NAME-values.yaml
1264 exit 1
1265 fi
1266 rm -rf $ERR_OUT
Test Userba1e7e72019-07-10 22:27:54 +00001267 espin - $VERIFIED
1268else
1269 espin $VERIFIED
1270fi
David Bainbridgee87067b2019-08-12 22:00:12 +00001271if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +00001272 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +00001273fi
Test Userba1e7e72019-07-10 22:27:54 +00001274
David Bainbridge99ac7a22019-08-31 02:26:43 +00001275STIME=$(date +%s)
1276bspin "Verify or download chart specific values files $DOWNLOAD"
1277VALUES_FILES="monkey-values.yaml"
David K. Bainbridgea00736b2020-01-08 14:33:17 -08001278ERR_OUT=$(mktemp)
David Bainbridge99ac7a22019-08-31 02:26:43 +00001279for i in $VALUES_FILES; do
1280 if [ ! -r ./$i ]; then
David K. Bainbridgea00736b2020-01-08 14:33:17 -08001281 (set -x; curl --fail -o ./$i -sSL https://raw.githubusercontent.com/ciena/kind-voltha/$VK_RELEASE/$i >>$LOG 2>$ERR_OUT) >>$LOG 2>&1
1282 if [ $? -ne 0 ]; then
1283 espin $THEX
1284 echo -e "${RED}${BOLD}${ERROR}ERROR: $i${NORMAL}${RED} - $(cat $ERR_OUT)${NORMAL}"
1285 echo "ERROR: $i - $(cat $ERR_OUT)" >>$LOG
1286 rm -rf $ERR_OUT ./$i
1287 exit 1
1288 fi
1289 rm -rf $ERR_OUT
David Bainbridge99ac7a22019-08-31 02:26:43 +00001290 fi
1291done
David Bainbridge1cecba52020-03-30 09:43:10 -07001292rm -rf $ERR_OUT
David Bainbridge99ac7a22019-08-31 02:26:43 +00001293espin $VERIFIED
1294if [ "$WITH_TIMINGS" == "yes" ]; then
1295 printtime $(expr $(date +%s) - $STIME)
1296fi
1297
1298if [ "$WITH_CHAOS" == "yes" ]; then
1299 bspin "Verify or clone kube-monkey helm chart $DOWNLOAD"
1300 if [ -r ./kube-monkey ]; then
1301 espin $VERIFIED
1302 else
1303 espin $NOT_VERIFIED
1304 bspin - "GIT clone kube-monkey"
1305 (set -x; git clone https://github.com/asobti/kube-monkey kube-monkey >>$LOG 2>&1) >>$LOG 2>&1
1306 espin - $VERIFIED
1307 fi
1308fi
1309
Test Userba1e7e72019-07-10 22:27:54 +00001310if [ "$JUST_K8S" == "yes" ]; then
1311 echo "Environment deployed, not deploying VOLTHA artifacts as requested. Good bye."
1312 echo ""
1313 echo "Please issue the following commands in your terminal to ensure that you" | tee -a $LOG
1314 echo "are accessing the correct Kubernetes/Kind cluster as well as have the " | tee -a $LOG
1315 echo "tools required by VOLTHA in your command path. " | tee -a $LOG
1316 echo "" | tee -a $LOG
1317 echo -en $BOLD
1318 if [ $DEPLOY_K8S == "yes" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +00001319 echo "export KUBECONFIG=\"\$(./bin/kind get kubeconfig-path --name=\"voltha-$NAME\")\"" | tee -a $LOG
Test Userba1e7e72019-07-10 22:27:54 +00001320 fi
1321 echo "export PATH=$GOPATH/bin:\$PATH" | tee -a $LOG
1322 echo -en $NORMAL
1323 echo "" | tee -a $LOG
1324 echo "Thank you for choosing kind-voltha for you quick cluster needs." | tee -a $LOG
1325 exit 0
1326fi
1327
David Bainbridge76afd812020-04-06 09:53:52 -07001328if [ $WITH_ETCD != "yes" -a $WITH_ETCD != "external" ]; then
David Bainbridge696bc632020-04-05 21:49:37 -07001329 bspin "Skip ETCD Operator Deployment"
1330 espin $NO_ENTRY
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001331else
David Bainbridge696bc632020-04-05 21:49:37 -07001332 STIME=$(date +%s)
David Bainbridge76afd812020-04-06 09:53:52 -07001333 NS=$VOLTHA_NS
1334 if [ $WITH_ETCD == "external" ]; then
1335 NS=$INFRA_NS
1336 fi
David Bainbridge696bc632020-04-05 21:49:37 -07001337 bspin "Verify ETCD Operator $OLD_KEY"
David Bainbridge7f8bf992020-04-08 21:53:22 -07001338 if [ $HELM_USE_UPGRADE == "yes" -o $(helm list --deployed --short --namespace $NS "^etcd-operator\$" | wc -l) -ne 1 ]; then
David Bainbridge696bc632020-04-05 21:49:37 -07001339 espin $NOT_VERIFIED
David Bainbridge7f8bf992020-04-08 21:53:22 -07001340 helm_install - $NS etcd-operator stable/etcd-operator latest "$_HELM_DESC ETCD Operator"
David Bainbridge696bc632020-04-05 21:49:37 -07001341 else
1342 espin $VERIFIED
1343 fi
1344 EXPECT=$(test "$TYPE" == "minimal" && echo "1" || echo "3")
David Bainbridge76afd812020-04-06 09:53:52 -07001345 wait_for_pods - "$NS" $EXPECT "includes" -1 "Waiting for ETCD Operator to start" "etcd-operator-.*"
David Bainbridge696bc632020-04-05 21:49:37 -07001346 if [ "$WITH_TIMINGS" == "yes" ]; then
1347 printtime $(expr $(date +%s) - $STIME)
1348 fi
David Bainbridgee87067b2019-08-12 22:00:12 +00001349fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001350
David Bainbridgee87067b2019-08-12 22:00:12 +00001351STIME=$(date +%s)
David Bainbridgeb270c202019-07-26 01:44:42 +00001352if [ $WITH_ONOS == "yes" ]; then
1353 bspin "Verify ONOS installed $BIRD"
David Bainbridge7f8bf992020-04-08 21:53:22 -07001354 if [ $HELM_USE_UPGRADE == "yes" -o $(helm list --deployed --short --namespace $INFRA_NS "^onos\$" | wc -l) -ne 1 ]; then
David Bainbridgeb270c202019-07-26 01:44:42 +00001355 espin $NOT_VERIFIED
David Bainbridge7f8bf992020-04-08 21:53:22 -07001356 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 +00001357 else
1358 espin $VERIFIED
1359 fi
David Bainbridge76afd812020-04-06 09:53:52 -07001360 wait_for_pods - "$INFRA_NS" 1 "includes" -1 "Waiting for ONOS to start" "onos-.*"
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001361
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -08001362 if [ $WITH_PORT_FORWARDS == "yes" ]; then
1363 bspin - "Forward ONOS API port $FORWARD"
1364 kill_port_forward onos-ui
David Bainbridge76afd812020-04-06 09:53:52 -07001365 port_forward $INFRA_NS onos-ui $ONOS_API_PORT 8181
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -08001366 espin - $VERIFIED
1367 bspin - "Forward ONOS SSH port $FORWARD"
1368 kill_port_forward onos-ssh
David Bainbridge76afd812020-04-06 09:53:52 -07001369 port_forward $INFRA_NS onos-ssh $ONOS_SSH_PORT 8101
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -08001370 espin - $VERIFIED
1371 _ONOS_API_EP="127.0.0.1:$ONOS_API_PORT"
1372 else
David Bainbridge76afd812020-04-06 09:53:52 -07001373 _ONOS_API_EP=$(get_service_ep $INFRA_NS onos-ui)
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -08001374 fi
David Bainbridged31d6122019-08-13 19:37:59 +00001375 bspin - "Verify or download ONOS configuration support files $DOWNLOAD"
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001376 ONOS_FILES="olt-onos-enableExtraneousRules.json onos-aaa.json \
David Bainbridge696bc632020-04-05 21:49:37 -07001377 onos-dhcpl2relay.json onos-sadis-sample.json"
David Bainbridged31d6122019-08-13 19:37:59 +00001378 (set -x; mkdir -p ./onos-files >>$LOG 2>&1) >>$LOG 2>&1
David K. Bainbridgea00736b2020-01-08 14:33:17 -08001379 ERR_OUT=$(mktemp)
David Bainbridge2b19e832019-08-16 02:40:53 +00001380 for i in $ONOS_FILES; do
David Bainbridged31d6122019-08-13 19:37:59 +00001381 if [ ! -r ./onos-files/$i ]; then
David K. Bainbridgea00736b2020-01-08 14:33:17 -08001382 (set -x; curl --fail -o ./onos-files/$i -sSL https://raw.githubusercontent.com/ciena/kind-voltha/$VK_RELEASE/onos-files/$i >>$LOG 2>$ERR_OUT) >>$LOG 2>&1
1383 if [ $? -ne 0 ]; then
1384 espin - $THEX
1385 echo -e "${RED}${BOLD}${ERROR}ERROR: $i${NORMAL}${RED} - $(cat $ERR_OUT)${NORMAL}"
1386 echo "ERROR: $(cat $ERR_OUT)" >>$LOG
1387 rm -rf $ERR_OUT ./onos-files/$i
1388 exit 1
1389 fi
1390 rm -rf $ERR_OUT
David Bainbridged31d6122019-08-13 19:37:59 +00001391 fi
1392 done
David Bainbridge1cecba52020-03-30 09:43:10 -07001393 rm -rf $ERR_OUT
Test Userba1e7e72019-07-10 22:27:54 +00001394 espin - $VERIFIED
David Bainbridge27790d62019-08-13 22:43:19 +00001395
1396 if [ $INSTALL_ONOS_APPS == "yes" ]; then
1397 bspin - "Installing custom ONOS applications"
1398 if [ -x onos-files/onos-apps -a $(ls -1 onos-files/onos-apps/*.oar 2>/dev/null | wc -l) -gt 0 ]; then
1399 for OAR in $(ls -1 onos-files/onos-apps/*.oar); do
1400 sspin - "Installing custom ONOS applications - $OAR$CEOL"
David Bainbridge2b19e832019-08-16 02:40:53 +00001401 override_onos_app $OAR
David Bainbridge27790d62019-08-13 22:43:19 +00001402 done
1403 espin - "$VERIFIED Installing custom ONOS applications$CEOL"
1404 else
1405 espin - "$NOT_VERIFIED Installing custom ONOS applications - None Found"
1406 fi
1407 fi
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001408
David Bainbridge696bc632020-04-05 21:49:37 -07001409 if [ $WITH_KAFKA != "no" ]; then
David Bainbridge837e8bd2020-04-06 13:17:14 -07001410 check_onos_app_active org.opencord.kafka
David Bainbridge76afd812020-04-06 09:53:52 -07001411 _HOST=voltha-kafka.$INFRA_NS.svc.cluster.local
David Bainbridge837e8bd2020-04-06 13:17:14 -07001412 _PORT=9092
David Bainbridge76afd812020-04-06 09:53:52 -07001413 if [ $WITH_KAFKA == "yes" ]; then
1414 _HOST=voltha-kafka.$VOLTHA_NS.svc.cluster.local
1415 _PORT=9092
1416 elif [ $WITH_KAFKA == "external" ]; then
1417 _HOST=kafka.$INFRA_NS.svc.cluster.local
1418 _PORT=9092
1419 else
David Bainbridge837e8bd2020-04-06 13:17:14 -07001420 _HOST=$(echo $WITH_KAFKA | cut -d: -f1)
1421 _PORT=$(echo $WITH_KAFKA | cut -s -d: -f2)
1422 _PORT=${_PORT:-9092}
1423 fi
1424 push_onos_config "json" "Push ONOS Kafka Configuration" "network/configuration/apps/org.opencord.kafka" \
1425 "$(echo $(cat <<EOJ
David Bainbridge696bc632020-04-05 21:49:37 -07001426{
1427 "kafka": {
1428 "bootstrapServers": "$_HOST:$_PORT"
1429 }
1430}
1431EOJ
1432) | tr -d '[:space:]')"
David Bainbridge837e8bd2020-04-06 13:17:14 -07001433 fi
Matteo Scandolo9a77a732020-01-09 14:24:12 -08001434 check_onos_app_active org.opencord.dhcpl2relay
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001435 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 -08001436 check_onos_app_active org.opencord.olt
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001437 # FIXME use WITH_DHCP and WITH_EAPOL flags to configre OLT App
Hardik Windlassa7501fb2020-02-17 14:28:20 +00001438 # Default value for "enableEapol" is true in OLT App
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001439 if [ $WITH_EAPOL == "yes" ]; then
1440 push_onos_config "json" "Enable VOLTHA ONOS EAPOL provisioning" "configuration/org.opencord.olt.impl.OltFlowService" '{"enableEapol":true}'
Hardik Windlassa7501fb2020-02-17 14:28:20 +00001441 elif [ $WITH_EAPOL == "no" ]; then
1442 push_onos_config "json" "Disable VOLTHA ONOS EAPOL provisioning" "configuration/org.opencord.olt.impl.OltFlowService" '{"enableEapol":false}'
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001443 fi
Hardik Windlassa7501fb2020-02-17 14:28:20 +00001444 # Default value for "enableDhcpOnProvisioning" is false and for "enableDhcpV4" is true in OLT App
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001445 if [ $WITH_DHCP == "yes" ]; then
1446 push_onos_config "json" "Enable VOLTHA ONOS DHCP provisioning" "configuration/org.opencord.olt.impl.OltFlowService" '{"enableDhcpOnProvisioning":true,"enableDhcpV4":true}'
Hardik Windlassa7501fb2020-02-17 14:28:20 +00001447 elif [ $WITH_DHCP == "no" ]; then
1448 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 -08001449 fi
Hardik Windlassa7501fb2020-02-17 14:28:20 +00001450 # Default value for "enableIgmpOnProvisioning" is false in OLT App
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001451 if [ $WITH_IGMP == "yes" ]; then
1452 push_onos_config "json" "Enable VOLTHA ONOS IGMP provisioning" "configuration/org.opencord.olt.impl.OltFlowService" '{"enableIgmpOnProvisioning":true}'
Hardik Windlassa7501fb2020-02-17 14:28:20 +00001453 elif [ $WITH_IGMP == "no" ]; then
1454 push_onos_config "json" "Disable VOLTHA ONOS IGMP provisioning" "configuration/org.opencord.olt.impl.OltFlowService" '{"enableIgmpOnProvisioning":false}'
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001455 fi
David K. Bainbridge484d80c2020-03-05 21:44:34 -08001456 if [ $ENABLE_ONOS_EXTRANEOUS_RULES == "yes" ]; then
1457 push_onos_config "file" "Enabling extraneous rules for ONOS" "configuration/org.onosproject.net.flow.impl.FlowRuleManager" "onos-files/olt-onos-enableExtraneousRules.json"
1458 fi
David K. Bainbridgeb859e912020-03-13 14:07:52 -07001459 if [ $(echo ":yes:file:" | grep -c ":$CONFIG_SADIS:") -eq 1 ]; then
Matteo Scandolo9a77a732020-01-09 14:24:12 -08001460 check_onos_app_active org.opencord.sadis
Hardik Windlassb3147602020-03-09 16:59:15 +05301461 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 -07001462 elif [ "$CONFIG_SADIS" == "bbsim" ]; then
1463 push_onos_config "json" \
1464 "[optional] Push ONOS configuration for BBSIM SADIS servers" \
1465 "network/configuration/apps/org.opencord.sadis" \
1466 "$(echo $(cat <<EOJ
1467{
1468 "sadis": {
1469 "integration": {
David Bainbridge76afd812020-04-06 09:53:52 -07001470 "url": "http://bbsim.$BBSIM_NS.svc.cluster.local:50074/v2/subscribers/%s",
David K. Bainbridgeb859e912020-03-13 14:07:52 -07001471 "cache": {
1472 "enabled": true,
1473 "maxsize": 50,
1474 "ttl": "PT1m"
1475 }
1476 }
1477 },
1478 "bandwidthprofile": {
1479 "integration": {
David Bainbridge76afd812020-04-06 09:53:52 -07001480 "url": "http://bbsim.$BBSIM_NS.svc.cluster.local:50074/v2/bandwidthprofiles/%s",
David K. Bainbridgeb859e912020-03-13 14:07:52 -07001481 "cache": {
1482 "enabled": true,
1483 "maxsize": 50,
1484 "ttl": "PT1m"
1485 }
1486 }
1487 }
1488}
1489EOJ
1490) | tr -d '[:space:]')"
1491 elif [ "$CONFIG_SADIS" == "url" ]; then
1492 push_onos_config "json" \
1493 "[optional] Push ONOS configuration for custom SADIS and Bandwidth Profile servers" \
1494 "network/configuration/apps/org.opencord.sadis" \
1495 "$(echo $(cat <<EOJ
1496{
1497 "sadis": {
1498 "integration": {
1499 "url": "$SADIS_SUBSCRIBERS",
1500 "cache": {
1501 "enabled": true,
1502 "maxsize": 50,
1503 "ttl": "PT1m"
1504 }
1505 }
1506 },
1507 "bandwidthprofile": {
1508 "integration": {
1509 "url": "$SADIS_BANDWIDTH_PROFILES",
1510 "cache": {
1511 "enabled": true,
1512 "maxsize": 50,
1513 "ttl": "PT1m"
1514 }
1515 }
1516 }
1517}
1518EOJ
1519) | tr -d '[:space:]')"
David Bainbridge2b19e832019-08-16 02:40:53 +00001520 fi
Test Userba1e7e72019-07-10 22:27:54 +00001521fi
David Bainbridgee87067b2019-08-12 22:00:12 +00001522if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +00001523 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +00001524fi
Test Userba1e7e72019-07-10 22:27:54 +00001525
David Bainbridge76afd812020-04-06 09:53:52 -07001526if [ $WITH_ETCD == "external" ]; then
1527 STIME=$(date +%s)
1528 bspin "Verify external ETCD cluster $OLD_KEY"
1529 EXPECT=$(test "$TYPE" == "minimal" && echo "1" || echo "3")
David Bainbridge7f8bf992020-04-08 21:53:22 -07001530 if [ $HELM_USE_UPGRADE == "yes" -o $(helm list --deployed --short --namespace $INFRA_NS "^etcd-cluster\$" | wc -l) -ne 1 ]; then
David Bainbridge76afd812020-04-06 09:53:52 -07001531 espin $NOT_VERIFIED
1532 INTERNAL_EXTRA_HELM_INSTALL_ARGS+="--set clusterName=etcd-cluster --set autoCompactionRetention=1 --set clusterSize=$EXPECT"
David Bainbridge7f8bf992020-04-08 21:53:22 -07001533 helm_install - $INFRA_NS etcd-cluster onf/voltha-etcd-cluster latest "$_HELM_DESC external ETCD cluster"
David Bainbridge76afd812020-04-06 09:53:52 -07001534 else
1535 espin $VERIFIED
1536 fi
1537 wait_for_pods - "$INFRA_NS" $EXPECT "includes" -1 "Waiting for ETCD cluster to start" "etcd-cluster-.*"
1538 if [ "$WITH_TIMINGS" == "yes" ]; then
1539 printtime $(expr $(date +%s) - $STIME)
1540 fi
1541fi
1542
1543if [ $WITH_KAFKA == "external" ]; then
1544 _TMP=$(mktemp -u)
1545 _COUNT=$(test $TYPE == "minimal" && echo "1" || echo "3")
1546 cat << EOC > $_TMP
1547configurationOverrides:
1548 "default.replication.factor": $_COUNT
1549 "offsets.topic.replication.factor": $_COUNT
1550 "log.retention.hours": 4
1551 "log.message.timestamp.type": "LogAppendTime"
1552persistence:
1553 enabled: false
1554zookeeper:
1555 replicaCount: 1
1556 persistence:
1557 enabled: false
1558replicas: $_COUNT
1559EOC
1560 STIME=$(date +%s)
1561 bspin "Verify external Kafka cluster $OLD_KEY"
1562 EXPECT=$(test "$TYPE" == "minimal" && echo "2" || echo "4")
David Bainbridge7f8bf992020-04-08 21:53:22 -07001563 if [ $HELM_USE_UPGRADE == "yes" -o $(helm list --deployed --short --namespace $INFRA_NS "^kafka\$" | wc -l) -ne 1 ]; then
David Bainbridge76afd812020-04-06 09:53:52 -07001564 espin $NOT_VERIFIED
1565 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" -f $_TMP"
David Bainbridge7f8bf992020-04-08 21:53:22 -07001566 helm_install - $INFRA_NS kafka incubator/kafka latest "$_HELM_DESC external Kafka cluster"
David Bainbridge76afd812020-04-06 09:53:52 -07001567 else
1568 espin $VERIFIED
1569 fi
1570 # DKB
1571 wait_for_pods - "$INFRA_NS" $EXPECT "includes" -1 "Waiting for Kafka cluster to start" "kafka-.*"
1572 if [ "$WITH_TIMINGS" == "yes" ]; then
1573 printtime $(expr $(date +%s) - $STIME)
1574 fi
1575 rm -rf $_TMP
1576fi
1577
David Bainbridgee87067b2019-08-12 22:00:12 +00001578STIME=$(date +%s)
David Bainbridge696bc632020-04-05 21:49:37 -07001579EXPECT=1
1580if [ "$ONLY_ONE" == "yes" ]; then
1581 EXPECT=$((EXPECT+1))
1582 INTERNAL_EXTRA_HELM_INSTALL_ARGS="--set therecanbeonlyone=true"
1583else
1584 EXPECT=$((EXPECT+2))
1585fi
David Bainbridge76afd812020-04-06 09:53:52 -07001586case $WITH_ETCD in
1587 no)
1588 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set private_etcd_cluster=false"
1589 ;;
1590 yes)
1591 _HOST="voltha-etcd-cluster-client.$VOLTHA_NS.svc.cluster.local"
1592 _PORT=2379
1593 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set services.etcd.service=$_HOST --set services.etcd.port=$_PORT"
1594 EXPECT=$((EXPECT+$(test "$TYPE" == "minimal" && echo "1" || echo "3")))
1595 ;;
1596 external)
1597 _HOST="etcd-cluster-client.$INFRA_NS.svc.cluster.local"
1598 _PORT=2379
1599 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set private_etcd_cluster=false --set services.etcd.service=$_HOST --set services.etcd.port=$_PORT"
1600 ;;
1601 *)
David Bainbridge696bc632020-04-05 21:49:37 -07001602 _HOST=$(echo $WITH_ETCD | cut -d: -f1)
1603 _PORT=$(echo $WITH_ETCD | cut -s -d: -f2)
1604 _PORT=${_PORT:-2379}
David Bainbridge76afd812020-04-06 09:53:52 -07001605 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set private_etcd_cluster=false --set services.etcd.service=$_HOST --set services.etcd.port=$_PORT"
1606 ;;
1607esac
1608case $WITH_KAFKA in
1609 no)
1610 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set private_kafka_cluster=false"
1611 ;;
1612 yes)
1613 _HOST=voltha-kafka.$VOLTHA_NS.svc.cluster.local
1614 _PORT=9092
1615 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set kafka_broker=$_HOST:$_PORT --set services.kafka.adapter.service=$_HOST --set services.kafka.adapter.port=$_PORT --set services.kafka.cluster.service=$_HOST --set services.kafka.cluster.port=$_PORT"
1616 EXPECT=$((EXPECT+$(test "$TYPE" == "minimal" && echo "2" || echo "4")))
1617 ;;
1618 external)
1619 _HOST=kafka.$INFRA_NS.svc.cluster.local
1620 _PORT=9092
1621 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set private_kafka_cluster=false --set kafka_broker=$_HOST:$_PORT --set services.kafka.adapter.service=$_HOST --set services.kafka.adapter.port=$_PORT --set services.kafka.cluster.service=$_HOST --set services.kafka.cluster.port=$_PORT"
1622 ;;
1623 *)
David Bainbridge696bc632020-04-05 21:49:37 -07001624 _HOST=$(echo $WITH_KAFKA | cut -d: -f1)
1625 _PORT=$(echo $WITH_KAFKA | cut -s -d: -f2)
1626 _PORT=${_PORT:-9092}
David Bainbridge76afd812020-04-06 09:53:52 -07001627 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set private_kafka_cluster=false --set kafka_broker=$_HOST:$_PORT --set services.kafka.adapter.service=$_HOST --set services.kafka.adapter.port=$_PORT --set services.kafka.cluster.service=$_HOST --set services.kafka.cluster.port=$_PORT"
1628 ;;
1629esac
1630
1631if [ $WITH_ONOS == "yes" ]; then
1632 _HOST=onos-openflow.$INFRA_NS.svc.cluster.local
1633 _PORT=6653
1634 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set services.controller.service=$_HOST --set services.controller.port=$_PORT"
1635elif [ $WITH_ONOS != "no" ]; then
1636 _HOST=$(echo $WITH_ONOS | cut -d: -f1)
1637 _PORT=$(echo $WITH_ONOS | cut -s -d: -f2)
1638 _PORT=${_PORT:-6653}
1639 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set services.controller.service=$_HOST --set services.controller.port=$_PORT"
David Bainbridge696bc632020-04-05 21:49:37 -07001640fi
Test Userb5712372019-07-03 21:52:17 +00001641bspin "Verify VOLTHA installed $HIGH_VOLTAGE"
David Bainbridge7f8bf992020-04-08 21:53:22 -07001642if [ $HELM_USE_UPGRADE == "yes" -o $(helm list --deployed --short --namespace $VOLTHA_NS "^voltha\$" | wc -l) -ne 1 ]; then
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001643 espin $NOT_VERIFIED
David Bainbridge7f8bf992020-04-08 21:53:22 -07001644 helm_install - $VOLTHA_NS voltha $VOLTHA_CHART $VOLTHA_CHART_VERSION "$_HELM_DESC VOLTHA Core"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001645else
1646 espin $VERIFIED
1647fi
David Bainbridge696bc632020-04-05 21:49:37 -07001648INTERNAL_EXTRA_HELM_INSTALL_ARGS=
Test Userba1e7e72019-07-10 22:27:54 +00001649
David Bainbridge90fd8e32019-08-21 23:32:47 +00001650VOLTHA="voltha-ofagent-.* \
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001651 rw-core.* \
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001652 voltha-etcd-cluster-.* \
1653 voltha-kafka-.* \
1654 voltha-zookeeper-.*"
David Bainbridge76afd812020-04-06 09:53:52 -07001655wait_for_pods - "$VOLTHA_NS" $EXPECT "includes" -1 "Waiting for VOLTHA Core to start" $VOLTHA
David Bainbridgee87067b2019-08-12 22:00:12 +00001656if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +00001657 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +00001658fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001659
David Bainbridge46505fb2019-10-01 21:13:20 +00001660if [ "$WITH_ADAPTERS" == "yes" ]; then
1661 STIME=$(date +%s)
1662 EXPECT=0
David Bainbridge3517f6c2020-04-08 12:14:08 -07001663 if [ $WITH_ETCD == "yes" ]; then
1664 _HOST=voltha-etcd-cluster-client.$VOLTHA_NS.svc.cluster.local
1665 _PORT=2379
1666 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set services.etcd.service=$_HOST --set services.etcd.port=$_PORT"
1667 elif [ $WITH_ETCD == "external" ]; then
1668 _HOST=etcd-cluster-client.$INFRA_NS.svc.cluster.local
1669 _PORT=2379
1670 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set services.etcd.service=$_HOST --set services.etcd.port=$_PORT"
1671 elif [ $WITH_ETCD != "no" ]; then
1672 _HOST=$(echo $WITH_ETCD | cut -d: -f1)
1673 _PORT=$(echo $WITH_ETCD | cut -s -d: -f2)
1674 _PORT=${_PORT:-2379}
1675 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set services.etcd.service=$_HOST --set services.etcd.port=$_PORT"
David Bainbridge696bc632020-04-05 21:49:37 -07001676 fi
David Bainbridge3517f6c2020-04-08 12:14:08 -07001677 if [ $WITH_KAFKA == "yes" ]; then
1678 _HOST=voltha-kafka.$VOLTHA_NS.svc.cluster.local
1679 _PORT=9092
1680 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set kafka_broker=$_HOST:$_PORT --set services.kafka.adapter.service=$_HOST --set services.kafka.adapter.port=$_PORT --set services.kafka.cluster.service=$_HOST --set services.kafka.cluster.port=$_PORT"
1681 elif [ $WITH_KAFKA == "external" ]; then
1682 _HOST=kafka.$INFRA_NS.svc.cluster.local
1683 _PORT=9092
1684 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set kafka_broker=$_HOST:$_PORT --set services.kafka.adapter.service=$_HOST --set services.kafka.adapter.port=$_PORT --set services.kafka.cluster.service=$_HOST --set services.kafka.cluster.port=$_PORT"
1685 elif [ $WITH_KAFKA != "no" ]; then
1686 _HOST=$(echo $WITH_KAFKA | cut -d: -f1)
1687 _PORT=$(echo $WITH_KAFKA | cut -s -d: -f2)
1688 _PORT=${_PORT:-9092}
1689 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set kafka_broker=$_HOST:$_PORT --set services.kafka.adapter.service=$_HOST --set services.kafka.adapter.port=$_PORT --set services.kafka.cluster.service=$_HOST --set services.kafka.cluster.port=$_PORT"
David Bainbridge696bc632020-04-05 21:49:37 -07001690 fi
David Bainbridge46505fb2019-10-01 21:13:20 +00001691 echo -e "Verify Adapters $PLUG"
1692 if [ "$WITH_SIM_ADAPTERS" == "yes" ]; then
1693 bspin - "Verify Simulated Adapters installed"
David Bainbridge7f8bf992020-04-08 21:53:22 -07001694 if [ $HELM_USE_UPGRADE == "yes" -o $(helm list --deployed --short --namespace $ADAPTER_NS "^sim\$" | wc -l) -ne 1 ]; then
David Bainbridge46505fb2019-10-01 21:13:20 +00001695 espin - $NOT_VERIFIED
David Bainbridge7f8bf992020-04-08 21:53:22 -07001696 helm_install - $ADAPTER_NS sim $VOLTHA_ADAPTER_SIM_CHART $VOLTHA_ADAPTER_SIM_CHART_VERSION "$_HELM_DESC Simulated Adapters"
David Bainbridge46505fb2019-10-01 21:13:20 +00001697 else
1698 espin - $VERIFIED
1699 fi
1700 EXPECT=$(expr $EXPECT + 2)
1701 fi
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001702
David Bainbridge46505fb2019-10-01 21:13:20 +00001703 if [ "$WITH_OPEN_ADAPTERS" == "yes" ]; then
1704 bspin - "Verify OpenOLT Adapter installed"
David Bainbridge7f8bf992020-04-08 21:53:22 -07001705 if [ $HELM_USE_UPGRADE == "yes" -o $(helm list --deployed --short --namespace $ADAPTER_NS "^open-olt\$" | wc -l) -ne 1 ]; then
David Bainbridge46505fb2019-10-01 21:13:20 +00001706 espin - $NOT_VERIFIED
David Bainbridge7f8bf992020-04-08 21:53:22 -07001707 helm_install - $ADAPTER_NS open-olt $VOLTHA_ADAPTER_OPEN_OLT_CHART $VOLTHA_ADAPTER_OPEN_OLT_CHART_VERSION "$_HELM_DESC OpenOLT Adapter"
David Bainbridge46505fb2019-10-01 21:13:20 +00001708 else
1709 espin - $VERIFIED
1710 fi
1711 bspin - "Verify OpenONU Adapter installed"
David Bainbridge7f8bf992020-04-08 21:53:22 -07001712 if [ $HELM_USE_UPGRADE == "yes" -o $(helm list --deployed --short --namespace $ADAPTER_NS "^open-onu\$" | wc -l) -ne 1 ]; then
David Bainbridge46505fb2019-10-01 21:13:20 +00001713 espin - $NOT_VERIFIED
David Bainbridge7f8bf992020-04-08 21:53:22 -07001714 helm_install - $ADAPTER_NS open-onu $VOLTHA_ADAPTER_OPEN_ONU_CHART $VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION "$_HELM_DESC OpenONU Adapter"
David Bainbridge46505fb2019-10-01 21:13:20 +00001715 else
1716 espin - $VERIFIED
1717 fi
1718 EXPECT=$(expr $EXPECT + 2)
1719 fi
David Bainbridge696bc632020-04-05 21:49:37 -07001720 INTERNAL_EXTRA_HELM_INSTALL_ARGS=
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001721
David Bainbridge46505fb2019-10-01 21:13:20 +00001722 ADAPTERS="adapter-.*"
David Bainbridge76afd812020-04-06 09:53:52 -07001723 wait_for_pods - "$ADAPTER_NS " $EXPECT "includes" -1 "Waiting for adapters to start" $ADAPTERS
David Bainbridge46505fb2019-10-01 21:13:20 +00001724 if [ "$WITH_TIMINGS" == "yes" ]; then
1725 printtime $(expr $(date +%s) - $STIME)
1726 fi
David Bainbridgee87067b2019-08-12 22:00:12 +00001727fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001728
Test User7d866122019-07-09 17:52:35 +00001729if [ $WITH_BBSIM == "yes" ]; then
David Bainbridgee87067b2019-08-12 22:00:12 +00001730 STIME=$(date +%s)
Test User7d866122019-07-09 17:52:35 +00001731 echo -e "Verify BBSIM $PLUG"
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001732 bspin - "Verify BBSIM Installed"
David K. Bainbridge43422402020-03-06 07:41:22 -08001733 for instance in $(seq 0 $(($NUM_OF_BBSIM-1))); do
1734 if [ $instance -eq 0 ]; then
1735 instance_num=""
1736 else
1737 instance_num=$instance
1738 fi
David Bainbridge7f8bf992020-04-08 21:53:22 -07001739 if [ $HELM_USE_UPGRADE == "yes" -o $(helm list --deployed --short --namespace $BBSIM_NS "^bbsim${instance_num}\$" | wc -l) -ne 1 ]; then
David K. Bainbridge43422402020-03-06 07:41:22 -08001740 espin - $NOT_VERIFIED
Matteo Scandolo5a149572020-04-01 10:14:57 -07001741 S_TAG=$((900+$instance))
1742 INTERNAL_EXTRA_HELM_INSTALL_ARGS="--set olt_id=$instance,s_tag=$S_TAG"
David Bainbridge7f8bf992020-04-08 21:53:22 -07001743 helm_install - $BBSIM_NS bbsim${instance_num} $VOLTHA_BBSIM_CHART $VOLTHA_BBSIM_CHART_VERSION "$_HELM_DESC BBSIM${instance_num}"
David Bainbridge2eaf2cf2020-03-18 12:54:08 -07001744 INTERNAL_EXTRA_HELM_INSTALL_ARGS=
David K. Bainbridge43422402020-03-06 07:41:22 -08001745 else
1746 espin - $VERIFIED
1747 fi
1748 done
David Bainbridge76afd812020-04-06 09:53:52 -07001749 wait_for_pods - "$BBSIM_NS" $NUM_OF_BBSIM "includes" -1 "Waiting for BBSIM to start" "bbsim*"
David Bainbridgee87067b2019-08-12 22:00:12 +00001750 if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +00001751 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +00001752 fi
Test User7d866122019-07-09 17:52:35 +00001753fi
1754
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001755if [ $WITH_RADIUS == "yes" ]; then
David Bainbridgee87067b2019-08-12 22:00:12 +00001756 STIME=$(date +%s)
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001757 echo -e "Verify RADIUS $LOCK"
1758 bspin - "Verify RADIUS Installed"
David Bainbridge7f8bf992020-04-08 21:53:22 -07001759 if [ $HELM_USE_UPGRADE == "yes" -o $(helm list --deployed --short --namespace $INFRA_NS "^radius\$" | wc -l) -ne 1 ]; then
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001760 espin - $NOT_VERIFIED
David Bainbridge7f8bf992020-04-08 21:53:22 -07001761 helm_install - $INFRA_NS radius onf/freeradius latest "$_HELM_DESC RADIUS"
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001762 else
1763 espin - $VERIFIED
1764 fi
David Bainbridge76afd812020-04-06 09:53:52 -07001765 wait_for_pods - "$INFRA_NS" 1 "includes" -1 "Waiting for RADIUS to start" "radius-.*"
David Bainbridgee87067b2019-08-12 22:00:12 +00001766 if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +00001767 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +00001768 fi
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001769fi
1770
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -08001771if [ $WITH_PORT_FORWARDS == "yes" ]; then
1772 STIME=$(date +%s)
1773 bspin - "Forward VOLTHA API port $FORWARD"
1774 kill_port_forward voltha-api
David Bainbridge76afd812020-04-06 09:53:52 -07001775 port_forward $VOLTHA_NS voltha-api $VOLTHA_API_PORT 55555
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -08001776 espin - $VERIFIED
David Bainbridge76afd812020-04-06 09:53:52 -07001777 if [ $WITH_ETCD == "yes" -o $WITH_ETCD == "external" ]; then
1778 _NS=$(test $WITH_ETCD == "yes" && echo $VOLTHA_NS || echo $INFRA_NS)
David Bainbridge696bc632020-04-05 21:49:37 -07001779 bspin - "Forward VOLTHA ETCD port $FORWARD"
1780 kill_port_forward voltha-etcd-cluster-client
David Bainbridge76afd812020-04-06 09:53:52 -07001781 port_forward $_NS voltha-etcd-cluster-client $VOLTHA_ETCD_PORT 2379
David Bainbridge696bc632020-04-05 21:49:37 -07001782 espin - $VERIFIED
1783 fi
David Bainbridge76afd812020-04-06 09:53:52 -07001784 if [ $WITH_KAFKA == "yes" -o $WITH_KAFKA == "external" ]; then
1785 _NS=$(test $WITH_ETCD == "yes" && echo $VOLTHA_NS || echo $INFRA_NS)
David Bainbridge696bc632020-04-05 21:49:37 -07001786 bspin - "Forward VOLTHA Kafka port $FORWARD"
1787 kill_port_forward voltha-kafka
David Bainbridge76afd812020-04-06 09:53:52 -07001788 port_forward $_NS voltha-kafka $VOLTHA_KAFKA_PORT 9092
David Bainbridge696bc632020-04-05 21:49:37 -07001789 espin - $VERIFIED
1790 fi
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -08001791 if [ "$WITH_TIMINGS" == "yes" ]; then
1792 printtime $(expr $(date +%s) - $STIME)
1793 fi
David Bainbridgee87067b2019-08-12 22:00:12 +00001794fi
Test User3d7ad8e2019-07-03 06:15:44 +00001795
David Bainbridge696bc632020-04-05 21:49:37 -07001796if [ $WITH_ONOS == "yes" -a $WITH_RADIUS != "no" ]; then
David Bainbridge76afd812020-04-06 09:53:52 -07001797 _HOST=radius.$INFRA_NS.svc.cluster.local
David Bainbridge696bc632020-04-05 21:49:37 -07001798 _PORT=1812
1799 if [ $WITH_RADIUS != "yes" ]; then
1800 _HOST=$(echo $WITH_RADIUS | cut -d: -f1)
1801 _PORT=$(echo $WITH_RADIUS | cut -s -d: -f2)
1802 _PORT=${_PORT:-1812}
1803 fi
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001804 bspin "Configure ONOS RADIUS Connection $GEAR"
David Bainbridge696bc632020-04-05 21:49:37 -07001805 (set -x; cat onos-files/onos-aaa.json | sed -e "s/:RADIUS_SVC:/$_HOST/g" -e "s/:RADIUS_PORT:/$_PORT/" | curl --fail -sSL --user karaf:karaf -X POST http://$_ONOS_API_EP/onos/v1/network/configuration/apps/org.opencord.aaa -H Content-type:application/json -d@- >>$LOG 2>&1) >>$LOG 2>&1
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001806 espin $VERIFIED
1807fi
1808
David Bainbridge99ac7a22019-08-31 02:26:43 +00001809if [ "$WITH_CHAOS" == "yes" ]; then
1810 STIME=$(date +%s)
1811 echo -e "Verify kube-monkey $LOCK"
1812 bspin - "Verify kube-monkey Installed"
David Bainbridge7f8bf992020-04-08 21:53:22 -07001813 if [ $HELM_USE_UPGRADE == "yes" -o $(helm list --deployed --short --namespace kube-monkey "^monkey\$" | wc -l) -ne 1 ]; then
David Bainbridge99ac7a22019-08-31 02:26:43 +00001814 espin - $NOT_VERIFIED
David Bainbridge7f8bf992020-04-08 21:53:22 -07001815 helm_install - kube-monkey monkey ./kube-monkey/helm/kubemonkey latest "$_HELM_DESC Chaos Monkey"
David Bainbridge99ac7a22019-08-31 02:26:43 +00001816 else
1817 espin - $VERIFIED
1818 fi
1819 wait_for_pods - "kube-monkey" 1 "includes" -1 "Waiting for Chaos to start" "monkey-.*"
1820 if [ "$WITH_TIMINGS" == "yes" ]; then
1821 printtime $(expr $(date +%s) - $STIME)
1822 fi
1823fi
1824
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001825bspin "Create voltctl configuration file"
Test User3d7ad8e2019-07-03 06:15:44 +00001826(set -x; mkdir -p $HOME/.volt >>$LOG 2>&1) >>$LOG 2>&1
David K. Bainbridgeb859e912020-03-13 14:07:52 -07001827MIN_VC_VERSION=$(echo -e "1.0.15\n$VC_VERSION" | sort -V | head -1)
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -08001828if [ $WITH_PORT_FORWARDS == "yes" ]; then
David K. Bainbridgeb859e912020-03-13 14:07:52 -07001829 KAFKA_FLAG="-k localhost:$VOLTHA_KAFKA_PORT"
1830 SERVER_FLAG="-s localhost:$VOLTHA_API_PORT"
1831 ETCD_FLAG=
1832 if [ "$MIN_VC_VERSION" == "1.0.15" ]; then
1833 ETCD_FLAG="-e localhost:$VOLTHA_ETCD_PORT"
1834 fi
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -08001835else
David K. Bainbridgeb859e912020-03-13 14:07:52 -07001836 KAFKA_FLAG="-k $(get_service_ep voltha voltha-kafka)"
David Bainbridge76afd812020-04-06 09:53:52 -07001837 SERVER_FLAG="-s $(get_service_ep $VOLTHA_NS voltha-api)"
David K. Bainbridgeb859e912020-03-13 14:07:52 -07001838 ETCD_FLAG=
1839 if [ "$MIN_VC_VERSION" == "1.0.15" ]; then
1840 ETCD_FLAG="-e $(get_service_ep voltha voltha-etcd-client)"
1841 fi
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -08001842fi
David K. Bainbridgeb859e912020-03-13 14:07:52 -07001843(set -x; voltctl -a v3 $KAFKA_FLAG $SERVER_FLAG $ETCD_FLAG config > $HOME/.volt/config-$NAME 2>>$LOG) >>$LOG 2>&1
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001844espin $VERIFIED
Test User08ebbd92019-07-03 17:15:39 +00001845
David Bainbridge0774b232019-08-02 06:37:19 +00001846if [ ! -f "$NAME-env.sh" ]; then
1847 touch $NAME-env.sh
David Bainbridgeb07fdf72019-07-29 22:51:40 +00001848fi
1849
David Bainbridge596f30d2019-07-30 17:07:59 +00001850for O in $ALL_OPTIONS; do
1851 VAL=$(eval echo \$$O)
David Bainbridge0774b232019-08-02 06:37:19 +00001852 if [ ! -z "$VAL" -a $(grep -c "^export $O=" $NAME-env.sh) -eq 0 ]; then
1853 echo "export $O=\"$(eval echo \$$O)\"" >> $NAME-env.sh
David Bainbridgeb07fdf72019-07-29 22:51:40 +00001854 fi
1855done
1856
David Bainbridge0774b232019-08-02 06:37:19 +00001857if [ $DEPLOY_K8S == "yes" -a $(grep -c "^export KUBECONFIG=" $NAME-env.sh) -eq 0 ]; then
1858 echo "export KUBECONFIG=\"$(./bin/kind get kubeconfig-path --name=voltha-$NAME)\"" >> $NAME-env.sh
David Bainbridgeb07fdf72019-07-29 22:51:40 +00001859fi
1860
David Bainbridge0774b232019-08-02 06:37:19 +00001861if [ $(grep -c "^export VOLTCONFIG=" $NAME-env.sh) -eq 0 ]; then
1862 echo "export VOLTCONFIG=\"$HOME/.volt/config-$NAME\"" >> $NAME-env.sh
David Bainbridgeb07fdf72019-07-29 22:51:40 +00001863fi
1864
David Bainbridge0774b232019-08-02 06:37:19 +00001865if [ $(grep -c "^export PATH=" $NAME-env.sh) -eq 0 ]; then
1866 echo "export PATH=\"$GOPATH/bin:\$PATH\"" >> $NAME-env.sh
David Bainbridgeb07fdf72019-07-29 22:51:40 +00001867fi
1868
Test User7d866122019-07-09 17:52:35 +00001869echo ""
Test User08ebbd92019-07-03 17:15:39 +00001870echo "Please issue the following commands in your terminal to ensure that you" | tee -a $LOG
1871echo "are accessing the correct Kubernetes/Kind cluster as well as have the " | tee -a $LOG
1872echo "tools required by VOLTHA in your command path. " | tee -a $LOG
1873echo "" | tee -a $LOG
Test User7d866122019-07-09 17:52:35 +00001874echo -en $BOLD
Test Userba1e7e72019-07-10 22:27:54 +00001875if [ $DEPLOY_K8S == "yes" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +00001876 echo "export KUBECONFIG=\"\$(./bin/kind get kubeconfig-path --name=\"voltha-$NAME\")\"" | tee -a $LOG
Test Userba1e7e72019-07-10 22:27:54 +00001877fi
David Bainbridge0774b232019-08-02 06:37:19 +00001878echo "export VOLTCONFIG=\"$HOME/.volt/config-$NAME\"" | tee -a $LOG
Test Userba1e7e72019-07-10 22:27:54 +00001879echo "export PATH=$GOPATH/bin:\$PATH" | tee -a $LOG
Test User7d866122019-07-09 17:52:35 +00001880echo -en $NORMAL
Test User08ebbd92019-07-03 17:15:39 +00001881echo "" | tee -a $LOG
1882echo "Thank you for choosing kind-voltha for you quick cluster needs." | tee -a $LOG
1883
David Bainbridge712afb82019-08-14 19:55:58 +00001884if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridgef858a022019-08-14 21:25:11 +00001885 echo -e "$CLOCK ${BOLD}TOTAL: $(duration $(expr $(date +%s) - $TOTAL_START_TIME))${NORMAL}"
David Bainbridge712afb82019-08-14 19:55:58 +00001886fi