blob: e974f2fc43acc8101f279baf0af79c0befc6ed93 [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 Bainbridge712afb82019-08-14 19:55:58 +000015TOTAL_START_TIME=$(date +%s)
David K. Bainbridgeb7285432019-07-02 22:05:24 -070016
David Bainbridge38dc1e82019-08-12 15:18:45 +000017FANCY=${FANCY:-1}
18if [ "$TERM X" == " X" ]; then
19 FANCY=0
20fi
21
David K. Bainbridgeb7285432019-07-02 22:05:24 -070022# trap ctrl-c and call ctrl_c()
23trap ctrl_c INT
24
25function ctrl_c() {
David Bainbridge38dc1e82019-08-12 15:18:45 +000026 echo -en $CNORM
David K. Bainbridgeb7285432019-07-02 22:05:24 -070027 echo ""
28 echo "ctrl-c trapped"
David Bainbridgec6a6eb62019-10-18 22:50:07 +000029 echo "Thank you for trying 'voltha up'"
David K. Bainbridgeb7285432019-07-02 22:05:24 -070030 exit
31}
32
David K. Bainbridgeebf38d92020-02-10 10:46:31 -080033VOLTCTL_VERSION=${VOLTCTL_VERSION:-latest}
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -080034KIND_VERSION=${KIND_VERSION:-v0.5.1}
David K. Bainbridgeb3a99372020-01-08 14:39:06 -080035VK_RELEASE=${VK_RELEASE:-master}
Test User08ebbd92019-07-03 17:15:39 +000036
David Bainbridge38dc1e82019-08-12 15:18:45 +000037BLACK=
38RED=
39GREEN=
40YELLOW=
41BLUE=
42MAGENTA=
43CYAN=
44WHITE=
45BOLD=
46NORMAL=
47ERROR=
48CEOL=
49CNORM=
50CIVIS=
51if [ $FANCY -eq 1 ]; then
52 BLACK=$(tput setaf 0)
53 RED=$(tput setaf 1)
54 GREEN=$(tput setaf 2)
55 YELLOW=$(tput setaf 3)
56 BLUE=$(tput setaf 4)
57 MAGENTA=$(tput setaf 5)
58 CYAN=$(tput setaf 6)
59 WHITE=$(tput setaf 7)
60 BOLD=$(tput bold)
61 NORMAL=$(tput sgr0)
62 ERROR="\xe2\x9c\x97\x20"
63 CEOL=$(tput el)
64 CNORM=$(tput cnorm)
65 CIVIS=$(tput civis)
66fi
Test User7d866122019-07-09 17:52:35 +000067
Test User3d7ad8e2019-07-03 06:15:44 +000068TYPE=${TYPE:-minimal}
David Bainbridge0774b232019-08-02 06:37:19 +000069NAME=${NAME:-$TYPE}
David K. Bainbridge484d80c2020-03-05 21:44:34 -080070
71ENABLE_ONOS_EXTRANEOUS_RULES=${ENABLE_ONOS_EXTRANEOUS_RULES:-no}
David Bainbridgee87067b2019-08-12 22:00:12 +000072WITH_TIMINGS=${WITH_TIMINGS:-no}
Test User7d866122019-07-09 17:52:35 +000073WITH_BBSIM=${WITH_BBSIM:-no}
David Bainbridge5b7b96b2019-07-25 20:29:13 +000074WITH_RADIUS=${WITH_RADIUS:-no}
Matteo Scandolo78dfee02020-02-13 16:18:03 -080075WITH_EAPOL=${WITH_EAPOL:-yes}
76WITH_DHCP=${WITH_DHCP:-yes}
77WITH_IGMP=${WITH_IGMP:-no}
David Bainbridgeb270c202019-07-26 01:44:42 +000078WITH_ONOS=${WITH_ONOS:-yes}
David Bainbridge99ac7a22019-08-31 02:26:43 +000079WITH_CHAOS=${WITH_CHAOS:-no}
David Bainbridge46505fb2019-10-01 21:13:20 +000080WITH_ADAPTERS=${WITH_ADAPTERS:-yes}
81WITH_SIM_ADAPTERS=${WITH_SIM_ADAPTERS:-yes}
82WITH_OPEN_ADAPTERS=${WITH_OPEN_ADAPTERS:-yes}
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -080083WITH_PORT_FORWARDS=${WITH_PORT_FORWARDS:-yes}
David Bainbridge05cd8822019-11-19 17:43:53 +000084ONLY_ONE=${ONLY_ONE:-yes}
David Bainbridge2b19e832019-08-16 02:40:53 +000085CONFIG_SADIS=${CONFIG_SADIS:-no}
David Bainbridge27790d62019-08-13 22:43:19 +000086INSTALL_ONOS_APPS=${INSTALL_ONOS_APPS:-no}
Test Userba1e7e72019-07-10 22:27:54 +000087JUST_K8S=${JUST_K8S:-no}
88DEPLOY_K8S=${DEPLOY_K8S:-yes}
David K. Bainbridge0e89cb92019-07-17 11:30:10 -070089INSTALL_KUBECTL=${INSTALL_KUBECTL:-yes}
90INSTALL_HELM=${INSTALL_HELM:-yes}
David Bainbridge46505fb2019-10-01 21:13:20 +000091UPDATE_HELM_REPOS=${UPDATE_HELM_REPOS:-yes}
Matteo Scandolofab98622020-01-28 15:17:20 -080092WAIT_ON_DOWN=${WAIT_ON_DOWN:-yes}
David Bainbridge5b7b96b2019-07-25 20:29:13 +000093VOLTHA_LOG_LEVEL=${VOLTHA_LOG_LEVEL:-WARN}
David Bainbridge90fd8e32019-08-21 23:32:47 +000094VOLTHA_CHART=${VOLTHA_CHART:-onf/voltha}
95VOLTHA_CHART_VERSION=${VOLTHA_CHART_VERSION:-latest}
96VOLTHA_BBSIM_CHART=${VOLTHA_BBSIM_CHART:-onf/bbsim}
Matteo Scandolodcd29f52019-10-07 15:42:42 -070097VOLTHA_BBSIM_CHART_VERSION=${VOLTHA_BBSIM_CHART_VERSION:-latest}
David Bainbridgee10f6d52019-07-25 00:28:13 +000098VOLTHA_ADAPTER_SIM_CHART=${VOLTHA_ADAPTER_SIM_CHART:-onf/voltha-adapter-simulated}
David Bainbridge90fd8e32019-08-21 23:32:47 +000099VOLTHA_ADAPTER_SIM_CHART_VERSION=${VOLTHA_ADAPTER_SIM_CHART_VERSION:-latest}
David Bainbridgee10f6d52019-07-25 00:28:13 +0000100VOLTHA_ADAPTER_OPEN_OLT_CHART=${VOLTHA_ADAPTER_OPEN_OLT_CHART:-onf/voltha-adapter-openolt}
David Bainbridge90fd8e32019-08-21 23:32:47 +0000101VOLTHA_ADAPTER_OPEN_OLT_CHART_VERSION=${VOLTHA_ADAPTER_OPEN_OLT_CHART_VERSION:-latest}
David Bainbridgee10f6d52019-07-25 00:28:13 +0000102VOLTHA_ADAPTER_OPEN_ONU_CHART=${VOLTHA_ADAPTER_OPEN_ONU_CHART:-onf/voltha-adapter-openonu}
David Bainbridge90fd8e32019-08-21 23:32:47 +0000103VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION=${VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION:-latest}
Andrea Campanella21323292019-12-18 11:44:19 -0800104ONOS_CHART_VERSION=${ONOS_CHART_VERSION:-latest}
David Bainbridge70c0ea82019-11-14 23:25:26 +0000105EXTRA_HELM_INSTALL_ARGS=
Test Userba1e7e72019-07-10 22:27:54 +0000106
107HAVE_GO=$(which go >/dev/null 2>&1 && echo "yes" || echo "no")
108HOSTOS=$(uname -s | tr "[:upper:]" "[:lower:"])
109HOSTARCH=$(uname -m | tr "[:upper:]" "[:lower:"])
110if [ $HOSTARCH == "x86_64" ]; then
111 HOSTARCH="amd64"
112fi
Test User7d866122019-07-09 17:52:35 +0000113
114# Verify TYPE setting
115if [ $(echo ":minimal:full:" | grep -ic ":$TYPE:") -eq 0 ]; then
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700116 >&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 +0000117 exit 1
118fi
119
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -0800120function get_service_ep() {
121 local NS=$1
122 local NAME=$2
123 kubectl -n $NS get service $NAME -o json | jq -r '.spec.clusterIP + ":" + (.spec.ports[0].port|tostring)'
124}
125
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000126# Used to verify configuration values are set to "yes" or "no" value or convert
127# equivalents to "yes" or "no"
128function verify_yes_no() {
129 local VAR=$1
130 local VAL=$(eval echo \$$VAR)
131 if [ $(echo ":y:yes:true:n:no:false:1:0:" | grep -ic ":$VAL:") -eq 0 ]; then
132 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} Invalid '$VAR' value of '$VAL'. Should be 'yes' or 'no'${NORMAL}"
133 echo "INVALID"
134 return 1
135 fi
136 if [ $(echo ":y:yes:true:1:" | grep -ic ":$VAL:") -eq 1 ]; then
137 echo "yes"
138 else
139 echo "no"
140 fi
141 return 0
142}
Test User7d866122019-07-09 17:52:35 +0000143
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000144ALL_YES_NO="\
David K. Bainbridge484d80c2020-03-05 21:44:34 -0800145 ENABLE_ONOS_EXTRANEOUS_RULES \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000146 WITH_TIMINGS \
147 WITH_BBSIM \
148 WITH_RADIUS \
Matteo Scandolo78dfee02020-02-13 16:18:03 -0800149 WITH_EAPOL \
150 WITH_DHCP \
151 WITH_IGMP \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000152 WITH_ONOS \
David Bainbridge99ac7a22019-08-31 02:26:43 +0000153 WITH_CHAOS \
David Bainbridge46505fb2019-10-01 21:13:20 +0000154 WITH_ADAPTERS \
155 WITH_SIM_ADAPTERS \
156 WITH_OPEN_ADAPTERS \
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -0800157 WITH_PORT_FORWARDS \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000158 CONFIG_SADIS \
159 JUST_K8S \
160 DEPLOY_K8S \
161 INSTALL_ONOS_APPS \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000162 INSTALL_KUBECTL \
163 INSTALL_HELM \
David Bainbridge46505fb2019-10-01 21:13:20 +0000164 UPDATE_HELM_REPOS \
David Bainbridge4f1b5562019-08-19 04:46:52 +0000165 WAIT_ON_DOWN \
David Bainbridge70c0ea82019-11-14 23:25:26 +0000166 ONLY_ONE \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000167 "
David Bainbridge5b7b96b2019-07-25 20:29:13 +0000168
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000169ALL_OPTIONS="\
170 NAME \
171 TYPE \
172 $ALL_YES_NO \
173 VOLTHA_LOG_LEVEL \
174 VOLTHA_CHART \
David Bainbridge90fd8e32019-08-21 23:32:47 +0000175 VOLTHA_CHART_VERSION \
176 VOLTHA_BBSIM_CHART \
177 VOLTHA_BBSIM_CHART_VERSION \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000178 VOLTHA_ADAPTER_SIM_CHART \
David Bainbridge90fd8e32019-08-21 23:32:47 +0000179 VOLTHA_ADAPTER_SIM_CHART_VERSION \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000180 VOLTHA_ADAPTER_OPEN_OLT_CHART \
David Bainbridge90fd8e32019-08-21 23:32:47 +0000181 VOLTHA_ADAPTER_OPEN_OLT_CHART_VERSION \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000182 VOLTHA_ADAPTER_OPEN_ONU_CHART \
David Bainbridge90fd8e32019-08-21 23:32:47 +0000183 VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION \
Andrea Campanella21323292019-12-18 11:44:19 -0800184 ONOS_CHART_VERSION \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000185 ONOS_API_PORT \
186 ONOS_SSH_PORT \
187 VOLTHA_API_PORT \
188 VOLTHA_SSH_PORT \
189 VOLTHA_ETCD_PORT \
David K. Bainbridge00ecd382020-02-28 12:31:58 -0800190 VOLTHA_KAFKA_PORT \
David K. Bainbridge8f7f30b2020-01-08 13:06:16 -0800191 VK_RELEASE \
192 KIND_VERSION \
193 VOLTCTL_VERSION \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000194 "
David Bainbridge01294952019-07-30 19:33:45 +0000195
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000196# Iterate over yes/no configuration options and validate
197for VAR in $ALL_YES_NO; do
198 eval $VAR=$(verify_yes_no $VAR)
199 if [ "$(eval echo \$$VAR)" == "INVALID" ]; then
200 exit 1;
201 fi
202done
David Bainbridgeb270c202019-07-26 01:44:42 +0000203
David Bainbridge0774b232019-08-02 06:37:19 +0000204mkdir -p .voltha
205touch .voltha/ports
206HAVE=$(grep $NAME .voltha/ports)
207if [ "$HAVE X" == " X" ]; then
208 # Find free port prefix
209 START=81
210 while true; do
211 if [ $(grep -c $START .voltha/ports) -eq 0 ]; then
212 break
213 fi
214 START=$(expr $START + 1)
215 done
216 DELTA=$(expr $START - 81)
David Bainbridgea2595422019-10-22 03:54:28 +0000217 ONOS_API_PORT=${ONOS_API_PORT:-${START}81}
218 ONOS_SSH_PORT=${ONOS_SSH_PORT:-${START}01}
219 VOLTHA_API_PORT=${VOLTHA_API_PORT:-5$(expr 55 + $DELTA)55}
220 VOLTHA_SSH_PORT=${VOLTHA_SSH_PORT:-$(expr 50 + $DELTA)22}
221 VOLTHA_ETCD_PORT=${VOLTHA_ETCD_PORT:-$(expr 23 + $DELTA)79}
David K. Bainbridge00ecd382020-02-28 12:31:58 -0800222 VOLTHA_KAFKA_PORT=${VOLTHA_KAFKA_PORT:-$(expr 90 + $DELTA)92}
Test User01ed0642019-07-03 20:17:06 +0000223else
David Bainbridge0774b232019-08-02 06:37:19 +0000224 VALUES=$(echo $HAVE | sed -e 's/\s//g' | cut -d= -f2)
David Bainbridgea2595422019-10-22 03:54:28 +0000225 ONOS_API_PORT=${ONOS_API_PORT:-$(echo $VALUES | cut -d, -f1)}
226 ONOS_SSH_PORT=${ONOS_SSH_PORT:-$(echo $VALUES | cut -d, -f2)}
227 VOLTHA_API_PORT=${VOLTHA_API_PORT:-$(echo $VALUES | cut -d, -f3)}
228 VOLTHA_SSH_PORT=${VOLTHA_SSH_PORT:-$(echo $VALUES | cut -d, -f4)}
229 VOLTHA_ETCD_PORT=${VOLTHA_ETCD_PORT:-$(echo $VALUES | cut -d, -f5)}
David K. Bainbridge00ecd382020-02-28 12:31:58 -0800230 VOLTHA_KAFKA_PORT=${VOLTHA_KAFKA_PORT:-$(echo $VALUES | cut -d, -f6)}
231
David K. Bainbridge00ecd382020-02-28 12:31:58 -0800232 # A bit of a hueristic required here as the KAFKA port forward was
233 # added after the .voltha/ports files was created. Basically, if
234 # the VOLTHA_KAFKA_PORT isn't in the file then calculate the original
235 # DELTA from the VOLTHA_SSH_PORT and apply it to the VOLTHA_KAFKA_PORT
236 if [ -z "$VOLTHA_KAFKA_PORT" ]; then
237 DELTA=$((VOLTHA_SSH_PORT/100-50))
238 VOLTHA_KAFKA_PORT=${VOLTHA_KAFKA_PORT:-$(expr 90 + $DELTA)92}
239 fi
Test User01ed0642019-07-03 20:17:06 +0000240fi
241
David Bainbridge0774b232019-08-02 06:37:19 +0000242PORTTMP=$(mktemp -u)
243cat .voltha/ports | grep -v $NAME > $PORTTMP
David K. Bainbridge00ecd382020-02-28 12:31:58 -0800244echo "$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 +0000245cp $PORTTMP .voltha/ports
246rm -f $PORTTMP
247
David Bainbridge27790d62019-08-13 22:43:19 +0000248export ONOS_API_PORT ONOS_SSH_PORT
David Bainbridge01294952019-07-30 19:33:45 +0000249
Test Userd87942b2019-07-03 07:20:24 +0000250IDX=1
David Bainbridgee87067b2019-08-12 22:00:12 +0000251CLOCK="TIME:"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000252SPIN_PARTS=
253NOT_VERIFIED=
David Bainbridgef858a022019-08-14 21:25:11 +0000254THEX=
255BUILD=
256CROSS=
257ENTER=
David Bainbridge38dc1e82019-08-12 15:18:45 +0000258VERIFIED=
259HELM=
260OLD_KEY=
261BIRD=
262HIGH_VOLTAGE=
263PLUG=
264RESTART=
265FORWARD=
266INSTALL=
267STOP=
268GO=
269DOWNLOAD=
270GEAR=
271NO_ENTRY=
272LOCK=
273
274if [ $FANCY -eq 1 ]; then
275 SPIN_PARTS="\
276 \xe2\xa2\x8e\xe2\xa1\xb0 \
277 \xe2\xa2\x8e\xe2\xa1\xa1 \
278 \xe2\xa2\x8e\xe2\xa1\x91 \
279 \xe2\xa2\x8e\xe2\xa0\xb1 \
280 \xe2\xa0\x8e\xe2\xa1\xb1 \
281 \xe2\xa2\x8a\xe2\xa1\xb1 \
282 \xe2\xa2\x8c\xe2\xa1\xb1 \
283 \xe2\xa2\x86\xe2\xa1\xb1 \
284 "
David Bainbridgee87067b2019-08-12 22:00:12 +0000285 CLOCK="\xe2\x8f\xb1"
David Bainbridgef858a022019-08-14 21:25:11 +0000286 THEX="${RED}${BOLD}\xe2\x9c\x97\x20${NORMAL}"
287 ENTER="${YELLOW}${BOLD}\xe2\x8e\x86${NORMAL}"
288 CROSS="${YELLOW}${BOLD}\xe2\x9c\x9a${NORMAL}"
289 BUILD="${YELLOW}${BOLD}\xf0\x9f\x8f\x97${NORMAL}"
290 NOT_VERIFIED="$BUILD"
291 VERIFIED="${GREEN}${BOLD}\xe2\x9c\x93\x20${NORMAL}"
292 HELM="${BLUE}${BOLD}\xE2\x8E\x88${NORMAL}"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000293 OLD_KEY="\xF0\x9F\x97\x9D"
294 BIRD="\xF0\x9F\x90\xA6"
295 HIGH_VOLTAGE="\xE2\x9A\xA1"
296 PLUG="\xF0\x9F\xa7\xa9"
297 RESTART="\xf0\x9f\x94\x84"
298 FORWARD="\xE2\x87\xA8"
299 INSTALL="\xF0\x9F\x8F\x97"
300 STOP="\xf0\x9f\x9b\x91"
301 GO="\xf0\x9f\x9a\x80"
302 DOWNLOAD="\xf0\x9f\x93\xa5"
303 GEAR="\xe2\x9a\x99"
304 NO_ENTRY="\xe2\x9b\x94"
305 LOCK="\xf0\x9f\x94\x92"
306fi
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700307
David Bainbridge712afb82019-08-14 19:55:58 +0000308duration() {
David Bainbridgee87067b2019-08-12 22:00:12 +0000309 local h=$(expr $1 / 3600)
310 local m=$(expr $1 % 3600 / 60)
311 local s=$(expr $1 % 60)
312 local t=""
313
314 if [ $h -gt 0 ]; then
315 t="$t${h}h"
316 fi
317 if [ $m -gt 0 ]; then
318 t="$t${m}m"
319 fi
David Bainbridge712afb82019-08-14 19:55:58 +0000320 echo "$t${s}s"
321}
322
323printtime() {
324 local INDENT=
325 if [ "$1" == "-" ]; then
326 INDENT=" "
327 shift
328 fi
329 echo -e "$INDENT $CLOCK $(duration $1)"
David Bainbridgee87067b2019-08-12 22:00:12 +0000330}
331
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700332bspin() {
Test Userd87942b2019-07-03 07:20:24 +0000333 IDX=1
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700334 local INDENT=
335 if [ "$1" == "-" ]; then
336 INDENT=" "
337 shift
338 fi
David Bainbridge38dc1e82019-08-12 15:18:45 +0000339 if [ $FANCY -eq 0 ]; then
340 LINE=$(echo $* | sed -e 's/[\s+-]//g')
341 if [ "$LINE X" == " X" ]; then
342 return
343 fi
344 echo -e "$CIVIS$INDENT$*"
345 else
346 echo -en "$CIVIS$INDENT $*"
347 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700348}
349
350sspin() {
351 local INDENT=
352 if [ "$1" == "-" ]; then
353 INDENT=" "
354 shift
355 fi
David Bainbridge38dc1e82019-08-12 15:18:45 +0000356 if [ $FANCY -eq 0 ]; then
357 LINE=$(echo $* | sed -e 's/[\s+-]//g')
358 if [ "$LINE X" == " X" ]; then
359 return
360 fi
361 echo -e "$INDENT$*"
362 else
363 C=$(echo $SPIN_PARTS | cut '-d ' -f $IDX)
364 echo -en "\r$INDENT$C $*"
365 IDX=$(expr $IDX + 1)
366 if [ $IDX -gt 8 ]; then
367 IDX=1
368 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700369 fi
370}
371
372espin() {
373 local INDENT=
374 if [ "$1" == "-" ]; then
375 INDENT=" "
376 shift
377 fi
David Bainbridge38dc1e82019-08-12 15:18:45 +0000378 if [ $FANCY -eq 0 ]; then
379 LINE=$(echo $* | sed -e 's/[\s+-]//g')
380 if [ "$LINE X" == " X" ]; then
381 return
382 fi
383 echo -e "$INDENT$*"
384 else
385 echo -e "\r$INDENT$*$CNORM"
386 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700387}
388
David Bainbridgeac7f8072019-08-01 22:15:33 +0000389if [ "$1" == "get" -a "$2" == "voltconfig" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000390 echo "$HOME/.volt/config-$NAME"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000391 exit
392fi
393
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -0700394if [ $# -ne 1 -o $(echo ":up:down:dump:" | grep -c ":$1:") -ne 1 ]; then
David Bainbridgeac7f8072019-08-01 22:15:33 +0000395 >&2 echo "What wouild you like to do today:"
396 >&2 echo " up - bring up voltha"
397 >&2 echo " down - tear down voltha"
398 >&2 echo " dump - create a debug dump of running system"
399 exit 1
400fi
401
David Bainbridge4f1b5562019-08-19 04:46:52 +0000402push_onos_config() {
Matteo Scandolo78dfee02020-02-13 16:18:03 -0800403 local TYPE=$1
404 local MSG=$2
405 local RESOURCE=$3
406 local DATA=$4
David Bainbridge4f1b5562019-08-19 04:46:52 +0000407
David K. Bainbridgeb4b163b2020-02-19 15:55:06 -0800408 # Thanks to the latest version of ONOS using the return code 207 this gets a
409 # whole lot nastier. Can't thank them enough for doing this. So in order to
410 # capture the command and the output in the log file as well as capture the
411 # status code to verify it is 200 and not 207 mutltiple files and a bit of
412 # hackery must be used. Thanks again ONOS.
413 local CMD_ECHO=$(mktemp -u)
414 local CMD_OUTPUT=$(mktemp -u)
415 local SC_OUTPUT=$(mktemp -u)
416
David Bainbridge4f1b5562019-08-19 04:46:52 +0000417 bspin - "$MSG $GEAR"
418 while true; do
Matteo Scandolo78dfee02020-02-13 16:18:03 -0800419 if [ $TYPE == "file" ]; then
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -0800420 (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
Matteo Scandolo78dfee02020-02-13 16:18:03 -0800421 fi
422 if [ $TYPE == "json" ]; then
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -0800423 (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
Matteo Scandolo78dfee02020-02-13 16:18:03 -0800424 fi
David K. Bainbridgeb4b163b2020-02-19 15:55:06 -0800425 RESULT=$?
426 # Dump everything to the log
427 cat $CMD_ECHO >> $LOG
428 cat $CMD_OUTPUT >> $LOG
429 SC=$(cat $SC_OUTPUT)
430
431 # clean up temp files
432 rm -f $CMD_ECHO $CMD_OUTPUT $SC_OUTPUT
433 if [ $RESULT -eq 0 -a "$SC" == "200" ]; then
David Bainbridge4f1b5562019-08-19 04:46:52 +0000434 break
435 fi
Matteo Scandolo9a77a732020-01-09 14:24:12 -0800436 sleep 1
David Bainbridge4f1b5562019-08-19 04:46:52 +0000437 sspin -
438 done
439 espin - $VERIFIED
440}
441
Matteo Scandolo9a77a732020-01-09 14:24:12 -0800442check_onos_app_active() {
443 local APP_ID=$1
444
445 bspin - "Checking that $APP_ID is active $CLOCK"
446 while true; do
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -0800447 (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
Matteo Scandolo9a77a732020-01-09 14:24:12 -0800448 if [ $? -eq 0 ]; then
449 break
450 fi
451 sleep 1
452 sspin -
453 done
454 sleep 5 # OSGI components take a little longer that the app to activate
455 espin - $VERIFIED
456}
457
David Bainbridge4f1b5562019-08-19 04:46:52 +0000458override_onos_app() {
459 local APP=$1
460 local NAME=$(basename $APP | sed -e 's/^[0-9][0-9]*-//g' -e 's/-.*$//g')
461 while true; do
462 sspin -
463 # Attempt to delete old version (if it exists)
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -0800464 (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 +0000465 sspin -
466 if [ $? -ne 0 ]; then
467 continue
468 fi
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -0800469 (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 +0000470 if [ $? -eq 0 ]; then
471 break
472 fi
473 sleep .2
474 done
475}
476
477activate_onos_app() {
478 local MSG="$1"
479 local APP=$2
480
481 bspin - "$MSG $GO"
482 while true; do
483 sspin -
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -0800484 (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 +0000485 if [ $? -eq 0 ]; then
486 break
487 fi
488 sleep .2
489 done
490 espin - "$VERIFIED"
491}
492
493count_pods() {
494 local NAMESPACE=$1; shift
495 if [ "$NAMESPACE" == "all-namespaces" ]; then
496 NAMESPACE="--all-namespaces"
497 else
498 NAMESPACE="-n $NAMESPACE"
499 fi
500 echo "$NAMESPACE" > /tmp/t
501 local STATES=$1; shift
502 echo "$STATES" >> /tmp/t
503 local PODS=$(kubectl get $NAMESPACE pod -o go-template="{{range .items}}{{.metadata.name}}/{{.status.phase}}/_{{range .status.containerStatuses}}{{.ready}}_{{end}} {{end}}")
504 local COUNT=0
505 local PATTERNS="$*"
506 for POD in $PODS; do
507 local NAME=$(echo $POD | cut -d/ -f 1)
508 local STATE=$(echo $POD | cut -d/ -f 2)
509 local CONTAINERS=$(echo $POD | cut -d/ -f 3 | sed -e 's/_/ /g')
510 if [ "$STATES" == "*" -o $(echo "$STATES" | grep -c ":$STATE:") -ne 0 ]; then
511 echo "IN WITH $POD" >> /tmp/t
512 local TOTAL=$(echo $CONTAINERS | wc -w)
513 local FOUND=$(echo $CONTAINERS | grep -o true | wc -l)
514 if [ $TOTAL -eq $FOUND ]; then
515 for PATTERN in $PATTERNS; do
516 echo "TEST $PATTERN AGAINST $NAME" >> /tmp/t
517 if [[ $NAME =~ $PATTERN ]]; then
518 echo "COUNT $NAME" >> /tmp/t
519 COUNT=$(expr $COUNT + 1)
520 break
521 fi
522 done
523 fi
524 fi
525 done
526 echo $COUNT >> /tmp/t
527 echo $COUNT
528}
529
530wait_for_pods() {
531 local INDENT=
532 if [ "$1" == "-" ]; then
533 INDENT=$1; shift
534 fi
535 local NAMESPACE=$1; shift
536 local EXPECT=$1; shift
537 local TYPE=$1; shift
538 local RETRY=$1; shift
539 local MESSAGE=$1; shift
540 local PATTERNS=$*
David Bainbridge99ac7a22019-08-31 02:26:43 +0000541 local STATES=":Running:"
542 if [ "$TYPE" == "not" ]; then
543 STATES="*"
544 fi
545 local HAVE=$(count_pods $NAMESPACE "$STATES" $PATTERNS)
David Bainbridge4f1b5562019-08-19 04:46:52 +0000546 local ALL=$HAVE
547 if [ "$TYPE" == "only" ]; then
548 ALL=$(count_pods "all-namespaces" "*" ".*")
549 fi
550 COUNT=$(expr 300 / 15)
551 bspin $INDENT $MESSAGE
552 sspin $INDENT
553 if [ $HAVE -ne $EXPECT -o $ALL -ne $HAVE ]; then
554 while [ $HAVE -ne $EXPECT -o $ALL -ne $HAVE ]; do
555 sspin $INDENT
556 COUNT=$(expr $COUNT - 1)
557 if [ $COUNT -eq 0 ]; then
David Bainbridge99ac7a22019-08-31 02:26:43 +0000558 HAVE=$(count_pods $NAMESPACE "$STATES" $PATTERNS)
David Bainbridge4f1b5562019-08-19 04:46:52 +0000559 ALL=$HAVE
560 if [ "$TYPE" == "only" ]; then
561 ALL=$(count_pods "all-namespaces" "*" ".*")
562 fi
563 COUNT=$(expr 300 / 15)
564 fi
565 sleep .15
566 done
567 fi
568 espin $INDENT $VERIFIED
569 if [ $HAVE -ne $EXPECT ]; then
570 return 1
571 fi
572 return 0
573}
574
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800575port_forward() {
576 local NS=$1
577 local SVC=$2
578 local FROM_PORT=$3
579 local TO_PORT=$4
580 local TAG=$SVC-$NAME
581
582 (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
583}
584
585kill_port_forward() {
586 local TAG=$1-$NAME
David Bainbridgec6871d22019-11-13 17:10:31 +0000587 local P_IDS=$(ps e -ww -A | grep "_TAG=$TAG" | grep -v grep | awk '{print $1}')
David Bainbridgebcf235b2019-11-12 21:33:58 +0000588 local PARENTS=
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800589 local KIDS=
David Bainbridgec6871d22019-11-13 17:10:31 +0000590 local UNKNOWN=
591 if [ ! -z "$P_IDS" ]; then
592 for P_ID in $P_IDS; do
593 local PP_ID=$(ps -o ppid $P_ID | tail -n +2)
594 if [ ! -z "$PP_ID" ]; then
595 if [ $PP_ID -eq 1 ]; then
596 PARENTS="$PARENTS $P_ID"
597 else
598 KIDS="$KIDS $P_ID"
599 fi
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800600 else
David Bainbridgec6871d22019-11-13 17:10:31 +0000601 UNKNOWN="$UNKNOWN $P_ID"
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800602 fi
603 done
David Bainbridgec6871d22019-11-13 17:10:31 +0000604 (set -x; kill -9 $PARENTS $KIDS $UNKNOWN >>$LOG 2>&1) >>$LOG 2>&1
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800605 fi
606}
607
David Bainbridgeac7f8072019-08-01 22:15:33 +0000608if [ "$1" == "down" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000609 echo "Tearing down voltha cluster $NAME"
610 LOG="down-$NAME.log"
611 echo $(date -u +"%Y%m%dT%H%M%SZ") >$LOG
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800612 bspin "Remove port-forwards: onos-ui-$NAME"
613 kill_port_forward onos-ui
614 sspin "Remove port-forwards: onos-ssh-$NAME$CEOL"
615 kill_port_forward onos-ssh
616 sspin "Remove port-forwards: voltha-api-$NAME$CEOL"
617 kill_port_forward voltha-api
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800618 sspin "Remove port-forwards: voltha-etcd-$NAME$CEOL"
619 kill_port_forward voltha-etcd-cluster-client
David K. Bainbridge00ecd382020-02-28 12:31:58 -0800620 sspin "Remove port-forwards: voltha-kafka-$NAME$CEOL"
621 kill_port_forward voltha-kafka
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800622 espin "$VERIFIED Remove port-forwards$CEOL"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000623 if [ $DEPLOY_K8S == "yes" ]; then
624 if [ -x ./bin/kind ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000625 bspin "Delete Kubernetes Kind Cluster"
626 (set -x; ./bin/kind delete cluster --name voltha-$NAME >>$LOG 2>&1) >>$LOG 2>&1
627 espin $VERIFIED
David Bainbridgeac7f8072019-08-01 22:15:33 +0000628 else
David Bainbridge0774b232019-08-02 06:37:19 +0000629 espin "$NO_ENTRY Delete Kubernetes Kind Cluster: kind command not found"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000630 fi
631 else
632 EXISTS=$(helm list -q)
633 EXPECT="etcd-operator onos open-olt open-onu sim voltha bbsim radius"
David Bainbridge0774b232019-08-02 06:37:19 +0000634 bspin "Remove Helm Deployments"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000635 for i in $EXISTS; do
636 if [ $(echo $EXPECT | grep -c $i) -eq 1 ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000637 sspin "Remove Helm Deployments: $i$CEOL"
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800638 (set -x; ./bin/helm delete --no-hooks --purge $i >>$LOG 2>&1) >>$LOG 2>&1
David Bainbridgeac7f8072019-08-01 22:15:33 +0000639 fi
640 done
David Bainbridge0774b232019-08-02 06:37:19 +0000641 espin "$VERIFIED Remove Helm Deployments$CEOL"
David Bainbridge4f1b5562019-08-19 04:46:52 +0000642 if [ "$WAIT_ON_DOWN" == "yes" ]; then
643 # There should only be 13 or 15 PODs in the kube-system name
644 # space and no other PODs
David Bainbridge4f1b5562019-08-19 04:46:52 +0000645 PODS="coredns-.* \
646 etcd-voltha-$NAME-control-plane \
647 kindnet-.* \
648 kube-apiserver-voltha-$NAME-control-plane \
649 kube-controller-manager-voltha-$NAME-control-plane \
650 kube-proxy-.* \
651 kube-scheduler-voltha-$NAME-control-plane \
652 tiller-deploy-.*"
653 EXPECT=$(test "$TYPE" == "minimal" && echo "13" || echo "15")
David Bainbridge99ac7a22019-08-31 02:26:43 +0000654 PODS="adapter-.* \
655 bbsim.* \
656 etcd-operator.* \
657 radius.* \
658 voltha-.*"
Matteo Scandolo73442f92020-01-29 09:53:22 -0800659
David Bainbridge99ac7a22019-08-31 02:26:43 +0000660 EXPECT=0
661
Matteo Scandolo73442f92020-01-29 09:53:22 -0800662 if [ "$WITH_ONOS" == "yes" ]; then
663 ONOS_PODS="onos-.*"
664 wait_for_pods "default" $EXPECT "not" -1 "Waiting for ONOS PODs to terminate" $ONOS_PODS
665 fi
David Bainbridge99ac7a22019-08-31 02:26:43 +0000666 wait_for_pods "voltha" $EXPECT "not" -1 "Waiting for VOLTHA PODs to terminate" $PODS
David Bainbridge4f1b5562019-08-19 04:46:52 +0000667 fi
David Bainbridgeac7f8072019-08-01 22:15:33 +0000668 fi
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -0700669 exit
David Bainbridgeac7f8072019-08-01 22:15:33 +0000670fi
671
672if [ "$1" == "dump" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000673 LOG="dump-$NAME.log"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000674 TS=$(date -u +"%Y%m%dT%H%M%SZ")
David Bainbridge76514a02019-10-08 01:50:35 +0000675 if [ ! -z "$DUMP_FROM" ]; then
676 TS=$(echo $DUMP_FROM | sed -e 's/[:-]//g')
677 fi
David Bainbridgeac7f8072019-08-01 22:15:33 +0000678 WORK=$(mktemp -u -d)
David Bainbridge0774b232019-08-02 06:37:19 +0000679 DATA=$WORK/voltha-debug-dump-$NAME-$TS
David Bainbridgeac7f8072019-08-01 22:15:33 +0000680 mkdir -p $DATA
681 echo $TS > $LOG
David Bainbridge0774b232019-08-02 06:37:19 +0000682 echo -e "Capturing debug dump to voltha-debug-dump-$NAME-$TS.tgz"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000683 bspin - "Copy install log"
David Bainbridge0774b232019-08-02 06:37:19 +0000684 if [ -f install-$NAME.log ]; then
685 (set -x; cp install-$NAME.log $DATA/install-$NAME.log) >>$LOG 2>&1
David Bainbridgeac7f8072019-08-01 22:15:33 +0000686 espin - $VERIFIED
687 else
David Bainbridge0774b232019-08-02 06:37:19 +0000688 espin - "$NO_ENTRY Copy install log: install-$NAME.log not found"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000689 fi
690 bspin - "Dumping Kubernetes PODs"
691 (set -x; kubectl get --all-namespaces pods >> $DATA/all-pods.txt 2>&1) >>$LOG 2>&1
692 espin - $VERIFIED
693 bspin - "Dumping Kubernetes SERVICEs"
694 (set -x; kubectl get --all-namespaces svc >> $DATA/all-services.txt 2>&1) >>$LOG 2>&1
695 espin - $VERIFIED
696 bspin - "Dumping Kubernetes EVENTs"
697 (set -x; kubectl get --all-namespaces events >> $DATA/all-events.txt 2>&1) >>$LOG 2>&1
698 espin - $VERIFIED
699 bspin - "Dumping VOLTHA POD details"
Matteo Scandolodcd29f52019-10-07 15:42:42 -0700700 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 +0000701 SINCE=
702 if [ ! -z "$DUMP_FROM" ]; then
703 SINCE="--since-time=$DUMP_FROM"
704 fi
David Bainbridgeac7f8072019-08-01 22:15:33 +0000705 for POD in $PODS; do
David Bainbridge1f0655a2019-10-01 22:08:48 +0000706 NS=$(echo $POD | cut -d: -f1)
707 POD=$(echo $POD | cut -d: -f2)
David Bainbridgeac7f8072019-08-01 22:15:33 +0000708 sspin - "Dumping VOLTHA POD details: $POD$CEOL"
709 mkdir -p $DATA/$POD
David Bainbridge1f0655a2019-10-01 22:08:48 +0000710 (set -x; kubectl describe -n $NS $POD >> $DATA/$POD/describe.txt 2>&1) >>$LOG 2>&1
David Bainbridgeac7f8072019-08-01 22:15:33 +0000711 sspin - "Dumping VOLTHA POD details: $POD"
David Bainbridgecfd7ca12019-10-06 03:31:41 +0000712 (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 +0000713 sspin - "Dumping VOLTHA POD details: $POD"
David Bainbridgecfd7ca12019-10-06 03:31:41 +0000714 (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 +0000715 sspin - "Dumping VOLTHA POD details: $POD"
716 done
717 espin - "$VERIFIED Dumping VOLTHA POD details$CEOL"
718 bspin - "Dumping ETCD"
719 if [ "$(which etcdctl) X" != " X" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000720 (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 +0000721 espin - $VERIFIED
722 else
723 espin - "$NO_ENTRY Dumping ETCD: etcdctl command not available"
724 fi
David Bainbridge0774b232019-08-02 06:37:19 +0000725 bspin - "Creating compressed TAR: voltha-debug-dump-$NAME-$TS.tgz"
726 (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 +0000727 espin - $VERIFIED
728 bspin - "Cleanup"
729 (set -x; rm -rf $WORK) >>$LOG 2>&1
730 espin - $VERIFIED
David Bainbridge0774b232019-08-02 06:37:19 +0000731 bspin - "$(ls -l voltha-debug-dump-$NAME-$TS.tgz)"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000732 espin - $VERIFIED
733 exit
734fi
735
David Bainbridge0774b232019-08-02 06:37:19 +0000736LOG="install-$NAME.log"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000737date > $LOG
David Bainbridge0774b232019-08-02 06:37:19 +0000738echo "PORTS=$ONOS_API_PORT,$ONOS_SSH_PORT,$VOLTHA_API_PORT,$VOLTHA_SSH_PORT,$VOLTHA_ETCD_PORT" >> $LOG
David Bainbridgeac7f8072019-08-01 22:15:33 +0000739
740# Output install options to log
741echo "OPTIONS" >> $LOG
David Bainbridgeac7f8072019-08-01 22:15:33 +0000742for O in $ALL_OPTIONS; do
743 VAL=$(eval echo \$$O)
David Bainbridgeac7f8072019-08-01 22:15:33 +0000744 if [ ! -z "$VAL" ]; then
745 printf " %-30s = %s\n" $O $VAL >> $LOG
746 fi
747done
748
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -0700749helm_install() {
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700750 local INDENT=
751 if [ "$1" == "-" ]; then
752 INDENT=$1; shift
753 fi
754 local NAMESPACE=$1; shift
David Bainbridge0774b232019-08-02 06:37:19 +0000755 local INAME=$1; shift
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700756 local CHART=$1; shift
David Bainbridge90fd8e32019-08-21 23:32:47 +0000757 local CHART_VERSION=$1; shift
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700758 local MESSAGE=$*
759
David Bainbridge90fd8e32019-08-21 23:32:47 +0000760 if [ "$CHART_VERSION X" != " X" -a "$CHART_VERSION" != "latest" ]; then
761 CHART_VERSION="--version $CHART_VERSION"
762 else
763 CHART_VERSION=
764 fi
765
David Bainbridge99ac7a22019-08-31 02:26:43 +0000766 local CHART_ARGS=
767 if [ -r "${INAME}-values.yaml" ]; then
768 CHART_ARGS="-f ${INAME}-values.yaml"
769 fi
770
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700771 COUNT=$(expr 300 / 15)
772 bspin $INDENT $MESSAGE
David Bainbridge70c0ea82019-11-14 23:25:26 +0000773 (set -x; helm install -f $NAME-values.yaml $CHART_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 -0700774 SUCCESS=$?
775 while [ $SUCCESS -ne 0 ]; do
776 sspin $INDENT
777 COUNT=$(expr $COUNT - 1)
778 if [ $COUNT -eq 0 ]; then
Andy Baviere22ff252019-12-19 11:40:31 -0700779 (set -x; helm delete --purge $INAME >>$LOG 2>&1) >>$LOG 2>&1
David Bainbridge99ac7a22019-08-31 02:26:43 +0000780 (set -x; helm install -f $NAME-values.yaml $CHART_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 -0700781 SUCCESS=$?
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700782 COUNT=$(expr 300 / 15)
783 fi
784 sleep .15
785 done
786 espin $INDENT $VERIFIED
787}
788
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700789echo "INSTALL TYPE: $TYPE" >> $LOG
790
791bspin "Verify GOPATH"
792export GOPATH=$(pwd)
Test User3d7ad8e2019-07-03 06:15:44 +0000793mkdir -p $GOPATH/bin
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700794espin $VERIFIED
795
David Bainbridgee87067b2019-08-12 22:00:12 +0000796STIME=$(date +%s)
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700797if [ "$INSTALL_KUBECTL" == "no" ]; then
798 bspin "Skip kubectl install"
799 espin $NO_ENTRY
Test Userc13bdc92019-07-03 20:57:49 +0000800else
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700801 bspin "Verify kubectl $HELM"
802 if [ -x $GOPATH/bin/kubectl ]; then
803 espin $VERIFIED
804 else
805 espin $NOT_VERIFIED
806 bspin - "Download and install Kubernetes/kubectl $DOWNLOAD"
807 (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
808 (set -x; chmod 755 $GOPATH/bin/kubectl >>$LOG 2>&1) >>$LOG 2>&1
809 espin - $VERIFIED
810 fi
Test Userc13bdc92019-07-03 20:57:49 +0000811fi
David Bainbridgee87067b2019-08-12 22:00:12 +0000812if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +0000813 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +0000814fi
Test Userc13bdc92019-07-03 20:57:49 +0000815
David Bainbridgee87067b2019-08-12 22:00:12 +0000816STIME=$(date +%s)
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700817if [ "$DEPLOY_K8S" == "no" ]; then
818 bspin "Skip Kubernetes/Kind Deployment"
819 espin $NO_ENTRY
820else
Test Userba1e7e72019-07-10 22:27:54 +0000821 bspin "Verify Kubernetes/Kind $HELM"
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800822 IS_INSTALLED=0
823 OP_TYPE="install"
Test Userba1e7e72019-07-10 22:27:54 +0000824 if [ -x $GOPATH/bin/kind ]; then
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800825 OP_TYPE="upgrade"
826 if [ $($GOPATH/bin/kind --version | grep -c $KIND_VERSION) -eq 1 ]; then
827 IS_INSTALLED=1
828 espin $VERIFIED
829 fi
830 fi
831 if [ $IS_INSTALLED -eq 0 ]; then
Test Userba1e7e72019-07-10 22:27:54 +0000832 espin $NOT_VERIFIED
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800833 bspin - "Download and $OP_TYPE Kubernetes/kind $DOWNLOAD"
David Bainbridge9e2a6662019-07-11 17:07:57 +0000834 (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 +0000835 (set -x; chmod 755 $GOPATH/bin/kind >>$LOG 2>&1) >>$LOG 2>&1
836 espin - $VERIFIED
837 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700838fi
839
David Bainbridgee87067b2019-08-12 22:00:12 +0000840if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +0000841 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +0000842fi
843
844STIME=$(date +%s)
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700845if [ "$INSTALL_HELM" == "no" ]; then
846 bspin "Skip Helm Install"
847 espin $NO_ENTRY
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700848else
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700849 bspin "Verify Helm $HELM"
850 if [ -x $GOPATH/bin/helm ]; then
851 espin $VERIFIED
852 else
853 espin $NOT_VERIFIED
854 bspin - "Download and install Helm $DOWNLOAD"
David Bainbridgec6a6eb62019-10-18 22:50:07 +0000855 (set -x; curl -sSL https://git.io/get_helm.sh | DESIRED_VERSION=v2.14.3 USE_SUDO=false HELM_INSTALL_DIR=$GOPATH/bin bash >>$LOG 2>&1) >>$LOG 2>&1
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700856 espin - $VERIFIED
857 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700858fi
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800859
David Bainbridgee87067b2019-08-12 22:00:12 +0000860if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +0000861 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +0000862fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700863
David Bainbridgee87067b2019-08-12 22:00:12 +0000864STIME=$(date +%s)
Test Userb5712372019-07-03 21:52:17 +0000865bspin "Verify voltctl $HIGH_VOLTAGE"
David Bainbridged2811972019-12-14 01:14:09 +0000866VOK=0
867VMESSAGE="install"
David K. Bainbridgeebf38d92020-02-10 10:46:31 -0800868export VC_VERSION="$VOLTCTL_VERSION"
869if [ "$VC_VERSION" == "latest" ]; then
870 export VC_VERSION=$(curl -sSL https://api.github.com/repos/opencord/voltctl/releases/latest | jq -r .tag_name | sed -e 's/^v//g')
871fi
Test User3d7ad8e2019-07-03 06:15:44 +0000872if [ -x $GOPATH/bin/voltctl ]; then
David Bainbridge1ba64f12019-12-18 00:40:13 +0000873 VHAVE=$($GOPATH/bin/voltctl version --clientonly -o json | jq -r .version)
David K. Bainbridgeebf38d92020-02-10 10:46:31 -0800874 if [ $? -eq 0 -a "$VHAVE" == "$VC_VERSION" ]; then
David Bainbridged2811972019-12-14 01:14:09 +0000875 VOK=1
David Bainbridge1ba64f12019-12-18 00:40:13 +0000876 espin $VERIFIED
877 else
David K. Bainbridgeebf38d92020-02-10 10:46:31 -0800878 VCHECK=$(echo -e "$VHAVE\n$VC_VERSION" | sort -V | head -1)
879 if [ "$VCHECK" == "$VHAVE" ]; then
880 VMESSAGE="upgrade"
881 else
882 VMESSAGE="downgrade"
883 fi
David Bainbridged2811972019-12-14 01:14:09 +0000884 fi
885fi
886
David Bainbridge1ba64f12019-12-18 00:40:13 +0000887if [ $VOK -eq 0 ]; then
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700888 espin $NOT_VERIFIED
David Bainbridged2811972019-12-14 01:14:09 +0000889 bspin - "Download and $VMESSAGE voltctl $DOWNLOAD"
David K. Bainbridgeebf38d92020-02-10 10:46:31 -0800890 (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 +0000891 (set -x; chmod 755 $GOPATH/bin/voltctl >>$LOG 2>&1) >>$LOG 2>&1
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700892 espin - $VERIFIED
893fi
David Bainbridgee87067b2019-08-12 22:00:12 +0000894if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +0000895 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +0000896fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700897
898bspin "Verify command PATH"
Test Userba1e7e72019-07-10 22:27:54 +0000899export PATH=$GOPATH/bin:$PATH
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700900espin $VERIFIED
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700901
David Bainbridgee87067b2019-08-12 22:00:12 +0000902STIME=$(date +%s)
Test Userba1e7e72019-07-10 22:27:54 +0000903if [ "$DEPLOY_K8S" == "yes" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000904 HAVE=$(kind get clusters | grep -c voltha-$NAME)
Test Userba1e7e72019-07-10 22:27:54 +0000905 bspin "Verify Kubernetes/Kind Cluster"
906 sspin
907 if [ $HAVE -eq 0 ]; then
David Bainbridge491b1bd2019-07-11 17:53:11 +0000908 espin $NOT_VERIFIED
909 bspin - "Verify cluster configuration"
David Bainbridge0774b232019-08-02 06:37:19 +0000910 if [ ! -r ./$NAME-cluster.cfg ]; then
David Bainbridge491b1bd2019-07-11 17:53:11 +0000911 espin - $NOT_VERIFIED
David Bainbridge0774b232019-08-02 06:37:19 +0000912 bspin - "Download cluster configuration: $TYPE-cluster.cfg to $NAME-cluster.cfg $DOWNLOAD"
David K. Bainbridgea00736b2020-01-08 14:33:17 -0800913 ERR_OUT=$(mktemp)
914 (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
915 if [ $? -ne 0 ]; then
916 espin - $THEX
917 echo -e "${RED}${BOLD}${ERROR}ERROR: $NAME-cluster.cfg${NORMAL}${RED} - $(cat $ERR_OUT)${NORMAL}"
918 echo "ERROR: $(cat $ERR_OUT)" >>$LOG
919 rm -rf $ERR_OUT ./$NAME-cluster.cfg
920 exit 1
921 fi
922 rm -rf $ERR_OUT
923 else
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700924 espin - $VERIFIED
David K. Bainbridgea00736b2020-01-08 14:33:17 -0800925 fi
David Bainbridge0774b232019-08-02 06:37:19 +0000926 kind create cluster --name voltha-$NAME --config $NAME-cluster.cfg
David Bainbridge491b1bd2019-07-11 17:53:11 +0000927 else
928 espin $VERIFIED
Test Userba1e7e72019-07-10 22:27:54 +0000929 fi
930
David Bainbridge0774b232019-08-02 06:37:19 +0000931 export KUBECONFIG="$(kind get kubeconfig-path --name="voltha-$NAME")"
Test Userba1e7e72019-07-10 22:27:54 +0000932 P="coredns-.* \
David Bainbridge0774b232019-08-02 06:37:19 +0000933 etcd-voltha-$NAME-control-plane \
Test Userba1e7e72019-07-10 22:27:54 +0000934 kindnet-.* \
David Bainbridge0774b232019-08-02 06:37:19 +0000935 kube-apiserver-voltha-$NAME-control-plane \
936 kube-controller-manager-voltha-$NAME-control-plane \
Test Userba1e7e72019-07-10 22:27:54 +0000937 kube-proxy-.* \
David Bainbridge0774b232019-08-02 06:37:19 +0000938 kube-scheduler-voltha-$NAME-control-plane"
Test Userba1e7e72019-07-10 22:27:54 +0000939
940 EXPECT=$(test "$TYPE" == "minimal" && echo "12" || echo "14")
David Bainbridge4f1b5562019-08-19 04:46:52 +0000941 wait_for_pods - "kube-system" $EXPECT "includes" -1 "Waiting for system PODs to start" $P
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700942fi
David Bainbridgee87067b2019-08-12 22:00:12 +0000943if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +0000944 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +0000945fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700946
David Bainbridgee87067b2019-08-12 22:00:12 +0000947STIME=$(date +%s)
David Bainbridge4c6289c2019-09-03 21:11:32 +0000948COUNT=$(count_pods "kube-system" ":Running:" "tiller-deploy-.*")
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700949bspin "Verify Helm"
Test Userba1e7e72019-07-10 22:27:54 +0000950if [ $COUNT -ne 1 ]; then
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700951 espin $NOT_VERIFIED
Test Userb5712372019-07-03 21:52:17 +0000952 echo -e "Configuring Helm $GEAR"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700953 if [ "$INSTALL_HELM" == "no" ]; then
954 bspin - "Skip Helm/Tiller Initialization"
955 espin - $NO_ENTRY
956 else
957 bspin - "Initialize Helm"
958 (set -x; helm init --upgrade >>$LOG 2>&1) >>$LOG 2>&1
959 espin - $VERIFIED
David Bainbridge4f1b5562019-08-19 04:46:52 +0000960 wait_for_pods - "kube-system" 1 "includes" -1 "Waiting for Tiller POD to start" "tiller-deploy-.*"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700961 fi
Test Userb5712372019-07-03 21:52:17 +0000962 bspin - "Add Google Incubator repository to Helm"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700963 (set -x; helm repo add incubator https://kubernetes-charts-incubator.storage.googleapis.com >>$LOG 2>&1) >>$LOG 2>&1
964 espin - $VERIFIED
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -0700965
Test Userba1e7e72019-07-10 22:27:54 +0000966 # HACK (sort-of) - the config for tiller is about to be patched, which will
967 # cause the tiller pod to be recreated. This can sometimes cause a timing
968 # issue with the "wait_for_pods" call on tiller as it may incorrectly
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -0700969 # identify the running/ready tiller pod that is soon to be terminated as
Test Userba1e7e72019-07-10 22:27:54 +0000970 # what it is waiting for. To avoid this issue we do a clean scale down and
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -0700971 # scale up of the pod so the script controlls when it should be expecting
Test Userba1e7e72019-07-10 22:27:54 +0000972 # things
973 (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 -0700974
Test Userb5712372019-07-03 21:52:17 +0000975 bspin - "Add Google Stable repository to Helm"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700976 (set -x; helm repo add stable https://kubernetes-charts.storage.googleapis.com >>$LOG 2>&1) >>$LOG 2>&1
977 espin - $VERIFIED
Test Userb5712372019-07-03 21:52:17 +0000978 bspin - "Add ONF repository to Helm"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700979 (set -x; helm repo add onf https://charts.opencord.org >>$LOG 2>&1) >>$LOG 2>&1
980 espin - $VERIFIED
Test Userb5712372019-07-03 21:52:17 +0000981 bspin - "Update Helm repository cache"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700982 (set -x; helm repo update >>$LOG 2>&1) >>$LOG 2>&1
983 espin - $VERIFIED
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -0700984
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700985 # Create and k8s service account so that Helm can create pods
Test Userb5712372019-07-03 21:52:17 +0000986 bspin - "Create Tiller ServiceAccount"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700987 (set -x; kubectl create serviceaccount --namespace kube-system tiller >>$LOG 2>&1) >>$LOG 2>&1
988 espin - $VERIFIED
Test Userb5712372019-07-03 21:52:17 +0000989 bspin - "Create Tiller ClusterRoleBinding"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700990 (set -x; kubectl create clusterrolebinding tiller-cluster-rule --clusterrole=cluster-admin --serviceaccount=kube-system:tiller >>$LOG 2>&1) >>$LOG 2>&1
991 espin - $VERIFIED
Test Userb5712372019-07-03 21:52:17 +0000992 bspin - "Update Tiller Manifest"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700993 (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 +0000994
995 # HACK (sort-of) - part to, spin it back up
996 (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 -0700997 espin - $VERIFIED
998else
999 espin $VERIFIED
David Bainbridge46505fb2019-10-01 21:13:20 +00001000 if [ "$UPDATE_HELM_REPOS" == "yes" ]; then
1001 bspin - "Update Helm repository cache"
1002 (set -x; helm repo update >>$LOG 2>&1) >>$LOG 2>&1
1003 espin - $VERIFIED
1004 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001005fi
David Bainbridge4f1b5562019-08-19 04:46:52 +00001006wait_for_pods - "kube-system" 1 "includes" -1 "Waiting for Tiller POD to start" "tiller-deploy-.*"
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
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001010
David Bainbridgee87067b2019-08-12 22:00:12 +00001011STIME=$(date +%s)
David Bainbridge0774b232019-08-02 06:37:19 +00001012bspin "Verify Helm values file: $NAME-values.yaml"
1013if [ ! -r "./$NAME-values.yaml" ]; then
Test Userba1e7e72019-07-10 22:27:54 +00001014 espin $NOT_VERIFIED
David Bainbridge0774b232019-08-02 06:37:19 +00001015 bspin - "Download Helm values file: $TYPE-values.yaml to $NAME-values.yaml $DOWNLOAD"
David K. Bainbridgea00736b2020-01-08 14:33:17 -08001016 ERR_OUT=$(mktemp)
1017 (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
1018 if [ $? -ne 0 ]; then
1019 espin - $THEX
1020 echo -e "${RED}${BOLD}${ERROR}ERROR: $NAME-values.yaml${NORMAL}${RED} - $(cat $ERR_OUT)${NORMAL}"
1021 echo "ERROR: $(cat $ERR_OUT)" >>$LOG
1022 rm -rf $ERR_OUT ./$NAME-values.yaml
1023 exit 1
1024 fi
1025 rm -rf $ERR_OUT
Test Userba1e7e72019-07-10 22:27:54 +00001026 espin - $VERIFIED
1027else
1028 espin $VERIFIED
1029fi
David Bainbridgee87067b2019-08-12 22:00:12 +00001030if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +00001031 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +00001032fi
Test Userba1e7e72019-07-10 22:27:54 +00001033
David Bainbridge99ac7a22019-08-31 02:26:43 +00001034STIME=$(date +%s)
1035bspin "Verify or download chart specific values files $DOWNLOAD"
1036VALUES_FILES="monkey-values.yaml"
David K. Bainbridgea00736b2020-01-08 14:33:17 -08001037ERR_OUT=$(mktemp)
David Bainbridge99ac7a22019-08-31 02:26:43 +00001038for i in $VALUES_FILES; do
1039 if [ ! -r ./$i ]; then
David K. Bainbridgea00736b2020-01-08 14:33:17 -08001040 (set -x; curl --fail -o ./$i -sSL https://raw.githubusercontent.com/ciena/kind-voltha/$VK_RELEASE/$i >>$LOG 2>$ERR_OUT) >>$LOG 2>&1
1041 if [ $? -ne 0 ]; then
1042 espin $THEX
1043 echo -e "${RED}${BOLD}${ERROR}ERROR: $i${NORMAL}${RED} - $(cat $ERR_OUT)${NORMAL}"
1044 echo "ERROR: $i - $(cat $ERR_OUT)" >>$LOG
1045 rm -rf $ERR_OUT ./$i
1046 exit 1
1047 fi
1048 rm -rf $ERR_OUT
David Bainbridge99ac7a22019-08-31 02:26:43 +00001049 fi
1050done
1051espin $VERIFIED
1052if [ "$WITH_TIMINGS" == "yes" ]; then
1053 printtime $(expr $(date +%s) - $STIME)
1054fi
1055
1056if [ "$WITH_CHAOS" == "yes" ]; then
1057 bspin "Verify or clone kube-monkey helm chart $DOWNLOAD"
1058 if [ -r ./kube-monkey ]; then
1059 espin $VERIFIED
1060 else
1061 espin $NOT_VERIFIED
1062 bspin - "GIT clone kube-monkey"
1063 (set -x; git clone https://github.com/asobti/kube-monkey kube-monkey >>$LOG 2>&1) >>$LOG 2>&1
1064 espin - $VERIFIED
1065 fi
1066fi
1067
Test Userba1e7e72019-07-10 22:27:54 +00001068if [ "$JUST_K8S" == "yes" ]; then
1069 echo "Environment deployed, not deploying VOLTHA artifacts as requested. Good bye."
1070 echo ""
1071 echo "Please issue the following commands in your terminal to ensure that you" | tee -a $LOG
1072 echo "are accessing the correct Kubernetes/Kind cluster as well as have the " | tee -a $LOG
1073 echo "tools required by VOLTHA in your command path. " | tee -a $LOG
1074 echo "" | tee -a $LOG
1075 echo -en $BOLD
1076 if [ $DEPLOY_K8S == "yes" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +00001077 echo "export KUBECONFIG=\"\$(./bin/kind get kubeconfig-path --name=\"voltha-$NAME\")\"" | tee -a $LOG
Test Userba1e7e72019-07-10 22:27:54 +00001078 fi
1079 echo "export PATH=$GOPATH/bin:\$PATH" | tee -a $LOG
1080 echo -en $NORMAL
1081 echo "" | tee -a $LOG
1082 echo "Thank you for choosing kind-voltha for you quick cluster needs." | tee -a $LOG
1083 exit 0
1084fi
1085
David Bainbridgee87067b2019-08-12 22:00:12 +00001086STIME=$(date +%s)
Test Userb5712372019-07-03 21:52:17 +00001087bspin "Verify ETCD Operator $OLD_KEY"
Test User7d866122019-07-09 17:52:35 +00001088if [ $(helm list --deployed --short --namespace voltha "^etcd-operator\$" | wc -l) -ne 1 ]; then
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001089 espin $NOT_VERIFIED
David Bainbridge90fd8e32019-08-21 23:32:47 +00001090 helm_install - voltha etcd-operator stable/etcd-operator latest "Install ETCD Operator"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001091else
1092 espin $VERIFIED
1093fi
Test User01ed0642019-07-03 20:17:06 +00001094EXPECT=$(test "$TYPE" == "minimal" && echo "1" || echo "3")
David Bainbridge4f1b5562019-08-19 04:46:52 +00001095wait_for_pods - "voltha" $EXPECT "includes" -1 "Waiting for ETCD Operator to start" "etcd-operator-.*"
David Bainbridgee87067b2019-08-12 22:00:12 +00001096if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +00001097 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +00001098fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001099
David Bainbridgee87067b2019-08-12 22:00:12 +00001100STIME=$(date +%s)
David Bainbridgeb270c202019-07-26 01:44:42 +00001101if [ $WITH_ONOS == "yes" ]; then
1102 bspin "Verify ONOS installed $BIRD"
1103 if [ $(helm list --deployed --short --namespace default "^onos\$" | wc -l) -ne 1 ]; then
1104 espin $NOT_VERIFIED
Andrea Campanella6afcb082019-12-18 16:51:30 -08001105 EXTRA_HELM_FLAGS="$SET_TAG $EXTRA_HELM_FLAGS" helm_install - default onos onf/onos $ONOS_CHART_VERSION "Install ONOS"
David Bainbridgeb270c202019-07-26 01:44:42 +00001106 else
1107 espin $VERIFIED
1108 fi
David Bainbridge4f1b5562019-08-19 04:46:52 +00001109 wait_for_pods - "default" 1 "includes" -1 "Waiting for ONOS to start" "onos-.*"
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001110
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -08001111 if [ $WITH_PORT_FORWARDS == "yes" ]; then
1112 bspin - "Forward ONOS API port $FORWARD"
1113 kill_port_forward onos-ui
1114 port_forward default onos-ui $ONOS_API_PORT 8181
1115 espin - $VERIFIED
1116 bspin - "Forward ONOS SSH port $FORWARD"
1117 kill_port_forward onos-ssh
1118 port_forward default onos-ssh $ONOS_SSH_PORT 8101
1119 espin - $VERIFIED
1120 _ONOS_API_EP="127.0.0.1:$ONOS_API_PORT"
1121 else
1122 _ONOS_API_EP=$(get_service_ep default onos-ui)
1123 fi
David Bainbridged31d6122019-08-13 19:37:59 +00001124 bspin - "Verify or download ONOS configuration support files $DOWNLOAD"
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001125 ONOS_FILES="olt-onos-enableExtraneousRules.json onos-aaa.json \
David Bainbridge90fd8e32019-08-21 23:32:47 +00001126 onos-dhcpl2relay.json onos-kafka.json onos-sadis-sample.json"
David Bainbridged31d6122019-08-13 19:37:59 +00001127 (set -x; mkdir -p ./onos-files >>$LOG 2>&1) >>$LOG 2>&1
David K. Bainbridgea00736b2020-01-08 14:33:17 -08001128 ERR_OUT=$(mktemp)
David Bainbridge2b19e832019-08-16 02:40:53 +00001129 for i in $ONOS_FILES; do
David Bainbridged31d6122019-08-13 19:37:59 +00001130 if [ ! -r ./onos-files/$i ]; then
David K. Bainbridgea00736b2020-01-08 14:33:17 -08001131 (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
1132 if [ $? -ne 0 ]; then
1133 espin - $THEX
1134 echo -e "${RED}${BOLD}${ERROR}ERROR: $i${NORMAL}${RED} - $(cat $ERR_OUT)${NORMAL}"
1135 echo "ERROR: $(cat $ERR_OUT)" >>$LOG
1136 rm -rf $ERR_OUT ./onos-files/$i
1137 exit 1
1138 fi
1139 rm -rf $ERR_OUT
David Bainbridged31d6122019-08-13 19:37:59 +00001140 fi
1141 done
Test Userba1e7e72019-07-10 22:27:54 +00001142 espin - $VERIFIED
David Bainbridge27790d62019-08-13 22:43:19 +00001143
1144 if [ $INSTALL_ONOS_APPS == "yes" ]; then
1145 bspin - "Installing custom ONOS applications"
1146 if [ -x onos-files/onos-apps -a $(ls -1 onos-files/onos-apps/*.oar 2>/dev/null | wc -l) -gt 0 ]; then
1147 for OAR in $(ls -1 onos-files/onos-apps/*.oar); do
1148 sspin - "Installing custom ONOS applications - $OAR$CEOL"
David Bainbridge2b19e832019-08-16 02:40:53 +00001149 override_onos_app $OAR
David Bainbridge27790d62019-08-13 22:43:19 +00001150 done
1151 espin - "$VERIFIED Installing custom ONOS applications$CEOL"
1152 else
1153 espin - "$NOT_VERIFIED Installing custom ONOS applications - None Found"
1154 fi
1155 fi
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001156
Matteo Scandolo9a77a732020-01-09 14:24:12 -08001157 check_onos_app_active org.opencord.kafka
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001158 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 -08001159 check_onos_app_active org.opencord.dhcpl2relay
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001160 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 -08001161 check_onos_app_active org.opencord.olt
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001162 # FIXME use WITH_DHCP and WITH_EAPOL flags to configre OLT App
Hardik Windlassa7501fb2020-02-17 14:28:20 +00001163 # Default value for "enableEapol" is true in OLT App
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001164 if [ $WITH_EAPOL == "yes" ]; then
1165 push_onos_config "json" "Enable VOLTHA ONOS EAPOL provisioning" "configuration/org.opencord.olt.impl.OltFlowService" '{"enableEapol":true}'
Hardik Windlassa7501fb2020-02-17 14:28:20 +00001166 elif [ $WITH_EAPOL == "no" ]; then
1167 push_onos_config "json" "Disable VOLTHA ONOS EAPOL provisioning" "configuration/org.opencord.olt.impl.OltFlowService" '{"enableEapol":false}'
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001168 fi
Hardik Windlassa7501fb2020-02-17 14:28:20 +00001169 # Default value for "enableDhcpOnProvisioning" is false and for "enableDhcpV4" is true in OLT App
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001170 if [ $WITH_DHCP == "yes" ]; then
1171 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 +00001172 elif [ $WITH_DHCP == "no" ]; then
1173 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 -08001174 fi
Hardik Windlassa7501fb2020-02-17 14:28:20 +00001175 # Default value for "enableIgmpOnProvisioning" is false in OLT App
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001176 if [ $WITH_IGMP == "yes" ]; then
1177 push_onos_config "json" "Enable VOLTHA ONOS IGMP provisioning" "configuration/org.opencord.olt.impl.OltFlowService" '{"enableIgmpOnProvisioning":true}'
Hardik Windlassa7501fb2020-02-17 14:28:20 +00001178 elif [ $WITH_IGMP == "no" ]; then
1179 push_onos_config "json" "Disable VOLTHA ONOS IGMP provisioning" "configuration/org.opencord.olt.impl.OltFlowService" '{"enableIgmpOnProvisioning":false}'
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001180 fi
David K. Bainbridge484d80c2020-03-05 21:44:34 -08001181 if [ $ENABLE_ONOS_EXTRANEOUS_RULES == "yes" ]; then
1182 push_onos_config "file" "Enabling extraneous rules for ONOS" "configuration/org.onosproject.net.flow.impl.FlowRuleManager" "onos-files/olt-onos-enableExtraneousRules.json"
1183 fi
David Bainbridge2b19e832019-08-16 02:40:53 +00001184 if [ -f onos-files/onos-sadis.json ]; then
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001185 push_onos_config "file" "[optional] Push ONOS SADIS Configuration" "network/configuration/apps/org.opencord.sadis" "onos-files/onos-sadis.json"
David Bainbridge2b19e832019-08-16 02:40:53 +00001186 elif [ "$CONFIG_SADIS" == "yes" ]; then
David Bainbridge90fd8e32019-08-21 23:32:47 +00001187 SADIS_CFG=onos-files/onos-sadis-sample.json
Matteo Scandolo9a77a732020-01-09 14:24:12 -08001188 check_onos_app_active org.opencord.sadis
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001189 push_onos_config "file" "[optional] Push ONOS SADIS Configuration" "network/configuration/apps/org.opencord.sadis" "$SADIS_CFG"
David Bainbridge2b19e832019-08-16 02:40:53 +00001190 fi
Test Userba1e7e72019-07-10 22:27:54 +00001191fi
David Bainbridgee87067b2019-08-12 22:00:12 +00001192if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +00001193 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +00001194fi
Test Userba1e7e72019-07-10 22:27:54 +00001195
David Bainbridgee87067b2019-08-12 22:00:12 +00001196STIME=$(date +%s)
Test Userb5712372019-07-03 21:52:17 +00001197bspin "Verify VOLTHA installed $HIGH_VOLTAGE"
Test User7d866122019-07-09 17:52:35 +00001198if [ $(helm list --deployed --short --namespace voltha "^voltha\$" | wc -l) -ne 1 ]; then
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001199 espin $NOT_VERIFIED
David Bainbridge70c0ea82019-11-14 23:25:26 +00001200 if [ "$ONLY_ONE" == "yes" ]; then
1201 EXTRA_HELM_INSTALL_ARGS="--set therecanbeonlyone=true"=
1202 fi
David Bainbridge90fd8e32019-08-21 23:32:47 +00001203 helm_install - voltha voltha $VOLTHA_CHART $VOLTHA_CHART_VERSION "Install VOLTHA Core"
David Bainbridge70c0ea82019-11-14 23:25:26 +00001204 EXTRA_HELM_INSTALL_ARGS=
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001205else
1206 espin $VERIFIED
1207fi
Test Userba1e7e72019-07-10 22:27:54 +00001208
David Bainbridge90fd8e32019-08-21 23:32:47 +00001209VOLTHA="voltha-ofagent-.* \
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001210 ro-core.* \
1211 rw-core.* \
1212 voltha-api-server-.* \
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001213 voltha-etcd-cluster-.* \
1214 voltha-kafka-.* \
1215 voltha-zookeeper-.*"
David Bainbridge70c0ea82019-11-14 23:25:26 +00001216if [ "$ONLY_ONE" == "yes" ]; then
David Bainbridge1ba64f12019-12-18 00:40:13 +00001217 EXPECT=$(test "$TYPE" == "minimal" && echo "5" || echo "7")
David Bainbridge70c0ea82019-11-14 23:25:26 +00001218else
David Bainbridge1ba64f12019-12-18 00:40:13 +00001219 EXPECT=$(test "$TYPE" == "minimal" && echo "8" || echo "10")
David Bainbridge70c0ea82019-11-14 23:25:26 +00001220fi
David Bainbridge4f1b5562019-08-19 04:46:52 +00001221wait_for_pods - "voltha" $EXPECT "includes" -1 "Waiting for VOLTHA Core to start" $VOLTHA
David Bainbridgee87067b2019-08-12 22:00:12 +00001222if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +00001223 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +00001224fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001225
David Bainbridge46505fb2019-10-01 21:13:20 +00001226if [ "$WITH_ADAPTERS" == "yes" ]; then
1227 STIME=$(date +%s)
1228 EXPECT=0
1229 echo -e "Verify Adapters $PLUG"
1230 if [ "$WITH_SIM_ADAPTERS" == "yes" ]; then
1231 bspin - "Verify Simulated Adapters installed"
1232 if [ $(helm list --deployed --short --namespace voltha "^sim\$" | wc -l) -ne 1 ]; then
1233 espin - $NOT_VERIFIED
1234 helm_install - voltha sim $VOLTHA_ADAPTER_SIM_CHART $VOLTHA_ADAPTER_SIM_CHART_VERSION "Install Simulated Adapters"
1235 else
1236 espin - $VERIFIED
1237 fi
1238 EXPECT=$(expr $EXPECT + 2)
1239 fi
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001240
David Bainbridge46505fb2019-10-01 21:13:20 +00001241 if [ "$WITH_OPEN_ADAPTERS" == "yes" ]; then
1242 bspin - "Verify OpenOLT Adapter installed"
1243 if [ $(helm list --deployed --short --namespace voltha "^open-olt\$" | wc -l) -ne 1 ]; then
1244 espin - $NOT_VERIFIED
1245 helm_install - voltha open-olt $VOLTHA_ADAPTER_OPEN_OLT_CHART $VOLTHA_ADAPTER_OPEN_OLT_CHART_VERSION "Install OpenOLT Adapter"
1246 else
1247 espin - $VERIFIED
1248 fi
1249 bspin - "Verify OpenONU Adapter installed"
1250 if [ $(helm list --deployed --short --namespace voltha "^open-onu\$" | wc -l) -ne 1 ]; then
1251 espin - $NOT_VERIFIED
1252 helm_install - voltha open-onu $VOLTHA_ADAPTER_OPEN_ONU_CHART $VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION "Install OpenONU Adapter"
1253 else
1254 espin - $VERIFIED
1255 fi
1256 EXPECT=$(expr $EXPECT + 2)
1257 fi
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001258
David Bainbridge46505fb2019-10-01 21:13:20 +00001259 ADAPTERS="adapter-.*"
1260 wait_for_pods - "voltha" $EXPECT "includes" -1 "Waiting for adapters to start" $ADAPTERS
1261 if [ "$WITH_TIMINGS" == "yes" ]; then
1262 printtime $(expr $(date +%s) - $STIME)
1263 fi
David Bainbridgee87067b2019-08-12 22:00:12 +00001264fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001265
Test User7d866122019-07-09 17:52:35 +00001266if [ $WITH_BBSIM == "yes" ]; then
David Bainbridgee87067b2019-08-12 22:00:12 +00001267 STIME=$(date +%s)
Test User7d866122019-07-09 17:52:35 +00001268 echo -e "Verify BBSIM $PLUG"
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001269 bspin - "Verify BBSIM Installed"
Test User7d866122019-07-09 17:52:35 +00001270 if [ $(helm list --deployed --short --namespace voltha "^bbsim\$" | wc -l) -ne 1 ]; then
1271 espin - $NOT_VERIFIED
David Bainbridge90fd8e32019-08-21 23:32:47 +00001272 helm_install - voltha bbsim $VOLTHA_BBSIM_CHART $VOLTHA_BBSIM_CHART_VERSION "Install BBSIM"
Test User7d866122019-07-09 17:52:35 +00001273 else
1274 espin - $VERIFIED
1275 fi
David Bainbridge4f1b5562019-08-19 04:46:52 +00001276 wait_for_pods - "voltha" 1 "includes" -1 "Waiting for BBSIM to start" "bbsim-.*"
David Bainbridgee87067b2019-08-12 22:00:12 +00001277 if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +00001278 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +00001279 fi
Test User7d866122019-07-09 17:52:35 +00001280fi
1281
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001282if [ $WITH_RADIUS == "yes" ]; then
David Bainbridgee87067b2019-08-12 22:00:12 +00001283 STIME=$(date +%s)
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001284 echo -e "Verify RADIUS $LOCK"
1285 bspin - "Verify RADIUS Installed"
1286 if [ $(helm list --deployed --short --namespace voltha "^radius\$" | wc -l) -ne 1 ]; then
1287 espin - $NOT_VERIFIED
David Bainbridge90fd8e32019-08-21 23:32:47 +00001288 helm_install - voltha radius onf/freeradius latest "Install RADIUS"
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001289 else
1290 espin - $VERIFIED
1291 fi
David Bainbridge4f1b5562019-08-19 04:46:52 +00001292 wait_for_pods - "voltha" 1 "includes" -1 "Waiting for RADIUS to start" "radius-.*"
David Bainbridgee87067b2019-08-12 22:00:12 +00001293 if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +00001294 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +00001295 fi
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001296fi
1297
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -08001298if [ $WITH_PORT_FORWARDS == "yes" ]; then
1299 STIME=$(date +%s)
1300 bspin - "Forward VOLTHA API port $FORWARD"
1301 kill_port_forward voltha-api
1302 port_forward voltha voltha-api $VOLTHA_API_PORT 55555
1303 espin - $VERIFIED
1304 bspin - "Forward VOLTHA ETCD port $FORWARD"
1305 kill_port_forward voltha-etcd-cluster-client
1306 port_forward voltha voltha-etcd-cluster-client $VOLTHA_ETCD_PORT 2379
1307 espin - $VERIFIED
1308 bspin - "Forward VOLTHA Kafka port $FORWARD"
1309 kill_port_forward voltha-kafka
1310 port_forward voltha voltha-kafka $VOLTHA_KAFKA_PORT 9092
1311 espin - $VERIFIED
1312 if [ "$WITH_TIMINGS" == "yes" ]; then
1313 printtime $(expr $(date +%s) - $STIME)
1314 fi
David Bainbridgee87067b2019-08-12 22:00:12 +00001315fi
Test User3d7ad8e2019-07-03 06:15:44 +00001316
David Bainbridgeb270c202019-07-26 01:44:42 +00001317if [ $WITH_ONOS == "yes" -a $WITH_RADIUS == "yes" ]; then
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001318 bspin "Configure ONOS RADIUS Connection $GEAR"
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -08001319 (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 +00001320 espin $VERIFIED
1321fi
1322
David Bainbridge99ac7a22019-08-31 02:26:43 +00001323if [ "$WITH_CHAOS" == "yes" ]; then
1324 STIME=$(date +%s)
1325 echo -e "Verify kube-monkey $LOCK"
1326 bspin - "Verify kube-monkey Installed"
1327 if [ $(helm list --deployed --short --namespace kube-monkey "^monkey\$" | wc -l) -ne 1 ]; then
1328 espin - $NOT_VERIFIED
1329 helm_install - kube-monkey monkey ./kube-monkey/helm/kubemonkey latest "Install Chaos Monkey"
1330 else
1331 espin - $VERIFIED
1332 fi
1333 wait_for_pods - "kube-monkey" 1 "includes" -1 "Waiting for Chaos to start" "monkey-.*"
1334 if [ "$WITH_TIMINGS" == "yes" ]; then
1335 printtime $(expr $(date +%s) - $STIME)
1336 fi
1337fi
1338
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001339bspin "Create voltctl configuration file"
Test User3d7ad8e2019-07-03 06:15:44 +00001340(set -x; mkdir -p $HOME/.volt >>$LOG 2>&1) >>$LOG 2>&1
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -08001341if [ $WITH_PORT_FORWARDS == "yes" ]; then
1342 (set -x; voltctl -a v3 -k localhost:$VOLTHA_KAFKA_PORT -s localhost:$VOLTHA_API_PORT config > $HOME/.volt/config-$NAME 2>>$LOG) >>$LOG 2>&1
1343else
1344 (set -x; voltctl -a v3 -k $(get_service_ep voltha voltha-kafka) -s $(get_service_ep voltha voltha-api) config > $HOME/.volt/config-$NAME 2>>$LOG) >>$LOG 2>&1
1345fi
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001346espin $VERIFIED
Test User08ebbd92019-07-03 17:15:39 +00001347
David Bainbridge0774b232019-08-02 06:37:19 +00001348if [ ! -f "$NAME-env.sh" ]; then
1349 touch $NAME-env.sh
David Bainbridgeb07fdf72019-07-29 22:51:40 +00001350fi
1351
David Bainbridge596f30d2019-07-30 17:07:59 +00001352for O in $ALL_OPTIONS; do
1353 VAL=$(eval echo \$$O)
David Bainbridge0774b232019-08-02 06:37:19 +00001354 if [ ! -z "$VAL" -a $(grep -c "^export $O=" $NAME-env.sh) -eq 0 ]; then
1355 echo "export $O=\"$(eval echo \$$O)\"" >> $NAME-env.sh
David Bainbridgeb07fdf72019-07-29 22:51:40 +00001356 fi
1357done
1358
David Bainbridge0774b232019-08-02 06:37:19 +00001359if [ $DEPLOY_K8S == "yes" -a $(grep -c "^export KUBECONFIG=" $NAME-env.sh) -eq 0 ]; then
1360 echo "export KUBECONFIG=\"$(./bin/kind get kubeconfig-path --name=voltha-$NAME)\"" >> $NAME-env.sh
David Bainbridgeb07fdf72019-07-29 22:51:40 +00001361fi
1362
David Bainbridge0774b232019-08-02 06:37:19 +00001363if [ $(grep -c "^export VOLTCONFIG=" $NAME-env.sh) -eq 0 ]; then
1364 echo "export VOLTCONFIG=\"$HOME/.volt/config-$NAME\"" >> $NAME-env.sh
David Bainbridgeb07fdf72019-07-29 22:51:40 +00001365fi
1366
David Bainbridge0774b232019-08-02 06:37:19 +00001367if [ $(grep -c "^export PATH=" $NAME-env.sh) -eq 0 ]; then
1368 echo "export PATH=\"$GOPATH/bin:\$PATH\"" >> $NAME-env.sh
David Bainbridgeb07fdf72019-07-29 22:51:40 +00001369fi
1370
Test User7d866122019-07-09 17:52:35 +00001371echo ""
Test User08ebbd92019-07-03 17:15:39 +00001372echo "Please issue the following commands in your terminal to ensure that you" | tee -a $LOG
1373echo "are accessing the correct Kubernetes/Kind cluster as well as have the " | tee -a $LOG
1374echo "tools required by VOLTHA in your command path. " | tee -a $LOG
1375echo "" | tee -a $LOG
Test User7d866122019-07-09 17:52:35 +00001376echo -en $BOLD
Test Userba1e7e72019-07-10 22:27:54 +00001377if [ $DEPLOY_K8S == "yes" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +00001378 echo "export KUBECONFIG=\"\$(./bin/kind get kubeconfig-path --name=\"voltha-$NAME\")\"" | tee -a $LOG
Test Userba1e7e72019-07-10 22:27:54 +00001379fi
David Bainbridge0774b232019-08-02 06:37:19 +00001380echo "export VOLTCONFIG=\"$HOME/.volt/config-$NAME\"" | tee -a $LOG
Test Userba1e7e72019-07-10 22:27:54 +00001381echo "export PATH=$GOPATH/bin:\$PATH" | tee -a $LOG
Test User7d866122019-07-09 17:52:35 +00001382echo -en $NORMAL
Test User08ebbd92019-07-03 17:15:39 +00001383echo "" | tee -a $LOG
1384echo "Thank you for choosing kind-voltha for you quick cluster needs." | tee -a $LOG
1385
David Bainbridge712afb82019-08-14 19:55:58 +00001386if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridgef858a022019-08-14 21:25:11 +00001387 echo -e "$CLOCK ${BOLD}TOTAL: $(duration $(expr $(date +%s) - $TOTAL_START_TIME))${NORMAL}"
David Bainbridge712afb82019-08-14 19:55:58 +00001388fi