blob: 28d0ea00844f5074d6256ea4f93615cbf6d1d9e6 [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"
29 echo "Thank you for trying 'votlha up'"
30 exit
31}
32
Test User08ebbd92019-07-03 17:15:39 +000033VOLTCTL_VERSION=${VOLTCTL_VERSION:-0.0.5-dev}
34KIND_VERSION=${KIND_VERSION:-v0.4.0}
35_VOLTCTL_VERSION=$(echo $VOLTCTL_VERSION | sed -e 's/-/_/g')
36
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 Bainbridgee87067b2019-08-12 22:00:12 +000070WITH_TIMINGS=${WITH_TIMINGS:-no}
Test User7d866122019-07-09 17:52:35 +000071WITH_BBSIM=${WITH_BBSIM:-no}
David Bainbridge5b7b96b2019-07-25 20:29:13 +000072WITH_RADIUS=${WITH_RADIUS:-no}
David Bainbridgeb270c202019-07-26 01:44:42 +000073WITH_ONOS=${WITH_ONOS:-yes}
David Bainbridge2b19e832019-08-16 02:40:53 +000074CONFIG_SADIS=${CONFIG_SADIS:-no}
David Bainbridge27790d62019-08-13 22:43:19 +000075INSTALL_ONOS_APPS=${INSTALL_ONOS_APPS:-no}
Test Userba1e7e72019-07-10 22:27:54 +000076JUST_K8S=${JUST_K8S:-no}
77DEPLOY_K8S=${DEPLOY_K8S:-yes}
David Bainbridgee10f6d52019-07-25 00:28:13 +000078SKIP_RESTART_API=${SKIP_RESTART_API:-no}
David K. Bainbridge0e89cb92019-07-17 11:30:10 -070079INSTALL_KUBECTL=${INSTALL_KUBECTL:-yes}
80INSTALL_HELM=${INSTALL_HELM:-yes}
David Bainbridge4f1b5562019-08-19 04:46:52 +000081WAIT_ON_DOWN=${WAIT_ON_DOWN:-no}
David Bainbridge5b7b96b2019-07-25 20:29:13 +000082VOLTHA_LOG_LEVEL=${VOLTHA_LOG_LEVEL:-WARN}
David Bainbridge90fd8e32019-08-21 23:32:47 +000083VOLTHA_CHART=${VOLTHA_CHART:-onf/voltha}
84VOLTHA_CHART_VERSION=${VOLTHA_CHART_VERSION:-latest}
85VOLTHA_BBSIM_CHART=${VOLTHA_BBSIM_CHART:-onf/bbsim}
86VOLTHA_BBSIM_CHART_VERSION=${VOLTHA_BBSIM_CHART_VERSION:-latest}
David Bainbridgee10f6d52019-07-25 00:28:13 +000087VOLTHA_ADAPTER_SIM_CHART=${VOLTHA_ADAPTER_SIM_CHART:-onf/voltha-adapter-simulated}
David Bainbridge90fd8e32019-08-21 23:32:47 +000088VOLTHA_ADAPTER_SIM_CHART_VERSION=${VOLTHA_ADAPTER_SIM_CHART_VERSION:-latest}
David Bainbridgee10f6d52019-07-25 00:28:13 +000089VOLTHA_ADAPTER_OPEN_OLT_CHART=${VOLTHA_ADAPTER_OPEN_OLT_CHART:-onf/voltha-adapter-openolt}
David Bainbridge90fd8e32019-08-21 23:32:47 +000090VOLTHA_ADAPTER_OPEN_OLT_CHART_VERSION=${VOLTHA_ADAPTER_OPEN_OLT_CHART_VERSION:-latest}
David Bainbridgee10f6d52019-07-25 00:28:13 +000091VOLTHA_ADAPTER_OPEN_ONU_CHART=${VOLTHA_ADAPTER_OPEN_ONU_CHART:-onf/voltha-adapter-openonu}
David Bainbridge90fd8e32019-08-21 23:32:47 +000092VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION=${VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION:-latest}
93
Test Userba1e7e72019-07-10 22:27:54 +000094
95HAVE_GO=$(which go >/dev/null 2>&1 && echo "yes" || echo "no")
96HOSTOS=$(uname -s | tr "[:upper:]" "[:lower:"])
97HOSTARCH=$(uname -m | tr "[:upper:]" "[:lower:"])
98if [ $HOSTARCH == "x86_64" ]; then
99 HOSTARCH="amd64"
100fi
Test User7d866122019-07-09 17:52:35 +0000101
102# Verify TYPE setting
103if [ $(echo ":minimal:full:" | grep -ic ":$TYPE:") -eq 0 ]; then
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700104 >&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 +0000105 exit 1
106fi
107
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000108# Used to verify configuration values are set to "yes" or "no" value or convert
109# equivalents to "yes" or "no"
110function verify_yes_no() {
111 local VAR=$1
112 local VAL=$(eval echo \$$VAR)
113 if [ $(echo ":y:yes:true:n:no:false:1:0:" | grep -ic ":$VAL:") -eq 0 ]; then
114 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} Invalid '$VAR' value of '$VAL'. Should be 'yes' or 'no'${NORMAL}"
115 echo "INVALID"
116 return 1
117 fi
118 if [ $(echo ":y:yes:true:1:" | grep -ic ":$VAL:") -eq 1 ]; then
119 echo "yes"
120 else
121 echo "no"
122 fi
123 return 0
124}
Test User7d866122019-07-09 17:52:35 +0000125
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000126ALL_YES_NO="\
127 WITH_TIMINGS \
128 WITH_BBSIM \
129 WITH_RADIUS \
130 WITH_ONOS \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000131 CONFIG_SADIS \
132 JUST_K8S \
133 DEPLOY_K8S \
134 INSTALL_ONOS_APPS \
135 SKIP_RESTART_API \
136 INSTALL_KUBECTL \
137 INSTALL_HELM \
David Bainbridge4f1b5562019-08-19 04:46:52 +0000138 WAIT_ON_DOWN \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000139 "
David Bainbridge5b7b96b2019-07-25 20:29:13 +0000140
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000141ALL_OPTIONS="\
142 NAME \
143 TYPE \
144 $ALL_YES_NO \
145 VOLTHA_LOG_LEVEL \
146 VOLTHA_CHART \
David Bainbridge90fd8e32019-08-21 23:32:47 +0000147 VOLTHA_CHART_VERSION \
148 VOLTHA_BBSIM_CHART \
149 VOLTHA_BBSIM_CHART_VERSION \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000150 VOLTHA_ADAPTER_SIM_CHART \
David Bainbridge90fd8e32019-08-21 23:32:47 +0000151 VOLTHA_ADAPTER_SIM_CHART_VERSION \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000152 VOLTHA_ADAPTER_OPEN_OLT_CHART \
David Bainbridge90fd8e32019-08-21 23:32:47 +0000153 VOLTHA_ADAPTER_OPEN_OLT_CHART_VERSION \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000154 VOLTHA_ADAPTER_OPEN_ONU_CHART \
David Bainbridge90fd8e32019-08-21 23:32:47 +0000155 VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000156 ONOS_API_PORT \
157 ONOS_SSH_PORT \
158 VOLTHA_API_PORT \
159 VOLTHA_SSH_PORT \
160 VOLTHA_ETCD_PORT \
161 "
David Bainbridge01294952019-07-30 19:33:45 +0000162
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000163# Iterate over yes/no configuration options and validate
164for VAR in $ALL_YES_NO; do
165 eval $VAR=$(verify_yes_no $VAR)
166 if [ "$(eval echo \$$VAR)" == "INVALID" ]; then
167 exit 1;
168 fi
169done
David Bainbridgeb270c202019-07-26 01:44:42 +0000170
David Bainbridge0774b232019-08-02 06:37:19 +0000171mkdir -p .voltha
172touch .voltha/ports
173HAVE=$(grep $NAME .voltha/ports)
174if [ "$HAVE X" == " X" ]; then
175 # Find free port prefix
176 START=81
177 while true; do
178 if [ $(grep -c $START .voltha/ports) -eq 0 ]; then
179 break
180 fi
181 START=$(expr $START + 1)
182 done
183 DELTA=$(expr $START - 81)
184 ONOS_API_PORT=${START}81
185 ONOS_SSH_PORT=${START}01
186 VOLTHA_API_PORT=5$(expr 55 + $DELTA)55
187 VOLTHA_SSH_PORT=$(expr 50 + $DELTA)22
188 VOLTHA_ETCD_PORT=$(expr 23 + $DELTA)79
Test User01ed0642019-07-03 20:17:06 +0000189else
David Bainbridge0774b232019-08-02 06:37:19 +0000190 VALUES=$(echo $HAVE | sed -e 's/\s//g' | cut -d= -f2)
191 ONOS_API_PORT=$(echo $VALUES | cut -d, -f1)
192 ONOS_SSH_PORT=$(echo $VALUES | cut -d, -f2)
193 VOLTHA_API_PORT=$(echo $VALUES | cut -d, -f3)
194 VOLTHA_SSH_PORT=$(echo $VALUES | cut -d, -f4)
195 VOLTHA_ETCD_PORT=$(echo $VALUES | cut -d, -f5)
Test User01ed0642019-07-03 20:17:06 +0000196fi
197
David Bainbridge0774b232019-08-02 06:37:19 +0000198PORTTMP=$(mktemp -u)
199cat .voltha/ports | grep -v $NAME > $PORTTMP
200echo "$NAME=$ONOS_API_PORT,$ONOS_SSH_PORT,$VOLTHA_API_PORT,$VOLTHA_SSH_PORT,$VOLTHA_ETCD_PORT" >> $PORTTMP
201cp $PORTTMP .voltha/ports
202rm -f $PORTTMP
203
David Bainbridge27790d62019-08-13 22:43:19 +0000204export ONOS_API_PORT ONOS_SSH_PORT
David Bainbridge01294952019-07-30 19:33:45 +0000205
Test Userd87942b2019-07-03 07:20:24 +0000206IDX=1
David Bainbridgee87067b2019-08-12 22:00:12 +0000207CLOCK="TIME:"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000208SPIN_PARTS=
209NOT_VERIFIED=
David Bainbridgef858a022019-08-14 21:25:11 +0000210THEX=
211BUILD=
212CROSS=
213ENTER=
David Bainbridge38dc1e82019-08-12 15:18:45 +0000214VERIFIED=
215HELM=
216OLD_KEY=
217BIRD=
218HIGH_VOLTAGE=
219PLUG=
220RESTART=
221FORWARD=
222INSTALL=
223STOP=
224GO=
225DOWNLOAD=
226GEAR=
227NO_ENTRY=
228LOCK=
229
230if [ $FANCY -eq 1 ]; then
231 SPIN_PARTS="\
232 \xe2\xa2\x8e\xe2\xa1\xb0 \
233 \xe2\xa2\x8e\xe2\xa1\xa1 \
234 \xe2\xa2\x8e\xe2\xa1\x91 \
235 \xe2\xa2\x8e\xe2\xa0\xb1 \
236 \xe2\xa0\x8e\xe2\xa1\xb1 \
237 \xe2\xa2\x8a\xe2\xa1\xb1 \
238 \xe2\xa2\x8c\xe2\xa1\xb1 \
239 \xe2\xa2\x86\xe2\xa1\xb1 \
240 "
David Bainbridgee87067b2019-08-12 22:00:12 +0000241 CLOCK="\xe2\x8f\xb1"
David Bainbridgef858a022019-08-14 21:25:11 +0000242 THEX="${RED}${BOLD}\xe2\x9c\x97\x20${NORMAL}"
243 ENTER="${YELLOW}${BOLD}\xe2\x8e\x86${NORMAL}"
244 CROSS="${YELLOW}${BOLD}\xe2\x9c\x9a${NORMAL}"
245 BUILD="${YELLOW}${BOLD}\xf0\x9f\x8f\x97${NORMAL}"
246 NOT_VERIFIED="$BUILD"
247 VERIFIED="${GREEN}${BOLD}\xe2\x9c\x93\x20${NORMAL}"
248 HELM="${BLUE}${BOLD}\xE2\x8E\x88${NORMAL}"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000249 OLD_KEY="\xF0\x9F\x97\x9D"
250 BIRD="\xF0\x9F\x90\xA6"
251 HIGH_VOLTAGE="\xE2\x9A\xA1"
252 PLUG="\xF0\x9F\xa7\xa9"
253 RESTART="\xf0\x9f\x94\x84"
254 FORWARD="\xE2\x87\xA8"
255 INSTALL="\xF0\x9F\x8F\x97"
256 STOP="\xf0\x9f\x9b\x91"
257 GO="\xf0\x9f\x9a\x80"
258 DOWNLOAD="\xf0\x9f\x93\xa5"
259 GEAR="\xe2\x9a\x99"
260 NO_ENTRY="\xe2\x9b\x94"
261 LOCK="\xf0\x9f\x94\x92"
262fi
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700263
David Bainbridge712afb82019-08-14 19:55:58 +0000264duration() {
David Bainbridgee87067b2019-08-12 22:00:12 +0000265 local h=$(expr $1 / 3600)
266 local m=$(expr $1 % 3600 / 60)
267 local s=$(expr $1 % 60)
268 local t=""
269
270 if [ $h -gt 0 ]; then
271 t="$t${h}h"
272 fi
273 if [ $m -gt 0 ]; then
274 t="$t${m}m"
275 fi
David Bainbridge712afb82019-08-14 19:55:58 +0000276 echo "$t${s}s"
277}
278
279printtime() {
280 local INDENT=
281 if [ "$1" == "-" ]; then
282 INDENT=" "
283 shift
284 fi
285 echo -e "$INDENT $CLOCK $(duration $1)"
David Bainbridgee87067b2019-08-12 22:00:12 +0000286}
287
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700288bspin() {
Test Userd87942b2019-07-03 07:20:24 +0000289 IDX=1
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700290 local INDENT=
291 if [ "$1" == "-" ]; then
292 INDENT=" "
293 shift
294 fi
David Bainbridge38dc1e82019-08-12 15:18:45 +0000295 if [ $FANCY -eq 0 ]; then
296 LINE=$(echo $* | sed -e 's/[\s+-]//g')
297 if [ "$LINE X" == " X" ]; then
298 return
299 fi
300 echo -e "$CIVIS$INDENT$*"
301 else
302 echo -en "$CIVIS$INDENT $*"
303 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700304}
305
306sspin() {
307 local INDENT=
308 if [ "$1" == "-" ]; then
309 INDENT=" "
310 shift
311 fi
David Bainbridge38dc1e82019-08-12 15:18:45 +0000312 if [ $FANCY -eq 0 ]; then
313 LINE=$(echo $* | sed -e 's/[\s+-]//g')
314 if [ "$LINE X" == " X" ]; then
315 return
316 fi
317 echo -e "$INDENT$*"
318 else
319 C=$(echo $SPIN_PARTS | cut '-d ' -f $IDX)
320 echo -en "\r$INDENT$C $*"
321 IDX=$(expr $IDX + 1)
322 if [ $IDX -gt 8 ]; then
323 IDX=1
324 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700325 fi
326}
327
328espin() {
329 local INDENT=
330 if [ "$1" == "-" ]; then
331 INDENT=" "
332 shift
333 fi
David Bainbridge38dc1e82019-08-12 15:18:45 +0000334 if [ $FANCY -eq 0 ]; then
335 LINE=$(echo $* | sed -e 's/[\s+-]//g')
336 if [ "$LINE X" == " X" ]; then
337 return
338 fi
339 echo -e "$INDENT$*"
340 else
341 echo -e "\r$INDENT$*$CNORM"
342 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700343}
344
David Bainbridgeac7f8072019-08-01 22:15:33 +0000345if [ "$1" == "get" -a "$2" == "voltconfig" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000346 echo "$HOME/.volt/config-$NAME"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000347 exit
348fi
349
350if [ $# -ne 1 -o $(echo ":up:down:dump:" | grep -c ":$1:") -ne 1 ]; then
351 >&2 echo "What wouild you like to do today:"
352 >&2 echo " up - bring up voltha"
353 >&2 echo " down - tear down voltha"
354 >&2 echo " dump - create a debug dump of running system"
355 exit 1
356fi
357
David Bainbridge4f1b5562019-08-19 04:46:52 +0000358push_onos_config() {
359 local MSG=$1
360 local RESOURCE=$2
361 local DATA=$3
362
363 bspin - "$MSG $GEAR"
364 while true; do
365 (set -x; curl --fail -sSL --user karaf:karaf -X POST -H Content-Type:application/json http://127.0.0.1:$ONOS_API_PORT/onos/v1/$RESOURCE --data @$DATA >>$LOG 2>&1) >>$LOG 2>&1
366 if [ $? -eq 0 ]; then
367 break
368 fi
369 sleep .2
370 sspin -
371 done
372 espin - $VERIFIED
373}
374
375override_onos_app() {
376 local APP=$1
377 local NAME=$(basename $APP | sed -e 's/^[0-9][0-9]*-//g' -e 's/-.*$//g')
378 while true; do
379 sspin -
380 # Attempt to delete old version (if it exists)
381 (set -x; curl --fail -sSL --user karaf:karaf -X DELETE http://127.0.0.1:$ONOS_API_PORT/onos/v1/applications/$NAME >>$LOG 2>&1) >>$LOG 2>&1
382 sspin -
383 if [ $? -ne 0 ]; then
384 continue
385 fi
386 (set -x; curl --fail -sSL --user karaf:karaf -X POST -H Content-Type:application/octet-stream http://127.0.0.1:$ONOS_API_PORT/onos/v1/applications?activate=true --data-binary @$APP >>$LOG 2>&1) >>$LOG 2>&1
387 if [ $? -eq 0 ]; then
388 break
389 fi
390 sleep .2
391 done
392}
393
394activate_onos_app() {
395 local MSG="$1"
396 local APP=$2
397
398 bspin - "$MSG $GO"
399 while true; do
400 sspin -
401 (set -x; curl --fail -sSL --user karaf:karaf -X POST http://127.0.0.1:$ONOS_API_PORT/onos/v1/applications/$APP/active >>$LOG 2>&1) >>$LOG 2>&1
402 if [ $? -eq 0 ]; then
403 break
404 fi
405 sleep .2
406 done
407 espin - "$VERIFIED"
408}
409
410count_pods() {
411 local NAMESPACE=$1; shift
412 if [ "$NAMESPACE" == "all-namespaces" ]; then
413 NAMESPACE="--all-namespaces"
414 else
415 NAMESPACE="-n $NAMESPACE"
416 fi
417 echo "$NAMESPACE" > /tmp/t
418 local STATES=$1; shift
419 echo "$STATES" >> /tmp/t
420 local PODS=$(kubectl get $NAMESPACE pod -o go-template="{{range .items}}{{.metadata.name}}/{{.status.phase}}/_{{range .status.containerStatuses}}{{.ready}}_{{end}} {{end}}")
421 local COUNT=0
422 local PATTERNS="$*"
423 for POD in $PODS; do
424 local NAME=$(echo $POD | cut -d/ -f 1)
425 local STATE=$(echo $POD | cut -d/ -f 2)
426 local CONTAINERS=$(echo $POD | cut -d/ -f 3 | sed -e 's/_/ /g')
427 if [ "$STATES" == "*" -o $(echo "$STATES" | grep -c ":$STATE:") -ne 0 ]; then
428 echo "IN WITH $POD" >> /tmp/t
429 local TOTAL=$(echo $CONTAINERS | wc -w)
430 local FOUND=$(echo $CONTAINERS | grep -o true | wc -l)
431 if [ $TOTAL -eq $FOUND ]; then
432 for PATTERN in $PATTERNS; do
433 echo "TEST $PATTERN AGAINST $NAME" >> /tmp/t
434 if [[ $NAME =~ $PATTERN ]]; then
435 echo "COUNT $NAME" >> /tmp/t
436 COUNT=$(expr $COUNT + 1)
437 break
438 fi
439 done
440 fi
441 fi
442 done
443 echo $COUNT >> /tmp/t
444 echo $COUNT
445}
446
447wait_for_pods() {
448 local INDENT=
449 if [ "$1" == "-" ]; then
450 INDENT=$1; shift
451 fi
452 local NAMESPACE=$1; shift
453 local EXPECT=$1; shift
454 local TYPE=$1; shift
455 local RETRY=$1; shift
456 local MESSAGE=$1; shift
457 local PATTERNS=$*
458 local HAVE=$(count_pods $NAMESPACE ":Running:" $PATTERNS)
459 local ALL=$HAVE
460 if [ "$TYPE" == "only" ]; then
461 ALL=$(count_pods "all-namespaces" "*" ".*")
462 fi
463 COUNT=$(expr 300 / 15)
464 bspin $INDENT $MESSAGE
465 sspin $INDENT
466 if [ $HAVE -ne $EXPECT -o $ALL -ne $HAVE ]; then
467 while [ $HAVE -ne $EXPECT -o $ALL -ne $HAVE ]; do
468 sspin $INDENT
469 COUNT=$(expr $COUNT - 1)
470 if [ $COUNT -eq 0 ]; then
471 HAVE=$(count_pods $NAMESPACE ":Running:" $PATTERNS)
472 ALL=$HAVE
473 if [ "$TYPE" == "only" ]; then
474 ALL=$(count_pods "all-namespaces" "*" ".*")
475 fi
476 COUNT=$(expr 300 / 15)
477 fi
478 sleep .15
479 done
480 fi
481 espin $INDENT $VERIFIED
482 if [ $HAVE -ne $EXPECT ]; then
483 return 1
484 fi
485 return 0
486}
487
David Bainbridgeac7f8072019-08-01 22:15:33 +0000488if [ "$1" == "down" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000489 echo "Tearing down voltha cluster $NAME"
490 LOG="down-$NAME.log"
491 echo $(date -u +"%Y%m%dT%H%M%SZ") >$LOG
David Bainbridgeac7f8072019-08-01 22:15:33 +0000492 if [ $DEPLOY_K8S == "yes" ]; then
493 if [ -x ./bin/kind ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000494 bspin "Delete Kubernetes Kind Cluster"
495 (set -x; ./bin/kind delete cluster --name voltha-$NAME >>$LOG 2>&1) >>$LOG 2>&1
496 espin $VERIFIED
David Bainbridgeac7f8072019-08-01 22:15:33 +0000497 else
David Bainbridge0774b232019-08-02 06:37:19 +0000498 espin "$NO_ENTRY Delete Kubernetes Kind Cluster: kind command not found"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000499 fi
500 else
501 EXISTS=$(helm list -q)
502 EXPECT="etcd-operator onos open-olt open-onu sim voltha bbsim radius"
David Bainbridge0774b232019-08-02 06:37:19 +0000503 bspin "Remove Helm Deployments"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000504 for i in $EXISTS; do
505 if [ $(echo $EXPECT | grep -c $i) -eq 1 ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000506 sspin "Remove Helm Deployments: $i$CEOL"
507 (set -x; ./bin/helm delete --purge $i >>$LOG 2>&1) >>$LOG 2>&1
David Bainbridgeac7f8072019-08-01 22:15:33 +0000508 fi
509 done
David Bainbridge0774b232019-08-02 06:37:19 +0000510 espin "$VERIFIED Remove Helm Deployments$CEOL"
David Bainbridge4f1b5562019-08-19 04:46:52 +0000511 if [ "$WAIT_ON_DOWN" == "yes" ]; then
512 # There should only be 13 or 15 PODs in the kube-system name
513 # space and no other PODs
514
515 PODS="coredns-.* \
516 etcd-voltha-$NAME-control-plane \
517 kindnet-.* \
518 kube-apiserver-voltha-$NAME-control-plane \
519 kube-controller-manager-voltha-$NAME-control-plane \
520 kube-proxy-.* \
521 kube-scheduler-voltha-$NAME-control-plane \
522 tiller-deploy-.*"
523 EXPECT=$(test "$TYPE" == "minimal" && echo "13" || echo "15")
524 wait_for_pods "all-namespaces" $EXPECT "only" -1 "Waiting for only system PODs to be running" $PODS
525 fi
David Bainbridgeac7f8072019-08-01 22:15:33 +0000526 fi
David Bainbridge0774b232019-08-02 06:37:19 +0000527 bspin "Remove port-forwards: onos-ui-$NAME"
528 for i in $(screen -ls | grep onos-ui-$NAME | awk '{print $1}'); do
529 sspin
530 (set -x; screen -X -S $i quit >>$LOG 2>&1) >>$LOG 2>&1
531 done
532 sspin "Remove port-forwards: onos-ssh-$NAME$CEOL"
533 for i in $(screen -ls | grep onos-ssh-$NAME | awk '{print $1}'); do
534 sspin
535 (set -x; screen -X -S $i quit >>$LOG 2>&1) >>$LOG 2>&1
536 done
537 sspin "Remove port-forwards: voltha-api-$NAME$CEOL"
538 for i in $(screen -ls | grep voltha-api-$NAME | awk '{print $1}'); do
539 sspin
540 (set -x; screen -X -S $i quit >>$LOG 2>&1) >>$LOG 2>&1
541 done
542 sspin "Remove port-forwards: voltha-ssh-$NAME$CEOL"
543 for i in $(screen -ls | grep voltha-ssh-$NAME | awk '{print $1}'); do
544 sspin
545 (set -x; screen -X -S $i quit >>$LOG 2>&1) >>$LOG 2>&1
546 done
547 sspin "Remove port-forwards: voltha-etcd-$NAME$CEOL"
548 for i in $(screen -ls | grep voltha-etcd-$NAME | awk '{print $1}'); do
549 sspin
550 (set -x; screen -X -S $i quit >>$LOG 2>&1) >>$LOG 2>&1
551 done
552 espin "$VERIFIED Remove port-forwards$CEOL"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000553 exit
554fi
555
556if [ "$1" == "dump" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000557 LOG="dump-$NAME.log"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000558 TS=$(date -u +"%Y%m%dT%H%M%SZ")
559 WORK=$(mktemp -u -d)
David Bainbridge0774b232019-08-02 06:37:19 +0000560 DATA=$WORK/voltha-debug-dump-$NAME-$TS
David Bainbridgeac7f8072019-08-01 22:15:33 +0000561 mkdir -p $DATA
562 echo $TS > $LOG
David Bainbridge0774b232019-08-02 06:37:19 +0000563 echo -e "Capturing debug dump to voltha-debug-dump-$NAME-$TS.tgz"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000564 bspin - "Copy install log"
David Bainbridge0774b232019-08-02 06:37:19 +0000565 if [ -f install-$NAME.log ]; then
566 (set -x; cp install-$NAME.log $DATA/install-$NAME.log) >>$LOG 2>&1
David Bainbridgeac7f8072019-08-01 22:15:33 +0000567 espin - $VERIFIED
568 else
David Bainbridge0774b232019-08-02 06:37:19 +0000569 espin - "$NO_ENTRY Copy install log: install-$NAME.log not found"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000570 fi
571 bspin - "Dumping Kubernetes PODs"
572 (set -x; kubectl get --all-namespaces pods >> $DATA/all-pods.txt 2>&1) >>$LOG 2>&1
573 espin - $VERIFIED
574 bspin - "Dumping Kubernetes SERVICEs"
575 (set -x; kubectl get --all-namespaces svc >> $DATA/all-services.txt 2>&1) >>$LOG 2>&1
576 espin - $VERIFIED
577 bspin - "Dumping Kubernetes EVENTs"
578 (set -x; kubectl get --all-namespaces events >> $DATA/all-events.txt 2>&1) >>$LOG 2>&1
579 espin - $VERIFIED
580 bspin - "Dumping VOLTHA POD details"
581 PODS=$(kubectl get -n voltha pod -o name)
582 for POD in $PODS; do
583 sspin - "Dumping VOLTHA POD details: $POD$CEOL"
584 mkdir -p $DATA/$POD
585 (set -x; kubectl describe -n voltha $POD >> $DATA/$POD/describe.txt 2>&1) >>$LOG 2>&1
586 sspin - "Dumping VOLTHA POD details: $POD"
587 (set -x; kubectl logs -n voltha --all-containers --previous $LOG_ARGS $POD >> $DATA/$POD/logs-previous.txt 2>&1) >>$LOG 2>&1
588 sspin - "Dumping VOLTHA POD details: $POD"
589 (set -x; kubectl logs -n voltha --all-containers $LOG_ARGS $POD >> $DATA/$POD/logs-current.txt 2>&1) >>$LOG 2>&1
590 sspin - "Dumping VOLTHA POD details: $POD"
591 done
592 espin - "$VERIFIED Dumping VOLTHA POD details$CEOL"
593 bspin - "Dumping ETCD"
594 if [ "$(which etcdctl) X" != " X" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000595 (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 +0000596 espin - $VERIFIED
597 else
598 espin - "$NO_ENTRY Dumping ETCD: etcdctl command not available"
599 fi
David Bainbridge0774b232019-08-02 06:37:19 +0000600 bspin - "Creating compressed TAR: voltha-debug-dump-$NAME-$TS.tgz"
601 (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 +0000602 espin - $VERIFIED
603 bspin - "Cleanup"
604 (set -x; rm -rf $WORK) >>$LOG 2>&1
605 espin - $VERIFIED
David Bainbridge0774b232019-08-02 06:37:19 +0000606 bspin - "$(ls -l voltha-debug-dump-$NAME-$TS.tgz)"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000607 espin - $VERIFIED
608 exit
609fi
610
David Bainbridge0774b232019-08-02 06:37:19 +0000611LOG="install-$NAME.log"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000612date > $LOG
David Bainbridge0774b232019-08-02 06:37:19 +0000613echo "PORTS=$ONOS_API_PORT,$ONOS_SSH_PORT,$VOLTHA_API_PORT,$VOLTHA_SSH_PORT,$VOLTHA_ETCD_PORT" >> $LOG
David Bainbridgeac7f8072019-08-01 22:15:33 +0000614
615# Output install options to log
616echo "OPTIONS" >> $LOG
David Bainbridgeac7f8072019-08-01 22:15:33 +0000617for O in $ALL_OPTIONS; do
618 VAL=$(eval echo \$$O)
David Bainbridgeac7f8072019-08-01 22:15:33 +0000619 if [ ! -z "$VAL" ]; then
620 printf " %-30s = %s\n" $O $VAL >> $LOG
621 fi
622done
623
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700624helm_install() {
625 local INDENT=
626 if [ "$1" == "-" ]; then
627 INDENT=$1; shift
628 fi
629 local NAMESPACE=$1; shift
David Bainbridge0774b232019-08-02 06:37:19 +0000630 local INAME=$1; shift
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700631 local CHART=$1; shift
David Bainbridge90fd8e32019-08-21 23:32:47 +0000632 local CHART_VERSION=$1; shift
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700633 local MESSAGE=$*
634
David Bainbridge90fd8e32019-08-21 23:32:47 +0000635 echo "CHART_VERSION=\"$CHART_VERSION\""
636 if [ "$CHART_VERSION X" != " X" -a "$CHART_VERSION" != "latest" ]; then
637 CHART_VERSION="--version $CHART_VERSION"
638 else
639 CHART_VERSION=
640 fi
641
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700642 COUNT=$(expr 300 / 15)
643 bspin $INDENT $MESSAGE
David Bainbridge90fd8e32019-08-21 23:32:47 +0000644 (set -x; helm install -f $NAME-values.yaml --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 -0700645 SUCCESS=$?
646 while [ $SUCCESS -ne 0 ]; do
647 sspin $INDENT
648 COUNT=$(expr $COUNT - 1)
649 if [ $COUNT -eq 0 ]; then
David Bainbridge90fd8e32019-08-21 23:32:47 +0000650 (set -x; helm install -f $NAME-values.yaml --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 -0700651 COUNT=$(expr 300 / 15)
652 fi
653 sleep .15
654 done
655 espin $INDENT $VERIFIED
656}
657
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700658echo "INSTALL TYPE: $TYPE" >> $LOG
659
660bspin "Verify GOPATH"
661export GOPATH=$(pwd)
Test User3d7ad8e2019-07-03 06:15:44 +0000662mkdir -p $GOPATH/bin
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700663espin $VERIFIED
664
David Bainbridgee87067b2019-08-12 22:00:12 +0000665STIME=$(date +%s)
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700666if [ "$INSTALL_KUBECTL" == "no" ]; then
667 bspin "Skip kubectl install"
668 espin $NO_ENTRY
Test Userc13bdc92019-07-03 20:57:49 +0000669else
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700670 bspin "Verify kubectl $HELM"
671 if [ -x $GOPATH/bin/kubectl ]; then
672 espin $VERIFIED
673 else
674 espin $NOT_VERIFIED
675 bspin - "Download and install Kubernetes/kubectl $DOWNLOAD"
676 (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
677 (set -x; chmod 755 $GOPATH/bin/kubectl >>$LOG 2>&1) >>$LOG 2>&1
678 espin - $VERIFIED
679 fi
Test Userc13bdc92019-07-03 20:57:49 +0000680fi
David Bainbridgee87067b2019-08-12 22:00:12 +0000681if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +0000682 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +0000683fi
Test Userc13bdc92019-07-03 20:57:49 +0000684
David Bainbridgee87067b2019-08-12 22:00:12 +0000685STIME=$(date +%s)
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700686if [ "$DEPLOY_K8S" == "no" ]; then
687 bspin "Skip Kubernetes/Kind Deployment"
688 espin $NO_ENTRY
689else
Test Userba1e7e72019-07-10 22:27:54 +0000690 bspin "Verify Kubernetes/Kind $HELM"
691 if [ -x $GOPATH/bin/kind ]; then
692 espin $VERIFIED
693 else
694 espin $NOT_VERIFIED
695 bspin - "Download and install Kubernetes/kind $DOWNLOAD"
David Bainbridge9e2a6662019-07-11 17:07:57 +0000696 (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 +0000697 (set -x; chmod 755 $GOPATH/bin/kind >>$LOG 2>&1) >>$LOG 2>&1
698 espin - $VERIFIED
699 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700700fi
701
David Bainbridgee87067b2019-08-12 22:00:12 +0000702if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +0000703 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +0000704fi
705
706STIME=$(date +%s)
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700707if [ "$INSTALL_HELM" == "no" ]; then
708 bspin "Skip Helm Install"
709 espin $NO_ENTRY
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700710else
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700711 bspin "Verify Helm $HELM"
712 if [ -x $GOPATH/bin/helm ]; then
713 espin $VERIFIED
714 else
715 espin $NOT_VERIFIED
716 bspin - "Download and install Helm $DOWNLOAD"
717 (set -x; curl -sSL https://git.io/get_helm.sh | USE_SUDO=false HELM_INSTALL_DIR=$GOPATH/bin bash >>$LOG 2>&1) >>$LOG 2>&1
718 espin - $VERIFIED
719 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700720fi
David Bainbridgee87067b2019-08-12 22:00:12 +0000721if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +0000722 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +0000723fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700724
David Bainbridgee87067b2019-08-12 22:00:12 +0000725STIME=$(date +%s)
Test Userb5712372019-07-03 21:52:17 +0000726bspin "Verify voltctl $HIGH_VOLTAGE"
Test User3d7ad8e2019-07-03 06:15:44 +0000727if [ -x $GOPATH/bin/voltctl ]; then
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700728 espin $VERIFIED
729else
730 espin $NOT_VERIFIED
Test Userb5712372019-07-03 21:52:17 +0000731 bspin - "Download and build voltctl $DOWNLOAD"
Test Userba1e7e72019-07-10 22:27:54 +0000732 (set -x; curl -o $GOPATH/bin/voltctl -sSL https://github.com/ciena/voltctl/releases/download/$VOLTCTL_VERSION/voltctl-$_VOLTCTL_VERSION-$HOSTOS-$HOSTARCH >>$LOG 2>&1) >>$LOG 2>&1
Test User08ebbd92019-07-03 17:15:39 +0000733 (set -x; chmod 755 $GOPATH/bin/voltctl >>$LOG 2>&1) >>$LOG 2>&1
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700734 espin - $VERIFIED
735fi
David Bainbridgee87067b2019-08-12 22:00:12 +0000736if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +0000737 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +0000738fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700739
740bspin "Verify command PATH"
Test Userba1e7e72019-07-10 22:27:54 +0000741export PATH=$GOPATH/bin:$PATH
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700742espin $VERIFIED
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700743
David Bainbridgee87067b2019-08-12 22:00:12 +0000744STIME=$(date +%s)
Test Userba1e7e72019-07-10 22:27:54 +0000745if [ "$DEPLOY_K8S" == "yes" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000746 HAVE=$(kind get clusters | grep -c voltha-$NAME)
Test Userba1e7e72019-07-10 22:27:54 +0000747 bspin "Verify Kubernetes/Kind Cluster"
748 sspin
749 if [ $HAVE -eq 0 ]; then
David Bainbridge491b1bd2019-07-11 17:53:11 +0000750 espin $NOT_VERIFIED
751 bspin - "Verify cluster configuration"
David Bainbridge0774b232019-08-02 06:37:19 +0000752 if [ ! -r ./$NAME-cluster.cfg ]; then
David Bainbridge491b1bd2019-07-11 17:53:11 +0000753 espin - $NOT_VERIFIED
David Bainbridge0774b232019-08-02 06:37:19 +0000754 bspin - "Download cluster configuration: $TYPE-cluster.cfg to $NAME-cluster.cfg $DOWNLOAD"
755 (set -x; curl -o ./$NAME-cluster.cfg -sSL https://raw.githubusercontent.com/ciena/kind-voltha/master/$TYPE-cluster.cfg >>$LOG 2>&1) >>$LOG 2>&1
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700756 espin - $VERIFIED
757 else
758 espin - $VERIFIED
759 fi
David Bainbridge0774b232019-08-02 06:37:19 +0000760 kind create cluster --name voltha-$NAME --config $NAME-cluster.cfg
David Bainbridge491b1bd2019-07-11 17:53:11 +0000761 else
762 espin $VERIFIED
Test Userba1e7e72019-07-10 22:27:54 +0000763 fi
764
David Bainbridge0774b232019-08-02 06:37:19 +0000765 export KUBECONFIG="$(kind get kubeconfig-path --name="voltha-$NAME")"
Test Userba1e7e72019-07-10 22:27:54 +0000766 P="coredns-.* \
David Bainbridge0774b232019-08-02 06:37:19 +0000767 etcd-voltha-$NAME-control-plane \
Test Userba1e7e72019-07-10 22:27:54 +0000768 kindnet-.* \
David Bainbridge0774b232019-08-02 06:37:19 +0000769 kube-apiserver-voltha-$NAME-control-plane \
770 kube-controller-manager-voltha-$NAME-control-plane \
Test Userba1e7e72019-07-10 22:27:54 +0000771 kube-proxy-.* \
David Bainbridge0774b232019-08-02 06:37:19 +0000772 kube-scheduler-voltha-$NAME-control-plane"
Test Userba1e7e72019-07-10 22:27:54 +0000773
774 EXPECT=$(test "$TYPE" == "minimal" && echo "12" || echo "14")
David Bainbridge4f1b5562019-08-19 04:46:52 +0000775 wait_for_pods - "kube-system" $EXPECT "includes" -1 "Waiting for system PODs to start" $P
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700776fi
David Bainbridgee87067b2019-08-12 22:00:12 +0000777if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +0000778 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +0000779fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700780
David Bainbridgee87067b2019-08-12 22:00:12 +0000781STIME=$(date +%s)
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700782COUNT=$(count_pods "kube-system" "tiller-deploy-.*")
783bspin "Verify Helm"
Test Userba1e7e72019-07-10 22:27:54 +0000784if [ $COUNT -ne 1 ]; then
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700785 espin $NOT_VERIFIED
Test Userb5712372019-07-03 21:52:17 +0000786 echo -e "Configuring Helm $GEAR"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700787 if [ "$INSTALL_HELM" == "no" ]; then
788 bspin - "Skip Helm/Tiller Initialization"
789 espin - $NO_ENTRY
790 else
791 bspin - "Initialize Helm"
792 (set -x; helm init --upgrade >>$LOG 2>&1) >>$LOG 2>&1
793 espin - $VERIFIED
David Bainbridge4f1b5562019-08-19 04:46:52 +0000794 wait_for_pods - "kube-system" 1 "includes" -1 "Waiting for Tiller POD to start" "tiller-deploy-.*"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700795 fi
Test Userb5712372019-07-03 21:52:17 +0000796 bspin - "Add Google Incubator repository to Helm"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700797 (set -x; helm repo add incubator https://kubernetes-charts-incubator.storage.googleapis.com >>$LOG 2>&1) >>$LOG 2>&1
798 espin - $VERIFIED
Test Userba1e7e72019-07-10 22:27:54 +0000799
800 # HACK (sort-of) - the config for tiller is about to be patched, which will
801 # cause the tiller pod to be recreated. This can sometimes cause a timing
802 # issue with the "wait_for_pods" call on tiller as it may incorrectly
803 # identify the running/ready tiller pod that is soon to be terminated as
804 # what it is waiting for. To avoid this issue we do a clean scale down and
805 # scale up of the pod so the script controlls when it should be expecting
806 # things
807 (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 -0700808
Test Userb5712372019-07-03 21:52:17 +0000809 bspin - "Add Google Stable repository to Helm"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700810 (set -x; helm repo add stable https://kubernetes-charts.storage.googleapis.com >>$LOG 2>&1) >>$LOG 2>&1
811 espin - $VERIFIED
Test Userb5712372019-07-03 21:52:17 +0000812 bspin - "Add ONF repository to Helm"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700813 (set -x; helm repo add onf https://charts.opencord.org >>$LOG 2>&1) >>$LOG 2>&1
814 espin - $VERIFIED
Test Userb5712372019-07-03 21:52:17 +0000815 bspin - "Update Helm repository cache"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700816 (set -x; helm repo update >>$LOG 2>&1) >>$LOG 2>&1
817 espin - $VERIFIED
818
819 # Create and k8s service account so that Helm can create pods
Test Userb5712372019-07-03 21:52:17 +0000820 bspin - "Create Tiller ServiceAccount"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700821 (set -x; kubectl create serviceaccount --namespace kube-system tiller >>$LOG 2>&1) >>$LOG 2>&1
822 espin - $VERIFIED
Test Userb5712372019-07-03 21:52:17 +0000823 bspin - "Create Tiller ClusterRoleBinding"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700824 (set -x; kubectl create clusterrolebinding tiller-cluster-rule --clusterrole=cluster-admin --serviceaccount=kube-system:tiller >>$LOG 2>&1) >>$LOG 2>&1
825 espin - $VERIFIED
Test Userb5712372019-07-03 21:52:17 +0000826 bspin - "Update Tiller Manifest"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700827 (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 +0000828
829 # HACK (sort-of) - part to, spin it back up
830 (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 -0700831 espin - $VERIFIED
832else
833 espin $VERIFIED
834fi
David Bainbridge4f1b5562019-08-19 04:46:52 +0000835wait_for_pods - "kube-system" 1 "includes" -1 "Waiting for Tiller POD to start" "tiller-deploy-.*"
David Bainbridgee87067b2019-08-12 22:00:12 +0000836if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +0000837 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +0000838fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700839
David Bainbridgee87067b2019-08-12 22:00:12 +0000840STIME=$(date +%s)
David Bainbridge0774b232019-08-02 06:37:19 +0000841bspin "Verify Helm values file: $NAME-values.yaml"
842if [ ! -r "./$NAME-values.yaml" ]; then
Test Userba1e7e72019-07-10 22:27:54 +0000843 espin $NOT_VERIFIED
David Bainbridge0774b232019-08-02 06:37:19 +0000844 bspin - "Download Helm values file: $TYPE-values.yaml to $NAME-values.yaml $DOWNLOAD"
845 (set -x; curl -o ./$NAME-values.yaml -sSL https://raw.githubusercontent.com/ciena/kind-voltha/master/$TYPE-values.yaml >>$LOG 2>&1) >>$LOG 2>&1
Test Userba1e7e72019-07-10 22:27:54 +0000846 espin - $VERIFIED
847else
848 espin $VERIFIED
849fi
David Bainbridgee87067b2019-08-12 22:00:12 +0000850if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +0000851 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +0000852fi
Test Userba1e7e72019-07-10 22:27:54 +0000853
854if [ "$JUST_K8S" == "yes" ]; then
855 echo "Environment deployed, not deploying VOLTHA artifacts as requested. Good bye."
856 echo ""
857 echo "Please issue the following commands in your terminal to ensure that you" | tee -a $LOG
858 echo "are accessing the correct Kubernetes/Kind cluster as well as have the " | tee -a $LOG
859 echo "tools required by VOLTHA in your command path. " | tee -a $LOG
860 echo "" | tee -a $LOG
861 echo -en $BOLD
862 if [ $DEPLOY_K8S == "yes" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000863 echo "export KUBECONFIG=\"\$(./bin/kind get kubeconfig-path --name=\"voltha-$NAME\")\"" | tee -a $LOG
Test Userba1e7e72019-07-10 22:27:54 +0000864 fi
865 echo "export PATH=$GOPATH/bin:\$PATH" | tee -a $LOG
866 echo -en $NORMAL
867 echo "" | tee -a $LOG
868 echo "Thank you for choosing kind-voltha for you quick cluster needs." | tee -a $LOG
869 exit 0
870fi
871
David Bainbridgee87067b2019-08-12 22:00:12 +0000872STIME=$(date +%s)
Test Userb5712372019-07-03 21:52:17 +0000873bspin "Verify ETCD Operator $OLD_KEY"
Test User7d866122019-07-09 17:52:35 +0000874if [ $(helm list --deployed --short --namespace voltha "^etcd-operator\$" | wc -l) -ne 1 ]; then
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700875 espin $NOT_VERIFIED
David Bainbridge90fd8e32019-08-21 23:32:47 +0000876 helm_install - voltha etcd-operator stable/etcd-operator latest "Install ETCD Operator"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700877else
878 espin $VERIFIED
879fi
Test User01ed0642019-07-03 20:17:06 +0000880EXPECT=$(test "$TYPE" == "minimal" && echo "1" || echo "3")
David Bainbridge4f1b5562019-08-19 04:46:52 +0000881wait_for_pods - "voltha" $EXPECT "includes" -1 "Waiting for ETCD Operator to start" "etcd-operator-.*"
David Bainbridgee87067b2019-08-12 22:00:12 +0000882if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +0000883 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +0000884fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700885
David Bainbridgee87067b2019-08-12 22:00:12 +0000886STIME=$(date +%s)
David Bainbridgeb270c202019-07-26 01:44:42 +0000887if [ $WITH_ONOS == "yes" ]; then
888 bspin "Verify ONOS installed $BIRD"
889 if [ $(helm list --deployed --short --namespace default "^onos\$" | wc -l) -ne 1 ]; then
890 espin $NOT_VERIFIED
David Bainbridge90fd8e32019-08-21 23:32:47 +0000891 EXTRA_HELM_FLAGS="$SET_TAG $EXTRA_HELM_FLAGS" helm_install - default onos onf/onos latest "Install ONOS"
David Bainbridgeb270c202019-07-26 01:44:42 +0000892 else
893 espin $VERIFIED
894 fi
David Bainbridge4f1b5562019-08-19 04:46:52 +0000895 wait_for_pods - "default" 1 "includes" -1 "Waiting for ONOS to start" "onos-.*"
David Bainbridgeb270c202019-07-26 01:44:42 +0000896
897 bspin - "Forward ONOS API port $FORWARD"
David Bainbridge0774b232019-08-02 06:37:19 +0000898 for i in $(screen -ls | grep onos-ui-$NAME | awk '{print $1}'); do
David Bainbridge82bd1212019-07-29 19:19:31 +0000899 (set -x; screen -X -S $i quit >>$LOG 2>&1) >>$LOG 2>&1
900 done
David Bainbridge0774b232019-08-02 06:37:19 +0000901 (set -x; screen -dmS onos-ui-$NAME bash -c "while true; do kubectl port-forward service/onos-ui $ONOS_API_PORT:8181; done" >>$LOG 2>&1) >>$LOG 2>&1
David Bainbridgeb270c202019-07-26 01:44:42 +0000902 espin - $VERIFIED
903 bspin - "Forward ONOS SSH port $FORWARD"
David Bainbridge0774b232019-08-02 06:37:19 +0000904 for i in $(screen -ls | grep onos-ssh-$NAME | awk '{print $1}'); do
David Bainbridge82bd1212019-07-29 19:19:31 +0000905 (set -x; screen -X -S $i quit >>$LOG 2>&1) >>$LOG 2>&1
906 done
David Bainbridge2b19e832019-08-16 02:40:53 +0000907
908
David Bainbridge0774b232019-08-02 06:37:19 +0000909 (set -x; screen -dmS onos-ssh-$NAME bash -c "while true; do kubectl port-forward service/onos-ssh $ONOS_SSH_PORT:8101; done" >>$LOG 2>&1) >>$LOG 2>&1
David Bainbridgeb270c202019-07-26 01:44:42 +0000910 espin - $VERIFIED
David Bainbridged31d6122019-08-13 19:37:59 +0000911 bspin - "Verify or download ONOS configuration support files $DOWNLOAD"
David Bainbridge2b19e832019-08-16 02:40:53 +0000912 ONOS_FILES="olt-onos-enableExtraneousRules.json olt-onos-olt-settings.json onos-aaa.json \
David Bainbridge90fd8e32019-08-21 23:32:47 +0000913 onos-dhcpl2relay.json onos-kafka.json onos-sadis-sample.json"
David Bainbridged31d6122019-08-13 19:37:59 +0000914 (set -x; mkdir -p ./onos-files >>$LOG 2>&1) >>$LOG 2>&1
David Bainbridge2b19e832019-08-16 02:40:53 +0000915 for i in $ONOS_FILES; do
David Bainbridged31d6122019-08-13 19:37:59 +0000916 if [ ! -r ./onos-files/$i ]; then
917 (set -x; curl -o ./onos-files/$i -sSL https://raw.githubusercontent.com/ciena/kind-voltha/master/onos-files/$i >>$LOG 2>&1) >>$LOG 2>&1
918 fi
919 done
Test Userba1e7e72019-07-10 22:27:54 +0000920 espin - $VERIFIED
David Bainbridge27790d62019-08-13 22:43:19 +0000921
922 if [ $INSTALL_ONOS_APPS == "yes" ]; then
923 bspin - "Installing custom ONOS applications"
924 if [ -x onos-files/onos-apps -a $(ls -1 onos-files/onos-apps/*.oar 2>/dev/null | wc -l) -gt 0 ]; then
925 for OAR in $(ls -1 onos-files/onos-apps/*.oar); do
926 sspin - "Installing custom ONOS applications - $OAR$CEOL"
David Bainbridge2b19e832019-08-16 02:40:53 +0000927 override_onos_app $OAR
David Bainbridge27790d62019-08-13 22:43:19 +0000928 done
929 espin - "$VERIFIED Installing custom ONOS applications$CEOL"
930 else
931 espin - "$NOT_VERIFIED Installing custom ONOS applications - None Found"
932 fi
933 fi
David Bainbridge2b19e832019-08-16 02:40:53 +0000934
935 push_onos_config "Push ONOS Kafka Configuration" "network/configuration/apps/org.opencord.kafka" "onos-files/onos-kafka.json"
936 push_onos_config "Push ONOS DHCP L2 Relay Configuration" "network/configuration/apps/org.opencord.dhcpl2relay" "onos-files/onos-dhcpl2relay.json"
David Bainbridged31d6122019-08-13 19:37:59 +0000937 push_onos_config "Enable VOLTHA ONOS DHCP provisioning" "configuration/org.opencord.olt.impl.Olt" "onos-files/olt-onos-olt-settings.json"
938 push_onos_config "Enabling extraneous rules for ONOS" "configuration/org.onosproject.net.flow.impl.FlowRuleManager" "onos-files/olt-onos-enableExtraneousRules.json"
David Bainbridge2b19e832019-08-16 02:40:53 +0000939 if [ -f onos-files/onos-sadis.json ]; then
940 push_onos_config "[optional] Push ONOS SADIS Configuration" "network/configuration/apps/org.opencord.sadis" "onos-files/onos-sadis.json"
941 elif [ "$CONFIG_SADIS" == "yes" ]; then
David Bainbridge90fd8e32019-08-21 23:32:47 +0000942 SADIS_CFG=onos-files/onos-sadis-sample.json
David Bainbridge2b19e832019-08-16 02:40:53 +0000943 push_onos_config "[optional] Push ONOS SADIS Configuration" "network/configuration/apps/org.opencord.sadis" "$SADIS_CFG"
944 fi
Test Userba1e7e72019-07-10 22:27:54 +0000945fi
David Bainbridgee87067b2019-08-12 22:00:12 +0000946if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +0000947 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +0000948fi
Test Userba1e7e72019-07-10 22:27:54 +0000949
David Bainbridgee87067b2019-08-12 22:00:12 +0000950STIME=$(date +%s)
Test Userb5712372019-07-03 21:52:17 +0000951bspin "Verify VOLTHA installed $HIGH_VOLTAGE"
Test User7d866122019-07-09 17:52:35 +0000952if [ $(helm list --deployed --short --namespace voltha "^voltha\$" | wc -l) -ne 1 ]; then
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700953 espin $NOT_VERIFIED
David Bainbridge90fd8e32019-08-21 23:32:47 +0000954 helm_install - voltha voltha $VOLTHA_CHART $VOLTHA_CHART_VERSION "Install VOLTHA Core"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700955else
956 espin $VERIFIED
957fi
Test Userba1e7e72019-07-10 22:27:54 +0000958
David Bainbridge90fd8e32019-08-21 23:32:47 +0000959VOLTHA="voltha-ofagent-.* \
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700960 ro-core.* \
961 rw-core.* \
962 voltha-api-server-.* \
963 voltha-cli-server-.* \
964 voltha-etcd-cluster-.* \
965 voltha-kafka-.* \
966 voltha-zookeeper-.*"
Test User01ed0642019-07-03 20:17:06 +0000967EXPECT=$(test "$TYPE" == "minimal" && echo "9" || echo "11")
David Bainbridge4f1b5562019-08-19 04:46:52 +0000968wait_for_pods - "voltha" $EXPECT "includes" -1 "Waiting for VOLTHA Core to start" $VOLTHA
David Bainbridgee87067b2019-08-12 22:00:12 +0000969if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +0000970 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +0000971fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700972
David Bainbridgee87067b2019-08-12 22:00:12 +0000973STIME=$(date +%s)
Test Userb5712372019-07-03 21:52:17 +0000974echo -e "Verify Adapters $PLUG"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700975bspin - "Verify Simulated Adapters installed"
Test User7d866122019-07-09 17:52:35 +0000976if [ $(helm list --deployed --short --namespace voltha "^sim\$" | wc -l) -ne 1 ]; then
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700977 espin - $NOT_VERIFIED
David Bainbridge90fd8e32019-08-21 23:32:47 +0000978 helm_install - voltha sim $VOLTHA_ADAPTER_SIM_CHART $VOLTHA_ADAPTER_SIM_CHART_VERSION "Install Simulated Adapters"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700979else
980 espin - $VERIFIED
981fi
982
983bspin - "Verify OpenOLT Adapter installed"
Test User7d866122019-07-09 17:52:35 +0000984if [ $(helm list --deployed --short --namespace voltha "^open-olt\$" | wc -l) -ne 1 ]; then
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700985 espin - $NOT_VERIFIED
David Bainbridge90fd8e32019-08-21 23:32:47 +0000986 helm_install - voltha open-olt $VOLTHA_ADAPTER_OPEN_OLT_CHART $VOLTHA_ADAPTER_OPEN_OLT_CHART_VERSION "Install OpenOLT Adapter"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700987else
988 espin - $VERIFIED
989fi
990bspin - "Verify OpenONU Adapter installed"
Test User7d866122019-07-09 17:52:35 +0000991if [ $(helm list --deployed --short --namespace voltha "^open-onu\$" | wc -l) -ne 1 ]; then
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700992 espin - $NOT_VERIFIED
David Bainbridge90fd8e32019-08-21 23:32:47 +0000993 helm_install - voltha open-onu $VOLTHA_ADAPTER_OPEN_ONU_CHART $VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION "Install OpenONU Adapter"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700994else
995 espin - $VERIFIED
996fi
997
998ADAPTERS="adapter-.*"
David Bainbridge4f1b5562019-08-19 04:46:52 +0000999wait_for_pods - "voltha" 4 "includes" -1 "Waiting for adapters to start" $ADAPTERS
David Bainbridgee87067b2019-08-12 22:00:12 +00001000if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +00001001 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +00001002fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001003
Test User7d866122019-07-09 17:52:35 +00001004if [ $WITH_BBSIM == "yes" ]; then
David Bainbridgee87067b2019-08-12 22:00:12 +00001005 STIME=$(date +%s)
Test User7d866122019-07-09 17:52:35 +00001006 echo -e "Verify BBSIM $PLUG"
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001007 bspin - "Verify BBSIM Installed"
Test User7d866122019-07-09 17:52:35 +00001008 if [ $(helm list --deployed --short --namespace voltha "^bbsim\$" | wc -l) -ne 1 ]; then
1009 espin - $NOT_VERIFIED
David Bainbridge90fd8e32019-08-21 23:32:47 +00001010 helm_install - voltha bbsim $VOLTHA_BBSIM_CHART $VOLTHA_BBSIM_CHART_VERSION "Install BBSIM"
Test User7d866122019-07-09 17:52:35 +00001011 else
1012 espin - $VERIFIED
1013 fi
David Bainbridge4f1b5562019-08-19 04:46:52 +00001014 wait_for_pods - "voltha" 1 "includes" -1 "Waiting for BBSIM to start" "bbsim-.*"
David Bainbridgee87067b2019-08-12 22:00:12 +00001015 if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +00001016 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +00001017 fi
Test User7d866122019-07-09 17:52:35 +00001018fi
1019
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001020if [ $WITH_RADIUS == "yes" ]; then
David Bainbridgee87067b2019-08-12 22:00:12 +00001021 STIME=$(date +%s)
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001022 echo -e "Verify RADIUS $LOCK"
1023 bspin - "Verify RADIUS Installed"
1024 if [ $(helm list --deployed --short --namespace voltha "^radius\$" | wc -l) -ne 1 ]; then
1025 espin - $NOT_VERIFIED
David Bainbridge90fd8e32019-08-21 23:32:47 +00001026 helm_install - voltha radius onf/freeradius latest "Install RADIUS"
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001027 else
1028 espin - $VERIFIED
1029 fi
David Bainbridge4f1b5562019-08-19 04:46:52 +00001030 wait_for_pods - "voltha" 1 "includes" -1 "Waiting for RADIUS to start" "radius-.*"
David Bainbridgee87067b2019-08-12 22:00:12 +00001031 if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +00001032 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +00001033 fi
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001034fi
1035
David Bainbridgee87067b2019-08-12 22:00:12 +00001036STIME=$(date +%s)
David Bainbridgee10f6d52019-07-25 00:28:13 +00001037if [ $SKIP_RESTART_API == "no" ]; then
1038 echo -e "Restart VOLTHA API $RESTART"
David Bainbridge90fd8e32019-08-21 23:32:47 +00001039 API="voltha-api-server-.* voltha-ofagent-.*"
1040 (set -x; kubectl scale --replicas=0 deployment -n voltha voltha-api-server voltha-ofagent >>$LOG 2>&1) >>$LOG 2>&1
David Bainbridge4f1b5562019-08-19 04:46:52 +00001041 wait_for_pods - "voltha" 0 "includes" -1 "Wait for API to stop $STOP" $API
David Bainbridge90fd8e32019-08-21 23:32:47 +00001042 (set -x; kubectl scale --replicas=1 deployment -n voltha voltha-api-server voltha-ofagent >>$LOG 2>&1) >>$LOG 2>&1
David Bainbridge4f1b5562019-08-19 04:46:52 +00001043 wait_for_pods - "voltha" 2 "includes" -1 "Wait for API to re-start $GO" $API
David Bainbridgee10f6d52019-07-25 00:28:13 +00001044else
1045 bspin "Skip VOLTHA API Restart"
1046 espin $NO_ENTRY
1047fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001048
Test Userb5712372019-07-03 21:52:17 +00001049bspin - "Forward VOLTHA API port $FORWARD"
David Bainbridge0774b232019-08-02 06:37:19 +00001050for i in $(screen -ls | grep voltha-api-$NAME | awk '{print $1}'); do
David Bainbridge82bd1212019-07-29 19:19:31 +00001051 (set -x; screen -X -S $i quit >>$LOG 2>&1) >>$LOG 2>&1
1052done
David Bainbridge0774b232019-08-02 06:37:19 +00001053(set -x; screen -dmS voltha-api-$NAME bash -c "while true; do kubectl port-forward -n voltha service/voltha-api $VOLTHA_API_PORT:55555; done" >>$LOG 2>&1) >>$LOG 2>&1
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001054espin - $VERIFIED
Test Userb5712372019-07-03 21:52:17 +00001055bspin - "Forward VOLTHA SSH port $FORWARD"
David Bainbridge0774b232019-08-02 06:37:19 +00001056for i in $(screen -ls | grep voltha-ssh-$NAME | awk '{print $1}'); do
David Bainbridge82bd1212019-07-29 19:19:31 +00001057 (set -x; screen -X -S $i quit >>$LOG 2>&1) >>$LOG 2>&1
1058done
David Bainbridge0774b232019-08-02 06:37:19 +00001059(set -x; screen -dmS voltha-ssh-$NAME bash -c "while true; do kubectl port-forward -n voltha service/voltha-cli $VOLTHA_SSH_PORT:5022; done" >>$LOG 2>&1) >>$LOG 2>&1
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001060espin - $VERIFIED
David Bainbridgeac7f8072019-08-01 22:15:33 +00001061bspin - "Forward VOLTHA ETCD port $FORWARD"
David Bainbridge0774b232019-08-02 06:37:19 +00001062for i in $(screen -ls | grep voltha-etcd-$NAME | awk '{print $1}'); do
David Bainbridgeac7f8072019-08-01 22:15:33 +00001063 (set -x; screen -X -S $i quit >>$LOG 2>&1) >>$LOG 2>&1
1064done
David Bainbridge0774b232019-08-02 06:37:19 +00001065(set -x; screen -dmS voltha-etcd-$NAME bash -c "while true; do kubectl port-forward -n voltha service/voltha-etcd-cluster-client $VOLTHA_ETCD_PORT:2379; done" >>$LOG 2>&1) >>$LOG 2>&1
David Bainbridgeac7f8072019-08-01 22:15:33 +00001066espin - $VERIFIED
David Bainbridgee87067b2019-08-12 22:00:12 +00001067if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +00001068 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +00001069fi
Test User3d7ad8e2019-07-03 06:15:44 +00001070
David Bainbridgeb270c202019-07-26 01:44:42 +00001071if [ $WITH_ONOS == "yes" -a $WITH_RADIUS == "yes" ]; then
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001072 bspin "Configure ONOS RADIUS Connection $GEAR"
David Bainbridge2b19e832019-08-16 02:40:53 +00001073 (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 -XPOST -sSL http://karaf:karaf@localhost:8181/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 +00001074 espin $VERIFIED
1075fi
1076
1077bspin "Create voltctl configuration file"
Test User3d7ad8e2019-07-03 06:15:44 +00001078(set -x; mkdir -p $HOME/.volt >>$LOG 2>&1) >>$LOG 2>&1
David Bainbridge0774b232019-08-02 06:37:19 +00001079(set -x; voltctl -a v2 -s localhost:$VOLTHA_API_PORT config > $HOME/.volt/config-$NAME 2>>$LOG) >>$LOG 2>&1
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001080espin $VERIFIED
Test User08ebbd92019-07-03 17:15:39 +00001081
David Bainbridge0774b232019-08-02 06:37:19 +00001082if [ ! -f "$NAME-env.sh" ]; then
1083 touch $NAME-env.sh
David Bainbridgeb07fdf72019-07-29 22:51:40 +00001084fi
1085
David Bainbridge596f30d2019-07-30 17:07:59 +00001086for O in $ALL_OPTIONS; do
1087 VAL=$(eval echo \$$O)
David Bainbridge0774b232019-08-02 06:37:19 +00001088 if [ ! -z "$VAL" -a $(grep -c "^export $O=" $NAME-env.sh) -eq 0 ]; then
1089 echo "export $O=\"$(eval echo \$$O)\"" >> $NAME-env.sh
David Bainbridgeb07fdf72019-07-29 22:51:40 +00001090 fi
1091done
1092
David Bainbridge0774b232019-08-02 06:37:19 +00001093if [ $DEPLOY_K8S == "yes" -a $(grep -c "^export KUBECONFIG=" $NAME-env.sh) -eq 0 ]; then
1094 echo "export KUBECONFIG=\"$(./bin/kind get kubeconfig-path --name=voltha-$NAME)\"" >> $NAME-env.sh
David Bainbridgeb07fdf72019-07-29 22:51:40 +00001095fi
1096
David Bainbridge0774b232019-08-02 06:37:19 +00001097if [ $(grep -c "^export VOLTCONFIG=" $NAME-env.sh) -eq 0 ]; then
1098 echo "export VOLTCONFIG=\"$HOME/.volt/config-$NAME\"" >> $NAME-env.sh
David Bainbridgeb07fdf72019-07-29 22:51:40 +00001099fi
1100
David Bainbridge0774b232019-08-02 06:37:19 +00001101if [ $(grep -c "^export PATH=" $NAME-env.sh) -eq 0 ]; then
1102 echo "export PATH=\"$GOPATH/bin:\$PATH\"" >> $NAME-env.sh
David Bainbridgeb07fdf72019-07-29 22:51:40 +00001103fi
1104
Test User7d866122019-07-09 17:52:35 +00001105echo ""
Test User08ebbd92019-07-03 17:15:39 +00001106echo "Please issue the following commands in your terminal to ensure that you" | tee -a $LOG
1107echo "are accessing the correct Kubernetes/Kind cluster as well as have the " | tee -a $LOG
1108echo "tools required by VOLTHA in your command path. " | tee -a $LOG
1109echo "" | tee -a $LOG
Test User7d866122019-07-09 17:52:35 +00001110echo -en $BOLD
Test Userba1e7e72019-07-10 22:27:54 +00001111if [ $DEPLOY_K8S == "yes" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +00001112 echo "export KUBECONFIG=\"\$(./bin/kind get kubeconfig-path --name=\"voltha-$NAME\")\"" | tee -a $LOG
Test Userba1e7e72019-07-10 22:27:54 +00001113fi
David Bainbridge0774b232019-08-02 06:37:19 +00001114echo "export VOLTCONFIG=\"$HOME/.volt/config-$NAME\"" | tee -a $LOG
Test Userba1e7e72019-07-10 22:27:54 +00001115echo "export PATH=$GOPATH/bin:\$PATH" | tee -a $LOG
Test User7d866122019-07-09 17:52:35 +00001116echo -en $NORMAL
Test User08ebbd92019-07-03 17:15:39 +00001117echo "" | tee -a $LOG
1118echo "Thank you for choosing kind-voltha for you quick cluster needs." | tee -a $LOG
1119
David Bainbridge712afb82019-08-14 19:55:58 +00001120if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridgef858a022019-08-14 21:25:11 +00001121 echo -e "$CLOCK ${BOLD}TOTAL: $(duration $(expr $(date +%s) - $TOTAL_START_TIME))${NORMAL}"
David Bainbridge712afb82019-08-14 19:55:58 +00001122fi
1123