blob: f4c2eb15c371043f9ba0ecc8d867c37cde7f0f71 [file] [log] [blame]
Test User01ed0642019-07-03 20:17:06 +00001#!/bin/bash
David K. Bainbridgeb7285432019-07-02 22:05:24 -07002# Copyright 2019 Ciena Corporation
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
David Bainbridge712afb82019-08-14 19:55:58 +000015TOTAL_START_TIME=$(date +%s)
David K. Bainbridgeb7285432019-07-02 22:05:24 -070016
David Bainbridge38dc1e82019-08-12 15:18:45 +000017FANCY=${FANCY:-1}
18if [ "$TERM X" == " X" ]; then
19 FANCY=0
20fi
21
David K. Bainbridgeb7285432019-07-02 22:05:24 -070022# trap ctrl-c and call ctrl_c()
23trap ctrl_c INT
24
25function ctrl_c() {
David Bainbridge38dc1e82019-08-12 15:18:45 +000026 echo -en $CNORM
David K. Bainbridgeb7285432019-07-02 22:05:24 -070027 echo ""
28 echo "ctrl-c trapped"
David Bainbridgec6a6eb62019-10-18 22:50:07 +000029 echo "Thank you for trying 'voltha up'"
David K. Bainbridgeb7285432019-07-02 22:05:24 -070030 exit
31}
32
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 K. Bainbridge0e89cb92019-07-17 11:30:10 -070082INSTALL_KUBECTL=${INSTALL_KUBECTL:-yes}
83INSTALL_HELM=${INSTALL_HELM:-yes}
David Bainbridge46505fb2019-10-01 21:13:20 +000084UPDATE_HELM_REPOS=${UPDATE_HELM_REPOS:-yes}
David Bainbridge4f1b5562019-08-19 04:46:52 +000085WAIT_ON_DOWN=${WAIT_ON_DOWN:-no}
David Bainbridge5b7b96b2019-07-25 20:29:13 +000086VOLTHA_LOG_LEVEL=${VOLTHA_LOG_LEVEL:-WARN}
David Bainbridge90fd8e32019-08-21 23:32:47 +000087VOLTHA_CHART=${VOLTHA_CHART:-onf/voltha}
88VOLTHA_CHART_VERSION=${VOLTHA_CHART_VERSION:-latest}
89VOLTHA_BBSIM_CHART=${VOLTHA_BBSIM_CHART:-onf/bbsim}
Matteo Scandolodcd29f52019-10-07 15:42:42 -070090VOLTHA_BBSIM_CHART_VERSION=${VOLTHA_BBSIM_CHART_VERSION:-latest}
David Bainbridgee10f6d52019-07-25 00:28:13 +000091VOLTHA_ADAPTER_SIM_CHART=${VOLTHA_ADAPTER_SIM_CHART:-onf/voltha-adapter-simulated}
David Bainbridge90fd8e32019-08-21 23:32:47 +000092VOLTHA_ADAPTER_SIM_CHART_VERSION=${VOLTHA_ADAPTER_SIM_CHART_VERSION:-latest}
David Bainbridgee10f6d52019-07-25 00:28:13 +000093VOLTHA_ADAPTER_OPEN_OLT_CHART=${VOLTHA_ADAPTER_OPEN_OLT_CHART:-onf/voltha-adapter-openolt}
David Bainbridge90fd8e32019-08-21 23:32:47 +000094VOLTHA_ADAPTER_OPEN_OLT_CHART_VERSION=${VOLTHA_ADAPTER_OPEN_OLT_CHART_VERSION:-latest}
David Bainbridgee10f6d52019-07-25 00:28:13 +000095VOLTHA_ADAPTER_OPEN_ONU_CHART=${VOLTHA_ADAPTER_OPEN_ONU_CHART:-onf/voltha-adapter-openonu}
David Bainbridge90fd8e32019-08-21 23:32:47 +000096VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION=${VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION:-latest}
97
Test Userba1e7e72019-07-10 22:27:54 +000098
99HAVE_GO=$(which go >/dev/null 2>&1 && echo "yes" || echo "no")
100HOSTOS=$(uname -s | tr "[:upper:]" "[:lower:"])
101HOSTARCH=$(uname -m | tr "[:upper:]" "[:lower:"])
102if [ $HOSTARCH == "x86_64" ]; then
103 HOSTARCH="amd64"
104fi
Test User7d866122019-07-09 17:52:35 +0000105
106# Verify TYPE setting
107if [ $(echo ":minimal:full:" | grep -ic ":$TYPE:") -eq 0 ]; then
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700108 >&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 +0000109 exit 1
110fi
111
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000112# Used to verify configuration values are set to "yes" or "no" value or convert
113# equivalents to "yes" or "no"
114function verify_yes_no() {
115 local VAR=$1
116 local VAL=$(eval echo \$$VAR)
117 if [ $(echo ":y:yes:true:n:no:false:1:0:" | grep -ic ":$VAL:") -eq 0 ]; then
118 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} Invalid '$VAR' value of '$VAL'. Should be 'yes' or 'no'${NORMAL}"
119 echo "INVALID"
120 return 1
121 fi
122 if [ $(echo ":y:yes:true:1:" | grep -ic ":$VAL:") -eq 1 ]; then
123 echo "yes"
124 else
125 echo "no"
126 fi
127 return 0
128}
Test User7d866122019-07-09 17:52:35 +0000129
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000130ALL_YES_NO="\
131 WITH_TIMINGS \
132 WITH_BBSIM \
133 WITH_RADIUS \
134 WITH_ONOS \
David Bainbridge99ac7a22019-08-31 02:26:43 +0000135 WITH_CHAOS \
David Bainbridge46505fb2019-10-01 21:13:20 +0000136 WITH_ADAPTERS \
137 WITH_SIM_ADAPTERS \
138 WITH_OPEN_ADAPTERS \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000139 CONFIG_SADIS \
140 JUST_K8S \
141 DEPLOY_K8S \
142 INSTALL_ONOS_APPS \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000143 INSTALL_KUBECTL \
144 INSTALL_HELM \
David Bainbridge46505fb2019-10-01 21:13:20 +0000145 UPDATE_HELM_REPOS \
David Bainbridge4f1b5562019-08-19 04:46:52 +0000146 WAIT_ON_DOWN \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000147 "
David Bainbridge5b7b96b2019-07-25 20:29:13 +0000148
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000149ALL_OPTIONS="\
150 NAME \
151 TYPE \
152 $ALL_YES_NO \
153 VOLTHA_LOG_LEVEL \
154 VOLTHA_CHART \
David Bainbridge90fd8e32019-08-21 23:32:47 +0000155 VOLTHA_CHART_VERSION \
156 VOLTHA_BBSIM_CHART \
157 VOLTHA_BBSIM_CHART_VERSION \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000158 VOLTHA_ADAPTER_SIM_CHART \
David Bainbridge90fd8e32019-08-21 23:32:47 +0000159 VOLTHA_ADAPTER_SIM_CHART_VERSION \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000160 VOLTHA_ADAPTER_OPEN_OLT_CHART \
David Bainbridge90fd8e32019-08-21 23:32:47 +0000161 VOLTHA_ADAPTER_OPEN_OLT_CHART_VERSION \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000162 VOLTHA_ADAPTER_OPEN_ONU_CHART \
David Bainbridge90fd8e32019-08-21 23:32:47 +0000163 VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000164 ONOS_API_PORT \
165 ONOS_SSH_PORT \
166 VOLTHA_API_PORT \
167 VOLTHA_SSH_PORT \
168 VOLTHA_ETCD_PORT \
169 "
David Bainbridge01294952019-07-30 19:33:45 +0000170
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000171# Iterate over yes/no configuration options and validate
172for VAR in $ALL_YES_NO; do
173 eval $VAR=$(verify_yes_no $VAR)
174 if [ "$(eval echo \$$VAR)" == "INVALID" ]; then
175 exit 1;
176 fi
177done
David Bainbridgeb270c202019-07-26 01:44:42 +0000178
David Bainbridge0774b232019-08-02 06:37:19 +0000179mkdir -p .voltha
180touch .voltha/ports
181HAVE=$(grep $NAME .voltha/ports)
182if [ "$HAVE X" == " X" ]; then
183 # Find free port prefix
184 START=81
185 while true; do
186 if [ $(grep -c $START .voltha/ports) -eq 0 ]; then
187 break
188 fi
189 START=$(expr $START + 1)
190 done
191 DELTA=$(expr $START - 81)
David Bainbridgea2595422019-10-22 03:54:28 +0000192 ONOS_API_PORT=${ONOS_API_PORT:-${START}81}
193 ONOS_SSH_PORT=${ONOS_SSH_PORT:-${START}01}
194 VOLTHA_API_PORT=${VOLTHA_API_PORT:-5$(expr 55 + $DELTA)55}
195 VOLTHA_SSH_PORT=${VOLTHA_SSH_PORT:-$(expr 50 + $DELTA)22}
196 VOLTHA_ETCD_PORT=${VOLTHA_ETCD_PORT:-$(expr 23 + $DELTA)79}
Test User01ed0642019-07-03 20:17:06 +0000197else
David Bainbridge0774b232019-08-02 06:37:19 +0000198 VALUES=$(echo $HAVE | sed -e 's/\s//g' | cut -d= -f2)
David Bainbridgea2595422019-10-22 03:54:28 +0000199 echo "VALUES = $VALUES"
200 ONOS_API_PORT=${ONOS_API_PORT:-$(echo $VALUES | cut -d, -f1)}
201 ONOS_SSH_PORT=${ONOS_SSH_PORT:-$(echo $VALUES | cut -d, -f2)}
202 VOLTHA_API_PORT=${VOLTHA_API_PORT:-$(echo $VALUES | cut -d, -f3)}
203 VOLTHA_SSH_PORT=${VOLTHA_SSH_PORT:-$(echo $VALUES | cut -d, -f4)}
204 VOLTHA_ETCD_PORT=${VOLTHA_ETCD_PORT:-$(echo $VALUES | cut -d, -f5)}
Test User01ed0642019-07-03 20:17:06 +0000205fi
206
David Bainbridge0774b232019-08-02 06:37:19 +0000207PORTTMP=$(mktemp -u)
208cat .voltha/ports | grep -v $NAME > $PORTTMP
209echo "$NAME=$ONOS_API_PORT,$ONOS_SSH_PORT,$VOLTHA_API_PORT,$VOLTHA_SSH_PORT,$VOLTHA_ETCD_PORT" >> $PORTTMP
210cp $PORTTMP .voltha/ports
211rm -f $PORTTMP
212
David Bainbridge27790d62019-08-13 22:43:19 +0000213export ONOS_API_PORT ONOS_SSH_PORT
David Bainbridge01294952019-07-30 19:33:45 +0000214
Test Userd87942b2019-07-03 07:20:24 +0000215IDX=1
David Bainbridgee87067b2019-08-12 22:00:12 +0000216CLOCK="TIME:"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000217SPIN_PARTS=
218NOT_VERIFIED=
David Bainbridgef858a022019-08-14 21:25:11 +0000219THEX=
220BUILD=
221CROSS=
222ENTER=
David Bainbridge38dc1e82019-08-12 15:18:45 +0000223VERIFIED=
224HELM=
225OLD_KEY=
226BIRD=
227HIGH_VOLTAGE=
228PLUG=
229RESTART=
230FORWARD=
231INSTALL=
232STOP=
233GO=
234DOWNLOAD=
235GEAR=
236NO_ENTRY=
237LOCK=
238
239if [ $FANCY -eq 1 ]; then
240 SPIN_PARTS="\
241 \xe2\xa2\x8e\xe2\xa1\xb0 \
242 \xe2\xa2\x8e\xe2\xa1\xa1 \
243 \xe2\xa2\x8e\xe2\xa1\x91 \
244 \xe2\xa2\x8e\xe2\xa0\xb1 \
245 \xe2\xa0\x8e\xe2\xa1\xb1 \
246 \xe2\xa2\x8a\xe2\xa1\xb1 \
247 \xe2\xa2\x8c\xe2\xa1\xb1 \
248 \xe2\xa2\x86\xe2\xa1\xb1 \
249 "
David Bainbridgee87067b2019-08-12 22:00:12 +0000250 CLOCK="\xe2\x8f\xb1"
David Bainbridgef858a022019-08-14 21:25:11 +0000251 THEX="${RED}${BOLD}\xe2\x9c\x97\x20${NORMAL}"
252 ENTER="${YELLOW}${BOLD}\xe2\x8e\x86${NORMAL}"
253 CROSS="${YELLOW}${BOLD}\xe2\x9c\x9a${NORMAL}"
254 BUILD="${YELLOW}${BOLD}\xf0\x9f\x8f\x97${NORMAL}"
255 NOT_VERIFIED="$BUILD"
256 VERIFIED="${GREEN}${BOLD}\xe2\x9c\x93\x20${NORMAL}"
257 HELM="${BLUE}${BOLD}\xE2\x8E\x88${NORMAL}"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000258 OLD_KEY="\xF0\x9F\x97\x9D"
259 BIRD="\xF0\x9F\x90\xA6"
260 HIGH_VOLTAGE="\xE2\x9A\xA1"
261 PLUG="\xF0\x9F\xa7\xa9"
262 RESTART="\xf0\x9f\x94\x84"
263 FORWARD="\xE2\x87\xA8"
264 INSTALL="\xF0\x9F\x8F\x97"
265 STOP="\xf0\x9f\x9b\x91"
266 GO="\xf0\x9f\x9a\x80"
267 DOWNLOAD="\xf0\x9f\x93\xa5"
268 GEAR="\xe2\x9a\x99"
269 NO_ENTRY="\xe2\x9b\x94"
270 LOCK="\xf0\x9f\x94\x92"
271fi
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700272
David Bainbridge712afb82019-08-14 19:55:58 +0000273duration() {
David Bainbridgee87067b2019-08-12 22:00:12 +0000274 local h=$(expr $1 / 3600)
275 local m=$(expr $1 % 3600 / 60)
276 local s=$(expr $1 % 60)
277 local t=""
278
279 if [ $h -gt 0 ]; then
280 t="$t${h}h"
281 fi
282 if [ $m -gt 0 ]; then
283 t="$t${m}m"
284 fi
David Bainbridge712afb82019-08-14 19:55:58 +0000285 echo "$t${s}s"
286}
287
288printtime() {
289 local INDENT=
290 if [ "$1" == "-" ]; then
291 INDENT=" "
292 shift
293 fi
294 echo -e "$INDENT $CLOCK $(duration $1)"
David Bainbridgee87067b2019-08-12 22:00:12 +0000295}
296
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700297bspin() {
Test Userd87942b2019-07-03 07:20:24 +0000298 IDX=1
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700299 local INDENT=
300 if [ "$1" == "-" ]; then
301 INDENT=" "
302 shift
303 fi
David Bainbridge38dc1e82019-08-12 15:18:45 +0000304 if [ $FANCY -eq 0 ]; then
305 LINE=$(echo $* | sed -e 's/[\s+-]//g')
306 if [ "$LINE X" == " X" ]; then
307 return
308 fi
309 echo -e "$CIVIS$INDENT$*"
310 else
311 echo -en "$CIVIS$INDENT $*"
312 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700313}
314
315sspin() {
316 local INDENT=
317 if [ "$1" == "-" ]; then
318 INDENT=" "
319 shift
320 fi
David Bainbridge38dc1e82019-08-12 15:18:45 +0000321 if [ $FANCY -eq 0 ]; then
322 LINE=$(echo $* | sed -e 's/[\s+-]//g')
323 if [ "$LINE X" == " X" ]; then
324 return
325 fi
326 echo -e "$INDENT$*"
327 else
328 C=$(echo $SPIN_PARTS | cut '-d ' -f $IDX)
329 echo -en "\r$INDENT$C $*"
330 IDX=$(expr $IDX + 1)
331 if [ $IDX -gt 8 ]; then
332 IDX=1
333 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700334 fi
335}
336
337espin() {
338 local INDENT=
339 if [ "$1" == "-" ]; then
340 INDENT=" "
341 shift
342 fi
David Bainbridge38dc1e82019-08-12 15:18:45 +0000343 if [ $FANCY -eq 0 ]; then
344 LINE=$(echo $* | sed -e 's/[\s+-]//g')
345 if [ "$LINE X" == " X" ]; then
346 return
347 fi
348 echo -e "$INDENT$*"
349 else
350 echo -e "\r$INDENT$*$CNORM"
351 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700352}
353
David Bainbridgeac7f8072019-08-01 22:15:33 +0000354if [ "$1" == "get" -a "$2" == "voltconfig" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000355 echo "$HOME/.volt/config-$NAME"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000356 exit
357fi
358
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -0700359if [ $# -ne 1 -o $(echo ":up:down:dump:" | grep -c ":$1:") -ne 1 ]; then
David Bainbridgeac7f8072019-08-01 22:15:33 +0000360 >&2 echo "What wouild you like to do today:"
361 >&2 echo " up - bring up voltha"
362 >&2 echo " down - tear down voltha"
363 >&2 echo " dump - create a debug dump of running system"
364 exit 1
365fi
366
David Bainbridge4f1b5562019-08-19 04:46:52 +0000367push_onos_config() {
368 local MSG=$1
369 local RESOURCE=$2
370 local DATA=$3
371
372 bspin - "$MSG $GEAR"
373 while true; do
374 (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
375 if [ $? -eq 0 ]; then
376 break
377 fi
378 sleep .2
379 sspin -
380 done
381 espin - $VERIFIED
382}
383
384override_onos_app() {
385 local APP=$1
386 local NAME=$(basename $APP | sed -e 's/^[0-9][0-9]*-//g' -e 's/-.*$//g')
387 while true; do
388 sspin -
389 # Attempt to delete old version (if it exists)
390 (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
391 sspin -
392 if [ $? -ne 0 ]; then
393 continue
394 fi
395 (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
396 if [ $? -eq 0 ]; then
397 break
398 fi
399 sleep .2
400 done
401}
402
403activate_onos_app() {
404 local MSG="$1"
405 local APP=$2
406
407 bspin - "$MSG $GO"
408 while true; do
409 sspin -
410 (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
411 if [ $? -eq 0 ]; then
412 break
413 fi
414 sleep .2
415 done
416 espin - "$VERIFIED"
417}
418
419count_pods() {
420 local NAMESPACE=$1; shift
421 if [ "$NAMESPACE" == "all-namespaces" ]; then
422 NAMESPACE="--all-namespaces"
423 else
424 NAMESPACE="-n $NAMESPACE"
425 fi
426 echo "$NAMESPACE" > /tmp/t
427 local STATES=$1; shift
428 echo "$STATES" >> /tmp/t
429 local PODS=$(kubectl get $NAMESPACE pod -o go-template="{{range .items}}{{.metadata.name}}/{{.status.phase}}/_{{range .status.containerStatuses}}{{.ready}}_{{end}} {{end}}")
430 local COUNT=0
431 local PATTERNS="$*"
432 for POD in $PODS; do
433 local NAME=$(echo $POD | cut -d/ -f 1)
434 local STATE=$(echo $POD | cut -d/ -f 2)
435 local CONTAINERS=$(echo $POD | cut -d/ -f 3 | sed -e 's/_/ /g')
436 if [ "$STATES" == "*" -o $(echo "$STATES" | grep -c ":$STATE:") -ne 0 ]; then
437 echo "IN WITH $POD" >> /tmp/t
438 local TOTAL=$(echo $CONTAINERS | wc -w)
439 local FOUND=$(echo $CONTAINERS | grep -o true | wc -l)
440 if [ $TOTAL -eq $FOUND ]; then
441 for PATTERN in $PATTERNS; do
442 echo "TEST $PATTERN AGAINST $NAME" >> /tmp/t
443 if [[ $NAME =~ $PATTERN ]]; then
444 echo "COUNT $NAME" >> /tmp/t
445 COUNT=$(expr $COUNT + 1)
446 break
447 fi
448 done
449 fi
450 fi
451 done
452 echo $COUNT >> /tmp/t
453 echo $COUNT
454}
455
456wait_for_pods() {
457 local INDENT=
458 if [ "$1" == "-" ]; then
459 INDENT=$1; shift
460 fi
461 local NAMESPACE=$1; shift
462 local EXPECT=$1; shift
463 local TYPE=$1; shift
464 local RETRY=$1; shift
465 local MESSAGE=$1; shift
466 local PATTERNS=$*
David Bainbridge99ac7a22019-08-31 02:26:43 +0000467 local STATES=":Running:"
468 if [ "$TYPE" == "not" ]; then
469 STATES="*"
470 fi
471 local HAVE=$(count_pods $NAMESPACE "$STATES" $PATTERNS)
David Bainbridge4f1b5562019-08-19 04:46:52 +0000472 local ALL=$HAVE
473 if [ "$TYPE" == "only" ]; then
474 ALL=$(count_pods "all-namespaces" "*" ".*")
475 fi
476 COUNT=$(expr 300 / 15)
477 bspin $INDENT $MESSAGE
478 sspin $INDENT
479 if [ $HAVE -ne $EXPECT -o $ALL -ne $HAVE ]; then
480 while [ $HAVE -ne $EXPECT -o $ALL -ne $HAVE ]; do
481 sspin $INDENT
482 COUNT=$(expr $COUNT - 1)
483 if [ $COUNT -eq 0 ]; then
David Bainbridge99ac7a22019-08-31 02:26:43 +0000484 HAVE=$(count_pods $NAMESPACE "$STATES" $PATTERNS)
David Bainbridge4f1b5562019-08-19 04:46:52 +0000485 ALL=$HAVE
486 if [ "$TYPE" == "only" ]; then
487 ALL=$(count_pods "all-namespaces" "*" ".*")
488 fi
489 COUNT=$(expr 300 / 15)
490 fi
491 sleep .15
492 done
493 fi
494 espin $INDENT $VERIFIED
495 if [ $HAVE -ne $EXPECT ]; then
496 return 1
497 fi
498 return 0
499}
500
David Bainbridgeac7f8072019-08-01 22:15:33 +0000501if [ "$1" == "down" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000502 echo "Tearing down voltha cluster $NAME"
503 LOG="down-$NAME.log"
504 echo $(date -u +"%Y%m%dT%H%M%SZ") >$LOG
David Bainbridgeac7f8072019-08-01 22:15:33 +0000505 if [ $DEPLOY_K8S == "yes" ]; then
506 if [ -x ./bin/kind ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000507 bspin "Delete Kubernetes Kind Cluster"
508 (set -x; ./bin/kind delete cluster --name voltha-$NAME >>$LOG 2>&1) >>$LOG 2>&1
509 espin $VERIFIED
David Bainbridgeac7f8072019-08-01 22:15:33 +0000510 else
David Bainbridge0774b232019-08-02 06:37:19 +0000511 espin "$NO_ENTRY Delete Kubernetes Kind Cluster: kind command not found"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000512 fi
513 else
514 EXISTS=$(helm list -q)
515 EXPECT="etcd-operator onos open-olt open-onu sim voltha bbsim radius"
David Bainbridge0774b232019-08-02 06:37:19 +0000516 bspin "Remove Helm Deployments"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000517 for i in $EXISTS; do
518 if [ $(echo $EXPECT | grep -c $i) -eq 1 ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000519 sspin "Remove Helm Deployments: $i$CEOL"
520 (set -x; ./bin/helm delete --purge $i >>$LOG 2>&1) >>$LOG 2>&1
David Bainbridgeac7f8072019-08-01 22:15:33 +0000521 fi
522 done
David Bainbridge0774b232019-08-02 06:37:19 +0000523 espin "$VERIFIED Remove Helm Deployments$CEOL"
David Bainbridge4f1b5562019-08-19 04:46:52 +0000524 if [ "$WAIT_ON_DOWN" == "yes" ]; then
525 # There should only be 13 or 15 PODs in the kube-system name
526 # space and no other PODs
David Bainbridge4f1b5562019-08-19 04:46:52 +0000527 PODS="coredns-.* \
528 etcd-voltha-$NAME-control-plane \
529 kindnet-.* \
530 kube-apiserver-voltha-$NAME-control-plane \
531 kube-controller-manager-voltha-$NAME-control-plane \
532 kube-proxy-.* \
533 kube-scheduler-voltha-$NAME-control-plane \
534 tiller-deploy-.*"
535 EXPECT=$(test "$TYPE" == "minimal" && echo "13" || echo "15")
David Bainbridge99ac7a22019-08-31 02:26:43 +0000536 PODS="adapter-.* \
537 bbsim.* \
538 etcd-operator.* \
539 radius.* \
540 voltha-.*"
541 EXPECT=0
542
543 wait_for_pods "voltha" $EXPECT "not" -1 "Waiting for VOLTHA PODs to terminate" $PODS
David Bainbridge4f1b5562019-08-19 04:46:52 +0000544 fi
David Bainbridgeac7f8072019-08-01 22:15:33 +0000545 fi
David Bainbridge0774b232019-08-02 06:37:19 +0000546 bspin "Remove port-forwards: onos-ui-$NAME"
547 for i in $(screen -ls | grep onos-ui-$NAME | awk '{print $1}'); do
548 sspin
549 (set -x; screen -X -S $i quit >>$LOG 2>&1) >>$LOG 2>&1
550 done
551 sspin "Remove port-forwards: onos-ssh-$NAME$CEOL"
552 for i in $(screen -ls | grep onos-ssh-$NAME | awk '{print $1}'); do
553 sspin
554 (set -x; screen -X -S $i quit >>$LOG 2>&1) >>$LOG 2>&1
555 done
556 sspin "Remove port-forwards: voltha-api-$NAME$CEOL"
557 for i in $(screen -ls | grep voltha-api-$NAME | awk '{print $1}'); do
558 sspin
559 (set -x; screen -X -S $i quit >>$LOG 2>&1) >>$LOG 2>&1
560 done
561 sspin "Remove port-forwards: voltha-ssh-$NAME$CEOL"
562 for i in $(screen -ls | grep voltha-ssh-$NAME | awk '{print $1}'); do
563 sspin
564 (set -x; screen -X -S $i quit >>$LOG 2>&1) >>$LOG 2>&1
565 done
566 sspin "Remove port-forwards: voltha-etcd-$NAME$CEOL"
567 for i in $(screen -ls | grep voltha-etcd-$NAME | awk '{print $1}'); do
568 sspin
569 (set -x; screen -X -S $i quit >>$LOG 2>&1) >>$LOG 2>&1
570 done
571 espin "$VERIFIED Remove port-forwards$CEOL"
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -0700572 exit
David Bainbridgeac7f8072019-08-01 22:15:33 +0000573fi
574
575if [ "$1" == "dump" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000576 LOG="dump-$NAME.log"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000577 TS=$(date -u +"%Y%m%dT%H%M%SZ")
David Bainbridge76514a02019-10-08 01:50:35 +0000578 if [ ! -z "$DUMP_FROM" ]; then
579 TS=$(echo $DUMP_FROM | sed -e 's/[:-]//g')
580 fi
David Bainbridgeac7f8072019-08-01 22:15:33 +0000581 WORK=$(mktemp -u -d)
David Bainbridge0774b232019-08-02 06:37:19 +0000582 DATA=$WORK/voltha-debug-dump-$NAME-$TS
David Bainbridgeac7f8072019-08-01 22:15:33 +0000583 mkdir -p $DATA
584 echo $TS > $LOG
David Bainbridge0774b232019-08-02 06:37:19 +0000585 echo -e "Capturing debug dump to voltha-debug-dump-$NAME-$TS.tgz"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000586 bspin - "Copy install log"
David Bainbridge0774b232019-08-02 06:37:19 +0000587 if [ -f install-$NAME.log ]; then
588 (set -x; cp install-$NAME.log $DATA/install-$NAME.log) >>$LOG 2>&1
David Bainbridgeac7f8072019-08-01 22:15:33 +0000589 espin - $VERIFIED
590 else
David Bainbridge0774b232019-08-02 06:37:19 +0000591 espin - "$NO_ENTRY Copy install log: install-$NAME.log not found"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000592 fi
593 bspin - "Dumping Kubernetes PODs"
594 (set -x; kubectl get --all-namespaces pods >> $DATA/all-pods.txt 2>&1) >>$LOG 2>&1
595 espin - $VERIFIED
596 bspin - "Dumping Kubernetes SERVICEs"
597 (set -x; kubectl get --all-namespaces svc >> $DATA/all-services.txt 2>&1) >>$LOG 2>&1
598 espin - $VERIFIED
599 bspin - "Dumping Kubernetes EVENTs"
600 (set -x; kubectl get --all-namespaces events >> $DATA/all-events.txt 2>&1) >>$LOG 2>&1
601 espin - $VERIFIED
602 bspin - "Dumping VOLTHA POD details"
Matteo Scandolodcd29f52019-10-07 15:42:42 -0700603 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 +0000604 SINCE=
605 if [ ! -z "$DUMP_FROM" ]; then
606 SINCE="--since-time=$DUMP_FROM"
607 fi
David Bainbridgeac7f8072019-08-01 22:15:33 +0000608 for POD in $PODS; do
David Bainbridge1f0655a2019-10-01 22:08:48 +0000609 NS=$(echo $POD | cut -d: -f1)
610 POD=$(echo $POD | cut -d: -f2)
David Bainbridgeac7f8072019-08-01 22:15:33 +0000611 sspin - "Dumping VOLTHA POD details: $POD$CEOL"
612 mkdir -p $DATA/$POD
David Bainbridge1f0655a2019-10-01 22:08:48 +0000613 (set -x; kubectl describe -n $NS $POD >> $DATA/$POD/describe.txt 2>&1) >>$LOG 2>&1
David Bainbridgeac7f8072019-08-01 22:15:33 +0000614 sspin - "Dumping VOLTHA POD details: $POD"
David Bainbridgecfd7ca12019-10-06 03:31:41 +0000615 (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 +0000616 sspin - "Dumping VOLTHA POD details: $POD"
David Bainbridgecfd7ca12019-10-06 03:31:41 +0000617 (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 +0000618 sspin - "Dumping VOLTHA POD details: $POD"
619 done
620 espin - "$VERIFIED Dumping VOLTHA POD details$CEOL"
621 bspin - "Dumping ETCD"
622 if [ "$(which etcdctl) X" != " X" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000623 (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 +0000624 espin - $VERIFIED
625 else
626 espin - "$NO_ENTRY Dumping ETCD: etcdctl command not available"
627 fi
David Bainbridge0774b232019-08-02 06:37:19 +0000628 bspin - "Creating compressed TAR: voltha-debug-dump-$NAME-$TS.tgz"
629 (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 +0000630 espin - $VERIFIED
631 bspin - "Cleanup"
632 (set -x; rm -rf $WORK) >>$LOG 2>&1
633 espin - $VERIFIED
David Bainbridge0774b232019-08-02 06:37:19 +0000634 bspin - "$(ls -l voltha-debug-dump-$NAME-$TS.tgz)"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000635 espin - $VERIFIED
636 exit
637fi
638
David Bainbridge0774b232019-08-02 06:37:19 +0000639LOG="install-$NAME.log"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000640date > $LOG
David Bainbridge0774b232019-08-02 06:37:19 +0000641echo "PORTS=$ONOS_API_PORT,$ONOS_SSH_PORT,$VOLTHA_API_PORT,$VOLTHA_SSH_PORT,$VOLTHA_ETCD_PORT" >> $LOG
David Bainbridgeac7f8072019-08-01 22:15:33 +0000642
643# Output install options to log
644echo "OPTIONS" >> $LOG
David Bainbridgeac7f8072019-08-01 22:15:33 +0000645for O in $ALL_OPTIONS; do
646 VAL=$(eval echo \$$O)
David Bainbridgeac7f8072019-08-01 22:15:33 +0000647 if [ ! -z "$VAL" ]; then
648 printf " %-30s = %s\n" $O $VAL >> $LOG
649 fi
650done
651
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -0700652helm_install() {
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700653 local INDENT=
654 if [ "$1" == "-" ]; then
655 INDENT=$1; shift
656 fi
657 local NAMESPACE=$1; shift
David Bainbridge0774b232019-08-02 06:37:19 +0000658 local INAME=$1; shift
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700659 local CHART=$1; shift
David Bainbridge90fd8e32019-08-21 23:32:47 +0000660 local CHART_VERSION=$1; shift
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700661 local MESSAGE=$*
662
David Bainbridge90fd8e32019-08-21 23:32:47 +0000663 if [ "$CHART_VERSION X" != " X" -a "$CHART_VERSION" != "latest" ]; then
664 CHART_VERSION="--version $CHART_VERSION"
665 else
666 CHART_VERSION=
667 fi
668
David Bainbridge99ac7a22019-08-31 02:26:43 +0000669 local CHART_ARGS=
670 if [ -r "${INAME}-values.yaml" ]; then
671 CHART_ARGS="-f ${INAME}-values.yaml"
672 fi
673
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700674 COUNT=$(expr 300 / 15)
675 bspin $INDENT $MESSAGE
David Bainbridge99ac7a22019-08-31 02:26:43 +0000676 (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 -0700677 SUCCESS=$?
678 while [ $SUCCESS -ne 0 ]; do
679 sspin $INDENT
680 COUNT=$(expr $COUNT - 1)
681 if [ $COUNT -eq 0 ]; then
David Bainbridge99ac7a22019-08-31 02:26:43 +0000682 (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 -0700683 COUNT=$(expr 300 / 15)
684 fi
685 sleep .15
686 done
687 espin $INDENT $VERIFIED
688}
689
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700690echo "INSTALL TYPE: $TYPE" >> $LOG
691
692bspin "Verify GOPATH"
693export GOPATH=$(pwd)
Test User3d7ad8e2019-07-03 06:15:44 +0000694mkdir -p $GOPATH/bin
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700695espin $VERIFIED
696
David Bainbridgee87067b2019-08-12 22:00:12 +0000697STIME=$(date +%s)
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700698if [ "$INSTALL_KUBECTL" == "no" ]; then
699 bspin "Skip kubectl install"
700 espin $NO_ENTRY
Test Userc13bdc92019-07-03 20:57:49 +0000701else
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700702 bspin "Verify kubectl $HELM"
703 if [ -x $GOPATH/bin/kubectl ]; then
704 espin $VERIFIED
705 else
706 espin $NOT_VERIFIED
707 bspin - "Download and install Kubernetes/kubectl $DOWNLOAD"
708 (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
709 (set -x; chmod 755 $GOPATH/bin/kubectl >>$LOG 2>&1) >>$LOG 2>&1
710 espin - $VERIFIED
711 fi
Test Userc13bdc92019-07-03 20:57:49 +0000712fi
David Bainbridgee87067b2019-08-12 22:00:12 +0000713if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +0000714 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +0000715fi
Test Userc13bdc92019-07-03 20:57:49 +0000716
David Bainbridgee87067b2019-08-12 22:00:12 +0000717STIME=$(date +%s)
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700718if [ "$DEPLOY_K8S" == "no" ]; then
719 bspin "Skip Kubernetes/Kind Deployment"
720 espin $NO_ENTRY
721else
Test Userba1e7e72019-07-10 22:27:54 +0000722 bspin "Verify Kubernetes/Kind $HELM"
723 if [ -x $GOPATH/bin/kind ]; then
724 espin $VERIFIED
725 else
726 espin $NOT_VERIFIED
727 bspin - "Download and install Kubernetes/kind $DOWNLOAD"
David Bainbridge9e2a6662019-07-11 17:07:57 +0000728 (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 +0000729 (set -x; chmod 755 $GOPATH/bin/kind >>$LOG 2>&1) >>$LOG 2>&1
730 espin - $VERIFIED
731 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700732fi
733
David Bainbridgee87067b2019-08-12 22:00:12 +0000734if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +0000735 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +0000736fi
737
738STIME=$(date +%s)
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700739if [ "$INSTALL_HELM" == "no" ]; then
740 bspin "Skip Helm Install"
741 espin $NO_ENTRY
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700742else
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700743 bspin "Verify Helm $HELM"
744 if [ -x $GOPATH/bin/helm ]; then
745 espin $VERIFIED
746 else
747 espin $NOT_VERIFIED
748 bspin - "Download and install Helm $DOWNLOAD"
David Bainbridgec6a6eb62019-10-18 22:50:07 +0000749 (set -x; curl -sSL https://git.io/get_helm.sh | DESIRED_VERSION=v2.14.3 USE_SUDO=false HELM_INSTALL_DIR=$GOPATH/bin bash >>$LOG 2>&1) >>$LOG 2>&1
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700750 espin - $VERIFIED
751 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700752fi
David Bainbridgee87067b2019-08-12 22:00:12 +0000753if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +0000754 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +0000755fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700756
David Bainbridgee87067b2019-08-12 22:00:12 +0000757STIME=$(date +%s)
Test Userb5712372019-07-03 21:52:17 +0000758bspin "Verify voltctl $HIGH_VOLTAGE"
Test User3d7ad8e2019-07-03 06:15:44 +0000759if [ -x $GOPATH/bin/voltctl ]; then
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700760 espin $VERIFIED
761else
762 espin $NOT_VERIFIED
David Bainbridge99ac7a22019-08-31 02:26:43 +0000763 bspin - "Download and install voltctl $DOWNLOAD"
Test Userba1e7e72019-07-10 22:27:54 +0000764 (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 +0000765 (set -x; chmod 755 $GOPATH/bin/voltctl >>$LOG 2>&1) >>$LOG 2>&1
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700766 espin - $VERIFIED
767fi
David Bainbridgee87067b2019-08-12 22:00:12 +0000768if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +0000769 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +0000770fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700771
772bspin "Verify command PATH"
Test Userba1e7e72019-07-10 22:27:54 +0000773export PATH=$GOPATH/bin:$PATH
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700774espin $VERIFIED
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700775
David Bainbridgee87067b2019-08-12 22:00:12 +0000776STIME=$(date +%s)
Test Userba1e7e72019-07-10 22:27:54 +0000777if [ "$DEPLOY_K8S" == "yes" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000778 HAVE=$(kind get clusters | grep -c voltha-$NAME)
Test Userba1e7e72019-07-10 22:27:54 +0000779 bspin "Verify Kubernetes/Kind Cluster"
780 sspin
781 if [ $HAVE -eq 0 ]; then
David Bainbridge491b1bd2019-07-11 17:53:11 +0000782 espin $NOT_VERIFIED
783 bspin - "Verify cluster configuration"
David Bainbridge0774b232019-08-02 06:37:19 +0000784 if [ ! -r ./$NAME-cluster.cfg ]; then
David Bainbridge491b1bd2019-07-11 17:53:11 +0000785 espin - $NOT_VERIFIED
David Bainbridge0774b232019-08-02 06:37:19 +0000786 bspin - "Download cluster configuration: $TYPE-cluster.cfg to $NAME-cluster.cfg $DOWNLOAD"
787 (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 -0700788 espin - $VERIFIED
789 else
790 espin - $VERIFIED
791 fi
David Bainbridge0774b232019-08-02 06:37:19 +0000792 kind create cluster --name voltha-$NAME --config $NAME-cluster.cfg
David Bainbridge491b1bd2019-07-11 17:53:11 +0000793 else
794 espin $VERIFIED
Test Userba1e7e72019-07-10 22:27:54 +0000795 fi
796
David Bainbridge0774b232019-08-02 06:37:19 +0000797 export KUBECONFIG="$(kind get kubeconfig-path --name="voltha-$NAME")"
Test Userba1e7e72019-07-10 22:27:54 +0000798 P="coredns-.* \
David Bainbridge0774b232019-08-02 06:37:19 +0000799 etcd-voltha-$NAME-control-plane \
Test Userba1e7e72019-07-10 22:27:54 +0000800 kindnet-.* \
David Bainbridge0774b232019-08-02 06:37:19 +0000801 kube-apiserver-voltha-$NAME-control-plane \
802 kube-controller-manager-voltha-$NAME-control-plane \
Test Userba1e7e72019-07-10 22:27:54 +0000803 kube-proxy-.* \
David Bainbridge0774b232019-08-02 06:37:19 +0000804 kube-scheduler-voltha-$NAME-control-plane"
Test Userba1e7e72019-07-10 22:27:54 +0000805
806 EXPECT=$(test "$TYPE" == "minimal" && echo "12" || echo "14")
David Bainbridge4f1b5562019-08-19 04:46:52 +0000807 wait_for_pods - "kube-system" $EXPECT "includes" -1 "Waiting for system PODs to start" $P
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700808fi
David Bainbridgee87067b2019-08-12 22:00:12 +0000809if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +0000810 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +0000811fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700812
David Bainbridgee87067b2019-08-12 22:00:12 +0000813STIME=$(date +%s)
David Bainbridge4c6289c2019-09-03 21:11:32 +0000814COUNT=$(count_pods "kube-system" ":Running:" "tiller-deploy-.*")
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700815bspin "Verify Helm"
Test Userba1e7e72019-07-10 22:27:54 +0000816if [ $COUNT -ne 1 ]; then
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700817 espin $NOT_VERIFIED
Test Userb5712372019-07-03 21:52:17 +0000818 echo -e "Configuring Helm $GEAR"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700819 if [ "$INSTALL_HELM" == "no" ]; then
820 bspin - "Skip Helm/Tiller Initialization"
821 espin - $NO_ENTRY
822 else
823 bspin - "Initialize Helm"
824 (set -x; helm init --upgrade >>$LOG 2>&1) >>$LOG 2>&1
825 espin - $VERIFIED
David Bainbridge4f1b5562019-08-19 04:46:52 +0000826 wait_for_pods - "kube-system" 1 "includes" -1 "Waiting for Tiller POD to start" "tiller-deploy-.*"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700827 fi
Test Userb5712372019-07-03 21:52:17 +0000828 bspin - "Add Google Incubator repository to Helm"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700829 (set -x; helm repo add incubator https://kubernetes-charts-incubator.storage.googleapis.com >>$LOG 2>&1) >>$LOG 2>&1
830 espin - $VERIFIED
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -0700831
Test Userba1e7e72019-07-10 22:27:54 +0000832 # HACK (sort-of) - the config for tiller is about to be patched, which will
833 # cause the tiller pod to be recreated. This can sometimes cause a timing
834 # issue with the "wait_for_pods" call on tiller as it may incorrectly
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -0700835 # identify the running/ready tiller pod that is soon to be terminated as
Test Userba1e7e72019-07-10 22:27:54 +0000836 # what it is waiting for. To avoid this issue we do a clean scale down and
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -0700837 # scale up of the pod so the script controlls when it should be expecting
Test Userba1e7e72019-07-10 22:27:54 +0000838 # things
839 (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 -0700840
Test Userb5712372019-07-03 21:52:17 +0000841 bspin - "Add Google Stable repository to Helm"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700842 (set -x; helm repo add stable https://kubernetes-charts.storage.googleapis.com >>$LOG 2>&1) >>$LOG 2>&1
843 espin - $VERIFIED
Test Userb5712372019-07-03 21:52:17 +0000844 bspin - "Add ONF repository to Helm"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700845 (set -x; helm repo add onf https://charts.opencord.org >>$LOG 2>&1) >>$LOG 2>&1
846 espin - $VERIFIED
Test Userb5712372019-07-03 21:52:17 +0000847 bspin - "Update Helm repository cache"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700848 (set -x; helm repo update >>$LOG 2>&1) >>$LOG 2>&1
849 espin - $VERIFIED
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -0700850
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700851 # Create and k8s service account so that Helm can create pods
Test Userb5712372019-07-03 21:52:17 +0000852 bspin - "Create Tiller ServiceAccount"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700853 (set -x; kubectl create serviceaccount --namespace kube-system tiller >>$LOG 2>&1) >>$LOG 2>&1
854 espin - $VERIFIED
Test Userb5712372019-07-03 21:52:17 +0000855 bspin - "Create Tiller ClusterRoleBinding"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700856 (set -x; kubectl create clusterrolebinding tiller-cluster-rule --clusterrole=cluster-admin --serviceaccount=kube-system:tiller >>$LOG 2>&1) >>$LOG 2>&1
857 espin - $VERIFIED
Test Userb5712372019-07-03 21:52:17 +0000858 bspin - "Update Tiller Manifest"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700859 (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 +0000860
861 # HACK (sort-of) - part to, spin it back up
862 (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 -0700863 espin - $VERIFIED
864else
865 espin $VERIFIED
David Bainbridge46505fb2019-10-01 21:13:20 +0000866 if [ "$UPDATE_HELM_REPOS" == "yes" ]; then
867 bspin - "Update Helm repository cache"
868 (set -x; helm repo update >>$LOG 2>&1) >>$LOG 2>&1
869 espin - $VERIFIED
870 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700871fi
David Bainbridge4f1b5562019-08-19 04:46:52 +0000872wait_for_pods - "kube-system" 1 "includes" -1 "Waiting for Tiller POD to start" "tiller-deploy-.*"
David Bainbridgee87067b2019-08-12 22:00:12 +0000873if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +0000874 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +0000875fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700876
David Bainbridgee87067b2019-08-12 22:00:12 +0000877STIME=$(date +%s)
David Bainbridge0774b232019-08-02 06:37:19 +0000878bspin "Verify Helm values file: $NAME-values.yaml"
879if [ ! -r "./$NAME-values.yaml" ]; then
Test Userba1e7e72019-07-10 22:27:54 +0000880 espin $NOT_VERIFIED
David Bainbridge0774b232019-08-02 06:37:19 +0000881 bspin - "Download Helm values file: $TYPE-values.yaml to $NAME-values.yaml $DOWNLOAD"
882 (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 +0000883 espin - $VERIFIED
884else
885 espin $VERIFIED
886fi
David Bainbridgee87067b2019-08-12 22:00:12 +0000887if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +0000888 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +0000889fi
Test Userba1e7e72019-07-10 22:27:54 +0000890
David Bainbridge99ac7a22019-08-31 02:26:43 +0000891STIME=$(date +%s)
892bspin "Verify or download chart specific values files $DOWNLOAD"
893VALUES_FILES="monkey-values.yaml"
894for i in $VALUES_FILES; do
895 if [ ! -r ./$i ]; then
896 (set -x; curl -o ./$i -sSL https://raw.githubusercontent.com/ciena/kind-voltha/master/$i >>$LOG 2>&1) >>$LOG 2>&1
897 fi
898done
899espin $VERIFIED
900if [ "$WITH_TIMINGS" == "yes" ]; then
901 printtime $(expr $(date +%s) - $STIME)
902fi
903
904if [ "$WITH_CHAOS" == "yes" ]; then
905 bspin "Verify or clone kube-monkey helm chart $DOWNLOAD"
906 if [ -r ./kube-monkey ]; then
907 espin $VERIFIED
908 else
909 espin $NOT_VERIFIED
910 bspin - "GIT clone kube-monkey"
911 (set -x; git clone https://github.com/asobti/kube-monkey kube-monkey >>$LOG 2>&1) >>$LOG 2>&1
912 espin - $VERIFIED
913 fi
914fi
915
Test Userba1e7e72019-07-10 22:27:54 +0000916if [ "$JUST_K8S" == "yes" ]; then
917 echo "Environment deployed, not deploying VOLTHA artifacts as requested. Good bye."
918 echo ""
919 echo "Please issue the following commands in your terminal to ensure that you" | tee -a $LOG
920 echo "are accessing the correct Kubernetes/Kind cluster as well as have the " | tee -a $LOG
921 echo "tools required by VOLTHA in your command path. " | tee -a $LOG
922 echo "" | tee -a $LOG
923 echo -en $BOLD
924 if [ $DEPLOY_K8S == "yes" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000925 echo "export KUBECONFIG=\"\$(./bin/kind get kubeconfig-path --name=\"voltha-$NAME\")\"" | tee -a $LOG
Test Userba1e7e72019-07-10 22:27:54 +0000926 fi
927 echo "export PATH=$GOPATH/bin:\$PATH" | tee -a $LOG
928 echo -en $NORMAL
929 echo "" | tee -a $LOG
930 echo "Thank you for choosing kind-voltha for you quick cluster needs." | tee -a $LOG
931 exit 0
932fi
933
David Bainbridgee87067b2019-08-12 22:00:12 +0000934STIME=$(date +%s)
Test Userb5712372019-07-03 21:52:17 +0000935bspin "Verify ETCD Operator $OLD_KEY"
Test User7d866122019-07-09 17:52:35 +0000936if [ $(helm list --deployed --short --namespace voltha "^etcd-operator\$" | wc -l) -ne 1 ]; then
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -0700937 espin $NOT_VERIFIED
David Bainbridge90fd8e32019-08-21 23:32:47 +0000938 helm_install - voltha etcd-operator stable/etcd-operator latest "Install ETCD Operator"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700939else
940 espin $VERIFIED
941fi
Test User01ed0642019-07-03 20:17:06 +0000942EXPECT=$(test "$TYPE" == "minimal" && echo "1" || echo "3")
David Bainbridge4f1b5562019-08-19 04:46:52 +0000943wait_for_pods - "voltha" $EXPECT "includes" -1 "Waiting for ETCD Operator to start" "etcd-operator-.*"
David Bainbridgee87067b2019-08-12 22:00:12 +0000944if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +0000945 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +0000946fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700947
David Bainbridgee87067b2019-08-12 22:00:12 +0000948STIME=$(date +%s)
David Bainbridgeb270c202019-07-26 01:44:42 +0000949if [ $WITH_ONOS == "yes" ]; then
950 bspin "Verify ONOS installed $BIRD"
951 if [ $(helm list --deployed --short --namespace default "^onos\$" | wc -l) -ne 1 ]; then
952 espin $NOT_VERIFIED
David Bainbridge90fd8e32019-08-21 23:32:47 +0000953 EXTRA_HELM_FLAGS="$SET_TAG $EXTRA_HELM_FLAGS" helm_install - default onos onf/onos latest "Install ONOS"
David Bainbridgeb270c202019-07-26 01:44:42 +0000954 else
955 espin $VERIFIED
956 fi
David Bainbridge4f1b5562019-08-19 04:46:52 +0000957 wait_for_pods - "default" 1 "includes" -1 "Waiting for ONOS to start" "onos-.*"
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -0700958
David Bainbridgeb270c202019-07-26 01:44:42 +0000959 bspin - "Forward ONOS API port $FORWARD"
David Bainbridge0774b232019-08-02 06:37:19 +0000960 for i in $(screen -ls | grep onos-ui-$NAME | awk '{print $1}'); do
David Bainbridge82bd1212019-07-29 19:19:31 +0000961 (set -x; screen -X -S $i quit >>$LOG 2>&1) >>$LOG 2>&1
962 done
David Bainbridge0774b232019-08-02 06:37:19 +0000963 (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 +0000964 espin - $VERIFIED
965 bspin - "Forward ONOS SSH port $FORWARD"
David Bainbridge0774b232019-08-02 06:37:19 +0000966 for i in $(screen -ls | grep onos-ssh-$NAME | awk '{print $1}'); do
David Bainbridge82bd1212019-07-29 19:19:31 +0000967 (set -x; screen -X -S $i quit >>$LOG 2>&1) >>$LOG 2>&1
968 done
David Bainbridge2b19e832019-08-16 02:40:53 +0000969
970
David Bainbridge0774b232019-08-02 06:37:19 +0000971 (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 +0000972 espin - $VERIFIED
David Bainbridged31d6122019-08-13 19:37:59 +0000973 bspin - "Verify or download ONOS configuration support files $DOWNLOAD"
David Bainbridge2b19e832019-08-16 02:40:53 +0000974 ONOS_FILES="olt-onos-enableExtraneousRules.json olt-onos-olt-settings.json onos-aaa.json \
David Bainbridge90fd8e32019-08-21 23:32:47 +0000975 onos-dhcpl2relay.json onos-kafka.json onos-sadis-sample.json"
David Bainbridged31d6122019-08-13 19:37:59 +0000976 (set -x; mkdir -p ./onos-files >>$LOG 2>&1) >>$LOG 2>&1
David Bainbridge2b19e832019-08-16 02:40:53 +0000977 for i in $ONOS_FILES; do
David Bainbridged31d6122019-08-13 19:37:59 +0000978 if [ ! -r ./onos-files/$i ]; then
979 (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
980 fi
981 done
Test Userba1e7e72019-07-10 22:27:54 +0000982 espin - $VERIFIED
David Bainbridge27790d62019-08-13 22:43:19 +0000983
984 if [ $INSTALL_ONOS_APPS == "yes" ]; then
985 bspin - "Installing custom ONOS applications"
986 if [ -x onos-files/onos-apps -a $(ls -1 onos-files/onos-apps/*.oar 2>/dev/null | wc -l) -gt 0 ]; then
987 for OAR in $(ls -1 onos-files/onos-apps/*.oar); do
988 sspin - "Installing custom ONOS applications - $OAR$CEOL"
David Bainbridge2b19e832019-08-16 02:40:53 +0000989 override_onos_app $OAR
David Bainbridge27790d62019-08-13 22:43:19 +0000990 done
991 espin - "$VERIFIED Installing custom ONOS applications$CEOL"
992 else
993 espin - "$NOT_VERIFIED Installing custom ONOS applications - None Found"
994 fi
995 fi
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -0700996
David Bainbridge2b19e832019-08-16 02:40:53 +0000997 push_onos_config "Push ONOS Kafka Configuration" "network/configuration/apps/org.opencord.kafka" "onos-files/onos-kafka.json"
998 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 +0000999 push_onos_config "Enable VOLTHA ONOS DHCP provisioning" "configuration/org.opencord.olt.impl.Olt" "onos-files/olt-onos-olt-settings.json"
1000 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 +00001001 if [ -f onos-files/onos-sadis.json ]; then
1002 push_onos_config "[optional] Push ONOS SADIS Configuration" "network/configuration/apps/org.opencord.sadis" "onos-files/onos-sadis.json"
1003 elif [ "$CONFIG_SADIS" == "yes" ]; then
David Bainbridge90fd8e32019-08-21 23:32:47 +00001004 SADIS_CFG=onos-files/onos-sadis-sample.json
David Bainbridge2b19e832019-08-16 02:40:53 +00001005 push_onos_config "[optional] Push ONOS SADIS Configuration" "network/configuration/apps/org.opencord.sadis" "$SADIS_CFG"
1006 fi
Test Userba1e7e72019-07-10 22:27:54 +00001007fi
David Bainbridgee87067b2019-08-12 22:00:12 +00001008if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +00001009 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +00001010fi
Test Userba1e7e72019-07-10 22:27:54 +00001011
David Bainbridgee87067b2019-08-12 22:00:12 +00001012STIME=$(date +%s)
Test Userb5712372019-07-03 21:52:17 +00001013bspin "Verify VOLTHA installed $HIGH_VOLTAGE"
Test User7d866122019-07-09 17:52:35 +00001014if [ $(helm list --deployed --short --namespace voltha "^voltha\$" | wc -l) -ne 1 ]; then
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001015 espin $NOT_VERIFIED
David Bainbridge90fd8e32019-08-21 23:32:47 +00001016 helm_install - voltha voltha $VOLTHA_CHART $VOLTHA_CHART_VERSION "Install VOLTHA Core"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001017else
1018 espin $VERIFIED
1019fi
Test Userba1e7e72019-07-10 22:27:54 +00001020
David Bainbridge90fd8e32019-08-21 23:32:47 +00001021VOLTHA="voltha-ofagent-.* \
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001022 ro-core.* \
1023 rw-core.* \
1024 voltha-api-server-.* \
1025 voltha-cli-server-.* \
1026 voltha-etcd-cluster-.* \
1027 voltha-kafka-.* \
1028 voltha-zookeeper-.*"
David Bainbridge46505fb2019-10-01 21:13:20 +00001029#EXPECT=$(test "$TYPE" == "minimal" && echo "8" || echo "11")
Test User01ed0642019-07-03 20:17:06 +00001030EXPECT=$(test "$TYPE" == "minimal" && echo "9" || echo "11")
David Bainbridge4f1b5562019-08-19 04:46:52 +00001031wait_for_pods - "voltha" $EXPECT "includes" -1 "Waiting for VOLTHA Core to start" $VOLTHA
David Bainbridgee87067b2019-08-12 22:00:12 +00001032if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +00001033 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +00001034fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001035
David Bainbridge46505fb2019-10-01 21:13:20 +00001036if [ "$WITH_ADAPTERS" == "yes" ]; then
1037 STIME=$(date +%s)
1038 EXPECT=0
1039 echo -e "Verify Adapters $PLUG"
1040 if [ "$WITH_SIM_ADAPTERS" == "yes" ]; then
1041 bspin - "Verify Simulated Adapters installed"
1042 if [ $(helm list --deployed --short --namespace voltha "^sim\$" | wc -l) -ne 1 ]; then
1043 espin - $NOT_VERIFIED
1044 helm_install - voltha sim $VOLTHA_ADAPTER_SIM_CHART $VOLTHA_ADAPTER_SIM_CHART_VERSION "Install Simulated Adapters"
1045 else
1046 espin - $VERIFIED
1047 fi
1048 EXPECT=$(expr $EXPECT + 2)
1049 fi
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001050
David Bainbridge46505fb2019-10-01 21:13:20 +00001051 if [ "$WITH_OPEN_ADAPTERS" == "yes" ]; then
1052 bspin - "Verify OpenOLT Adapter installed"
1053 if [ $(helm list --deployed --short --namespace voltha "^open-olt\$" | wc -l) -ne 1 ]; then
1054 espin - $NOT_VERIFIED
1055 helm_install - voltha open-olt $VOLTHA_ADAPTER_OPEN_OLT_CHART $VOLTHA_ADAPTER_OPEN_OLT_CHART_VERSION "Install OpenOLT Adapter"
1056 else
1057 espin - $VERIFIED
1058 fi
1059 bspin - "Verify OpenONU Adapter installed"
1060 if [ $(helm list --deployed --short --namespace voltha "^open-onu\$" | wc -l) -ne 1 ]; then
1061 espin - $NOT_VERIFIED
1062 helm_install - voltha open-onu $VOLTHA_ADAPTER_OPEN_ONU_CHART $VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION "Install OpenONU Adapter"
1063 else
1064 espin - $VERIFIED
1065 fi
1066 EXPECT=$(expr $EXPECT + 2)
1067 fi
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001068
David Bainbridge46505fb2019-10-01 21:13:20 +00001069 ADAPTERS="adapter-.*"
1070 wait_for_pods - "voltha" $EXPECT "includes" -1 "Waiting for adapters to start" $ADAPTERS
1071 if [ "$WITH_TIMINGS" == "yes" ]; then
1072 printtime $(expr $(date +%s) - $STIME)
1073 fi
David Bainbridgee87067b2019-08-12 22:00:12 +00001074fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001075
Test User7d866122019-07-09 17:52:35 +00001076if [ $WITH_BBSIM == "yes" ]; then
David Bainbridgee87067b2019-08-12 22:00:12 +00001077 STIME=$(date +%s)
Test User7d866122019-07-09 17:52:35 +00001078 echo -e "Verify BBSIM $PLUG"
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001079 bspin - "Verify BBSIM Installed"
Test User7d866122019-07-09 17:52:35 +00001080 if [ $(helm list --deployed --short --namespace voltha "^bbsim\$" | wc -l) -ne 1 ]; then
1081 espin - $NOT_VERIFIED
David Bainbridge90fd8e32019-08-21 23:32:47 +00001082 helm_install - voltha bbsim $VOLTHA_BBSIM_CHART $VOLTHA_BBSIM_CHART_VERSION "Install BBSIM"
Test User7d866122019-07-09 17:52:35 +00001083 else
1084 espin - $VERIFIED
1085 fi
David Bainbridge4f1b5562019-08-19 04:46:52 +00001086 wait_for_pods - "voltha" 1 "includes" -1 "Waiting for BBSIM to start" "bbsim-.*"
David Bainbridgee87067b2019-08-12 22:00:12 +00001087 if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +00001088 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +00001089 fi
Test User7d866122019-07-09 17:52:35 +00001090fi
1091
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001092if [ $WITH_RADIUS == "yes" ]; then
David Bainbridgee87067b2019-08-12 22:00:12 +00001093 STIME=$(date +%s)
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001094 echo -e "Verify RADIUS $LOCK"
1095 bspin - "Verify RADIUS Installed"
1096 if [ $(helm list --deployed --short --namespace voltha "^radius\$" | wc -l) -ne 1 ]; then
1097 espin - $NOT_VERIFIED
David Bainbridge90fd8e32019-08-21 23:32:47 +00001098 helm_install - voltha radius onf/freeradius latest "Install RADIUS"
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001099 else
1100 espin - $VERIFIED
1101 fi
David Bainbridge4f1b5562019-08-19 04:46:52 +00001102 wait_for_pods - "voltha" 1 "includes" -1 "Waiting for RADIUS to start" "radius-.*"
David Bainbridgee87067b2019-08-12 22:00:12 +00001103 if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +00001104 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +00001105 fi
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001106fi
1107
David Bainbridgee87067b2019-08-12 22:00:12 +00001108STIME=$(date +%s)
Test Userb5712372019-07-03 21:52:17 +00001109bspin - "Forward VOLTHA API port $FORWARD"
David Bainbridge0774b232019-08-02 06:37:19 +00001110for i in $(screen -ls | grep voltha-api-$NAME | awk '{print $1}'); do
David Bainbridge82bd1212019-07-29 19:19:31 +00001111 (set -x; screen -X -S $i quit >>$LOG 2>&1) >>$LOG 2>&1
1112done
David Bainbridge0774b232019-08-02 06:37:19 +00001113(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 -07001114espin - $VERIFIED
Test Userb5712372019-07-03 21:52:17 +00001115bspin - "Forward VOLTHA SSH port $FORWARD"
David Bainbridge0774b232019-08-02 06:37:19 +00001116for i in $(screen -ls | grep voltha-ssh-$NAME | awk '{print $1}'); do
David Bainbridge82bd1212019-07-29 19:19:31 +00001117 (set -x; screen -X -S $i quit >>$LOG 2>&1) >>$LOG 2>&1
1118done
David Bainbridge0774b232019-08-02 06:37:19 +00001119(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 -07001120espin - $VERIFIED
David Bainbridgeac7f8072019-08-01 22:15:33 +00001121bspin - "Forward VOLTHA ETCD port $FORWARD"
David Bainbridge0774b232019-08-02 06:37:19 +00001122for i in $(screen -ls | grep voltha-etcd-$NAME | awk '{print $1}'); do
David Bainbridgeac7f8072019-08-01 22:15:33 +00001123 (set -x; screen -X -S $i quit >>$LOG 2>&1) >>$LOG 2>&1
1124done
David Bainbridge0774b232019-08-02 06:37:19 +00001125(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 +00001126espin - $VERIFIED
David Bainbridgee87067b2019-08-12 22:00:12 +00001127if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +00001128 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +00001129fi
Test User3d7ad8e2019-07-03 06:15:44 +00001130
David Bainbridgeb270c202019-07-26 01:44:42 +00001131if [ $WITH_ONOS == "yes" -a $WITH_RADIUS == "yes" ]; then
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001132 bspin "Configure ONOS RADIUS Connection $GEAR"
David Bainbridge2b19e832019-08-16 02:40:53 +00001133 (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 +00001134 espin $VERIFIED
1135fi
1136
David Bainbridge99ac7a22019-08-31 02:26:43 +00001137if [ "$WITH_CHAOS" == "yes" ]; then
1138 STIME=$(date +%s)
1139 echo -e "Verify kube-monkey $LOCK"
1140 bspin - "Verify kube-monkey Installed"
1141 if [ $(helm list --deployed --short --namespace kube-monkey "^monkey\$" | wc -l) -ne 1 ]; then
1142 espin - $NOT_VERIFIED
1143 helm_install - kube-monkey monkey ./kube-monkey/helm/kubemonkey latest "Install Chaos Monkey"
1144 else
1145 espin - $VERIFIED
1146 fi
1147 wait_for_pods - "kube-monkey" 1 "includes" -1 "Waiting for Chaos to start" "monkey-.*"
1148 if [ "$WITH_TIMINGS" == "yes" ]; then
1149 printtime $(expr $(date +%s) - $STIME)
1150 fi
1151fi
1152
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001153bspin "Create voltctl configuration file"
Test User3d7ad8e2019-07-03 06:15:44 +00001154(set -x; mkdir -p $HOME/.volt >>$LOG 2>&1) >>$LOG 2>&1
David Bainbridge0774b232019-08-02 06:37:19 +00001155(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 +00001156espin $VERIFIED
Test User08ebbd92019-07-03 17:15:39 +00001157
David Bainbridge0774b232019-08-02 06:37:19 +00001158if [ ! -f "$NAME-env.sh" ]; then
1159 touch $NAME-env.sh
David Bainbridgeb07fdf72019-07-29 22:51:40 +00001160fi
1161
David Bainbridge596f30d2019-07-30 17:07:59 +00001162for O in $ALL_OPTIONS; do
1163 VAL=$(eval echo \$$O)
David Bainbridge0774b232019-08-02 06:37:19 +00001164 if [ ! -z "$VAL" -a $(grep -c "^export $O=" $NAME-env.sh) -eq 0 ]; then
1165 echo "export $O=\"$(eval echo \$$O)\"" >> $NAME-env.sh
David Bainbridgeb07fdf72019-07-29 22:51:40 +00001166 fi
1167done
1168
David Bainbridge0774b232019-08-02 06:37:19 +00001169if [ $DEPLOY_K8S == "yes" -a $(grep -c "^export KUBECONFIG=" $NAME-env.sh) -eq 0 ]; then
1170 echo "export KUBECONFIG=\"$(./bin/kind get kubeconfig-path --name=voltha-$NAME)\"" >> $NAME-env.sh
David Bainbridgeb07fdf72019-07-29 22:51:40 +00001171fi
1172
David Bainbridge0774b232019-08-02 06:37:19 +00001173if [ $(grep -c "^export VOLTCONFIG=" $NAME-env.sh) -eq 0 ]; then
1174 echo "export VOLTCONFIG=\"$HOME/.volt/config-$NAME\"" >> $NAME-env.sh
David Bainbridgeb07fdf72019-07-29 22:51:40 +00001175fi
1176
David Bainbridge0774b232019-08-02 06:37:19 +00001177if [ $(grep -c "^export PATH=" $NAME-env.sh) -eq 0 ]; then
1178 echo "export PATH=\"$GOPATH/bin:\$PATH\"" >> $NAME-env.sh
David Bainbridgeb07fdf72019-07-29 22:51:40 +00001179fi
1180
Test User7d866122019-07-09 17:52:35 +00001181echo ""
Test User08ebbd92019-07-03 17:15:39 +00001182echo "Please issue the following commands in your terminal to ensure that you" | tee -a $LOG
1183echo "are accessing the correct Kubernetes/Kind cluster as well as have the " | tee -a $LOG
1184echo "tools required by VOLTHA in your command path. " | tee -a $LOG
1185echo "" | tee -a $LOG
Test User7d866122019-07-09 17:52:35 +00001186echo -en $BOLD
Test Userba1e7e72019-07-10 22:27:54 +00001187if [ $DEPLOY_K8S == "yes" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +00001188 echo "export KUBECONFIG=\"\$(./bin/kind get kubeconfig-path --name=\"voltha-$NAME\")\"" | tee -a $LOG
Test Userba1e7e72019-07-10 22:27:54 +00001189fi
David Bainbridge0774b232019-08-02 06:37:19 +00001190echo "export VOLTCONFIG=\"$HOME/.volt/config-$NAME\"" | tee -a $LOG
Test Userba1e7e72019-07-10 22:27:54 +00001191echo "export PATH=$GOPATH/bin:\$PATH" | tee -a $LOG
Test User7d866122019-07-09 17:52:35 +00001192echo -en $NORMAL
Test User08ebbd92019-07-03 17:15:39 +00001193echo "" | tee -a $LOG
1194echo "Thank you for choosing kind-voltha for you quick cluster needs." | tee -a $LOG
1195
David Bainbridge712afb82019-08-14 19:55:58 +00001196if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridgef858a022019-08-14 21:25:11 +00001197 echo -e "$CLOCK ${BOLD}TOTAL: $(duration $(expr $(date +%s) - $TOTAL_START_TIME))${NORMAL}"
David Bainbridge712afb82019-08-14 19:55:58 +00001198fi