blob: b76dff1bc46eae48597ad89f90cedc42097a2782 [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
David Bainbridge28c64462019-12-12 22:25:26 +000033VOLTCTL_VERSION=${VOLTCTL_VERSION:-1.0.1}
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -080034KIND_VERSION=${KIND_VERSION:-v0.5.1}
David K. Bainbridgeb3a99372020-01-08 14:39:06 -080035VK_RELEASE=${VK_RELEASE:-master}
Test User08ebbd92019-07-03 17:15:39 +000036
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 Bainbridge05cd8822019-11-19 17:43:53 +000078ONLY_ONE=${ONLY_ONE:-yes}
David Bainbridge2b19e832019-08-16 02:40:53 +000079CONFIG_SADIS=${CONFIG_SADIS:-no}
David Bainbridge27790d62019-08-13 22:43:19 +000080INSTALL_ONOS_APPS=${INSTALL_ONOS_APPS:-no}
Test Userba1e7e72019-07-10 22:27:54 +000081JUST_K8S=${JUST_K8S:-no}
82DEPLOY_K8S=${DEPLOY_K8S:-yes}
David K. Bainbridge0e89cb92019-07-17 11:30:10 -070083INSTALL_KUBECTL=${INSTALL_KUBECTL:-yes}
84INSTALL_HELM=${INSTALL_HELM:-yes}
David Bainbridge46505fb2019-10-01 21:13:20 +000085UPDATE_HELM_REPOS=${UPDATE_HELM_REPOS:-yes}
Matteo Scandolofab98622020-01-28 15:17:20 -080086WAIT_ON_DOWN=${WAIT_ON_DOWN:-yes}
David Bainbridge5b7b96b2019-07-25 20:29:13 +000087VOLTHA_LOG_LEVEL=${VOLTHA_LOG_LEVEL:-WARN}
David Bainbridge90fd8e32019-08-21 23:32:47 +000088VOLTHA_CHART=${VOLTHA_CHART:-onf/voltha}
89VOLTHA_CHART_VERSION=${VOLTHA_CHART_VERSION:-latest}
90VOLTHA_BBSIM_CHART=${VOLTHA_BBSIM_CHART:-onf/bbsim}
Matteo Scandolodcd29f52019-10-07 15:42:42 -070091VOLTHA_BBSIM_CHART_VERSION=${VOLTHA_BBSIM_CHART_VERSION:-latest}
David Bainbridgee10f6d52019-07-25 00:28:13 +000092VOLTHA_ADAPTER_SIM_CHART=${VOLTHA_ADAPTER_SIM_CHART:-onf/voltha-adapter-simulated}
David Bainbridge90fd8e32019-08-21 23:32:47 +000093VOLTHA_ADAPTER_SIM_CHART_VERSION=${VOLTHA_ADAPTER_SIM_CHART_VERSION:-latest}
David Bainbridgee10f6d52019-07-25 00:28:13 +000094VOLTHA_ADAPTER_OPEN_OLT_CHART=${VOLTHA_ADAPTER_OPEN_OLT_CHART:-onf/voltha-adapter-openolt}
David Bainbridge90fd8e32019-08-21 23:32:47 +000095VOLTHA_ADAPTER_OPEN_OLT_CHART_VERSION=${VOLTHA_ADAPTER_OPEN_OLT_CHART_VERSION:-latest}
David Bainbridgee10f6d52019-07-25 00:28:13 +000096VOLTHA_ADAPTER_OPEN_ONU_CHART=${VOLTHA_ADAPTER_OPEN_ONU_CHART:-onf/voltha-adapter-openonu}
David Bainbridge90fd8e32019-08-21 23:32:47 +000097VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION=${VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION:-latest}
Andrea Campanella21323292019-12-18 11:44:19 -080098ONOS_CHART_VERSION=${ONOS_CHART_VERSION:-latest}
David Bainbridge70c0ea82019-11-14 23:25:26 +000099EXTRA_HELM_INSTALL_ARGS=
Test Userba1e7e72019-07-10 22:27:54 +0000100
101HAVE_GO=$(which go >/dev/null 2>&1 && echo "yes" || echo "no")
102HOSTOS=$(uname -s | tr "[:upper:]" "[:lower:"])
103HOSTARCH=$(uname -m | tr "[:upper:]" "[:lower:"])
104if [ $HOSTARCH == "x86_64" ]; then
105 HOSTARCH="amd64"
106fi
Test User7d866122019-07-09 17:52:35 +0000107
108# Verify TYPE setting
109if [ $(echo ":minimal:full:" | grep -ic ":$TYPE:") -eq 0 ]; then
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700110 >&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 +0000111 exit 1
112fi
113
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000114# Used to verify configuration values are set to "yes" or "no" value or convert
115# equivalents to "yes" or "no"
116function verify_yes_no() {
117 local VAR=$1
118 local VAL=$(eval echo \$$VAR)
119 if [ $(echo ":y:yes:true:n:no:false:1:0:" | grep -ic ":$VAL:") -eq 0 ]; then
120 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} Invalid '$VAR' value of '$VAL'. Should be 'yes' or 'no'${NORMAL}"
121 echo "INVALID"
122 return 1
123 fi
124 if [ $(echo ":y:yes:true:1:" | grep -ic ":$VAL:") -eq 1 ]; then
125 echo "yes"
126 else
127 echo "no"
128 fi
129 return 0
130}
Test User7d866122019-07-09 17:52:35 +0000131
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000132ALL_YES_NO="\
133 WITH_TIMINGS \
134 WITH_BBSIM \
135 WITH_RADIUS \
136 WITH_ONOS \
David Bainbridge99ac7a22019-08-31 02:26:43 +0000137 WITH_CHAOS \
David Bainbridge46505fb2019-10-01 21:13:20 +0000138 WITH_ADAPTERS \
139 WITH_SIM_ADAPTERS \
140 WITH_OPEN_ADAPTERS \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000141 CONFIG_SADIS \
142 JUST_K8S \
143 DEPLOY_K8S \
144 INSTALL_ONOS_APPS \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000145 INSTALL_KUBECTL \
146 INSTALL_HELM \
David Bainbridge46505fb2019-10-01 21:13:20 +0000147 UPDATE_HELM_REPOS \
David Bainbridge4f1b5562019-08-19 04:46:52 +0000148 WAIT_ON_DOWN \
David Bainbridge70c0ea82019-11-14 23:25:26 +0000149 ONLY_ONE \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000150 "
David Bainbridge5b7b96b2019-07-25 20:29:13 +0000151
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000152ALL_OPTIONS="\
153 NAME \
154 TYPE \
155 $ALL_YES_NO \
156 VOLTHA_LOG_LEVEL \
157 VOLTHA_CHART \
David Bainbridge90fd8e32019-08-21 23:32:47 +0000158 VOLTHA_CHART_VERSION \
159 VOLTHA_BBSIM_CHART \
160 VOLTHA_BBSIM_CHART_VERSION \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000161 VOLTHA_ADAPTER_SIM_CHART \
David Bainbridge90fd8e32019-08-21 23:32:47 +0000162 VOLTHA_ADAPTER_SIM_CHART_VERSION \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000163 VOLTHA_ADAPTER_OPEN_OLT_CHART \
David Bainbridge90fd8e32019-08-21 23:32:47 +0000164 VOLTHA_ADAPTER_OPEN_OLT_CHART_VERSION \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000165 VOLTHA_ADAPTER_OPEN_ONU_CHART \
David Bainbridge90fd8e32019-08-21 23:32:47 +0000166 VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION \
Andrea Campanella21323292019-12-18 11:44:19 -0800167 ONOS_CHART_VERSION \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000168 ONOS_API_PORT \
169 ONOS_SSH_PORT \
170 VOLTHA_API_PORT \
171 VOLTHA_SSH_PORT \
172 VOLTHA_ETCD_PORT \
David K. Bainbridge8f7f30b2020-01-08 13:06:16 -0800173 VK_RELEASE \
174 KIND_VERSION \
175 VOLTCTL_VERSION \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000176 "
David Bainbridge01294952019-07-30 19:33:45 +0000177
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000178# Iterate over yes/no configuration options and validate
179for VAR in $ALL_YES_NO; do
180 eval $VAR=$(verify_yes_no $VAR)
181 if [ "$(eval echo \$$VAR)" == "INVALID" ]; then
182 exit 1;
183 fi
184done
David Bainbridgeb270c202019-07-26 01:44:42 +0000185
David Bainbridge0774b232019-08-02 06:37:19 +0000186mkdir -p .voltha
187touch .voltha/ports
188HAVE=$(grep $NAME .voltha/ports)
189if [ "$HAVE X" == " X" ]; then
190 # Find free port prefix
191 START=81
192 while true; do
193 if [ $(grep -c $START .voltha/ports) -eq 0 ]; then
194 break
195 fi
196 START=$(expr $START + 1)
197 done
198 DELTA=$(expr $START - 81)
David Bainbridgea2595422019-10-22 03:54:28 +0000199 ONOS_API_PORT=${ONOS_API_PORT:-${START}81}
200 ONOS_SSH_PORT=${ONOS_SSH_PORT:-${START}01}
201 VOLTHA_API_PORT=${VOLTHA_API_PORT:-5$(expr 55 + $DELTA)55}
202 VOLTHA_SSH_PORT=${VOLTHA_SSH_PORT:-$(expr 50 + $DELTA)22}
203 VOLTHA_ETCD_PORT=${VOLTHA_ETCD_PORT:-$(expr 23 + $DELTA)79}
Test User01ed0642019-07-03 20:17:06 +0000204else
David Bainbridge0774b232019-08-02 06:37:19 +0000205 VALUES=$(echo $HAVE | sed -e 's/\s//g' | cut -d= -f2)
David Bainbridgea2595422019-10-22 03:54:28 +0000206 ONOS_API_PORT=${ONOS_API_PORT:-$(echo $VALUES | cut -d, -f1)}
207 ONOS_SSH_PORT=${ONOS_SSH_PORT:-$(echo $VALUES | cut -d, -f2)}
208 VOLTHA_API_PORT=${VOLTHA_API_PORT:-$(echo $VALUES | cut -d, -f3)}
209 VOLTHA_SSH_PORT=${VOLTHA_SSH_PORT:-$(echo $VALUES | cut -d, -f4)}
210 VOLTHA_ETCD_PORT=${VOLTHA_ETCD_PORT:-$(echo $VALUES | cut -d, -f5)}
Test User01ed0642019-07-03 20:17:06 +0000211fi
212
David Bainbridge0774b232019-08-02 06:37:19 +0000213PORTTMP=$(mktemp -u)
214cat .voltha/ports | grep -v $NAME > $PORTTMP
215echo "$NAME=$ONOS_API_PORT,$ONOS_SSH_PORT,$VOLTHA_API_PORT,$VOLTHA_SSH_PORT,$VOLTHA_ETCD_PORT" >> $PORTTMP
216cp $PORTTMP .voltha/ports
217rm -f $PORTTMP
218
David Bainbridge27790d62019-08-13 22:43:19 +0000219export ONOS_API_PORT ONOS_SSH_PORT
David Bainbridge01294952019-07-30 19:33:45 +0000220
Test Userd87942b2019-07-03 07:20:24 +0000221IDX=1
David Bainbridgee87067b2019-08-12 22:00:12 +0000222CLOCK="TIME:"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000223SPIN_PARTS=
224NOT_VERIFIED=
David Bainbridgef858a022019-08-14 21:25:11 +0000225THEX=
226BUILD=
227CROSS=
228ENTER=
David Bainbridge38dc1e82019-08-12 15:18:45 +0000229VERIFIED=
230HELM=
231OLD_KEY=
232BIRD=
233HIGH_VOLTAGE=
234PLUG=
235RESTART=
236FORWARD=
237INSTALL=
238STOP=
239GO=
240DOWNLOAD=
241GEAR=
242NO_ENTRY=
243LOCK=
244
245if [ $FANCY -eq 1 ]; then
246 SPIN_PARTS="\
247 \xe2\xa2\x8e\xe2\xa1\xb0 \
248 \xe2\xa2\x8e\xe2\xa1\xa1 \
249 \xe2\xa2\x8e\xe2\xa1\x91 \
250 \xe2\xa2\x8e\xe2\xa0\xb1 \
251 \xe2\xa0\x8e\xe2\xa1\xb1 \
252 \xe2\xa2\x8a\xe2\xa1\xb1 \
253 \xe2\xa2\x8c\xe2\xa1\xb1 \
254 \xe2\xa2\x86\xe2\xa1\xb1 \
255 "
David Bainbridgee87067b2019-08-12 22:00:12 +0000256 CLOCK="\xe2\x8f\xb1"
David Bainbridgef858a022019-08-14 21:25:11 +0000257 THEX="${RED}${BOLD}\xe2\x9c\x97\x20${NORMAL}"
258 ENTER="${YELLOW}${BOLD}\xe2\x8e\x86${NORMAL}"
259 CROSS="${YELLOW}${BOLD}\xe2\x9c\x9a${NORMAL}"
260 BUILD="${YELLOW}${BOLD}\xf0\x9f\x8f\x97${NORMAL}"
261 NOT_VERIFIED="$BUILD"
262 VERIFIED="${GREEN}${BOLD}\xe2\x9c\x93\x20${NORMAL}"
263 HELM="${BLUE}${BOLD}\xE2\x8E\x88${NORMAL}"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000264 OLD_KEY="\xF0\x9F\x97\x9D"
265 BIRD="\xF0\x9F\x90\xA6"
266 HIGH_VOLTAGE="\xE2\x9A\xA1"
267 PLUG="\xF0\x9F\xa7\xa9"
268 RESTART="\xf0\x9f\x94\x84"
269 FORWARD="\xE2\x87\xA8"
270 INSTALL="\xF0\x9F\x8F\x97"
271 STOP="\xf0\x9f\x9b\x91"
272 GO="\xf0\x9f\x9a\x80"
273 DOWNLOAD="\xf0\x9f\x93\xa5"
274 GEAR="\xe2\x9a\x99"
275 NO_ENTRY="\xe2\x9b\x94"
276 LOCK="\xf0\x9f\x94\x92"
277fi
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700278
David Bainbridge712afb82019-08-14 19:55:58 +0000279duration() {
David Bainbridgee87067b2019-08-12 22:00:12 +0000280 local h=$(expr $1 / 3600)
281 local m=$(expr $1 % 3600 / 60)
282 local s=$(expr $1 % 60)
283 local t=""
284
285 if [ $h -gt 0 ]; then
286 t="$t${h}h"
287 fi
288 if [ $m -gt 0 ]; then
289 t="$t${m}m"
290 fi
David Bainbridge712afb82019-08-14 19:55:58 +0000291 echo "$t${s}s"
292}
293
294printtime() {
295 local INDENT=
296 if [ "$1" == "-" ]; then
297 INDENT=" "
298 shift
299 fi
300 echo -e "$INDENT $CLOCK $(duration $1)"
David Bainbridgee87067b2019-08-12 22:00:12 +0000301}
302
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700303bspin() {
Test Userd87942b2019-07-03 07:20:24 +0000304 IDX=1
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700305 local INDENT=
306 if [ "$1" == "-" ]; then
307 INDENT=" "
308 shift
309 fi
David Bainbridge38dc1e82019-08-12 15:18:45 +0000310 if [ $FANCY -eq 0 ]; then
311 LINE=$(echo $* | sed -e 's/[\s+-]//g')
312 if [ "$LINE X" == " X" ]; then
313 return
314 fi
315 echo -e "$CIVIS$INDENT$*"
316 else
317 echo -en "$CIVIS$INDENT $*"
318 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700319}
320
321sspin() {
322 local INDENT=
323 if [ "$1" == "-" ]; then
324 INDENT=" "
325 shift
326 fi
David Bainbridge38dc1e82019-08-12 15:18:45 +0000327 if [ $FANCY -eq 0 ]; then
328 LINE=$(echo $* | sed -e 's/[\s+-]//g')
329 if [ "$LINE X" == " X" ]; then
330 return
331 fi
332 echo -e "$INDENT$*"
333 else
334 C=$(echo $SPIN_PARTS | cut '-d ' -f $IDX)
335 echo -en "\r$INDENT$C $*"
336 IDX=$(expr $IDX + 1)
337 if [ $IDX -gt 8 ]; then
338 IDX=1
339 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700340 fi
341}
342
343espin() {
344 local INDENT=
345 if [ "$1" == "-" ]; then
346 INDENT=" "
347 shift
348 fi
David Bainbridge38dc1e82019-08-12 15:18:45 +0000349 if [ $FANCY -eq 0 ]; then
350 LINE=$(echo $* | sed -e 's/[\s+-]//g')
351 if [ "$LINE X" == " X" ]; then
352 return
353 fi
354 echo -e "$INDENT$*"
355 else
356 echo -e "\r$INDENT$*$CNORM"
357 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700358}
359
David Bainbridgeac7f8072019-08-01 22:15:33 +0000360if [ "$1" == "get" -a "$2" == "voltconfig" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000361 echo "$HOME/.volt/config-$NAME"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000362 exit
363fi
364
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -0700365if [ $# -ne 1 -o $(echo ":up:down:dump:" | grep -c ":$1:") -ne 1 ]; then
David Bainbridgeac7f8072019-08-01 22:15:33 +0000366 >&2 echo "What wouild you like to do today:"
367 >&2 echo " up - bring up voltha"
368 >&2 echo " down - tear down voltha"
369 >&2 echo " dump - create a debug dump of running system"
370 exit 1
371fi
372
David Bainbridge4f1b5562019-08-19 04:46:52 +0000373push_onos_config() {
374 local MSG=$1
375 local RESOURCE=$2
376 local DATA=$3
377
378 bspin - "$MSG $GEAR"
379 while true; do
380 (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
381 if [ $? -eq 0 ]; then
382 break
383 fi
Matteo Scandolo9a77a732020-01-09 14:24:12 -0800384 sleep 1
David Bainbridge4f1b5562019-08-19 04:46:52 +0000385 sspin -
386 done
387 espin - $VERIFIED
388}
389
Matteo Scandolo9a77a732020-01-09 14:24:12 -0800390check_onos_app_active() {
391 local APP_ID=$1
392
393 bspin - "Checking that $APP_ID is active $CLOCK"
394 while true; do
395 (set -x; curl --fail -sSL --user karaf:karaf -X GET http://127.0.0.1:$ONOS_API_PORT/onos/v1/applications/$APP_ID | grep ACTIVE >>$LOG 2>&1) >>$LOG 2>&1
396 if [ $? -eq 0 ]; then
397 break
398 fi
399 sleep 1
400 sspin -
401 done
402 sleep 5 # OSGI components take a little longer that the app to activate
403 espin - $VERIFIED
404}
405
David Bainbridge4f1b5562019-08-19 04:46:52 +0000406override_onos_app() {
407 local APP=$1
408 local NAME=$(basename $APP | sed -e 's/^[0-9][0-9]*-//g' -e 's/-.*$//g')
409 while true; do
410 sspin -
411 # Attempt to delete old version (if it exists)
412 (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
413 sspin -
414 if [ $? -ne 0 ]; then
415 continue
416 fi
417 (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
418 if [ $? -eq 0 ]; then
419 break
420 fi
421 sleep .2
422 done
423}
424
425activate_onos_app() {
426 local MSG="$1"
427 local APP=$2
428
429 bspin - "$MSG $GO"
430 while true; do
431 sspin -
432 (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
433 if [ $? -eq 0 ]; then
434 break
435 fi
436 sleep .2
437 done
438 espin - "$VERIFIED"
439}
440
441count_pods() {
442 local NAMESPACE=$1; shift
443 if [ "$NAMESPACE" == "all-namespaces" ]; then
444 NAMESPACE="--all-namespaces"
445 else
446 NAMESPACE="-n $NAMESPACE"
447 fi
448 echo "$NAMESPACE" > /tmp/t
449 local STATES=$1; shift
450 echo "$STATES" >> /tmp/t
451 local PODS=$(kubectl get $NAMESPACE pod -o go-template="{{range .items}}{{.metadata.name}}/{{.status.phase}}/_{{range .status.containerStatuses}}{{.ready}}_{{end}} {{end}}")
452 local COUNT=0
453 local PATTERNS="$*"
454 for POD in $PODS; do
455 local NAME=$(echo $POD | cut -d/ -f 1)
456 local STATE=$(echo $POD | cut -d/ -f 2)
457 local CONTAINERS=$(echo $POD | cut -d/ -f 3 | sed -e 's/_/ /g')
458 if [ "$STATES" == "*" -o $(echo "$STATES" | grep -c ":$STATE:") -ne 0 ]; then
459 echo "IN WITH $POD" >> /tmp/t
460 local TOTAL=$(echo $CONTAINERS | wc -w)
461 local FOUND=$(echo $CONTAINERS | grep -o true | wc -l)
462 if [ $TOTAL -eq $FOUND ]; then
463 for PATTERN in $PATTERNS; do
464 echo "TEST $PATTERN AGAINST $NAME" >> /tmp/t
465 if [[ $NAME =~ $PATTERN ]]; then
466 echo "COUNT $NAME" >> /tmp/t
467 COUNT=$(expr $COUNT + 1)
468 break
469 fi
470 done
471 fi
472 fi
473 done
474 echo $COUNT >> /tmp/t
475 echo $COUNT
476}
477
478wait_for_pods() {
479 local INDENT=
480 if [ "$1" == "-" ]; then
481 INDENT=$1; shift
482 fi
483 local NAMESPACE=$1; shift
484 local EXPECT=$1; shift
485 local TYPE=$1; shift
486 local RETRY=$1; shift
487 local MESSAGE=$1; shift
488 local PATTERNS=$*
David Bainbridge99ac7a22019-08-31 02:26:43 +0000489 local STATES=":Running:"
490 if [ "$TYPE" == "not" ]; then
491 STATES="*"
492 fi
493 local HAVE=$(count_pods $NAMESPACE "$STATES" $PATTERNS)
David Bainbridge4f1b5562019-08-19 04:46:52 +0000494 local ALL=$HAVE
495 if [ "$TYPE" == "only" ]; then
496 ALL=$(count_pods "all-namespaces" "*" ".*")
497 fi
498 COUNT=$(expr 300 / 15)
499 bspin $INDENT $MESSAGE
500 sspin $INDENT
501 if [ $HAVE -ne $EXPECT -o $ALL -ne $HAVE ]; then
502 while [ $HAVE -ne $EXPECT -o $ALL -ne $HAVE ]; do
503 sspin $INDENT
504 COUNT=$(expr $COUNT - 1)
505 if [ $COUNT -eq 0 ]; then
David Bainbridge99ac7a22019-08-31 02:26:43 +0000506 HAVE=$(count_pods $NAMESPACE "$STATES" $PATTERNS)
David Bainbridge4f1b5562019-08-19 04:46:52 +0000507 ALL=$HAVE
508 if [ "$TYPE" == "only" ]; then
509 ALL=$(count_pods "all-namespaces" "*" ".*")
510 fi
511 COUNT=$(expr 300 / 15)
512 fi
513 sleep .15
514 done
515 fi
516 espin $INDENT $VERIFIED
517 if [ $HAVE -ne $EXPECT ]; then
518 return 1
519 fi
520 return 0
521}
522
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800523port_forward() {
524 local NS=$1
525 local SVC=$2
526 local FROM_PORT=$3
527 local TO_PORT=$4
528 local TAG=$SVC-$NAME
529
530 (set -x; _TAG=$TAG bash -c "while true; do kubectl port-forward -n $NS service/$SVC $FROM_PORT:$TO_PORT; done" >>$LOG 2>&1 &) >>$LOG 2>&1
531}
532
533kill_port_forward() {
534 local TAG=$1-$NAME
David Bainbridgec6871d22019-11-13 17:10:31 +0000535 local P_IDS=$(ps e -ww -A | grep "_TAG=$TAG" | grep -v grep | awk '{print $1}')
David Bainbridgebcf235b2019-11-12 21:33:58 +0000536 local PARENTS=
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800537 local KIDS=
David Bainbridgec6871d22019-11-13 17:10:31 +0000538 local UNKNOWN=
539 if [ ! -z "$P_IDS" ]; then
540 for P_ID in $P_IDS; do
541 local PP_ID=$(ps -o ppid $P_ID | tail -n +2)
542 if [ ! -z "$PP_ID" ]; then
543 if [ $PP_ID -eq 1 ]; then
544 PARENTS="$PARENTS $P_ID"
545 else
546 KIDS="$KIDS $P_ID"
547 fi
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800548 else
David Bainbridgec6871d22019-11-13 17:10:31 +0000549 UNKNOWN="$UNKNOWN $P_ID"
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800550 fi
551 done
David Bainbridgec6871d22019-11-13 17:10:31 +0000552 (set -x; kill -9 $PARENTS $KIDS $UNKNOWN >>$LOG 2>&1) >>$LOG 2>&1
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800553 fi
554}
555
David Bainbridgeac7f8072019-08-01 22:15:33 +0000556if [ "$1" == "down" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000557 echo "Tearing down voltha cluster $NAME"
558 LOG="down-$NAME.log"
559 echo $(date -u +"%Y%m%dT%H%M%SZ") >$LOG
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800560 bspin "Remove port-forwards: onos-ui-$NAME"
561 kill_port_forward onos-ui
562 sspin "Remove port-forwards: onos-ssh-$NAME$CEOL"
563 kill_port_forward onos-ssh
564 sspin "Remove port-forwards: voltha-api-$NAME$CEOL"
565 kill_port_forward voltha-api
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800566 sspin "Remove port-forwards: voltha-etcd-$NAME$CEOL"
567 kill_port_forward voltha-etcd-cluster-client
568 espin "$VERIFIED Remove port-forwards$CEOL"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000569 if [ $DEPLOY_K8S == "yes" ]; then
570 if [ -x ./bin/kind ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000571 bspin "Delete Kubernetes Kind Cluster"
572 (set -x; ./bin/kind delete cluster --name voltha-$NAME >>$LOG 2>&1) >>$LOG 2>&1
573 espin $VERIFIED
David Bainbridgeac7f8072019-08-01 22:15:33 +0000574 else
David Bainbridge0774b232019-08-02 06:37:19 +0000575 espin "$NO_ENTRY Delete Kubernetes Kind Cluster: kind command not found"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000576 fi
577 else
578 EXISTS=$(helm list -q)
579 EXPECT="etcd-operator onos open-olt open-onu sim voltha bbsim radius"
David Bainbridge0774b232019-08-02 06:37:19 +0000580 bspin "Remove Helm Deployments"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000581 for i in $EXISTS; do
582 if [ $(echo $EXPECT | grep -c $i) -eq 1 ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000583 sspin "Remove Helm Deployments: $i$CEOL"
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800584 (set -x; ./bin/helm delete --no-hooks --purge $i >>$LOG 2>&1) >>$LOG 2>&1
David Bainbridgeac7f8072019-08-01 22:15:33 +0000585 fi
586 done
David Bainbridge0774b232019-08-02 06:37:19 +0000587 espin "$VERIFIED Remove Helm Deployments$CEOL"
David Bainbridge4f1b5562019-08-19 04:46:52 +0000588 if [ "$WAIT_ON_DOWN" == "yes" ]; then
589 # There should only be 13 or 15 PODs in the kube-system name
590 # space and no other PODs
David Bainbridge4f1b5562019-08-19 04:46:52 +0000591 PODS="coredns-.* \
592 etcd-voltha-$NAME-control-plane \
593 kindnet-.* \
594 kube-apiserver-voltha-$NAME-control-plane \
595 kube-controller-manager-voltha-$NAME-control-plane \
596 kube-proxy-.* \
597 kube-scheduler-voltha-$NAME-control-plane \
598 tiller-deploy-.*"
599 EXPECT=$(test "$TYPE" == "minimal" && echo "13" || echo "15")
David Bainbridge99ac7a22019-08-31 02:26:43 +0000600 PODS="adapter-.* \
601 bbsim.* \
602 etcd-operator.* \
603 radius.* \
604 voltha-.*"
Matteo Scandolofab98622020-01-28 15:17:20 -0800605 ONOS_PODS="onos-.*"
David Bainbridge99ac7a22019-08-31 02:26:43 +0000606 EXPECT=0
607
Matteo Scandolofab98622020-01-28 15:17:20 -0800608 wait_for_pods "default" $EXPECT "not" -1 "Waiting for ONOS PODs to terminate" $ONOS_PODS
David Bainbridge99ac7a22019-08-31 02:26:43 +0000609 wait_for_pods "voltha" $EXPECT "not" -1 "Waiting for VOLTHA PODs to terminate" $PODS
David Bainbridge4f1b5562019-08-19 04:46:52 +0000610 fi
David Bainbridgeac7f8072019-08-01 22:15:33 +0000611 fi
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -0700612 exit
David Bainbridgeac7f8072019-08-01 22:15:33 +0000613fi
614
615if [ "$1" == "dump" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000616 LOG="dump-$NAME.log"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000617 TS=$(date -u +"%Y%m%dT%H%M%SZ")
David Bainbridge76514a02019-10-08 01:50:35 +0000618 if [ ! -z "$DUMP_FROM" ]; then
619 TS=$(echo $DUMP_FROM | sed -e 's/[:-]//g')
620 fi
David Bainbridgeac7f8072019-08-01 22:15:33 +0000621 WORK=$(mktemp -u -d)
David Bainbridge0774b232019-08-02 06:37:19 +0000622 DATA=$WORK/voltha-debug-dump-$NAME-$TS
David Bainbridgeac7f8072019-08-01 22:15:33 +0000623 mkdir -p $DATA
624 echo $TS > $LOG
David Bainbridge0774b232019-08-02 06:37:19 +0000625 echo -e "Capturing debug dump to voltha-debug-dump-$NAME-$TS.tgz"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000626 bspin - "Copy install log"
David Bainbridge0774b232019-08-02 06:37:19 +0000627 if [ -f install-$NAME.log ]; then
628 (set -x; cp install-$NAME.log $DATA/install-$NAME.log) >>$LOG 2>&1
David Bainbridgeac7f8072019-08-01 22:15:33 +0000629 espin - $VERIFIED
630 else
David Bainbridge0774b232019-08-02 06:37:19 +0000631 espin - "$NO_ENTRY Copy install log: install-$NAME.log not found"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000632 fi
633 bspin - "Dumping Kubernetes PODs"
634 (set -x; kubectl get --all-namespaces pods >> $DATA/all-pods.txt 2>&1) >>$LOG 2>&1
635 espin - $VERIFIED
636 bspin - "Dumping Kubernetes SERVICEs"
637 (set -x; kubectl get --all-namespaces svc >> $DATA/all-services.txt 2>&1) >>$LOG 2>&1
638 espin - $VERIFIED
639 bspin - "Dumping Kubernetes EVENTs"
640 (set -x; kubectl get --all-namespaces events >> $DATA/all-events.txt 2>&1) >>$LOG 2>&1
641 espin - $VERIFIED
642 bspin - "Dumping VOLTHA POD details"
Matteo Scandolodcd29f52019-10-07 15:42:42 -0700643 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 +0000644 SINCE=
645 if [ ! -z "$DUMP_FROM" ]; then
646 SINCE="--since-time=$DUMP_FROM"
647 fi
David Bainbridgeac7f8072019-08-01 22:15:33 +0000648 for POD in $PODS; do
David Bainbridge1f0655a2019-10-01 22:08:48 +0000649 NS=$(echo $POD | cut -d: -f1)
650 POD=$(echo $POD | cut -d: -f2)
David Bainbridgeac7f8072019-08-01 22:15:33 +0000651 sspin - "Dumping VOLTHA POD details: $POD$CEOL"
652 mkdir -p $DATA/$POD
David Bainbridge1f0655a2019-10-01 22:08:48 +0000653 (set -x; kubectl describe -n $NS $POD >> $DATA/$POD/describe.txt 2>&1) >>$LOG 2>&1
David Bainbridgeac7f8072019-08-01 22:15:33 +0000654 sspin - "Dumping VOLTHA POD details: $POD"
David Bainbridgecfd7ca12019-10-06 03:31:41 +0000655 (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 +0000656 sspin - "Dumping VOLTHA POD details: $POD"
David Bainbridgecfd7ca12019-10-06 03:31:41 +0000657 (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 +0000658 sspin - "Dumping VOLTHA POD details: $POD"
659 done
660 espin - "$VERIFIED Dumping VOLTHA POD details$CEOL"
661 bspin - "Dumping ETCD"
662 if [ "$(which etcdctl) X" != " X" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000663 (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 +0000664 espin - $VERIFIED
665 else
666 espin - "$NO_ENTRY Dumping ETCD: etcdctl command not available"
667 fi
David Bainbridge0774b232019-08-02 06:37:19 +0000668 bspin - "Creating compressed TAR: voltha-debug-dump-$NAME-$TS.tgz"
669 (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 +0000670 espin - $VERIFIED
671 bspin - "Cleanup"
672 (set -x; rm -rf $WORK) >>$LOG 2>&1
673 espin - $VERIFIED
David Bainbridge0774b232019-08-02 06:37:19 +0000674 bspin - "$(ls -l voltha-debug-dump-$NAME-$TS.tgz)"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000675 espin - $VERIFIED
676 exit
677fi
678
David Bainbridge0774b232019-08-02 06:37:19 +0000679LOG="install-$NAME.log"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000680date > $LOG
David Bainbridge0774b232019-08-02 06:37:19 +0000681echo "PORTS=$ONOS_API_PORT,$ONOS_SSH_PORT,$VOLTHA_API_PORT,$VOLTHA_SSH_PORT,$VOLTHA_ETCD_PORT" >> $LOG
David Bainbridgeac7f8072019-08-01 22:15:33 +0000682
683# Output install options to log
684echo "OPTIONS" >> $LOG
David Bainbridgeac7f8072019-08-01 22:15:33 +0000685for O in $ALL_OPTIONS; do
686 VAL=$(eval echo \$$O)
David Bainbridgeac7f8072019-08-01 22:15:33 +0000687 if [ ! -z "$VAL" ]; then
688 printf " %-30s = %s\n" $O $VAL >> $LOG
689 fi
690done
691
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -0700692helm_install() {
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700693 local INDENT=
694 if [ "$1" == "-" ]; then
695 INDENT=$1; shift
696 fi
697 local NAMESPACE=$1; shift
David Bainbridge0774b232019-08-02 06:37:19 +0000698 local INAME=$1; shift
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700699 local CHART=$1; shift
David Bainbridge90fd8e32019-08-21 23:32:47 +0000700 local CHART_VERSION=$1; shift
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700701 local MESSAGE=$*
702
David Bainbridge90fd8e32019-08-21 23:32:47 +0000703 if [ "$CHART_VERSION X" != " X" -a "$CHART_VERSION" != "latest" ]; then
704 CHART_VERSION="--version $CHART_VERSION"
705 else
706 CHART_VERSION=
707 fi
708
David Bainbridge99ac7a22019-08-31 02:26:43 +0000709 local CHART_ARGS=
710 if [ -r "${INAME}-values.yaml" ]; then
711 CHART_ARGS="-f ${INAME}-values.yaml"
712 fi
713
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700714 COUNT=$(expr 300 / 15)
715 bspin $INDENT $MESSAGE
David Bainbridge70c0ea82019-11-14 23:25:26 +0000716 (set -x; helm install -f $NAME-values.yaml $CHART_ARGS $EXTRA_HELM_INSTALL_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 -0700717 SUCCESS=$?
718 while [ $SUCCESS -ne 0 ]; do
719 sspin $INDENT
720 COUNT=$(expr $COUNT - 1)
721 if [ $COUNT -eq 0 ]; then
Andy Baviere22ff252019-12-19 11:40:31 -0700722 (set -x; helm delete --purge $INAME >>$LOG 2>&1) >>$LOG 2>&1
David Bainbridge99ac7a22019-08-31 02:26:43 +0000723 (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
Andy Baviere22ff252019-12-19 11:40:31 -0700724 SUCCESS=$?
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700725 COUNT=$(expr 300 / 15)
726 fi
727 sleep .15
728 done
729 espin $INDENT $VERIFIED
730}
731
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700732echo "INSTALL TYPE: $TYPE" >> $LOG
733
734bspin "Verify GOPATH"
735export GOPATH=$(pwd)
Test User3d7ad8e2019-07-03 06:15:44 +0000736mkdir -p $GOPATH/bin
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700737espin $VERIFIED
738
David Bainbridgee87067b2019-08-12 22:00:12 +0000739STIME=$(date +%s)
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700740if [ "$INSTALL_KUBECTL" == "no" ]; then
741 bspin "Skip kubectl install"
742 espin $NO_ENTRY
Test Userc13bdc92019-07-03 20:57:49 +0000743else
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700744 bspin "Verify kubectl $HELM"
745 if [ -x $GOPATH/bin/kubectl ]; then
746 espin $VERIFIED
747 else
748 espin $NOT_VERIFIED
749 bspin - "Download and install Kubernetes/kubectl $DOWNLOAD"
750 (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
751 (set -x; chmod 755 $GOPATH/bin/kubectl >>$LOG 2>&1) >>$LOG 2>&1
752 espin - $VERIFIED
753 fi
Test Userc13bdc92019-07-03 20:57:49 +0000754fi
David Bainbridgee87067b2019-08-12 22:00:12 +0000755if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +0000756 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +0000757fi
Test Userc13bdc92019-07-03 20:57:49 +0000758
David Bainbridgee87067b2019-08-12 22:00:12 +0000759STIME=$(date +%s)
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700760if [ "$DEPLOY_K8S" == "no" ]; then
761 bspin "Skip Kubernetes/Kind Deployment"
762 espin $NO_ENTRY
763else
Test Userba1e7e72019-07-10 22:27:54 +0000764 bspin "Verify Kubernetes/Kind $HELM"
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800765 IS_INSTALLED=0
766 OP_TYPE="install"
Test Userba1e7e72019-07-10 22:27:54 +0000767 if [ -x $GOPATH/bin/kind ]; then
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800768 OP_TYPE="upgrade"
769 if [ $($GOPATH/bin/kind --version | grep -c $KIND_VERSION) -eq 1 ]; then
770 IS_INSTALLED=1
771 espin $VERIFIED
772 fi
773 fi
774 if [ $IS_INSTALLED -eq 0 ]; then
Test Userba1e7e72019-07-10 22:27:54 +0000775 espin $NOT_VERIFIED
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800776 bspin - "Download and $OP_TYPE Kubernetes/kind $DOWNLOAD"
David Bainbridge9e2a6662019-07-11 17:07:57 +0000777 (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 +0000778 (set -x; chmod 755 $GOPATH/bin/kind >>$LOG 2>&1) >>$LOG 2>&1
779 espin - $VERIFIED
780 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700781fi
782
David Bainbridgee87067b2019-08-12 22:00:12 +0000783if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +0000784 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +0000785fi
786
787STIME=$(date +%s)
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700788if [ "$INSTALL_HELM" == "no" ]; then
789 bspin "Skip Helm Install"
790 espin $NO_ENTRY
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700791else
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700792 bspin "Verify Helm $HELM"
793 if [ -x $GOPATH/bin/helm ]; then
794 espin $VERIFIED
795 else
796 espin $NOT_VERIFIED
797 bspin - "Download and install Helm $DOWNLOAD"
David Bainbridgec6a6eb62019-10-18 22:50:07 +0000798 (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 -0700799 espin - $VERIFIED
800 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700801fi
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800802
David Bainbridgee87067b2019-08-12 22:00:12 +0000803if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +0000804 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +0000805fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700806
David Bainbridgee87067b2019-08-12 22:00:12 +0000807STIME=$(date +%s)
Test Userb5712372019-07-03 21:52:17 +0000808bspin "Verify voltctl $HIGH_VOLTAGE"
David Bainbridged2811972019-12-14 01:14:09 +0000809VOK=0
810VMESSAGE="install"
Test User3d7ad8e2019-07-03 06:15:44 +0000811if [ -x $GOPATH/bin/voltctl ]; then
David Bainbridge1ba64f12019-12-18 00:40:13 +0000812 VHAVE=$($GOPATH/bin/voltctl version --clientonly -o json | jq -r .version)
813 if [ $? -eq 0 -a "$VHAVE" == "$VOLTCTL_VERSION" ]; then
David Bainbridged2811972019-12-14 01:14:09 +0000814 VOK=1
David Bainbridge1ba64f12019-12-18 00:40:13 +0000815 espin $VERIFIED
816 else
817 VMESSAGE="upgrade"
David Bainbridged2811972019-12-14 01:14:09 +0000818 fi
819fi
820
David Bainbridge1ba64f12019-12-18 00:40:13 +0000821if [ $VOK -eq 0 ]; then
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700822 espin $NOT_VERIFIED
David Bainbridged2811972019-12-14 01:14:09 +0000823 bspin - "Download and $VMESSAGE voltctl $DOWNLOAD"
David Bainbridge28c64462019-12-12 22:25:26 +0000824 (set -x; curl -o $GOPATH/bin/voltctl -sSL https://github.com/opencord/voltctl/releases/download/v$VOLTCTL_VERSION/voltctl-$VOLTCTL_VERSION-$HOSTOS-$HOSTARCH >>$LOG 2>&1) >>$LOG 2>&1
Test User08ebbd92019-07-03 17:15:39 +0000825 (set -x; chmod 755 $GOPATH/bin/voltctl >>$LOG 2>&1) >>$LOG 2>&1
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700826 espin - $VERIFIED
827fi
David Bainbridgee87067b2019-08-12 22:00:12 +0000828if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +0000829 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +0000830fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700831
832bspin "Verify command PATH"
Test Userba1e7e72019-07-10 22:27:54 +0000833export PATH=$GOPATH/bin:$PATH
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700834espin $VERIFIED
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700835
David Bainbridgee87067b2019-08-12 22:00:12 +0000836STIME=$(date +%s)
Test Userba1e7e72019-07-10 22:27:54 +0000837if [ "$DEPLOY_K8S" == "yes" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000838 HAVE=$(kind get clusters | grep -c voltha-$NAME)
Test Userba1e7e72019-07-10 22:27:54 +0000839 bspin "Verify Kubernetes/Kind Cluster"
840 sspin
841 if [ $HAVE -eq 0 ]; then
David Bainbridge491b1bd2019-07-11 17:53:11 +0000842 espin $NOT_VERIFIED
843 bspin - "Verify cluster configuration"
David Bainbridge0774b232019-08-02 06:37:19 +0000844 if [ ! -r ./$NAME-cluster.cfg ]; then
David Bainbridge491b1bd2019-07-11 17:53:11 +0000845 espin - $NOT_VERIFIED
David Bainbridge0774b232019-08-02 06:37:19 +0000846 bspin - "Download cluster configuration: $TYPE-cluster.cfg to $NAME-cluster.cfg $DOWNLOAD"
David K. Bainbridgea00736b2020-01-08 14:33:17 -0800847 ERR_OUT=$(mktemp)
848 (set -x; curl --fail -o ./$NAME-cluster.cfg -sSL https://raw.githubusercontent.com/ciena/kind-voltha/$VK_RELEASE/$TYPE-cluster.cfg >>$LOG 2>>$ERR_OUT) >>$LOG 2>&1
849 if [ $? -ne 0 ]; then
850 espin - $THEX
851 echo -e "${RED}${BOLD}${ERROR}ERROR: $NAME-cluster.cfg${NORMAL}${RED} - $(cat $ERR_OUT)${NORMAL}"
852 echo "ERROR: $(cat $ERR_OUT)" >>$LOG
853 rm -rf $ERR_OUT ./$NAME-cluster.cfg
854 exit 1
855 fi
856 rm -rf $ERR_OUT
857 else
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700858 espin - $VERIFIED
David K. Bainbridgea00736b2020-01-08 14:33:17 -0800859 fi
David Bainbridge0774b232019-08-02 06:37:19 +0000860 kind create cluster --name voltha-$NAME --config $NAME-cluster.cfg
David Bainbridge491b1bd2019-07-11 17:53:11 +0000861 else
862 espin $VERIFIED
Test Userba1e7e72019-07-10 22:27:54 +0000863 fi
864
David Bainbridge0774b232019-08-02 06:37:19 +0000865 export KUBECONFIG="$(kind get kubeconfig-path --name="voltha-$NAME")"
Test Userba1e7e72019-07-10 22:27:54 +0000866 P="coredns-.* \
David Bainbridge0774b232019-08-02 06:37:19 +0000867 etcd-voltha-$NAME-control-plane \
Test Userba1e7e72019-07-10 22:27:54 +0000868 kindnet-.* \
David Bainbridge0774b232019-08-02 06:37:19 +0000869 kube-apiserver-voltha-$NAME-control-plane \
870 kube-controller-manager-voltha-$NAME-control-plane \
Test Userba1e7e72019-07-10 22:27:54 +0000871 kube-proxy-.* \
David Bainbridge0774b232019-08-02 06:37:19 +0000872 kube-scheduler-voltha-$NAME-control-plane"
Test Userba1e7e72019-07-10 22:27:54 +0000873
874 EXPECT=$(test "$TYPE" == "minimal" && echo "12" || echo "14")
David Bainbridge4f1b5562019-08-19 04:46:52 +0000875 wait_for_pods - "kube-system" $EXPECT "includes" -1 "Waiting for system PODs to start" $P
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700876fi
David Bainbridgee87067b2019-08-12 22:00:12 +0000877if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +0000878 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +0000879fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700880
David Bainbridgee87067b2019-08-12 22:00:12 +0000881STIME=$(date +%s)
David Bainbridge4c6289c2019-09-03 21:11:32 +0000882COUNT=$(count_pods "kube-system" ":Running:" "tiller-deploy-.*")
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700883bspin "Verify Helm"
Test Userba1e7e72019-07-10 22:27:54 +0000884if [ $COUNT -ne 1 ]; then
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700885 espin $NOT_VERIFIED
Test Userb5712372019-07-03 21:52:17 +0000886 echo -e "Configuring Helm $GEAR"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700887 if [ "$INSTALL_HELM" == "no" ]; then
888 bspin - "Skip Helm/Tiller Initialization"
889 espin - $NO_ENTRY
890 else
891 bspin - "Initialize Helm"
892 (set -x; helm init --upgrade >>$LOG 2>&1) >>$LOG 2>&1
893 espin - $VERIFIED
David Bainbridge4f1b5562019-08-19 04:46:52 +0000894 wait_for_pods - "kube-system" 1 "includes" -1 "Waiting for Tiller POD to start" "tiller-deploy-.*"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700895 fi
Test Userb5712372019-07-03 21:52:17 +0000896 bspin - "Add Google Incubator repository to Helm"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700897 (set -x; helm repo add incubator https://kubernetes-charts-incubator.storage.googleapis.com >>$LOG 2>&1) >>$LOG 2>&1
898 espin - $VERIFIED
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -0700899
Test Userba1e7e72019-07-10 22:27:54 +0000900 # HACK (sort-of) - the config for tiller is about to be patched, which will
901 # cause the tiller pod to be recreated. This can sometimes cause a timing
902 # issue with the "wait_for_pods" call on tiller as it may incorrectly
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -0700903 # identify the running/ready tiller pod that is soon to be terminated as
Test Userba1e7e72019-07-10 22:27:54 +0000904 # what it is waiting for. To avoid this issue we do a clean scale down and
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -0700905 # scale up of the pod so the script controlls when it should be expecting
Test Userba1e7e72019-07-10 22:27:54 +0000906 # things
907 (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 -0700908
Test Userb5712372019-07-03 21:52:17 +0000909 bspin - "Add Google Stable repository to Helm"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700910 (set -x; helm repo add stable https://kubernetes-charts.storage.googleapis.com >>$LOG 2>&1) >>$LOG 2>&1
911 espin - $VERIFIED
Test Userb5712372019-07-03 21:52:17 +0000912 bspin - "Add ONF repository to Helm"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700913 (set -x; helm repo add onf https://charts.opencord.org >>$LOG 2>&1) >>$LOG 2>&1
914 espin - $VERIFIED
Test Userb5712372019-07-03 21:52:17 +0000915 bspin - "Update Helm repository cache"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700916 (set -x; helm repo update >>$LOG 2>&1) >>$LOG 2>&1
917 espin - $VERIFIED
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -0700918
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700919 # Create and k8s service account so that Helm can create pods
Test Userb5712372019-07-03 21:52:17 +0000920 bspin - "Create Tiller ServiceAccount"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700921 (set -x; kubectl create serviceaccount --namespace kube-system tiller >>$LOG 2>&1) >>$LOG 2>&1
922 espin - $VERIFIED
Test Userb5712372019-07-03 21:52:17 +0000923 bspin - "Create Tiller ClusterRoleBinding"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700924 (set -x; kubectl create clusterrolebinding tiller-cluster-rule --clusterrole=cluster-admin --serviceaccount=kube-system:tiller >>$LOG 2>&1) >>$LOG 2>&1
925 espin - $VERIFIED
Test Userb5712372019-07-03 21:52:17 +0000926 bspin - "Update Tiller Manifest"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700927 (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 +0000928
929 # HACK (sort-of) - part to, spin it back up
930 (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 -0700931 espin - $VERIFIED
932else
933 espin $VERIFIED
David Bainbridge46505fb2019-10-01 21:13:20 +0000934 if [ "$UPDATE_HELM_REPOS" == "yes" ]; then
935 bspin - "Update Helm repository cache"
936 (set -x; helm repo update >>$LOG 2>&1) >>$LOG 2>&1
937 espin - $VERIFIED
938 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700939fi
David Bainbridge4f1b5562019-08-19 04:46:52 +0000940wait_for_pods - "kube-system" 1 "includes" -1 "Waiting for Tiller POD to start" "tiller-deploy-.*"
David Bainbridgee87067b2019-08-12 22:00:12 +0000941if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +0000942 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +0000943fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700944
David Bainbridgee87067b2019-08-12 22:00:12 +0000945STIME=$(date +%s)
David Bainbridge0774b232019-08-02 06:37:19 +0000946bspin "Verify Helm values file: $NAME-values.yaml"
947if [ ! -r "./$NAME-values.yaml" ]; then
Test Userba1e7e72019-07-10 22:27:54 +0000948 espin $NOT_VERIFIED
David Bainbridge0774b232019-08-02 06:37:19 +0000949 bspin - "Download Helm values file: $TYPE-values.yaml to $NAME-values.yaml $DOWNLOAD"
David K. Bainbridgea00736b2020-01-08 14:33:17 -0800950 ERR_OUT=$(mktemp)
951 (set -x; curl --fail -o ./$NAME-values.yaml -sSL https://raw.githubusercontent.com/ciena/kind-voltha/$VK_RELEASE/$TYPE-values.yaml >>$LOG 2>$ERR_OUT) >>$LOG 2>&1
952 if [ $? -ne 0 ]; then
953 espin - $THEX
954 echo -e "${RED}${BOLD}${ERROR}ERROR: $NAME-values.yaml${NORMAL}${RED} - $(cat $ERR_OUT)${NORMAL}"
955 echo "ERROR: $(cat $ERR_OUT)" >>$LOG
956 rm -rf $ERR_OUT ./$NAME-values.yaml
957 exit 1
958 fi
959 rm -rf $ERR_OUT
Test Userba1e7e72019-07-10 22:27:54 +0000960 espin - $VERIFIED
961else
962 espin $VERIFIED
963fi
David Bainbridgee87067b2019-08-12 22:00:12 +0000964if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +0000965 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +0000966fi
Test Userba1e7e72019-07-10 22:27:54 +0000967
David Bainbridge99ac7a22019-08-31 02:26:43 +0000968STIME=$(date +%s)
969bspin "Verify or download chart specific values files $DOWNLOAD"
970VALUES_FILES="monkey-values.yaml"
David K. Bainbridgea00736b2020-01-08 14:33:17 -0800971ERR_OUT=$(mktemp)
David Bainbridge99ac7a22019-08-31 02:26:43 +0000972for i in $VALUES_FILES; do
973 if [ ! -r ./$i ]; then
David K. Bainbridgea00736b2020-01-08 14:33:17 -0800974 (set -x; curl --fail -o ./$i -sSL https://raw.githubusercontent.com/ciena/kind-voltha/$VK_RELEASE/$i >>$LOG 2>$ERR_OUT) >>$LOG 2>&1
975 if [ $? -ne 0 ]; then
976 espin $THEX
977 echo -e "${RED}${BOLD}${ERROR}ERROR: $i${NORMAL}${RED} - $(cat $ERR_OUT)${NORMAL}"
978 echo "ERROR: $i - $(cat $ERR_OUT)" >>$LOG
979 rm -rf $ERR_OUT ./$i
980 exit 1
981 fi
982 rm -rf $ERR_OUT
David Bainbridge99ac7a22019-08-31 02:26:43 +0000983 fi
984done
985espin $VERIFIED
986if [ "$WITH_TIMINGS" == "yes" ]; then
987 printtime $(expr $(date +%s) - $STIME)
988fi
989
990if [ "$WITH_CHAOS" == "yes" ]; then
991 bspin "Verify or clone kube-monkey helm chart $DOWNLOAD"
992 if [ -r ./kube-monkey ]; then
993 espin $VERIFIED
994 else
995 espin $NOT_VERIFIED
996 bspin - "GIT clone kube-monkey"
997 (set -x; git clone https://github.com/asobti/kube-monkey kube-monkey >>$LOG 2>&1) >>$LOG 2>&1
998 espin - $VERIFIED
999 fi
1000fi
1001
Test Userba1e7e72019-07-10 22:27:54 +00001002if [ "$JUST_K8S" == "yes" ]; then
1003 echo "Environment deployed, not deploying VOLTHA artifacts as requested. Good bye."
1004 echo ""
1005 echo "Please issue the following commands in your terminal to ensure that you" | tee -a $LOG
1006 echo "are accessing the correct Kubernetes/Kind cluster as well as have the " | tee -a $LOG
1007 echo "tools required by VOLTHA in your command path. " | tee -a $LOG
1008 echo "" | tee -a $LOG
1009 echo -en $BOLD
1010 if [ $DEPLOY_K8S == "yes" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +00001011 echo "export KUBECONFIG=\"\$(./bin/kind get kubeconfig-path --name=\"voltha-$NAME\")\"" | tee -a $LOG
Test Userba1e7e72019-07-10 22:27:54 +00001012 fi
1013 echo "export PATH=$GOPATH/bin:\$PATH" | tee -a $LOG
1014 echo -en $NORMAL
1015 echo "" | tee -a $LOG
1016 echo "Thank you for choosing kind-voltha for you quick cluster needs." | tee -a $LOG
1017 exit 0
1018fi
1019
David Bainbridgee87067b2019-08-12 22:00:12 +00001020STIME=$(date +%s)
Test Userb5712372019-07-03 21:52:17 +00001021bspin "Verify ETCD Operator $OLD_KEY"
Test User7d866122019-07-09 17:52:35 +00001022if [ $(helm list --deployed --short --namespace voltha "^etcd-operator\$" | wc -l) -ne 1 ]; then
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001023 espin $NOT_VERIFIED
David Bainbridge90fd8e32019-08-21 23:32:47 +00001024 helm_install - voltha etcd-operator stable/etcd-operator latest "Install ETCD Operator"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001025else
1026 espin $VERIFIED
1027fi
Test User01ed0642019-07-03 20:17:06 +00001028EXPECT=$(test "$TYPE" == "minimal" && echo "1" || echo "3")
David Bainbridge4f1b5562019-08-19 04:46:52 +00001029wait_for_pods - "voltha" $EXPECT "includes" -1 "Waiting for ETCD Operator to start" "etcd-operator-.*"
David Bainbridgee87067b2019-08-12 22:00:12 +00001030if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +00001031 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +00001032fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001033
David Bainbridgee87067b2019-08-12 22:00:12 +00001034STIME=$(date +%s)
David Bainbridgeb270c202019-07-26 01:44:42 +00001035if [ $WITH_ONOS == "yes" ]; then
1036 bspin "Verify ONOS installed $BIRD"
1037 if [ $(helm list --deployed --short --namespace default "^onos\$" | wc -l) -ne 1 ]; then
1038 espin $NOT_VERIFIED
Andrea Campanella6afcb082019-12-18 16:51:30 -08001039 EXTRA_HELM_FLAGS="$SET_TAG $EXTRA_HELM_FLAGS" helm_install - default onos onf/onos $ONOS_CHART_VERSION "Install ONOS"
David Bainbridgeb270c202019-07-26 01:44:42 +00001040 else
1041 espin $VERIFIED
1042 fi
David Bainbridge4f1b5562019-08-19 04:46:52 +00001043 wait_for_pods - "default" 1 "includes" -1 "Waiting for ONOS to start" "onos-.*"
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001044
David Bainbridgeb270c202019-07-26 01:44:42 +00001045 bspin - "Forward ONOS API port $FORWARD"
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -08001046 kill_port_forward onos-ui
1047 port_forward default onos-ui $ONOS_API_PORT 8181
David Bainbridgeb270c202019-07-26 01:44:42 +00001048 espin - $VERIFIED
1049 bspin - "Forward ONOS SSH port $FORWARD"
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -08001050 kill_port_forward onos-ssh
1051 port_forward default onos-ssh $ONOS_SSH_PORT 8101
David Bainbridgeb270c202019-07-26 01:44:42 +00001052 espin - $VERIFIED
David Bainbridged31d6122019-08-13 19:37:59 +00001053 bspin - "Verify or download ONOS configuration support files $DOWNLOAD"
David Bainbridge2b19e832019-08-16 02:40:53 +00001054 ONOS_FILES="olt-onos-enableExtraneousRules.json olt-onos-olt-settings.json onos-aaa.json \
David Bainbridge90fd8e32019-08-21 23:32:47 +00001055 onos-dhcpl2relay.json onos-kafka.json onos-sadis-sample.json"
David Bainbridged31d6122019-08-13 19:37:59 +00001056 (set -x; mkdir -p ./onos-files >>$LOG 2>&1) >>$LOG 2>&1
David K. Bainbridgea00736b2020-01-08 14:33:17 -08001057 ERR_OUT=$(mktemp)
David Bainbridge2b19e832019-08-16 02:40:53 +00001058 for i in $ONOS_FILES; do
David Bainbridged31d6122019-08-13 19:37:59 +00001059 if [ ! -r ./onos-files/$i ]; then
David K. Bainbridgea00736b2020-01-08 14:33:17 -08001060 (set -x; curl --fail -o ./onos-files/$i -sSL https://raw.githubusercontent.com/ciena/kind-voltha/$VK_RELEASE/onos-files/$i >>$LOG 2>$ERR_OUT) >>$LOG 2>&1
1061 if [ $? -ne 0 ]; then
1062 espin - $THEX
1063 echo -e "${RED}${BOLD}${ERROR}ERROR: $i${NORMAL}${RED} - $(cat $ERR_OUT)${NORMAL}"
1064 echo "ERROR: $(cat $ERR_OUT)" >>$LOG
1065 rm -rf $ERR_OUT ./onos-files/$i
1066 exit 1
1067 fi
1068 rm -rf $ERR_OUT
David Bainbridged31d6122019-08-13 19:37:59 +00001069 fi
1070 done
Test Userba1e7e72019-07-10 22:27:54 +00001071 espin - $VERIFIED
David Bainbridge27790d62019-08-13 22:43:19 +00001072
1073 if [ $INSTALL_ONOS_APPS == "yes" ]; then
1074 bspin - "Installing custom ONOS applications"
1075 if [ -x onos-files/onos-apps -a $(ls -1 onos-files/onos-apps/*.oar 2>/dev/null | wc -l) -gt 0 ]; then
1076 for OAR in $(ls -1 onos-files/onos-apps/*.oar); do
1077 sspin - "Installing custom ONOS applications - $OAR$CEOL"
David Bainbridge2b19e832019-08-16 02:40:53 +00001078 override_onos_app $OAR
David Bainbridge27790d62019-08-13 22:43:19 +00001079 done
1080 espin - "$VERIFIED Installing custom ONOS applications$CEOL"
1081 else
1082 espin - "$NOT_VERIFIED Installing custom ONOS applications - None Found"
1083 fi
1084 fi
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001085
Matteo Scandolo9a77a732020-01-09 14:24:12 -08001086 check_onos_app_active org.opencord.kafka
David Bainbridge2b19e832019-08-16 02:40:53 +00001087 push_onos_config "Push ONOS Kafka Configuration" "network/configuration/apps/org.opencord.kafka" "onos-files/onos-kafka.json"
Matteo Scandolo9a77a732020-01-09 14:24:12 -08001088 check_onos_app_active org.opencord.dhcpl2relay
David Bainbridge2b19e832019-08-16 02:40:53 +00001089 push_onos_config "Push ONOS DHCP L2 Relay Configuration" "network/configuration/apps/org.opencord.dhcpl2relay" "onos-files/onos-dhcpl2relay.json"
Matteo Scandolo9a77a732020-01-09 14:24:12 -08001090 check_onos_app_active org.opencord.olt
David Bainbridged31d6122019-08-13 19:37:59 +00001091 push_onos_config "Enable VOLTHA ONOS DHCP provisioning" "configuration/org.opencord.olt.impl.Olt" "onos-files/olt-onos-olt-settings.json"
1092 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 +00001093 if [ -f onos-files/onos-sadis.json ]; then
1094 push_onos_config "[optional] Push ONOS SADIS Configuration" "network/configuration/apps/org.opencord.sadis" "onos-files/onos-sadis.json"
1095 elif [ "$CONFIG_SADIS" == "yes" ]; then
David Bainbridge90fd8e32019-08-21 23:32:47 +00001096 SADIS_CFG=onos-files/onos-sadis-sample.json
Matteo Scandolo9a77a732020-01-09 14:24:12 -08001097 check_onos_app_active org.opencord.sadis
David Bainbridge2b19e832019-08-16 02:40:53 +00001098 push_onos_config "[optional] Push ONOS SADIS Configuration" "network/configuration/apps/org.opencord.sadis" "$SADIS_CFG"
1099 fi
Test Userba1e7e72019-07-10 22:27:54 +00001100fi
David Bainbridgee87067b2019-08-12 22:00:12 +00001101if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +00001102 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +00001103fi
Test Userba1e7e72019-07-10 22:27:54 +00001104
David Bainbridgee87067b2019-08-12 22:00:12 +00001105STIME=$(date +%s)
Test Userb5712372019-07-03 21:52:17 +00001106bspin "Verify VOLTHA installed $HIGH_VOLTAGE"
Test User7d866122019-07-09 17:52:35 +00001107if [ $(helm list --deployed --short --namespace voltha "^voltha\$" | wc -l) -ne 1 ]; then
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001108 espin $NOT_VERIFIED
David Bainbridge70c0ea82019-11-14 23:25:26 +00001109 if [ "$ONLY_ONE" == "yes" ]; then
1110 EXTRA_HELM_INSTALL_ARGS="--set therecanbeonlyone=true"=
1111 fi
David Bainbridge90fd8e32019-08-21 23:32:47 +00001112 helm_install - voltha voltha $VOLTHA_CHART $VOLTHA_CHART_VERSION "Install VOLTHA Core"
David Bainbridge70c0ea82019-11-14 23:25:26 +00001113 EXTRA_HELM_INSTALL_ARGS=
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001114else
1115 espin $VERIFIED
1116fi
Test Userba1e7e72019-07-10 22:27:54 +00001117
David Bainbridge90fd8e32019-08-21 23:32:47 +00001118VOLTHA="voltha-ofagent-.* \
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001119 ro-core.* \
1120 rw-core.* \
1121 voltha-api-server-.* \
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001122 voltha-etcd-cluster-.* \
1123 voltha-kafka-.* \
1124 voltha-zookeeper-.*"
David Bainbridge70c0ea82019-11-14 23:25:26 +00001125if [ "$ONLY_ONE" == "yes" ]; then
David Bainbridge1ba64f12019-12-18 00:40:13 +00001126 EXPECT=$(test "$TYPE" == "minimal" && echo "5" || echo "7")
David Bainbridge70c0ea82019-11-14 23:25:26 +00001127else
David Bainbridge1ba64f12019-12-18 00:40:13 +00001128 EXPECT=$(test "$TYPE" == "minimal" && echo "8" || echo "10")
David Bainbridge70c0ea82019-11-14 23:25:26 +00001129fi
David Bainbridge4f1b5562019-08-19 04:46:52 +00001130wait_for_pods - "voltha" $EXPECT "includes" -1 "Waiting for VOLTHA Core to start" $VOLTHA
David Bainbridgee87067b2019-08-12 22:00:12 +00001131if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +00001132 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +00001133fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001134
David Bainbridge46505fb2019-10-01 21:13:20 +00001135if [ "$WITH_ADAPTERS" == "yes" ]; then
1136 STIME=$(date +%s)
1137 EXPECT=0
1138 echo -e "Verify Adapters $PLUG"
1139 if [ "$WITH_SIM_ADAPTERS" == "yes" ]; then
1140 bspin - "Verify Simulated Adapters installed"
1141 if [ $(helm list --deployed --short --namespace voltha "^sim\$" | wc -l) -ne 1 ]; then
1142 espin - $NOT_VERIFIED
1143 helm_install - voltha sim $VOLTHA_ADAPTER_SIM_CHART $VOLTHA_ADAPTER_SIM_CHART_VERSION "Install Simulated Adapters"
1144 else
1145 espin - $VERIFIED
1146 fi
1147 EXPECT=$(expr $EXPECT + 2)
1148 fi
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001149
David Bainbridge46505fb2019-10-01 21:13:20 +00001150 if [ "$WITH_OPEN_ADAPTERS" == "yes" ]; then
1151 bspin - "Verify OpenOLT Adapter installed"
1152 if [ $(helm list --deployed --short --namespace voltha "^open-olt\$" | wc -l) -ne 1 ]; then
1153 espin - $NOT_VERIFIED
1154 helm_install - voltha open-olt $VOLTHA_ADAPTER_OPEN_OLT_CHART $VOLTHA_ADAPTER_OPEN_OLT_CHART_VERSION "Install OpenOLT Adapter"
1155 else
1156 espin - $VERIFIED
1157 fi
1158 bspin - "Verify OpenONU Adapter installed"
1159 if [ $(helm list --deployed --short --namespace voltha "^open-onu\$" | wc -l) -ne 1 ]; then
1160 espin - $NOT_VERIFIED
1161 helm_install - voltha open-onu $VOLTHA_ADAPTER_OPEN_ONU_CHART $VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION "Install OpenONU Adapter"
1162 else
1163 espin - $VERIFIED
1164 fi
1165 EXPECT=$(expr $EXPECT + 2)
1166 fi
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001167
David Bainbridge46505fb2019-10-01 21:13:20 +00001168 ADAPTERS="adapter-.*"
1169 wait_for_pods - "voltha" $EXPECT "includes" -1 "Waiting for adapters to start" $ADAPTERS
1170 if [ "$WITH_TIMINGS" == "yes" ]; then
1171 printtime $(expr $(date +%s) - $STIME)
1172 fi
David Bainbridgee87067b2019-08-12 22:00:12 +00001173fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001174
Test User7d866122019-07-09 17:52:35 +00001175if [ $WITH_BBSIM == "yes" ]; then
David Bainbridgee87067b2019-08-12 22:00:12 +00001176 STIME=$(date +%s)
Test User7d866122019-07-09 17:52:35 +00001177 echo -e "Verify BBSIM $PLUG"
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001178 bspin - "Verify BBSIM Installed"
Test User7d866122019-07-09 17:52:35 +00001179 if [ $(helm list --deployed --short --namespace voltha "^bbsim\$" | wc -l) -ne 1 ]; then
1180 espin - $NOT_VERIFIED
David Bainbridge90fd8e32019-08-21 23:32:47 +00001181 helm_install - voltha bbsim $VOLTHA_BBSIM_CHART $VOLTHA_BBSIM_CHART_VERSION "Install BBSIM"
Test User7d866122019-07-09 17:52:35 +00001182 else
1183 espin - $VERIFIED
1184 fi
David Bainbridge4f1b5562019-08-19 04:46:52 +00001185 wait_for_pods - "voltha" 1 "includes" -1 "Waiting for BBSIM to start" "bbsim-.*"
David Bainbridgee87067b2019-08-12 22:00:12 +00001186 if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +00001187 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +00001188 fi
Test User7d866122019-07-09 17:52:35 +00001189fi
1190
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001191if [ $WITH_RADIUS == "yes" ]; then
David Bainbridgee87067b2019-08-12 22:00:12 +00001192 STIME=$(date +%s)
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001193 echo -e "Verify RADIUS $LOCK"
1194 bspin - "Verify RADIUS Installed"
1195 if [ $(helm list --deployed --short --namespace voltha "^radius\$" | wc -l) -ne 1 ]; then
1196 espin - $NOT_VERIFIED
David Bainbridge90fd8e32019-08-21 23:32:47 +00001197 helm_install - voltha radius onf/freeradius latest "Install RADIUS"
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001198 else
1199 espin - $VERIFIED
1200 fi
David Bainbridge4f1b5562019-08-19 04:46:52 +00001201 wait_for_pods - "voltha" 1 "includes" -1 "Waiting for RADIUS to start" "radius-.*"
David Bainbridgee87067b2019-08-12 22:00:12 +00001202 if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +00001203 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +00001204 fi
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001205fi
1206
David Bainbridgee87067b2019-08-12 22:00:12 +00001207STIME=$(date +%s)
Test Userb5712372019-07-03 21:52:17 +00001208bspin - "Forward VOLTHA API port $FORWARD"
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -08001209kill_port_forward voltha-api
1210port_forward voltha voltha-api $VOLTHA_API_PORT 55555
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001211espin - $VERIFIED
David Bainbridgeac7f8072019-08-01 22:15:33 +00001212bspin - "Forward VOLTHA ETCD port $FORWARD"
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -08001213kill_port_forward voltha-etcd-cluster-client
1214port_forward voltha voltha-etcd-cluster-client $VOLTHA_ETCD_PORT 2379
David Bainbridgeac7f8072019-08-01 22:15:33 +00001215espin - $VERIFIED
David Bainbridgee87067b2019-08-12 22:00:12 +00001216if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +00001217 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +00001218fi
Test User3d7ad8e2019-07-03 06:15:44 +00001219
David Bainbridgeb270c202019-07-26 01:44:42 +00001220if [ $WITH_ONOS == "yes" -a $WITH_RADIUS == "yes" ]; then
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001221 bspin "Configure ONOS RADIUS Connection $GEAR"
Andy Bavier658ebef2019-11-05 17:22:56 -07001222 (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 --fail -sSL --user karaf:karaf -X POST http://127.0.0.1:$ONOS_API_PORT/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 +00001223 espin $VERIFIED
1224fi
1225
David Bainbridge99ac7a22019-08-31 02:26:43 +00001226if [ "$WITH_CHAOS" == "yes" ]; then
1227 STIME=$(date +%s)
1228 echo -e "Verify kube-monkey $LOCK"
1229 bspin - "Verify kube-monkey Installed"
1230 if [ $(helm list --deployed --short --namespace kube-monkey "^monkey\$" | wc -l) -ne 1 ]; then
1231 espin - $NOT_VERIFIED
1232 helm_install - kube-monkey monkey ./kube-monkey/helm/kubemonkey latest "Install Chaos Monkey"
1233 else
1234 espin - $VERIFIED
1235 fi
1236 wait_for_pods - "kube-monkey" 1 "includes" -1 "Waiting for Chaos to start" "monkey-.*"
1237 if [ "$WITH_TIMINGS" == "yes" ]; then
1238 printtime $(expr $(date +%s) - $STIME)
1239 fi
1240fi
1241
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001242bspin "Create voltctl configuration file"
Test User3d7ad8e2019-07-03 06:15:44 +00001243(set -x; mkdir -p $HOME/.volt >>$LOG 2>&1) >>$LOG 2>&1
David Bainbridge0774b232019-08-02 06:37:19 +00001244(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 +00001245espin $VERIFIED
Test User08ebbd92019-07-03 17:15:39 +00001246
David Bainbridge0774b232019-08-02 06:37:19 +00001247if [ ! -f "$NAME-env.sh" ]; then
1248 touch $NAME-env.sh
David Bainbridgeb07fdf72019-07-29 22:51:40 +00001249fi
1250
David Bainbridge596f30d2019-07-30 17:07:59 +00001251for O in $ALL_OPTIONS; do
1252 VAL=$(eval echo \$$O)
David Bainbridge0774b232019-08-02 06:37:19 +00001253 if [ ! -z "$VAL" -a $(grep -c "^export $O=" $NAME-env.sh) -eq 0 ]; then
1254 echo "export $O=\"$(eval echo \$$O)\"" >> $NAME-env.sh
David Bainbridgeb07fdf72019-07-29 22:51:40 +00001255 fi
1256done
1257
David Bainbridge0774b232019-08-02 06:37:19 +00001258if [ $DEPLOY_K8S == "yes" -a $(grep -c "^export KUBECONFIG=" $NAME-env.sh) -eq 0 ]; then
1259 echo "export KUBECONFIG=\"$(./bin/kind get kubeconfig-path --name=voltha-$NAME)\"" >> $NAME-env.sh
David Bainbridgeb07fdf72019-07-29 22:51:40 +00001260fi
1261
David Bainbridge0774b232019-08-02 06:37:19 +00001262if [ $(grep -c "^export VOLTCONFIG=" $NAME-env.sh) -eq 0 ]; then
1263 echo "export VOLTCONFIG=\"$HOME/.volt/config-$NAME\"" >> $NAME-env.sh
David Bainbridgeb07fdf72019-07-29 22:51:40 +00001264fi
1265
David Bainbridge0774b232019-08-02 06:37:19 +00001266if [ $(grep -c "^export PATH=" $NAME-env.sh) -eq 0 ]; then
1267 echo "export PATH=\"$GOPATH/bin:\$PATH\"" >> $NAME-env.sh
David Bainbridgeb07fdf72019-07-29 22:51:40 +00001268fi
1269
Test User7d866122019-07-09 17:52:35 +00001270echo ""
Test User08ebbd92019-07-03 17:15:39 +00001271echo "Please issue the following commands in your terminal to ensure that you" | tee -a $LOG
1272echo "are accessing the correct Kubernetes/Kind cluster as well as have the " | tee -a $LOG
1273echo "tools required by VOLTHA in your command path. " | tee -a $LOG
1274echo "" | tee -a $LOG
Test User7d866122019-07-09 17:52:35 +00001275echo -en $BOLD
Test Userba1e7e72019-07-10 22:27:54 +00001276if [ $DEPLOY_K8S == "yes" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +00001277 echo "export KUBECONFIG=\"\$(./bin/kind get kubeconfig-path --name=\"voltha-$NAME\")\"" | tee -a $LOG
Test Userba1e7e72019-07-10 22:27:54 +00001278fi
David Bainbridge0774b232019-08-02 06:37:19 +00001279echo "export VOLTCONFIG=\"$HOME/.volt/config-$NAME\"" | tee -a $LOG
Test Userba1e7e72019-07-10 22:27:54 +00001280echo "export PATH=$GOPATH/bin:\$PATH" | tee -a $LOG
Test User7d866122019-07-09 17:52:35 +00001281echo -en $NORMAL
Test User08ebbd92019-07-03 17:15:39 +00001282echo "" | tee -a $LOG
1283echo "Thank you for choosing kind-voltha for you quick cluster needs." | tee -a $LOG
1284
David Bainbridge712afb82019-08-14 19:55:58 +00001285if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridgef858a022019-08-14 21:25:11 +00001286 echo -e "$CLOCK ${BOLD}TOTAL: $(duration $(expr $(date +%s) - $TOTAL_START_TIME))${NORMAL}"
David Bainbridge712afb82019-08-14 19:55:58 +00001287fi