blob: 9706535e7b18e81c091ee11eb324b8b5fe6ee509 [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 Bainbridge46505fb2019-10-01 21:13:20 +0000102UPDATE_HELM_REPOS=${UPDATE_HELM_REPOS:-yes}
Matteo Scandolofab98622020-01-28 15:17:20 -0800103WAIT_ON_DOWN=${WAIT_ON_DOWN:-yes}
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700104WAIT_TIMEOUT=${WAIT_TIMEOUT:-30m}
105VOLTHA_DOWN_ON_TIMEOUT=${VOLTHA_DOWN_ON_TIMEOUT:-no}
David Bainbridge5b7b96b2019-07-25 20:29:13 +0000106VOLTHA_LOG_LEVEL=${VOLTHA_LOG_LEVEL:-WARN}
David Bainbridge90fd8e32019-08-21 23:32:47 +0000107VOLTHA_CHART=${VOLTHA_CHART:-onf/voltha}
108VOLTHA_CHART_VERSION=${VOLTHA_CHART_VERSION:-latest}
109VOLTHA_BBSIM_CHART=${VOLTHA_BBSIM_CHART:-onf/bbsim}
Matteo Scandolodcd29f52019-10-07 15:42:42 -0700110VOLTHA_BBSIM_CHART_VERSION=${VOLTHA_BBSIM_CHART_VERSION:-latest}
David Bainbridgee10f6d52019-07-25 00:28:13 +0000111VOLTHA_ADAPTER_SIM_CHART=${VOLTHA_ADAPTER_SIM_CHART:-onf/voltha-adapter-simulated}
David Bainbridge90fd8e32019-08-21 23:32:47 +0000112VOLTHA_ADAPTER_SIM_CHART_VERSION=${VOLTHA_ADAPTER_SIM_CHART_VERSION:-latest}
David Bainbridgee10f6d52019-07-25 00:28:13 +0000113VOLTHA_ADAPTER_OPEN_OLT_CHART=${VOLTHA_ADAPTER_OPEN_OLT_CHART:-onf/voltha-adapter-openolt}
David Bainbridge90fd8e32019-08-21 23:32:47 +0000114VOLTHA_ADAPTER_OPEN_OLT_CHART_VERSION=${VOLTHA_ADAPTER_OPEN_OLT_CHART_VERSION:-latest}
David Bainbridgee10f6d52019-07-25 00:28:13 +0000115VOLTHA_ADAPTER_OPEN_ONU_CHART=${VOLTHA_ADAPTER_OPEN_ONU_CHART:-onf/voltha-adapter-openonu}
David Bainbridge90fd8e32019-08-21 23:32:47 +0000116VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION=${VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION:-latest}
David K. Bainbridgeda33d652020-03-06 10:31:23 -0800117ONOS_CHART=${ONOS_CHART:-onf/onos}
Andrea Campanella21323292019-12-18 11:44:19 -0800118ONOS_CHART_VERSION=${ONOS_CHART_VERSION:-latest}
David Bainbridge2eaf2cf2020-03-18 12:54:08 -0700119EXTRA_HELM_INSTALL_ARGS=${EXTRA_HELM_INSTALL_ARGS:-}
120INTERNAL_EXTRA_HELM_INSTALL_ARGS=
uottrembb16d3982020-02-28 08:34:36 +0100121NUM_OF_BBSIM=${NUM_OF_BBSIM:-1}
122MAX_NUM_OF_BBSIM=10
Test Userba1e7e72019-07-10 22:27:54 +0000123
124HAVE_GO=$(which go >/dev/null 2>&1 && echo "yes" || echo "no")
125HOSTOS=$(uname -s | tr "[:upper:]" "[:lower:"])
126HOSTARCH=$(uname -m | tr "[:upper:]" "[:lower:"])
127if [ $HOSTARCH == "x86_64" ]; then
128 HOSTARCH="amd64"
129fi
Test User7d866122019-07-09 17:52:35 +0000130
uottrembb16d3982020-02-28 08:34:36 +0100131# check number (range) of bbsim, max bbsim must not exceed 10 instances!
132# note: instances will be numbered from 0 to 9
133if [ "$1" == "up" ]; then
David K. Bainbridge43422402020-03-06 07:41:22 -0800134 if [ "$NUM_OF_BBSIM" -lt 1 ]; then
135 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} Invalid setting of BBSIM instances. NUM_OF_BBSIM is less than 1${NORMAL}"
136 exit 1
137 fi
138 if [ "$NUM_OF_BBSIM" -gt $MAX_NUM_OF_BBSIM ]; then
139 >&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}"
140 exit 1
141 fi
uottrembb16d3982020-02-28 08:34:36 +0100142fi
Test User7d866122019-07-09 17:52:35 +0000143# Verify TYPE setting
144if [ $(echo ":minimal:full:" | grep -ic ":$TYPE:") -eq 0 ]; then
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700145 >&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 +0000146 exit 1
147fi
148
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700149function parseDuration() {
150 local DUR=$1
151 local RESULT=0
David Bainbridge6cdb6462020-03-25 10:24:38 -0700152 local TERMS=$(echo $DUR | sed -Ee 's/([sSmMhHdD])/\1 /g' -e 's/,$//g')
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700153 for TERM in $TERMS; do
David Bainbridge6cdb6462020-03-25 10:24:38 -0700154 local VALUE=$(echo $TERM | sed -Ee 's/([0-9]+)[sSmMhHdD]/\1/')
155 local UNIT=$(echo $TERM | sed -Ee 's/[0-9]+([sSmMhHdD])/\1/')
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700156 case $UNIT in
157 s|S)
158 RESULT=$(($RESULT + $VALUE)) ;;
159 m|M)
160 RESULT=$(($RESULT + ($VALUE * 60))) ;;
161 h|H)
162 RESULT=$(($RESULT + ($VALUE * 3600))) ;;
163 d|D)
164 RESULT=$(($RESULT + ($VALUE * 86400))) ;;
165 *) ;;
166 esac
167 done
168 echo $RESULT
169}
170
171function doTimeout() {
172 local MSG=$1
173 2>&1 echo -e "\n${RED}${BOLD}${ERROR}TIMEOUT:${NORMAL}${RED} Operation timed out after '$WAIT_TIMEOUT': $MSG"
174 exit 125
175}
176
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -0800177function get_service_ep() {
178 local NS=$1
179 local NAME=$2
180 kubectl -n $NS get service $NAME -o json | jq -r '.spec.clusterIP + ":" + (.spec.ports[0].port|tostring)'
181}
182
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000183# Used to verify configuration values are set to "yes" or "no" value or convert
184# equivalents to "yes" or "no"
185function verify_yes_no() {
186 local VAR=$1
187 local VAL=$(eval echo \$$VAR)
188 if [ $(echo ":y:yes:true:n:no:false:1:0:" | grep -ic ":$VAL:") -eq 0 ]; then
189 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} Invalid '$VAR' value of '$VAL'. Should be 'yes' or 'no'${NORMAL}"
190 echo "INVALID"
191 return 1
192 fi
193 if [ $(echo ":y:yes:true:1:" | grep -ic ":$VAL:") -eq 1 ]; then
194 echo "yes"
195 else
196 echo "no"
197 fi
198 return 0
199}
Test User7d866122019-07-09 17:52:35 +0000200
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000201ALL_YES_NO="\
David K. Bainbridge484d80c2020-03-05 21:44:34 -0800202 ENABLE_ONOS_EXTRANEOUS_RULES \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000203 WITH_TIMINGS \
204 WITH_BBSIM \
Matteo Scandolo78dfee02020-02-13 16:18:03 -0800205 WITH_EAPOL \
206 WITH_DHCP \
207 WITH_IGMP \
David Bainbridge99ac7a22019-08-31 02:26:43 +0000208 WITH_CHAOS \
David Bainbridge46505fb2019-10-01 21:13:20 +0000209 WITH_ADAPTERS \
210 WITH_SIM_ADAPTERS \
211 WITH_OPEN_ADAPTERS \
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -0800212 WITH_PORT_FORWARDS \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000213 JUST_K8S \
214 DEPLOY_K8S \
215 INSTALL_ONOS_APPS \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000216 INSTALL_KUBECTL \
217 INSTALL_HELM \
David Bainbridge46505fb2019-10-01 21:13:20 +0000218 UPDATE_HELM_REPOS \
David Bainbridge4f1b5562019-08-19 04:46:52 +0000219 WAIT_ON_DOWN \
David Bainbridge70c0ea82019-11-14 23:25:26 +0000220 ONLY_ONE \
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700221 VOLTHA_DOWN_ON_TIMEOUT \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000222 "
David Bainbridge5b7b96b2019-07-25 20:29:13 +0000223
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000224ALL_OPTIONS="\
225 NAME \
226 TYPE \
227 $ALL_YES_NO \
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700228 WAIT_TIMEOUT \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000229 VOLTHA_LOG_LEVEL \
230 VOLTHA_CHART \
David Bainbridge90fd8e32019-08-21 23:32:47 +0000231 VOLTHA_CHART_VERSION \
232 VOLTHA_BBSIM_CHART \
233 VOLTHA_BBSIM_CHART_VERSION \
uottrembd5a20572020-03-06 09:15:01 +0100234 NUM_OF_BBSIM \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000235 VOLTHA_ADAPTER_SIM_CHART \
David Bainbridge90fd8e32019-08-21 23:32:47 +0000236 VOLTHA_ADAPTER_SIM_CHART_VERSION \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000237 VOLTHA_ADAPTER_OPEN_OLT_CHART \
David Bainbridge90fd8e32019-08-21 23:32:47 +0000238 VOLTHA_ADAPTER_OPEN_OLT_CHART_VERSION \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000239 VOLTHA_ADAPTER_OPEN_ONU_CHART \
David Bainbridge90fd8e32019-08-21 23:32:47 +0000240 VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION \
David K. Bainbridgeda33d652020-03-06 10:31:23 -0800241 ONOS_CHART \
Andrea Campanella21323292019-12-18 11:44:19 -0800242 ONOS_CHART_VERSION \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000243 ONOS_API_PORT \
244 ONOS_SSH_PORT \
David K. Bainbridgeb859e912020-03-13 14:07:52 -0700245 CONFIG_SADIS \
Hardik Windlassb3147602020-03-09 16:59:15 +0530246 SADIS_CFG \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000247 VOLTHA_API_PORT \
248 VOLTHA_SSH_PORT \
249 VOLTHA_ETCD_PORT \
David K. Bainbridge00ecd382020-02-28 12:31:58 -0800250 VOLTHA_KAFKA_PORT \
David K. Bainbridge8f7f30b2020-01-08 13:06:16 -0800251 VK_RELEASE \
252 KIND_VERSION \
253 VOLTCTL_VERSION \
David Bainbridgea34993d2020-04-01 09:15:42 -0700254 HELM_VERSION \
David Bainbridge696bc632020-04-05 21:49:37 -0700255 WITH_RADIUS \
256 WITH_KAFKA \
257 WITH_ETCD \
David Bainbridge76afd812020-04-06 09:53:52 -0700258 WITH_ONOS \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000259 "
David Bainbridge01294952019-07-30 19:33:45 +0000260
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000261# Iterate over yes/no configuration options and validate
262for VAR in $ALL_YES_NO; do
263 eval $VAR=$(verify_yes_no $VAR)
264 if [ "$(eval echo \$$VAR)" == "INVALID" ]; then
265 exit 1;
266 fi
267done
David Bainbridgeb270c202019-07-26 01:44:42 +0000268
David Bainbridge15f6f232020-03-30 09:15:43 -0700269# Special case for CONFIG_SADIS
270if [ $(echo ":y:yes:true:1:" | grep -ic ":$CONFIG_SADIS:") -eq 1 ]; then
271 CONFIG_SADIS="yes"
272fi
273if [ $(echo ":n:no:false:0:" | grep -ic ":$CONFIG_SADIS:") -eq 1 ]; then
274 CONFIG_SADIS="no"
275fi
276
David Bainbridge76afd812020-04-06 09:53:52 -0700277# Special case for WITH_ONOS, WITH_RADIUS, WITH_KAFKA, and WITH_ETCD
David Bainbridge696bc632020-04-05 21:49:37 -0700278if [ $(echo ":y:yes:true:1:" | grep -ic ":$WITH_KAFKA:") -eq 1 ]; then
279 WITH_KAFKA="yes"
280fi
281if [ $(echo ":n:no:false:0:" | grep -ic ":$WITH_KAFKA:") -eq 1 ]; then
282 WITH_KAFKA="no"
283fi
David Bainbridge76afd812020-04-06 09:53:52 -0700284if [ $(echo ":external:" | grep -ic ":$WITH_KAFKA:") -eq 1 ]; then
285 WITH_KAFKA="external"
286fi
David Bainbridge696bc632020-04-05 21:49:37 -0700287if [ $(echo ":y:yes:true:1:" | grep -ic ":$WITH_ETCD:") -eq 1 ]; then
288 WITH_ETCD="yes"
289fi
290if [ $(echo ":n:no:false:0:" | grep -ic ":$WITH_ETCD:") -eq 1 ]; then
291 WITH_ETCD="no"
292fi
David Bainbridge76afd812020-04-06 09:53:52 -0700293if [ $(echo ":external:" | grep -ic ":$WITH_ETCD:") -eq 1 ]; then
294 WITH_ETCD="external"
295fi
David Bainbridge29c31cb2020-04-06 09:45:50 -0700296if [ $(echo ":y:yes:true:1:" | grep -ic ":$WITH_RADIUS:") -eq 1 ]; then
297 WITH_RADIUS="yes"
298fi
299if [ $(echo ":n:no:false:0:" | grep -ic ":$WITH_RADIUS:") -eq 1 ]; then
300 WITH_RADIUS="no"
301fi
David Bainbridge76afd812020-04-06 09:53:52 -0700302if [ $(echo ":y:yes:true:1:" | grep -ic ":$WITH_ONOS:") -eq 1 ]; then
303 WITH_ONOS="yes"
304fi
305if [ $(echo ":n:no:false:0:" | grep -ic ":$WITH_ONOS:") -eq 1 ]; then
306 WITH_ONOS="no"
307fi
David Bainbridge696bc632020-04-05 21:49:37 -0700308
David K. Bainbridgeda33d652020-03-06 10:31:23 -0800309# Check for prerequiste tools
David K. Bainbridge726ff6a2020-03-06 11:09:50 -0800310TOOLS="curl sed jq"
David K. Bainbridgeda33d652020-03-06 10:31:23 -0800311if [ $DEPLOY_K8S == "yes" ]; then
312 TOOLS+=" docker"
313fi
314NOT_FOUND=""
315for T in $TOOLS; do
316 if [ -z "$(which $T)" ]; then
317 NOT_FOUND+=" $T"
318 fi
319done
320
321if [ ! -z "$NOT_FOUND" ]; then
322 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} The following required tools where not found, please install them:$NOT_FOUND"
323 exit 1
324fi
325
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700326TIMEOUT_SECONDS=$(parseDuration $WAIT_TIMEOUT)
327
David Bainbridge0774b232019-08-02 06:37:19 +0000328mkdir -p .voltha
329touch .voltha/ports
330HAVE=$(grep $NAME .voltha/ports)
331if [ "$HAVE X" == " X" ]; then
332 # Find free port prefix
333 START=81
334 while true; do
335 if [ $(grep -c $START .voltha/ports) -eq 0 ]; then
336 break
337 fi
338 START=$(expr $START + 1)
339 done
340 DELTA=$(expr $START - 81)
David Bainbridgea2595422019-10-22 03:54:28 +0000341 ONOS_API_PORT=${ONOS_API_PORT:-${START}81}
342 ONOS_SSH_PORT=${ONOS_SSH_PORT:-${START}01}
343 VOLTHA_API_PORT=${VOLTHA_API_PORT:-5$(expr 55 + $DELTA)55}
344 VOLTHA_SSH_PORT=${VOLTHA_SSH_PORT:-$(expr 50 + $DELTA)22}
345 VOLTHA_ETCD_PORT=${VOLTHA_ETCD_PORT:-$(expr 23 + $DELTA)79}
David K. Bainbridge00ecd382020-02-28 12:31:58 -0800346 VOLTHA_KAFKA_PORT=${VOLTHA_KAFKA_PORT:-$(expr 90 + $DELTA)92}
Test User01ed0642019-07-03 20:17:06 +0000347else
David Bainbridge0774b232019-08-02 06:37:19 +0000348 VALUES=$(echo $HAVE | sed -e 's/\s//g' | cut -d= -f2)
David Bainbridgea2595422019-10-22 03:54:28 +0000349 ONOS_API_PORT=${ONOS_API_PORT:-$(echo $VALUES | cut -d, -f1)}
350 ONOS_SSH_PORT=${ONOS_SSH_PORT:-$(echo $VALUES | cut -d, -f2)}
351 VOLTHA_API_PORT=${VOLTHA_API_PORT:-$(echo $VALUES | cut -d, -f3)}
352 VOLTHA_SSH_PORT=${VOLTHA_SSH_PORT:-$(echo $VALUES | cut -d, -f4)}
353 VOLTHA_ETCD_PORT=${VOLTHA_ETCD_PORT:-$(echo $VALUES | cut -d, -f5)}
David K. Bainbridge00ecd382020-02-28 12:31:58 -0800354 VOLTHA_KAFKA_PORT=${VOLTHA_KAFKA_PORT:-$(echo $VALUES | cut -d, -f6)}
355
David K. Bainbridge00ecd382020-02-28 12:31:58 -0800356 # A bit of a hueristic required here as the KAFKA port forward was
357 # added after the .voltha/ports files was created. Basically, if
358 # the VOLTHA_KAFKA_PORT isn't in the file then calculate the original
359 # DELTA from the VOLTHA_SSH_PORT and apply it to the VOLTHA_KAFKA_PORT
360 if [ -z "$VOLTHA_KAFKA_PORT" ]; then
361 DELTA=$((VOLTHA_SSH_PORT/100-50))
362 VOLTHA_KAFKA_PORT=${VOLTHA_KAFKA_PORT:-$(expr 90 + $DELTA)92}
363 fi
Test User01ed0642019-07-03 20:17:06 +0000364fi
365
David Bainbridge0774b232019-08-02 06:37:19 +0000366PORTTMP=$(mktemp -u)
367cat .voltha/ports | grep -v $NAME > $PORTTMP
David K. Bainbridge00ecd382020-02-28 12:31:58 -0800368echo "$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 +0000369cp $PORTTMP .voltha/ports
370rm -f $PORTTMP
371
David Bainbridge27790d62019-08-13 22:43:19 +0000372export ONOS_API_PORT ONOS_SSH_PORT
David Bainbridge01294952019-07-30 19:33:45 +0000373
Test Userd87942b2019-07-03 07:20:24 +0000374IDX=1
David Bainbridgee87067b2019-08-12 22:00:12 +0000375CLOCK="TIME:"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000376SPIN_PARTS=
377NOT_VERIFIED=
David Bainbridgef858a022019-08-14 21:25:11 +0000378THEX=
379BUILD=
380CROSS=
381ENTER=
David Bainbridge38dc1e82019-08-12 15:18:45 +0000382VERIFIED=
383HELM=
384OLD_KEY=
385BIRD=
386HIGH_VOLTAGE=
387PLUG=
388RESTART=
389FORWARD=
390INSTALL=
391STOP=
392GO=
393DOWNLOAD=
394GEAR=
395NO_ENTRY=
396LOCK=
397
398if [ $FANCY -eq 1 ]; then
399 SPIN_PARTS="\
400 \xe2\xa2\x8e\xe2\xa1\xb0 \
401 \xe2\xa2\x8e\xe2\xa1\xa1 \
402 \xe2\xa2\x8e\xe2\xa1\x91 \
403 \xe2\xa2\x8e\xe2\xa0\xb1 \
404 \xe2\xa0\x8e\xe2\xa1\xb1 \
405 \xe2\xa2\x8a\xe2\xa1\xb1 \
406 \xe2\xa2\x8c\xe2\xa1\xb1 \
407 \xe2\xa2\x86\xe2\xa1\xb1 \
408 "
David Bainbridgee87067b2019-08-12 22:00:12 +0000409 CLOCK="\xe2\x8f\xb1"
David Bainbridgef858a022019-08-14 21:25:11 +0000410 THEX="${RED}${BOLD}\xe2\x9c\x97\x20${NORMAL}"
411 ENTER="${YELLOW}${BOLD}\xe2\x8e\x86${NORMAL}"
412 CROSS="${YELLOW}${BOLD}\xe2\x9c\x9a${NORMAL}"
413 BUILD="${YELLOW}${BOLD}\xf0\x9f\x8f\x97${NORMAL}"
414 NOT_VERIFIED="$BUILD"
415 VERIFIED="${GREEN}${BOLD}\xe2\x9c\x93\x20${NORMAL}"
416 HELM="${BLUE}${BOLD}\xE2\x8E\x88${NORMAL}"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000417 OLD_KEY="\xF0\x9F\x97\x9D"
418 BIRD="\xF0\x9F\x90\xA6"
419 HIGH_VOLTAGE="\xE2\x9A\xA1"
420 PLUG="\xF0\x9F\xa7\xa9"
421 RESTART="\xf0\x9f\x94\x84"
422 FORWARD="\xE2\x87\xA8"
423 INSTALL="\xF0\x9F\x8F\x97"
424 STOP="\xf0\x9f\x9b\x91"
425 GO="\xf0\x9f\x9a\x80"
426 DOWNLOAD="\xf0\x9f\x93\xa5"
427 GEAR="\xe2\x9a\x99"
428 NO_ENTRY="\xe2\x9b\x94"
429 LOCK="\xf0\x9f\x94\x92"
430fi
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700431
David Bainbridge712afb82019-08-14 19:55:58 +0000432duration() {
David Bainbridgee87067b2019-08-12 22:00:12 +0000433 local h=$(expr $1 / 3600)
434 local m=$(expr $1 % 3600 / 60)
435 local s=$(expr $1 % 60)
436 local t=""
437
438 if [ $h -gt 0 ]; then
439 t="$t${h}h"
440 fi
441 if [ $m -gt 0 ]; then
442 t="$t${m}m"
443 fi
David Bainbridge712afb82019-08-14 19:55:58 +0000444 echo "$t${s}s"
445}
446
447printtime() {
448 local INDENT=
449 if [ "$1" == "-" ]; then
450 INDENT=" "
451 shift
452 fi
453 echo -e "$INDENT $CLOCK $(duration $1)"
David Bainbridgee87067b2019-08-12 22:00:12 +0000454}
455
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700456bspin() {
Test Userd87942b2019-07-03 07:20:24 +0000457 IDX=1
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700458 local INDENT=
459 if [ "$1" == "-" ]; then
460 INDENT=" "
461 shift
462 fi
David Bainbridge38dc1e82019-08-12 15:18:45 +0000463 if [ $FANCY -eq 0 ]; then
464 LINE=$(echo $* | sed -e 's/[\s+-]//g')
465 if [ "$LINE X" == " X" ]; then
466 return
467 fi
468 echo -e "$CIVIS$INDENT$*"
469 else
470 echo -en "$CIVIS$INDENT $*"
471 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700472}
473
474sspin() {
475 local INDENT=
476 if [ "$1" == "-" ]; then
477 INDENT=" "
478 shift
479 fi
David Bainbridge38dc1e82019-08-12 15:18:45 +0000480 if [ $FANCY -eq 0 ]; then
481 LINE=$(echo $* | sed -e 's/[\s+-]//g')
482 if [ "$LINE X" == " X" ]; then
483 return
484 fi
485 echo -e "$INDENT$*"
486 else
487 C=$(echo $SPIN_PARTS | cut '-d ' -f $IDX)
488 echo -en "\r$INDENT$C $*"
489 IDX=$(expr $IDX + 1)
490 if [ $IDX -gt 8 ]; then
491 IDX=1
492 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700493 fi
494}
495
496espin() {
497 local INDENT=
498 if [ "$1" == "-" ]; then
499 INDENT=" "
500 shift
501 fi
David Bainbridge38dc1e82019-08-12 15:18:45 +0000502 if [ $FANCY -eq 0 ]; then
503 LINE=$(echo $* | sed -e 's/[\s+-]//g')
504 if [ "$LINE X" == " X" ]; then
505 return
506 fi
507 echo -e "$INDENT$*"
508 else
509 echo -e "\r$INDENT$*$CNORM"
510 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700511}
512
David Bainbridgeac7f8072019-08-01 22:15:33 +0000513if [ "$1" == "get" -a "$2" == "voltconfig" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000514 echo "$HOME/.volt/config-$NAME"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000515 exit
516fi
517
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -0700518if [ $# -ne 1 -o $(echo ":up:down:dump:" | grep -c ":$1:") -ne 1 ]; then
David Bainbridgeac7f8072019-08-01 22:15:33 +0000519 >&2 echo "What wouild you like to do today:"
520 >&2 echo " up - bring up voltha"
521 >&2 echo " down - tear down voltha"
522 >&2 echo " dump - create a debug dump of running system"
523 exit 1
524fi
525
David Bainbridge4f1b5562019-08-19 04:46:52 +0000526push_onos_config() {
Matteo Scandolo78dfee02020-02-13 16:18:03 -0800527 local TYPE=$1
528 local MSG=$2
529 local RESOURCE=$3
530 local DATA=$4
David Bainbridge4f1b5562019-08-19 04:46:52 +0000531
David K. Bainbridgeb4b163b2020-02-19 15:55:06 -0800532 # Thanks to the latest version of ONOS using the return code 207 this gets a
533 # whole lot nastier. Can't thank them enough for doing this. So in order to
534 # capture the command and the output in the log file as well as capture the
535 # status code to verify it is 200 and not 207 mutltiple files and a bit of
536 # hackery must be used. Thanks again ONOS.
537 local CMD_ECHO=$(mktemp -u)
538 local CMD_OUTPUT=$(mktemp -u)
539 local SC_OUTPUT=$(mktemp -u)
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700540 local WAIT_START=$(date +%s)
David K. Bainbridgeb4b163b2020-02-19 15:55:06 -0800541
David Bainbridge4f1b5562019-08-19 04:46:52 +0000542 bspin - "$MSG $GEAR"
543 while true; do
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700544 if [ $(($(date +%s) - $WAIT_START)) -gt $TIMEOUT_SECONDS ]; then
545 espin - "$THEX"
David Bainbridge1cecba52020-03-30 09:43:10 -0700546 rm -f $CMD_ECHO $CMD_OUTPUT $SC_OUTPUT
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700547 doTimeout "waiting for ONOS config push on $RESOURCE"
548 fi
Matteo Scandolo78dfee02020-02-13 16:18:03 -0800549 if [ $TYPE == "file" ]; then
David K. Bainbridgeb859e912020-03-13 14:07:52 -0700550 (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
551 RESULT=$?
Matteo Scandolo78dfee02020-02-13 16:18:03 -0800552 fi
553 if [ $TYPE == "json" ]; then
David K. Bainbridgeb859e912020-03-13 14:07:52 -0700554 (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
555 RESULT=$?
Matteo Scandolo78dfee02020-02-13 16:18:03 -0800556 fi
David K. Bainbridgeb4b163b2020-02-19 15:55:06 -0800557 # Dump everything to the log
558 cat $CMD_ECHO >> $LOG
David K. Bainbridgeb859e912020-03-13 14:07:52 -0700559 test -r $CMD_OUTPUT && cat $CMD_OUTPUT >> $LOG
David K. Bainbridgeb4b163b2020-02-19 15:55:06 -0800560 SC=$(cat $SC_OUTPUT)
David K. Bainbridgeb859e912020-03-13 14:07:52 -0700561 echo "RESPONSE CODE: $SC" >> $LOG
562 echo "ERROR CODE: $RESULT" >> $LOG
David K. Bainbridgeb4b163b2020-02-19 15:55:06 -0800563
564 # clean up temp files
565 rm -f $CMD_ECHO $CMD_OUTPUT $SC_OUTPUT
566 if [ $RESULT -eq 0 -a "$SC" == "200" ]; then
David Bainbridge4f1b5562019-08-19 04:46:52 +0000567 break
568 fi
Matteo Scandolo9a77a732020-01-09 14:24:12 -0800569 sleep 1
David Bainbridge4f1b5562019-08-19 04:46:52 +0000570 sspin -
571 done
572 espin - $VERIFIED
573}
574
Matteo Scandolo9a77a732020-01-09 14:24:12 -0800575check_onos_app_active() {
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700576 local APP_ID=$1
577 local WAIT_START=$(date +%s)
Matteo Scandolo9a77a732020-01-09 14:24:12 -0800578
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700579 bspin - "Checking that $APP_ID is active $CLOCK"
580 while true; do
581 if [ $(($(date +%s) - $WAIT_START)) -gt $TIMEOUT_SECONDS ]; then
582 espin - "$THEX"
583 doTimeout "waiting for ONOS application activation '$APP_ID'"
584 fi
585 (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
586 if [ $? -eq 0 ]; then
587 break
588 fi
589 sleep 1
590 sspin -
591 done
592 sleep 5 # OSGI components take a little longer that the app to activate
593 espin - $VERIFIED
Matteo Scandolo9a77a732020-01-09 14:24:12 -0800594}
595
David Bainbridge4f1b5562019-08-19 04:46:52 +0000596override_onos_app() {
597 local APP=$1
598 local NAME=$(basename $APP | sed -e 's/^[0-9][0-9]*-//g' -e 's/-.*$//g')
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700599 local WAIT_START=$(date +%s)
600
David Bainbridge4f1b5562019-08-19 04:46:52 +0000601 while true; do
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700602 if [ $(($(date +%s) - $WAIT_START)) -gt $TIMEOUT_SECONDS ]; then
603 espin - "$THEX"
604 doTimeout "waiting to overwrite ONOS application '$APP'"
605 fi
David Bainbridge4f1b5562019-08-19 04:46:52 +0000606 sspin -
607 # Attempt to delete old version (if it exists)
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -0800608 (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 +0000609 sspin -
610 if [ $? -ne 0 ]; then
611 continue
612 fi
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -0800613 (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 +0000614 if [ $? -eq 0 ]; then
615 break
616 fi
617 sleep .2
618 done
619}
620
621activate_onos_app() {
622 local MSG="$1"
623 local APP=$2
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700624 local WAIT_START=$(date +%s)
David Bainbridge4f1b5562019-08-19 04:46:52 +0000625
626 bspin - "$MSG $GO"
627 while true; do
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700628 if [ $(($(date +%s) - $WAIT_START)) -gt $TIMEOUT_SECONDS ]; then
629 espin - "$THEX"
630 doTimeout "waiting to activate ONOS application '$APP'"
631 fi
David Bainbridge4f1b5562019-08-19 04:46:52 +0000632 sspin -
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -0800633 (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 +0000634 if [ $? -eq 0 ]; then
635 break
636 fi
637 sleep .2
638 done
639 espin - "$VERIFIED"
640}
641
642count_pods() {
643 local NAMESPACE=$1; shift
644 if [ "$NAMESPACE" == "all-namespaces" ]; then
645 NAMESPACE="--all-namespaces"
646 else
647 NAMESPACE="-n $NAMESPACE"
648 fi
David Bainbridge4f1b5562019-08-19 04:46:52 +0000649 local STATES=$1; shift
David Bainbridge4f1b5562019-08-19 04:46:52 +0000650 local PODS=$(kubectl get $NAMESPACE pod -o go-template="{{range .items}}{{.metadata.name}}/{{.status.phase}}/_{{range .status.containerStatuses}}{{.ready}}_{{end}} {{end}}")
651 local COUNT=0
652 local PATTERNS="$*"
653 for POD in $PODS; do
654 local NAME=$(echo $POD | cut -d/ -f 1)
655 local STATE=$(echo $POD | cut -d/ -f 2)
656 local CONTAINERS=$(echo $POD | cut -d/ -f 3 | sed -e 's/_/ /g')
657 if [ "$STATES" == "*" -o $(echo "$STATES" | grep -c ":$STATE:") -ne 0 ]; then
David Bainbridge4f1b5562019-08-19 04:46:52 +0000658 local TOTAL=$(echo $CONTAINERS | wc -w)
659 local FOUND=$(echo $CONTAINERS | grep -o true | wc -l)
660 if [ $TOTAL -eq $FOUND ]; then
661 for PATTERN in $PATTERNS; do
David Bainbridge4f1b5562019-08-19 04:46:52 +0000662 if [[ $NAME =~ $PATTERN ]]; then
David Bainbridge4f1b5562019-08-19 04:46:52 +0000663 COUNT=$(expr $COUNT + 1)
664 break
665 fi
666 done
667 fi
668 fi
669 done
David Bainbridge4f1b5562019-08-19 04:46:52 +0000670 echo $COUNT
671}
672
673wait_for_pods() {
674 local INDENT=
675 if [ "$1" == "-" ]; then
676 INDENT=$1; shift
677 fi
678 local NAMESPACE=$1; shift
679 local EXPECT=$1; shift
680 local TYPE=$1; shift
681 local RETRY=$1; shift
682 local MESSAGE=$1; shift
683 local PATTERNS=$*
David Bainbridge99ac7a22019-08-31 02:26:43 +0000684 local STATES=":Running:"
685 if [ "$TYPE" == "not" ]; then
686 STATES="*"
687 fi
688 local HAVE=$(count_pods $NAMESPACE "$STATES" $PATTERNS)
David Bainbridge4f1b5562019-08-19 04:46:52 +0000689 local ALL=$HAVE
690 if [ "$TYPE" == "only" ]; then
691 ALL=$(count_pods "all-namespaces" "*" ".*")
692 fi
693 COUNT=$(expr 300 / 15)
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700694 local WAIT_START=$(date +%s)
David Bainbridge4f1b5562019-08-19 04:46:52 +0000695 bspin $INDENT $MESSAGE
696 sspin $INDENT
697 if [ $HAVE -ne $EXPECT -o $ALL -ne $HAVE ]; then
698 while [ $HAVE -ne $EXPECT -o $ALL -ne $HAVE ]; do
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700699 if [ $(($(date +%s) - $WAIT_START)) -gt $TIMEOUT_SECONDS ]; then
700 espin $INDENT "$THEX"
701 doTimeout "waiting for PODs to start"
702 fi
David Bainbridge4f1b5562019-08-19 04:46:52 +0000703 sspin $INDENT
704 COUNT=$(expr $COUNT - 1)
705 if [ $COUNT -eq 0 ]; then
David Bainbridge99ac7a22019-08-31 02:26:43 +0000706 HAVE=$(count_pods $NAMESPACE "$STATES" $PATTERNS)
David Bainbridge4f1b5562019-08-19 04:46:52 +0000707 ALL=$HAVE
708 if [ "$TYPE" == "only" ]; then
709 ALL=$(count_pods "all-namespaces" "*" ".*")
710 fi
711 COUNT=$(expr 300 / 15)
712 fi
713 sleep .15
714 done
715 fi
716 espin $INDENT $VERIFIED
717 if [ $HAVE -ne $EXPECT ]; then
718 return 1
719 fi
720 return 0
721}
722
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800723port_forward() {
724 local NS=$1
725 local SVC=$2
726 local FROM_PORT=$3
727 local TO_PORT=$4
728 local TAG=$SVC-$NAME
729
David Bainbridge70cc33a2020-04-07 11:06:59 -0700730 (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 -0800731}
732
733kill_port_forward() {
734 local TAG=$1-$NAME
David Bainbridgec6871d22019-11-13 17:10:31 +0000735 local P_IDS=$(ps e -ww -A | grep "_TAG=$TAG" | grep -v grep | awk '{print $1}')
David Bainbridgebcf235b2019-11-12 21:33:58 +0000736 local PARENTS=
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800737 local KIDS=
David Bainbridgec6871d22019-11-13 17:10:31 +0000738 local UNKNOWN=
739 if [ ! -z "$P_IDS" ]; then
740 for P_ID in $P_IDS; do
741 local PP_ID=$(ps -o ppid $P_ID | tail -n +2)
742 if [ ! -z "$PP_ID" ]; then
743 if [ $PP_ID -eq 1 ]; then
744 PARENTS="$PARENTS $P_ID"
745 else
746 KIDS="$KIDS $P_ID"
747 fi
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800748 else
David Bainbridgec6871d22019-11-13 17:10:31 +0000749 UNKNOWN="$UNKNOWN $P_ID"
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800750 fi
751 done
David Bainbridgec6871d22019-11-13 17:10:31 +0000752 (set -x; kill -9 $PARENTS $KIDS $UNKNOWN >>$LOG 2>&1) >>$LOG 2>&1
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800753 fi
754}
755
David Bainbridgeac7f8072019-08-01 22:15:33 +0000756if [ "$1" == "down" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000757 echo "Tearing down voltha cluster $NAME"
758 LOG="down-$NAME.log"
759 echo $(date -u +"%Y%m%dT%H%M%SZ") >$LOG
David Bainbridge696bc632020-04-05 21:49:37 -0700760 if [ $WITH_ONOS == "yes" ]; then
761 bspin "Remove port-forwards: onos-ui-$NAME"
762 kill_port_forward onos-ui
763 sspin "Remove port-forwards: onos-ssh-$NAME$CEOL"
764 kill_port_forward onos-ssh
765 fi
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800766 sspin "Remove port-forwards: voltha-api-$NAME$CEOL"
767 kill_port_forward voltha-api
David Bainbridge76afd812020-04-06 09:53:52 -0700768 if [ $WITH_ETCD == "yes" -o $WITH_ETCD == "external" ]; then
David Bainbridge696bc632020-04-05 21:49:37 -0700769 sspin "Remove port-forwards: voltha-etcd-$NAME$CEOL"
770 kill_port_forward voltha-etcd-cluster-client
771 fi
772 if [ $WITH_KAFKA == "yes" ]; then
773 sspin "Remove port-forwards: voltha-kafka-$NAME$CEOL"
774 kill_port_forward voltha-kafka
775 fi
776
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800777 espin "$VERIFIED Remove port-forwards$CEOL"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000778 if [ $DEPLOY_K8S == "yes" ]; then
779 if [ -x ./bin/kind ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000780 bspin "Delete Kubernetes Kind Cluster"
781 (set -x; ./bin/kind delete cluster --name voltha-$NAME >>$LOG 2>&1) >>$LOG 2>&1
782 espin $VERIFIED
David Bainbridgeac7f8072019-08-01 22:15:33 +0000783 else
David Bainbridge0774b232019-08-02 06:37:19 +0000784 espin "$NO_ENTRY Delete Kubernetes Kind Cluster: kind command not found"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000785 fi
786 else
787 EXISTS=$(helm list -q)
David Bainbridge76afd812020-04-06 09:53:52 -0700788 EXPECT="voltha"
David Bainbridge696bc632020-04-05 21:49:37 -0700789 if [ $WITH_ONOS == yes ]; then
790 EXPECT+=" onos"
791 fi
792 if [ $WITH_RADIUS == "yes" ]; then
793 EXPECT+=" radius"
794 fi
795 if [ $WITH_BBSIM == "yes" ]; then
796 EXPECT+=" bbsim"
797 fi
798 if [ $WITH_OPEN_ADAPTERS == "yes" ]; then
799 EXPECT+=" open-olt open-onu"
800 fi
801 if [ $WITH_SIM_ADAPTERS == "yes" ]; then
802 EXPECT+=" sim"
803 fi
David Bainbridge76afd812020-04-06 09:53:52 -0700804 if [ $WITH_ETCD == "external" ]; then
805 EXPECT+=" etcd-operator etcd-cluster"
806 elif [ $WITH_ETCD == "yes" ]; then
807 EXPECT+=" etcd-operator"
808 fi
809 if [ $WITH_KAFKA == "external" ]; then
810 EXPECT+=" kafka"
811 fi
David Bainbridge0774b232019-08-02 06:37:19 +0000812 bspin "Remove Helm Deployments"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000813 for i in $EXISTS; do
David K. Bainbridge43422402020-03-06 07:41:22 -0800814 for j in $EXPECT; do
815 if [[ $i =~ $j ]]; then
816 sspin "Remove Helm Deployments: $i$CEOL"
817 (set -x; ./bin/helm delete --no-hooks --purge $i >>$LOG 2>&1) >>$LOG 2>&1
818 fi
819 done
uottrembb16d3982020-02-28 08:34:36 +0100820 done
David Bainbridge0774b232019-08-02 06:37:19 +0000821 espin "$VERIFIED Remove Helm Deployments$CEOL"
David Bainbridge4f1b5562019-08-19 04:46:52 +0000822 if [ "$WAIT_ON_DOWN" == "yes" ]; then
David Bainbridge76afd812020-04-06 09:53:52 -0700823 PODS="voltha-kafka.* voltha-ofagent.* voltha-rw-core.* voltha-etcd.*"
824 INFRA_PODS=
825 ADAPT_PODS=
826 SIM_PODS=
David Bainbridge696bc632020-04-05 21:49:37 -0700827 if [ $WITH_RADIUS == "yes" ]; then
828 PODS+=" radius.*"
829 fi
830 if [ $WITH_BBSIM == "yes" ]; then
David Bainbridge76afd812020-04-06 09:53:52 -0700831 SIM_PODS+=" bbsim.*"
David Bainbridge696bc632020-04-05 21:49:37 -0700832 fi
833 if [ $WITH_OPEN_ADAPTERS -o $WITH_SIM_ADAPTERS ]; then
David Bainbridge76afd812020-04-06 09:53:52 -0700834 ADAPT_PODS+=" adapter-*"
David Bainbridge696bc632020-04-05 21:49:37 -0700835 fi
David Bainbridge76afd812020-04-06 09:53:52 -0700836 if [ $WITH_ONOS == "yes" ]; then
837 INFRA_PODS+=" onos-.*"
838 fi
839 if [ $WITH_ETCD == "external" ]; then
840 INFRA_PODS+=" etcd-operator.* etcd-cluster.*"
841 elif [ $WITH_ETCD == "yes" ]; then
842 PODS+=" etcd-operator.*"
843 fi
844 if [ $WITH_KAFKA == "external" ]; then
845 INFRA_PODS+=" kafka.*"
846 fi
847 if [ ! -z "$SIM_PODS" ]; then
848 wait_for_pods "$BBSIM_NS" 0 "not" -1 "Waiting for BBSIM PODs to terminate" $SIM_PODS
849 fi
850 if [ ! -z "$INFRA_PODS" ]; then
851 wait_for_pods "$INFRA_NS" 0 "not" -1 "Waiting for infrastructure PODs to terminate" $INFRA_PODS
852 fi
853 if [ ! -z "$ADAPT_PODS" ]; then
854 wait_for_pods "$ADAPTER_NS" 0 "not" -1 "Waiting for adapter PODs to terminate" $ADAPT_PODS
855 fi
856 wait_for_pods "$VOLTHA_NS" 0 "not" -1 "Waiting for VOLTHA PODs to terminate" $PODS
David Bainbridge4f1b5562019-08-19 04:46:52 +0000857 fi
David Bainbridgeac7f8072019-08-01 22:15:33 +0000858 fi
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -0700859 exit
David Bainbridgeac7f8072019-08-01 22:15:33 +0000860fi
861
862if [ "$1" == "dump" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000863 LOG="dump-$NAME.log"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000864 TS=$(date -u +"%Y%m%dT%H%M%SZ")
David Bainbridge76514a02019-10-08 01:50:35 +0000865 if [ ! -z "$DUMP_FROM" ]; then
866 TS=$(echo $DUMP_FROM | sed -e 's/[:-]//g')
867 fi
David Bainbridgeac7f8072019-08-01 22:15:33 +0000868 WORK=$(mktemp -u -d)
David Bainbridge0774b232019-08-02 06:37:19 +0000869 DATA=$WORK/voltha-debug-dump-$NAME-$TS
David Bainbridgeac7f8072019-08-01 22:15:33 +0000870 mkdir -p $DATA
871 echo $TS > $LOG
David Bainbridge0774b232019-08-02 06:37:19 +0000872 echo -e "Capturing debug dump to voltha-debug-dump-$NAME-$TS.tgz"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000873 bspin - "Copy install log"
David Bainbridge0774b232019-08-02 06:37:19 +0000874 if [ -f install-$NAME.log ]; then
875 (set -x; cp install-$NAME.log $DATA/install-$NAME.log) >>$LOG 2>&1
David Bainbridgeac7f8072019-08-01 22:15:33 +0000876 espin - $VERIFIED
877 else
David Bainbridge0774b232019-08-02 06:37:19 +0000878 espin - "$NO_ENTRY Copy install log: install-$NAME.log not found"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000879 fi
880 bspin - "Dumping Kubernetes PODs"
881 (set -x; kubectl get --all-namespaces pods >> $DATA/all-pods.txt 2>&1) >>$LOG 2>&1
882 espin - $VERIFIED
883 bspin - "Dumping Kubernetes SERVICEs"
884 (set -x; kubectl get --all-namespaces svc >> $DATA/all-services.txt 2>&1) >>$LOG 2>&1
885 espin - $VERIFIED
886 bspin - "Dumping Kubernetes EVENTs"
887 (set -x; kubectl get --all-namespaces events >> $DATA/all-events.txt 2>&1) >>$LOG 2>&1
888 espin - $VERIFIED
889 bspin - "Dumping VOLTHA POD details"
David Bainbridge76afd812020-04-06 09:53:52 -0700890 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 +0000891 SINCE=
892 if [ ! -z "$DUMP_FROM" ]; then
893 SINCE="--since-time=$DUMP_FROM"
894 fi
David Bainbridgeac7f8072019-08-01 22:15:33 +0000895 for POD in $PODS; do
David Bainbridge1f0655a2019-10-01 22:08:48 +0000896 NS=$(echo $POD | cut -d: -f1)
897 POD=$(echo $POD | cut -d: -f2)
David Bainbridgeac7f8072019-08-01 22:15:33 +0000898 sspin - "Dumping VOLTHA POD details: $POD$CEOL"
899 mkdir -p $DATA/$POD
David Bainbridge1f0655a2019-10-01 22:08:48 +0000900 (set -x; kubectl describe -n $NS $POD >> $DATA/$POD/describe.txt 2>&1) >>$LOG 2>&1
David Bainbridgeac7f8072019-08-01 22:15:33 +0000901 sspin - "Dumping VOLTHA POD details: $POD"
David Bainbridgecfd7ca12019-10-06 03:31:41 +0000902 (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 +0000903 sspin - "Dumping VOLTHA POD details: $POD"
David Bainbridgecfd7ca12019-10-06 03:31:41 +0000904 (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 +0000905 sspin - "Dumping VOLTHA POD details: $POD"
906 done
907 espin - "$VERIFIED Dumping VOLTHA POD details$CEOL"
908 bspin - "Dumping ETCD"
909 if [ "$(which etcdctl) X" != " X" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000910 (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 +0000911 espin - $VERIFIED
912 else
913 espin - "$NO_ENTRY Dumping ETCD: etcdctl command not available"
914 fi
David Bainbridge0774b232019-08-02 06:37:19 +0000915 bspin - "Creating compressed TAR: voltha-debug-dump-$NAME-$TS.tgz"
916 (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 +0000917 espin - $VERIFIED
918 bspin - "Cleanup"
919 (set -x; rm -rf $WORK) >>$LOG 2>&1
920 espin - $VERIFIED
David Bainbridge0774b232019-08-02 06:37:19 +0000921 bspin - "$(ls -l voltha-debug-dump-$NAME-$TS.tgz)"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000922 espin - $VERIFIED
923 exit
924fi
925
David Bainbridge0774b232019-08-02 06:37:19 +0000926LOG="install-$NAME.log"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000927date > $LOG
David Bainbridge0774b232019-08-02 06:37:19 +0000928echo "PORTS=$ONOS_API_PORT,$ONOS_SSH_PORT,$VOLTHA_API_PORT,$VOLTHA_SSH_PORT,$VOLTHA_ETCD_PORT" >> $LOG
David Bainbridgeac7f8072019-08-01 22:15:33 +0000929
930# Output install options to log
931echo "OPTIONS" >> $LOG
David Bainbridgeac7f8072019-08-01 22:15:33 +0000932for O in $ALL_OPTIONS; do
933 VAL=$(eval echo \$$O)
David Bainbridgeac7f8072019-08-01 22:15:33 +0000934 if [ ! -z "$VAL" ]; then
935 printf " %-30s = %s\n" $O $VAL >> $LOG
936 fi
937done
938
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -0700939helm_install() {
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700940 local INDENT=
941 if [ "$1" == "-" ]; then
942 INDENT=$1; shift
943 fi
944 local NAMESPACE=$1; shift
David Bainbridge0774b232019-08-02 06:37:19 +0000945 local INAME=$1; shift
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700946 local CHART=$1; shift
David Bainbridge90fd8e32019-08-21 23:32:47 +0000947 local CHART_VERSION=$1; shift
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700948 local MESSAGE=$*
949
David Bainbridge90fd8e32019-08-21 23:32:47 +0000950 if [ "$CHART_VERSION X" != " X" -a "$CHART_VERSION" != "latest" ]; then
951 CHART_VERSION="--version $CHART_VERSION"
952 else
953 CHART_VERSION=
954 fi
955
David Bainbridge99ac7a22019-08-31 02:26:43 +0000956 local CHART_ARGS=
957 if [ -r "${INAME}-values.yaml" ]; then
958 CHART_ARGS="-f ${INAME}-values.yaml"
959 fi
960
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700961 local WAIT_START=$(date +%s)
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700962 COUNT=$(expr 300 / 15)
963 bspin $INDENT $MESSAGE
David Bainbridge2eaf2cf2020-03-18 12:54:08 -0700964 (set -x; helm install -f $NAME-values.yaml $CHART_ARGS $INTERNAL_EXTRA_HELM_INSTALL_ARGS $EXTRA_HELM_INSTALL_ARGS --set defaults.log_level=$VOLTHA_LOG_LEVEL --namespace $NAMESPACE --name $INAME $CHART_VERSION $EXTRA_HELM_FLAGS $CHART >>$LOG 2>&1) >>$LOG 2>&1
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700965 SUCCESS=$?
966 while [ $SUCCESS -ne 0 ]; do
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700967 if [ $(($(date +%s) - $WAIT_START)) -gt $TIMEOUT_SECONDS ]; then
968 espin "$THEX"
969 doTimeout "waiting for helm install $CHART"
970 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700971 sspin $INDENT
972 COUNT=$(expr $COUNT - 1)
973 if [ $COUNT -eq 0 ]; then
Andy Baviere22ff252019-12-19 11:40:31 -0700974 (set -x; helm delete --purge $INAME >>$LOG 2>&1) >>$LOG 2>&1
David Bainbridge2eaf2cf2020-03-18 12:54:08 -0700975 (set -x; helm install -f $NAME-values.yaml $CHART_ARGS $INTERNAL_EXTRA_HELM_INSTALL_ARGS $EXTRA_HELM_INSTALL_ARGS --set defaults.log_level=$VOLTHA_LOG_LEVEL --namespace $NAMESPACE --name $INAME $CHART_VERSION $EXTRA_HELM_FLAGS $CHART >>$LOG 2>&1) >>$LOG 2>&1
Andy Baviere22ff252019-12-19 11:40:31 -0700976 SUCCESS=$?
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700977 COUNT=$(expr 300 / 15)
978 fi
979 sleep .15
980 done
981 espin $INDENT $VERIFIED
982}
983
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700984echo "INSTALL TYPE: $TYPE" >> $LOG
985
986bspin "Verify GOPATH"
987export GOPATH=$(pwd)
Test User3d7ad8e2019-07-03 06:15:44 +0000988mkdir -p $GOPATH/bin
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700989espin $VERIFIED
990
David Bainbridgee87067b2019-08-12 22:00:12 +0000991STIME=$(date +%s)
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700992if [ "$INSTALL_KUBECTL" == "no" ]; then
993 bspin "Skip kubectl install"
994 espin $NO_ENTRY
Test Userc13bdc92019-07-03 20:57:49 +0000995else
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700996 bspin "Verify kubectl $HELM"
997 if [ -x $GOPATH/bin/kubectl ]; then
998 espin $VERIFIED
999 else
1000 espin $NOT_VERIFIED
1001 bspin - "Download and install Kubernetes/kubectl $DOWNLOAD"
1002 (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
1003 (set -x; chmod 755 $GOPATH/bin/kubectl >>$LOG 2>&1) >>$LOG 2>&1
1004 espin - $VERIFIED
1005 fi
Test Userc13bdc92019-07-03 20:57:49 +00001006fi
David Bainbridgee87067b2019-08-12 22:00:12 +00001007if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +00001008 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +00001009fi
Test Userc13bdc92019-07-03 20:57:49 +00001010
David Bainbridgee87067b2019-08-12 22:00:12 +00001011STIME=$(date +%s)
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001012if [ "$DEPLOY_K8S" == "no" ]; then
1013 bspin "Skip Kubernetes/Kind Deployment"
1014 espin $NO_ENTRY
1015else
Test Userba1e7e72019-07-10 22:27:54 +00001016 bspin "Verify Kubernetes/Kind $HELM"
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -08001017 IS_INSTALLED=0
1018 OP_TYPE="install"
Test Userba1e7e72019-07-10 22:27:54 +00001019 if [ -x $GOPATH/bin/kind ]; then
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -08001020 OP_TYPE="upgrade"
1021 if [ $($GOPATH/bin/kind --version | grep -c $KIND_VERSION) -eq 1 ]; then
1022 IS_INSTALLED=1
1023 espin $VERIFIED
1024 fi
1025 fi
1026 if [ $IS_INSTALLED -eq 0 ]; then
Test Userba1e7e72019-07-10 22:27:54 +00001027 espin $NOT_VERIFIED
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -08001028 bspin - "Download and $OP_TYPE Kubernetes/kind $DOWNLOAD"
David Bainbridge9e2a6662019-07-11 17:07:57 +00001029 (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 +00001030 (set -x; chmod 755 $GOPATH/bin/kind >>$LOG 2>&1) >>$LOG 2>&1
1031 espin - $VERIFIED
1032 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001033fi
1034
David Bainbridgee87067b2019-08-12 22:00:12 +00001035if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +00001036 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +00001037fi
1038
1039STIME=$(date +%s)
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001040if [ "$INSTALL_HELM" == "no" ]; then
1041 bspin "Skip Helm Install"
1042 espin $NO_ENTRY
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001043else
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001044 bspin "Verify Helm $HELM"
David Bainbridgea34993d2020-04-01 09:15:42 -07001045 HELM_UPGRADE=0
1046 HELM_UPGRADE_DESC="install"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001047 if [ -x $GOPATH/bin/helm ]; then
David Bainbridgea34993d2020-04-01 09:15:42 -07001048 HAVE_VER=$($GOPATH/bin/helm version -c --template '{{.Client.SemVer}}')
1049 HELM_UP_DOWN=$(echo -e "$HAVE_VER\n$HELM_VERSION" | sort -V | head -1)
1050 if [ $HAVE_VER != $HELM_VERSION ]; then
1051 if [ $HELM_UP_DOWN == $HELM_VERSION ]; then
1052 HELM_UPGRADE_DESC="downgrade"
1053 else
1054 HELM_UPGRADE_DESC="upgrade"
1055 fi
1056 HELM_UPGRADE=1
1057 else
1058 espin $VERIFIED
1059 fi
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001060 else
David Bainbridgea34993d2020-04-01 09:15:42 -07001061 HELM_UPGRADE=1
1062 fi
1063
1064 if [ $HELM_UPGRADE -ne 0 ]; then
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001065 espin $NOT_VERIFIED
David Bainbridgea34993d2020-04-01 09:15:42 -07001066 bspin - "Download and $HELM_UPGRADE_DESC Helm $DOWNLOAD"
1067 (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 -07001068 espin - $VERIFIED
1069 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001070fi
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -08001071
David Bainbridgee87067b2019-08-12 22:00:12 +00001072if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +00001073 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +00001074fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001075
David Bainbridgee87067b2019-08-12 22:00:12 +00001076STIME=$(date +%s)
Test Userb5712372019-07-03 21:52:17 +00001077bspin "Verify voltctl $HIGH_VOLTAGE"
David Bainbridged2811972019-12-14 01:14:09 +00001078VOK=0
1079VMESSAGE="install"
David K. Bainbridgeebf38d92020-02-10 10:46:31 -08001080export VC_VERSION="$VOLTCTL_VERSION"
1081if [ "$VC_VERSION" == "latest" ]; then
1082 export VC_VERSION=$(curl -sSL https://api.github.com/repos/opencord/voltctl/releases/latest | jq -r .tag_name | sed -e 's/^v//g')
1083fi
Test User3d7ad8e2019-07-03 06:15:44 +00001084if [ -x $GOPATH/bin/voltctl ]; then
David Bainbridge1ba64f12019-12-18 00:40:13 +00001085 VHAVE=$($GOPATH/bin/voltctl version --clientonly -o json | jq -r .version)
David K. Bainbridgeebf38d92020-02-10 10:46:31 -08001086 if [ $? -eq 0 -a "$VHAVE" == "$VC_VERSION" ]; then
David Bainbridged2811972019-12-14 01:14:09 +00001087 VOK=1
David Bainbridge1ba64f12019-12-18 00:40:13 +00001088 espin $VERIFIED
1089 else
David K. Bainbridgeebf38d92020-02-10 10:46:31 -08001090 VCHECK=$(echo -e "$VHAVE\n$VC_VERSION" | sort -V | head -1)
1091 if [ "$VCHECK" == "$VHAVE" ]; then
1092 VMESSAGE="upgrade"
1093 else
1094 VMESSAGE="downgrade"
1095 fi
David Bainbridged2811972019-12-14 01:14:09 +00001096 fi
1097fi
1098
David Bainbridge1ba64f12019-12-18 00:40:13 +00001099if [ $VOK -eq 0 ]; then
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001100 espin $NOT_VERIFIED
David Bainbridged2811972019-12-14 01:14:09 +00001101 bspin - "Download and $VMESSAGE voltctl $DOWNLOAD"
David K. Bainbridgeebf38d92020-02-10 10:46:31 -08001102 (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 +00001103 (set -x; chmod 755 $GOPATH/bin/voltctl >>$LOG 2>&1) >>$LOG 2>&1
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001104 espin - $VERIFIED
1105fi
David Bainbridgee87067b2019-08-12 22:00:12 +00001106if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +00001107 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +00001108fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001109
1110bspin "Verify command PATH"
Test Userba1e7e72019-07-10 22:27:54 +00001111export PATH=$GOPATH/bin:$PATH
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001112espin $VERIFIED
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001113
David Bainbridgee87067b2019-08-12 22:00:12 +00001114STIME=$(date +%s)
Test Userba1e7e72019-07-10 22:27:54 +00001115if [ "$DEPLOY_K8S" == "yes" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +00001116 HAVE=$(kind get clusters | grep -c voltha-$NAME)
Test Userba1e7e72019-07-10 22:27:54 +00001117 bspin "Verify Kubernetes/Kind Cluster"
1118 sspin
1119 if [ $HAVE -eq 0 ]; then
David Bainbridge491b1bd2019-07-11 17:53:11 +00001120 espin $NOT_VERIFIED
1121 bspin - "Verify cluster configuration"
David Bainbridge0774b232019-08-02 06:37:19 +00001122 if [ ! -r ./$NAME-cluster.cfg ]; then
David Bainbridge491b1bd2019-07-11 17:53:11 +00001123 espin - $NOT_VERIFIED
David K. Bainbridge43422402020-03-06 07:41:22 -08001124 bspin - "Download cluster configuration: $TYPE-cluster.cfg to $NAME-cluster.cfg $DOWNLOAD"
David K. Bainbridgea00736b2020-01-08 14:33:17 -08001125 ERR_OUT=$(mktemp)
1126 (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
1127 if [ $? -ne 0 ]; then
1128 espin - $THEX
1129 echo -e "${RED}${BOLD}${ERROR}ERROR: $NAME-cluster.cfg${NORMAL}${RED} - $(cat $ERR_OUT)${NORMAL}"
1130 echo "ERROR: $(cat $ERR_OUT)" >>$LOG
1131 rm -rf $ERR_OUT ./$NAME-cluster.cfg
1132 exit 1
1133 fi
1134 rm -rf $ERR_OUT
1135 else
David K. Bainbridge43422402020-03-06 07:41:22 -08001136 espin - $VERIFIED
David K. Bainbridgea00736b2020-01-08 14:33:17 -08001137 fi
David Bainbridge0774b232019-08-02 06:37:19 +00001138 kind create cluster --name voltha-$NAME --config $NAME-cluster.cfg
David Bainbridge491b1bd2019-07-11 17:53:11 +00001139 else
1140 espin $VERIFIED
Test Userba1e7e72019-07-10 22:27:54 +00001141 fi
1142
David Bainbridge0774b232019-08-02 06:37:19 +00001143 export KUBECONFIG="$(kind get kubeconfig-path --name="voltha-$NAME")"
Test Userba1e7e72019-07-10 22:27:54 +00001144 P="coredns-.* \
David Bainbridge0774b232019-08-02 06:37:19 +00001145 etcd-voltha-$NAME-control-plane \
Test Userba1e7e72019-07-10 22:27:54 +00001146 kindnet-.* \
David Bainbridge0774b232019-08-02 06:37:19 +00001147 kube-apiserver-voltha-$NAME-control-plane \
1148 kube-controller-manager-voltha-$NAME-control-plane \
Test Userba1e7e72019-07-10 22:27:54 +00001149 kube-proxy-.* \
David Bainbridge0774b232019-08-02 06:37:19 +00001150 kube-scheduler-voltha-$NAME-control-plane"
Test Userba1e7e72019-07-10 22:27:54 +00001151
1152 EXPECT=$(test "$TYPE" == "minimal" && echo "12" || echo "14")
David Bainbridge4f1b5562019-08-19 04:46:52 +00001153 wait_for_pods - "kube-system" $EXPECT "includes" -1 "Waiting for system PODs to start" $P
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001154fi
David Bainbridgee87067b2019-08-12 22:00:12 +00001155if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +00001156 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +00001157fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001158
David Bainbridgee87067b2019-08-12 22:00:12 +00001159STIME=$(date +%s)
David Bainbridge4c6289c2019-09-03 21:11:32 +00001160COUNT=$(count_pods "kube-system" ":Running:" "tiller-deploy-.*")
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001161bspin "Verify Helm"
Test Userba1e7e72019-07-10 22:27:54 +00001162if [ $COUNT -ne 1 ]; then
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001163 espin $NOT_VERIFIED
Test Userb5712372019-07-03 21:52:17 +00001164 echo -e "Configuring Helm $GEAR"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001165 if [ "$INSTALL_HELM" == "no" ]; then
1166 bspin - "Skip Helm/Tiller Initialization"
1167 espin - $NO_ENTRY
1168 else
1169 bspin - "Initialize Helm"
1170 (set -x; helm init --upgrade >>$LOG 2>&1) >>$LOG 2>&1
1171 espin - $VERIFIED
David Bainbridge4f1b5562019-08-19 04:46:52 +00001172 wait_for_pods - "kube-system" 1 "includes" -1 "Waiting for Tiller POD to start" "tiller-deploy-.*"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001173 fi
Test Userb5712372019-07-03 21:52:17 +00001174 bspin - "Add Google Incubator repository to Helm"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001175 (set -x; helm repo add incubator https://kubernetes-charts-incubator.storage.googleapis.com >>$LOG 2>&1) >>$LOG 2>&1
1176 espin - $VERIFIED
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001177
Test Userba1e7e72019-07-10 22:27:54 +00001178 # HACK (sort-of) - the config for tiller is about to be patched, which will
1179 # cause the tiller pod to be recreated. This can sometimes cause a timing
1180 # issue with the "wait_for_pods" call on tiller as it may incorrectly
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001181 # identify the running/ready tiller pod that is soon to be terminated as
Test Userba1e7e72019-07-10 22:27:54 +00001182 # what it is waiting for. To avoid this issue we do a clean scale down and
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001183 # scale up of the pod so the script controlls when it should be expecting
Test Userba1e7e72019-07-10 22:27:54 +00001184 # things
1185 (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 -07001186
Test Userb5712372019-07-03 21:52:17 +00001187 bspin - "Add Google Stable repository to Helm"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001188 (set -x; helm repo add stable https://kubernetes-charts.storage.googleapis.com >>$LOG 2>&1) >>$LOG 2>&1
1189 espin - $VERIFIED
Test Userb5712372019-07-03 21:52:17 +00001190 bspin - "Add ONF repository to Helm"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001191 (set -x; helm repo add onf https://charts.opencord.org >>$LOG 2>&1) >>$LOG 2>&1
1192 espin - $VERIFIED
Test Userb5712372019-07-03 21:52:17 +00001193 bspin - "Update Helm repository cache"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001194 (set -x; helm repo update >>$LOG 2>&1) >>$LOG 2>&1
1195 espin - $VERIFIED
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001196
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001197 # Create and k8s service account so that Helm can create pods
Test Userb5712372019-07-03 21:52:17 +00001198 bspin - "Create Tiller ServiceAccount"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001199 (set -x; kubectl create serviceaccount --namespace kube-system tiller >>$LOG 2>&1) >>$LOG 2>&1
1200 espin - $VERIFIED
Test Userb5712372019-07-03 21:52:17 +00001201 bspin - "Create Tiller ClusterRoleBinding"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001202 (set -x; kubectl create clusterrolebinding tiller-cluster-rule --clusterrole=cluster-admin --serviceaccount=kube-system:tiller >>$LOG 2>&1) >>$LOG 2>&1
1203 espin - $VERIFIED
Test Userb5712372019-07-03 21:52:17 +00001204 bspin - "Update Tiller Manifest"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001205 (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 +00001206
1207 # HACK (sort-of) - part to, spin it back up
1208 (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 -07001209 espin - $VERIFIED
1210else
David Bainbridgea34993d2020-04-01 09:15:42 -07001211 if [ $(helm version -s --template '{{.Server.SemVer}}') != $HELM_VERSION ]; then
1212 espin $NOT_VERIFIED
1213 bspin - "Sync Tiller server version with helm client"
1214 (set -x; helm init --upgrade --force-upgrade --wait >>$LOG 2>&1) >>$LOG 2>&1
1215 espin - $VERIFIED
1216 else
1217 espin $VERIFIED
1218 fi
1219
David Bainbridge46505fb2019-10-01 21:13:20 +00001220 if [ "$UPDATE_HELM_REPOS" == "yes" ]; then
1221 bspin - "Update Helm repository cache"
1222 (set -x; helm repo update >>$LOG 2>&1) >>$LOG 2>&1
1223 espin - $VERIFIED
1224 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001225fi
David Bainbridge4f1b5562019-08-19 04:46:52 +00001226wait_for_pods - "kube-system" 1 "includes" -1 "Waiting for Tiller POD to start" "tiller-deploy-.*"
David Bainbridgee87067b2019-08-12 22:00:12 +00001227if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +00001228 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +00001229fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001230
David Bainbridgee87067b2019-08-12 22:00:12 +00001231STIME=$(date +%s)
David Bainbridge0774b232019-08-02 06:37:19 +00001232bspin "Verify Helm values file: $NAME-values.yaml"
1233if [ ! -r "./$NAME-values.yaml" ]; then
Test Userba1e7e72019-07-10 22:27:54 +00001234 espin $NOT_VERIFIED
David Bainbridge0774b232019-08-02 06:37:19 +00001235 bspin - "Download Helm values file: $TYPE-values.yaml to $NAME-values.yaml $DOWNLOAD"
David K. Bainbridgea00736b2020-01-08 14:33:17 -08001236 ERR_OUT=$(mktemp)
1237 (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
1238 if [ $? -ne 0 ]; then
1239 espin - $THEX
1240 echo -e "${RED}${BOLD}${ERROR}ERROR: $NAME-values.yaml${NORMAL}${RED} - $(cat $ERR_OUT)${NORMAL}"
1241 echo "ERROR: $(cat $ERR_OUT)" >>$LOG
1242 rm -rf $ERR_OUT ./$NAME-values.yaml
1243 exit 1
1244 fi
1245 rm -rf $ERR_OUT
Test Userba1e7e72019-07-10 22:27:54 +00001246 espin - $VERIFIED
1247else
1248 espin $VERIFIED
1249fi
David Bainbridgee87067b2019-08-12 22:00:12 +00001250if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +00001251 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +00001252fi
Test Userba1e7e72019-07-10 22:27:54 +00001253
David Bainbridge99ac7a22019-08-31 02:26:43 +00001254STIME=$(date +%s)
1255bspin "Verify or download chart specific values files $DOWNLOAD"
1256VALUES_FILES="monkey-values.yaml"
David K. Bainbridgea00736b2020-01-08 14:33:17 -08001257ERR_OUT=$(mktemp)
David Bainbridge99ac7a22019-08-31 02:26:43 +00001258for i in $VALUES_FILES; do
1259 if [ ! -r ./$i ]; then
David K. Bainbridgea00736b2020-01-08 14:33:17 -08001260 (set -x; curl --fail -o ./$i -sSL https://raw.githubusercontent.com/ciena/kind-voltha/$VK_RELEASE/$i >>$LOG 2>$ERR_OUT) >>$LOG 2>&1
1261 if [ $? -ne 0 ]; then
1262 espin $THEX
1263 echo -e "${RED}${BOLD}${ERROR}ERROR: $i${NORMAL}${RED} - $(cat $ERR_OUT)${NORMAL}"
1264 echo "ERROR: $i - $(cat $ERR_OUT)" >>$LOG
1265 rm -rf $ERR_OUT ./$i
1266 exit 1
1267 fi
1268 rm -rf $ERR_OUT
David Bainbridge99ac7a22019-08-31 02:26:43 +00001269 fi
1270done
David Bainbridge1cecba52020-03-30 09:43:10 -07001271rm -rf $ERR_OUT
David Bainbridge99ac7a22019-08-31 02:26:43 +00001272espin $VERIFIED
1273if [ "$WITH_TIMINGS" == "yes" ]; then
1274 printtime $(expr $(date +%s) - $STIME)
1275fi
1276
1277if [ "$WITH_CHAOS" == "yes" ]; then
1278 bspin "Verify or clone kube-monkey helm chart $DOWNLOAD"
1279 if [ -r ./kube-monkey ]; then
1280 espin $VERIFIED
1281 else
1282 espin $NOT_VERIFIED
1283 bspin - "GIT clone kube-monkey"
1284 (set -x; git clone https://github.com/asobti/kube-monkey kube-monkey >>$LOG 2>&1) >>$LOG 2>&1
1285 espin - $VERIFIED
1286 fi
1287fi
1288
Test Userba1e7e72019-07-10 22:27:54 +00001289if [ "$JUST_K8S" == "yes" ]; then
1290 echo "Environment deployed, not deploying VOLTHA artifacts as requested. Good bye."
1291 echo ""
1292 echo "Please issue the following commands in your terminal to ensure that you" | tee -a $LOG
1293 echo "are accessing the correct Kubernetes/Kind cluster as well as have the " | tee -a $LOG
1294 echo "tools required by VOLTHA in your command path. " | tee -a $LOG
1295 echo "" | tee -a $LOG
1296 echo -en $BOLD
1297 if [ $DEPLOY_K8S == "yes" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +00001298 echo "export KUBECONFIG=\"\$(./bin/kind get kubeconfig-path --name=\"voltha-$NAME\")\"" | tee -a $LOG
Test Userba1e7e72019-07-10 22:27:54 +00001299 fi
1300 echo "export PATH=$GOPATH/bin:\$PATH" | tee -a $LOG
1301 echo -en $NORMAL
1302 echo "" | tee -a $LOG
1303 echo "Thank you for choosing kind-voltha for you quick cluster needs." | tee -a $LOG
1304 exit 0
1305fi
1306
David Bainbridge76afd812020-04-06 09:53:52 -07001307if [ $WITH_ETCD != "yes" -a $WITH_ETCD != "external" ]; then
David Bainbridge696bc632020-04-05 21:49:37 -07001308 bspin "Skip ETCD Operator Deployment"
1309 espin $NO_ENTRY
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001310else
David Bainbridge696bc632020-04-05 21:49:37 -07001311 STIME=$(date +%s)
David Bainbridge76afd812020-04-06 09:53:52 -07001312 NS=$VOLTHA_NS
1313 if [ $WITH_ETCD == "external" ]; then
1314 NS=$INFRA_NS
1315 fi
David Bainbridge696bc632020-04-05 21:49:37 -07001316 bspin "Verify ETCD Operator $OLD_KEY"
David Bainbridge76afd812020-04-06 09:53:52 -07001317 if [ $(helm list --deployed --short --namespace $NS "^etcd-operator\$" | wc -l) -ne 1 ]; then
David Bainbridge696bc632020-04-05 21:49:37 -07001318 espin $NOT_VERIFIED
David Bainbridge76afd812020-04-06 09:53:52 -07001319 helm_install - $NS etcd-operator stable/etcd-operator latest "Install ETCD Operator"
David Bainbridge696bc632020-04-05 21:49:37 -07001320 else
1321 espin $VERIFIED
1322 fi
1323 EXPECT=$(test "$TYPE" == "minimal" && echo "1" || echo "3")
David Bainbridge76afd812020-04-06 09:53:52 -07001324 wait_for_pods - "$NS" $EXPECT "includes" -1 "Waiting for ETCD Operator to start" "etcd-operator-.*"
David Bainbridge696bc632020-04-05 21:49:37 -07001325 if [ "$WITH_TIMINGS" == "yes" ]; then
1326 printtime $(expr $(date +%s) - $STIME)
1327 fi
David Bainbridgee87067b2019-08-12 22:00:12 +00001328fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001329
David Bainbridgee87067b2019-08-12 22:00:12 +00001330STIME=$(date +%s)
David Bainbridgeb270c202019-07-26 01:44:42 +00001331if [ $WITH_ONOS == "yes" ]; then
1332 bspin "Verify ONOS installed $BIRD"
David Bainbridge76afd812020-04-06 09:53:52 -07001333 if [ $(helm list --deployed --short --namespace $INFRA_NS "^onos\$" | wc -l) -ne 1 ]; then
David Bainbridgeb270c202019-07-26 01:44:42 +00001334 espin $NOT_VERIFIED
David Bainbridge76afd812020-04-06 09:53:52 -07001335 EXTRA_HELM_FLAGS="$SET_TAG $EXTRA_HELM_FLAGS" helm_install - $INFRA_NS onos $ONOS_CHART $ONOS_CHART_VERSION "Install ONOS"
David Bainbridgeb270c202019-07-26 01:44:42 +00001336 else
1337 espin $VERIFIED
1338 fi
David Bainbridge76afd812020-04-06 09:53:52 -07001339 wait_for_pods - "$INFRA_NS" 1 "includes" -1 "Waiting for ONOS to start" "onos-.*"
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001340
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -08001341 if [ $WITH_PORT_FORWARDS == "yes" ]; then
1342 bspin - "Forward ONOS API port $FORWARD"
1343 kill_port_forward onos-ui
David Bainbridge76afd812020-04-06 09:53:52 -07001344 port_forward $INFRA_NS onos-ui $ONOS_API_PORT 8181
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -08001345 espin - $VERIFIED
1346 bspin - "Forward ONOS SSH port $FORWARD"
1347 kill_port_forward onos-ssh
David Bainbridge76afd812020-04-06 09:53:52 -07001348 port_forward $INFRA_NS onos-ssh $ONOS_SSH_PORT 8101
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -08001349 espin - $VERIFIED
1350 _ONOS_API_EP="127.0.0.1:$ONOS_API_PORT"
1351 else
David Bainbridge76afd812020-04-06 09:53:52 -07001352 _ONOS_API_EP=$(get_service_ep $INFRA_NS onos-ui)
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -08001353 fi
David Bainbridged31d6122019-08-13 19:37:59 +00001354 bspin - "Verify or download ONOS configuration support files $DOWNLOAD"
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001355 ONOS_FILES="olt-onos-enableExtraneousRules.json onos-aaa.json \
David Bainbridge696bc632020-04-05 21:49:37 -07001356 onos-dhcpl2relay.json onos-sadis-sample.json"
David Bainbridged31d6122019-08-13 19:37:59 +00001357 (set -x; mkdir -p ./onos-files >>$LOG 2>&1) >>$LOG 2>&1
David K. Bainbridgea00736b2020-01-08 14:33:17 -08001358 ERR_OUT=$(mktemp)
David Bainbridge2b19e832019-08-16 02:40:53 +00001359 for i in $ONOS_FILES; do
David Bainbridged31d6122019-08-13 19:37:59 +00001360 if [ ! -r ./onos-files/$i ]; then
David K. Bainbridgea00736b2020-01-08 14:33:17 -08001361 (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
1362 if [ $? -ne 0 ]; then
1363 espin - $THEX
1364 echo -e "${RED}${BOLD}${ERROR}ERROR: $i${NORMAL}${RED} - $(cat $ERR_OUT)${NORMAL}"
1365 echo "ERROR: $(cat $ERR_OUT)" >>$LOG
1366 rm -rf $ERR_OUT ./onos-files/$i
1367 exit 1
1368 fi
1369 rm -rf $ERR_OUT
David Bainbridged31d6122019-08-13 19:37:59 +00001370 fi
1371 done
David Bainbridge1cecba52020-03-30 09:43:10 -07001372 rm -rf $ERR_OUT
Test Userba1e7e72019-07-10 22:27:54 +00001373 espin - $VERIFIED
David Bainbridge27790d62019-08-13 22:43:19 +00001374
1375 if [ $INSTALL_ONOS_APPS == "yes" ]; then
1376 bspin - "Installing custom ONOS applications"
1377 if [ -x onos-files/onos-apps -a $(ls -1 onos-files/onos-apps/*.oar 2>/dev/null | wc -l) -gt 0 ]; then
1378 for OAR in $(ls -1 onos-files/onos-apps/*.oar); do
1379 sspin - "Installing custom ONOS applications - $OAR$CEOL"
David Bainbridge2b19e832019-08-16 02:40:53 +00001380 override_onos_app $OAR
David Bainbridge27790d62019-08-13 22:43:19 +00001381 done
1382 espin - "$VERIFIED Installing custom ONOS applications$CEOL"
1383 else
1384 espin - "$NOT_VERIFIED Installing custom ONOS applications - None Found"
1385 fi
1386 fi
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001387
David Bainbridge696bc632020-04-05 21:49:37 -07001388 if [ $WITH_KAFKA != "no" ]; then
David Bainbridge837e8bd2020-04-06 13:17:14 -07001389 check_onos_app_active org.opencord.kafka
David Bainbridge76afd812020-04-06 09:53:52 -07001390 _HOST=voltha-kafka.$INFRA_NS.svc.cluster.local
David Bainbridge837e8bd2020-04-06 13:17:14 -07001391 _PORT=9092
David Bainbridge76afd812020-04-06 09:53:52 -07001392 if [ $WITH_KAFKA == "yes" ]; then
1393 _HOST=voltha-kafka.$VOLTHA_NS.svc.cluster.local
1394 _PORT=9092
1395 elif [ $WITH_KAFKA == "external" ]; then
1396 _HOST=kafka.$INFRA_NS.svc.cluster.local
1397 _PORT=9092
1398 else
David Bainbridge837e8bd2020-04-06 13:17:14 -07001399 _HOST=$(echo $WITH_KAFKA | cut -d: -f1)
1400 _PORT=$(echo $WITH_KAFKA | cut -s -d: -f2)
1401 _PORT=${_PORT:-9092}
1402 fi
1403 push_onos_config "json" "Push ONOS Kafka Configuration" "network/configuration/apps/org.opencord.kafka" \
1404 "$(echo $(cat <<EOJ
David Bainbridge696bc632020-04-05 21:49:37 -07001405{
1406 "kafka": {
1407 "bootstrapServers": "$_HOST:$_PORT"
1408 }
1409}
1410EOJ
1411) | tr -d '[:space:]')"
David Bainbridge837e8bd2020-04-06 13:17:14 -07001412 fi
Matteo Scandolo9a77a732020-01-09 14:24:12 -08001413 check_onos_app_active org.opencord.dhcpl2relay
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001414 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 -08001415 check_onos_app_active org.opencord.olt
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001416 # FIXME use WITH_DHCP and WITH_EAPOL flags to configre OLT App
Hardik Windlassa7501fb2020-02-17 14:28:20 +00001417 # Default value for "enableEapol" is true in OLT App
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001418 if [ $WITH_EAPOL == "yes" ]; then
1419 push_onos_config "json" "Enable VOLTHA ONOS EAPOL provisioning" "configuration/org.opencord.olt.impl.OltFlowService" '{"enableEapol":true}'
Hardik Windlassa7501fb2020-02-17 14:28:20 +00001420 elif [ $WITH_EAPOL == "no" ]; then
1421 push_onos_config "json" "Disable VOLTHA ONOS EAPOL provisioning" "configuration/org.opencord.olt.impl.OltFlowService" '{"enableEapol":false}'
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001422 fi
Hardik Windlassa7501fb2020-02-17 14:28:20 +00001423 # Default value for "enableDhcpOnProvisioning" is false and for "enableDhcpV4" is true in OLT App
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001424 if [ $WITH_DHCP == "yes" ]; then
1425 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 +00001426 elif [ $WITH_DHCP == "no" ]; then
1427 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 -08001428 fi
Hardik Windlassa7501fb2020-02-17 14:28:20 +00001429 # Default value for "enableIgmpOnProvisioning" is false in OLT App
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001430 if [ $WITH_IGMP == "yes" ]; then
1431 push_onos_config "json" "Enable VOLTHA ONOS IGMP provisioning" "configuration/org.opencord.olt.impl.OltFlowService" '{"enableIgmpOnProvisioning":true}'
Hardik Windlassa7501fb2020-02-17 14:28:20 +00001432 elif [ $WITH_IGMP == "no" ]; then
1433 push_onos_config "json" "Disable VOLTHA ONOS IGMP provisioning" "configuration/org.opencord.olt.impl.OltFlowService" '{"enableIgmpOnProvisioning":false}'
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001434 fi
David K. Bainbridge484d80c2020-03-05 21:44:34 -08001435 if [ $ENABLE_ONOS_EXTRANEOUS_RULES == "yes" ]; then
1436 push_onos_config "file" "Enabling extraneous rules for ONOS" "configuration/org.onosproject.net.flow.impl.FlowRuleManager" "onos-files/olt-onos-enableExtraneousRules.json"
1437 fi
David K. Bainbridgeb859e912020-03-13 14:07:52 -07001438 if [ $(echo ":yes:file:" | grep -c ":$CONFIG_SADIS:") -eq 1 ]; then
Matteo Scandolo9a77a732020-01-09 14:24:12 -08001439 check_onos_app_active org.opencord.sadis
Hardik Windlassb3147602020-03-09 16:59:15 +05301440 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 -07001441 elif [ "$CONFIG_SADIS" == "bbsim" ]; then
1442 push_onos_config "json" \
1443 "[optional] Push ONOS configuration for BBSIM SADIS servers" \
1444 "network/configuration/apps/org.opencord.sadis" \
1445 "$(echo $(cat <<EOJ
1446{
1447 "sadis": {
1448 "integration": {
David Bainbridge76afd812020-04-06 09:53:52 -07001449 "url": "http://bbsim.$BBSIM_NS.svc.cluster.local:50074/v2/subscribers/%s",
David K. Bainbridgeb859e912020-03-13 14:07:52 -07001450 "cache": {
1451 "enabled": true,
1452 "maxsize": 50,
1453 "ttl": "PT1m"
1454 }
1455 }
1456 },
1457 "bandwidthprofile": {
1458 "integration": {
David Bainbridge76afd812020-04-06 09:53:52 -07001459 "url": "http://bbsim.$BBSIM_NS.svc.cluster.local:50074/v2/bandwidthprofiles/%s",
David K. Bainbridgeb859e912020-03-13 14:07:52 -07001460 "cache": {
1461 "enabled": true,
1462 "maxsize": 50,
1463 "ttl": "PT1m"
1464 }
1465 }
1466 }
1467}
1468EOJ
1469) | tr -d '[:space:]')"
1470 elif [ "$CONFIG_SADIS" == "url" ]; then
1471 push_onos_config "json" \
1472 "[optional] Push ONOS configuration for custom SADIS and Bandwidth Profile servers" \
1473 "network/configuration/apps/org.opencord.sadis" \
1474 "$(echo $(cat <<EOJ
1475{
1476 "sadis": {
1477 "integration": {
1478 "url": "$SADIS_SUBSCRIBERS",
1479 "cache": {
1480 "enabled": true,
1481 "maxsize": 50,
1482 "ttl": "PT1m"
1483 }
1484 }
1485 },
1486 "bandwidthprofile": {
1487 "integration": {
1488 "url": "$SADIS_BANDWIDTH_PROFILES",
1489 "cache": {
1490 "enabled": true,
1491 "maxsize": 50,
1492 "ttl": "PT1m"
1493 }
1494 }
1495 }
1496}
1497EOJ
1498) | tr -d '[:space:]')"
David Bainbridge2b19e832019-08-16 02:40:53 +00001499 fi
Test Userba1e7e72019-07-10 22:27:54 +00001500fi
David Bainbridgee87067b2019-08-12 22:00:12 +00001501if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +00001502 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +00001503fi
Test Userba1e7e72019-07-10 22:27:54 +00001504
David Bainbridge76afd812020-04-06 09:53:52 -07001505if [ $WITH_ETCD == "external" ]; then
1506 STIME=$(date +%s)
1507 bspin "Verify external ETCD cluster $OLD_KEY"
1508 EXPECT=$(test "$TYPE" == "minimal" && echo "1" || echo "3")
1509 if [ $(helm list --deployed --short --namespace $INFRA_NS "^etcd-cluster\$" | wc -l) -ne 1 ]; then
1510 espin $NOT_VERIFIED
1511 INTERNAL_EXTRA_HELM_INSTALL_ARGS+="--set clusterName=etcd-cluster --set autoCompactionRetention=1 --set clusterSize=$EXPECT"
1512 helm_install - $INFRA_NS etcd-cluster onf/voltha-etcd-cluster latest "Install eternal ETCD cluster"
1513 else
1514 espin $VERIFIED
1515 fi
1516 wait_for_pods - "$INFRA_NS" $EXPECT "includes" -1 "Waiting for ETCD cluster to start" "etcd-cluster-.*"
1517 if [ "$WITH_TIMINGS" == "yes" ]; then
1518 printtime $(expr $(date +%s) - $STIME)
1519 fi
1520fi
1521
1522if [ $WITH_KAFKA == "external" ]; then
1523 _TMP=$(mktemp -u)
1524 _COUNT=$(test $TYPE == "minimal" && echo "1" || echo "3")
1525 cat << EOC > $_TMP
1526configurationOverrides:
1527 "default.replication.factor": $_COUNT
1528 "offsets.topic.replication.factor": $_COUNT
1529 "log.retention.hours": 4
1530 "log.message.timestamp.type": "LogAppendTime"
1531persistence:
1532 enabled: false
1533zookeeper:
1534 replicaCount: 1
1535 persistence:
1536 enabled: false
1537replicas: $_COUNT
1538EOC
1539 STIME=$(date +%s)
1540 bspin "Verify external Kafka cluster $OLD_KEY"
1541 EXPECT=$(test "$TYPE" == "minimal" && echo "2" || echo "4")
1542 if [ $(helm list --deployed --short --namespace $INFRA_NS "^kafka\$" | wc -l) -ne 1 ]; then
1543 espin $NOT_VERIFIED
1544 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" -f $_TMP"
1545 helm_install - $INFRA_NS kafka incubator/kafka latest "Install eternal Kafka cluster"
1546 else
1547 espin $VERIFIED
1548 fi
1549 # DKB
1550 wait_for_pods - "$INFRA_NS" $EXPECT "includes" -1 "Waiting for Kafka cluster to start" "kafka-.*"
1551 if [ "$WITH_TIMINGS" == "yes" ]; then
1552 printtime $(expr $(date +%s) - $STIME)
1553 fi
1554 rm -rf $_TMP
1555fi
1556
David Bainbridgee87067b2019-08-12 22:00:12 +00001557STIME=$(date +%s)
David Bainbridge696bc632020-04-05 21:49:37 -07001558EXPECT=1
1559if [ "$ONLY_ONE" == "yes" ]; then
1560 EXPECT=$((EXPECT+1))
1561 INTERNAL_EXTRA_HELM_INSTALL_ARGS="--set therecanbeonlyone=true"
1562else
1563 EXPECT=$((EXPECT+2))
1564fi
David Bainbridge76afd812020-04-06 09:53:52 -07001565case $WITH_ETCD in
1566 no)
1567 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set private_etcd_cluster=false"
1568 ;;
1569 yes)
1570 _HOST="voltha-etcd-cluster-client.$VOLTHA_NS.svc.cluster.local"
1571 _PORT=2379
1572 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set services.etcd.service=$_HOST --set services.etcd.port=$_PORT"
1573 EXPECT=$((EXPECT+$(test "$TYPE" == "minimal" && echo "1" || echo "3")))
1574 ;;
1575 external)
1576 _HOST="etcd-cluster-client.$INFRA_NS.svc.cluster.local"
1577 _PORT=2379
1578 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set private_etcd_cluster=false --set services.etcd.service=$_HOST --set services.etcd.port=$_PORT"
1579 ;;
1580 *)
David Bainbridge696bc632020-04-05 21:49:37 -07001581 _HOST=$(echo $WITH_ETCD | cut -d: -f1)
1582 _PORT=$(echo $WITH_ETCD | cut -s -d: -f2)
1583 _PORT=${_PORT:-2379}
David Bainbridge76afd812020-04-06 09:53:52 -07001584 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set private_etcd_cluster=false --set services.etcd.service=$_HOST --set services.etcd.port=$_PORT"
1585 ;;
1586esac
1587case $WITH_KAFKA in
1588 no)
1589 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set private_kafka_cluster=false"
1590 ;;
1591 yes)
1592 _HOST=voltha-kafka.$VOLTHA_NS.svc.cluster.local
1593 _PORT=9092
1594 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"
1595 EXPECT=$((EXPECT+$(test "$TYPE" == "minimal" && echo "2" || echo "4")))
1596 ;;
1597 external)
1598 _HOST=kafka.$INFRA_NS.svc.cluster.local
1599 _PORT=9092
1600 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"
1601 ;;
1602 *)
David Bainbridge696bc632020-04-05 21:49:37 -07001603 _HOST=$(echo $WITH_KAFKA | cut -d: -f1)
1604 _PORT=$(echo $WITH_KAFKA | cut -s -d: -f2)
1605 _PORT=${_PORT:-9092}
David Bainbridge76afd812020-04-06 09:53:52 -07001606 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"
1607 ;;
1608esac
1609
1610if [ $WITH_ONOS == "yes" ]; then
1611 _HOST=onos-openflow.$INFRA_NS.svc.cluster.local
1612 _PORT=6653
1613 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set services.controller.service=$_HOST --set services.controller.port=$_PORT"
1614elif [ $WITH_ONOS != "no" ]; then
1615 _HOST=$(echo $WITH_ONOS | cut -d: -f1)
1616 _PORT=$(echo $WITH_ONOS | cut -s -d: -f2)
1617 _PORT=${_PORT:-6653}
1618 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set services.controller.service=$_HOST --set services.controller.port=$_PORT"
David Bainbridge696bc632020-04-05 21:49:37 -07001619fi
Test Userb5712372019-07-03 21:52:17 +00001620bspin "Verify VOLTHA installed $HIGH_VOLTAGE"
David Bainbridge76afd812020-04-06 09:53:52 -07001621if [ $(helm list --deployed --short --namespace $VOLTHA_NS "^$VOLTHA_NS\$" | wc -l) -ne 1 ]; then
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001622 espin $NOT_VERIFIED
David Bainbridge76afd812020-04-06 09:53:52 -07001623 helm_install - $VOLTHA_NS voltha $VOLTHA_CHART $VOLTHA_CHART_VERSION "Install VOLTHA Core"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001624else
1625 espin $VERIFIED
1626fi
David Bainbridge696bc632020-04-05 21:49:37 -07001627INTERNAL_EXTRA_HELM_INSTALL_ARGS=
Test Userba1e7e72019-07-10 22:27:54 +00001628
David Bainbridge90fd8e32019-08-21 23:32:47 +00001629VOLTHA="voltha-ofagent-.* \
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001630 rw-core.* \
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001631 voltha-etcd-cluster-.* \
1632 voltha-kafka-.* \
1633 voltha-zookeeper-.*"
David Bainbridge76afd812020-04-06 09:53:52 -07001634wait_for_pods - "$VOLTHA_NS" $EXPECT "includes" -1 "Waiting for VOLTHA Core to start" $VOLTHA
David Bainbridgee87067b2019-08-12 22:00:12 +00001635if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +00001636 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +00001637fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001638
David Bainbridge46505fb2019-10-01 21:13:20 +00001639if [ "$WITH_ADAPTERS" == "yes" ]; then
1640 STIME=$(date +%s)
1641 EXPECT=0
David Bainbridge696bc632020-04-05 21:49:37 -07001642 if [ $WITH_ETCD != "yes" ]; then
David Bainbridge76afd812020-04-06 09:53:52 -07001643 if [ $WITH_ETCD == "external" ]; then
1644 _HOST=etcd-cluster-client.$INFRA_NS.svc.cluster.local
1645 _PORT=2379
1646 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set services.etcd.service=$_HOST --set services.etcd.port=$_PORT"
1647 elif [ $WITH_ETCD != "no" ]; then
David Bainbridge696bc632020-04-05 21:49:37 -07001648 _HOST=$(echo $WITH_ETCD | cut -d: -f1)
1649 _PORT=$(echo $WITH_ETCD | cut -s -d: -f2)
1650 _PORT=${_PORT:-2379}
1651 INTERNAL_EXTRA_HELM_INSTALL_ARGS+=" --set services.etcd.service=$_HOST --set services.etcd.port=$_PORT"
1652 fi
1653 fi
1654 if [ $WITH_KAFKA != "yes" ]; then
David Bainbridge76afd812020-04-06 09:53:52 -07001655 if [ $WITH_KAFKA == "external" ]; then
1656 _HOST=kafka.$INFRA_NS.svc.cluster.local
1657 _PORT=9092
1658 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"
1659 elif [ $WITH_KAFKA != "no" ]; then
David Bainbridge696bc632020-04-05 21:49:37 -07001660 _HOST=$(echo $WITH_KAFKA | cut -d: -f1)
1661 _PORT=$(echo $WITH_KAFKA | cut -s -d: -f2)
1662 _PORT=${_PORT:-9092}
1663 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"
1664 fi
1665 fi
David Bainbridge46505fb2019-10-01 21:13:20 +00001666 echo -e "Verify Adapters $PLUG"
1667 if [ "$WITH_SIM_ADAPTERS" == "yes" ]; then
1668 bspin - "Verify Simulated Adapters installed"
David Bainbridge76afd812020-04-06 09:53:52 -07001669 if [ $(helm list --deployed --short --namespace $ADAPTER_NS "^sim\$" | wc -l) -ne 1 ]; then
David Bainbridge46505fb2019-10-01 21:13:20 +00001670 espin - $NOT_VERIFIED
David Bainbridge76afd812020-04-06 09:53:52 -07001671 helm_install - $ADAPTER_NS sim $VOLTHA_ADAPTER_SIM_CHART $VOLTHA_ADAPTER_SIM_CHART_VERSION "Install Simulated Adapters"
David Bainbridge46505fb2019-10-01 21:13:20 +00001672 else
1673 espin - $VERIFIED
1674 fi
1675 EXPECT=$(expr $EXPECT + 2)
1676 fi
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001677
David Bainbridge46505fb2019-10-01 21:13:20 +00001678 if [ "$WITH_OPEN_ADAPTERS" == "yes" ]; then
1679 bspin - "Verify OpenOLT Adapter installed"
David Bainbridge76afd812020-04-06 09:53:52 -07001680 if [ $(helm list --deployed --short --namespace $ADAPTER_NS "^open-olt\$" | wc -l) -ne 1 ]; then
David Bainbridge46505fb2019-10-01 21:13:20 +00001681 espin - $NOT_VERIFIED
David Bainbridge76afd812020-04-06 09:53:52 -07001682 helm_install - $ADAPTER_NS open-olt $VOLTHA_ADAPTER_OPEN_OLT_CHART $VOLTHA_ADAPTER_OPEN_OLT_CHART_VERSION "Install OpenOLT Adapter"
David Bainbridge46505fb2019-10-01 21:13:20 +00001683 else
1684 espin - $VERIFIED
1685 fi
1686 bspin - "Verify OpenONU Adapter installed"
David Bainbridge76afd812020-04-06 09:53:52 -07001687 if [ $(helm list --deployed --short --namespace $ADAPTER_NS "^open-onu\$" | wc -l) -ne 1 ]; then
David Bainbridge46505fb2019-10-01 21:13:20 +00001688 espin - $NOT_VERIFIED
David Bainbridge76afd812020-04-06 09:53:52 -07001689 helm_install - $ADAPTER_NS open-onu $VOLTHA_ADAPTER_OPEN_ONU_CHART $VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION "Install OpenONU Adapter"
David Bainbridge46505fb2019-10-01 21:13:20 +00001690 else
1691 espin - $VERIFIED
1692 fi
1693 EXPECT=$(expr $EXPECT + 2)
1694 fi
David Bainbridge696bc632020-04-05 21:49:37 -07001695 INTERNAL_EXTRA_HELM_INSTALL_ARGS=
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001696
David Bainbridge46505fb2019-10-01 21:13:20 +00001697 ADAPTERS="adapter-.*"
David Bainbridge76afd812020-04-06 09:53:52 -07001698 wait_for_pods - "$ADAPTER_NS " $EXPECT "includes" -1 "Waiting for adapters to start" $ADAPTERS
David Bainbridge46505fb2019-10-01 21:13:20 +00001699 if [ "$WITH_TIMINGS" == "yes" ]; then
1700 printtime $(expr $(date +%s) - $STIME)
1701 fi
David Bainbridgee87067b2019-08-12 22:00:12 +00001702fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001703
Test User7d866122019-07-09 17:52:35 +00001704if [ $WITH_BBSIM == "yes" ]; then
David Bainbridgee87067b2019-08-12 22:00:12 +00001705 STIME=$(date +%s)
Test User7d866122019-07-09 17:52:35 +00001706 echo -e "Verify BBSIM $PLUG"
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001707 bspin - "Verify BBSIM Installed"
David K. Bainbridge43422402020-03-06 07:41:22 -08001708 for instance in $(seq 0 $(($NUM_OF_BBSIM-1))); do
1709 if [ $instance -eq 0 ]; then
1710 instance_num=""
1711 else
1712 instance_num=$instance
1713 fi
David Bainbridge76afd812020-04-06 09:53:52 -07001714 if [ $(helm list --deployed --short --namespace $BBSIM_NS "^bbsim${instance_num}\$" | wc -l) -ne 1 ]; then
David K. Bainbridge43422402020-03-06 07:41:22 -08001715 espin - $NOT_VERIFIED
Matteo Scandolo5a149572020-04-01 10:14:57 -07001716 S_TAG=$((900+$instance))
1717 INTERNAL_EXTRA_HELM_INSTALL_ARGS="--set olt_id=$instance,s_tag=$S_TAG"
David Bainbridge76afd812020-04-06 09:53:52 -07001718 helm_install - $BBSIM_NS bbsim${instance_num} $VOLTHA_BBSIM_CHART $VOLTHA_BBSIM_CHART_VERSION "Install BBSIM${instance_num}"
David Bainbridge2eaf2cf2020-03-18 12:54:08 -07001719 INTERNAL_EXTRA_HELM_INSTALL_ARGS=
David K. Bainbridge43422402020-03-06 07:41:22 -08001720 else
1721 espin - $VERIFIED
1722 fi
1723 done
David Bainbridge76afd812020-04-06 09:53:52 -07001724 wait_for_pods - "$BBSIM_NS" $NUM_OF_BBSIM "includes" -1 "Waiting for BBSIM to start" "bbsim*"
David Bainbridgee87067b2019-08-12 22:00:12 +00001725 if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +00001726 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +00001727 fi
Test User7d866122019-07-09 17:52:35 +00001728fi
1729
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001730if [ $WITH_RADIUS == "yes" ]; then
David Bainbridgee87067b2019-08-12 22:00:12 +00001731 STIME=$(date +%s)
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001732 echo -e "Verify RADIUS $LOCK"
1733 bspin - "Verify RADIUS Installed"
David Bainbridge76afd812020-04-06 09:53:52 -07001734 if [ $(helm list --deployed --short --namespace $INFRA_NS "^radius\$" | wc -l) -ne 1 ]; then
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001735 espin - $NOT_VERIFIED
David Bainbridge76afd812020-04-06 09:53:52 -07001736 helm_install - $INFRA_NS radius onf/freeradius latest "Install RADIUS"
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001737 else
1738 espin - $VERIFIED
1739 fi
David Bainbridge76afd812020-04-06 09:53:52 -07001740 wait_for_pods - "$INFRA_NS" 1 "includes" -1 "Waiting for RADIUS to start" "radius-.*"
David Bainbridgee87067b2019-08-12 22:00:12 +00001741 if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +00001742 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +00001743 fi
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001744fi
1745
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -08001746if [ $WITH_PORT_FORWARDS == "yes" ]; then
1747 STIME=$(date +%s)
1748 bspin - "Forward VOLTHA API port $FORWARD"
1749 kill_port_forward voltha-api
David Bainbridge76afd812020-04-06 09:53:52 -07001750 port_forward $VOLTHA_NS voltha-api $VOLTHA_API_PORT 55555
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -08001751 espin - $VERIFIED
David Bainbridge76afd812020-04-06 09:53:52 -07001752 if [ $WITH_ETCD == "yes" -o $WITH_ETCD == "external" ]; then
1753 _NS=$(test $WITH_ETCD == "yes" && echo $VOLTHA_NS || echo $INFRA_NS)
David Bainbridge696bc632020-04-05 21:49:37 -07001754 bspin - "Forward VOLTHA ETCD port $FORWARD"
1755 kill_port_forward voltha-etcd-cluster-client
David Bainbridge76afd812020-04-06 09:53:52 -07001756 port_forward $_NS voltha-etcd-cluster-client $VOLTHA_ETCD_PORT 2379
David Bainbridge696bc632020-04-05 21:49:37 -07001757 espin - $VERIFIED
1758 fi
David Bainbridge76afd812020-04-06 09:53:52 -07001759 if [ $WITH_KAFKA == "yes" -o $WITH_KAFKA == "external" ]; then
1760 _NS=$(test $WITH_ETCD == "yes" && echo $VOLTHA_NS || echo $INFRA_NS)
David Bainbridge696bc632020-04-05 21:49:37 -07001761 bspin - "Forward VOLTHA Kafka port $FORWARD"
1762 kill_port_forward voltha-kafka
David Bainbridge76afd812020-04-06 09:53:52 -07001763 port_forward $_NS voltha-kafka $VOLTHA_KAFKA_PORT 9092
David Bainbridge696bc632020-04-05 21:49:37 -07001764 espin - $VERIFIED
1765 fi
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -08001766 if [ "$WITH_TIMINGS" == "yes" ]; then
1767 printtime $(expr $(date +%s) - $STIME)
1768 fi
David Bainbridgee87067b2019-08-12 22:00:12 +00001769fi
Test User3d7ad8e2019-07-03 06:15:44 +00001770
David Bainbridge696bc632020-04-05 21:49:37 -07001771if [ $WITH_ONOS == "yes" -a $WITH_RADIUS != "no" ]; then
David Bainbridge76afd812020-04-06 09:53:52 -07001772 _HOST=radius.$INFRA_NS.svc.cluster.local
David Bainbridge696bc632020-04-05 21:49:37 -07001773 _PORT=1812
1774 if [ $WITH_RADIUS != "yes" ]; then
1775 _HOST=$(echo $WITH_RADIUS | cut -d: -f1)
1776 _PORT=$(echo $WITH_RADIUS | cut -s -d: -f2)
1777 _PORT=${_PORT:-1812}
1778 fi
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001779 bspin "Configure ONOS RADIUS Connection $GEAR"
David Bainbridge696bc632020-04-05 21:49:37 -07001780 (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 +00001781 espin $VERIFIED
1782fi
1783
David Bainbridge99ac7a22019-08-31 02:26:43 +00001784if [ "$WITH_CHAOS" == "yes" ]; then
1785 STIME=$(date +%s)
1786 echo -e "Verify kube-monkey $LOCK"
1787 bspin - "Verify kube-monkey Installed"
1788 if [ $(helm list --deployed --short --namespace kube-monkey "^monkey\$" | wc -l) -ne 1 ]; then
1789 espin - $NOT_VERIFIED
1790 helm_install - kube-monkey monkey ./kube-monkey/helm/kubemonkey latest "Install Chaos Monkey"
1791 else
1792 espin - $VERIFIED
1793 fi
1794 wait_for_pods - "kube-monkey" 1 "includes" -1 "Waiting for Chaos to start" "monkey-.*"
1795 if [ "$WITH_TIMINGS" == "yes" ]; then
1796 printtime $(expr $(date +%s) - $STIME)
1797 fi
1798fi
1799
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001800bspin "Create voltctl configuration file"
Test User3d7ad8e2019-07-03 06:15:44 +00001801(set -x; mkdir -p $HOME/.volt >>$LOG 2>&1) >>$LOG 2>&1
David K. Bainbridgeb859e912020-03-13 14:07:52 -07001802MIN_VC_VERSION=$(echo -e "1.0.15\n$VC_VERSION" | sort -V | head -1)
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -08001803if [ $WITH_PORT_FORWARDS == "yes" ]; then
David K. Bainbridgeb859e912020-03-13 14:07:52 -07001804 KAFKA_FLAG="-k localhost:$VOLTHA_KAFKA_PORT"
1805 SERVER_FLAG="-s localhost:$VOLTHA_API_PORT"
1806 ETCD_FLAG=
1807 if [ "$MIN_VC_VERSION" == "1.0.15" ]; then
1808 ETCD_FLAG="-e localhost:$VOLTHA_ETCD_PORT"
1809 fi
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -08001810else
David K. Bainbridgeb859e912020-03-13 14:07:52 -07001811 KAFKA_FLAG="-k $(get_service_ep voltha voltha-kafka)"
David Bainbridge76afd812020-04-06 09:53:52 -07001812 SERVER_FLAG="-s $(get_service_ep $VOLTHA_NS voltha-api)"
David K. Bainbridgeb859e912020-03-13 14:07:52 -07001813 ETCD_FLAG=
1814 if [ "$MIN_VC_VERSION" == "1.0.15" ]; then
1815 ETCD_FLAG="-e $(get_service_ep voltha voltha-etcd-client)"
1816 fi
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -08001817fi
David K. Bainbridgeb859e912020-03-13 14:07:52 -07001818(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 +00001819espin $VERIFIED
Test User08ebbd92019-07-03 17:15:39 +00001820
David Bainbridge0774b232019-08-02 06:37:19 +00001821if [ ! -f "$NAME-env.sh" ]; then
1822 touch $NAME-env.sh
David Bainbridgeb07fdf72019-07-29 22:51:40 +00001823fi
1824
David Bainbridge596f30d2019-07-30 17:07:59 +00001825for O in $ALL_OPTIONS; do
1826 VAL=$(eval echo \$$O)
David Bainbridge0774b232019-08-02 06:37:19 +00001827 if [ ! -z "$VAL" -a $(grep -c "^export $O=" $NAME-env.sh) -eq 0 ]; then
1828 echo "export $O=\"$(eval echo \$$O)\"" >> $NAME-env.sh
David Bainbridgeb07fdf72019-07-29 22:51:40 +00001829 fi
1830done
1831
David Bainbridge0774b232019-08-02 06:37:19 +00001832if [ $DEPLOY_K8S == "yes" -a $(grep -c "^export KUBECONFIG=" $NAME-env.sh) -eq 0 ]; then
1833 echo "export KUBECONFIG=\"$(./bin/kind get kubeconfig-path --name=voltha-$NAME)\"" >> $NAME-env.sh
David Bainbridgeb07fdf72019-07-29 22:51:40 +00001834fi
1835
David Bainbridge0774b232019-08-02 06:37:19 +00001836if [ $(grep -c "^export VOLTCONFIG=" $NAME-env.sh) -eq 0 ]; then
1837 echo "export VOLTCONFIG=\"$HOME/.volt/config-$NAME\"" >> $NAME-env.sh
David Bainbridgeb07fdf72019-07-29 22:51:40 +00001838fi
1839
David Bainbridge0774b232019-08-02 06:37:19 +00001840if [ $(grep -c "^export PATH=" $NAME-env.sh) -eq 0 ]; then
1841 echo "export PATH=\"$GOPATH/bin:\$PATH\"" >> $NAME-env.sh
David Bainbridgeb07fdf72019-07-29 22:51:40 +00001842fi
1843
Test User7d866122019-07-09 17:52:35 +00001844echo ""
Test User08ebbd92019-07-03 17:15:39 +00001845echo "Please issue the following commands in your terminal to ensure that you" | tee -a $LOG
1846echo "are accessing the correct Kubernetes/Kind cluster as well as have the " | tee -a $LOG
1847echo "tools required by VOLTHA in your command path. " | tee -a $LOG
1848echo "" | tee -a $LOG
Test User7d866122019-07-09 17:52:35 +00001849echo -en $BOLD
Test Userba1e7e72019-07-10 22:27:54 +00001850if [ $DEPLOY_K8S == "yes" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +00001851 echo "export KUBECONFIG=\"\$(./bin/kind get kubeconfig-path --name=\"voltha-$NAME\")\"" | tee -a $LOG
Test Userba1e7e72019-07-10 22:27:54 +00001852fi
David Bainbridge0774b232019-08-02 06:37:19 +00001853echo "export VOLTCONFIG=\"$HOME/.volt/config-$NAME\"" | tee -a $LOG
Test Userba1e7e72019-07-10 22:27:54 +00001854echo "export PATH=$GOPATH/bin:\$PATH" | tee -a $LOG
Test User7d866122019-07-09 17:52:35 +00001855echo -en $NORMAL
Test User08ebbd92019-07-03 17:15:39 +00001856echo "" | tee -a $LOG
1857echo "Thank you for choosing kind-voltha for you quick cluster needs." | tee -a $LOG
1858
David Bainbridge712afb82019-08-14 19:55:58 +00001859if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridgef858a022019-08-14 21:25:11 +00001860 echo -e "$CLOCK ${BOLD}TOTAL: $(duration $(expr $(date +%s) - $TOTAL_START_TIME))${NORMAL}"
David Bainbridge712afb82019-08-14 19:55:58 +00001861fi