blob: 7ca7b0d6cf1aef27c1f6fd429d18155373c7bb41 [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 ONOS_API_PORT=${ONOS_API_PORT:-$(echo $VALUES | cut -d, -f1)}
200 ONOS_SSH_PORT=${ONOS_SSH_PORT:-$(echo $VALUES | cut -d, -f2)}
201 VOLTHA_API_PORT=${VOLTHA_API_PORT:-$(echo $VALUES | cut -d, -f3)}
202 VOLTHA_SSH_PORT=${VOLTHA_SSH_PORT:-$(echo $VALUES | cut -d, -f4)}
203 VOLTHA_ETCD_PORT=${VOLTHA_ETCD_PORT:-$(echo $VALUES | cut -d, -f5)}
Test User01ed0642019-07-03 20:17:06 +0000204fi
205
David Bainbridge0774b232019-08-02 06:37:19 +0000206PORTTMP=$(mktemp -u)
207cat .voltha/ports | grep -v $NAME > $PORTTMP
208echo "$NAME=$ONOS_API_PORT,$ONOS_SSH_PORT,$VOLTHA_API_PORT,$VOLTHA_SSH_PORT,$VOLTHA_ETCD_PORT" >> $PORTTMP
209cp $PORTTMP .voltha/ports
210rm -f $PORTTMP
211
David Bainbridge27790d62019-08-13 22:43:19 +0000212export ONOS_API_PORT ONOS_SSH_PORT
David Bainbridge01294952019-07-30 19:33:45 +0000213
Test Userd87942b2019-07-03 07:20:24 +0000214IDX=1
David Bainbridgee87067b2019-08-12 22:00:12 +0000215CLOCK="TIME:"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000216SPIN_PARTS=
217NOT_VERIFIED=
David Bainbridgef858a022019-08-14 21:25:11 +0000218THEX=
219BUILD=
220CROSS=
221ENTER=
David Bainbridge38dc1e82019-08-12 15:18:45 +0000222VERIFIED=
223HELM=
224OLD_KEY=
225BIRD=
226HIGH_VOLTAGE=
227PLUG=
228RESTART=
229FORWARD=
230INSTALL=
231STOP=
232GO=
233DOWNLOAD=
234GEAR=
235NO_ENTRY=
236LOCK=
237
238if [ $FANCY -eq 1 ]; then
239 SPIN_PARTS="\
240 \xe2\xa2\x8e\xe2\xa1\xb0 \
241 \xe2\xa2\x8e\xe2\xa1\xa1 \
242 \xe2\xa2\x8e\xe2\xa1\x91 \
243 \xe2\xa2\x8e\xe2\xa0\xb1 \
244 \xe2\xa0\x8e\xe2\xa1\xb1 \
245 \xe2\xa2\x8a\xe2\xa1\xb1 \
246 \xe2\xa2\x8c\xe2\xa1\xb1 \
247 \xe2\xa2\x86\xe2\xa1\xb1 \
248 "
David Bainbridgee87067b2019-08-12 22:00:12 +0000249 CLOCK="\xe2\x8f\xb1"
David Bainbridgef858a022019-08-14 21:25:11 +0000250 THEX="${RED}${BOLD}\xe2\x9c\x97\x20${NORMAL}"
251 ENTER="${YELLOW}${BOLD}\xe2\x8e\x86${NORMAL}"
252 CROSS="${YELLOW}${BOLD}\xe2\x9c\x9a${NORMAL}"
253 BUILD="${YELLOW}${BOLD}\xf0\x9f\x8f\x97${NORMAL}"
254 NOT_VERIFIED="$BUILD"
255 VERIFIED="${GREEN}${BOLD}\xe2\x9c\x93\x20${NORMAL}"
256 HELM="${BLUE}${BOLD}\xE2\x8E\x88${NORMAL}"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000257 OLD_KEY="\xF0\x9F\x97\x9D"
258 BIRD="\xF0\x9F\x90\xA6"
259 HIGH_VOLTAGE="\xE2\x9A\xA1"
260 PLUG="\xF0\x9F\xa7\xa9"
261 RESTART="\xf0\x9f\x94\x84"
262 FORWARD="\xE2\x87\xA8"
263 INSTALL="\xF0\x9F\x8F\x97"
264 STOP="\xf0\x9f\x9b\x91"
265 GO="\xf0\x9f\x9a\x80"
266 DOWNLOAD="\xf0\x9f\x93\xa5"
267 GEAR="\xe2\x9a\x99"
268 NO_ENTRY="\xe2\x9b\x94"
269 LOCK="\xf0\x9f\x94\x92"
270fi
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700271
David Bainbridge712afb82019-08-14 19:55:58 +0000272duration() {
David Bainbridgee87067b2019-08-12 22:00:12 +0000273 local h=$(expr $1 / 3600)
274 local m=$(expr $1 % 3600 / 60)
275 local s=$(expr $1 % 60)
276 local t=""
277
278 if [ $h -gt 0 ]; then
279 t="$t${h}h"
280 fi
281 if [ $m -gt 0 ]; then
282 t="$t${m}m"
283 fi
David Bainbridge712afb82019-08-14 19:55:58 +0000284 echo "$t${s}s"
285}
286
287printtime() {
288 local INDENT=
289 if [ "$1" == "-" ]; then
290 INDENT=" "
291 shift
292 fi
293 echo -e "$INDENT $CLOCK $(duration $1)"
David Bainbridgee87067b2019-08-12 22:00:12 +0000294}
295
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700296bspin() {
Test Userd87942b2019-07-03 07:20:24 +0000297 IDX=1
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700298 local INDENT=
299 if [ "$1" == "-" ]; then
300 INDENT=" "
301 shift
302 fi
David Bainbridge38dc1e82019-08-12 15:18:45 +0000303 if [ $FANCY -eq 0 ]; then
304 LINE=$(echo $* | sed -e 's/[\s+-]//g')
305 if [ "$LINE X" == " X" ]; then
306 return
307 fi
308 echo -e "$CIVIS$INDENT$*"
309 else
310 echo -en "$CIVIS$INDENT $*"
311 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700312}
313
314sspin() {
315 local INDENT=
316 if [ "$1" == "-" ]; then
317 INDENT=" "
318 shift
319 fi
David Bainbridge38dc1e82019-08-12 15:18:45 +0000320 if [ $FANCY -eq 0 ]; then
321 LINE=$(echo $* | sed -e 's/[\s+-]//g')
322 if [ "$LINE X" == " X" ]; then
323 return
324 fi
325 echo -e "$INDENT$*"
326 else
327 C=$(echo $SPIN_PARTS | cut '-d ' -f $IDX)
328 echo -en "\r$INDENT$C $*"
329 IDX=$(expr $IDX + 1)
330 if [ $IDX -gt 8 ]; then
331 IDX=1
332 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700333 fi
334}
335
336espin() {
337 local INDENT=
338 if [ "$1" == "-" ]; then
339 INDENT=" "
340 shift
341 fi
David Bainbridge38dc1e82019-08-12 15:18:45 +0000342 if [ $FANCY -eq 0 ]; then
343 LINE=$(echo $* | sed -e 's/[\s+-]//g')
344 if [ "$LINE X" == " X" ]; then
345 return
346 fi
347 echo -e "$INDENT$*"
348 else
349 echo -e "\r$INDENT$*$CNORM"
350 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700351}
352
David Bainbridgeac7f8072019-08-01 22:15:33 +0000353if [ "$1" == "get" -a "$2" == "voltconfig" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000354 echo "$HOME/.volt/config-$NAME"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000355 exit
356fi
357
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -0700358if [ $# -ne 1 -o $(echo ":up:down:dump:" | grep -c ":$1:") -ne 1 ]; then
David Bainbridgeac7f8072019-08-01 22:15:33 +0000359 >&2 echo "What wouild you like to do today:"
360 >&2 echo " up - bring up voltha"
361 >&2 echo " down - tear down voltha"
362 >&2 echo " dump - create a debug dump of running system"
363 exit 1
364fi
365
David Bainbridge4f1b5562019-08-19 04:46:52 +0000366push_onos_config() {
367 local MSG=$1
368 local RESOURCE=$2
369 local DATA=$3
370
371 bspin - "$MSG $GEAR"
372 while true; do
373 (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
374 if [ $? -eq 0 ]; then
375 break
376 fi
377 sleep .2
378 sspin -
379 done
380 espin - $VERIFIED
381}
382
383override_onos_app() {
384 local APP=$1
385 local NAME=$(basename $APP | sed -e 's/^[0-9][0-9]*-//g' -e 's/-.*$//g')
386 while true; do
387 sspin -
388 # Attempt to delete old version (if it exists)
389 (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
390 sspin -
391 if [ $? -ne 0 ]; then
392 continue
393 fi
394 (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
395 if [ $? -eq 0 ]; then
396 break
397 fi
398 sleep .2
399 done
400}
401
402activate_onos_app() {
403 local MSG="$1"
404 local APP=$2
405
406 bspin - "$MSG $GO"
407 while true; do
408 sspin -
409 (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
410 if [ $? -eq 0 ]; then
411 break
412 fi
413 sleep .2
414 done
415 espin - "$VERIFIED"
416}
417
418count_pods() {
419 local NAMESPACE=$1; shift
420 if [ "$NAMESPACE" == "all-namespaces" ]; then
421 NAMESPACE="--all-namespaces"
422 else
423 NAMESPACE="-n $NAMESPACE"
424 fi
425 echo "$NAMESPACE" > /tmp/t
426 local STATES=$1; shift
427 echo "$STATES" >> /tmp/t
428 local PODS=$(kubectl get $NAMESPACE pod -o go-template="{{range .items}}{{.metadata.name}}/{{.status.phase}}/_{{range .status.containerStatuses}}{{.ready}}_{{end}} {{end}}")
429 local COUNT=0
430 local PATTERNS="$*"
431 for POD in $PODS; do
432 local NAME=$(echo $POD | cut -d/ -f 1)
433 local STATE=$(echo $POD | cut -d/ -f 2)
434 local CONTAINERS=$(echo $POD | cut -d/ -f 3 | sed -e 's/_/ /g')
435 if [ "$STATES" == "*" -o $(echo "$STATES" | grep -c ":$STATE:") -ne 0 ]; then
436 echo "IN WITH $POD" >> /tmp/t
437 local TOTAL=$(echo $CONTAINERS | wc -w)
438 local FOUND=$(echo $CONTAINERS | grep -o true | wc -l)
439 if [ $TOTAL -eq $FOUND ]; then
440 for PATTERN in $PATTERNS; do
441 echo "TEST $PATTERN AGAINST $NAME" >> /tmp/t
442 if [[ $NAME =~ $PATTERN ]]; then
443 echo "COUNT $NAME" >> /tmp/t
444 COUNT=$(expr $COUNT + 1)
445 break
446 fi
447 done
448 fi
449 fi
450 done
451 echo $COUNT >> /tmp/t
452 echo $COUNT
453}
454
455wait_for_pods() {
456 local INDENT=
457 if [ "$1" == "-" ]; then
458 INDENT=$1; shift
459 fi
460 local NAMESPACE=$1; shift
461 local EXPECT=$1; shift
462 local TYPE=$1; shift
463 local RETRY=$1; shift
464 local MESSAGE=$1; shift
465 local PATTERNS=$*
David Bainbridge99ac7a22019-08-31 02:26:43 +0000466 local STATES=":Running:"
467 if [ "$TYPE" == "not" ]; then
468 STATES="*"
469 fi
470 local HAVE=$(count_pods $NAMESPACE "$STATES" $PATTERNS)
David Bainbridge4f1b5562019-08-19 04:46:52 +0000471 local ALL=$HAVE
472 if [ "$TYPE" == "only" ]; then
473 ALL=$(count_pods "all-namespaces" "*" ".*")
474 fi
475 COUNT=$(expr 300 / 15)
476 bspin $INDENT $MESSAGE
477 sspin $INDENT
478 if [ $HAVE -ne $EXPECT -o $ALL -ne $HAVE ]; then
479 while [ $HAVE -ne $EXPECT -o $ALL -ne $HAVE ]; do
480 sspin $INDENT
481 COUNT=$(expr $COUNT - 1)
482 if [ $COUNT -eq 0 ]; then
David Bainbridge99ac7a22019-08-31 02:26:43 +0000483 HAVE=$(count_pods $NAMESPACE "$STATES" $PATTERNS)
David Bainbridge4f1b5562019-08-19 04:46:52 +0000484 ALL=$HAVE
485 if [ "$TYPE" == "only" ]; then
486 ALL=$(count_pods "all-namespaces" "*" ".*")
487 fi
488 COUNT=$(expr 300 / 15)
489 fi
490 sleep .15
491 done
492 fi
493 espin $INDENT $VERIFIED
494 if [ $HAVE -ne $EXPECT ]; then
495 return 1
496 fi
497 return 0
498}
499
David Bainbridgeac7f8072019-08-01 22:15:33 +0000500if [ "$1" == "down" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000501 echo "Tearing down voltha cluster $NAME"
502 LOG="down-$NAME.log"
503 echo $(date -u +"%Y%m%dT%H%M%SZ") >$LOG
David Bainbridgeac7f8072019-08-01 22:15:33 +0000504 if [ $DEPLOY_K8S == "yes" ]; then
505 if [ -x ./bin/kind ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000506 bspin "Delete Kubernetes Kind Cluster"
507 (set -x; ./bin/kind delete cluster --name voltha-$NAME >>$LOG 2>&1) >>$LOG 2>&1
508 espin $VERIFIED
David Bainbridgeac7f8072019-08-01 22:15:33 +0000509 else
David Bainbridge0774b232019-08-02 06:37:19 +0000510 espin "$NO_ENTRY Delete Kubernetes Kind Cluster: kind command not found"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000511 fi
512 else
513 EXISTS=$(helm list -q)
514 EXPECT="etcd-operator onos open-olt open-onu sim voltha bbsim radius"
David Bainbridge0774b232019-08-02 06:37:19 +0000515 bspin "Remove Helm Deployments"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000516 for i in $EXISTS; do
517 if [ $(echo $EXPECT | grep -c $i) -eq 1 ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000518 sspin "Remove Helm Deployments: $i$CEOL"
519 (set -x; ./bin/helm delete --purge $i >>$LOG 2>&1) >>$LOG 2>&1
David Bainbridgeac7f8072019-08-01 22:15:33 +0000520 fi
521 done
David Bainbridge0774b232019-08-02 06:37:19 +0000522 espin "$VERIFIED Remove Helm Deployments$CEOL"
David Bainbridge4f1b5562019-08-19 04:46:52 +0000523 if [ "$WAIT_ON_DOWN" == "yes" ]; then
524 # There should only be 13 or 15 PODs in the kube-system name
525 # space and no other PODs
David Bainbridge4f1b5562019-08-19 04:46:52 +0000526 PODS="coredns-.* \
527 etcd-voltha-$NAME-control-plane \
528 kindnet-.* \
529 kube-apiserver-voltha-$NAME-control-plane \
530 kube-controller-manager-voltha-$NAME-control-plane \
531 kube-proxy-.* \
532 kube-scheduler-voltha-$NAME-control-plane \
533 tiller-deploy-.*"
534 EXPECT=$(test "$TYPE" == "minimal" && echo "13" || echo "15")
David Bainbridge99ac7a22019-08-31 02:26:43 +0000535 PODS="adapter-.* \
536 bbsim.* \
537 etcd-operator.* \
538 radius.* \
539 voltha-.*"
540 EXPECT=0
541
542 wait_for_pods "voltha" $EXPECT "not" -1 "Waiting for VOLTHA PODs to terminate" $PODS
David Bainbridge4f1b5562019-08-19 04:46:52 +0000543 fi
David Bainbridgeac7f8072019-08-01 22:15:33 +0000544 fi
David Bainbridge0774b232019-08-02 06:37:19 +0000545 bspin "Remove port-forwards: onos-ui-$NAME"
546 for i in $(screen -ls | grep onos-ui-$NAME | awk '{print $1}'); do
547 sspin
548 (set -x; screen -X -S $i quit >>$LOG 2>&1) >>$LOG 2>&1
549 done
550 sspin "Remove port-forwards: onos-ssh-$NAME$CEOL"
551 for i in $(screen -ls | grep onos-ssh-$NAME | awk '{print $1}'); do
552 sspin
553 (set -x; screen -X -S $i quit >>$LOG 2>&1) >>$LOG 2>&1
554 done
555 sspin "Remove port-forwards: voltha-api-$NAME$CEOL"
556 for i in $(screen -ls | grep voltha-api-$NAME | awk '{print $1}'); do
557 sspin
558 (set -x; screen -X -S $i quit >>$LOG 2>&1) >>$LOG 2>&1
559 done
560 sspin "Remove port-forwards: voltha-ssh-$NAME$CEOL"
561 for i in $(screen -ls | grep voltha-ssh-$NAME | awk '{print $1}'); do
562 sspin
563 (set -x; screen -X -S $i quit >>$LOG 2>&1) >>$LOG 2>&1
564 done
565 sspin "Remove port-forwards: voltha-etcd-$NAME$CEOL"
566 for i in $(screen -ls | grep voltha-etcd-$NAME | awk '{print $1}'); do
567 sspin
568 (set -x; screen -X -S $i quit >>$LOG 2>&1) >>$LOG 2>&1
569 done
570 espin "$VERIFIED Remove port-forwards$CEOL"
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -0700571 exit
David Bainbridgeac7f8072019-08-01 22:15:33 +0000572fi
573
574if [ "$1" == "dump" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000575 LOG="dump-$NAME.log"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000576 TS=$(date -u +"%Y%m%dT%H%M%SZ")
David Bainbridge76514a02019-10-08 01:50:35 +0000577 if [ ! -z "$DUMP_FROM" ]; then
578 TS=$(echo $DUMP_FROM | sed -e 's/[:-]//g')
579 fi
David Bainbridgeac7f8072019-08-01 22:15:33 +0000580 WORK=$(mktemp -u -d)
David Bainbridge0774b232019-08-02 06:37:19 +0000581 DATA=$WORK/voltha-debug-dump-$NAME-$TS
David Bainbridgeac7f8072019-08-01 22:15:33 +0000582 mkdir -p $DATA
583 echo $TS > $LOG
David Bainbridge0774b232019-08-02 06:37:19 +0000584 echo -e "Capturing debug dump to voltha-debug-dump-$NAME-$TS.tgz"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000585 bspin - "Copy install log"
David Bainbridge0774b232019-08-02 06:37:19 +0000586 if [ -f install-$NAME.log ]; then
587 (set -x; cp install-$NAME.log $DATA/install-$NAME.log) >>$LOG 2>&1
David Bainbridgeac7f8072019-08-01 22:15:33 +0000588 espin - $VERIFIED
589 else
David Bainbridge0774b232019-08-02 06:37:19 +0000590 espin - "$NO_ENTRY Copy install log: install-$NAME.log not found"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000591 fi
592 bspin - "Dumping Kubernetes PODs"
593 (set -x; kubectl get --all-namespaces pods >> $DATA/all-pods.txt 2>&1) >>$LOG 2>&1
594 espin - $VERIFIED
595 bspin - "Dumping Kubernetes SERVICEs"
596 (set -x; kubectl get --all-namespaces svc >> $DATA/all-services.txt 2>&1) >>$LOG 2>&1
597 espin - $VERIFIED
598 bspin - "Dumping Kubernetes EVENTs"
599 (set -x; kubectl get --all-namespaces events >> $DATA/all-events.txt 2>&1) >>$LOG 2>&1
600 espin - $VERIFIED
601 bspin - "Dumping VOLTHA POD details"
Matteo Scandolodcd29f52019-10-07 15:42:42 -0700602 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 +0000603 SINCE=
604 if [ ! -z "$DUMP_FROM" ]; then
605 SINCE="--since-time=$DUMP_FROM"
606 fi
David Bainbridgeac7f8072019-08-01 22:15:33 +0000607 for POD in $PODS; do
David Bainbridge1f0655a2019-10-01 22:08:48 +0000608 NS=$(echo $POD | cut -d: -f1)
609 POD=$(echo $POD | cut -d: -f2)
David Bainbridgeac7f8072019-08-01 22:15:33 +0000610 sspin - "Dumping VOLTHA POD details: $POD$CEOL"
611 mkdir -p $DATA/$POD
David Bainbridge1f0655a2019-10-01 22:08:48 +0000612 (set -x; kubectl describe -n $NS $POD >> $DATA/$POD/describe.txt 2>&1) >>$LOG 2>&1
David Bainbridgeac7f8072019-08-01 22:15:33 +0000613 sspin - "Dumping VOLTHA POD details: $POD"
David Bainbridgecfd7ca12019-10-06 03:31:41 +0000614 (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 +0000615 sspin - "Dumping VOLTHA POD details: $POD"
David Bainbridgecfd7ca12019-10-06 03:31:41 +0000616 (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 +0000617 sspin - "Dumping VOLTHA POD details: $POD"
618 done
619 espin - "$VERIFIED Dumping VOLTHA POD details$CEOL"
620 bspin - "Dumping ETCD"
621 if [ "$(which etcdctl) X" != " X" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000622 (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 +0000623 espin - $VERIFIED
624 else
625 espin - "$NO_ENTRY Dumping ETCD: etcdctl command not available"
626 fi
David Bainbridge0774b232019-08-02 06:37:19 +0000627 bspin - "Creating compressed TAR: voltha-debug-dump-$NAME-$TS.tgz"
628 (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 +0000629 espin - $VERIFIED
630 bspin - "Cleanup"
631 (set -x; rm -rf $WORK) >>$LOG 2>&1
632 espin - $VERIFIED
David Bainbridge0774b232019-08-02 06:37:19 +0000633 bspin - "$(ls -l voltha-debug-dump-$NAME-$TS.tgz)"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000634 espin - $VERIFIED
635 exit
636fi
637
David Bainbridge0774b232019-08-02 06:37:19 +0000638LOG="install-$NAME.log"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000639date > $LOG
David Bainbridge0774b232019-08-02 06:37:19 +0000640echo "PORTS=$ONOS_API_PORT,$ONOS_SSH_PORT,$VOLTHA_API_PORT,$VOLTHA_SSH_PORT,$VOLTHA_ETCD_PORT" >> $LOG
David Bainbridgeac7f8072019-08-01 22:15:33 +0000641
642# Output install options to log
643echo "OPTIONS" >> $LOG
David Bainbridgeac7f8072019-08-01 22:15:33 +0000644for O in $ALL_OPTIONS; do
645 VAL=$(eval echo \$$O)
David Bainbridgeac7f8072019-08-01 22:15:33 +0000646 if [ ! -z "$VAL" ]; then
647 printf " %-30s = %s\n" $O $VAL >> $LOG
648 fi
649done
650
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -0700651helm_install() {
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700652 local INDENT=
653 if [ "$1" == "-" ]; then
654 INDENT=$1; shift
655 fi
656 local NAMESPACE=$1; shift
David Bainbridge0774b232019-08-02 06:37:19 +0000657 local INAME=$1; shift
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700658 local CHART=$1; shift
David Bainbridge90fd8e32019-08-21 23:32:47 +0000659 local CHART_VERSION=$1; shift
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700660 local MESSAGE=$*
661
David Bainbridge90fd8e32019-08-21 23:32:47 +0000662 if [ "$CHART_VERSION X" != " X" -a "$CHART_VERSION" != "latest" ]; then
663 CHART_VERSION="--version $CHART_VERSION"
664 else
665 CHART_VERSION=
666 fi
667
David Bainbridge99ac7a22019-08-31 02:26:43 +0000668 local CHART_ARGS=
669 if [ -r "${INAME}-values.yaml" ]; then
670 CHART_ARGS="-f ${INAME}-values.yaml"
671 fi
672
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700673 COUNT=$(expr 300 / 15)
674 bspin $INDENT $MESSAGE
David Bainbridge99ac7a22019-08-31 02:26:43 +0000675 (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 -0700676 SUCCESS=$?
677 while [ $SUCCESS -ne 0 ]; do
678 sspin $INDENT
679 COUNT=$(expr $COUNT - 1)
680 if [ $COUNT -eq 0 ]; then
David Bainbridge99ac7a22019-08-31 02:26:43 +0000681 (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 -0700682 COUNT=$(expr 300 / 15)
683 fi
684 sleep .15
685 done
686 espin $INDENT $VERIFIED
687}
688
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700689echo "INSTALL TYPE: $TYPE" >> $LOG
690
691bspin "Verify GOPATH"
692export GOPATH=$(pwd)
Test User3d7ad8e2019-07-03 06:15:44 +0000693mkdir -p $GOPATH/bin
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700694espin $VERIFIED
695
David Bainbridgee87067b2019-08-12 22:00:12 +0000696STIME=$(date +%s)
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700697if [ "$INSTALL_KUBECTL" == "no" ]; then
698 bspin "Skip kubectl install"
699 espin $NO_ENTRY
Test Userc13bdc92019-07-03 20:57:49 +0000700else
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700701 bspin "Verify kubectl $HELM"
702 if [ -x $GOPATH/bin/kubectl ]; then
703 espin $VERIFIED
704 else
705 espin $NOT_VERIFIED
706 bspin - "Download and install Kubernetes/kubectl $DOWNLOAD"
707 (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
708 (set -x; chmod 755 $GOPATH/bin/kubectl >>$LOG 2>&1) >>$LOG 2>&1
709 espin - $VERIFIED
710 fi
Test Userc13bdc92019-07-03 20:57:49 +0000711fi
David Bainbridgee87067b2019-08-12 22:00:12 +0000712if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +0000713 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +0000714fi
Test Userc13bdc92019-07-03 20:57:49 +0000715
David Bainbridgee87067b2019-08-12 22:00:12 +0000716STIME=$(date +%s)
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700717if [ "$DEPLOY_K8S" == "no" ]; then
718 bspin "Skip Kubernetes/Kind Deployment"
719 espin $NO_ENTRY
720else
Test Userba1e7e72019-07-10 22:27:54 +0000721 bspin "Verify Kubernetes/Kind $HELM"
722 if [ -x $GOPATH/bin/kind ]; then
723 espin $VERIFIED
724 else
725 espin $NOT_VERIFIED
726 bspin - "Download and install Kubernetes/kind $DOWNLOAD"
David Bainbridge9e2a6662019-07-11 17:07:57 +0000727 (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 +0000728 (set -x; chmod 755 $GOPATH/bin/kind >>$LOG 2>&1) >>$LOG 2>&1
729 espin - $VERIFIED
730 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700731fi
732
David Bainbridgee87067b2019-08-12 22:00:12 +0000733if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +0000734 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +0000735fi
736
737STIME=$(date +%s)
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700738if [ "$INSTALL_HELM" == "no" ]; then
739 bspin "Skip Helm Install"
740 espin $NO_ENTRY
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700741else
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700742 bspin "Verify Helm $HELM"
743 if [ -x $GOPATH/bin/helm ]; then
744 espin $VERIFIED
745 else
746 espin $NOT_VERIFIED
747 bspin - "Download and install Helm $DOWNLOAD"
David Bainbridgec6a6eb62019-10-18 22:50:07 +0000748 (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 -0700749 espin - $VERIFIED
750 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700751fi
David Bainbridgee87067b2019-08-12 22:00:12 +0000752if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +0000753 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +0000754fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700755
David Bainbridgee87067b2019-08-12 22:00:12 +0000756STIME=$(date +%s)
Test Userb5712372019-07-03 21:52:17 +0000757bspin "Verify voltctl $HIGH_VOLTAGE"
Test User3d7ad8e2019-07-03 06:15:44 +0000758if [ -x $GOPATH/bin/voltctl ]; then
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700759 espin $VERIFIED
760else
761 espin $NOT_VERIFIED
David Bainbridge99ac7a22019-08-31 02:26:43 +0000762 bspin - "Download and install voltctl $DOWNLOAD"
Test Userba1e7e72019-07-10 22:27:54 +0000763 (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 +0000764 (set -x; chmod 755 $GOPATH/bin/voltctl >>$LOG 2>&1) >>$LOG 2>&1
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700765 espin - $VERIFIED
766fi
David Bainbridgee87067b2019-08-12 22:00:12 +0000767if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +0000768 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +0000769fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700770
771bspin "Verify command PATH"
Test Userba1e7e72019-07-10 22:27:54 +0000772export PATH=$GOPATH/bin:$PATH
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700773espin $VERIFIED
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700774
David Bainbridgee87067b2019-08-12 22:00:12 +0000775STIME=$(date +%s)
Test Userba1e7e72019-07-10 22:27:54 +0000776if [ "$DEPLOY_K8S" == "yes" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000777 HAVE=$(kind get clusters | grep -c voltha-$NAME)
Test Userba1e7e72019-07-10 22:27:54 +0000778 bspin "Verify Kubernetes/Kind Cluster"
779 sspin
780 if [ $HAVE -eq 0 ]; then
David Bainbridge491b1bd2019-07-11 17:53:11 +0000781 espin $NOT_VERIFIED
782 bspin - "Verify cluster configuration"
David Bainbridge0774b232019-08-02 06:37:19 +0000783 if [ ! -r ./$NAME-cluster.cfg ]; then
David Bainbridge491b1bd2019-07-11 17:53:11 +0000784 espin - $NOT_VERIFIED
David Bainbridge0774b232019-08-02 06:37:19 +0000785 bspin - "Download cluster configuration: $TYPE-cluster.cfg to $NAME-cluster.cfg $DOWNLOAD"
786 (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 -0700787 espin - $VERIFIED
788 else
789 espin - $VERIFIED
790 fi
David Bainbridge0774b232019-08-02 06:37:19 +0000791 kind create cluster --name voltha-$NAME --config $NAME-cluster.cfg
David Bainbridge491b1bd2019-07-11 17:53:11 +0000792 else
793 espin $VERIFIED
Test Userba1e7e72019-07-10 22:27:54 +0000794 fi
795
David Bainbridge0774b232019-08-02 06:37:19 +0000796 export KUBECONFIG="$(kind get kubeconfig-path --name="voltha-$NAME")"
Test Userba1e7e72019-07-10 22:27:54 +0000797 P="coredns-.* \
David Bainbridge0774b232019-08-02 06:37:19 +0000798 etcd-voltha-$NAME-control-plane \
Test Userba1e7e72019-07-10 22:27:54 +0000799 kindnet-.* \
David Bainbridge0774b232019-08-02 06:37:19 +0000800 kube-apiserver-voltha-$NAME-control-plane \
801 kube-controller-manager-voltha-$NAME-control-plane \
Test Userba1e7e72019-07-10 22:27:54 +0000802 kube-proxy-.* \
David Bainbridge0774b232019-08-02 06:37:19 +0000803 kube-scheduler-voltha-$NAME-control-plane"
Test Userba1e7e72019-07-10 22:27:54 +0000804
805 EXPECT=$(test "$TYPE" == "minimal" && echo "12" || echo "14")
David Bainbridge4f1b5562019-08-19 04:46:52 +0000806 wait_for_pods - "kube-system" $EXPECT "includes" -1 "Waiting for system PODs to start" $P
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700807fi
David Bainbridgee87067b2019-08-12 22:00:12 +0000808if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +0000809 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +0000810fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700811
David Bainbridgee87067b2019-08-12 22:00:12 +0000812STIME=$(date +%s)
David Bainbridge4c6289c2019-09-03 21:11:32 +0000813COUNT=$(count_pods "kube-system" ":Running:" "tiller-deploy-.*")
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700814bspin "Verify Helm"
Test Userba1e7e72019-07-10 22:27:54 +0000815if [ $COUNT -ne 1 ]; then
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700816 espin $NOT_VERIFIED
Test Userb5712372019-07-03 21:52:17 +0000817 echo -e "Configuring Helm $GEAR"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700818 if [ "$INSTALL_HELM" == "no" ]; then
819 bspin - "Skip Helm/Tiller Initialization"
820 espin - $NO_ENTRY
821 else
822 bspin - "Initialize Helm"
823 (set -x; helm init --upgrade >>$LOG 2>&1) >>$LOG 2>&1
824 espin - $VERIFIED
David Bainbridge4f1b5562019-08-19 04:46:52 +0000825 wait_for_pods - "kube-system" 1 "includes" -1 "Waiting for Tiller POD to start" "tiller-deploy-.*"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700826 fi
Test Userb5712372019-07-03 21:52:17 +0000827 bspin - "Add Google Incubator repository to Helm"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700828 (set -x; helm repo add incubator https://kubernetes-charts-incubator.storage.googleapis.com >>$LOG 2>&1) >>$LOG 2>&1
829 espin - $VERIFIED
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -0700830
Test Userba1e7e72019-07-10 22:27:54 +0000831 # HACK (sort-of) - the config for tiller is about to be patched, which will
832 # cause the tiller pod to be recreated. This can sometimes cause a timing
833 # issue with the "wait_for_pods" call on tiller as it may incorrectly
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -0700834 # identify the running/ready tiller pod that is soon to be terminated as
Test Userba1e7e72019-07-10 22:27:54 +0000835 # what it is waiting for. To avoid this issue we do a clean scale down and
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -0700836 # scale up of the pod so the script controlls when it should be expecting
Test Userba1e7e72019-07-10 22:27:54 +0000837 # things
838 (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 -0700839
Test Userb5712372019-07-03 21:52:17 +0000840 bspin - "Add Google Stable repository to Helm"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700841 (set -x; helm repo add stable https://kubernetes-charts.storage.googleapis.com >>$LOG 2>&1) >>$LOG 2>&1
842 espin - $VERIFIED
Test Userb5712372019-07-03 21:52:17 +0000843 bspin - "Add ONF repository to Helm"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700844 (set -x; helm repo add onf https://charts.opencord.org >>$LOG 2>&1) >>$LOG 2>&1
845 espin - $VERIFIED
Test Userb5712372019-07-03 21:52:17 +0000846 bspin - "Update Helm repository cache"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700847 (set -x; helm repo update >>$LOG 2>&1) >>$LOG 2>&1
848 espin - $VERIFIED
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -0700849
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700850 # Create and k8s service account so that Helm can create pods
Test Userb5712372019-07-03 21:52:17 +0000851 bspin - "Create Tiller ServiceAccount"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700852 (set -x; kubectl create serviceaccount --namespace kube-system tiller >>$LOG 2>&1) >>$LOG 2>&1
853 espin - $VERIFIED
Test Userb5712372019-07-03 21:52:17 +0000854 bspin - "Create Tiller ClusterRoleBinding"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700855 (set -x; kubectl create clusterrolebinding tiller-cluster-rule --clusterrole=cluster-admin --serviceaccount=kube-system:tiller >>$LOG 2>&1) >>$LOG 2>&1
856 espin - $VERIFIED
Test Userb5712372019-07-03 21:52:17 +0000857 bspin - "Update Tiller Manifest"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700858 (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 +0000859
860 # HACK (sort-of) - part to, spin it back up
861 (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 -0700862 espin - $VERIFIED
863else
864 espin $VERIFIED
David Bainbridge46505fb2019-10-01 21:13:20 +0000865 if [ "$UPDATE_HELM_REPOS" == "yes" ]; then
866 bspin - "Update Helm repository cache"
867 (set -x; helm repo update >>$LOG 2>&1) >>$LOG 2>&1
868 espin - $VERIFIED
869 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700870fi
David Bainbridge4f1b5562019-08-19 04:46:52 +0000871wait_for_pods - "kube-system" 1 "includes" -1 "Waiting for Tiller POD to start" "tiller-deploy-.*"
David Bainbridgee87067b2019-08-12 22:00:12 +0000872if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +0000873 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +0000874fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700875
David Bainbridgee87067b2019-08-12 22:00:12 +0000876STIME=$(date +%s)
David Bainbridge0774b232019-08-02 06:37:19 +0000877bspin "Verify Helm values file: $NAME-values.yaml"
878if [ ! -r "./$NAME-values.yaml" ]; then
Test Userba1e7e72019-07-10 22:27:54 +0000879 espin $NOT_VERIFIED
David Bainbridge0774b232019-08-02 06:37:19 +0000880 bspin - "Download Helm values file: $TYPE-values.yaml to $NAME-values.yaml $DOWNLOAD"
881 (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 +0000882 espin - $VERIFIED
883else
884 espin $VERIFIED
885fi
David Bainbridgee87067b2019-08-12 22:00:12 +0000886if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +0000887 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +0000888fi
Test Userba1e7e72019-07-10 22:27:54 +0000889
David Bainbridge99ac7a22019-08-31 02:26:43 +0000890STIME=$(date +%s)
891bspin "Verify or download chart specific values files $DOWNLOAD"
892VALUES_FILES="monkey-values.yaml"
893for i in $VALUES_FILES; do
894 if [ ! -r ./$i ]; then
895 (set -x; curl -o ./$i -sSL https://raw.githubusercontent.com/ciena/kind-voltha/master/$i >>$LOG 2>&1) >>$LOG 2>&1
896 fi
897done
898espin $VERIFIED
899if [ "$WITH_TIMINGS" == "yes" ]; then
900 printtime $(expr $(date +%s) - $STIME)
901fi
902
903if [ "$WITH_CHAOS" == "yes" ]; then
904 bspin "Verify or clone kube-monkey helm chart $DOWNLOAD"
905 if [ -r ./kube-monkey ]; then
906 espin $VERIFIED
907 else
908 espin $NOT_VERIFIED
909 bspin - "GIT clone kube-monkey"
910 (set -x; git clone https://github.com/asobti/kube-monkey kube-monkey >>$LOG 2>&1) >>$LOG 2>&1
911 espin - $VERIFIED
912 fi
913fi
914
Test Userba1e7e72019-07-10 22:27:54 +0000915if [ "$JUST_K8S" == "yes" ]; then
916 echo "Environment deployed, not deploying VOLTHA artifacts as requested. Good bye."
917 echo ""
918 echo "Please issue the following commands in your terminal to ensure that you" | tee -a $LOG
919 echo "are accessing the correct Kubernetes/Kind cluster as well as have the " | tee -a $LOG
920 echo "tools required by VOLTHA in your command path. " | tee -a $LOG
921 echo "" | tee -a $LOG
922 echo -en $BOLD
923 if [ $DEPLOY_K8S == "yes" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000924 echo "export KUBECONFIG=\"\$(./bin/kind get kubeconfig-path --name=\"voltha-$NAME\")\"" | tee -a $LOG
Test Userba1e7e72019-07-10 22:27:54 +0000925 fi
926 echo "export PATH=$GOPATH/bin:\$PATH" | tee -a $LOG
927 echo -en $NORMAL
928 echo "" | tee -a $LOG
929 echo "Thank you for choosing kind-voltha for you quick cluster needs." | tee -a $LOG
930 exit 0
931fi
932
David Bainbridgee87067b2019-08-12 22:00:12 +0000933STIME=$(date +%s)
Test Userb5712372019-07-03 21:52:17 +0000934bspin "Verify ETCD Operator $OLD_KEY"
Test User7d866122019-07-09 17:52:35 +0000935if [ $(helm list --deployed --short --namespace voltha "^etcd-operator\$" | wc -l) -ne 1 ]; then
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -0700936 espin $NOT_VERIFIED
David Bainbridge90fd8e32019-08-21 23:32:47 +0000937 helm_install - voltha etcd-operator stable/etcd-operator latest "Install ETCD Operator"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700938else
939 espin $VERIFIED
940fi
Test User01ed0642019-07-03 20:17:06 +0000941EXPECT=$(test "$TYPE" == "minimal" && echo "1" || echo "3")
David Bainbridge4f1b5562019-08-19 04:46:52 +0000942wait_for_pods - "voltha" $EXPECT "includes" -1 "Waiting for ETCD Operator to start" "etcd-operator-.*"
David Bainbridgee87067b2019-08-12 22:00:12 +0000943if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +0000944 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +0000945fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700946
David Bainbridgee87067b2019-08-12 22:00:12 +0000947STIME=$(date +%s)
David Bainbridgeb270c202019-07-26 01:44:42 +0000948if [ $WITH_ONOS == "yes" ]; then
949 bspin "Verify ONOS installed $BIRD"
950 if [ $(helm list --deployed --short --namespace default "^onos\$" | wc -l) -ne 1 ]; then
951 espin $NOT_VERIFIED
David Bainbridge90fd8e32019-08-21 23:32:47 +0000952 EXTRA_HELM_FLAGS="$SET_TAG $EXTRA_HELM_FLAGS" helm_install - default onos onf/onos latest "Install ONOS"
David Bainbridgeb270c202019-07-26 01:44:42 +0000953 else
954 espin $VERIFIED
955 fi
David Bainbridge4f1b5562019-08-19 04:46:52 +0000956 wait_for_pods - "default" 1 "includes" -1 "Waiting for ONOS to start" "onos-.*"
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -0700957
David Bainbridgeb270c202019-07-26 01:44:42 +0000958 bspin - "Forward ONOS API port $FORWARD"
David Bainbridge0774b232019-08-02 06:37:19 +0000959 for i in $(screen -ls | grep onos-ui-$NAME | awk '{print $1}'); do
David Bainbridge82bd1212019-07-29 19:19:31 +0000960 (set -x; screen -X -S $i quit >>$LOG 2>&1) >>$LOG 2>&1
961 done
David Bainbridge0774b232019-08-02 06:37:19 +0000962 (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 +0000963 espin - $VERIFIED
964 bspin - "Forward ONOS SSH port $FORWARD"
David Bainbridge0774b232019-08-02 06:37:19 +0000965 for i in $(screen -ls | grep onos-ssh-$NAME | awk '{print $1}'); do
David Bainbridge82bd1212019-07-29 19:19:31 +0000966 (set -x; screen -X -S $i quit >>$LOG 2>&1) >>$LOG 2>&1
967 done
David Bainbridge2b19e832019-08-16 02:40:53 +0000968
969
David Bainbridge0774b232019-08-02 06:37:19 +0000970 (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 +0000971 espin - $VERIFIED
David Bainbridged31d6122019-08-13 19:37:59 +0000972 bspin - "Verify or download ONOS configuration support files $DOWNLOAD"
David Bainbridge2b19e832019-08-16 02:40:53 +0000973 ONOS_FILES="olt-onos-enableExtraneousRules.json olt-onos-olt-settings.json onos-aaa.json \
David Bainbridge90fd8e32019-08-21 23:32:47 +0000974 onos-dhcpl2relay.json onos-kafka.json onos-sadis-sample.json"
David Bainbridged31d6122019-08-13 19:37:59 +0000975 (set -x; mkdir -p ./onos-files >>$LOG 2>&1) >>$LOG 2>&1
David Bainbridge2b19e832019-08-16 02:40:53 +0000976 for i in $ONOS_FILES; do
David Bainbridged31d6122019-08-13 19:37:59 +0000977 if [ ! -r ./onos-files/$i ]; then
978 (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
979 fi
980 done
Test Userba1e7e72019-07-10 22:27:54 +0000981 espin - $VERIFIED
David Bainbridge27790d62019-08-13 22:43:19 +0000982
983 if [ $INSTALL_ONOS_APPS == "yes" ]; then
984 bspin - "Installing custom ONOS applications"
985 if [ -x onos-files/onos-apps -a $(ls -1 onos-files/onos-apps/*.oar 2>/dev/null | wc -l) -gt 0 ]; then
986 for OAR in $(ls -1 onos-files/onos-apps/*.oar); do
987 sspin - "Installing custom ONOS applications - $OAR$CEOL"
David Bainbridge2b19e832019-08-16 02:40:53 +0000988 override_onos_app $OAR
David Bainbridge27790d62019-08-13 22:43:19 +0000989 done
990 espin - "$VERIFIED Installing custom ONOS applications$CEOL"
991 else
992 espin - "$NOT_VERIFIED Installing custom ONOS applications - None Found"
993 fi
994 fi
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -0700995
David Bainbridge2b19e832019-08-16 02:40:53 +0000996 push_onos_config "Push ONOS Kafka Configuration" "network/configuration/apps/org.opencord.kafka" "onos-files/onos-kafka.json"
997 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 +0000998 push_onos_config "Enable VOLTHA ONOS DHCP provisioning" "configuration/org.opencord.olt.impl.Olt" "onos-files/olt-onos-olt-settings.json"
999 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 +00001000 if [ -f onos-files/onos-sadis.json ]; then
1001 push_onos_config "[optional] Push ONOS SADIS Configuration" "network/configuration/apps/org.opencord.sadis" "onos-files/onos-sadis.json"
1002 elif [ "$CONFIG_SADIS" == "yes" ]; then
David Bainbridge90fd8e32019-08-21 23:32:47 +00001003 SADIS_CFG=onos-files/onos-sadis-sample.json
David Bainbridge2b19e832019-08-16 02:40:53 +00001004 push_onos_config "[optional] Push ONOS SADIS Configuration" "network/configuration/apps/org.opencord.sadis" "$SADIS_CFG"
1005 fi
Test Userba1e7e72019-07-10 22:27:54 +00001006fi
David Bainbridgee87067b2019-08-12 22:00:12 +00001007if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +00001008 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +00001009fi
Test Userba1e7e72019-07-10 22:27:54 +00001010
David Bainbridgee87067b2019-08-12 22:00:12 +00001011STIME=$(date +%s)
Test Userb5712372019-07-03 21:52:17 +00001012bspin "Verify VOLTHA installed $HIGH_VOLTAGE"
Test User7d866122019-07-09 17:52:35 +00001013if [ $(helm list --deployed --short --namespace voltha "^voltha\$" | wc -l) -ne 1 ]; then
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001014 espin $NOT_VERIFIED
David Bainbridge90fd8e32019-08-21 23:32:47 +00001015 helm_install - voltha voltha $VOLTHA_CHART $VOLTHA_CHART_VERSION "Install VOLTHA Core"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001016else
1017 espin $VERIFIED
1018fi
Test Userba1e7e72019-07-10 22:27:54 +00001019
David Bainbridge90fd8e32019-08-21 23:32:47 +00001020VOLTHA="voltha-ofagent-.* \
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001021 ro-core.* \
1022 rw-core.* \
1023 voltha-api-server-.* \
1024 voltha-cli-server-.* \
1025 voltha-etcd-cluster-.* \
1026 voltha-kafka-.* \
1027 voltha-zookeeper-.*"
David Bainbridge46505fb2019-10-01 21:13:20 +00001028#EXPECT=$(test "$TYPE" == "minimal" && echo "8" || echo "11")
Test User01ed0642019-07-03 20:17:06 +00001029EXPECT=$(test "$TYPE" == "minimal" && echo "9" || echo "11")
David Bainbridge4f1b5562019-08-19 04:46:52 +00001030wait_for_pods - "voltha" $EXPECT "includes" -1 "Waiting for VOLTHA Core to start" $VOLTHA
David Bainbridgee87067b2019-08-12 22:00:12 +00001031if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +00001032 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +00001033fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001034
David Bainbridge46505fb2019-10-01 21:13:20 +00001035if [ "$WITH_ADAPTERS" == "yes" ]; then
1036 STIME=$(date +%s)
1037 EXPECT=0
1038 echo -e "Verify Adapters $PLUG"
1039 if [ "$WITH_SIM_ADAPTERS" == "yes" ]; then
1040 bspin - "Verify Simulated Adapters installed"
1041 if [ $(helm list --deployed --short --namespace voltha "^sim\$" | wc -l) -ne 1 ]; then
1042 espin - $NOT_VERIFIED
1043 helm_install - voltha sim $VOLTHA_ADAPTER_SIM_CHART $VOLTHA_ADAPTER_SIM_CHART_VERSION "Install Simulated Adapters"
1044 else
1045 espin - $VERIFIED
1046 fi
1047 EXPECT=$(expr $EXPECT + 2)
1048 fi
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001049
David Bainbridge46505fb2019-10-01 21:13:20 +00001050 if [ "$WITH_OPEN_ADAPTERS" == "yes" ]; then
1051 bspin - "Verify OpenOLT Adapter installed"
1052 if [ $(helm list --deployed --short --namespace voltha "^open-olt\$" | wc -l) -ne 1 ]; then
1053 espin - $NOT_VERIFIED
1054 helm_install - voltha open-olt $VOLTHA_ADAPTER_OPEN_OLT_CHART $VOLTHA_ADAPTER_OPEN_OLT_CHART_VERSION "Install OpenOLT Adapter"
1055 else
1056 espin - $VERIFIED
1057 fi
1058 bspin - "Verify OpenONU Adapter installed"
1059 if [ $(helm list --deployed --short --namespace voltha "^open-onu\$" | wc -l) -ne 1 ]; then
1060 espin - $NOT_VERIFIED
1061 helm_install - voltha open-onu $VOLTHA_ADAPTER_OPEN_ONU_CHART $VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION "Install OpenONU Adapter"
1062 else
1063 espin - $VERIFIED
1064 fi
1065 EXPECT=$(expr $EXPECT + 2)
1066 fi
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001067
David Bainbridge46505fb2019-10-01 21:13:20 +00001068 ADAPTERS="adapter-.*"
1069 wait_for_pods - "voltha" $EXPECT "includes" -1 "Waiting for adapters to start" $ADAPTERS
1070 if [ "$WITH_TIMINGS" == "yes" ]; then
1071 printtime $(expr $(date +%s) - $STIME)
1072 fi
David Bainbridgee87067b2019-08-12 22:00:12 +00001073fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001074
Test User7d866122019-07-09 17:52:35 +00001075if [ $WITH_BBSIM == "yes" ]; then
David Bainbridgee87067b2019-08-12 22:00:12 +00001076 STIME=$(date +%s)
Test User7d866122019-07-09 17:52:35 +00001077 echo -e "Verify BBSIM $PLUG"
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001078 bspin - "Verify BBSIM Installed"
Test User7d866122019-07-09 17:52:35 +00001079 if [ $(helm list --deployed --short --namespace voltha "^bbsim\$" | wc -l) -ne 1 ]; then
1080 espin - $NOT_VERIFIED
David Bainbridge90fd8e32019-08-21 23:32:47 +00001081 helm_install - voltha bbsim $VOLTHA_BBSIM_CHART $VOLTHA_BBSIM_CHART_VERSION "Install BBSIM"
Test User7d866122019-07-09 17:52:35 +00001082 else
1083 espin - $VERIFIED
1084 fi
David Bainbridge4f1b5562019-08-19 04:46:52 +00001085 wait_for_pods - "voltha" 1 "includes" -1 "Waiting for BBSIM to start" "bbsim-.*"
David Bainbridgee87067b2019-08-12 22:00:12 +00001086 if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +00001087 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +00001088 fi
Test User7d866122019-07-09 17:52:35 +00001089fi
1090
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001091if [ $WITH_RADIUS == "yes" ]; then
David Bainbridgee87067b2019-08-12 22:00:12 +00001092 STIME=$(date +%s)
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001093 echo -e "Verify RADIUS $LOCK"
1094 bspin - "Verify RADIUS Installed"
1095 if [ $(helm list --deployed --short --namespace voltha "^radius\$" | wc -l) -ne 1 ]; then
1096 espin - $NOT_VERIFIED
David Bainbridge90fd8e32019-08-21 23:32:47 +00001097 helm_install - voltha radius onf/freeradius latest "Install RADIUS"
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001098 else
1099 espin - $VERIFIED
1100 fi
David Bainbridge4f1b5562019-08-19 04:46:52 +00001101 wait_for_pods - "voltha" 1 "includes" -1 "Waiting for RADIUS to start" "radius-.*"
David Bainbridgee87067b2019-08-12 22:00:12 +00001102 if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +00001103 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +00001104 fi
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001105fi
1106
David Bainbridgee87067b2019-08-12 22:00:12 +00001107STIME=$(date +%s)
Test Userb5712372019-07-03 21:52:17 +00001108bspin - "Forward VOLTHA API port $FORWARD"
David Bainbridge0774b232019-08-02 06:37:19 +00001109for i in $(screen -ls | grep voltha-api-$NAME | awk '{print $1}'); do
David Bainbridge82bd1212019-07-29 19:19:31 +00001110 (set -x; screen -X -S $i quit >>$LOG 2>&1) >>$LOG 2>&1
1111done
David Bainbridge0774b232019-08-02 06:37:19 +00001112(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 -07001113espin - $VERIFIED
Test Userb5712372019-07-03 21:52:17 +00001114bspin - "Forward VOLTHA SSH port $FORWARD"
David Bainbridge0774b232019-08-02 06:37:19 +00001115for i in $(screen -ls | grep voltha-ssh-$NAME | awk '{print $1}'); do
David Bainbridge82bd1212019-07-29 19:19:31 +00001116 (set -x; screen -X -S $i quit >>$LOG 2>&1) >>$LOG 2>&1
1117done
David Bainbridge0774b232019-08-02 06:37:19 +00001118(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 -07001119espin - $VERIFIED
David Bainbridgeac7f8072019-08-01 22:15:33 +00001120bspin - "Forward VOLTHA ETCD port $FORWARD"
David Bainbridge0774b232019-08-02 06:37:19 +00001121for i in $(screen -ls | grep voltha-etcd-$NAME | awk '{print $1}'); do
David Bainbridgeac7f8072019-08-01 22:15:33 +00001122 (set -x; screen -X -S $i quit >>$LOG 2>&1) >>$LOG 2>&1
1123done
David Bainbridge0774b232019-08-02 06:37:19 +00001124(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 +00001125espin - $VERIFIED
David Bainbridgee87067b2019-08-12 22:00:12 +00001126if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +00001127 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +00001128fi
Test User3d7ad8e2019-07-03 06:15:44 +00001129
David Bainbridgeb270c202019-07-26 01:44:42 +00001130if [ $WITH_ONOS == "yes" -a $WITH_RADIUS == "yes" ]; then
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001131 bspin "Configure ONOS RADIUS Connection $GEAR"
David Bainbridge2b19e832019-08-16 02:40:53 +00001132 (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 +00001133 espin $VERIFIED
1134fi
1135
David Bainbridge99ac7a22019-08-31 02:26:43 +00001136if [ "$WITH_CHAOS" == "yes" ]; then
1137 STIME=$(date +%s)
1138 echo -e "Verify kube-monkey $LOCK"
1139 bspin - "Verify kube-monkey Installed"
1140 if [ $(helm list --deployed --short --namespace kube-monkey "^monkey\$" | wc -l) -ne 1 ]; then
1141 espin - $NOT_VERIFIED
1142 helm_install - kube-monkey monkey ./kube-monkey/helm/kubemonkey latest "Install Chaos Monkey"
1143 else
1144 espin - $VERIFIED
1145 fi
1146 wait_for_pods - "kube-monkey" 1 "includes" -1 "Waiting for Chaos to start" "monkey-.*"
1147 if [ "$WITH_TIMINGS" == "yes" ]; then
1148 printtime $(expr $(date +%s) - $STIME)
1149 fi
1150fi
1151
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001152bspin "Create voltctl configuration file"
Test User3d7ad8e2019-07-03 06:15:44 +00001153(set -x; mkdir -p $HOME/.volt >>$LOG 2>&1) >>$LOG 2>&1
David Bainbridge0774b232019-08-02 06:37:19 +00001154(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 +00001155espin $VERIFIED
Test User08ebbd92019-07-03 17:15:39 +00001156
David Bainbridge0774b232019-08-02 06:37:19 +00001157if [ ! -f "$NAME-env.sh" ]; then
1158 touch $NAME-env.sh
David Bainbridgeb07fdf72019-07-29 22:51:40 +00001159fi
1160
David Bainbridge596f30d2019-07-30 17:07:59 +00001161for O in $ALL_OPTIONS; do
1162 VAL=$(eval echo \$$O)
David Bainbridge0774b232019-08-02 06:37:19 +00001163 if [ ! -z "$VAL" -a $(grep -c "^export $O=" $NAME-env.sh) -eq 0 ]; then
1164 echo "export $O=\"$(eval echo \$$O)\"" >> $NAME-env.sh
David Bainbridgeb07fdf72019-07-29 22:51:40 +00001165 fi
1166done
1167
David Bainbridge0774b232019-08-02 06:37:19 +00001168if [ $DEPLOY_K8S == "yes" -a $(grep -c "^export KUBECONFIG=" $NAME-env.sh) -eq 0 ]; then
1169 echo "export KUBECONFIG=\"$(./bin/kind get kubeconfig-path --name=voltha-$NAME)\"" >> $NAME-env.sh
David Bainbridgeb07fdf72019-07-29 22:51:40 +00001170fi
1171
David Bainbridge0774b232019-08-02 06:37:19 +00001172if [ $(grep -c "^export VOLTCONFIG=" $NAME-env.sh) -eq 0 ]; then
1173 echo "export VOLTCONFIG=\"$HOME/.volt/config-$NAME\"" >> $NAME-env.sh
David Bainbridgeb07fdf72019-07-29 22:51:40 +00001174fi
1175
David Bainbridge0774b232019-08-02 06:37:19 +00001176if [ $(grep -c "^export PATH=" $NAME-env.sh) -eq 0 ]; then
1177 echo "export PATH=\"$GOPATH/bin:\$PATH\"" >> $NAME-env.sh
David Bainbridgeb07fdf72019-07-29 22:51:40 +00001178fi
1179
Test User7d866122019-07-09 17:52:35 +00001180echo ""
Test User08ebbd92019-07-03 17:15:39 +00001181echo "Please issue the following commands in your terminal to ensure that you" | tee -a $LOG
1182echo "are accessing the correct Kubernetes/Kind cluster as well as have the " | tee -a $LOG
1183echo "tools required by VOLTHA in your command path. " | tee -a $LOG
1184echo "" | tee -a $LOG
Test User7d866122019-07-09 17:52:35 +00001185echo -en $BOLD
Test Userba1e7e72019-07-10 22:27:54 +00001186if [ $DEPLOY_K8S == "yes" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +00001187 echo "export KUBECONFIG=\"\$(./bin/kind get kubeconfig-path --name=\"voltha-$NAME\")\"" | tee -a $LOG
Test Userba1e7e72019-07-10 22:27:54 +00001188fi
David Bainbridge0774b232019-08-02 06:37:19 +00001189echo "export VOLTCONFIG=\"$HOME/.volt/config-$NAME\"" | tee -a $LOG
Test Userba1e7e72019-07-10 22:27:54 +00001190echo "export PATH=$GOPATH/bin:\$PATH" | tee -a $LOG
Test User7d866122019-07-09 17:52:35 +00001191echo -en $NORMAL
Test User08ebbd92019-07-03 17:15:39 +00001192echo "" | tee -a $LOG
1193echo "Thank you for choosing kind-voltha for you quick cluster needs." | tee -a $LOG
1194
David Bainbridge712afb82019-08-14 19:55:58 +00001195if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridgef858a022019-08-14 21:25:11 +00001196 echo -e "$CLOCK ${BOLD}TOTAL: $(duration $(expr $(date +%s) - $TOTAL_START_TIME))${NORMAL}"
David Bainbridge712afb82019-08-14 19:55:58 +00001197fi