blob: 90184371e8fd263f2a3a21cd8d52b8062edf0ed4 [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 Bainbridge99ac7a22019-08-31 02:26:43 +000074WITH_CHAOS=${WITH_CHAOS:-no}
David Bainbridge2b19e832019-08-16 02:40:53 +000075CONFIG_SADIS=${CONFIG_SADIS:-no}
David Bainbridge27790d62019-08-13 22:43:19 +000076INSTALL_ONOS_APPS=${INSTALL_ONOS_APPS:-no}
Test Userba1e7e72019-07-10 22:27:54 +000077JUST_K8S=${JUST_K8S:-no}
78DEPLOY_K8S=${DEPLOY_K8S:-yes}
David Bainbridgea3b56322019-09-03 20:40:42 +000079SKIP_RESTART_API=${SKIP_RESTART_API:-yes}
David K. Bainbridge0e89cb92019-07-17 11:30:10 -070080INSTALL_KUBECTL=${INSTALL_KUBECTL:-yes}
81INSTALL_HELM=${INSTALL_HELM:-yes}
David Bainbridge4f1b5562019-08-19 04:46:52 +000082WAIT_ON_DOWN=${WAIT_ON_DOWN:-no}
David Bainbridge5b7b96b2019-07-25 20:29:13 +000083VOLTHA_LOG_LEVEL=${VOLTHA_LOG_LEVEL:-WARN}
David Bainbridge90fd8e32019-08-21 23:32:47 +000084VOLTHA_CHART=${VOLTHA_CHART:-onf/voltha}
85VOLTHA_CHART_VERSION=${VOLTHA_CHART_VERSION:-latest}
86VOLTHA_BBSIM_CHART=${VOLTHA_BBSIM_CHART:-onf/bbsim}
87VOLTHA_BBSIM_CHART_VERSION=${VOLTHA_BBSIM_CHART_VERSION:-latest}
David Bainbridgee10f6d52019-07-25 00:28:13 +000088VOLTHA_ADAPTER_SIM_CHART=${VOLTHA_ADAPTER_SIM_CHART:-onf/voltha-adapter-simulated}
David Bainbridge90fd8e32019-08-21 23:32:47 +000089VOLTHA_ADAPTER_SIM_CHART_VERSION=${VOLTHA_ADAPTER_SIM_CHART_VERSION:-latest}
David Bainbridgee10f6d52019-07-25 00:28:13 +000090VOLTHA_ADAPTER_OPEN_OLT_CHART=${VOLTHA_ADAPTER_OPEN_OLT_CHART:-onf/voltha-adapter-openolt}
David Bainbridge90fd8e32019-08-21 23:32:47 +000091VOLTHA_ADAPTER_OPEN_OLT_CHART_VERSION=${VOLTHA_ADAPTER_OPEN_OLT_CHART_VERSION:-latest}
David Bainbridgee10f6d52019-07-25 00:28:13 +000092VOLTHA_ADAPTER_OPEN_ONU_CHART=${VOLTHA_ADAPTER_OPEN_ONU_CHART:-onf/voltha-adapter-openonu}
David Bainbridge90fd8e32019-08-21 23:32:47 +000093VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION=${VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION:-latest}
94
Test Userba1e7e72019-07-10 22:27:54 +000095
96HAVE_GO=$(which go >/dev/null 2>&1 && echo "yes" || echo "no")
97HOSTOS=$(uname -s | tr "[:upper:]" "[:lower:"])
98HOSTARCH=$(uname -m | tr "[:upper:]" "[:lower:"])
99if [ $HOSTARCH == "x86_64" ]; then
100 HOSTARCH="amd64"
101fi
Test User7d866122019-07-09 17:52:35 +0000102
103# Verify TYPE setting
104if [ $(echo ":minimal:full:" | grep -ic ":$TYPE:") -eq 0 ]; then
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700105 >&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 +0000106 exit 1
107fi
108
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000109# Used to verify configuration values are set to "yes" or "no" value or convert
110# equivalents to "yes" or "no"
111function verify_yes_no() {
112 local VAR=$1
113 local VAL=$(eval echo \$$VAR)
114 if [ $(echo ":y:yes:true:n:no:false:1:0:" | grep -ic ":$VAL:") -eq 0 ]; then
115 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} Invalid '$VAR' value of '$VAL'. Should be 'yes' or 'no'${NORMAL}"
116 echo "INVALID"
117 return 1
118 fi
119 if [ $(echo ":y:yes:true:1:" | grep -ic ":$VAL:") -eq 1 ]; then
120 echo "yes"
121 else
122 echo "no"
123 fi
124 return 0
125}
Test User7d866122019-07-09 17:52:35 +0000126
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000127ALL_YES_NO="\
128 WITH_TIMINGS \
129 WITH_BBSIM \
130 WITH_RADIUS \
131 WITH_ONOS \
David Bainbridge99ac7a22019-08-31 02:26:43 +0000132 WITH_CHAOS \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000133 CONFIG_SADIS \
134 JUST_K8S \
135 DEPLOY_K8S \
136 INSTALL_ONOS_APPS \
137 SKIP_RESTART_API \
138 INSTALL_KUBECTL \
139 INSTALL_HELM \
David Bainbridge4f1b5562019-08-19 04:46:52 +0000140 WAIT_ON_DOWN \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000141 "
David Bainbridge5b7b96b2019-07-25 20:29:13 +0000142
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000143ALL_OPTIONS="\
144 NAME \
145 TYPE \
146 $ALL_YES_NO \
147 VOLTHA_LOG_LEVEL \
148 VOLTHA_CHART \
David Bainbridge90fd8e32019-08-21 23:32:47 +0000149 VOLTHA_CHART_VERSION \
150 VOLTHA_BBSIM_CHART \
151 VOLTHA_BBSIM_CHART_VERSION \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000152 VOLTHA_ADAPTER_SIM_CHART \
David Bainbridge90fd8e32019-08-21 23:32:47 +0000153 VOLTHA_ADAPTER_SIM_CHART_VERSION \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000154 VOLTHA_ADAPTER_OPEN_OLT_CHART \
David Bainbridge90fd8e32019-08-21 23:32:47 +0000155 VOLTHA_ADAPTER_OPEN_OLT_CHART_VERSION \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000156 VOLTHA_ADAPTER_OPEN_ONU_CHART \
David Bainbridge90fd8e32019-08-21 23:32:47 +0000157 VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000158 ONOS_API_PORT \
159 ONOS_SSH_PORT \
160 VOLTHA_API_PORT \
161 VOLTHA_SSH_PORT \
162 VOLTHA_ETCD_PORT \
163 "
David Bainbridge01294952019-07-30 19:33:45 +0000164
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000165# Iterate over yes/no configuration options and validate
166for VAR in $ALL_YES_NO; do
167 eval $VAR=$(verify_yes_no $VAR)
168 if [ "$(eval echo \$$VAR)" == "INVALID" ]; then
169 exit 1;
170 fi
171done
David Bainbridgeb270c202019-07-26 01:44:42 +0000172
David Bainbridge0774b232019-08-02 06:37:19 +0000173mkdir -p .voltha
174touch .voltha/ports
175HAVE=$(grep $NAME .voltha/ports)
176if [ "$HAVE X" == " X" ]; then
177 # Find free port prefix
178 START=81
179 while true; do
180 if [ $(grep -c $START .voltha/ports) -eq 0 ]; then
181 break
182 fi
183 START=$(expr $START + 1)
184 done
185 DELTA=$(expr $START - 81)
186 ONOS_API_PORT=${START}81
187 ONOS_SSH_PORT=${START}01
188 VOLTHA_API_PORT=5$(expr 55 + $DELTA)55
189 VOLTHA_SSH_PORT=$(expr 50 + $DELTA)22
190 VOLTHA_ETCD_PORT=$(expr 23 + $DELTA)79
Test User01ed0642019-07-03 20:17:06 +0000191else
David Bainbridge0774b232019-08-02 06:37:19 +0000192 VALUES=$(echo $HAVE | sed -e 's/\s//g' | cut -d= -f2)
193 ONOS_API_PORT=$(echo $VALUES | cut -d, -f1)
194 ONOS_SSH_PORT=$(echo $VALUES | cut -d, -f2)
195 VOLTHA_API_PORT=$(echo $VALUES | cut -d, -f3)
196 VOLTHA_SSH_PORT=$(echo $VALUES | cut -d, -f4)
197 VOLTHA_ETCD_PORT=$(echo $VALUES | cut -d, -f5)
Test User01ed0642019-07-03 20:17:06 +0000198fi
199
David Bainbridge0774b232019-08-02 06:37:19 +0000200PORTTMP=$(mktemp -u)
201cat .voltha/ports | grep -v $NAME > $PORTTMP
202echo "$NAME=$ONOS_API_PORT,$ONOS_SSH_PORT,$VOLTHA_API_PORT,$VOLTHA_SSH_PORT,$VOLTHA_ETCD_PORT" >> $PORTTMP
203cp $PORTTMP .voltha/ports
204rm -f $PORTTMP
205
David Bainbridge27790d62019-08-13 22:43:19 +0000206export ONOS_API_PORT ONOS_SSH_PORT
David Bainbridge01294952019-07-30 19:33:45 +0000207
Test Userd87942b2019-07-03 07:20:24 +0000208IDX=1
David Bainbridgee87067b2019-08-12 22:00:12 +0000209CLOCK="TIME:"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000210SPIN_PARTS=
211NOT_VERIFIED=
David Bainbridgef858a022019-08-14 21:25:11 +0000212THEX=
213BUILD=
214CROSS=
215ENTER=
David Bainbridge38dc1e82019-08-12 15:18:45 +0000216VERIFIED=
217HELM=
218OLD_KEY=
219BIRD=
220HIGH_VOLTAGE=
221PLUG=
222RESTART=
223FORWARD=
224INSTALL=
225STOP=
226GO=
227DOWNLOAD=
228GEAR=
229NO_ENTRY=
230LOCK=
231
232if [ $FANCY -eq 1 ]; then
233 SPIN_PARTS="\
234 \xe2\xa2\x8e\xe2\xa1\xb0 \
235 \xe2\xa2\x8e\xe2\xa1\xa1 \
236 \xe2\xa2\x8e\xe2\xa1\x91 \
237 \xe2\xa2\x8e\xe2\xa0\xb1 \
238 \xe2\xa0\x8e\xe2\xa1\xb1 \
239 \xe2\xa2\x8a\xe2\xa1\xb1 \
240 \xe2\xa2\x8c\xe2\xa1\xb1 \
241 \xe2\xa2\x86\xe2\xa1\xb1 \
242 "
David Bainbridgee87067b2019-08-12 22:00:12 +0000243 CLOCK="\xe2\x8f\xb1"
David Bainbridgef858a022019-08-14 21:25:11 +0000244 THEX="${RED}${BOLD}\xe2\x9c\x97\x20${NORMAL}"
245 ENTER="${YELLOW}${BOLD}\xe2\x8e\x86${NORMAL}"
246 CROSS="${YELLOW}${BOLD}\xe2\x9c\x9a${NORMAL}"
247 BUILD="${YELLOW}${BOLD}\xf0\x9f\x8f\x97${NORMAL}"
248 NOT_VERIFIED="$BUILD"
249 VERIFIED="${GREEN}${BOLD}\xe2\x9c\x93\x20${NORMAL}"
250 HELM="${BLUE}${BOLD}\xE2\x8E\x88${NORMAL}"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000251 OLD_KEY="\xF0\x9F\x97\x9D"
252 BIRD="\xF0\x9F\x90\xA6"
253 HIGH_VOLTAGE="\xE2\x9A\xA1"
254 PLUG="\xF0\x9F\xa7\xa9"
255 RESTART="\xf0\x9f\x94\x84"
256 FORWARD="\xE2\x87\xA8"
257 INSTALL="\xF0\x9F\x8F\x97"
258 STOP="\xf0\x9f\x9b\x91"
259 GO="\xf0\x9f\x9a\x80"
260 DOWNLOAD="\xf0\x9f\x93\xa5"
261 GEAR="\xe2\x9a\x99"
262 NO_ENTRY="\xe2\x9b\x94"
263 LOCK="\xf0\x9f\x94\x92"
264fi
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700265
David Bainbridge712afb82019-08-14 19:55:58 +0000266duration() {
David Bainbridgee87067b2019-08-12 22:00:12 +0000267 local h=$(expr $1 / 3600)
268 local m=$(expr $1 % 3600 / 60)
269 local s=$(expr $1 % 60)
270 local t=""
271
272 if [ $h -gt 0 ]; then
273 t="$t${h}h"
274 fi
275 if [ $m -gt 0 ]; then
276 t="$t${m}m"
277 fi
David Bainbridge712afb82019-08-14 19:55:58 +0000278 echo "$t${s}s"
279}
280
281printtime() {
282 local INDENT=
283 if [ "$1" == "-" ]; then
284 INDENT=" "
285 shift
286 fi
287 echo -e "$INDENT $CLOCK $(duration $1)"
David Bainbridgee87067b2019-08-12 22:00:12 +0000288}
289
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700290bspin() {
Test Userd87942b2019-07-03 07:20:24 +0000291 IDX=1
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700292 local INDENT=
293 if [ "$1" == "-" ]; then
294 INDENT=" "
295 shift
296 fi
David Bainbridge38dc1e82019-08-12 15:18:45 +0000297 if [ $FANCY -eq 0 ]; then
298 LINE=$(echo $* | sed -e 's/[\s+-]//g')
299 if [ "$LINE X" == " X" ]; then
300 return
301 fi
302 echo -e "$CIVIS$INDENT$*"
303 else
304 echo -en "$CIVIS$INDENT $*"
305 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700306}
307
308sspin() {
309 local INDENT=
310 if [ "$1" == "-" ]; then
311 INDENT=" "
312 shift
313 fi
David Bainbridge38dc1e82019-08-12 15:18:45 +0000314 if [ $FANCY -eq 0 ]; then
315 LINE=$(echo $* | sed -e 's/[\s+-]//g')
316 if [ "$LINE X" == " X" ]; then
317 return
318 fi
319 echo -e "$INDENT$*"
320 else
321 C=$(echo $SPIN_PARTS | cut '-d ' -f $IDX)
322 echo -en "\r$INDENT$C $*"
323 IDX=$(expr $IDX + 1)
324 if [ $IDX -gt 8 ]; then
325 IDX=1
326 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700327 fi
328}
329
330espin() {
331 local INDENT=
332 if [ "$1" == "-" ]; then
333 INDENT=" "
334 shift
335 fi
David Bainbridge38dc1e82019-08-12 15:18:45 +0000336 if [ $FANCY -eq 0 ]; then
337 LINE=$(echo $* | sed -e 's/[\s+-]//g')
338 if [ "$LINE X" == " X" ]; then
339 return
340 fi
341 echo -e "$INDENT$*"
342 else
343 echo -e "\r$INDENT$*$CNORM"
344 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700345}
346
David Bainbridgeac7f8072019-08-01 22:15:33 +0000347if [ "$1" == "get" -a "$2" == "voltconfig" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000348 echo "$HOME/.volt/config-$NAME"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000349 exit
350fi
351
352if [ $# -ne 1 -o $(echo ":up:down:dump:" | grep -c ":$1:") -ne 1 ]; then
353 >&2 echo "What wouild you like to do today:"
354 >&2 echo " up - bring up voltha"
355 >&2 echo " down - tear down voltha"
356 >&2 echo " dump - create a debug dump of running system"
357 exit 1
358fi
359
David Bainbridge4f1b5562019-08-19 04:46:52 +0000360push_onos_config() {
361 local MSG=$1
362 local RESOURCE=$2
363 local DATA=$3
364
365 bspin - "$MSG $GEAR"
366 while true; do
367 (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
368 if [ $? -eq 0 ]; then
369 break
370 fi
371 sleep .2
372 sspin -
373 done
374 espin - $VERIFIED
375}
376
377override_onos_app() {
378 local APP=$1
379 local NAME=$(basename $APP | sed -e 's/^[0-9][0-9]*-//g' -e 's/-.*$//g')
380 while true; do
381 sspin -
382 # Attempt to delete old version (if it exists)
383 (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
384 sspin -
385 if [ $? -ne 0 ]; then
386 continue
387 fi
388 (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
389 if [ $? -eq 0 ]; then
390 break
391 fi
392 sleep .2
393 done
394}
395
396activate_onos_app() {
397 local MSG="$1"
398 local APP=$2
399
400 bspin - "$MSG $GO"
401 while true; do
402 sspin -
403 (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
404 if [ $? -eq 0 ]; then
405 break
406 fi
407 sleep .2
408 done
409 espin - "$VERIFIED"
410}
411
412count_pods() {
413 local NAMESPACE=$1; shift
414 if [ "$NAMESPACE" == "all-namespaces" ]; then
415 NAMESPACE="--all-namespaces"
416 else
417 NAMESPACE="-n $NAMESPACE"
418 fi
419 echo "$NAMESPACE" > /tmp/t
420 local STATES=$1; shift
421 echo "$STATES" >> /tmp/t
422 local PODS=$(kubectl get $NAMESPACE pod -o go-template="{{range .items}}{{.metadata.name}}/{{.status.phase}}/_{{range .status.containerStatuses}}{{.ready}}_{{end}} {{end}}")
423 local COUNT=0
424 local PATTERNS="$*"
425 for POD in $PODS; do
426 local NAME=$(echo $POD | cut -d/ -f 1)
427 local STATE=$(echo $POD | cut -d/ -f 2)
428 local CONTAINERS=$(echo $POD | cut -d/ -f 3 | sed -e 's/_/ /g')
429 if [ "$STATES" == "*" -o $(echo "$STATES" | grep -c ":$STATE:") -ne 0 ]; then
430 echo "IN WITH $POD" >> /tmp/t
431 local TOTAL=$(echo $CONTAINERS | wc -w)
432 local FOUND=$(echo $CONTAINERS | grep -o true | wc -l)
433 if [ $TOTAL -eq $FOUND ]; then
434 for PATTERN in $PATTERNS; do
435 echo "TEST $PATTERN AGAINST $NAME" >> /tmp/t
436 if [[ $NAME =~ $PATTERN ]]; then
437 echo "COUNT $NAME" >> /tmp/t
438 COUNT=$(expr $COUNT + 1)
439 break
440 fi
441 done
442 fi
443 fi
444 done
445 echo $COUNT >> /tmp/t
446 echo $COUNT
447}
448
449wait_for_pods() {
450 local INDENT=
451 if [ "$1" == "-" ]; then
452 INDENT=$1; shift
453 fi
454 local NAMESPACE=$1; shift
455 local EXPECT=$1; shift
456 local TYPE=$1; shift
457 local RETRY=$1; shift
458 local MESSAGE=$1; shift
459 local PATTERNS=$*
David Bainbridge99ac7a22019-08-31 02:26:43 +0000460 local STATES=":Running:"
461 if [ "$TYPE" == "not" ]; then
462 STATES="*"
463 fi
464 local HAVE=$(count_pods $NAMESPACE "$STATES" $PATTERNS)
David Bainbridge4f1b5562019-08-19 04:46:52 +0000465 local ALL=$HAVE
466 if [ "$TYPE" == "only" ]; then
467 ALL=$(count_pods "all-namespaces" "*" ".*")
468 fi
469 COUNT=$(expr 300 / 15)
470 bspin $INDENT $MESSAGE
471 sspin $INDENT
472 if [ $HAVE -ne $EXPECT -o $ALL -ne $HAVE ]; then
473 while [ $HAVE -ne $EXPECT -o $ALL -ne $HAVE ]; do
474 sspin $INDENT
475 COUNT=$(expr $COUNT - 1)
476 if [ $COUNT -eq 0 ]; then
David Bainbridge99ac7a22019-08-31 02:26:43 +0000477 HAVE=$(count_pods $NAMESPACE "$STATES" $PATTERNS)
David Bainbridge4f1b5562019-08-19 04:46:52 +0000478 ALL=$HAVE
479 if [ "$TYPE" == "only" ]; then
480 ALL=$(count_pods "all-namespaces" "*" ".*")
481 fi
482 COUNT=$(expr 300 / 15)
483 fi
484 sleep .15
485 done
486 fi
487 espin $INDENT $VERIFIED
488 if [ $HAVE -ne $EXPECT ]; then
489 return 1
490 fi
491 return 0
492}
493
David Bainbridgeac7f8072019-08-01 22:15:33 +0000494if [ "$1" == "down" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000495 echo "Tearing down voltha cluster $NAME"
496 LOG="down-$NAME.log"
497 echo $(date -u +"%Y%m%dT%H%M%SZ") >$LOG
David Bainbridgeac7f8072019-08-01 22:15:33 +0000498 if [ $DEPLOY_K8S == "yes" ]; then
499 if [ -x ./bin/kind ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000500 bspin "Delete Kubernetes Kind Cluster"
501 (set -x; ./bin/kind delete cluster --name voltha-$NAME >>$LOG 2>&1) >>$LOG 2>&1
502 espin $VERIFIED
David Bainbridgeac7f8072019-08-01 22:15:33 +0000503 else
David Bainbridge0774b232019-08-02 06:37:19 +0000504 espin "$NO_ENTRY Delete Kubernetes Kind Cluster: kind command not found"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000505 fi
506 else
507 EXISTS=$(helm list -q)
508 EXPECT="etcd-operator onos open-olt open-onu sim voltha bbsim radius"
David Bainbridge0774b232019-08-02 06:37:19 +0000509 bspin "Remove Helm Deployments"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000510 for i in $EXISTS; do
511 if [ $(echo $EXPECT | grep -c $i) -eq 1 ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000512 sspin "Remove Helm Deployments: $i$CEOL"
513 (set -x; ./bin/helm delete --purge $i >>$LOG 2>&1) >>$LOG 2>&1
David Bainbridgeac7f8072019-08-01 22:15:33 +0000514 fi
515 done
David Bainbridge0774b232019-08-02 06:37:19 +0000516 espin "$VERIFIED Remove Helm Deployments$CEOL"
David Bainbridge4f1b5562019-08-19 04:46:52 +0000517 if [ "$WAIT_ON_DOWN" == "yes" ]; then
518 # There should only be 13 or 15 PODs in the kube-system name
519 # space and no other PODs
David Bainbridge4f1b5562019-08-19 04:46:52 +0000520 PODS="coredns-.* \
521 etcd-voltha-$NAME-control-plane \
522 kindnet-.* \
523 kube-apiserver-voltha-$NAME-control-plane \
524 kube-controller-manager-voltha-$NAME-control-plane \
525 kube-proxy-.* \
526 kube-scheduler-voltha-$NAME-control-plane \
527 tiller-deploy-.*"
528 EXPECT=$(test "$TYPE" == "minimal" && echo "13" || echo "15")
David Bainbridge99ac7a22019-08-31 02:26:43 +0000529 PODS="adapter-.* \
530 bbsim.* \
531 etcd-operator.* \
532 radius.* \
533 voltha-.*"
534 EXPECT=0
535
536 wait_for_pods "voltha" $EXPECT "not" -1 "Waiting for VOLTHA PODs to terminate" $PODS
David Bainbridge4f1b5562019-08-19 04:46:52 +0000537 fi
David Bainbridgeac7f8072019-08-01 22:15:33 +0000538 fi
David Bainbridge0774b232019-08-02 06:37:19 +0000539 bspin "Remove port-forwards: onos-ui-$NAME"
540 for i in $(screen -ls | grep onos-ui-$NAME | awk '{print $1}'); do
541 sspin
542 (set -x; screen -X -S $i quit >>$LOG 2>&1) >>$LOG 2>&1
543 done
544 sspin "Remove port-forwards: onos-ssh-$NAME$CEOL"
545 for i in $(screen -ls | grep onos-ssh-$NAME | awk '{print $1}'); do
546 sspin
547 (set -x; screen -X -S $i quit >>$LOG 2>&1) >>$LOG 2>&1
548 done
549 sspin "Remove port-forwards: voltha-api-$NAME$CEOL"
550 for i in $(screen -ls | grep voltha-api-$NAME | awk '{print $1}'); do
551 sspin
552 (set -x; screen -X -S $i quit >>$LOG 2>&1) >>$LOG 2>&1
553 done
554 sspin "Remove port-forwards: voltha-ssh-$NAME$CEOL"
555 for i in $(screen -ls | grep voltha-ssh-$NAME | awk '{print $1}'); do
556 sspin
557 (set -x; screen -X -S $i quit >>$LOG 2>&1) >>$LOG 2>&1
558 done
559 sspin "Remove port-forwards: voltha-etcd-$NAME$CEOL"
560 for i in $(screen -ls | grep voltha-etcd-$NAME | awk '{print $1}'); do
561 sspin
562 (set -x; screen -X -S $i quit >>$LOG 2>&1) >>$LOG 2>&1
563 done
564 espin "$VERIFIED Remove port-forwards$CEOL"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000565 exit
566fi
567
568if [ "$1" == "dump" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000569 LOG="dump-$NAME.log"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000570 TS=$(date -u +"%Y%m%dT%H%M%SZ")
571 WORK=$(mktemp -u -d)
David Bainbridge0774b232019-08-02 06:37:19 +0000572 DATA=$WORK/voltha-debug-dump-$NAME-$TS
David Bainbridgeac7f8072019-08-01 22:15:33 +0000573 mkdir -p $DATA
574 echo $TS > $LOG
David Bainbridge0774b232019-08-02 06:37:19 +0000575 echo -e "Capturing debug dump to voltha-debug-dump-$NAME-$TS.tgz"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000576 bspin - "Copy install log"
David Bainbridge0774b232019-08-02 06:37:19 +0000577 if [ -f install-$NAME.log ]; then
578 (set -x; cp install-$NAME.log $DATA/install-$NAME.log) >>$LOG 2>&1
David Bainbridgeac7f8072019-08-01 22:15:33 +0000579 espin - $VERIFIED
580 else
David Bainbridge0774b232019-08-02 06:37:19 +0000581 espin - "$NO_ENTRY Copy install log: install-$NAME.log not found"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000582 fi
583 bspin - "Dumping Kubernetes PODs"
584 (set -x; kubectl get --all-namespaces pods >> $DATA/all-pods.txt 2>&1) >>$LOG 2>&1
585 espin - $VERIFIED
586 bspin - "Dumping Kubernetes SERVICEs"
587 (set -x; kubectl get --all-namespaces svc >> $DATA/all-services.txt 2>&1) >>$LOG 2>&1
588 espin - $VERIFIED
589 bspin - "Dumping Kubernetes EVENTs"
590 (set -x; kubectl get --all-namespaces events >> $DATA/all-events.txt 2>&1) >>$LOG 2>&1
591 espin - $VERIFIED
592 bspin - "Dumping VOLTHA POD details"
593 PODS=$(kubectl get -n voltha pod -o name)
594 for POD in $PODS; do
595 sspin - "Dumping VOLTHA POD details: $POD$CEOL"
596 mkdir -p $DATA/$POD
597 (set -x; kubectl describe -n voltha $POD >> $DATA/$POD/describe.txt 2>&1) >>$LOG 2>&1
598 sspin - "Dumping VOLTHA POD details: $POD"
599 (set -x; kubectl logs -n voltha --all-containers --previous $LOG_ARGS $POD >> $DATA/$POD/logs-previous.txt 2>&1) >>$LOG 2>&1
600 sspin - "Dumping VOLTHA POD details: $POD"
601 (set -x; kubectl logs -n voltha --all-containers $LOG_ARGS $POD >> $DATA/$POD/logs-current.txt 2>&1) >>$LOG 2>&1
602 sspin - "Dumping VOLTHA POD details: $POD"
603 done
604 espin - "$VERIFIED Dumping VOLTHA POD details$CEOL"
605 bspin - "Dumping ETCD"
606 if [ "$(which etcdctl) X" != " X" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000607 (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 +0000608 espin - $VERIFIED
609 else
610 espin - "$NO_ENTRY Dumping ETCD: etcdctl command not available"
611 fi
David Bainbridge0774b232019-08-02 06:37:19 +0000612 bspin - "Creating compressed TAR: voltha-debug-dump-$NAME-$TS.tgz"
613 (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 +0000614 espin - $VERIFIED
615 bspin - "Cleanup"
616 (set -x; rm -rf $WORK) >>$LOG 2>&1
617 espin - $VERIFIED
David Bainbridge0774b232019-08-02 06:37:19 +0000618 bspin - "$(ls -l voltha-debug-dump-$NAME-$TS.tgz)"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000619 espin - $VERIFIED
620 exit
621fi
622
David Bainbridge0774b232019-08-02 06:37:19 +0000623LOG="install-$NAME.log"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000624date > $LOG
David Bainbridge0774b232019-08-02 06:37:19 +0000625echo "PORTS=$ONOS_API_PORT,$ONOS_SSH_PORT,$VOLTHA_API_PORT,$VOLTHA_SSH_PORT,$VOLTHA_ETCD_PORT" >> $LOG
David Bainbridgeac7f8072019-08-01 22:15:33 +0000626
627# Output install options to log
628echo "OPTIONS" >> $LOG
David Bainbridgeac7f8072019-08-01 22:15:33 +0000629for O in $ALL_OPTIONS; do
630 VAL=$(eval echo \$$O)
David Bainbridgeac7f8072019-08-01 22:15:33 +0000631 if [ ! -z "$VAL" ]; then
632 printf " %-30s = %s\n" $O $VAL >> $LOG
633 fi
634done
635
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700636helm_install() {
637 local INDENT=
638 if [ "$1" == "-" ]; then
639 INDENT=$1; shift
640 fi
641 local NAMESPACE=$1; shift
David Bainbridge0774b232019-08-02 06:37:19 +0000642 local INAME=$1; shift
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700643 local CHART=$1; shift
David Bainbridge90fd8e32019-08-21 23:32:47 +0000644 local CHART_VERSION=$1; shift
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700645 local MESSAGE=$*
646
David Bainbridge90fd8e32019-08-21 23:32:47 +0000647 if [ "$CHART_VERSION X" != " X" -a "$CHART_VERSION" != "latest" ]; then
648 CHART_VERSION="--version $CHART_VERSION"
649 else
650 CHART_VERSION=
651 fi
652
David Bainbridge99ac7a22019-08-31 02:26:43 +0000653 local CHART_ARGS=
654 if [ -r "${INAME}-values.yaml" ]; then
655 CHART_ARGS="-f ${INAME}-values.yaml"
656 fi
657
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700658 COUNT=$(expr 300 / 15)
659 bspin $INDENT $MESSAGE
David Bainbridge99ac7a22019-08-31 02:26:43 +0000660 (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
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700661 SUCCESS=$?
662 while [ $SUCCESS -ne 0 ]; do
663 sspin $INDENT
664 COUNT=$(expr $COUNT - 1)
665 if [ $COUNT -eq 0 ]; then
David Bainbridge99ac7a22019-08-31 02:26:43 +0000666 (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
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700667 COUNT=$(expr 300 / 15)
668 fi
669 sleep .15
670 done
671 espin $INDENT $VERIFIED
672}
673
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700674echo "INSTALL TYPE: $TYPE" >> $LOG
675
676bspin "Verify GOPATH"
677export GOPATH=$(pwd)
Test User3d7ad8e2019-07-03 06:15:44 +0000678mkdir -p $GOPATH/bin
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700679espin $VERIFIED
680
David Bainbridgee87067b2019-08-12 22:00:12 +0000681STIME=$(date +%s)
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700682if [ "$INSTALL_KUBECTL" == "no" ]; then
683 bspin "Skip kubectl install"
684 espin $NO_ENTRY
Test Userc13bdc92019-07-03 20:57:49 +0000685else
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700686 bspin "Verify kubectl $HELM"
687 if [ -x $GOPATH/bin/kubectl ]; then
688 espin $VERIFIED
689 else
690 espin $NOT_VERIFIED
691 bspin - "Download and install Kubernetes/kubectl $DOWNLOAD"
692 (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
693 (set -x; chmod 755 $GOPATH/bin/kubectl >>$LOG 2>&1) >>$LOG 2>&1
694 espin - $VERIFIED
695 fi
Test Userc13bdc92019-07-03 20:57:49 +0000696fi
David Bainbridgee87067b2019-08-12 22:00:12 +0000697if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +0000698 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +0000699fi
Test Userc13bdc92019-07-03 20:57:49 +0000700
David Bainbridgee87067b2019-08-12 22:00:12 +0000701STIME=$(date +%s)
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700702if [ "$DEPLOY_K8S" == "no" ]; then
703 bspin "Skip Kubernetes/Kind Deployment"
704 espin $NO_ENTRY
705else
Test Userba1e7e72019-07-10 22:27:54 +0000706 bspin "Verify Kubernetes/Kind $HELM"
707 if [ -x $GOPATH/bin/kind ]; then
708 espin $VERIFIED
709 else
710 espin $NOT_VERIFIED
711 bspin - "Download and install Kubernetes/kind $DOWNLOAD"
David Bainbridge9e2a6662019-07-11 17:07:57 +0000712 (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 +0000713 (set -x; chmod 755 $GOPATH/bin/kind >>$LOG 2>&1) >>$LOG 2>&1
714 espin - $VERIFIED
715 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700716fi
717
David Bainbridgee87067b2019-08-12 22:00:12 +0000718if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +0000719 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +0000720fi
721
722STIME=$(date +%s)
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700723if [ "$INSTALL_HELM" == "no" ]; then
724 bspin "Skip Helm Install"
725 espin $NO_ENTRY
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700726else
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700727 bspin "Verify Helm $HELM"
728 if [ -x $GOPATH/bin/helm ]; then
729 espin $VERIFIED
730 else
731 espin $NOT_VERIFIED
732 bspin - "Download and install Helm $DOWNLOAD"
733 (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
734 espin - $VERIFIED
735 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700736fi
David Bainbridgee87067b2019-08-12 22:00:12 +0000737if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +0000738 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +0000739fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700740
David Bainbridgee87067b2019-08-12 22:00:12 +0000741STIME=$(date +%s)
Test Userb5712372019-07-03 21:52:17 +0000742bspin "Verify voltctl $HIGH_VOLTAGE"
Test User3d7ad8e2019-07-03 06:15:44 +0000743if [ -x $GOPATH/bin/voltctl ]; then
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700744 espin $VERIFIED
745else
746 espin $NOT_VERIFIED
David Bainbridge99ac7a22019-08-31 02:26:43 +0000747 bspin - "Download and install voltctl $DOWNLOAD"
Test Userba1e7e72019-07-10 22:27:54 +0000748 (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 +0000749 (set -x; chmod 755 $GOPATH/bin/voltctl >>$LOG 2>&1) >>$LOG 2>&1
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700750 espin - $VERIFIED
751fi
David Bainbridgee87067b2019-08-12 22:00:12 +0000752if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +0000753 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +0000754fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700755
756bspin "Verify command PATH"
Test Userba1e7e72019-07-10 22:27:54 +0000757export PATH=$GOPATH/bin:$PATH
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700758espin $VERIFIED
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700759
David Bainbridgee87067b2019-08-12 22:00:12 +0000760STIME=$(date +%s)
Test Userba1e7e72019-07-10 22:27:54 +0000761if [ "$DEPLOY_K8S" == "yes" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000762 HAVE=$(kind get clusters | grep -c voltha-$NAME)
Test Userba1e7e72019-07-10 22:27:54 +0000763 bspin "Verify Kubernetes/Kind Cluster"
764 sspin
765 if [ $HAVE -eq 0 ]; then
David Bainbridge491b1bd2019-07-11 17:53:11 +0000766 espin $NOT_VERIFIED
767 bspin - "Verify cluster configuration"
David Bainbridge0774b232019-08-02 06:37:19 +0000768 if [ ! -r ./$NAME-cluster.cfg ]; then
David Bainbridge491b1bd2019-07-11 17:53:11 +0000769 espin - $NOT_VERIFIED
David Bainbridge0774b232019-08-02 06:37:19 +0000770 bspin - "Download cluster configuration: $TYPE-cluster.cfg to $NAME-cluster.cfg $DOWNLOAD"
771 (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 -0700772 espin - $VERIFIED
773 else
774 espin - $VERIFIED
775 fi
David Bainbridge0774b232019-08-02 06:37:19 +0000776 kind create cluster --name voltha-$NAME --config $NAME-cluster.cfg
David Bainbridge491b1bd2019-07-11 17:53:11 +0000777 else
778 espin $VERIFIED
Test Userba1e7e72019-07-10 22:27:54 +0000779 fi
780
David Bainbridge0774b232019-08-02 06:37:19 +0000781 export KUBECONFIG="$(kind get kubeconfig-path --name="voltha-$NAME")"
Test Userba1e7e72019-07-10 22:27:54 +0000782 P="coredns-.* \
David Bainbridge0774b232019-08-02 06:37:19 +0000783 etcd-voltha-$NAME-control-plane \
Test Userba1e7e72019-07-10 22:27:54 +0000784 kindnet-.* \
David Bainbridge0774b232019-08-02 06:37:19 +0000785 kube-apiserver-voltha-$NAME-control-plane \
786 kube-controller-manager-voltha-$NAME-control-plane \
Test Userba1e7e72019-07-10 22:27:54 +0000787 kube-proxy-.* \
David Bainbridge0774b232019-08-02 06:37:19 +0000788 kube-scheduler-voltha-$NAME-control-plane"
Test Userba1e7e72019-07-10 22:27:54 +0000789
790 EXPECT=$(test "$TYPE" == "minimal" && echo "12" || echo "14")
David Bainbridge4f1b5562019-08-19 04:46:52 +0000791 wait_for_pods - "kube-system" $EXPECT "includes" -1 "Waiting for system PODs to start" $P
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700792fi
David Bainbridgee87067b2019-08-12 22:00:12 +0000793if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +0000794 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +0000795fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700796
David Bainbridgee87067b2019-08-12 22:00:12 +0000797STIME=$(date +%s)
David Bainbridge4c6289c2019-09-03 21:11:32 +0000798COUNT=$(count_pods "kube-system" ":Running:" "tiller-deploy-.*")
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700799bspin "Verify Helm"
Test Userba1e7e72019-07-10 22:27:54 +0000800if [ $COUNT -ne 1 ]; then
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700801 espin $NOT_VERIFIED
Test Userb5712372019-07-03 21:52:17 +0000802 echo -e "Configuring Helm $GEAR"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700803 if [ "$INSTALL_HELM" == "no" ]; then
804 bspin - "Skip Helm/Tiller Initialization"
805 espin - $NO_ENTRY
806 else
807 bspin - "Initialize Helm"
808 (set -x; helm init --upgrade >>$LOG 2>&1) >>$LOG 2>&1
809 espin - $VERIFIED
David Bainbridge4f1b5562019-08-19 04:46:52 +0000810 wait_for_pods - "kube-system" 1 "includes" -1 "Waiting for Tiller POD to start" "tiller-deploy-.*"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700811 fi
Test Userb5712372019-07-03 21:52:17 +0000812 bspin - "Add Google Incubator repository to Helm"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700813 (set -x; helm repo add incubator https://kubernetes-charts-incubator.storage.googleapis.com >>$LOG 2>&1) >>$LOG 2>&1
814 espin - $VERIFIED
Test Userba1e7e72019-07-10 22:27:54 +0000815
816 # HACK (sort-of) - the config for tiller is about to be patched, which will
817 # cause the tiller pod to be recreated. This can sometimes cause a timing
818 # issue with the "wait_for_pods" call on tiller as it may incorrectly
819 # identify the running/ready tiller pod that is soon to be terminated as
820 # what it is waiting for. To avoid this issue we do a clean scale down and
821 # scale up of the pod so the script controlls when it should be expecting
822 # things
823 (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 -0700824
Test Userb5712372019-07-03 21:52:17 +0000825 bspin - "Add Google Stable repository to Helm"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700826 (set -x; helm repo add stable https://kubernetes-charts.storage.googleapis.com >>$LOG 2>&1) >>$LOG 2>&1
827 espin - $VERIFIED
Test Userb5712372019-07-03 21:52:17 +0000828 bspin - "Add ONF repository to Helm"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700829 (set -x; helm repo add onf https://charts.opencord.org >>$LOG 2>&1) >>$LOG 2>&1
830 espin - $VERIFIED
Test Userb5712372019-07-03 21:52:17 +0000831 bspin - "Update Helm repository cache"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700832 (set -x; helm repo update >>$LOG 2>&1) >>$LOG 2>&1
833 espin - $VERIFIED
834
835 # Create and k8s service account so that Helm can create pods
Test Userb5712372019-07-03 21:52:17 +0000836 bspin - "Create Tiller ServiceAccount"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700837 (set -x; kubectl create serviceaccount --namespace kube-system tiller >>$LOG 2>&1) >>$LOG 2>&1
838 espin - $VERIFIED
Test Userb5712372019-07-03 21:52:17 +0000839 bspin - "Create Tiller ClusterRoleBinding"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700840 (set -x; kubectl create clusterrolebinding tiller-cluster-rule --clusterrole=cluster-admin --serviceaccount=kube-system:tiller >>$LOG 2>&1) >>$LOG 2>&1
841 espin - $VERIFIED
Test Userb5712372019-07-03 21:52:17 +0000842 bspin - "Update Tiller Manifest"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700843 (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 +0000844
845 # HACK (sort-of) - part to, spin it back up
846 (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 -0700847 espin - $VERIFIED
848else
849 espin $VERIFIED
850fi
David Bainbridge4f1b5562019-08-19 04:46:52 +0000851wait_for_pods - "kube-system" 1 "includes" -1 "Waiting for Tiller POD to start" "tiller-deploy-.*"
David Bainbridgee87067b2019-08-12 22:00:12 +0000852if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +0000853 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +0000854fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700855
David Bainbridgee87067b2019-08-12 22:00:12 +0000856STIME=$(date +%s)
David Bainbridge0774b232019-08-02 06:37:19 +0000857bspin "Verify Helm values file: $NAME-values.yaml"
858if [ ! -r "./$NAME-values.yaml" ]; then
Test Userba1e7e72019-07-10 22:27:54 +0000859 espin $NOT_VERIFIED
David Bainbridge0774b232019-08-02 06:37:19 +0000860 bspin - "Download Helm values file: $TYPE-values.yaml to $NAME-values.yaml $DOWNLOAD"
861 (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 +0000862 espin - $VERIFIED
863else
864 espin $VERIFIED
865fi
David Bainbridgee87067b2019-08-12 22:00:12 +0000866if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +0000867 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +0000868fi
Test Userba1e7e72019-07-10 22:27:54 +0000869
David Bainbridge99ac7a22019-08-31 02:26:43 +0000870STIME=$(date +%s)
871bspin "Verify or download chart specific values files $DOWNLOAD"
872VALUES_FILES="monkey-values.yaml"
873for i in $VALUES_FILES; do
874 if [ ! -r ./$i ]; then
875 (set -x; curl -o ./$i -sSL https://raw.githubusercontent.com/ciena/kind-voltha/master/$i >>$LOG 2>&1) >>$LOG 2>&1
876 fi
877done
878espin $VERIFIED
879if [ "$WITH_TIMINGS" == "yes" ]; then
880 printtime $(expr $(date +%s) - $STIME)
881fi
882
883if [ "$WITH_CHAOS" == "yes" ]; then
884 bspin "Verify or clone kube-monkey helm chart $DOWNLOAD"
885 if [ -r ./kube-monkey ]; then
886 espin $VERIFIED
887 else
888 espin $NOT_VERIFIED
889 bspin - "GIT clone kube-monkey"
890 (set -x; git clone https://github.com/asobti/kube-monkey kube-monkey >>$LOG 2>&1) >>$LOG 2>&1
891 espin - $VERIFIED
892 fi
893fi
894
Test Userba1e7e72019-07-10 22:27:54 +0000895if [ "$JUST_K8S" == "yes" ]; then
896 echo "Environment deployed, not deploying VOLTHA artifacts as requested. Good bye."
897 echo ""
898 echo "Please issue the following commands in your terminal to ensure that you" | tee -a $LOG
899 echo "are accessing the correct Kubernetes/Kind cluster as well as have the " | tee -a $LOG
900 echo "tools required by VOLTHA in your command path. " | tee -a $LOG
901 echo "" | tee -a $LOG
902 echo -en $BOLD
903 if [ $DEPLOY_K8S == "yes" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000904 echo "export KUBECONFIG=\"\$(./bin/kind get kubeconfig-path --name=\"voltha-$NAME\")\"" | tee -a $LOG
Test Userba1e7e72019-07-10 22:27:54 +0000905 fi
906 echo "export PATH=$GOPATH/bin:\$PATH" | tee -a $LOG
907 echo -en $NORMAL
908 echo "" | tee -a $LOG
909 echo "Thank you for choosing kind-voltha for you quick cluster needs." | tee -a $LOG
910 exit 0
911fi
912
David Bainbridgee87067b2019-08-12 22:00:12 +0000913STIME=$(date +%s)
Test Userb5712372019-07-03 21:52:17 +0000914bspin "Verify ETCD Operator $OLD_KEY"
Test User7d866122019-07-09 17:52:35 +0000915if [ $(helm list --deployed --short --namespace voltha "^etcd-operator\$" | wc -l) -ne 1 ]; then
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700916 espin $NOT_VERIFIED
David Bainbridge90fd8e32019-08-21 23:32:47 +0000917 helm_install - voltha etcd-operator stable/etcd-operator latest "Install ETCD Operator"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700918else
919 espin $VERIFIED
920fi
Test User01ed0642019-07-03 20:17:06 +0000921EXPECT=$(test "$TYPE" == "minimal" && echo "1" || echo "3")
David Bainbridge4f1b5562019-08-19 04:46:52 +0000922wait_for_pods - "voltha" $EXPECT "includes" -1 "Waiting for ETCD Operator to start" "etcd-operator-.*"
David Bainbridgee87067b2019-08-12 22:00:12 +0000923if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +0000924 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +0000925fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700926
David Bainbridgee87067b2019-08-12 22:00:12 +0000927STIME=$(date +%s)
David Bainbridgeb270c202019-07-26 01:44:42 +0000928if [ $WITH_ONOS == "yes" ]; then
929 bspin "Verify ONOS installed $BIRD"
930 if [ $(helm list --deployed --short --namespace default "^onos\$" | wc -l) -ne 1 ]; then
931 espin $NOT_VERIFIED
David Bainbridge90fd8e32019-08-21 23:32:47 +0000932 EXTRA_HELM_FLAGS="$SET_TAG $EXTRA_HELM_FLAGS" helm_install - default onos onf/onos latest "Install ONOS"
David Bainbridgeb270c202019-07-26 01:44:42 +0000933 else
934 espin $VERIFIED
935 fi
David Bainbridge4f1b5562019-08-19 04:46:52 +0000936 wait_for_pods - "default" 1 "includes" -1 "Waiting for ONOS to start" "onos-.*"
David Bainbridgeb270c202019-07-26 01:44:42 +0000937
938 bspin - "Forward ONOS API port $FORWARD"
David Bainbridge0774b232019-08-02 06:37:19 +0000939 for i in $(screen -ls | grep onos-ui-$NAME | awk '{print $1}'); do
David Bainbridge82bd1212019-07-29 19:19:31 +0000940 (set -x; screen -X -S $i quit >>$LOG 2>&1) >>$LOG 2>&1
941 done
David Bainbridge0774b232019-08-02 06:37:19 +0000942 (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 +0000943 espin - $VERIFIED
944 bspin - "Forward ONOS SSH port $FORWARD"
David Bainbridge0774b232019-08-02 06:37:19 +0000945 for i in $(screen -ls | grep onos-ssh-$NAME | awk '{print $1}'); do
David Bainbridge82bd1212019-07-29 19:19:31 +0000946 (set -x; screen -X -S $i quit >>$LOG 2>&1) >>$LOG 2>&1
947 done
David Bainbridge2b19e832019-08-16 02:40:53 +0000948
949
David Bainbridge0774b232019-08-02 06:37:19 +0000950 (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 +0000951 espin - $VERIFIED
David Bainbridged31d6122019-08-13 19:37:59 +0000952 bspin - "Verify or download ONOS configuration support files $DOWNLOAD"
David Bainbridge2b19e832019-08-16 02:40:53 +0000953 ONOS_FILES="olt-onos-enableExtraneousRules.json olt-onos-olt-settings.json onos-aaa.json \
David Bainbridge90fd8e32019-08-21 23:32:47 +0000954 onos-dhcpl2relay.json onos-kafka.json onos-sadis-sample.json"
David Bainbridged31d6122019-08-13 19:37:59 +0000955 (set -x; mkdir -p ./onos-files >>$LOG 2>&1) >>$LOG 2>&1
David Bainbridge2b19e832019-08-16 02:40:53 +0000956 for i in $ONOS_FILES; do
David Bainbridged31d6122019-08-13 19:37:59 +0000957 if [ ! -r ./onos-files/$i ]; then
958 (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
959 fi
960 done
Test Userba1e7e72019-07-10 22:27:54 +0000961 espin - $VERIFIED
David Bainbridge27790d62019-08-13 22:43:19 +0000962
963 if [ $INSTALL_ONOS_APPS == "yes" ]; then
964 bspin - "Installing custom ONOS applications"
965 if [ -x onos-files/onos-apps -a $(ls -1 onos-files/onos-apps/*.oar 2>/dev/null | wc -l) -gt 0 ]; then
966 for OAR in $(ls -1 onos-files/onos-apps/*.oar); do
967 sspin - "Installing custom ONOS applications - $OAR$CEOL"
David Bainbridge2b19e832019-08-16 02:40:53 +0000968 override_onos_app $OAR
David Bainbridge27790d62019-08-13 22:43:19 +0000969 done
970 espin - "$VERIFIED Installing custom ONOS applications$CEOL"
971 else
972 espin - "$NOT_VERIFIED Installing custom ONOS applications - None Found"
973 fi
974 fi
David Bainbridge2b19e832019-08-16 02:40:53 +0000975
976 push_onos_config "Push ONOS Kafka Configuration" "network/configuration/apps/org.opencord.kafka" "onos-files/onos-kafka.json"
977 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 +0000978 push_onos_config "Enable VOLTHA ONOS DHCP provisioning" "configuration/org.opencord.olt.impl.Olt" "onos-files/olt-onos-olt-settings.json"
979 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 +0000980 if [ -f onos-files/onos-sadis.json ]; then
981 push_onos_config "[optional] Push ONOS SADIS Configuration" "network/configuration/apps/org.opencord.sadis" "onos-files/onos-sadis.json"
982 elif [ "$CONFIG_SADIS" == "yes" ]; then
David Bainbridge90fd8e32019-08-21 23:32:47 +0000983 SADIS_CFG=onos-files/onos-sadis-sample.json
David Bainbridge2b19e832019-08-16 02:40:53 +0000984 push_onos_config "[optional] Push ONOS SADIS Configuration" "network/configuration/apps/org.opencord.sadis" "$SADIS_CFG"
985 fi
Test Userba1e7e72019-07-10 22:27:54 +0000986fi
David Bainbridgee87067b2019-08-12 22:00:12 +0000987if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +0000988 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +0000989fi
Test Userba1e7e72019-07-10 22:27:54 +0000990
David Bainbridgee87067b2019-08-12 22:00:12 +0000991STIME=$(date +%s)
Test Userb5712372019-07-03 21:52:17 +0000992bspin "Verify VOLTHA installed $HIGH_VOLTAGE"
Test User7d866122019-07-09 17:52:35 +0000993if [ $(helm list --deployed --short --namespace voltha "^voltha\$" | wc -l) -ne 1 ]; then
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700994 espin $NOT_VERIFIED
David Bainbridge90fd8e32019-08-21 23:32:47 +0000995 helm_install - voltha voltha $VOLTHA_CHART $VOLTHA_CHART_VERSION "Install VOLTHA Core"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700996else
997 espin $VERIFIED
998fi
Test Userba1e7e72019-07-10 22:27:54 +0000999
David Bainbridge90fd8e32019-08-21 23:32:47 +00001000VOLTHA="voltha-ofagent-.* \
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001001 ro-core.* \
1002 rw-core.* \
1003 voltha-api-server-.* \
1004 voltha-cli-server-.* \
1005 voltha-etcd-cluster-.* \
1006 voltha-kafka-.* \
1007 voltha-zookeeper-.*"
Test User01ed0642019-07-03 20:17:06 +00001008EXPECT=$(test "$TYPE" == "minimal" && echo "9" || echo "11")
David Bainbridge4f1b5562019-08-19 04:46:52 +00001009wait_for_pods - "voltha" $EXPECT "includes" -1 "Waiting for VOLTHA Core to start" $VOLTHA
David Bainbridgee87067b2019-08-12 22:00:12 +00001010if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +00001011 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +00001012fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001013
David Bainbridgee87067b2019-08-12 22:00:12 +00001014STIME=$(date +%s)
Test Userb5712372019-07-03 21:52:17 +00001015echo -e "Verify Adapters $PLUG"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001016bspin - "Verify Simulated Adapters installed"
Test User7d866122019-07-09 17:52:35 +00001017if [ $(helm list --deployed --short --namespace voltha "^sim\$" | wc -l) -ne 1 ]; then
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001018 espin - $NOT_VERIFIED
David Bainbridge90fd8e32019-08-21 23:32:47 +00001019 helm_install - voltha sim $VOLTHA_ADAPTER_SIM_CHART $VOLTHA_ADAPTER_SIM_CHART_VERSION "Install Simulated Adapters"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001020else
1021 espin - $VERIFIED
1022fi
1023
1024bspin - "Verify OpenOLT Adapter installed"
Test User7d866122019-07-09 17:52:35 +00001025if [ $(helm list --deployed --short --namespace voltha "^open-olt\$" | wc -l) -ne 1 ]; then
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001026 espin - $NOT_VERIFIED
David Bainbridge90fd8e32019-08-21 23:32:47 +00001027 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 -07001028else
1029 espin - $VERIFIED
1030fi
1031bspin - "Verify OpenONU Adapter installed"
Test User7d866122019-07-09 17:52:35 +00001032if [ $(helm list --deployed --short --namespace voltha "^open-onu\$" | wc -l) -ne 1 ]; then
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001033 espin - $NOT_VERIFIED
David Bainbridge90fd8e32019-08-21 23:32:47 +00001034 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 -07001035else
1036 espin - $VERIFIED
1037fi
1038
1039ADAPTERS="adapter-.*"
David Bainbridge4f1b5562019-08-19 04:46:52 +00001040wait_for_pods - "voltha" 4 "includes" -1 "Waiting for adapters to start" $ADAPTERS
David Bainbridgee87067b2019-08-12 22:00:12 +00001041if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +00001042 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +00001043fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001044
Test User7d866122019-07-09 17:52:35 +00001045if [ $WITH_BBSIM == "yes" ]; then
David Bainbridgee87067b2019-08-12 22:00:12 +00001046 STIME=$(date +%s)
Test User7d866122019-07-09 17:52:35 +00001047 echo -e "Verify BBSIM $PLUG"
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001048 bspin - "Verify BBSIM Installed"
Test User7d866122019-07-09 17:52:35 +00001049 if [ $(helm list --deployed --short --namespace voltha "^bbsim\$" | wc -l) -ne 1 ]; then
1050 espin - $NOT_VERIFIED
David Bainbridge90fd8e32019-08-21 23:32:47 +00001051 helm_install - voltha bbsim $VOLTHA_BBSIM_CHART $VOLTHA_BBSIM_CHART_VERSION "Install BBSIM"
Test User7d866122019-07-09 17:52:35 +00001052 else
1053 espin - $VERIFIED
1054 fi
David Bainbridge4f1b5562019-08-19 04:46:52 +00001055 wait_for_pods - "voltha" 1 "includes" -1 "Waiting for BBSIM to start" "bbsim-.*"
David Bainbridgee87067b2019-08-12 22:00:12 +00001056 if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +00001057 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +00001058 fi
Test User7d866122019-07-09 17:52:35 +00001059fi
1060
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001061if [ $WITH_RADIUS == "yes" ]; then
David Bainbridgee87067b2019-08-12 22:00:12 +00001062 STIME=$(date +%s)
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001063 echo -e "Verify RADIUS $LOCK"
1064 bspin - "Verify RADIUS Installed"
1065 if [ $(helm list --deployed --short --namespace voltha "^radius\$" | wc -l) -ne 1 ]; then
1066 espin - $NOT_VERIFIED
David Bainbridge90fd8e32019-08-21 23:32:47 +00001067 helm_install - voltha radius onf/freeradius latest "Install RADIUS"
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001068 else
1069 espin - $VERIFIED
1070 fi
David Bainbridge4f1b5562019-08-19 04:46:52 +00001071 wait_for_pods - "voltha" 1 "includes" -1 "Waiting for RADIUS to start" "radius-.*"
David Bainbridgee87067b2019-08-12 22:00:12 +00001072 if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +00001073 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +00001074 fi
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001075fi
1076
David Bainbridgee87067b2019-08-12 22:00:12 +00001077STIME=$(date +%s)
David Bainbridgee10f6d52019-07-25 00:28:13 +00001078if [ $SKIP_RESTART_API == "no" ]; then
1079 echo -e "Restart VOLTHA API $RESTART"
David Bainbridge90fd8e32019-08-21 23:32:47 +00001080 API="voltha-api-server-.* voltha-ofagent-.*"
1081 (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 +00001082 wait_for_pods - "voltha" 0 "includes" -1 "Wait for API to stop $STOP" $API
David Bainbridge90fd8e32019-08-21 23:32:47 +00001083 (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 +00001084 wait_for_pods - "voltha" 2 "includes" -1 "Wait for API to re-start $GO" $API
David Bainbridgee10f6d52019-07-25 00:28:13 +00001085fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001086
Test Userb5712372019-07-03 21:52:17 +00001087bspin - "Forward VOLTHA API port $FORWARD"
David Bainbridge0774b232019-08-02 06:37:19 +00001088for i in $(screen -ls | grep voltha-api-$NAME | awk '{print $1}'); do
David Bainbridge82bd1212019-07-29 19:19:31 +00001089 (set -x; screen -X -S $i quit >>$LOG 2>&1) >>$LOG 2>&1
1090done
David Bainbridge0774b232019-08-02 06:37:19 +00001091(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 -07001092espin - $VERIFIED
Test Userb5712372019-07-03 21:52:17 +00001093bspin - "Forward VOLTHA SSH port $FORWARD"
David Bainbridge0774b232019-08-02 06:37:19 +00001094for i in $(screen -ls | grep voltha-ssh-$NAME | awk '{print $1}'); do
David Bainbridge82bd1212019-07-29 19:19:31 +00001095 (set -x; screen -X -S $i quit >>$LOG 2>&1) >>$LOG 2>&1
1096done
David Bainbridge0774b232019-08-02 06:37:19 +00001097(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 -07001098espin - $VERIFIED
David Bainbridgeac7f8072019-08-01 22:15:33 +00001099bspin - "Forward VOLTHA ETCD port $FORWARD"
David Bainbridge0774b232019-08-02 06:37:19 +00001100for i in $(screen -ls | grep voltha-etcd-$NAME | awk '{print $1}'); do
David Bainbridgeac7f8072019-08-01 22:15:33 +00001101 (set -x; screen -X -S $i quit >>$LOG 2>&1) >>$LOG 2>&1
1102done
David Bainbridge0774b232019-08-02 06:37:19 +00001103(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 +00001104espin - $VERIFIED
David Bainbridgee87067b2019-08-12 22:00:12 +00001105if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +00001106 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +00001107fi
Test User3d7ad8e2019-07-03 06:15:44 +00001108
David Bainbridgeb270c202019-07-26 01:44:42 +00001109if [ $WITH_ONOS == "yes" -a $WITH_RADIUS == "yes" ]; then
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001110 bspin "Configure ONOS RADIUS Connection $GEAR"
David Bainbridge2b19e832019-08-16 02:40:53 +00001111 (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 +00001112 espin $VERIFIED
1113fi
1114
David Bainbridge99ac7a22019-08-31 02:26:43 +00001115if [ "$WITH_CHAOS" == "yes" ]; then
1116 STIME=$(date +%s)
1117 echo -e "Verify kube-monkey $LOCK"
1118 bspin - "Verify kube-monkey Installed"
1119 if [ $(helm list --deployed --short --namespace kube-monkey "^monkey\$" | wc -l) -ne 1 ]; then
1120 espin - $NOT_VERIFIED
1121 helm_install - kube-monkey monkey ./kube-monkey/helm/kubemonkey latest "Install Chaos Monkey"
1122 else
1123 espin - $VERIFIED
1124 fi
1125 wait_for_pods - "kube-monkey" 1 "includes" -1 "Waiting for Chaos to start" "monkey-.*"
1126 if [ "$WITH_TIMINGS" == "yes" ]; then
1127 printtime $(expr $(date +%s) - $STIME)
1128 fi
1129fi
1130
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001131bspin "Create voltctl configuration file"
Test User3d7ad8e2019-07-03 06:15:44 +00001132(set -x; mkdir -p $HOME/.volt >>$LOG 2>&1) >>$LOG 2>&1
David Bainbridge0774b232019-08-02 06:37:19 +00001133(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 +00001134espin $VERIFIED
Test User08ebbd92019-07-03 17:15:39 +00001135
David Bainbridge0774b232019-08-02 06:37:19 +00001136if [ ! -f "$NAME-env.sh" ]; then
1137 touch $NAME-env.sh
David Bainbridgeb07fdf72019-07-29 22:51:40 +00001138fi
1139
David Bainbridge596f30d2019-07-30 17:07:59 +00001140for O in $ALL_OPTIONS; do
1141 VAL=$(eval echo \$$O)
David Bainbridge0774b232019-08-02 06:37:19 +00001142 if [ ! -z "$VAL" -a $(grep -c "^export $O=" $NAME-env.sh) -eq 0 ]; then
1143 echo "export $O=\"$(eval echo \$$O)\"" >> $NAME-env.sh
David Bainbridgeb07fdf72019-07-29 22:51:40 +00001144 fi
1145done
1146
David Bainbridge0774b232019-08-02 06:37:19 +00001147if [ $DEPLOY_K8S == "yes" -a $(grep -c "^export KUBECONFIG=" $NAME-env.sh) -eq 0 ]; then
1148 echo "export KUBECONFIG=\"$(./bin/kind get kubeconfig-path --name=voltha-$NAME)\"" >> $NAME-env.sh
David Bainbridgeb07fdf72019-07-29 22:51:40 +00001149fi
1150
David Bainbridge0774b232019-08-02 06:37:19 +00001151if [ $(grep -c "^export VOLTCONFIG=" $NAME-env.sh) -eq 0 ]; then
1152 echo "export VOLTCONFIG=\"$HOME/.volt/config-$NAME\"" >> $NAME-env.sh
David Bainbridgeb07fdf72019-07-29 22:51:40 +00001153fi
1154
David Bainbridge0774b232019-08-02 06:37:19 +00001155if [ $(grep -c "^export PATH=" $NAME-env.sh) -eq 0 ]; then
1156 echo "export PATH=\"$GOPATH/bin:\$PATH\"" >> $NAME-env.sh
David Bainbridgeb07fdf72019-07-29 22:51:40 +00001157fi
1158
Test User7d866122019-07-09 17:52:35 +00001159echo ""
Test User08ebbd92019-07-03 17:15:39 +00001160echo "Please issue the following commands in your terminal to ensure that you" | tee -a $LOG
1161echo "are accessing the correct Kubernetes/Kind cluster as well as have the " | tee -a $LOG
1162echo "tools required by VOLTHA in your command path. " | tee -a $LOG
1163echo "" | tee -a $LOG
Test User7d866122019-07-09 17:52:35 +00001164echo -en $BOLD
Test Userba1e7e72019-07-10 22:27:54 +00001165if [ $DEPLOY_K8S == "yes" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +00001166 echo "export KUBECONFIG=\"\$(./bin/kind get kubeconfig-path --name=\"voltha-$NAME\")\"" | tee -a $LOG
Test Userba1e7e72019-07-10 22:27:54 +00001167fi
David Bainbridge0774b232019-08-02 06:37:19 +00001168echo "export VOLTCONFIG=\"$HOME/.volt/config-$NAME\"" | tee -a $LOG
Test Userba1e7e72019-07-10 22:27:54 +00001169echo "export PATH=$GOPATH/bin:\$PATH" | tee -a $LOG
Test User7d866122019-07-09 17:52:35 +00001170echo -en $NORMAL
Test User08ebbd92019-07-03 17:15:39 +00001171echo "" | tee -a $LOG
1172echo "Thank you for choosing kind-voltha for you quick cluster needs." | tee -a $LOG
1173
David Bainbridge712afb82019-08-14 19:55:58 +00001174if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridgef858a022019-08-14 21:25:11 +00001175 echo -e "$CLOCK ${BOLD}TOTAL: $(duration $(expr $(date +%s) - $TOTAL_START_TIME))${NORMAL}"
David Bainbridge712afb82019-08-14 19:55:58 +00001176fi
1177