blob: 05fcd84094bec9a39fda9f7c5d5a15bbf3113b8e [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 Bainbridgee87067b2019-08-12 22:00:12 +000074WITH_TIMINGS=${WITH_TIMINGS:-no}
Test User7d866122019-07-09 17:52:35 +000075WITH_BBSIM=${WITH_BBSIM:-no}
David Bainbridge5b7b96b2019-07-25 20:29:13 +000076WITH_RADIUS=${WITH_RADIUS:-no}
Matteo Scandolo78dfee02020-02-13 16:18:03 -080077WITH_EAPOL=${WITH_EAPOL:-yes}
78WITH_DHCP=${WITH_DHCP:-yes}
79WITH_IGMP=${WITH_IGMP:-no}
David Bainbridgeb270c202019-07-26 01:44:42 +000080WITH_ONOS=${WITH_ONOS:-yes}
David Bainbridge99ac7a22019-08-31 02:26:43 +000081WITH_CHAOS=${WITH_CHAOS:-no}
David Bainbridge46505fb2019-10-01 21:13:20 +000082WITH_ADAPTERS=${WITH_ADAPTERS:-yes}
David K. Bainbridgeda33d652020-03-06 10:31:23 -080083WITH_SIM_ADAPTERS=${WITH_SIM_ADAPTERS:-no}
David Bainbridge46505fb2019-10-01 21:13:20 +000084WITH_OPEN_ADAPTERS=${WITH_OPEN_ADAPTERS:-yes}
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -080085WITH_PORT_FORWARDS=${WITH_PORT_FORWARDS:-yes}
David Bainbridge05cd8822019-11-19 17:43:53 +000086ONLY_ONE=${ONLY_ONE:-yes}
David K. Bainbridgeb859e912020-03-13 14:07:52 -070087CONFIG_SADIS=${CONFIG_SADIS:-no} # yes | no | file | bbsim | URL
88SADIS_SUBSCRIBERS=${SADIS_SUBSCRIBERS:-http://bbsim.voltha.svc:50074/v2/subscribers/%s}
89SADIS_BANDWIDTH_PROFILES=${SADIS_BANDWIDTH_PROFILES:-http://bbsim.voltha.svc:50074/v2/bandwidthprofiles/%s}
Hardik Windlassb3147602020-03-09 16:59:15 +053090SADIS_CFG=${SADIS_CFG:-onos-files/onos-sadis-sample.json}
David Bainbridge27790d62019-08-13 22:43:19 +000091INSTALL_ONOS_APPS=${INSTALL_ONOS_APPS:-no}
Test Userba1e7e72019-07-10 22:27:54 +000092JUST_K8S=${JUST_K8S:-no}
93DEPLOY_K8S=${DEPLOY_K8S:-yes}
David K. Bainbridge0e89cb92019-07-17 11:30:10 -070094INSTALL_KUBECTL=${INSTALL_KUBECTL:-yes}
95INSTALL_HELM=${INSTALL_HELM:-yes}
David Bainbridge46505fb2019-10-01 21:13:20 +000096UPDATE_HELM_REPOS=${UPDATE_HELM_REPOS:-yes}
Matteo Scandolofab98622020-01-28 15:17:20 -080097WAIT_ON_DOWN=${WAIT_ON_DOWN:-yes}
David Bainbridge52e6e9d2020-03-23 13:48:27 -070098WAIT_TIMEOUT=${WAIT_TIMEOUT:-30m}
99VOLTHA_DOWN_ON_TIMEOUT=${VOLTHA_DOWN_ON_TIMEOUT:-no}
David Bainbridge5b7b96b2019-07-25 20:29:13 +0000100VOLTHA_LOG_LEVEL=${VOLTHA_LOG_LEVEL:-WARN}
David Bainbridge90fd8e32019-08-21 23:32:47 +0000101VOLTHA_CHART=${VOLTHA_CHART:-onf/voltha}
102VOLTHA_CHART_VERSION=${VOLTHA_CHART_VERSION:-latest}
103VOLTHA_BBSIM_CHART=${VOLTHA_BBSIM_CHART:-onf/bbsim}
Matteo Scandolodcd29f52019-10-07 15:42:42 -0700104VOLTHA_BBSIM_CHART_VERSION=${VOLTHA_BBSIM_CHART_VERSION:-latest}
David Bainbridgee10f6d52019-07-25 00:28:13 +0000105VOLTHA_ADAPTER_SIM_CHART=${VOLTHA_ADAPTER_SIM_CHART:-onf/voltha-adapter-simulated}
David Bainbridge90fd8e32019-08-21 23:32:47 +0000106VOLTHA_ADAPTER_SIM_CHART_VERSION=${VOLTHA_ADAPTER_SIM_CHART_VERSION:-latest}
David Bainbridgee10f6d52019-07-25 00:28:13 +0000107VOLTHA_ADAPTER_OPEN_OLT_CHART=${VOLTHA_ADAPTER_OPEN_OLT_CHART:-onf/voltha-adapter-openolt}
David Bainbridge90fd8e32019-08-21 23:32:47 +0000108VOLTHA_ADAPTER_OPEN_OLT_CHART_VERSION=${VOLTHA_ADAPTER_OPEN_OLT_CHART_VERSION:-latest}
David Bainbridgee10f6d52019-07-25 00:28:13 +0000109VOLTHA_ADAPTER_OPEN_ONU_CHART=${VOLTHA_ADAPTER_OPEN_ONU_CHART:-onf/voltha-adapter-openonu}
David Bainbridge90fd8e32019-08-21 23:32:47 +0000110VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION=${VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION:-latest}
David K. Bainbridgeda33d652020-03-06 10:31:23 -0800111ONOS_CHART=${ONOS_CHART:-onf/onos}
Andrea Campanella21323292019-12-18 11:44:19 -0800112ONOS_CHART_VERSION=${ONOS_CHART_VERSION:-latest}
David Bainbridge2eaf2cf2020-03-18 12:54:08 -0700113EXTRA_HELM_INSTALL_ARGS=${EXTRA_HELM_INSTALL_ARGS:-}
114INTERNAL_EXTRA_HELM_INSTALL_ARGS=
uottrembb16d3982020-02-28 08:34:36 +0100115NUM_OF_BBSIM=${NUM_OF_BBSIM:-1}
116MAX_NUM_OF_BBSIM=10
Test Userba1e7e72019-07-10 22:27:54 +0000117
118HAVE_GO=$(which go >/dev/null 2>&1 && echo "yes" || echo "no")
119HOSTOS=$(uname -s | tr "[:upper:]" "[:lower:"])
120HOSTARCH=$(uname -m | tr "[:upper:]" "[:lower:"])
121if [ $HOSTARCH == "x86_64" ]; then
122 HOSTARCH="amd64"
123fi
Test User7d866122019-07-09 17:52:35 +0000124
uottrembb16d3982020-02-28 08:34:36 +0100125# check number (range) of bbsim, max bbsim must not exceed 10 instances!
126# note: instances will be numbered from 0 to 9
127if [ "$1" == "up" ]; then
David K. Bainbridge43422402020-03-06 07:41:22 -0800128 if [ "$NUM_OF_BBSIM" -lt 1 ]; then
129 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} Invalid setting of BBSIM instances. NUM_OF_BBSIM is less than 1${NORMAL}"
130 exit 1
131 fi
132 if [ "$NUM_OF_BBSIM" -gt $MAX_NUM_OF_BBSIM ]; then
133 >&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}"
134 exit 1
135 fi
uottrembb16d3982020-02-28 08:34:36 +0100136fi
Test User7d866122019-07-09 17:52:35 +0000137# Verify TYPE setting
138if [ $(echo ":minimal:full:" | grep -ic ":$TYPE:") -eq 0 ]; then
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700139 >&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 +0000140 exit 1
141fi
142
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700143function parseDuration() {
144 local DUR=$1
145 local RESULT=0
David Bainbridge6cdb6462020-03-25 10:24:38 -0700146 local TERMS=$(echo $DUR | sed -Ee 's/([sSmMhHdD])/\1 /g' -e 's/,$//g')
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700147 for TERM in $TERMS; do
David Bainbridge6cdb6462020-03-25 10:24:38 -0700148 local VALUE=$(echo $TERM | sed -Ee 's/([0-9]+)[sSmMhHdD]/\1/')
149 local UNIT=$(echo $TERM | sed -Ee 's/[0-9]+([sSmMhHdD])/\1/')
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700150 case $UNIT in
151 s|S)
152 RESULT=$(($RESULT + $VALUE)) ;;
153 m|M)
154 RESULT=$(($RESULT + ($VALUE * 60))) ;;
155 h|H)
156 RESULT=$(($RESULT + ($VALUE * 3600))) ;;
157 d|D)
158 RESULT=$(($RESULT + ($VALUE * 86400))) ;;
159 *) ;;
160 esac
161 done
162 echo $RESULT
163}
164
165function doTimeout() {
166 local MSG=$1
167 2>&1 echo -e "\n${RED}${BOLD}${ERROR}TIMEOUT:${NORMAL}${RED} Operation timed out after '$WAIT_TIMEOUT': $MSG"
168 exit 125
169}
170
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -0800171function get_service_ep() {
172 local NS=$1
173 local NAME=$2
174 kubectl -n $NS get service $NAME -o json | jq -r '.spec.clusterIP + ":" + (.spec.ports[0].port|tostring)'
175}
176
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000177# Used to verify configuration values are set to "yes" or "no" value or convert
178# equivalents to "yes" or "no"
179function verify_yes_no() {
180 local VAR=$1
181 local VAL=$(eval echo \$$VAR)
182 if [ $(echo ":y:yes:true:n:no:false:1:0:" | grep -ic ":$VAL:") -eq 0 ]; then
183 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} Invalid '$VAR' value of '$VAL'. Should be 'yes' or 'no'${NORMAL}"
184 echo "INVALID"
185 return 1
186 fi
187 if [ $(echo ":y:yes:true:1:" | grep -ic ":$VAL:") -eq 1 ]; then
188 echo "yes"
189 else
190 echo "no"
191 fi
192 return 0
193}
Test User7d866122019-07-09 17:52:35 +0000194
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000195ALL_YES_NO="\
David K. Bainbridge484d80c2020-03-05 21:44:34 -0800196 ENABLE_ONOS_EXTRANEOUS_RULES \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000197 WITH_TIMINGS \
198 WITH_BBSIM \
199 WITH_RADIUS \
Matteo Scandolo78dfee02020-02-13 16:18:03 -0800200 WITH_EAPOL \
201 WITH_DHCP \
202 WITH_IGMP \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000203 WITH_ONOS \
David Bainbridge99ac7a22019-08-31 02:26:43 +0000204 WITH_CHAOS \
David Bainbridge46505fb2019-10-01 21:13:20 +0000205 WITH_ADAPTERS \
206 WITH_SIM_ADAPTERS \
207 WITH_OPEN_ADAPTERS \
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -0800208 WITH_PORT_FORWARDS \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000209 JUST_K8S \
210 DEPLOY_K8S \
211 INSTALL_ONOS_APPS \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000212 INSTALL_KUBECTL \
213 INSTALL_HELM \
David Bainbridge46505fb2019-10-01 21:13:20 +0000214 UPDATE_HELM_REPOS \
David Bainbridge4f1b5562019-08-19 04:46:52 +0000215 WAIT_ON_DOWN \
David Bainbridge70c0ea82019-11-14 23:25:26 +0000216 ONLY_ONE \
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700217 VOLTHA_DOWN_ON_TIMEOUT \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000218 "
David Bainbridge5b7b96b2019-07-25 20:29:13 +0000219
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000220ALL_OPTIONS="\
221 NAME \
222 TYPE \
223 $ALL_YES_NO \
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700224 WAIT_TIMEOUT \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000225 VOLTHA_LOG_LEVEL \
226 VOLTHA_CHART \
David Bainbridge90fd8e32019-08-21 23:32:47 +0000227 VOLTHA_CHART_VERSION \
228 VOLTHA_BBSIM_CHART \
229 VOLTHA_BBSIM_CHART_VERSION \
uottrembd5a20572020-03-06 09:15:01 +0100230 NUM_OF_BBSIM \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000231 VOLTHA_ADAPTER_SIM_CHART \
David Bainbridge90fd8e32019-08-21 23:32:47 +0000232 VOLTHA_ADAPTER_SIM_CHART_VERSION \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000233 VOLTHA_ADAPTER_OPEN_OLT_CHART \
David Bainbridge90fd8e32019-08-21 23:32:47 +0000234 VOLTHA_ADAPTER_OPEN_OLT_CHART_VERSION \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000235 VOLTHA_ADAPTER_OPEN_ONU_CHART \
David Bainbridge90fd8e32019-08-21 23:32:47 +0000236 VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION \
David K. Bainbridgeda33d652020-03-06 10:31:23 -0800237 ONOS_CHART \
Andrea Campanella21323292019-12-18 11:44:19 -0800238 ONOS_CHART_VERSION \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000239 ONOS_API_PORT \
240 ONOS_SSH_PORT \
David K. Bainbridgeb859e912020-03-13 14:07:52 -0700241 CONFIG_SADIS \
Hardik Windlassb3147602020-03-09 16:59:15 +0530242 SADIS_CFG \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000243 VOLTHA_API_PORT \
244 VOLTHA_SSH_PORT \
245 VOLTHA_ETCD_PORT \
David K. Bainbridge00ecd382020-02-28 12:31:58 -0800246 VOLTHA_KAFKA_PORT \
David K. Bainbridge8f7f30b2020-01-08 13:06:16 -0800247 VK_RELEASE \
248 KIND_VERSION \
249 VOLTCTL_VERSION \
David Bainbridgea34993d2020-04-01 09:15:42 -0700250 HELM_VERSION \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000251 "
David Bainbridge01294952019-07-30 19:33:45 +0000252
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000253# Iterate over yes/no configuration options and validate
254for VAR in $ALL_YES_NO; do
255 eval $VAR=$(verify_yes_no $VAR)
256 if [ "$(eval echo \$$VAR)" == "INVALID" ]; then
257 exit 1;
258 fi
259done
David Bainbridgeb270c202019-07-26 01:44:42 +0000260
David Bainbridge15f6f232020-03-30 09:15:43 -0700261# Special case for CONFIG_SADIS
262if [ $(echo ":y:yes:true:1:" | grep -ic ":$CONFIG_SADIS:") -eq 1 ]; then
263 CONFIG_SADIS="yes"
264fi
265if [ $(echo ":n:no:false:0:" | grep -ic ":$CONFIG_SADIS:") -eq 1 ]; then
266 CONFIG_SADIS="no"
267fi
268
David K. Bainbridgeda33d652020-03-06 10:31:23 -0800269# Check for prerequiste tools
David K. Bainbridge726ff6a2020-03-06 11:09:50 -0800270TOOLS="curl sed jq"
David K. Bainbridgeda33d652020-03-06 10:31:23 -0800271if [ $DEPLOY_K8S == "yes" ]; then
272 TOOLS+=" docker"
273fi
274NOT_FOUND=""
275for T in $TOOLS; do
276 if [ -z "$(which $T)" ]; then
277 NOT_FOUND+=" $T"
278 fi
279done
280
281if [ ! -z "$NOT_FOUND" ]; then
282 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} The following required tools where not found, please install them:$NOT_FOUND"
283 exit 1
284fi
285
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700286TIMEOUT_SECONDS=$(parseDuration $WAIT_TIMEOUT)
287
David Bainbridge0774b232019-08-02 06:37:19 +0000288mkdir -p .voltha
289touch .voltha/ports
290HAVE=$(grep $NAME .voltha/ports)
291if [ "$HAVE X" == " X" ]; then
292 # Find free port prefix
293 START=81
294 while true; do
295 if [ $(grep -c $START .voltha/ports) -eq 0 ]; then
296 break
297 fi
298 START=$(expr $START + 1)
299 done
300 DELTA=$(expr $START - 81)
David Bainbridgea2595422019-10-22 03:54:28 +0000301 ONOS_API_PORT=${ONOS_API_PORT:-${START}81}
302 ONOS_SSH_PORT=${ONOS_SSH_PORT:-${START}01}
303 VOLTHA_API_PORT=${VOLTHA_API_PORT:-5$(expr 55 + $DELTA)55}
304 VOLTHA_SSH_PORT=${VOLTHA_SSH_PORT:-$(expr 50 + $DELTA)22}
305 VOLTHA_ETCD_PORT=${VOLTHA_ETCD_PORT:-$(expr 23 + $DELTA)79}
David K. Bainbridge00ecd382020-02-28 12:31:58 -0800306 VOLTHA_KAFKA_PORT=${VOLTHA_KAFKA_PORT:-$(expr 90 + $DELTA)92}
Test User01ed0642019-07-03 20:17:06 +0000307else
David Bainbridge0774b232019-08-02 06:37:19 +0000308 VALUES=$(echo $HAVE | sed -e 's/\s//g' | cut -d= -f2)
David Bainbridgea2595422019-10-22 03:54:28 +0000309 ONOS_API_PORT=${ONOS_API_PORT:-$(echo $VALUES | cut -d, -f1)}
310 ONOS_SSH_PORT=${ONOS_SSH_PORT:-$(echo $VALUES | cut -d, -f2)}
311 VOLTHA_API_PORT=${VOLTHA_API_PORT:-$(echo $VALUES | cut -d, -f3)}
312 VOLTHA_SSH_PORT=${VOLTHA_SSH_PORT:-$(echo $VALUES | cut -d, -f4)}
313 VOLTHA_ETCD_PORT=${VOLTHA_ETCD_PORT:-$(echo $VALUES | cut -d, -f5)}
David K. Bainbridge00ecd382020-02-28 12:31:58 -0800314 VOLTHA_KAFKA_PORT=${VOLTHA_KAFKA_PORT:-$(echo $VALUES | cut -d, -f6)}
315
David K. Bainbridge00ecd382020-02-28 12:31:58 -0800316 # A bit of a hueristic required here as the KAFKA port forward was
317 # added after the .voltha/ports files was created. Basically, if
318 # the VOLTHA_KAFKA_PORT isn't in the file then calculate the original
319 # DELTA from the VOLTHA_SSH_PORT and apply it to the VOLTHA_KAFKA_PORT
320 if [ -z "$VOLTHA_KAFKA_PORT" ]; then
321 DELTA=$((VOLTHA_SSH_PORT/100-50))
322 VOLTHA_KAFKA_PORT=${VOLTHA_KAFKA_PORT:-$(expr 90 + $DELTA)92}
323 fi
Test User01ed0642019-07-03 20:17:06 +0000324fi
325
David Bainbridge0774b232019-08-02 06:37:19 +0000326PORTTMP=$(mktemp -u)
327cat .voltha/ports | grep -v $NAME > $PORTTMP
David K. Bainbridge00ecd382020-02-28 12:31:58 -0800328echo "$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 +0000329cp $PORTTMP .voltha/ports
330rm -f $PORTTMP
331
David Bainbridge27790d62019-08-13 22:43:19 +0000332export ONOS_API_PORT ONOS_SSH_PORT
David Bainbridge01294952019-07-30 19:33:45 +0000333
Test Userd87942b2019-07-03 07:20:24 +0000334IDX=1
David Bainbridgee87067b2019-08-12 22:00:12 +0000335CLOCK="TIME:"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000336SPIN_PARTS=
337NOT_VERIFIED=
David Bainbridgef858a022019-08-14 21:25:11 +0000338THEX=
339BUILD=
340CROSS=
341ENTER=
David Bainbridge38dc1e82019-08-12 15:18:45 +0000342VERIFIED=
343HELM=
344OLD_KEY=
345BIRD=
346HIGH_VOLTAGE=
347PLUG=
348RESTART=
349FORWARD=
350INSTALL=
351STOP=
352GO=
353DOWNLOAD=
354GEAR=
355NO_ENTRY=
356LOCK=
357
358if [ $FANCY -eq 1 ]; then
359 SPIN_PARTS="\
360 \xe2\xa2\x8e\xe2\xa1\xb0 \
361 \xe2\xa2\x8e\xe2\xa1\xa1 \
362 \xe2\xa2\x8e\xe2\xa1\x91 \
363 \xe2\xa2\x8e\xe2\xa0\xb1 \
364 \xe2\xa0\x8e\xe2\xa1\xb1 \
365 \xe2\xa2\x8a\xe2\xa1\xb1 \
366 \xe2\xa2\x8c\xe2\xa1\xb1 \
367 \xe2\xa2\x86\xe2\xa1\xb1 \
368 "
David Bainbridgee87067b2019-08-12 22:00:12 +0000369 CLOCK="\xe2\x8f\xb1"
David Bainbridgef858a022019-08-14 21:25:11 +0000370 THEX="${RED}${BOLD}\xe2\x9c\x97\x20${NORMAL}"
371 ENTER="${YELLOW}${BOLD}\xe2\x8e\x86${NORMAL}"
372 CROSS="${YELLOW}${BOLD}\xe2\x9c\x9a${NORMAL}"
373 BUILD="${YELLOW}${BOLD}\xf0\x9f\x8f\x97${NORMAL}"
374 NOT_VERIFIED="$BUILD"
375 VERIFIED="${GREEN}${BOLD}\xe2\x9c\x93\x20${NORMAL}"
376 HELM="${BLUE}${BOLD}\xE2\x8E\x88${NORMAL}"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000377 OLD_KEY="\xF0\x9F\x97\x9D"
378 BIRD="\xF0\x9F\x90\xA6"
379 HIGH_VOLTAGE="\xE2\x9A\xA1"
380 PLUG="\xF0\x9F\xa7\xa9"
381 RESTART="\xf0\x9f\x94\x84"
382 FORWARD="\xE2\x87\xA8"
383 INSTALL="\xF0\x9F\x8F\x97"
384 STOP="\xf0\x9f\x9b\x91"
385 GO="\xf0\x9f\x9a\x80"
386 DOWNLOAD="\xf0\x9f\x93\xa5"
387 GEAR="\xe2\x9a\x99"
388 NO_ENTRY="\xe2\x9b\x94"
389 LOCK="\xf0\x9f\x94\x92"
390fi
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700391
David Bainbridge712afb82019-08-14 19:55:58 +0000392duration() {
David Bainbridgee87067b2019-08-12 22:00:12 +0000393 local h=$(expr $1 / 3600)
394 local m=$(expr $1 % 3600 / 60)
395 local s=$(expr $1 % 60)
396 local t=""
397
398 if [ $h -gt 0 ]; then
399 t="$t${h}h"
400 fi
401 if [ $m -gt 0 ]; then
402 t="$t${m}m"
403 fi
David Bainbridge712afb82019-08-14 19:55:58 +0000404 echo "$t${s}s"
405}
406
407printtime() {
408 local INDENT=
409 if [ "$1" == "-" ]; then
410 INDENT=" "
411 shift
412 fi
413 echo -e "$INDENT $CLOCK $(duration $1)"
David Bainbridgee87067b2019-08-12 22:00:12 +0000414}
415
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700416bspin() {
Test Userd87942b2019-07-03 07:20:24 +0000417 IDX=1
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700418 local INDENT=
419 if [ "$1" == "-" ]; then
420 INDENT=" "
421 shift
422 fi
David Bainbridge38dc1e82019-08-12 15:18:45 +0000423 if [ $FANCY -eq 0 ]; then
424 LINE=$(echo $* | sed -e 's/[\s+-]//g')
425 if [ "$LINE X" == " X" ]; then
426 return
427 fi
428 echo -e "$CIVIS$INDENT$*"
429 else
430 echo -en "$CIVIS$INDENT $*"
431 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700432}
433
434sspin() {
435 local INDENT=
436 if [ "$1" == "-" ]; then
437 INDENT=" "
438 shift
439 fi
David Bainbridge38dc1e82019-08-12 15:18:45 +0000440 if [ $FANCY -eq 0 ]; then
441 LINE=$(echo $* | sed -e 's/[\s+-]//g')
442 if [ "$LINE X" == " X" ]; then
443 return
444 fi
445 echo -e "$INDENT$*"
446 else
447 C=$(echo $SPIN_PARTS | cut '-d ' -f $IDX)
448 echo -en "\r$INDENT$C $*"
449 IDX=$(expr $IDX + 1)
450 if [ $IDX -gt 8 ]; then
451 IDX=1
452 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700453 fi
454}
455
456espin() {
457 local INDENT=
458 if [ "$1" == "-" ]; then
459 INDENT=" "
460 shift
461 fi
David Bainbridge38dc1e82019-08-12 15:18:45 +0000462 if [ $FANCY -eq 0 ]; then
463 LINE=$(echo $* | sed -e 's/[\s+-]//g')
464 if [ "$LINE X" == " X" ]; then
465 return
466 fi
467 echo -e "$INDENT$*"
468 else
469 echo -e "\r$INDENT$*$CNORM"
470 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700471}
472
David Bainbridgeac7f8072019-08-01 22:15:33 +0000473if [ "$1" == "get" -a "$2" == "voltconfig" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000474 echo "$HOME/.volt/config-$NAME"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000475 exit
476fi
477
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -0700478if [ $# -ne 1 -o $(echo ":up:down:dump:" | grep -c ":$1:") -ne 1 ]; then
David Bainbridgeac7f8072019-08-01 22:15:33 +0000479 >&2 echo "What wouild you like to do today:"
480 >&2 echo " up - bring up voltha"
481 >&2 echo " down - tear down voltha"
482 >&2 echo " dump - create a debug dump of running system"
483 exit 1
484fi
485
David Bainbridge4f1b5562019-08-19 04:46:52 +0000486push_onos_config() {
Matteo Scandolo78dfee02020-02-13 16:18:03 -0800487 local TYPE=$1
488 local MSG=$2
489 local RESOURCE=$3
490 local DATA=$4
David Bainbridge4f1b5562019-08-19 04:46:52 +0000491
David K. Bainbridgeb4b163b2020-02-19 15:55:06 -0800492 # Thanks to the latest version of ONOS using the return code 207 this gets a
493 # whole lot nastier. Can't thank them enough for doing this. So in order to
494 # capture the command and the output in the log file as well as capture the
495 # status code to verify it is 200 and not 207 mutltiple files and a bit of
496 # hackery must be used. Thanks again ONOS.
497 local CMD_ECHO=$(mktemp -u)
498 local CMD_OUTPUT=$(mktemp -u)
499 local SC_OUTPUT=$(mktemp -u)
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700500 local WAIT_START=$(date +%s)
David K. Bainbridgeb4b163b2020-02-19 15:55:06 -0800501
David Bainbridge4f1b5562019-08-19 04:46:52 +0000502 bspin - "$MSG $GEAR"
503 while true; do
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700504 if [ $(($(date +%s) - $WAIT_START)) -gt $TIMEOUT_SECONDS ]; then
505 espin - "$THEX"
David Bainbridge1cecba52020-03-30 09:43:10 -0700506 rm -f $CMD_ECHO $CMD_OUTPUT $SC_OUTPUT
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700507 doTimeout "waiting for ONOS config push on $RESOURCE"
508 fi
Matteo Scandolo78dfee02020-02-13 16:18:03 -0800509 if [ $TYPE == "file" ]; then
David K. Bainbridgeb859e912020-03-13 14:07:52 -0700510 (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
511 RESULT=$?
Matteo Scandolo78dfee02020-02-13 16:18:03 -0800512 fi
513 if [ $TYPE == "json" ]; then
David K. Bainbridgeb859e912020-03-13 14:07:52 -0700514 (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
515 RESULT=$?
Matteo Scandolo78dfee02020-02-13 16:18:03 -0800516 fi
David K. Bainbridgeb4b163b2020-02-19 15:55:06 -0800517 # Dump everything to the log
518 cat $CMD_ECHO >> $LOG
David K. Bainbridgeb859e912020-03-13 14:07:52 -0700519 test -r $CMD_OUTPUT && cat $CMD_OUTPUT >> $LOG
David K. Bainbridgeb4b163b2020-02-19 15:55:06 -0800520 SC=$(cat $SC_OUTPUT)
David K. Bainbridgeb859e912020-03-13 14:07:52 -0700521 echo "RESPONSE CODE: $SC" >> $LOG
522 echo "ERROR CODE: $RESULT" >> $LOG
David K. Bainbridgeb4b163b2020-02-19 15:55:06 -0800523
524 # clean up temp files
525 rm -f $CMD_ECHO $CMD_OUTPUT $SC_OUTPUT
526 if [ $RESULT -eq 0 -a "$SC" == "200" ]; then
David Bainbridge4f1b5562019-08-19 04:46:52 +0000527 break
528 fi
Matteo Scandolo9a77a732020-01-09 14:24:12 -0800529 sleep 1
David Bainbridge4f1b5562019-08-19 04:46:52 +0000530 sspin -
531 done
532 espin - $VERIFIED
533}
534
Matteo Scandolo9a77a732020-01-09 14:24:12 -0800535check_onos_app_active() {
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700536 local APP_ID=$1
537 local WAIT_START=$(date +%s)
Matteo Scandolo9a77a732020-01-09 14:24:12 -0800538
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700539 bspin - "Checking that $APP_ID is active $CLOCK"
540 while true; do
541 if [ $(($(date +%s) - $WAIT_START)) -gt $TIMEOUT_SECONDS ]; then
542 espin - "$THEX"
543 doTimeout "waiting for ONOS application activation '$APP_ID'"
544 fi
545 (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
546 if [ $? -eq 0 ]; then
547 break
548 fi
549 sleep 1
550 sspin -
551 done
552 sleep 5 # OSGI components take a little longer that the app to activate
553 espin - $VERIFIED
Matteo Scandolo9a77a732020-01-09 14:24:12 -0800554}
555
David Bainbridge4f1b5562019-08-19 04:46:52 +0000556override_onos_app() {
557 local APP=$1
558 local NAME=$(basename $APP | sed -e 's/^[0-9][0-9]*-//g' -e 's/-.*$//g')
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700559 local WAIT_START=$(date +%s)
560
David Bainbridge4f1b5562019-08-19 04:46:52 +0000561 while true; do
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700562 if [ $(($(date +%s) - $WAIT_START)) -gt $TIMEOUT_SECONDS ]; then
563 espin - "$THEX"
564 doTimeout "waiting to overwrite ONOS application '$APP'"
565 fi
David Bainbridge4f1b5562019-08-19 04:46:52 +0000566 sspin -
567 # Attempt to delete old version (if it exists)
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -0800568 (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 +0000569 sspin -
570 if [ $? -ne 0 ]; then
571 continue
572 fi
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -0800573 (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 +0000574 if [ $? -eq 0 ]; then
575 break
576 fi
577 sleep .2
578 done
579}
580
581activate_onos_app() {
582 local MSG="$1"
583 local APP=$2
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700584 local WAIT_START=$(date +%s)
David Bainbridge4f1b5562019-08-19 04:46:52 +0000585
586 bspin - "$MSG $GO"
587 while true; do
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700588 if [ $(($(date +%s) - $WAIT_START)) -gt $TIMEOUT_SECONDS ]; then
589 espin - "$THEX"
590 doTimeout "waiting to activate ONOS application '$APP'"
591 fi
David Bainbridge4f1b5562019-08-19 04:46:52 +0000592 sspin -
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -0800593 (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 +0000594 if [ $? -eq 0 ]; then
595 break
596 fi
597 sleep .2
598 done
599 espin - "$VERIFIED"
600}
601
602count_pods() {
603 local NAMESPACE=$1; shift
604 if [ "$NAMESPACE" == "all-namespaces" ]; then
605 NAMESPACE="--all-namespaces"
606 else
607 NAMESPACE="-n $NAMESPACE"
608 fi
David Bainbridge4f1b5562019-08-19 04:46:52 +0000609 local STATES=$1; shift
David Bainbridge4f1b5562019-08-19 04:46:52 +0000610 local PODS=$(kubectl get $NAMESPACE pod -o go-template="{{range .items}}{{.metadata.name}}/{{.status.phase}}/_{{range .status.containerStatuses}}{{.ready}}_{{end}} {{end}}")
611 local COUNT=0
612 local PATTERNS="$*"
613 for POD in $PODS; do
614 local NAME=$(echo $POD | cut -d/ -f 1)
615 local STATE=$(echo $POD | cut -d/ -f 2)
616 local CONTAINERS=$(echo $POD | cut -d/ -f 3 | sed -e 's/_/ /g')
617 if [ "$STATES" == "*" -o $(echo "$STATES" | grep -c ":$STATE:") -ne 0 ]; then
David Bainbridge4f1b5562019-08-19 04:46:52 +0000618 local TOTAL=$(echo $CONTAINERS | wc -w)
619 local FOUND=$(echo $CONTAINERS | grep -o true | wc -l)
620 if [ $TOTAL -eq $FOUND ]; then
621 for PATTERN in $PATTERNS; do
David Bainbridge4f1b5562019-08-19 04:46:52 +0000622 if [[ $NAME =~ $PATTERN ]]; then
David Bainbridge4f1b5562019-08-19 04:46:52 +0000623 COUNT=$(expr $COUNT + 1)
624 break
625 fi
626 done
627 fi
628 fi
629 done
David Bainbridge4f1b5562019-08-19 04:46:52 +0000630 echo $COUNT
631}
632
633wait_for_pods() {
634 local INDENT=
635 if [ "$1" == "-" ]; then
636 INDENT=$1; shift
637 fi
638 local NAMESPACE=$1; shift
639 local EXPECT=$1; shift
640 local TYPE=$1; shift
641 local RETRY=$1; shift
642 local MESSAGE=$1; shift
643 local PATTERNS=$*
David Bainbridge99ac7a22019-08-31 02:26:43 +0000644 local STATES=":Running:"
645 if [ "$TYPE" == "not" ]; then
646 STATES="*"
647 fi
648 local HAVE=$(count_pods $NAMESPACE "$STATES" $PATTERNS)
David Bainbridge4f1b5562019-08-19 04:46:52 +0000649 local ALL=$HAVE
650 if [ "$TYPE" == "only" ]; then
651 ALL=$(count_pods "all-namespaces" "*" ".*")
652 fi
653 COUNT=$(expr 300 / 15)
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700654 local WAIT_START=$(date +%s)
David Bainbridge4f1b5562019-08-19 04:46:52 +0000655 bspin $INDENT $MESSAGE
656 sspin $INDENT
657 if [ $HAVE -ne $EXPECT -o $ALL -ne $HAVE ]; then
658 while [ $HAVE -ne $EXPECT -o $ALL -ne $HAVE ]; do
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700659 if [ $(($(date +%s) - $WAIT_START)) -gt $TIMEOUT_SECONDS ]; then
660 espin $INDENT "$THEX"
661 doTimeout "waiting for PODs to start"
662 fi
David Bainbridge4f1b5562019-08-19 04:46:52 +0000663 sspin $INDENT
664 COUNT=$(expr $COUNT - 1)
665 if [ $COUNT -eq 0 ]; then
David Bainbridge99ac7a22019-08-31 02:26:43 +0000666 HAVE=$(count_pods $NAMESPACE "$STATES" $PATTERNS)
David Bainbridge4f1b5562019-08-19 04:46:52 +0000667 ALL=$HAVE
668 if [ "$TYPE" == "only" ]; then
669 ALL=$(count_pods "all-namespaces" "*" ".*")
670 fi
671 COUNT=$(expr 300 / 15)
672 fi
673 sleep .15
674 done
675 fi
676 espin $INDENT $VERIFIED
677 if [ $HAVE -ne $EXPECT ]; then
678 return 1
679 fi
680 return 0
681}
682
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800683port_forward() {
684 local NS=$1
685 local SVC=$2
686 local FROM_PORT=$3
687 local TO_PORT=$4
688 local TAG=$SVC-$NAME
689
690 (set -x; _TAG=$TAG bash -c "while true; do kubectl port-forward -n $NS service/$SVC $FROM_PORT:$TO_PORT; done" >>$LOG 2>&1 &) >>$LOG 2>&1
691}
692
693kill_port_forward() {
694 local TAG=$1-$NAME
David Bainbridgec6871d22019-11-13 17:10:31 +0000695 local P_IDS=$(ps e -ww -A | grep "_TAG=$TAG" | grep -v grep | awk '{print $1}')
David Bainbridgebcf235b2019-11-12 21:33:58 +0000696 local PARENTS=
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800697 local KIDS=
David Bainbridgec6871d22019-11-13 17:10:31 +0000698 local UNKNOWN=
699 if [ ! -z "$P_IDS" ]; then
700 for P_ID in $P_IDS; do
701 local PP_ID=$(ps -o ppid $P_ID | tail -n +2)
702 if [ ! -z "$PP_ID" ]; then
703 if [ $PP_ID -eq 1 ]; then
704 PARENTS="$PARENTS $P_ID"
705 else
706 KIDS="$KIDS $P_ID"
707 fi
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800708 else
David Bainbridgec6871d22019-11-13 17:10:31 +0000709 UNKNOWN="$UNKNOWN $P_ID"
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800710 fi
711 done
David Bainbridgec6871d22019-11-13 17:10:31 +0000712 (set -x; kill -9 $PARENTS $KIDS $UNKNOWN >>$LOG 2>&1) >>$LOG 2>&1
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800713 fi
714}
715
David Bainbridgeac7f8072019-08-01 22:15:33 +0000716if [ "$1" == "down" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000717 echo "Tearing down voltha cluster $NAME"
718 LOG="down-$NAME.log"
719 echo $(date -u +"%Y%m%dT%H%M%SZ") >$LOG
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800720 bspin "Remove port-forwards: onos-ui-$NAME"
721 kill_port_forward onos-ui
722 sspin "Remove port-forwards: onos-ssh-$NAME$CEOL"
723 kill_port_forward onos-ssh
724 sspin "Remove port-forwards: voltha-api-$NAME$CEOL"
725 kill_port_forward voltha-api
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800726 sspin "Remove port-forwards: voltha-etcd-$NAME$CEOL"
727 kill_port_forward voltha-etcd-cluster-client
David K. Bainbridge00ecd382020-02-28 12:31:58 -0800728 sspin "Remove port-forwards: voltha-kafka-$NAME$CEOL"
729 kill_port_forward voltha-kafka
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800730 espin "$VERIFIED Remove port-forwards$CEOL"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000731 if [ $DEPLOY_K8S == "yes" ]; then
732 if [ -x ./bin/kind ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000733 bspin "Delete Kubernetes Kind Cluster"
734 (set -x; ./bin/kind delete cluster --name voltha-$NAME >>$LOG 2>&1) >>$LOG 2>&1
735 espin $VERIFIED
David Bainbridgeac7f8072019-08-01 22:15:33 +0000736 else
David Bainbridge0774b232019-08-02 06:37:19 +0000737 espin "$NO_ENTRY Delete Kubernetes Kind Cluster: kind command not found"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000738 fi
739 else
740 EXISTS=$(helm list -q)
741 EXPECT="etcd-operator onos open-olt open-onu sim voltha bbsim radius"
David Bainbridge0774b232019-08-02 06:37:19 +0000742 bspin "Remove Helm Deployments"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000743 for i in $EXISTS; do
David K. Bainbridge43422402020-03-06 07:41:22 -0800744 for j in $EXPECT; do
745 if [[ $i =~ $j ]]; then
746 sspin "Remove Helm Deployments: $i$CEOL"
747 (set -x; ./bin/helm delete --no-hooks --purge $i >>$LOG 2>&1) >>$LOG 2>&1
748 fi
749 done
uottrembb16d3982020-02-28 08:34:36 +0100750 done
David Bainbridge0774b232019-08-02 06:37:19 +0000751 espin "$VERIFIED Remove Helm Deployments$CEOL"
David Bainbridge4f1b5562019-08-19 04:46:52 +0000752 if [ "$WAIT_ON_DOWN" == "yes" ]; then
753 # There should only be 13 or 15 PODs in the kube-system name
754 # space and no other PODs
David Bainbridge4f1b5562019-08-19 04:46:52 +0000755 PODS="coredns-.* \
756 etcd-voltha-$NAME-control-plane \
757 kindnet-.* \
758 kube-apiserver-voltha-$NAME-control-plane \
759 kube-controller-manager-voltha-$NAME-control-plane \
760 kube-proxy-.* \
761 kube-scheduler-voltha-$NAME-control-plane \
762 tiller-deploy-.*"
763 EXPECT=$(test "$TYPE" == "minimal" && echo "13" || echo "15")
David Bainbridge99ac7a22019-08-31 02:26:43 +0000764 PODS="adapter-.* \
765 bbsim.* \
766 etcd-operator.* \
767 radius.* \
768 voltha-.*"
Matteo Scandolo73442f92020-01-29 09:53:22 -0800769
David Bainbridge99ac7a22019-08-31 02:26:43 +0000770 EXPECT=0
771
Matteo Scandolo73442f92020-01-29 09:53:22 -0800772 if [ "$WITH_ONOS" == "yes" ]; then
773 ONOS_PODS="onos-.*"
774 wait_for_pods "default" $EXPECT "not" -1 "Waiting for ONOS PODs to terminate" $ONOS_PODS
775 fi
David Bainbridge99ac7a22019-08-31 02:26:43 +0000776 wait_for_pods "voltha" $EXPECT "not" -1 "Waiting for VOLTHA PODs to terminate" $PODS
David Bainbridge4f1b5562019-08-19 04:46:52 +0000777 fi
David Bainbridgeac7f8072019-08-01 22:15:33 +0000778 fi
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -0700779 exit
David Bainbridgeac7f8072019-08-01 22:15:33 +0000780fi
781
782if [ "$1" == "dump" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000783 LOG="dump-$NAME.log"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000784 TS=$(date -u +"%Y%m%dT%H%M%SZ")
David Bainbridge76514a02019-10-08 01:50:35 +0000785 if [ ! -z "$DUMP_FROM" ]; then
786 TS=$(echo $DUMP_FROM | sed -e 's/[:-]//g')
787 fi
David Bainbridgeac7f8072019-08-01 22:15:33 +0000788 WORK=$(mktemp -u -d)
David Bainbridge0774b232019-08-02 06:37:19 +0000789 DATA=$WORK/voltha-debug-dump-$NAME-$TS
David Bainbridgeac7f8072019-08-01 22:15:33 +0000790 mkdir -p $DATA
791 echo $TS > $LOG
David Bainbridge0774b232019-08-02 06:37:19 +0000792 echo -e "Capturing debug dump to voltha-debug-dump-$NAME-$TS.tgz"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000793 bspin - "Copy install log"
David Bainbridge0774b232019-08-02 06:37:19 +0000794 if [ -f install-$NAME.log ]; then
795 (set -x; cp install-$NAME.log $DATA/install-$NAME.log) >>$LOG 2>&1
David Bainbridgeac7f8072019-08-01 22:15:33 +0000796 espin - $VERIFIED
797 else
David Bainbridge0774b232019-08-02 06:37:19 +0000798 espin - "$NO_ENTRY Copy install log: install-$NAME.log not found"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000799 fi
800 bspin - "Dumping Kubernetes PODs"
801 (set -x; kubectl get --all-namespaces pods >> $DATA/all-pods.txt 2>&1) >>$LOG 2>&1
802 espin - $VERIFIED
803 bspin - "Dumping Kubernetes SERVICEs"
804 (set -x; kubectl get --all-namespaces svc >> $DATA/all-services.txt 2>&1) >>$LOG 2>&1
805 espin - $VERIFIED
806 bspin - "Dumping Kubernetes EVENTs"
807 (set -x; kubectl get --all-namespaces events >> $DATA/all-events.txt 2>&1) >>$LOG 2>&1
808 espin - $VERIFIED
809 bspin - "Dumping VOLTHA POD details"
Matteo Scandolodcd29f52019-10-07 15:42:42 -0700810 PODS="$(kubectl -n default get pod -o name | grep onos | sed -e 's/^/default:/g') $(kubectl get -n voltha pod -o name | sed -e 's/^/voltha:/g')"
David Bainbridgecfd7ca12019-10-06 03:31:41 +0000811 SINCE=
812 if [ ! -z "$DUMP_FROM" ]; then
813 SINCE="--since-time=$DUMP_FROM"
814 fi
David Bainbridgeac7f8072019-08-01 22:15:33 +0000815 for POD in $PODS; do
David Bainbridge1f0655a2019-10-01 22:08:48 +0000816 NS=$(echo $POD | cut -d: -f1)
817 POD=$(echo $POD | cut -d: -f2)
David Bainbridgeac7f8072019-08-01 22:15:33 +0000818 sspin - "Dumping VOLTHA POD details: $POD$CEOL"
819 mkdir -p $DATA/$POD
David Bainbridge1f0655a2019-10-01 22:08:48 +0000820 (set -x; kubectl describe -n $NS $POD >> $DATA/$POD/describe.txt 2>&1) >>$LOG 2>&1
David Bainbridgeac7f8072019-08-01 22:15:33 +0000821 sspin - "Dumping VOLTHA POD details: $POD"
David Bainbridgecfd7ca12019-10-06 03:31:41 +0000822 (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 +0000823 sspin - "Dumping VOLTHA POD details: $POD"
David Bainbridgecfd7ca12019-10-06 03:31:41 +0000824 (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 +0000825 sspin - "Dumping VOLTHA POD details: $POD"
826 done
827 espin - "$VERIFIED Dumping VOLTHA POD details$CEOL"
828 bspin - "Dumping ETCD"
829 if [ "$(which etcdctl) X" != " X" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000830 (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 +0000831 espin - $VERIFIED
832 else
833 espin - "$NO_ENTRY Dumping ETCD: etcdctl command not available"
834 fi
David Bainbridge0774b232019-08-02 06:37:19 +0000835 bspin - "Creating compressed TAR: voltha-debug-dump-$NAME-$TS.tgz"
836 (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 +0000837 espin - $VERIFIED
838 bspin - "Cleanup"
839 (set -x; rm -rf $WORK) >>$LOG 2>&1
840 espin - $VERIFIED
David Bainbridge0774b232019-08-02 06:37:19 +0000841 bspin - "$(ls -l voltha-debug-dump-$NAME-$TS.tgz)"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000842 espin - $VERIFIED
843 exit
844fi
845
David Bainbridge0774b232019-08-02 06:37:19 +0000846LOG="install-$NAME.log"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000847date > $LOG
David Bainbridge0774b232019-08-02 06:37:19 +0000848echo "PORTS=$ONOS_API_PORT,$ONOS_SSH_PORT,$VOLTHA_API_PORT,$VOLTHA_SSH_PORT,$VOLTHA_ETCD_PORT" >> $LOG
David Bainbridgeac7f8072019-08-01 22:15:33 +0000849
850# Output install options to log
851echo "OPTIONS" >> $LOG
David Bainbridgeac7f8072019-08-01 22:15:33 +0000852for O in $ALL_OPTIONS; do
853 VAL=$(eval echo \$$O)
David Bainbridgeac7f8072019-08-01 22:15:33 +0000854 if [ ! -z "$VAL" ]; then
855 printf " %-30s = %s\n" $O $VAL >> $LOG
856 fi
857done
858
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -0700859helm_install() {
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700860 local INDENT=
861 if [ "$1" == "-" ]; then
862 INDENT=$1; shift
863 fi
864 local NAMESPACE=$1; shift
David Bainbridge0774b232019-08-02 06:37:19 +0000865 local INAME=$1; shift
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700866 local CHART=$1; shift
David Bainbridge90fd8e32019-08-21 23:32:47 +0000867 local CHART_VERSION=$1; shift
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700868 local MESSAGE=$*
869
David Bainbridge90fd8e32019-08-21 23:32:47 +0000870 if [ "$CHART_VERSION X" != " X" -a "$CHART_VERSION" != "latest" ]; then
871 CHART_VERSION="--version $CHART_VERSION"
872 else
873 CHART_VERSION=
874 fi
875
David Bainbridge99ac7a22019-08-31 02:26:43 +0000876 local CHART_ARGS=
877 if [ -r "${INAME}-values.yaml" ]; then
878 CHART_ARGS="-f ${INAME}-values.yaml"
879 fi
880
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700881 local WAIT_START=$(date +%s)
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700882 COUNT=$(expr 300 / 15)
883 bspin $INDENT $MESSAGE
David Bainbridge2eaf2cf2020-03-18 12:54:08 -0700884 (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 -0700885 SUCCESS=$?
886 while [ $SUCCESS -ne 0 ]; do
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700887 if [ $(($(date +%s) - $WAIT_START)) -gt $TIMEOUT_SECONDS ]; then
888 espin "$THEX"
889 doTimeout "waiting for helm install $CHART"
890 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700891 sspin $INDENT
892 COUNT=$(expr $COUNT - 1)
893 if [ $COUNT -eq 0 ]; then
Andy Baviere22ff252019-12-19 11:40:31 -0700894 (set -x; helm delete --purge $INAME >>$LOG 2>&1) >>$LOG 2>&1
David Bainbridge2eaf2cf2020-03-18 12:54:08 -0700895 (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 -0700896 SUCCESS=$?
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700897 COUNT=$(expr 300 / 15)
898 fi
899 sleep .15
900 done
901 espin $INDENT $VERIFIED
902}
903
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700904echo "INSTALL TYPE: $TYPE" >> $LOG
905
906bspin "Verify GOPATH"
907export GOPATH=$(pwd)
Test User3d7ad8e2019-07-03 06:15:44 +0000908mkdir -p $GOPATH/bin
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700909espin $VERIFIED
910
David Bainbridgee87067b2019-08-12 22:00:12 +0000911STIME=$(date +%s)
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700912if [ "$INSTALL_KUBECTL" == "no" ]; then
913 bspin "Skip kubectl install"
914 espin $NO_ENTRY
Test Userc13bdc92019-07-03 20:57:49 +0000915else
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700916 bspin "Verify kubectl $HELM"
917 if [ -x $GOPATH/bin/kubectl ]; then
918 espin $VERIFIED
919 else
920 espin $NOT_VERIFIED
921 bspin - "Download and install Kubernetes/kubectl $DOWNLOAD"
922 (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
923 (set -x; chmod 755 $GOPATH/bin/kubectl >>$LOG 2>&1) >>$LOG 2>&1
924 espin - $VERIFIED
925 fi
Test Userc13bdc92019-07-03 20:57:49 +0000926fi
David Bainbridgee87067b2019-08-12 22:00:12 +0000927if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +0000928 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +0000929fi
Test Userc13bdc92019-07-03 20:57:49 +0000930
David Bainbridgee87067b2019-08-12 22:00:12 +0000931STIME=$(date +%s)
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700932if [ "$DEPLOY_K8S" == "no" ]; then
933 bspin "Skip Kubernetes/Kind Deployment"
934 espin $NO_ENTRY
935else
Test Userba1e7e72019-07-10 22:27:54 +0000936 bspin "Verify Kubernetes/Kind $HELM"
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800937 IS_INSTALLED=0
938 OP_TYPE="install"
Test Userba1e7e72019-07-10 22:27:54 +0000939 if [ -x $GOPATH/bin/kind ]; then
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800940 OP_TYPE="upgrade"
941 if [ $($GOPATH/bin/kind --version | grep -c $KIND_VERSION) -eq 1 ]; then
942 IS_INSTALLED=1
943 espin $VERIFIED
944 fi
945 fi
946 if [ $IS_INSTALLED -eq 0 ]; then
Test Userba1e7e72019-07-10 22:27:54 +0000947 espin $NOT_VERIFIED
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800948 bspin - "Download and $OP_TYPE Kubernetes/kind $DOWNLOAD"
David Bainbridge9e2a6662019-07-11 17:07:57 +0000949 (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 +0000950 (set -x; chmod 755 $GOPATH/bin/kind >>$LOG 2>&1) >>$LOG 2>&1
951 espin - $VERIFIED
952 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700953fi
954
David Bainbridgee87067b2019-08-12 22:00:12 +0000955if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +0000956 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +0000957fi
958
959STIME=$(date +%s)
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700960if [ "$INSTALL_HELM" == "no" ]; then
961 bspin "Skip Helm Install"
962 espin $NO_ENTRY
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700963else
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700964 bspin "Verify Helm $HELM"
David Bainbridgea34993d2020-04-01 09:15:42 -0700965 HELM_UPGRADE=0
966 HELM_UPGRADE_DESC="install"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700967 if [ -x $GOPATH/bin/helm ]; then
David Bainbridgea34993d2020-04-01 09:15:42 -0700968 HAVE_VER=$($GOPATH/bin/helm version -c --template '{{.Client.SemVer}}')
969 HELM_UP_DOWN=$(echo -e "$HAVE_VER\n$HELM_VERSION" | sort -V | head -1)
970 if [ $HAVE_VER != $HELM_VERSION ]; then
971 if [ $HELM_UP_DOWN == $HELM_VERSION ]; then
972 HELM_UPGRADE_DESC="downgrade"
973 else
974 HELM_UPGRADE_DESC="upgrade"
975 fi
976 HELM_UPGRADE=1
977 else
978 espin $VERIFIED
979 fi
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700980 else
David Bainbridgea34993d2020-04-01 09:15:42 -0700981 HELM_UPGRADE=1
982 fi
983
984 if [ $HELM_UPGRADE -ne 0 ]; then
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700985 espin $NOT_VERIFIED
David Bainbridgea34993d2020-04-01 09:15:42 -0700986 bspin - "Download and $HELM_UPGRADE_DESC Helm $DOWNLOAD"
987 (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 -0700988 espin - $VERIFIED
989 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700990fi
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800991
David Bainbridgee87067b2019-08-12 22:00:12 +0000992if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +0000993 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +0000994fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700995
David Bainbridgee87067b2019-08-12 22:00:12 +0000996STIME=$(date +%s)
Test Userb5712372019-07-03 21:52:17 +0000997bspin "Verify voltctl $HIGH_VOLTAGE"
David Bainbridged2811972019-12-14 01:14:09 +0000998VOK=0
999VMESSAGE="install"
David K. Bainbridgeebf38d92020-02-10 10:46:31 -08001000export VC_VERSION="$VOLTCTL_VERSION"
1001if [ "$VC_VERSION" == "latest" ]; then
1002 export VC_VERSION=$(curl -sSL https://api.github.com/repos/opencord/voltctl/releases/latest | jq -r .tag_name | sed -e 's/^v//g')
1003fi
Test User3d7ad8e2019-07-03 06:15:44 +00001004if [ -x $GOPATH/bin/voltctl ]; then
David Bainbridge1ba64f12019-12-18 00:40:13 +00001005 VHAVE=$($GOPATH/bin/voltctl version --clientonly -o json | jq -r .version)
David K. Bainbridgeebf38d92020-02-10 10:46:31 -08001006 if [ $? -eq 0 -a "$VHAVE" == "$VC_VERSION" ]; then
David Bainbridged2811972019-12-14 01:14:09 +00001007 VOK=1
David Bainbridge1ba64f12019-12-18 00:40:13 +00001008 espin $VERIFIED
1009 else
David K. Bainbridgeebf38d92020-02-10 10:46:31 -08001010 VCHECK=$(echo -e "$VHAVE\n$VC_VERSION" | sort -V | head -1)
1011 if [ "$VCHECK" == "$VHAVE" ]; then
1012 VMESSAGE="upgrade"
1013 else
1014 VMESSAGE="downgrade"
1015 fi
David Bainbridged2811972019-12-14 01:14:09 +00001016 fi
1017fi
1018
David Bainbridge1ba64f12019-12-18 00:40:13 +00001019if [ $VOK -eq 0 ]; then
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001020 espin $NOT_VERIFIED
David Bainbridged2811972019-12-14 01:14:09 +00001021 bspin - "Download and $VMESSAGE voltctl $DOWNLOAD"
David K. Bainbridgeebf38d92020-02-10 10:46:31 -08001022 (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 +00001023 (set -x; chmod 755 $GOPATH/bin/voltctl >>$LOG 2>&1) >>$LOG 2>&1
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001024 espin - $VERIFIED
1025fi
David Bainbridgee87067b2019-08-12 22:00:12 +00001026if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +00001027 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +00001028fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001029
1030bspin "Verify command PATH"
Test Userba1e7e72019-07-10 22:27:54 +00001031export PATH=$GOPATH/bin:$PATH
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001032espin $VERIFIED
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001033
David Bainbridgee87067b2019-08-12 22:00:12 +00001034STIME=$(date +%s)
Test Userba1e7e72019-07-10 22:27:54 +00001035if [ "$DEPLOY_K8S" == "yes" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +00001036 HAVE=$(kind get clusters | grep -c voltha-$NAME)
Test Userba1e7e72019-07-10 22:27:54 +00001037 bspin "Verify Kubernetes/Kind Cluster"
1038 sspin
1039 if [ $HAVE -eq 0 ]; then
David Bainbridge491b1bd2019-07-11 17:53:11 +00001040 espin $NOT_VERIFIED
1041 bspin - "Verify cluster configuration"
David Bainbridge0774b232019-08-02 06:37:19 +00001042 if [ ! -r ./$NAME-cluster.cfg ]; then
David Bainbridge491b1bd2019-07-11 17:53:11 +00001043 espin - $NOT_VERIFIED
David K. Bainbridge43422402020-03-06 07:41:22 -08001044 bspin - "Download cluster configuration: $TYPE-cluster.cfg to $NAME-cluster.cfg $DOWNLOAD"
David K. Bainbridgea00736b2020-01-08 14:33:17 -08001045 ERR_OUT=$(mktemp)
1046 (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
1047 if [ $? -ne 0 ]; then
1048 espin - $THEX
1049 echo -e "${RED}${BOLD}${ERROR}ERROR: $NAME-cluster.cfg${NORMAL}${RED} - $(cat $ERR_OUT)${NORMAL}"
1050 echo "ERROR: $(cat $ERR_OUT)" >>$LOG
1051 rm -rf $ERR_OUT ./$NAME-cluster.cfg
1052 exit 1
1053 fi
1054 rm -rf $ERR_OUT
1055 else
David K. Bainbridge43422402020-03-06 07:41:22 -08001056 espin - $VERIFIED
David K. Bainbridgea00736b2020-01-08 14:33:17 -08001057 fi
David Bainbridge0774b232019-08-02 06:37:19 +00001058 kind create cluster --name voltha-$NAME --config $NAME-cluster.cfg
David Bainbridge491b1bd2019-07-11 17:53:11 +00001059 else
1060 espin $VERIFIED
Test Userba1e7e72019-07-10 22:27:54 +00001061 fi
1062
David Bainbridge0774b232019-08-02 06:37:19 +00001063 export KUBECONFIG="$(kind get kubeconfig-path --name="voltha-$NAME")"
Test Userba1e7e72019-07-10 22:27:54 +00001064 P="coredns-.* \
David Bainbridge0774b232019-08-02 06:37:19 +00001065 etcd-voltha-$NAME-control-plane \
Test Userba1e7e72019-07-10 22:27:54 +00001066 kindnet-.* \
David Bainbridge0774b232019-08-02 06:37:19 +00001067 kube-apiserver-voltha-$NAME-control-plane \
1068 kube-controller-manager-voltha-$NAME-control-plane \
Test Userba1e7e72019-07-10 22:27:54 +00001069 kube-proxy-.* \
David Bainbridge0774b232019-08-02 06:37:19 +00001070 kube-scheduler-voltha-$NAME-control-plane"
Test Userba1e7e72019-07-10 22:27:54 +00001071
1072 EXPECT=$(test "$TYPE" == "minimal" && echo "12" || echo "14")
David Bainbridge4f1b5562019-08-19 04:46:52 +00001073 wait_for_pods - "kube-system" $EXPECT "includes" -1 "Waiting for system PODs to start" $P
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001074fi
David Bainbridgee87067b2019-08-12 22:00:12 +00001075if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +00001076 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +00001077fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001078
David Bainbridgee87067b2019-08-12 22:00:12 +00001079STIME=$(date +%s)
David Bainbridge4c6289c2019-09-03 21:11:32 +00001080COUNT=$(count_pods "kube-system" ":Running:" "tiller-deploy-.*")
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001081bspin "Verify Helm"
Test Userba1e7e72019-07-10 22:27:54 +00001082if [ $COUNT -ne 1 ]; then
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001083 espin $NOT_VERIFIED
Test Userb5712372019-07-03 21:52:17 +00001084 echo -e "Configuring Helm $GEAR"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001085 if [ "$INSTALL_HELM" == "no" ]; then
1086 bspin - "Skip Helm/Tiller Initialization"
1087 espin - $NO_ENTRY
1088 else
1089 bspin - "Initialize Helm"
1090 (set -x; helm init --upgrade >>$LOG 2>&1) >>$LOG 2>&1
1091 espin - $VERIFIED
David Bainbridge4f1b5562019-08-19 04:46:52 +00001092 wait_for_pods - "kube-system" 1 "includes" -1 "Waiting for Tiller POD to start" "tiller-deploy-.*"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001093 fi
Test Userb5712372019-07-03 21:52:17 +00001094 bspin - "Add Google Incubator repository to Helm"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001095 (set -x; helm repo add incubator https://kubernetes-charts-incubator.storage.googleapis.com >>$LOG 2>&1) >>$LOG 2>&1
1096 espin - $VERIFIED
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001097
Test Userba1e7e72019-07-10 22:27:54 +00001098 # HACK (sort-of) - the config for tiller is about to be patched, which will
1099 # cause the tiller pod to be recreated. This can sometimes cause a timing
1100 # issue with the "wait_for_pods" call on tiller as it may incorrectly
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001101 # identify the running/ready tiller pod that is soon to be terminated as
Test Userba1e7e72019-07-10 22:27:54 +00001102 # what it is waiting for. To avoid this issue we do a clean scale down and
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001103 # scale up of the pod so the script controlls when it should be expecting
Test Userba1e7e72019-07-10 22:27:54 +00001104 # things
1105 (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 -07001106
Test Userb5712372019-07-03 21:52:17 +00001107 bspin - "Add Google Stable repository to Helm"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001108 (set -x; helm repo add stable https://kubernetes-charts.storage.googleapis.com >>$LOG 2>&1) >>$LOG 2>&1
1109 espin - $VERIFIED
Test Userb5712372019-07-03 21:52:17 +00001110 bspin - "Add ONF repository to Helm"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001111 (set -x; helm repo add onf https://charts.opencord.org >>$LOG 2>&1) >>$LOG 2>&1
1112 espin - $VERIFIED
Test Userb5712372019-07-03 21:52:17 +00001113 bspin - "Update Helm repository cache"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001114 (set -x; helm repo update >>$LOG 2>&1) >>$LOG 2>&1
1115 espin - $VERIFIED
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001116
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001117 # Create and k8s service account so that Helm can create pods
Test Userb5712372019-07-03 21:52:17 +00001118 bspin - "Create Tiller ServiceAccount"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001119 (set -x; kubectl create serviceaccount --namespace kube-system tiller >>$LOG 2>&1) >>$LOG 2>&1
1120 espin - $VERIFIED
Test Userb5712372019-07-03 21:52:17 +00001121 bspin - "Create Tiller ClusterRoleBinding"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001122 (set -x; kubectl create clusterrolebinding tiller-cluster-rule --clusterrole=cluster-admin --serviceaccount=kube-system:tiller >>$LOG 2>&1) >>$LOG 2>&1
1123 espin - $VERIFIED
Test Userb5712372019-07-03 21:52:17 +00001124 bspin - "Update Tiller Manifest"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001125 (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 +00001126
1127 # HACK (sort-of) - part to, spin it back up
1128 (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 -07001129 espin - $VERIFIED
1130else
David Bainbridgea34993d2020-04-01 09:15:42 -07001131 if [ $(helm version -s --template '{{.Server.SemVer}}') != $HELM_VERSION ]; then
1132 espin $NOT_VERIFIED
1133 bspin - "Sync Tiller server version with helm client"
1134 (set -x; helm init --upgrade --force-upgrade --wait >>$LOG 2>&1) >>$LOG 2>&1
1135 espin - $VERIFIED
1136 else
1137 espin $VERIFIED
1138 fi
1139
David Bainbridge46505fb2019-10-01 21:13:20 +00001140 if [ "$UPDATE_HELM_REPOS" == "yes" ]; then
1141 bspin - "Update Helm repository cache"
1142 (set -x; helm repo update >>$LOG 2>&1) >>$LOG 2>&1
1143 espin - $VERIFIED
1144 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001145fi
David Bainbridge4f1b5562019-08-19 04:46:52 +00001146wait_for_pods - "kube-system" 1 "includes" -1 "Waiting for Tiller POD to start" "tiller-deploy-.*"
David Bainbridgee87067b2019-08-12 22:00:12 +00001147if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +00001148 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +00001149fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001150
David Bainbridgee87067b2019-08-12 22:00:12 +00001151STIME=$(date +%s)
David Bainbridge0774b232019-08-02 06:37:19 +00001152bspin "Verify Helm values file: $NAME-values.yaml"
1153if [ ! -r "./$NAME-values.yaml" ]; then
Test Userba1e7e72019-07-10 22:27:54 +00001154 espin $NOT_VERIFIED
David Bainbridge0774b232019-08-02 06:37:19 +00001155 bspin - "Download Helm values file: $TYPE-values.yaml to $NAME-values.yaml $DOWNLOAD"
David K. Bainbridgea00736b2020-01-08 14:33:17 -08001156 ERR_OUT=$(mktemp)
1157 (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
1158 if [ $? -ne 0 ]; then
1159 espin - $THEX
1160 echo -e "${RED}${BOLD}${ERROR}ERROR: $NAME-values.yaml${NORMAL}${RED} - $(cat $ERR_OUT)${NORMAL}"
1161 echo "ERROR: $(cat $ERR_OUT)" >>$LOG
1162 rm -rf $ERR_OUT ./$NAME-values.yaml
1163 exit 1
1164 fi
1165 rm -rf $ERR_OUT
Test Userba1e7e72019-07-10 22:27:54 +00001166 espin - $VERIFIED
1167else
1168 espin $VERIFIED
1169fi
David Bainbridgee87067b2019-08-12 22:00:12 +00001170if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +00001171 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +00001172fi
Test Userba1e7e72019-07-10 22:27:54 +00001173
David Bainbridge99ac7a22019-08-31 02:26:43 +00001174STIME=$(date +%s)
1175bspin "Verify or download chart specific values files $DOWNLOAD"
1176VALUES_FILES="monkey-values.yaml"
David K. Bainbridgea00736b2020-01-08 14:33:17 -08001177ERR_OUT=$(mktemp)
David Bainbridge99ac7a22019-08-31 02:26:43 +00001178for i in $VALUES_FILES; do
1179 if [ ! -r ./$i ]; then
David K. Bainbridgea00736b2020-01-08 14:33:17 -08001180 (set -x; curl --fail -o ./$i -sSL https://raw.githubusercontent.com/ciena/kind-voltha/$VK_RELEASE/$i >>$LOG 2>$ERR_OUT) >>$LOG 2>&1
1181 if [ $? -ne 0 ]; then
1182 espin $THEX
1183 echo -e "${RED}${BOLD}${ERROR}ERROR: $i${NORMAL}${RED} - $(cat $ERR_OUT)${NORMAL}"
1184 echo "ERROR: $i - $(cat $ERR_OUT)" >>$LOG
1185 rm -rf $ERR_OUT ./$i
1186 exit 1
1187 fi
1188 rm -rf $ERR_OUT
David Bainbridge99ac7a22019-08-31 02:26:43 +00001189 fi
1190done
David Bainbridge1cecba52020-03-30 09:43:10 -07001191rm -rf $ERR_OUT
David Bainbridge99ac7a22019-08-31 02:26:43 +00001192espin $VERIFIED
1193if [ "$WITH_TIMINGS" == "yes" ]; then
1194 printtime $(expr $(date +%s) - $STIME)
1195fi
1196
1197if [ "$WITH_CHAOS" == "yes" ]; then
1198 bspin "Verify or clone kube-monkey helm chart $DOWNLOAD"
1199 if [ -r ./kube-monkey ]; then
1200 espin $VERIFIED
1201 else
1202 espin $NOT_VERIFIED
1203 bspin - "GIT clone kube-monkey"
1204 (set -x; git clone https://github.com/asobti/kube-monkey kube-monkey >>$LOG 2>&1) >>$LOG 2>&1
1205 espin - $VERIFIED
1206 fi
1207fi
1208
Test Userba1e7e72019-07-10 22:27:54 +00001209if [ "$JUST_K8S" == "yes" ]; then
1210 echo "Environment deployed, not deploying VOLTHA artifacts as requested. Good bye."
1211 echo ""
1212 echo "Please issue the following commands in your terminal to ensure that you" | tee -a $LOG
1213 echo "are accessing the correct Kubernetes/Kind cluster as well as have the " | tee -a $LOG
1214 echo "tools required by VOLTHA in your command path. " | tee -a $LOG
1215 echo "" | tee -a $LOG
1216 echo -en $BOLD
1217 if [ $DEPLOY_K8S == "yes" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +00001218 echo "export KUBECONFIG=\"\$(./bin/kind get kubeconfig-path --name=\"voltha-$NAME\")\"" | tee -a $LOG
Test Userba1e7e72019-07-10 22:27:54 +00001219 fi
1220 echo "export PATH=$GOPATH/bin:\$PATH" | tee -a $LOG
1221 echo -en $NORMAL
1222 echo "" | tee -a $LOG
1223 echo "Thank you for choosing kind-voltha for you quick cluster needs." | tee -a $LOG
1224 exit 0
1225fi
1226
David Bainbridgee87067b2019-08-12 22:00:12 +00001227STIME=$(date +%s)
Test Userb5712372019-07-03 21:52:17 +00001228bspin "Verify ETCD Operator $OLD_KEY"
Test User7d866122019-07-09 17:52:35 +00001229if [ $(helm list --deployed --short --namespace voltha "^etcd-operator\$" | wc -l) -ne 1 ]; then
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001230 espin $NOT_VERIFIED
David Bainbridge90fd8e32019-08-21 23:32:47 +00001231 helm_install - voltha etcd-operator stable/etcd-operator latest "Install ETCD Operator"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001232else
1233 espin $VERIFIED
1234fi
Test User01ed0642019-07-03 20:17:06 +00001235EXPECT=$(test "$TYPE" == "minimal" && echo "1" || echo "3")
David Bainbridge4f1b5562019-08-19 04:46:52 +00001236wait_for_pods - "voltha" $EXPECT "includes" -1 "Waiting for ETCD Operator to start" "etcd-operator-.*"
David Bainbridgee87067b2019-08-12 22:00:12 +00001237if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +00001238 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +00001239fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001240
David Bainbridgee87067b2019-08-12 22:00:12 +00001241STIME=$(date +%s)
David Bainbridgeb270c202019-07-26 01:44:42 +00001242if [ $WITH_ONOS == "yes" ]; then
1243 bspin "Verify ONOS installed $BIRD"
1244 if [ $(helm list --deployed --short --namespace default "^onos\$" | wc -l) -ne 1 ]; then
1245 espin $NOT_VERIFIED
David K. Bainbridgeda33d652020-03-06 10:31:23 -08001246 EXTRA_HELM_FLAGS="$SET_TAG $EXTRA_HELM_FLAGS" helm_install - default onos $ONOS_CHART $ONOS_CHART_VERSION "Install ONOS"
David Bainbridgeb270c202019-07-26 01:44:42 +00001247 else
1248 espin $VERIFIED
1249 fi
David Bainbridge4f1b5562019-08-19 04:46:52 +00001250 wait_for_pods - "default" 1 "includes" -1 "Waiting for ONOS to start" "onos-.*"
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001251
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -08001252 if [ $WITH_PORT_FORWARDS == "yes" ]; then
1253 bspin - "Forward ONOS API port $FORWARD"
1254 kill_port_forward onos-ui
1255 port_forward default onos-ui $ONOS_API_PORT 8181
1256 espin - $VERIFIED
1257 bspin - "Forward ONOS SSH port $FORWARD"
1258 kill_port_forward onos-ssh
1259 port_forward default onos-ssh $ONOS_SSH_PORT 8101
1260 espin - $VERIFIED
1261 _ONOS_API_EP="127.0.0.1:$ONOS_API_PORT"
1262 else
1263 _ONOS_API_EP=$(get_service_ep default onos-ui)
1264 fi
David Bainbridged31d6122019-08-13 19:37:59 +00001265 bspin - "Verify or download ONOS configuration support files $DOWNLOAD"
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001266 ONOS_FILES="olt-onos-enableExtraneousRules.json onos-aaa.json \
David Bainbridge90fd8e32019-08-21 23:32:47 +00001267 onos-dhcpl2relay.json onos-kafka.json onos-sadis-sample.json"
David Bainbridged31d6122019-08-13 19:37:59 +00001268 (set -x; mkdir -p ./onos-files >>$LOG 2>&1) >>$LOG 2>&1
David K. Bainbridgea00736b2020-01-08 14:33:17 -08001269 ERR_OUT=$(mktemp)
David Bainbridge2b19e832019-08-16 02:40:53 +00001270 for i in $ONOS_FILES; do
David Bainbridged31d6122019-08-13 19:37:59 +00001271 if [ ! -r ./onos-files/$i ]; then
David K. Bainbridgea00736b2020-01-08 14:33:17 -08001272 (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
1273 if [ $? -ne 0 ]; then
1274 espin - $THEX
1275 echo -e "${RED}${BOLD}${ERROR}ERROR: $i${NORMAL}${RED} - $(cat $ERR_OUT)${NORMAL}"
1276 echo "ERROR: $(cat $ERR_OUT)" >>$LOG
1277 rm -rf $ERR_OUT ./onos-files/$i
1278 exit 1
1279 fi
1280 rm -rf $ERR_OUT
David Bainbridged31d6122019-08-13 19:37:59 +00001281 fi
1282 done
David Bainbridge1cecba52020-03-30 09:43:10 -07001283 rm -rf $ERR_OUT
Test Userba1e7e72019-07-10 22:27:54 +00001284 espin - $VERIFIED
David Bainbridge27790d62019-08-13 22:43:19 +00001285
1286 if [ $INSTALL_ONOS_APPS == "yes" ]; then
1287 bspin - "Installing custom ONOS applications"
1288 if [ -x onos-files/onos-apps -a $(ls -1 onos-files/onos-apps/*.oar 2>/dev/null | wc -l) -gt 0 ]; then
1289 for OAR in $(ls -1 onos-files/onos-apps/*.oar); do
1290 sspin - "Installing custom ONOS applications - $OAR$CEOL"
David Bainbridge2b19e832019-08-16 02:40:53 +00001291 override_onos_app $OAR
David Bainbridge27790d62019-08-13 22:43:19 +00001292 done
1293 espin - "$VERIFIED Installing custom ONOS applications$CEOL"
1294 else
1295 espin - "$NOT_VERIFIED Installing custom ONOS applications - None Found"
1296 fi
1297 fi
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001298
Matteo Scandolo9a77a732020-01-09 14:24:12 -08001299 check_onos_app_active org.opencord.kafka
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001300 push_onos_config "file" "Push ONOS Kafka Configuration" "network/configuration/apps/org.opencord.kafka" "onos-files/onos-kafka.json"
Matteo Scandolo9a77a732020-01-09 14:24:12 -08001301 check_onos_app_active org.opencord.dhcpl2relay
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001302 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 -08001303 check_onos_app_active org.opencord.olt
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001304 # FIXME use WITH_DHCP and WITH_EAPOL flags to configre OLT App
Hardik Windlassa7501fb2020-02-17 14:28:20 +00001305 # Default value for "enableEapol" is true in OLT App
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001306 if [ $WITH_EAPOL == "yes" ]; then
1307 push_onos_config "json" "Enable VOLTHA ONOS EAPOL provisioning" "configuration/org.opencord.olt.impl.OltFlowService" '{"enableEapol":true}'
Hardik Windlassa7501fb2020-02-17 14:28:20 +00001308 elif [ $WITH_EAPOL == "no" ]; then
1309 push_onos_config "json" "Disable VOLTHA ONOS EAPOL provisioning" "configuration/org.opencord.olt.impl.OltFlowService" '{"enableEapol":false}'
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001310 fi
Hardik Windlassa7501fb2020-02-17 14:28:20 +00001311 # Default value for "enableDhcpOnProvisioning" is false and for "enableDhcpV4" is true in OLT App
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001312 if [ $WITH_DHCP == "yes" ]; then
1313 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 +00001314 elif [ $WITH_DHCP == "no" ]; then
1315 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 -08001316 fi
Hardik Windlassa7501fb2020-02-17 14:28:20 +00001317 # Default value for "enableIgmpOnProvisioning" is false in OLT App
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001318 if [ $WITH_IGMP == "yes" ]; then
1319 push_onos_config "json" "Enable VOLTHA ONOS IGMP provisioning" "configuration/org.opencord.olt.impl.OltFlowService" '{"enableIgmpOnProvisioning":true}'
Hardik Windlassa7501fb2020-02-17 14:28:20 +00001320 elif [ $WITH_IGMP == "no" ]; then
1321 push_onos_config "json" "Disable VOLTHA ONOS IGMP provisioning" "configuration/org.opencord.olt.impl.OltFlowService" '{"enableIgmpOnProvisioning":false}'
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001322 fi
David K. Bainbridge484d80c2020-03-05 21:44:34 -08001323 if [ $ENABLE_ONOS_EXTRANEOUS_RULES == "yes" ]; then
1324 push_onos_config "file" "Enabling extraneous rules for ONOS" "configuration/org.onosproject.net.flow.impl.FlowRuleManager" "onos-files/olt-onos-enableExtraneousRules.json"
1325 fi
David K. Bainbridgeb859e912020-03-13 14:07:52 -07001326 if [ $(echo ":yes:file:" | grep -c ":$CONFIG_SADIS:") -eq 1 ]; then
Matteo Scandolo9a77a732020-01-09 14:24:12 -08001327 check_onos_app_active org.opencord.sadis
Hardik Windlassb3147602020-03-09 16:59:15 +05301328 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 -07001329 elif [ "$CONFIG_SADIS" == "bbsim" ]; then
1330 push_onos_config "json" \
1331 "[optional] Push ONOS configuration for BBSIM SADIS servers" \
1332 "network/configuration/apps/org.opencord.sadis" \
1333 "$(echo $(cat <<EOJ
1334{
1335 "sadis": {
1336 "integration": {
1337 "url": "http://bbsim.voltha.svc.cluster.local:50074/v2/subscribers/%s",
1338 "cache": {
1339 "enabled": true,
1340 "maxsize": 50,
1341 "ttl": "PT1m"
1342 }
1343 }
1344 },
1345 "bandwidthprofile": {
1346 "integration": {
1347 "url": "http://bbsim.voltha.svc.cluster.local:50074/v2/bandwidthprofiles/%s",
1348 "cache": {
1349 "enabled": true,
1350 "maxsize": 50,
1351 "ttl": "PT1m"
1352 }
1353 }
1354 }
1355}
1356EOJ
1357) | tr -d '[:space:]')"
1358 elif [ "$CONFIG_SADIS" == "url" ]; then
1359 push_onos_config "json" \
1360 "[optional] Push ONOS configuration for custom SADIS and Bandwidth Profile servers" \
1361 "network/configuration/apps/org.opencord.sadis" \
1362 "$(echo $(cat <<EOJ
1363{
1364 "sadis": {
1365 "integration": {
1366 "url": "$SADIS_SUBSCRIBERS",
1367 "cache": {
1368 "enabled": true,
1369 "maxsize": 50,
1370 "ttl": "PT1m"
1371 }
1372 }
1373 },
1374 "bandwidthprofile": {
1375 "integration": {
1376 "url": "$SADIS_BANDWIDTH_PROFILES",
1377 "cache": {
1378 "enabled": true,
1379 "maxsize": 50,
1380 "ttl": "PT1m"
1381 }
1382 }
1383 }
1384}
1385EOJ
1386) | tr -d '[:space:]')"
David Bainbridge2b19e832019-08-16 02:40:53 +00001387 fi
Test Userba1e7e72019-07-10 22:27:54 +00001388fi
David Bainbridgee87067b2019-08-12 22:00:12 +00001389if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +00001390 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +00001391fi
Test Userba1e7e72019-07-10 22:27:54 +00001392
David Bainbridgee87067b2019-08-12 22:00:12 +00001393STIME=$(date +%s)
Test Userb5712372019-07-03 21:52:17 +00001394bspin "Verify VOLTHA installed $HIGH_VOLTAGE"
Test User7d866122019-07-09 17:52:35 +00001395if [ $(helm list --deployed --short --namespace voltha "^voltha\$" | wc -l) -ne 1 ]; then
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001396 espin $NOT_VERIFIED
David Bainbridge70c0ea82019-11-14 23:25:26 +00001397 if [ "$ONLY_ONE" == "yes" ]; then
David Bainbridge2eaf2cf2020-03-18 12:54:08 -07001398 INTERNAL_EXTRA_HELM_INSTALL_ARGS="--set therecanbeonlyone=true"
David Bainbridge70c0ea82019-11-14 23:25:26 +00001399 fi
David Bainbridge90fd8e32019-08-21 23:32:47 +00001400 helm_install - voltha voltha $VOLTHA_CHART $VOLTHA_CHART_VERSION "Install VOLTHA Core"
David Bainbridge2eaf2cf2020-03-18 12:54:08 -07001401 INTERNAL_EXTRA_HELM_INSTALL_ARGS=
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001402else
1403 espin $VERIFIED
1404fi
Test Userba1e7e72019-07-10 22:27:54 +00001405
David Bainbridge90fd8e32019-08-21 23:32:47 +00001406VOLTHA="voltha-ofagent-.* \
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001407 ro-core.* \
1408 rw-core.* \
1409 voltha-api-server-.* \
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001410 voltha-etcd-cluster-.* \
1411 voltha-kafka-.* \
1412 voltha-zookeeper-.*"
David Bainbridge70c0ea82019-11-14 23:25:26 +00001413if [ "$ONLY_ONE" == "yes" ]; then
David Bainbridgefce8af42020-03-17 12:50:39 -07001414 EXPECT=$(test "$TYPE" == "minimal" && echo "5" || echo "9")
David Bainbridge70c0ea82019-11-14 23:25:26 +00001415else
David Bainbridgefce8af42020-03-17 12:50:39 -07001416 EXPECT=$(test "$TYPE" == "minimal" && echo "8" || echo "12")
David Bainbridge70c0ea82019-11-14 23:25:26 +00001417fi
David Bainbridge4f1b5562019-08-19 04:46:52 +00001418wait_for_pods - "voltha" $EXPECT "includes" -1 "Waiting for VOLTHA Core to start" $VOLTHA
David Bainbridgee87067b2019-08-12 22:00:12 +00001419if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +00001420 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +00001421fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001422
David Bainbridge46505fb2019-10-01 21:13:20 +00001423if [ "$WITH_ADAPTERS" == "yes" ]; then
1424 STIME=$(date +%s)
1425 EXPECT=0
1426 echo -e "Verify Adapters $PLUG"
1427 if [ "$WITH_SIM_ADAPTERS" == "yes" ]; then
1428 bspin - "Verify Simulated Adapters installed"
1429 if [ $(helm list --deployed --short --namespace voltha "^sim\$" | wc -l) -ne 1 ]; then
1430 espin - $NOT_VERIFIED
1431 helm_install - voltha sim $VOLTHA_ADAPTER_SIM_CHART $VOLTHA_ADAPTER_SIM_CHART_VERSION "Install Simulated Adapters"
1432 else
1433 espin - $VERIFIED
1434 fi
1435 EXPECT=$(expr $EXPECT + 2)
1436 fi
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001437
David Bainbridge46505fb2019-10-01 21:13:20 +00001438 if [ "$WITH_OPEN_ADAPTERS" == "yes" ]; then
1439 bspin - "Verify OpenOLT Adapter installed"
1440 if [ $(helm list --deployed --short --namespace voltha "^open-olt\$" | wc -l) -ne 1 ]; then
1441 espin - $NOT_VERIFIED
1442 helm_install - voltha open-olt $VOLTHA_ADAPTER_OPEN_OLT_CHART $VOLTHA_ADAPTER_OPEN_OLT_CHART_VERSION "Install OpenOLT Adapter"
1443 else
1444 espin - $VERIFIED
1445 fi
1446 bspin - "Verify OpenONU Adapter installed"
1447 if [ $(helm list --deployed --short --namespace voltha "^open-onu\$" | wc -l) -ne 1 ]; then
1448 espin - $NOT_VERIFIED
1449 helm_install - voltha open-onu $VOLTHA_ADAPTER_OPEN_ONU_CHART $VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION "Install OpenONU Adapter"
1450 else
1451 espin - $VERIFIED
1452 fi
1453 EXPECT=$(expr $EXPECT + 2)
1454 fi
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001455
David Bainbridge46505fb2019-10-01 21:13:20 +00001456 ADAPTERS="adapter-.*"
1457 wait_for_pods - "voltha" $EXPECT "includes" -1 "Waiting for adapters to start" $ADAPTERS
1458 if [ "$WITH_TIMINGS" == "yes" ]; then
1459 printtime $(expr $(date +%s) - $STIME)
1460 fi
David Bainbridgee87067b2019-08-12 22:00:12 +00001461fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001462
Test User7d866122019-07-09 17:52:35 +00001463if [ $WITH_BBSIM == "yes" ]; then
David Bainbridgee87067b2019-08-12 22:00:12 +00001464 STIME=$(date +%s)
Test User7d866122019-07-09 17:52:35 +00001465 echo -e "Verify BBSIM $PLUG"
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001466 bspin - "Verify BBSIM Installed"
David K. Bainbridge43422402020-03-06 07:41:22 -08001467 for instance in $(seq 0 $(($NUM_OF_BBSIM-1))); do
1468 if [ $instance -eq 0 ]; then
1469 instance_num=""
1470 else
1471 instance_num=$instance
1472 fi
1473 if [ $(helm list --deployed --short --namespace voltha "^bbsim${instance_num}\$" | wc -l) -ne 1 ]; then
1474 espin - $NOT_VERIFIED
David Bainbridge2eaf2cf2020-03-18 12:54:08 -07001475 INTERNAL_EXTRA_HELM_INSTALL_ARGS="--set olt_id=$instance"
David K. Bainbridge43422402020-03-06 07:41:22 -08001476 helm_install - voltha bbsim${instance_num} $VOLTHA_BBSIM_CHART $VOLTHA_BBSIM_CHART_VERSION "Install BBSIM${instance_num}"
David Bainbridge2eaf2cf2020-03-18 12:54:08 -07001477 INTERNAL_EXTRA_HELM_INSTALL_ARGS=
David K. Bainbridge43422402020-03-06 07:41:22 -08001478 else
1479 espin - $VERIFIED
1480 fi
1481 done
uottrembb16d3982020-02-28 08:34:36 +01001482 wait_for_pods - "voltha" $NUM_OF_BBSIM "includes" -1 "Waiting for BBSIM to start" "bbsim*"
David Bainbridgee87067b2019-08-12 22:00:12 +00001483 if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +00001484 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +00001485 fi
Test User7d866122019-07-09 17:52:35 +00001486fi
1487
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001488if [ $WITH_RADIUS == "yes" ]; then
David Bainbridgee87067b2019-08-12 22:00:12 +00001489 STIME=$(date +%s)
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001490 echo -e "Verify RADIUS $LOCK"
1491 bspin - "Verify RADIUS Installed"
1492 if [ $(helm list --deployed --short --namespace voltha "^radius\$" | wc -l) -ne 1 ]; then
1493 espin - $NOT_VERIFIED
David Bainbridge90fd8e32019-08-21 23:32:47 +00001494 helm_install - voltha radius onf/freeradius latest "Install RADIUS"
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001495 else
1496 espin - $VERIFIED
1497 fi
David Bainbridge4f1b5562019-08-19 04:46:52 +00001498 wait_for_pods - "voltha" 1 "includes" -1 "Waiting for RADIUS to start" "radius-.*"
David Bainbridgee87067b2019-08-12 22:00:12 +00001499 if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +00001500 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +00001501 fi
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001502fi
1503
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -08001504if [ $WITH_PORT_FORWARDS == "yes" ]; then
1505 STIME=$(date +%s)
1506 bspin - "Forward VOLTHA API port $FORWARD"
1507 kill_port_forward voltha-api
1508 port_forward voltha voltha-api $VOLTHA_API_PORT 55555
1509 espin - $VERIFIED
1510 bspin - "Forward VOLTHA ETCD port $FORWARD"
1511 kill_port_forward voltha-etcd-cluster-client
1512 port_forward voltha voltha-etcd-cluster-client $VOLTHA_ETCD_PORT 2379
1513 espin - $VERIFIED
1514 bspin - "Forward VOLTHA Kafka port $FORWARD"
1515 kill_port_forward voltha-kafka
1516 port_forward voltha voltha-kafka $VOLTHA_KAFKA_PORT 9092
1517 espin - $VERIFIED
1518 if [ "$WITH_TIMINGS" == "yes" ]; then
1519 printtime $(expr $(date +%s) - $STIME)
1520 fi
David Bainbridgee87067b2019-08-12 22:00:12 +00001521fi
Test User3d7ad8e2019-07-03 06:15:44 +00001522
David Bainbridgeb270c202019-07-26 01:44:42 +00001523if [ $WITH_ONOS == "yes" -a $WITH_RADIUS == "yes" ]; then
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001524 bspin "Configure ONOS RADIUS Connection $GEAR"
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -08001525 (set -x; cat onos-files/onos-aaa.json | sed -e "s/:RADIUS_IP:/$(kubectl -n voltha get service/radius -o jsonpath={.spec.clusterIP})/g" | 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 +00001526 espin $VERIFIED
1527fi
1528
David Bainbridge99ac7a22019-08-31 02:26:43 +00001529if [ "$WITH_CHAOS" == "yes" ]; then
1530 STIME=$(date +%s)
1531 echo -e "Verify kube-monkey $LOCK"
1532 bspin - "Verify kube-monkey Installed"
1533 if [ $(helm list --deployed --short --namespace kube-monkey "^monkey\$" | wc -l) -ne 1 ]; then
1534 espin - $NOT_VERIFIED
1535 helm_install - kube-monkey monkey ./kube-monkey/helm/kubemonkey latest "Install Chaos Monkey"
1536 else
1537 espin - $VERIFIED
1538 fi
1539 wait_for_pods - "kube-monkey" 1 "includes" -1 "Waiting for Chaos to start" "monkey-.*"
1540 if [ "$WITH_TIMINGS" == "yes" ]; then
1541 printtime $(expr $(date +%s) - $STIME)
1542 fi
1543fi
1544
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001545bspin "Create voltctl configuration file"
Test User3d7ad8e2019-07-03 06:15:44 +00001546(set -x; mkdir -p $HOME/.volt >>$LOG 2>&1) >>$LOG 2>&1
David K. Bainbridgeb859e912020-03-13 14:07:52 -07001547MIN_VC_VERSION=$(echo -e "1.0.15\n$VC_VERSION" | sort -V | head -1)
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -08001548if [ $WITH_PORT_FORWARDS == "yes" ]; then
David K. Bainbridgeb859e912020-03-13 14:07:52 -07001549 KAFKA_FLAG="-k localhost:$VOLTHA_KAFKA_PORT"
1550 SERVER_FLAG="-s localhost:$VOLTHA_API_PORT"
1551 ETCD_FLAG=
1552 if [ "$MIN_VC_VERSION" == "1.0.15" ]; then
1553 ETCD_FLAG="-e localhost:$VOLTHA_ETCD_PORT"
1554 fi
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -08001555else
David K. Bainbridgeb859e912020-03-13 14:07:52 -07001556 KAFKA_FLAG="-k $(get_service_ep voltha voltha-kafka)"
1557 SERVER_FLAG="-s $(get_service_ep voltha voltha-api)"
1558 ETCD_FLAG=
1559 if [ "$MIN_VC_VERSION" == "1.0.15" ]; then
1560 ETCD_FLAG="-e $(get_service_ep voltha voltha-etcd-client)"
1561 fi
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -08001562fi
David K. Bainbridgeb859e912020-03-13 14:07:52 -07001563(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 +00001564espin $VERIFIED
Test User08ebbd92019-07-03 17:15:39 +00001565
David Bainbridge0774b232019-08-02 06:37:19 +00001566if [ ! -f "$NAME-env.sh" ]; then
1567 touch $NAME-env.sh
David Bainbridgeb07fdf72019-07-29 22:51:40 +00001568fi
1569
David Bainbridge596f30d2019-07-30 17:07:59 +00001570for O in $ALL_OPTIONS; do
1571 VAL=$(eval echo \$$O)
David Bainbridge0774b232019-08-02 06:37:19 +00001572 if [ ! -z "$VAL" -a $(grep -c "^export $O=" $NAME-env.sh) -eq 0 ]; then
1573 echo "export $O=\"$(eval echo \$$O)\"" >> $NAME-env.sh
David Bainbridgeb07fdf72019-07-29 22:51:40 +00001574 fi
1575done
1576
David Bainbridge0774b232019-08-02 06:37:19 +00001577if [ $DEPLOY_K8S == "yes" -a $(grep -c "^export KUBECONFIG=" $NAME-env.sh) -eq 0 ]; then
1578 echo "export KUBECONFIG=\"$(./bin/kind get kubeconfig-path --name=voltha-$NAME)\"" >> $NAME-env.sh
David Bainbridgeb07fdf72019-07-29 22:51:40 +00001579fi
1580
David Bainbridge0774b232019-08-02 06:37:19 +00001581if [ $(grep -c "^export VOLTCONFIG=" $NAME-env.sh) -eq 0 ]; then
1582 echo "export VOLTCONFIG=\"$HOME/.volt/config-$NAME\"" >> $NAME-env.sh
David Bainbridgeb07fdf72019-07-29 22:51:40 +00001583fi
1584
David Bainbridge0774b232019-08-02 06:37:19 +00001585if [ $(grep -c "^export PATH=" $NAME-env.sh) -eq 0 ]; then
1586 echo "export PATH=\"$GOPATH/bin:\$PATH\"" >> $NAME-env.sh
David Bainbridgeb07fdf72019-07-29 22:51:40 +00001587fi
1588
Test User7d866122019-07-09 17:52:35 +00001589echo ""
Test User08ebbd92019-07-03 17:15:39 +00001590echo "Please issue the following commands in your terminal to ensure that you" | tee -a $LOG
1591echo "are accessing the correct Kubernetes/Kind cluster as well as have the " | tee -a $LOG
1592echo "tools required by VOLTHA in your command path. " | tee -a $LOG
1593echo "" | tee -a $LOG
Test User7d866122019-07-09 17:52:35 +00001594echo -en $BOLD
Test Userba1e7e72019-07-10 22:27:54 +00001595if [ $DEPLOY_K8S == "yes" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +00001596 echo "export KUBECONFIG=\"\$(./bin/kind get kubeconfig-path --name=\"voltha-$NAME\")\"" | tee -a $LOG
Test Userba1e7e72019-07-10 22:27:54 +00001597fi
David Bainbridge0774b232019-08-02 06:37:19 +00001598echo "export VOLTCONFIG=\"$HOME/.volt/config-$NAME\"" | tee -a $LOG
Test Userba1e7e72019-07-10 22:27:54 +00001599echo "export PATH=$GOPATH/bin:\$PATH" | tee -a $LOG
Test User7d866122019-07-09 17:52:35 +00001600echo -en $NORMAL
Test User08ebbd92019-07-03 17:15:39 +00001601echo "" | tee -a $LOG
1602echo "Thank you for choosing kind-voltha for you quick cluster needs." | tee -a $LOG
1603
David Bainbridge712afb82019-08-14 19:55:58 +00001604if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridgef858a022019-08-14 21:25:11 +00001605 echo -e "$CLOCK ${BOLD}TOTAL: $(duration $(expr $(date +%s) - $TOTAL_START_TIME))${NORMAL}"
David Bainbridge712afb82019-08-14 19:55:58 +00001606fi