blob: 68fdab853f7476145eb08ec5af100ef3361d4a8e [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 Bainbridge46505fb2019-10-01 21:13:20 +000075WITH_ADAPTERS=${WITH_ADAPTERS:-yes}
76WITH_SIM_ADAPTERS=${WITH_SIM_ADAPTERS:-yes}
77WITH_OPEN_ADAPTERS=${WITH_OPEN_ADAPTERS:-yes}
David Bainbridge2b19e832019-08-16 02:40:53 +000078CONFIG_SADIS=${CONFIG_SADIS:-no}
David Bainbridge27790d62019-08-13 22:43:19 +000079INSTALL_ONOS_APPS=${INSTALL_ONOS_APPS:-no}
Test Userba1e7e72019-07-10 22:27:54 +000080JUST_K8S=${JUST_K8S:-no}
81DEPLOY_K8S=${DEPLOY_K8S:-yes}
David Bainbridgea3b56322019-09-03 20:40:42 +000082SKIP_RESTART_API=${SKIP_RESTART_API:-yes}
David K. Bainbridge0e89cb92019-07-17 11:30:10 -070083INSTALL_KUBECTL=${INSTALL_KUBECTL:-yes}
84INSTALL_HELM=${INSTALL_HELM:-yes}
David Bainbridge46505fb2019-10-01 21:13:20 +000085UPDATE_HELM_REPOS=${UPDATE_HELM_REPOS:-yes}
David Bainbridge4f1b5562019-08-19 04:46:52 +000086WAIT_ON_DOWN=${WAIT_ON_DOWN:-no}
David Bainbridge5b7b96b2019-07-25 20:29:13 +000087VOLTHA_LOG_LEVEL=${VOLTHA_LOG_LEVEL:-WARN}
David Bainbridge90fd8e32019-08-21 23:32:47 +000088VOLTHA_CHART=${VOLTHA_CHART:-onf/voltha}
89VOLTHA_CHART_VERSION=${VOLTHA_CHART_VERSION:-latest}
90VOLTHA_BBSIM_CHART=${VOLTHA_BBSIM_CHART:-onf/bbsim}
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -070091VOLTHA_BBSIM_CHART_VERSION=${VOLTHA_BBSIM_CHART_VERSION:-2.1.1}
David Bainbridgee10f6d52019-07-25 00:28:13 +000092VOLTHA_ADAPTER_SIM_CHART=${VOLTHA_ADAPTER_SIM_CHART:-onf/voltha-adapter-simulated}
David Bainbridge90fd8e32019-08-21 23:32:47 +000093VOLTHA_ADAPTER_SIM_CHART_VERSION=${VOLTHA_ADAPTER_SIM_CHART_VERSION:-latest}
David Bainbridgee10f6d52019-07-25 00:28:13 +000094VOLTHA_ADAPTER_OPEN_OLT_CHART=${VOLTHA_ADAPTER_OPEN_OLT_CHART:-onf/voltha-adapter-openolt}
David Bainbridge90fd8e32019-08-21 23:32:47 +000095VOLTHA_ADAPTER_OPEN_OLT_CHART_VERSION=${VOLTHA_ADAPTER_OPEN_OLT_CHART_VERSION:-latest}
David Bainbridgee10f6d52019-07-25 00:28:13 +000096VOLTHA_ADAPTER_OPEN_ONU_CHART=${VOLTHA_ADAPTER_OPEN_ONU_CHART:-onf/voltha-adapter-openonu}
David Bainbridge90fd8e32019-08-21 23:32:47 +000097VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION=${VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION:-latest}
98
Test Userba1e7e72019-07-10 22:27:54 +000099
100HAVE_GO=$(which go >/dev/null 2>&1 && echo "yes" || echo "no")
101HOSTOS=$(uname -s | tr "[:upper:]" "[:lower:"])
102HOSTARCH=$(uname -m | tr "[:upper:]" "[:lower:"])
103if [ $HOSTARCH == "x86_64" ]; then
104 HOSTARCH="amd64"
105fi
Test User7d866122019-07-09 17:52:35 +0000106
107# Verify TYPE setting
108if [ $(echo ":minimal:full:" | grep -ic ":$TYPE:") -eq 0 ]; then
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700109 >&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 +0000110 exit 1
111fi
112
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000113# Used to verify configuration values are set to "yes" or "no" value or convert
114# equivalents to "yes" or "no"
115function verify_yes_no() {
116 local VAR=$1
117 local VAL=$(eval echo \$$VAR)
118 if [ $(echo ":y:yes:true:n:no:false:1:0:" | grep -ic ":$VAL:") -eq 0 ]; then
119 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} Invalid '$VAR' value of '$VAL'. Should be 'yes' or 'no'${NORMAL}"
120 echo "INVALID"
121 return 1
122 fi
123 if [ $(echo ":y:yes:true:1:" | grep -ic ":$VAL:") -eq 1 ]; then
124 echo "yes"
125 else
126 echo "no"
127 fi
128 return 0
129}
Test User7d866122019-07-09 17:52:35 +0000130
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000131ALL_YES_NO="\
132 WITH_TIMINGS \
133 WITH_BBSIM \
134 WITH_RADIUS \
135 WITH_ONOS \
David Bainbridge99ac7a22019-08-31 02:26:43 +0000136 WITH_CHAOS \
David Bainbridge46505fb2019-10-01 21:13:20 +0000137 WITH_ADAPTERS \
138 WITH_SIM_ADAPTERS \
139 WITH_OPEN_ADAPTERS \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000140 CONFIG_SADIS \
141 JUST_K8S \
142 DEPLOY_K8S \
143 INSTALL_ONOS_APPS \
144 SKIP_RESTART_API \
145 INSTALL_KUBECTL \
146 INSTALL_HELM \
David Bainbridge46505fb2019-10-01 21:13:20 +0000147 UPDATE_HELM_REPOS \
David Bainbridge4f1b5562019-08-19 04:46:52 +0000148 WAIT_ON_DOWN \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000149 "
David Bainbridge5b7b96b2019-07-25 20:29:13 +0000150
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000151ALL_OPTIONS="\
152 NAME \
153 TYPE \
154 $ALL_YES_NO \
155 VOLTHA_LOG_LEVEL \
156 VOLTHA_CHART \
David Bainbridge90fd8e32019-08-21 23:32:47 +0000157 VOLTHA_CHART_VERSION \
158 VOLTHA_BBSIM_CHART \
159 VOLTHA_BBSIM_CHART_VERSION \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000160 VOLTHA_ADAPTER_SIM_CHART \
David Bainbridge90fd8e32019-08-21 23:32:47 +0000161 VOLTHA_ADAPTER_SIM_CHART_VERSION \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000162 VOLTHA_ADAPTER_OPEN_OLT_CHART \
David Bainbridge90fd8e32019-08-21 23:32:47 +0000163 VOLTHA_ADAPTER_OPEN_OLT_CHART_VERSION \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000164 VOLTHA_ADAPTER_OPEN_ONU_CHART \
David Bainbridge90fd8e32019-08-21 23:32:47 +0000165 VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000166 ONOS_API_PORT \
167 ONOS_SSH_PORT \
168 VOLTHA_API_PORT \
169 VOLTHA_SSH_PORT \
170 VOLTHA_ETCD_PORT \
171 "
David Bainbridge01294952019-07-30 19:33:45 +0000172
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000173# Iterate over yes/no configuration options and validate
174for VAR in $ALL_YES_NO; do
175 eval $VAR=$(verify_yes_no $VAR)
176 if [ "$(eval echo \$$VAR)" == "INVALID" ]; then
177 exit 1;
178 fi
179done
David Bainbridgeb270c202019-07-26 01:44:42 +0000180
David Bainbridge0774b232019-08-02 06:37:19 +0000181mkdir -p .voltha
182touch .voltha/ports
183HAVE=$(grep $NAME .voltha/ports)
184if [ "$HAVE X" == " X" ]; then
185 # Find free port prefix
186 START=81
187 while true; do
188 if [ $(grep -c $START .voltha/ports) -eq 0 ]; then
189 break
190 fi
191 START=$(expr $START + 1)
192 done
193 DELTA=$(expr $START - 81)
194 ONOS_API_PORT=${START}81
195 ONOS_SSH_PORT=${START}01
196 VOLTHA_API_PORT=5$(expr 55 + $DELTA)55
197 VOLTHA_SSH_PORT=$(expr 50 + $DELTA)22
198 VOLTHA_ETCD_PORT=$(expr 23 + $DELTA)79
Test User01ed0642019-07-03 20:17:06 +0000199else
David Bainbridge0774b232019-08-02 06:37:19 +0000200 VALUES=$(echo $HAVE | sed -e 's/\s//g' | cut -d= -f2)
201 ONOS_API_PORT=$(echo $VALUES | cut -d, -f1)
202 ONOS_SSH_PORT=$(echo $VALUES | cut -d, -f2)
203 VOLTHA_API_PORT=$(echo $VALUES | cut -d, -f3)
204 VOLTHA_SSH_PORT=$(echo $VALUES | cut -d, -f4)
205 VOLTHA_ETCD_PORT=$(echo $VALUES | cut -d, -f5)
Test User01ed0642019-07-03 20:17:06 +0000206fi
207
David Bainbridge0774b232019-08-02 06:37:19 +0000208PORTTMP=$(mktemp -u)
209cat .voltha/ports | grep -v $NAME > $PORTTMP
210echo "$NAME=$ONOS_API_PORT,$ONOS_SSH_PORT,$VOLTHA_API_PORT,$VOLTHA_SSH_PORT,$VOLTHA_ETCD_PORT" >> $PORTTMP
211cp $PORTTMP .voltha/ports
212rm -f $PORTTMP
213
David Bainbridge27790d62019-08-13 22:43:19 +0000214export ONOS_API_PORT ONOS_SSH_PORT
David Bainbridge01294952019-07-30 19:33:45 +0000215
Test Userd87942b2019-07-03 07:20:24 +0000216IDX=1
David Bainbridgee87067b2019-08-12 22:00:12 +0000217CLOCK="TIME:"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000218SPIN_PARTS=
219NOT_VERIFIED=
David Bainbridgef858a022019-08-14 21:25:11 +0000220THEX=
221BUILD=
222CROSS=
223ENTER=
David Bainbridge38dc1e82019-08-12 15:18:45 +0000224VERIFIED=
225HELM=
226OLD_KEY=
227BIRD=
228HIGH_VOLTAGE=
229PLUG=
230RESTART=
231FORWARD=
232INSTALL=
233STOP=
234GO=
235DOWNLOAD=
236GEAR=
237NO_ENTRY=
238LOCK=
239
240if [ $FANCY -eq 1 ]; then
241 SPIN_PARTS="\
242 \xe2\xa2\x8e\xe2\xa1\xb0 \
243 \xe2\xa2\x8e\xe2\xa1\xa1 \
244 \xe2\xa2\x8e\xe2\xa1\x91 \
245 \xe2\xa2\x8e\xe2\xa0\xb1 \
246 \xe2\xa0\x8e\xe2\xa1\xb1 \
247 \xe2\xa2\x8a\xe2\xa1\xb1 \
248 \xe2\xa2\x8c\xe2\xa1\xb1 \
249 \xe2\xa2\x86\xe2\xa1\xb1 \
250 "
David Bainbridgee87067b2019-08-12 22:00:12 +0000251 CLOCK="\xe2\x8f\xb1"
David Bainbridgef858a022019-08-14 21:25:11 +0000252 THEX="${RED}${BOLD}\xe2\x9c\x97\x20${NORMAL}"
253 ENTER="${YELLOW}${BOLD}\xe2\x8e\x86${NORMAL}"
254 CROSS="${YELLOW}${BOLD}\xe2\x9c\x9a${NORMAL}"
255 BUILD="${YELLOW}${BOLD}\xf0\x9f\x8f\x97${NORMAL}"
256 NOT_VERIFIED="$BUILD"
257 VERIFIED="${GREEN}${BOLD}\xe2\x9c\x93\x20${NORMAL}"
258 HELM="${BLUE}${BOLD}\xE2\x8E\x88${NORMAL}"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000259 OLD_KEY="\xF0\x9F\x97\x9D"
260 BIRD="\xF0\x9F\x90\xA6"
261 HIGH_VOLTAGE="\xE2\x9A\xA1"
262 PLUG="\xF0\x9F\xa7\xa9"
263 RESTART="\xf0\x9f\x94\x84"
264 FORWARD="\xE2\x87\xA8"
265 INSTALL="\xF0\x9F\x8F\x97"
266 STOP="\xf0\x9f\x9b\x91"
267 GO="\xf0\x9f\x9a\x80"
268 DOWNLOAD="\xf0\x9f\x93\xa5"
269 GEAR="\xe2\x9a\x99"
270 NO_ENTRY="\xe2\x9b\x94"
271 LOCK="\xf0\x9f\x94\x92"
272fi
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700273
David Bainbridge712afb82019-08-14 19:55:58 +0000274duration() {
David Bainbridgee87067b2019-08-12 22:00:12 +0000275 local h=$(expr $1 / 3600)
276 local m=$(expr $1 % 3600 / 60)
277 local s=$(expr $1 % 60)
278 local t=""
279
280 if [ $h -gt 0 ]; then
281 t="$t${h}h"
282 fi
283 if [ $m -gt 0 ]; then
284 t="$t${m}m"
285 fi
David Bainbridge712afb82019-08-14 19:55:58 +0000286 echo "$t${s}s"
287}
288
289printtime() {
290 local INDENT=
291 if [ "$1" == "-" ]; then
292 INDENT=" "
293 shift
294 fi
295 echo -e "$INDENT $CLOCK $(duration $1)"
David Bainbridgee87067b2019-08-12 22:00:12 +0000296}
297
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700298bspin() {
Test Userd87942b2019-07-03 07:20:24 +0000299 IDX=1
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700300 local INDENT=
301 if [ "$1" == "-" ]; then
302 INDENT=" "
303 shift
304 fi
David Bainbridge38dc1e82019-08-12 15:18:45 +0000305 if [ $FANCY -eq 0 ]; then
306 LINE=$(echo $* | sed -e 's/[\s+-]//g')
307 if [ "$LINE X" == " X" ]; then
308 return
309 fi
310 echo -e "$CIVIS$INDENT$*"
311 else
312 echo -en "$CIVIS$INDENT $*"
313 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700314}
315
316sspin() {
317 local INDENT=
318 if [ "$1" == "-" ]; then
319 INDENT=" "
320 shift
321 fi
David Bainbridge38dc1e82019-08-12 15:18:45 +0000322 if [ $FANCY -eq 0 ]; then
323 LINE=$(echo $* | sed -e 's/[\s+-]//g')
324 if [ "$LINE X" == " X" ]; then
325 return
326 fi
327 echo -e "$INDENT$*"
328 else
329 C=$(echo $SPIN_PARTS | cut '-d ' -f $IDX)
330 echo -en "\r$INDENT$C $*"
331 IDX=$(expr $IDX + 1)
332 if [ $IDX -gt 8 ]; then
333 IDX=1
334 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700335 fi
336}
337
338espin() {
339 local INDENT=
340 if [ "$1" == "-" ]; then
341 INDENT=" "
342 shift
343 fi
David Bainbridge38dc1e82019-08-12 15:18:45 +0000344 if [ $FANCY -eq 0 ]; then
345 LINE=$(echo $* | sed -e 's/[\s+-]//g')
346 if [ "$LINE X" == " X" ]; then
347 return
348 fi
349 echo -e "$INDENT$*"
350 else
351 echo -e "\r$INDENT$*$CNORM"
352 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700353}
354
David Bainbridgeac7f8072019-08-01 22:15:33 +0000355if [ "$1" == "get" -a "$2" == "voltconfig" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000356 echo "$HOME/.volt/config-$NAME"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000357 exit
358fi
359
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -0700360if [ $# -ne 1 -o $(echo ":up:down:dump:" | grep -c ":$1:") -ne 1 ]; then
David Bainbridgeac7f8072019-08-01 22:15:33 +0000361 >&2 echo "What wouild you like to do today:"
362 >&2 echo " up - bring up voltha"
363 >&2 echo " down - tear down voltha"
364 >&2 echo " dump - create a debug dump of running system"
365 exit 1
366fi
367
David Bainbridge4f1b5562019-08-19 04:46:52 +0000368push_onos_config() {
369 local MSG=$1
370 local RESOURCE=$2
371 local DATA=$3
372
373 bspin - "$MSG $GEAR"
374 while true; do
375 (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
376 if [ $? -eq 0 ]; then
377 break
378 fi
379 sleep .2
380 sspin -
381 done
382 espin - $VERIFIED
383}
384
385override_onos_app() {
386 local APP=$1
387 local NAME=$(basename $APP | sed -e 's/^[0-9][0-9]*-//g' -e 's/-.*$//g')
388 while true; do
389 sspin -
390 # Attempt to delete old version (if it exists)
391 (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
392 sspin -
393 if [ $? -ne 0 ]; then
394 continue
395 fi
396 (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
397 if [ $? -eq 0 ]; then
398 break
399 fi
400 sleep .2
401 done
402}
403
404activate_onos_app() {
405 local MSG="$1"
406 local APP=$2
407
408 bspin - "$MSG $GO"
409 while true; do
410 sspin -
411 (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
412 if [ $? -eq 0 ]; then
413 break
414 fi
415 sleep .2
416 done
417 espin - "$VERIFIED"
418}
419
420count_pods() {
421 local NAMESPACE=$1; shift
422 if [ "$NAMESPACE" == "all-namespaces" ]; then
423 NAMESPACE="--all-namespaces"
424 else
425 NAMESPACE="-n $NAMESPACE"
426 fi
427 echo "$NAMESPACE" > /tmp/t
428 local STATES=$1; shift
429 echo "$STATES" >> /tmp/t
430 local PODS=$(kubectl get $NAMESPACE pod -o go-template="{{range .items}}{{.metadata.name}}/{{.status.phase}}/_{{range .status.containerStatuses}}{{.ready}}_{{end}} {{end}}")
431 local COUNT=0
432 local PATTERNS="$*"
433 for POD in $PODS; do
434 local NAME=$(echo $POD | cut -d/ -f 1)
435 local STATE=$(echo $POD | cut -d/ -f 2)
436 local CONTAINERS=$(echo $POD | cut -d/ -f 3 | sed -e 's/_/ /g')
437 if [ "$STATES" == "*" -o $(echo "$STATES" | grep -c ":$STATE:") -ne 0 ]; then
438 echo "IN WITH $POD" >> /tmp/t
439 local TOTAL=$(echo $CONTAINERS | wc -w)
440 local FOUND=$(echo $CONTAINERS | grep -o true | wc -l)
441 if [ $TOTAL -eq $FOUND ]; then
442 for PATTERN in $PATTERNS; do
443 echo "TEST $PATTERN AGAINST $NAME" >> /tmp/t
444 if [[ $NAME =~ $PATTERN ]]; then
445 echo "COUNT $NAME" >> /tmp/t
446 COUNT=$(expr $COUNT + 1)
447 break
448 fi
449 done
450 fi
451 fi
452 done
453 echo $COUNT >> /tmp/t
454 echo $COUNT
455}
456
457wait_for_pods() {
458 local INDENT=
459 if [ "$1" == "-" ]; then
460 INDENT=$1; shift
461 fi
462 local NAMESPACE=$1; shift
463 local EXPECT=$1; shift
464 local TYPE=$1; shift
465 local RETRY=$1; shift
466 local MESSAGE=$1; shift
467 local PATTERNS=$*
David Bainbridge99ac7a22019-08-31 02:26:43 +0000468 local STATES=":Running:"
469 if [ "$TYPE" == "not" ]; then
470 STATES="*"
471 fi
472 local HAVE=$(count_pods $NAMESPACE "$STATES" $PATTERNS)
David Bainbridge4f1b5562019-08-19 04:46:52 +0000473 local ALL=$HAVE
474 if [ "$TYPE" == "only" ]; then
475 ALL=$(count_pods "all-namespaces" "*" ".*")
476 fi
477 COUNT=$(expr 300 / 15)
478 bspin $INDENT $MESSAGE
479 sspin $INDENT
480 if [ $HAVE -ne $EXPECT -o $ALL -ne $HAVE ]; then
481 while [ $HAVE -ne $EXPECT -o $ALL -ne $HAVE ]; do
482 sspin $INDENT
483 COUNT=$(expr $COUNT - 1)
484 if [ $COUNT -eq 0 ]; then
David Bainbridge99ac7a22019-08-31 02:26:43 +0000485 HAVE=$(count_pods $NAMESPACE "$STATES" $PATTERNS)
David Bainbridge4f1b5562019-08-19 04:46:52 +0000486 ALL=$HAVE
487 if [ "$TYPE" == "only" ]; then
488 ALL=$(count_pods "all-namespaces" "*" ".*")
489 fi
490 COUNT=$(expr 300 / 15)
491 fi
492 sleep .15
493 done
494 fi
495 espin $INDENT $VERIFIED
496 if [ $HAVE -ne $EXPECT ]; then
497 return 1
498 fi
499 return 0
500}
501
David Bainbridgeac7f8072019-08-01 22:15:33 +0000502if [ "$1" == "down" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000503 echo "Tearing down voltha cluster $NAME"
504 LOG="down-$NAME.log"
505 echo $(date -u +"%Y%m%dT%H%M%SZ") >$LOG
David Bainbridgeac7f8072019-08-01 22:15:33 +0000506 if [ $DEPLOY_K8S == "yes" ]; then
507 if [ -x ./bin/kind ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000508 bspin "Delete Kubernetes Kind Cluster"
509 (set -x; ./bin/kind delete cluster --name voltha-$NAME >>$LOG 2>&1) >>$LOG 2>&1
510 espin $VERIFIED
David Bainbridgeac7f8072019-08-01 22:15:33 +0000511 else
David Bainbridge0774b232019-08-02 06:37:19 +0000512 espin "$NO_ENTRY Delete Kubernetes Kind Cluster: kind command not found"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000513 fi
514 else
515 EXISTS=$(helm list -q)
516 EXPECT="etcd-operator onos open-olt open-onu sim voltha bbsim radius"
David Bainbridge0774b232019-08-02 06:37:19 +0000517 bspin "Remove Helm Deployments"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000518 for i in $EXISTS; do
519 if [ $(echo $EXPECT | grep -c $i) -eq 1 ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000520 sspin "Remove Helm Deployments: $i$CEOL"
521 (set -x; ./bin/helm delete --purge $i >>$LOG 2>&1) >>$LOG 2>&1
David Bainbridgeac7f8072019-08-01 22:15:33 +0000522 fi
523 done
David Bainbridge0774b232019-08-02 06:37:19 +0000524 espin "$VERIFIED Remove Helm Deployments$CEOL"
David Bainbridge4f1b5562019-08-19 04:46:52 +0000525 if [ "$WAIT_ON_DOWN" == "yes" ]; then
526 # There should only be 13 or 15 PODs in the kube-system name
527 # space and no other PODs
David Bainbridge4f1b5562019-08-19 04:46:52 +0000528 PODS="coredns-.* \
529 etcd-voltha-$NAME-control-plane \
530 kindnet-.* \
531 kube-apiserver-voltha-$NAME-control-plane \
532 kube-controller-manager-voltha-$NAME-control-plane \
533 kube-proxy-.* \
534 kube-scheduler-voltha-$NAME-control-plane \
535 tiller-deploy-.*"
536 EXPECT=$(test "$TYPE" == "minimal" && echo "13" || echo "15")
David Bainbridge99ac7a22019-08-31 02:26:43 +0000537 PODS="adapter-.* \
538 bbsim.* \
539 etcd-operator.* \
540 radius.* \
541 voltha-.*"
542 EXPECT=0
543
544 wait_for_pods "voltha" $EXPECT "not" -1 "Waiting for VOLTHA PODs to terminate" $PODS
David Bainbridge4f1b5562019-08-19 04:46:52 +0000545 fi
David Bainbridgeac7f8072019-08-01 22:15:33 +0000546 fi
David Bainbridge0774b232019-08-02 06:37:19 +0000547 bspin "Remove port-forwards: onos-ui-$NAME"
548 for i in $(screen -ls | grep onos-ui-$NAME | awk '{print $1}'); do
549 sspin
550 (set -x; screen -X -S $i quit >>$LOG 2>&1) >>$LOG 2>&1
551 done
552 sspin "Remove port-forwards: onos-ssh-$NAME$CEOL"
553 for i in $(screen -ls | grep onos-ssh-$NAME | awk '{print $1}'); do
554 sspin
555 (set -x; screen -X -S $i quit >>$LOG 2>&1) >>$LOG 2>&1
556 done
557 sspin "Remove port-forwards: voltha-api-$NAME$CEOL"
558 for i in $(screen -ls | grep voltha-api-$NAME | awk '{print $1}'); do
559 sspin
560 (set -x; screen -X -S $i quit >>$LOG 2>&1) >>$LOG 2>&1
561 done
562 sspin "Remove port-forwards: voltha-ssh-$NAME$CEOL"
563 for i in $(screen -ls | grep voltha-ssh-$NAME | awk '{print $1}'); do
564 sspin
565 (set -x; screen -X -S $i quit >>$LOG 2>&1) >>$LOG 2>&1
566 done
567 sspin "Remove port-forwards: voltha-etcd-$NAME$CEOL"
568 for i in $(screen -ls | grep voltha-etcd-$NAME | awk '{print $1}'); do
569 sspin
570 (set -x; screen -X -S $i quit >>$LOG 2>&1) >>$LOG 2>&1
571 done
572 espin "$VERIFIED Remove port-forwards$CEOL"
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -0700573 exit
David Bainbridgeac7f8072019-08-01 22:15:33 +0000574fi
575
576if [ "$1" == "dump" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000577 LOG="dump-$NAME.log"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000578 TS=$(date -u +"%Y%m%dT%H%M%SZ")
David Bainbridge76514a02019-10-08 01:50:35 +0000579 if [ ! -z "$DUMP_FROM" ]; then
580 TS=$(echo $DUMP_FROM | sed -e 's/[:-]//g')
581 fi
David Bainbridgeac7f8072019-08-01 22:15:33 +0000582 WORK=$(mktemp -u -d)
David Bainbridge0774b232019-08-02 06:37:19 +0000583 DATA=$WORK/voltha-debug-dump-$NAME-$TS
David Bainbridgeac7f8072019-08-01 22:15:33 +0000584 mkdir -p $DATA
585 echo $TS > $LOG
David Bainbridge0774b232019-08-02 06:37:19 +0000586 echo -e "Capturing debug dump to voltha-debug-dump-$NAME-$TS.tgz"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000587 bspin - "Copy install log"
David Bainbridge0774b232019-08-02 06:37:19 +0000588 if [ -f install-$NAME.log ]; then
589 (set -x; cp install-$NAME.log $DATA/install-$NAME.log) >>$LOG 2>&1
David Bainbridgeac7f8072019-08-01 22:15:33 +0000590 espin - $VERIFIED
591 else
David Bainbridge0774b232019-08-02 06:37:19 +0000592 espin - "$NO_ENTRY Copy install log: install-$NAME.log not found"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000593 fi
594 bspin - "Dumping Kubernetes PODs"
595 (set -x; kubectl get --all-namespaces pods >> $DATA/all-pods.txt 2>&1) >>$LOG 2>&1
596 espin - $VERIFIED
597 bspin - "Dumping Kubernetes SERVICEs"
598 (set -x; kubectl get --all-namespaces svc >> $DATA/all-services.txt 2>&1) >>$LOG 2>&1
599 espin - $VERIFIED
600 bspin - "Dumping Kubernetes EVENTs"
601 (set -x; kubectl get --all-namespaces events >> $DATA/all-events.txt 2>&1) >>$LOG 2>&1
602 espin - $VERIFIED
603 bspin - "Dumping VOLTHA POD details"
David Bainbridge1f0655a2019-10-01 22:08:48 +0000604 PODS="$(kubectl -n default get pod -o name | grep onos | sed -e 's/^/default:/g') $(kubectl get -n voltha pod -o name | sed -e 's/^/voltha:/g')"
David Bainbridgecfd7ca12019-10-06 03:31:41 +0000605 SINCE=
606 if [ ! -z "$DUMP_FROM" ]; then
607 SINCE="--since-time=$DUMP_FROM"
608 fi
David Bainbridgeac7f8072019-08-01 22:15:33 +0000609 for POD in $PODS; do
David Bainbridge1f0655a2019-10-01 22:08:48 +0000610 NS=$(echo $POD | cut -d: -f1)
611 POD=$(echo $POD | cut -d: -f2)
David Bainbridgeac7f8072019-08-01 22:15:33 +0000612 sspin - "Dumping VOLTHA POD details: $POD$CEOL"
613 mkdir -p $DATA/$POD
David Bainbridge1f0655a2019-10-01 22:08:48 +0000614 (set -x; kubectl describe -n $NS $POD >> $DATA/$POD/describe.txt 2>&1) >>$LOG 2>&1
David Bainbridgeac7f8072019-08-01 22:15:33 +0000615 sspin - "Dumping VOLTHA POD details: $POD"
David Bainbridgecfd7ca12019-10-06 03:31:41 +0000616 (set -x; kubectl logs -n $NS --all-containers $SINCE --previous $LOG_ARGS $POD >> $DATA/$POD/logs-previous.txt 2>&1) >>$LOG 2>&1
David Bainbridgeac7f8072019-08-01 22:15:33 +0000617 sspin - "Dumping VOLTHA POD details: $POD"
David Bainbridgecfd7ca12019-10-06 03:31:41 +0000618 (set -x; kubectl logs -n $NS --all-containers $SINCE $LOG_ARGS $POD >> $DATA/$POD/logs-current.txt 2>&1) >>$LOG 2>&1
David Bainbridgeac7f8072019-08-01 22:15:33 +0000619 sspin - "Dumping VOLTHA POD details: $POD"
620 done
621 espin - "$VERIFIED Dumping VOLTHA POD details$CEOL"
622 bspin - "Dumping ETCD"
623 if [ "$(which etcdctl) X" != " X" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000624 (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 +0000625 espin - $VERIFIED
626 else
627 espin - "$NO_ENTRY Dumping ETCD: etcdctl command not available"
628 fi
David Bainbridge0774b232019-08-02 06:37:19 +0000629 bspin - "Creating compressed TAR: voltha-debug-dump-$NAME-$TS.tgz"
630 (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 +0000631 espin - $VERIFIED
632 bspin - "Cleanup"
633 (set -x; rm -rf $WORK) >>$LOG 2>&1
634 espin - $VERIFIED
David Bainbridge0774b232019-08-02 06:37:19 +0000635 bspin - "$(ls -l voltha-debug-dump-$NAME-$TS.tgz)"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000636 espin - $VERIFIED
637 exit
638fi
639
David Bainbridge0774b232019-08-02 06:37:19 +0000640LOG="install-$NAME.log"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000641date > $LOG
David Bainbridge0774b232019-08-02 06:37:19 +0000642echo "PORTS=$ONOS_API_PORT,$ONOS_SSH_PORT,$VOLTHA_API_PORT,$VOLTHA_SSH_PORT,$VOLTHA_ETCD_PORT" >> $LOG
David Bainbridgeac7f8072019-08-01 22:15:33 +0000643
644# Output install options to log
645echo "OPTIONS" >> $LOG
David Bainbridgeac7f8072019-08-01 22:15:33 +0000646for O in $ALL_OPTIONS; do
647 VAL=$(eval echo \$$O)
David Bainbridgeac7f8072019-08-01 22:15:33 +0000648 if [ ! -z "$VAL" ]; then
649 printf " %-30s = %s\n" $O $VAL >> $LOG
650 fi
651done
652
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -0700653helm_install() {
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700654 local INDENT=
655 if [ "$1" == "-" ]; then
656 INDENT=$1; shift
657 fi
658 local NAMESPACE=$1; shift
David Bainbridge0774b232019-08-02 06:37:19 +0000659 local INAME=$1; shift
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700660 local CHART=$1; shift
David Bainbridge90fd8e32019-08-21 23:32:47 +0000661 local CHART_VERSION=$1; shift
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700662 local MESSAGE=$*
663
David Bainbridge90fd8e32019-08-21 23:32:47 +0000664 if [ "$CHART_VERSION X" != " X" -a "$CHART_VERSION" != "latest" ]; then
665 CHART_VERSION="--version $CHART_VERSION"
666 else
667 CHART_VERSION=
668 fi
669
David Bainbridge99ac7a22019-08-31 02:26:43 +0000670 local CHART_ARGS=
671 if [ -r "${INAME}-values.yaml" ]; then
672 CHART_ARGS="-f ${INAME}-values.yaml"
673 fi
674
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700675 COUNT=$(expr 300 / 15)
676 bspin $INDENT $MESSAGE
David Bainbridge99ac7a22019-08-31 02:26:43 +0000677 (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 -0700678 SUCCESS=$?
679 while [ $SUCCESS -ne 0 ]; do
680 sspin $INDENT
681 COUNT=$(expr $COUNT - 1)
682 if [ $COUNT -eq 0 ]; then
David Bainbridge99ac7a22019-08-31 02:26:43 +0000683 (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 -0700684 COUNT=$(expr 300 / 15)
685 fi
686 sleep .15
687 done
688 espin $INDENT $VERIFIED
689}
690
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700691echo "INSTALL TYPE: $TYPE" >> $LOG
692
693bspin "Verify GOPATH"
694export GOPATH=$(pwd)
Test User3d7ad8e2019-07-03 06:15:44 +0000695mkdir -p $GOPATH/bin
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700696espin $VERIFIED
697
David Bainbridgee87067b2019-08-12 22:00:12 +0000698STIME=$(date +%s)
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700699if [ "$INSTALL_KUBECTL" == "no" ]; then
700 bspin "Skip kubectl install"
701 espin $NO_ENTRY
Test Userc13bdc92019-07-03 20:57:49 +0000702else
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700703 bspin "Verify kubectl $HELM"
704 if [ -x $GOPATH/bin/kubectl ]; then
705 espin $VERIFIED
706 else
707 espin $NOT_VERIFIED
708 bspin - "Download and install Kubernetes/kubectl $DOWNLOAD"
709 (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
710 (set -x; chmod 755 $GOPATH/bin/kubectl >>$LOG 2>&1) >>$LOG 2>&1
711 espin - $VERIFIED
712 fi
Test Userc13bdc92019-07-03 20:57:49 +0000713fi
David Bainbridgee87067b2019-08-12 22:00:12 +0000714if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +0000715 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +0000716fi
Test Userc13bdc92019-07-03 20:57:49 +0000717
David Bainbridgee87067b2019-08-12 22:00:12 +0000718STIME=$(date +%s)
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700719if [ "$DEPLOY_K8S" == "no" ]; then
720 bspin "Skip Kubernetes/Kind Deployment"
721 espin $NO_ENTRY
722else
Test Userba1e7e72019-07-10 22:27:54 +0000723 bspin "Verify Kubernetes/Kind $HELM"
724 if [ -x $GOPATH/bin/kind ]; then
725 espin $VERIFIED
726 else
727 espin $NOT_VERIFIED
728 bspin - "Download and install Kubernetes/kind $DOWNLOAD"
David Bainbridge9e2a6662019-07-11 17:07:57 +0000729 (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 +0000730 (set -x; chmod 755 $GOPATH/bin/kind >>$LOG 2>&1) >>$LOG 2>&1
731 espin - $VERIFIED
732 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700733fi
734
David Bainbridgee87067b2019-08-12 22:00:12 +0000735if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +0000736 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +0000737fi
738
739STIME=$(date +%s)
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700740if [ "$INSTALL_HELM" == "no" ]; then
741 bspin "Skip Helm Install"
742 espin $NO_ENTRY
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700743else
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700744 bspin "Verify Helm $HELM"
745 if [ -x $GOPATH/bin/helm ]; then
746 espin $VERIFIED
747 else
748 espin $NOT_VERIFIED
749 bspin - "Download and install Helm $DOWNLOAD"
750 (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
751 espin - $VERIFIED
752 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700753fi
David Bainbridgee87067b2019-08-12 22:00:12 +0000754if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +0000755 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +0000756fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700757
David Bainbridgee87067b2019-08-12 22:00:12 +0000758STIME=$(date +%s)
Test Userb5712372019-07-03 21:52:17 +0000759bspin "Verify voltctl $HIGH_VOLTAGE"
Test User3d7ad8e2019-07-03 06:15:44 +0000760if [ -x $GOPATH/bin/voltctl ]; then
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700761 espin $VERIFIED
762else
763 espin $NOT_VERIFIED
David Bainbridge99ac7a22019-08-31 02:26:43 +0000764 bspin - "Download and install voltctl $DOWNLOAD"
Test Userba1e7e72019-07-10 22:27:54 +0000765 (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 +0000766 (set -x; chmod 755 $GOPATH/bin/voltctl >>$LOG 2>&1) >>$LOG 2>&1
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700767 espin - $VERIFIED
768fi
David Bainbridgee87067b2019-08-12 22:00:12 +0000769if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +0000770 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +0000771fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700772
773bspin "Verify command PATH"
Test Userba1e7e72019-07-10 22:27:54 +0000774export PATH=$GOPATH/bin:$PATH
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700775espin $VERIFIED
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700776
David Bainbridgee87067b2019-08-12 22:00:12 +0000777STIME=$(date +%s)
Test Userba1e7e72019-07-10 22:27:54 +0000778if [ "$DEPLOY_K8S" == "yes" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000779 HAVE=$(kind get clusters | grep -c voltha-$NAME)
Test Userba1e7e72019-07-10 22:27:54 +0000780 bspin "Verify Kubernetes/Kind Cluster"
781 sspin
782 if [ $HAVE -eq 0 ]; then
David Bainbridge491b1bd2019-07-11 17:53:11 +0000783 espin $NOT_VERIFIED
784 bspin - "Verify cluster configuration"
David Bainbridge0774b232019-08-02 06:37:19 +0000785 if [ ! -r ./$NAME-cluster.cfg ]; then
David Bainbridge491b1bd2019-07-11 17:53:11 +0000786 espin - $NOT_VERIFIED
David Bainbridge0774b232019-08-02 06:37:19 +0000787 bspin - "Download cluster configuration: $TYPE-cluster.cfg to $NAME-cluster.cfg $DOWNLOAD"
788 (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 -0700789 espin - $VERIFIED
790 else
791 espin - $VERIFIED
792 fi
David Bainbridge0774b232019-08-02 06:37:19 +0000793 kind create cluster --name voltha-$NAME --config $NAME-cluster.cfg
David Bainbridge491b1bd2019-07-11 17:53:11 +0000794 else
795 espin $VERIFIED
Test Userba1e7e72019-07-10 22:27:54 +0000796 fi
797
David Bainbridge0774b232019-08-02 06:37:19 +0000798 export KUBECONFIG="$(kind get kubeconfig-path --name="voltha-$NAME")"
Test Userba1e7e72019-07-10 22:27:54 +0000799 P="coredns-.* \
David Bainbridge0774b232019-08-02 06:37:19 +0000800 etcd-voltha-$NAME-control-plane \
Test Userba1e7e72019-07-10 22:27:54 +0000801 kindnet-.* \
David Bainbridge0774b232019-08-02 06:37:19 +0000802 kube-apiserver-voltha-$NAME-control-plane \
803 kube-controller-manager-voltha-$NAME-control-plane \
Test Userba1e7e72019-07-10 22:27:54 +0000804 kube-proxy-.* \
David Bainbridge0774b232019-08-02 06:37:19 +0000805 kube-scheduler-voltha-$NAME-control-plane"
Test Userba1e7e72019-07-10 22:27:54 +0000806
807 EXPECT=$(test "$TYPE" == "minimal" && echo "12" || echo "14")
David Bainbridge4f1b5562019-08-19 04:46:52 +0000808 wait_for_pods - "kube-system" $EXPECT "includes" -1 "Waiting for system PODs to start" $P
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700809fi
David Bainbridgee87067b2019-08-12 22:00:12 +0000810if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +0000811 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +0000812fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700813
David Bainbridgee87067b2019-08-12 22:00:12 +0000814STIME=$(date +%s)
David Bainbridge4c6289c2019-09-03 21:11:32 +0000815COUNT=$(count_pods "kube-system" ":Running:" "tiller-deploy-.*")
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700816bspin "Verify Helm"
Test Userba1e7e72019-07-10 22:27:54 +0000817if [ $COUNT -ne 1 ]; then
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700818 espin $NOT_VERIFIED
Test Userb5712372019-07-03 21:52:17 +0000819 echo -e "Configuring Helm $GEAR"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700820 if [ "$INSTALL_HELM" == "no" ]; then
821 bspin - "Skip Helm/Tiller Initialization"
822 espin - $NO_ENTRY
823 else
824 bspin - "Initialize Helm"
825 (set -x; helm init --upgrade >>$LOG 2>&1) >>$LOG 2>&1
826 espin - $VERIFIED
David Bainbridge4f1b5562019-08-19 04:46:52 +0000827 wait_for_pods - "kube-system" 1 "includes" -1 "Waiting for Tiller POD to start" "tiller-deploy-.*"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700828 fi
Test Userb5712372019-07-03 21:52:17 +0000829 bspin - "Add Google Incubator repository to Helm"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700830 (set -x; helm repo add incubator https://kubernetes-charts-incubator.storage.googleapis.com >>$LOG 2>&1) >>$LOG 2>&1
831 espin - $VERIFIED
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -0700832
Test Userba1e7e72019-07-10 22:27:54 +0000833 # HACK (sort-of) - the config for tiller is about to be patched, which will
834 # cause the tiller pod to be recreated. This can sometimes cause a timing
835 # issue with the "wait_for_pods" call on tiller as it may incorrectly
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -0700836 # identify the running/ready tiller pod that is soon to be terminated as
Test Userba1e7e72019-07-10 22:27:54 +0000837 # what it is waiting for. To avoid this issue we do a clean scale down and
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -0700838 # scale up of the pod so the script controlls when it should be expecting
Test Userba1e7e72019-07-10 22:27:54 +0000839 # things
840 (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 -0700841
Test Userb5712372019-07-03 21:52:17 +0000842 bspin - "Add Google Stable repository to Helm"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700843 (set -x; helm repo add stable https://kubernetes-charts.storage.googleapis.com >>$LOG 2>&1) >>$LOG 2>&1
844 espin - $VERIFIED
Test Userb5712372019-07-03 21:52:17 +0000845 bspin - "Add ONF repository to Helm"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700846 (set -x; helm repo add onf https://charts.opencord.org >>$LOG 2>&1) >>$LOG 2>&1
847 espin - $VERIFIED
Test Userb5712372019-07-03 21:52:17 +0000848 bspin - "Update Helm repository cache"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700849 (set -x; helm repo update >>$LOG 2>&1) >>$LOG 2>&1
850 espin - $VERIFIED
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -0700851
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700852 # Create and k8s service account so that Helm can create pods
Test Userb5712372019-07-03 21:52:17 +0000853 bspin - "Create Tiller ServiceAccount"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700854 (set -x; kubectl create serviceaccount --namespace kube-system tiller >>$LOG 2>&1) >>$LOG 2>&1
855 espin - $VERIFIED
Test Userb5712372019-07-03 21:52:17 +0000856 bspin - "Create Tiller ClusterRoleBinding"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700857 (set -x; kubectl create clusterrolebinding tiller-cluster-rule --clusterrole=cluster-admin --serviceaccount=kube-system:tiller >>$LOG 2>&1) >>$LOG 2>&1
858 espin - $VERIFIED
Test Userb5712372019-07-03 21:52:17 +0000859 bspin - "Update Tiller Manifest"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700860 (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 +0000861
862 # HACK (sort-of) - part to, spin it back up
863 (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 -0700864 espin - $VERIFIED
865else
866 espin $VERIFIED
David Bainbridge46505fb2019-10-01 21:13:20 +0000867 if [ "$UPDATE_HELM_REPOS" == "yes" ]; then
868 bspin - "Update Helm repository cache"
869 (set -x; helm repo update >>$LOG 2>&1) >>$LOG 2>&1
870 espin - $VERIFIED
871 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700872fi
David Bainbridge4f1b5562019-08-19 04:46:52 +0000873wait_for_pods - "kube-system" 1 "includes" -1 "Waiting for Tiller POD to start" "tiller-deploy-.*"
David Bainbridgee87067b2019-08-12 22:00:12 +0000874if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +0000875 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +0000876fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700877
David Bainbridgee87067b2019-08-12 22:00:12 +0000878STIME=$(date +%s)
David Bainbridge0774b232019-08-02 06:37:19 +0000879bspin "Verify Helm values file: $NAME-values.yaml"
880if [ ! -r "./$NAME-values.yaml" ]; then
Test Userba1e7e72019-07-10 22:27:54 +0000881 espin $NOT_VERIFIED
David Bainbridge0774b232019-08-02 06:37:19 +0000882 bspin - "Download Helm values file: $TYPE-values.yaml to $NAME-values.yaml $DOWNLOAD"
883 (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 +0000884 espin - $VERIFIED
885else
886 espin $VERIFIED
887fi
David Bainbridgee87067b2019-08-12 22:00:12 +0000888if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +0000889 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +0000890fi
Test Userba1e7e72019-07-10 22:27:54 +0000891
David Bainbridge99ac7a22019-08-31 02:26:43 +0000892STIME=$(date +%s)
893bspin "Verify or download chart specific values files $DOWNLOAD"
894VALUES_FILES="monkey-values.yaml"
895for i in $VALUES_FILES; do
896 if [ ! -r ./$i ]; then
897 (set -x; curl -o ./$i -sSL https://raw.githubusercontent.com/ciena/kind-voltha/master/$i >>$LOG 2>&1) >>$LOG 2>&1
898 fi
899done
900espin $VERIFIED
901if [ "$WITH_TIMINGS" == "yes" ]; then
902 printtime $(expr $(date +%s) - $STIME)
903fi
904
905if [ "$WITH_CHAOS" == "yes" ]; then
906 bspin "Verify or clone kube-monkey helm chart $DOWNLOAD"
907 if [ -r ./kube-monkey ]; then
908 espin $VERIFIED
909 else
910 espin $NOT_VERIFIED
911 bspin - "GIT clone kube-monkey"
912 (set -x; git clone https://github.com/asobti/kube-monkey kube-monkey >>$LOG 2>&1) >>$LOG 2>&1
913 espin - $VERIFIED
914 fi
915fi
916
Test Userba1e7e72019-07-10 22:27:54 +0000917if [ "$JUST_K8S" == "yes" ]; then
918 echo "Environment deployed, not deploying VOLTHA artifacts as requested. Good bye."
919 echo ""
920 echo "Please issue the following commands in your terminal to ensure that you" | tee -a $LOG
921 echo "are accessing the correct Kubernetes/Kind cluster as well as have the " | tee -a $LOG
922 echo "tools required by VOLTHA in your command path. " | tee -a $LOG
923 echo "" | tee -a $LOG
924 echo -en $BOLD
925 if [ $DEPLOY_K8S == "yes" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000926 echo "export KUBECONFIG=\"\$(./bin/kind get kubeconfig-path --name=\"voltha-$NAME\")\"" | tee -a $LOG
Test Userba1e7e72019-07-10 22:27:54 +0000927 fi
928 echo "export PATH=$GOPATH/bin:\$PATH" | tee -a $LOG
929 echo -en $NORMAL
930 echo "" | tee -a $LOG
931 echo "Thank you for choosing kind-voltha for you quick cluster needs." | tee -a $LOG
932 exit 0
933fi
934
David Bainbridgee87067b2019-08-12 22:00:12 +0000935STIME=$(date +%s)
Test Userb5712372019-07-03 21:52:17 +0000936bspin "Verify ETCD Operator $OLD_KEY"
Test User7d866122019-07-09 17:52:35 +0000937if [ $(helm list --deployed --short --namespace voltha "^etcd-operator\$" | wc -l) -ne 1 ]; then
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -0700938 espin $NOT_VERIFIED
David Bainbridge90fd8e32019-08-21 23:32:47 +0000939 helm_install - voltha etcd-operator stable/etcd-operator latest "Install ETCD Operator"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700940else
941 espin $VERIFIED
942fi
Test User01ed0642019-07-03 20:17:06 +0000943EXPECT=$(test "$TYPE" == "minimal" && echo "1" || echo "3")
David Bainbridge4f1b5562019-08-19 04:46:52 +0000944wait_for_pods - "voltha" $EXPECT "includes" -1 "Waiting for ETCD Operator to start" "etcd-operator-.*"
David Bainbridgee87067b2019-08-12 22:00:12 +0000945if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +0000946 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +0000947fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700948
David Bainbridgee87067b2019-08-12 22:00:12 +0000949STIME=$(date +%s)
David Bainbridgeb270c202019-07-26 01:44:42 +0000950if [ $WITH_ONOS == "yes" ]; then
951 bspin "Verify ONOS installed $BIRD"
952 if [ $(helm list --deployed --short --namespace default "^onos\$" | wc -l) -ne 1 ]; then
953 espin $NOT_VERIFIED
David Bainbridge90fd8e32019-08-21 23:32:47 +0000954 EXTRA_HELM_FLAGS="$SET_TAG $EXTRA_HELM_FLAGS" helm_install - default onos onf/onos latest "Install ONOS"
David Bainbridgeb270c202019-07-26 01:44:42 +0000955 else
956 espin $VERIFIED
957 fi
David Bainbridge4f1b5562019-08-19 04:46:52 +0000958 wait_for_pods - "default" 1 "includes" -1 "Waiting for ONOS to start" "onos-.*"
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -0700959
David Bainbridgeb270c202019-07-26 01:44:42 +0000960 bspin - "Forward ONOS API port $FORWARD"
David Bainbridge0774b232019-08-02 06:37:19 +0000961 for i in $(screen -ls | grep onos-ui-$NAME | awk '{print $1}'); do
David Bainbridge82bd1212019-07-29 19:19:31 +0000962 (set -x; screen -X -S $i quit >>$LOG 2>&1) >>$LOG 2>&1
963 done
David Bainbridge0774b232019-08-02 06:37:19 +0000964 (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 +0000965 espin - $VERIFIED
966 bspin - "Forward ONOS SSH port $FORWARD"
David Bainbridge0774b232019-08-02 06:37:19 +0000967 for i in $(screen -ls | grep onos-ssh-$NAME | awk '{print $1}'); do
David Bainbridge82bd1212019-07-29 19:19:31 +0000968 (set -x; screen -X -S $i quit >>$LOG 2>&1) >>$LOG 2>&1
969 done
David Bainbridge2b19e832019-08-16 02:40:53 +0000970
971
David Bainbridge0774b232019-08-02 06:37:19 +0000972 (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 +0000973 espin - $VERIFIED
David Bainbridged31d6122019-08-13 19:37:59 +0000974 bspin - "Verify or download ONOS configuration support files $DOWNLOAD"
David Bainbridge2b19e832019-08-16 02:40:53 +0000975 ONOS_FILES="olt-onos-enableExtraneousRules.json olt-onos-olt-settings.json onos-aaa.json \
David Bainbridge90fd8e32019-08-21 23:32:47 +0000976 onos-dhcpl2relay.json onos-kafka.json onos-sadis-sample.json"
David Bainbridged31d6122019-08-13 19:37:59 +0000977 (set -x; mkdir -p ./onos-files >>$LOG 2>&1) >>$LOG 2>&1
David Bainbridge2b19e832019-08-16 02:40:53 +0000978 for i in $ONOS_FILES; do
David Bainbridged31d6122019-08-13 19:37:59 +0000979 if [ ! -r ./onos-files/$i ]; then
980 (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
981 fi
982 done
Test Userba1e7e72019-07-10 22:27:54 +0000983 espin - $VERIFIED
David Bainbridge27790d62019-08-13 22:43:19 +0000984
985 if [ $INSTALL_ONOS_APPS == "yes" ]; then
986 bspin - "Installing custom ONOS applications"
987 if [ -x onos-files/onos-apps -a $(ls -1 onos-files/onos-apps/*.oar 2>/dev/null | wc -l) -gt 0 ]; then
988 for OAR in $(ls -1 onos-files/onos-apps/*.oar); do
989 sspin - "Installing custom ONOS applications - $OAR$CEOL"
David Bainbridge2b19e832019-08-16 02:40:53 +0000990 override_onos_app $OAR
David Bainbridge27790d62019-08-13 22:43:19 +0000991 done
992 espin - "$VERIFIED Installing custom ONOS applications$CEOL"
993 else
994 espin - "$NOT_VERIFIED Installing custom ONOS applications - None Found"
995 fi
996 fi
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -0700997
David Bainbridge2b19e832019-08-16 02:40:53 +0000998 push_onos_config "Push ONOS Kafka Configuration" "network/configuration/apps/org.opencord.kafka" "onos-files/onos-kafka.json"
999 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 +00001000 push_onos_config "Enable VOLTHA ONOS DHCP provisioning" "configuration/org.opencord.olt.impl.Olt" "onos-files/olt-onos-olt-settings.json"
1001 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 +00001002 if [ -f onos-files/onos-sadis.json ]; then
1003 push_onos_config "[optional] Push ONOS SADIS Configuration" "network/configuration/apps/org.opencord.sadis" "onos-files/onos-sadis.json"
1004 elif [ "$CONFIG_SADIS" == "yes" ]; then
David Bainbridge90fd8e32019-08-21 23:32:47 +00001005 SADIS_CFG=onos-files/onos-sadis-sample.json
David Bainbridge2b19e832019-08-16 02:40:53 +00001006 push_onos_config "[optional] Push ONOS SADIS Configuration" "network/configuration/apps/org.opencord.sadis" "$SADIS_CFG"
1007 fi
Test Userba1e7e72019-07-10 22:27:54 +00001008fi
David Bainbridgee87067b2019-08-12 22:00:12 +00001009if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +00001010 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +00001011fi
Test Userba1e7e72019-07-10 22:27:54 +00001012
David Bainbridgee87067b2019-08-12 22:00:12 +00001013STIME=$(date +%s)
Test Userb5712372019-07-03 21:52:17 +00001014bspin "Verify VOLTHA installed $HIGH_VOLTAGE"
Test User7d866122019-07-09 17:52:35 +00001015if [ $(helm list --deployed --short --namespace voltha "^voltha\$" | wc -l) -ne 1 ]; then
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001016 espin $NOT_VERIFIED
David Bainbridge90fd8e32019-08-21 23:32:47 +00001017 helm_install - voltha voltha $VOLTHA_CHART $VOLTHA_CHART_VERSION "Install VOLTHA Core"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001018else
1019 espin $VERIFIED
1020fi
Test Userba1e7e72019-07-10 22:27:54 +00001021
David Bainbridge90fd8e32019-08-21 23:32:47 +00001022VOLTHA="voltha-ofagent-.* \
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001023 ro-core.* \
1024 rw-core.* \
1025 voltha-api-server-.* \
1026 voltha-cli-server-.* \
1027 voltha-etcd-cluster-.* \
1028 voltha-kafka-.* \
1029 voltha-zookeeper-.*"
David Bainbridge46505fb2019-10-01 21:13:20 +00001030#EXPECT=$(test "$TYPE" == "minimal" && echo "8" || echo "11")
Test User01ed0642019-07-03 20:17:06 +00001031EXPECT=$(test "$TYPE" == "minimal" && echo "9" || echo "11")
David Bainbridge4f1b5562019-08-19 04:46:52 +00001032wait_for_pods - "voltha" $EXPECT "includes" -1 "Waiting for VOLTHA Core to start" $VOLTHA
David Bainbridgee87067b2019-08-12 22:00:12 +00001033if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +00001034 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +00001035fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001036
David Bainbridge46505fb2019-10-01 21:13:20 +00001037if [ "$WITH_ADAPTERS" == "yes" ]; then
1038 STIME=$(date +%s)
1039 EXPECT=0
1040 echo -e "Verify Adapters $PLUG"
1041 if [ "$WITH_SIM_ADAPTERS" == "yes" ]; then
1042 bspin - "Verify Simulated Adapters installed"
1043 if [ $(helm list --deployed --short --namespace voltha "^sim\$" | wc -l) -ne 1 ]; then
1044 espin - $NOT_VERIFIED
1045 helm_install - voltha sim $VOLTHA_ADAPTER_SIM_CHART $VOLTHA_ADAPTER_SIM_CHART_VERSION "Install Simulated Adapters"
1046 else
1047 espin - $VERIFIED
1048 fi
1049 EXPECT=$(expr $EXPECT + 2)
1050 fi
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001051
David Bainbridge46505fb2019-10-01 21:13:20 +00001052 if [ "$WITH_OPEN_ADAPTERS" == "yes" ]; then
1053 bspin - "Verify OpenOLT Adapter installed"
1054 if [ $(helm list --deployed --short --namespace voltha "^open-olt\$" | wc -l) -ne 1 ]; then
1055 espin - $NOT_VERIFIED
1056 helm_install - voltha open-olt $VOLTHA_ADAPTER_OPEN_OLT_CHART $VOLTHA_ADAPTER_OPEN_OLT_CHART_VERSION "Install OpenOLT Adapter"
1057 else
1058 espin - $VERIFIED
1059 fi
1060 bspin - "Verify OpenONU Adapter installed"
1061 if [ $(helm list --deployed --short --namespace voltha "^open-onu\$" | wc -l) -ne 1 ]; then
1062 espin - $NOT_VERIFIED
1063 helm_install - voltha open-onu $VOLTHA_ADAPTER_OPEN_ONU_CHART $VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION "Install OpenONU Adapter"
1064 else
1065 espin - $VERIFIED
1066 fi
1067 EXPECT=$(expr $EXPECT + 2)
1068 fi
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001069
David Bainbridge46505fb2019-10-01 21:13:20 +00001070 ADAPTERS="adapter-.*"
1071 wait_for_pods - "voltha" $EXPECT "includes" -1 "Waiting for adapters to start" $ADAPTERS
1072 if [ "$WITH_TIMINGS" == "yes" ]; then
1073 printtime $(expr $(date +%s) - $STIME)
1074 fi
David Bainbridgee87067b2019-08-12 22:00:12 +00001075fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001076
Test User7d866122019-07-09 17:52:35 +00001077if [ $WITH_BBSIM == "yes" ]; then
David Bainbridgee87067b2019-08-12 22:00:12 +00001078 STIME=$(date +%s)
Test User7d866122019-07-09 17:52:35 +00001079 echo -e "Verify BBSIM $PLUG"
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001080 bspin - "Verify BBSIM Installed"
Test User7d866122019-07-09 17:52:35 +00001081 if [ $(helm list --deployed --short --namespace voltha "^bbsim\$" | wc -l) -ne 1 ]; then
1082 espin - $NOT_VERIFIED
David Bainbridge90fd8e32019-08-21 23:32:47 +00001083 helm_install - voltha bbsim $VOLTHA_BBSIM_CHART $VOLTHA_BBSIM_CHART_VERSION "Install BBSIM"
Test User7d866122019-07-09 17:52:35 +00001084 else
1085 espin - $VERIFIED
1086 fi
David Bainbridge4f1b5562019-08-19 04:46:52 +00001087 wait_for_pods - "voltha" 1 "includes" -1 "Waiting for BBSIM to start" "bbsim-.*"
David Bainbridgee87067b2019-08-12 22:00:12 +00001088 if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +00001089 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +00001090 fi
Test User7d866122019-07-09 17:52:35 +00001091fi
1092
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001093if [ $WITH_RADIUS == "yes" ]; then
David Bainbridgee87067b2019-08-12 22:00:12 +00001094 STIME=$(date +%s)
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001095 echo -e "Verify RADIUS $LOCK"
1096 bspin - "Verify RADIUS Installed"
1097 if [ $(helm list --deployed --short --namespace voltha "^radius\$" | wc -l) -ne 1 ]; then
1098 espin - $NOT_VERIFIED
David Bainbridge90fd8e32019-08-21 23:32:47 +00001099 helm_install - voltha radius onf/freeradius latest "Install RADIUS"
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001100 else
1101 espin - $VERIFIED
1102 fi
David Bainbridge4f1b5562019-08-19 04:46:52 +00001103 wait_for_pods - "voltha" 1 "includes" -1 "Waiting for RADIUS to start" "radius-.*"
David Bainbridgee87067b2019-08-12 22:00:12 +00001104 if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +00001105 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +00001106 fi
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001107fi
1108
David Bainbridgee87067b2019-08-12 22:00:12 +00001109STIME=$(date +%s)
David Bainbridgee10f6d52019-07-25 00:28:13 +00001110if [ $SKIP_RESTART_API == "no" ]; then
1111 echo -e "Restart VOLTHA API $RESTART"
David Bainbridge90fd8e32019-08-21 23:32:47 +00001112 API="voltha-api-server-.* voltha-ofagent-.*"
1113 (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 +00001114 wait_for_pods - "voltha" 0 "includes" -1 "Wait for API to stop $STOP" $API
David Bainbridge90fd8e32019-08-21 23:32:47 +00001115 (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 +00001116 wait_for_pods - "voltha" 2 "includes" -1 "Wait for API to re-start $GO" $API
David Bainbridgee10f6d52019-07-25 00:28:13 +00001117fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001118
Test Userb5712372019-07-03 21:52:17 +00001119bspin - "Forward VOLTHA API port $FORWARD"
David Bainbridge0774b232019-08-02 06:37:19 +00001120for i in $(screen -ls | grep voltha-api-$NAME | awk '{print $1}'); do
David Bainbridge82bd1212019-07-29 19:19:31 +00001121 (set -x; screen -X -S $i quit >>$LOG 2>&1) >>$LOG 2>&1
1122done
David Bainbridge0774b232019-08-02 06:37:19 +00001123(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 -07001124espin - $VERIFIED
Test Userb5712372019-07-03 21:52:17 +00001125bspin - "Forward VOLTHA SSH port $FORWARD"
David Bainbridge0774b232019-08-02 06:37:19 +00001126for i in $(screen -ls | grep voltha-ssh-$NAME | awk '{print $1}'); do
David Bainbridge82bd1212019-07-29 19:19:31 +00001127 (set -x; screen -X -S $i quit >>$LOG 2>&1) >>$LOG 2>&1
1128done
David Bainbridge0774b232019-08-02 06:37:19 +00001129(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 -07001130espin - $VERIFIED
David Bainbridgeac7f8072019-08-01 22:15:33 +00001131bspin - "Forward VOLTHA ETCD port $FORWARD"
David Bainbridge0774b232019-08-02 06:37:19 +00001132for i in $(screen -ls | grep voltha-etcd-$NAME | awk '{print $1}'); do
David Bainbridgeac7f8072019-08-01 22:15:33 +00001133 (set -x; screen -X -S $i quit >>$LOG 2>&1) >>$LOG 2>&1
1134done
David Bainbridge0774b232019-08-02 06:37:19 +00001135(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 +00001136espin - $VERIFIED
David Bainbridgee87067b2019-08-12 22:00:12 +00001137if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +00001138 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +00001139fi
Test User3d7ad8e2019-07-03 06:15:44 +00001140
David Bainbridgeb270c202019-07-26 01:44:42 +00001141if [ $WITH_ONOS == "yes" -a $WITH_RADIUS == "yes" ]; then
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001142 bspin "Configure ONOS RADIUS Connection $GEAR"
David Bainbridge2b19e832019-08-16 02:40:53 +00001143 (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 +00001144 espin $VERIFIED
1145fi
1146
David Bainbridge99ac7a22019-08-31 02:26:43 +00001147if [ "$WITH_CHAOS" == "yes" ]; then
1148 STIME=$(date +%s)
1149 echo -e "Verify kube-monkey $LOCK"
1150 bspin - "Verify kube-monkey Installed"
1151 if [ $(helm list --deployed --short --namespace kube-monkey "^monkey\$" | wc -l) -ne 1 ]; then
1152 espin - $NOT_VERIFIED
1153 helm_install - kube-monkey monkey ./kube-monkey/helm/kubemonkey latest "Install Chaos Monkey"
1154 else
1155 espin - $VERIFIED
1156 fi
1157 wait_for_pods - "kube-monkey" 1 "includes" -1 "Waiting for Chaos to start" "monkey-.*"
1158 if [ "$WITH_TIMINGS" == "yes" ]; then
1159 printtime $(expr $(date +%s) - $STIME)
1160 fi
1161fi
1162
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001163bspin "Create voltctl configuration file"
Test User3d7ad8e2019-07-03 06:15:44 +00001164(set -x; mkdir -p $HOME/.volt >>$LOG 2>&1) >>$LOG 2>&1
David Bainbridge0774b232019-08-02 06:37:19 +00001165(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 +00001166espin $VERIFIED
Test User08ebbd92019-07-03 17:15:39 +00001167
David Bainbridge0774b232019-08-02 06:37:19 +00001168if [ ! -f "$NAME-env.sh" ]; then
1169 touch $NAME-env.sh
David Bainbridgeb07fdf72019-07-29 22:51:40 +00001170fi
1171
David Bainbridge596f30d2019-07-30 17:07:59 +00001172for O in $ALL_OPTIONS; do
1173 VAL=$(eval echo \$$O)
David Bainbridge0774b232019-08-02 06:37:19 +00001174 if [ ! -z "$VAL" -a $(grep -c "^export $O=" $NAME-env.sh) -eq 0 ]; then
1175 echo "export $O=\"$(eval echo \$$O)\"" >> $NAME-env.sh
David Bainbridgeb07fdf72019-07-29 22:51:40 +00001176 fi
1177done
1178
David Bainbridge0774b232019-08-02 06:37:19 +00001179if [ $DEPLOY_K8S == "yes" -a $(grep -c "^export KUBECONFIG=" $NAME-env.sh) -eq 0 ]; then
1180 echo "export KUBECONFIG=\"$(./bin/kind get kubeconfig-path --name=voltha-$NAME)\"" >> $NAME-env.sh
David Bainbridgeb07fdf72019-07-29 22:51:40 +00001181fi
1182
David Bainbridge0774b232019-08-02 06:37:19 +00001183if [ $(grep -c "^export VOLTCONFIG=" $NAME-env.sh) -eq 0 ]; then
1184 echo "export VOLTCONFIG=\"$HOME/.volt/config-$NAME\"" >> $NAME-env.sh
David Bainbridgeb07fdf72019-07-29 22:51:40 +00001185fi
1186
David Bainbridge0774b232019-08-02 06:37:19 +00001187if [ $(grep -c "^export PATH=" $NAME-env.sh) -eq 0 ]; then
1188 echo "export PATH=\"$GOPATH/bin:\$PATH\"" >> $NAME-env.sh
David Bainbridgeb07fdf72019-07-29 22:51:40 +00001189fi
1190
Test User7d866122019-07-09 17:52:35 +00001191echo ""
Test User08ebbd92019-07-03 17:15:39 +00001192echo "Please issue the following commands in your terminal to ensure that you" | tee -a $LOG
1193echo "are accessing the correct Kubernetes/Kind cluster as well as have the " | tee -a $LOG
1194echo "tools required by VOLTHA in your command path. " | tee -a $LOG
1195echo "" | tee -a $LOG
Test User7d866122019-07-09 17:52:35 +00001196echo -en $BOLD
Test Userba1e7e72019-07-10 22:27:54 +00001197if [ $DEPLOY_K8S == "yes" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +00001198 echo "export KUBECONFIG=\"\$(./bin/kind get kubeconfig-path --name=\"voltha-$NAME\")\"" | tee -a $LOG
Test Userba1e7e72019-07-10 22:27:54 +00001199fi
David Bainbridge0774b232019-08-02 06:37:19 +00001200echo "export VOLTCONFIG=\"$HOME/.volt/config-$NAME\"" | tee -a $LOG
Test Userba1e7e72019-07-10 22:27:54 +00001201echo "export PATH=$GOPATH/bin:\$PATH" | tee -a $LOG
Test User7d866122019-07-09 17:52:35 +00001202echo -en $NORMAL
Test User08ebbd92019-07-03 17:15:39 +00001203echo "" | tee -a $LOG
1204echo "Thank you for choosing kind-voltha for you quick cluster needs." | tee -a $LOG
1205
David Bainbridge712afb82019-08-14 19:55:58 +00001206if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridgef858a022019-08-14 21:25:11 +00001207 echo -e "$CLOCK ${BOLD}TOTAL: $(duration $(expr $(date +%s) - $TOTAL_START_TIME))${NORMAL}"
David Bainbridge712afb82019-08-14 19:55:58 +00001208fi