blob: e733cc2ecbfd72bf7c7b61049576bc330ddf14e7 [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}
David Bainbridge4f1b5562019-08-19 04:46:52 +000086WAIT_ON_DOWN=${WAIT_ON_DOWN:-no}
David Bainbridge5b7b96b2019-07-25 20:29:13 +000087VOLTHA_LOG_LEVEL=${VOLTHA_LOG_LEVEL:-WARN}
David Bainbridge90fd8e32019-08-21 23:32:47 +000088VOLTHA_CHART=${VOLTHA_CHART:-onf/voltha}
89VOLTHA_CHART_VERSION=${VOLTHA_CHART_VERSION:-latest}
90VOLTHA_BBSIM_CHART=${VOLTHA_BBSIM_CHART:-onf/bbsim}
Matteo 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
384 sleep .2
385 sspin -
386 done
387 espin - $VERIFIED
388}
389
390override_onos_app() {
391 local APP=$1
392 local NAME=$(basename $APP | sed -e 's/^[0-9][0-9]*-//g' -e 's/-.*$//g')
393 while true; do
394 sspin -
395 # Attempt to delete old version (if it exists)
396 (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
397 sspin -
398 if [ $? -ne 0 ]; then
399 continue
400 fi
401 (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
402 if [ $? -eq 0 ]; then
403 break
404 fi
405 sleep .2
406 done
407}
408
409activate_onos_app() {
410 local MSG="$1"
411 local APP=$2
412
413 bspin - "$MSG $GO"
414 while true; do
415 sspin -
416 (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
417 if [ $? -eq 0 ]; then
418 break
419 fi
420 sleep .2
421 done
422 espin - "$VERIFIED"
423}
424
425count_pods() {
426 local NAMESPACE=$1; shift
427 if [ "$NAMESPACE" == "all-namespaces" ]; then
428 NAMESPACE="--all-namespaces"
429 else
430 NAMESPACE="-n $NAMESPACE"
431 fi
432 echo "$NAMESPACE" > /tmp/t
433 local STATES=$1; shift
434 echo "$STATES" >> /tmp/t
435 local PODS=$(kubectl get $NAMESPACE pod -o go-template="{{range .items}}{{.metadata.name}}/{{.status.phase}}/_{{range .status.containerStatuses}}{{.ready}}_{{end}} {{end}}")
436 local COUNT=0
437 local PATTERNS="$*"
438 for POD in $PODS; do
439 local NAME=$(echo $POD | cut -d/ -f 1)
440 local STATE=$(echo $POD | cut -d/ -f 2)
441 local CONTAINERS=$(echo $POD | cut -d/ -f 3 | sed -e 's/_/ /g')
442 if [ "$STATES" == "*" -o $(echo "$STATES" | grep -c ":$STATE:") -ne 0 ]; then
443 echo "IN WITH $POD" >> /tmp/t
444 local TOTAL=$(echo $CONTAINERS | wc -w)
445 local FOUND=$(echo $CONTAINERS | grep -o true | wc -l)
446 if [ $TOTAL -eq $FOUND ]; then
447 for PATTERN in $PATTERNS; do
448 echo "TEST $PATTERN AGAINST $NAME" >> /tmp/t
449 if [[ $NAME =~ $PATTERN ]]; then
450 echo "COUNT $NAME" >> /tmp/t
451 COUNT=$(expr $COUNT + 1)
452 break
453 fi
454 done
455 fi
456 fi
457 done
458 echo $COUNT >> /tmp/t
459 echo $COUNT
460}
461
462wait_for_pods() {
463 local INDENT=
464 if [ "$1" == "-" ]; then
465 INDENT=$1; shift
466 fi
467 local NAMESPACE=$1; shift
468 local EXPECT=$1; shift
469 local TYPE=$1; shift
470 local RETRY=$1; shift
471 local MESSAGE=$1; shift
472 local PATTERNS=$*
David Bainbridge99ac7a22019-08-31 02:26:43 +0000473 local STATES=":Running:"
474 if [ "$TYPE" == "not" ]; then
475 STATES="*"
476 fi
477 local HAVE=$(count_pods $NAMESPACE "$STATES" $PATTERNS)
David Bainbridge4f1b5562019-08-19 04:46:52 +0000478 local ALL=$HAVE
479 if [ "$TYPE" == "only" ]; then
480 ALL=$(count_pods "all-namespaces" "*" ".*")
481 fi
482 COUNT=$(expr 300 / 15)
483 bspin $INDENT $MESSAGE
484 sspin $INDENT
485 if [ $HAVE -ne $EXPECT -o $ALL -ne $HAVE ]; then
486 while [ $HAVE -ne $EXPECT -o $ALL -ne $HAVE ]; do
487 sspin $INDENT
488 COUNT=$(expr $COUNT - 1)
489 if [ $COUNT -eq 0 ]; then
David Bainbridge99ac7a22019-08-31 02:26:43 +0000490 HAVE=$(count_pods $NAMESPACE "$STATES" $PATTERNS)
David Bainbridge4f1b5562019-08-19 04:46:52 +0000491 ALL=$HAVE
492 if [ "$TYPE" == "only" ]; then
493 ALL=$(count_pods "all-namespaces" "*" ".*")
494 fi
495 COUNT=$(expr 300 / 15)
496 fi
497 sleep .15
498 done
499 fi
500 espin $INDENT $VERIFIED
501 if [ $HAVE -ne $EXPECT ]; then
502 return 1
503 fi
504 return 0
505}
506
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800507port_forward() {
508 local NS=$1
509 local SVC=$2
510 local FROM_PORT=$3
511 local TO_PORT=$4
512 local TAG=$SVC-$NAME
513
514 (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
515}
516
517kill_port_forward() {
518 local TAG=$1-$NAME
David Bainbridgec6871d22019-11-13 17:10:31 +0000519 local P_IDS=$(ps e -ww -A | grep "_TAG=$TAG" | grep -v grep | awk '{print $1}')
David Bainbridgebcf235b2019-11-12 21:33:58 +0000520 local PARENTS=
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800521 local KIDS=
David Bainbridgec6871d22019-11-13 17:10:31 +0000522 local UNKNOWN=
523 if [ ! -z "$P_IDS" ]; then
524 for P_ID in $P_IDS; do
525 local PP_ID=$(ps -o ppid $P_ID | tail -n +2)
526 if [ ! -z "$PP_ID" ]; then
527 if [ $PP_ID -eq 1 ]; then
528 PARENTS="$PARENTS $P_ID"
529 else
530 KIDS="$KIDS $P_ID"
531 fi
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800532 else
David Bainbridgec6871d22019-11-13 17:10:31 +0000533 UNKNOWN="$UNKNOWN $P_ID"
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800534 fi
535 done
David Bainbridgec6871d22019-11-13 17:10:31 +0000536 (set -x; kill -9 $PARENTS $KIDS $UNKNOWN >>$LOG 2>&1) >>$LOG 2>&1
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800537 fi
538}
539
David Bainbridgeac7f8072019-08-01 22:15:33 +0000540if [ "$1" == "down" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000541 echo "Tearing down voltha cluster $NAME"
542 LOG="down-$NAME.log"
543 echo $(date -u +"%Y%m%dT%H%M%SZ") >$LOG
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800544 bspin "Remove port-forwards: onos-ui-$NAME"
545 kill_port_forward onos-ui
546 sspin "Remove port-forwards: onos-ssh-$NAME$CEOL"
547 kill_port_forward onos-ssh
548 sspin "Remove port-forwards: voltha-api-$NAME$CEOL"
549 kill_port_forward voltha-api
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800550 sspin "Remove port-forwards: voltha-etcd-$NAME$CEOL"
551 kill_port_forward voltha-etcd-cluster-client
552 espin "$VERIFIED Remove port-forwards$CEOL"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000553 if [ $DEPLOY_K8S == "yes" ]; then
554 if [ -x ./bin/kind ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000555 bspin "Delete Kubernetes Kind Cluster"
556 (set -x; ./bin/kind delete cluster --name voltha-$NAME >>$LOG 2>&1) >>$LOG 2>&1
557 espin $VERIFIED
David Bainbridgeac7f8072019-08-01 22:15:33 +0000558 else
David Bainbridge0774b232019-08-02 06:37:19 +0000559 espin "$NO_ENTRY Delete Kubernetes Kind Cluster: kind command not found"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000560 fi
561 else
562 EXISTS=$(helm list -q)
563 EXPECT="etcd-operator onos open-olt open-onu sim voltha bbsim radius"
David Bainbridge0774b232019-08-02 06:37:19 +0000564 bspin "Remove Helm Deployments"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000565 for i in $EXISTS; do
566 if [ $(echo $EXPECT | grep -c $i) -eq 1 ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000567 sspin "Remove Helm Deployments: $i$CEOL"
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800568 (set -x; ./bin/helm delete --no-hooks --purge $i >>$LOG 2>&1) >>$LOG 2>&1
David Bainbridgeac7f8072019-08-01 22:15:33 +0000569 fi
570 done
David Bainbridge0774b232019-08-02 06:37:19 +0000571 espin "$VERIFIED Remove Helm Deployments$CEOL"
David Bainbridge4f1b5562019-08-19 04:46:52 +0000572 if [ "$WAIT_ON_DOWN" == "yes" ]; then
573 # There should only be 13 or 15 PODs in the kube-system name
574 # space and no other PODs
David Bainbridge4f1b5562019-08-19 04:46:52 +0000575 PODS="coredns-.* \
576 etcd-voltha-$NAME-control-plane \
577 kindnet-.* \
578 kube-apiserver-voltha-$NAME-control-plane \
579 kube-controller-manager-voltha-$NAME-control-plane \
580 kube-proxy-.* \
581 kube-scheduler-voltha-$NAME-control-plane \
582 tiller-deploy-.*"
583 EXPECT=$(test "$TYPE" == "minimal" && echo "13" || echo "15")
David Bainbridge99ac7a22019-08-31 02:26:43 +0000584 PODS="adapter-.* \
585 bbsim.* \
586 etcd-operator.* \
587 radius.* \
588 voltha-.*"
589 EXPECT=0
590
591 wait_for_pods "voltha" $EXPECT "not" -1 "Waiting for VOLTHA PODs to terminate" $PODS
David Bainbridge4f1b5562019-08-19 04:46:52 +0000592 fi
David Bainbridgeac7f8072019-08-01 22:15:33 +0000593 fi
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -0700594 exit
David Bainbridgeac7f8072019-08-01 22:15:33 +0000595fi
596
597if [ "$1" == "dump" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000598 LOG="dump-$NAME.log"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000599 TS=$(date -u +"%Y%m%dT%H%M%SZ")
David Bainbridge76514a02019-10-08 01:50:35 +0000600 if [ ! -z "$DUMP_FROM" ]; then
601 TS=$(echo $DUMP_FROM | sed -e 's/[:-]//g')
602 fi
David Bainbridgeac7f8072019-08-01 22:15:33 +0000603 WORK=$(mktemp -u -d)
David Bainbridge0774b232019-08-02 06:37:19 +0000604 DATA=$WORK/voltha-debug-dump-$NAME-$TS
David Bainbridgeac7f8072019-08-01 22:15:33 +0000605 mkdir -p $DATA
606 echo $TS > $LOG
David Bainbridge0774b232019-08-02 06:37:19 +0000607 echo -e "Capturing debug dump to voltha-debug-dump-$NAME-$TS.tgz"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000608 bspin - "Copy install log"
David Bainbridge0774b232019-08-02 06:37:19 +0000609 if [ -f install-$NAME.log ]; then
610 (set -x; cp install-$NAME.log $DATA/install-$NAME.log) >>$LOG 2>&1
David Bainbridgeac7f8072019-08-01 22:15:33 +0000611 espin - $VERIFIED
612 else
David Bainbridge0774b232019-08-02 06:37:19 +0000613 espin - "$NO_ENTRY Copy install log: install-$NAME.log not found"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000614 fi
615 bspin - "Dumping Kubernetes PODs"
616 (set -x; kubectl get --all-namespaces pods >> $DATA/all-pods.txt 2>&1) >>$LOG 2>&1
617 espin - $VERIFIED
618 bspin - "Dumping Kubernetes SERVICEs"
619 (set -x; kubectl get --all-namespaces svc >> $DATA/all-services.txt 2>&1) >>$LOG 2>&1
620 espin - $VERIFIED
621 bspin - "Dumping Kubernetes EVENTs"
622 (set -x; kubectl get --all-namespaces events >> $DATA/all-events.txt 2>&1) >>$LOG 2>&1
623 espin - $VERIFIED
624 bspin - "Dumping VOLTHA POD details"
Matteo Scandolodcd29f52019-10-07 15:42:42 -0700625 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 +0000626 SINCE=
627 if [ ! -z "$DUMP_FROM" ]; then
628 SINCE="--since-time=$DUMP_FROM"
629 fi
David Bainbridgeac7f8072019-08-01 22:15:33 +0000630 for POD in $PODS; do
David Bainbridge1f0655a2019-10-01 22:08:48 +0000631 NS=$(echo $POD | cut -d: -f1)
632 POD=$(echo $POD | cut -d: -f2)
David Bainbridgeac7f8072019-08-01 22:15:33 +0000633 sspin - "Dumping VOLTHA POD details: $POD$CEOL"
634 mkdir -p $DATA/$POD
David Bainbridge1f0655a2019-10-01 22:08:48 +0000635 (set -x; kubectl describe -n $NS $POD >> $DATA/$POD/describe.txt 2>&1) >>$LOG 2>&1
David Bainbridgeac7f8072019-08-01 22:15:33 +0000636 sspin - "Dumping VOLTHA POD details: $POD"
David Bainbridgecfd7ca12019-10-06 03:31:41 +0000637 (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 +0000638 sspin - "Dumping VOLTHA POD details: $POD"
David Bainbridgecfd7ca12019-10-06 03:31:41 +0000639 (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 +0000640 sspin - "Dumping VOLTHA POD details: $POD"
641 done
642 espin - "$VERIFIED Dumping VOLTHA POD details$CEOL"
643 bspin - "Dumping ETCD"
644 if [ "$(which etcdctl) X" != " X" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000645 (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 +0000646 espin - $VERIFIED
647 else
648 espin - "$NO_ENTRY Dumping ETCD: etcdctl command not available"
649 fi
David Bainbridge0774b232019-08-02 06:37:19 +0000650 bspin - "Creating compressed TAR: voltha-debug-dump-$NAME-$TS.tgz"
651 (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 +0000652 espin - $VERIFIED
653 bspin - "Cleanup"
654 (set -x; rm -rf $WORK) >>$LOG 2>&1
655 espin - $VERIFIED
David Bainbridge0774b232019-08-02 06:37:19 +0000656 bspin - "$(ls -l voltha-debug-dump-$NAME-$TS.tgz)"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000657 espin - $VERIFIED
658 exit
659fi
660
David Bainbridge0774b232019-08-02 06:37:19 +0000661LOG="install-$NAME.log"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000662date > $LOG
David Bainbridge0774b232019-08-02 06:37:19 +0000663echo "PORTS=$ONOS_API_PORT,$ONOS_SSH_PORT,$VOLTHA_API_PORT,$VOLTHA_SSH_PORT,$VOLTHA_ETCD_PORT" >> $LOG
David Bainbridgeac7f8072019-08-01 22:15:33 +0000664
665# Output install options to log
666echo "OPTIONS" >> $LOG
David Bainbridgeac7f8072019-08-01 22:15:33 +0000667for O in $ALL_OPTIONS; do
668 VAL=$(eval echo \$$O)
David Bainbridgeac7f8072019-08-01 22:15:33 +0000669 if [ ! -z "$VAL" ]; then
670 printf " %-30s = %s\n" $O $VAL >> $LOG
671 fi
672done
673
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -0700674helm_install() {
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700675 local INDENT=
676 if [ "$1" == "-" ]; then
677 INDENT=$1; shift
678 fi
679 local NAMESPACE=$1; shift
David Bainbridge0774b232019-08-02 06:37:19 +0000680 local INAME=$1; shift
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700681 local CHART=$1; shift
David Bainbridge90fd8e32019-08-21 23:32:47 +0000682 local CHART_VERSION=$1; shift
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700683 local MESSAGE=$*
684
David Bainbridge90fd8e32019-08-21 23:32:47 +0000685 if [ "$CHART_VERSION X" != " X" -a "$CHART_VERSION" != "latest" ]; then
686 CHART_VERSION="--version $CHART_VERSION"
687 else
688 CHART_VERSION=
689 fi
690
David Bainbridge99ac7a22019-08-31 02:26:43 +0000691 local CHART_ARGS=
692 if [ -r "${INAME}-values.yaml" ]; then
693 CHART_ARGS="-f ${INAME}-values.yaml"
694 fi
695
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700696 COUNT=$(expr 300 / 15)
697 bspin $INDENT $MESSAGE
David Bainbridge70c0ea82019-11-14 23:25:26 +0000698 (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 -0700699 SUCCESS=$?
700 while [ $SUCCESS -ne 0 ]; do
701 sspin $INDENT
702 COUNT=$(expr $COUNT - 1)
703 if [ $COUNT -eq 0 ]; then
Andy Baviere22ff252019-12-19 11:40:31 -0700704 (set -x; helm delete --purge $INAME >>$LOG 2>&1) >>$LOG 2>&1
David Bainbridge99ac7a22019-08-31 02:26:43 +0000705 (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 -0700706 SUCCESS=$?
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700707 COUNT=$(expr 300 / 15)
708 fi
709 sleep .15
710 done
711 espin $INDENT $VERIFIED
712}
713
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700714echo "INSTALL TYPE: $TYPE" >> $LOG
715
716bspin "Verify GOPATH"
717export GOPATH=$(pwd)
Test User3d7ad8e2019-07-03 06:15:44 +0000718mkdir -p $GOPATH/bin
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700719espin $VERIFIED
720
David Bainbridgee87067b2019-08-12 22:00:12 +0000721STIME=$(date +%s)
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700722if [ "$INSTALL_KUBECTL" == "no" ]; then
723 bspin "Skip kubectl install"
724 espin $NO_ENTRY
Test Userc13bdc92019-07-03 20:57:49 +0000725else
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700726 bspin "Verify kubectl $HELM"
727 if [ -x $GOPATH/bin/kubectl ]; then
728 espin $VERIFIED
729 else
730 espin $NOT_VERIFIED
731 bspin - "Download and install Kubernetes/kubectl $DOWNLOAD"
732 (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
733 (set -x; chmod 755 $GOPATH/bin/kubectl >>$LOG 2>&1) >>$LOG 2>&1
734 espin - $VERIFIED
735 fi
Test Userc13bdc92019-07-03 20:57:49 +0000736fi
David Bainbridgee87067b2019-08-12 22:00:12 +0000737if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +0000738 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +0000739fi
Test Userc13bdc92019-07-03 20:57:49 +0000740
David Bainbridgee87067b2019-08-12 22:00:12 +0000741STIME=$(date +%s)
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700742if [ "$DEPLOY_K8S" == "no" ]; then
743 bspin "Skip Kubernetes/Kind Deployment"
744 espin $NO_ENTRY
745else
Test Userba1e7e72019-07-10 22:27:54 +0000746 bspin "Verify Kubernetes/Kind $HELM"
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800747 IS_INSTALLED=0
748 OP_TYPE="install"
Test Userba1e7e72019-07-10 22:27:54 +0000749 if [ -x $GOPATH/bin/kind ]; then
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800750 OP_TYPE="upgrade"
751 if [ $($GOPATH/bin/kind --version | grep -c $KIND_VERSION) -eq 1 ]; then
752 IS_INSTALLED=1
753 espin $VERIFIED
754 fi
755 fi
756 if [ $IS_INSTALLED -eq 0 ]; then
Test Userba1e7e72019-07-10 22:27:54 +0000757 espin $NOT_VERIFIED
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800758 bspin - "Download and $OP_TYPE Kubernetes/kind $DOWNLOAD"
David Bainbridge9e2a6662019-07-11 17:07:57 +0000759 (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 +0000760 (set -x; chmod 755 $GOPATH/bin/kind >>$LOG 2>&1) >>$LOG 2>&1
761 espin - $VERIFIED
762 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700763fi
764
David Bainbridgee87067b2019-08-12 22:00:12 +0000765if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +0000766 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +0000767fi
768
769STIME=$(date +%s)
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700770if [ "$INSTALL_HELM" == "no" ]; then
771 bspin "Skip Helm Install"
772 espin $NO_ENTRY
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700773else
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700774 bspin "Verify Helm $HELM"
775 if [ -x $GOPATH/bin/helm ]; then
776 espin $VERIFIED
777 else
778 espin $NOT_VERIFIED
779 bspin - "Download and install Helm $DOWNLOAD"
David Bainbridgec6a6eb62019-10-18 22:50:07 +0000780 (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 -0700781 espin - $VERIFIED
782 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700783fi
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800784
David Bainbridgee87067b2019-08-12 22:00:12 +0000785if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +0000786 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +0000787fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700788
David Bainbridgee87067b2019-08-12 22:00:12 +0000789STIME=$(date +%s)
Test Userb5712372019-07-03 21:52:17 +0000790bspin "Verify voltctl $HIGH_VOLTAGE"
David Bainbridged2811972019-12-14 01:14:09 +0000791VOK=0
792VMESSAGE="install"
Test User3d7ad8e2019-07-03 06:15:44 +0000793if [ -x $GOPATH/bin/voltctl ]; then
David Bainbridge1ba64f12019-12-18 00:40:13 +0000794 VHAVE=$($GOPATH/bin/voltctl version --clientonly -o json | jq -r .version)
795 if [ $? -eq 0 -a "$VHAVE" == "$VOLTCTL_VERSION" ]; then
David Bainbridged2811972019-12-14 01:14:09 +0000796 VOK=1
David Bainbridge1ba64f12019-12-18 00:40:13 +0000797 espin $VERIFIED
798 else
799 VMESSAGE="upgrade"
David Bainbridged2811972019-12-14 01:14:09 +0000800 fi
801fi
802
David Bainbridge1ba64f12019-12-18 00:40:13 +0000803if [ $VOK -eq 0 ]; then
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700804 espin $NOT_VERIFIED
David Bainbridged2811972019-12-14 01:14:09 +0000805 bspin - "Download and $VMESSAGE voltctl $DOWNLOAD"
David Bainbridge28c64462019-12-12 22:25:26 +0000806 (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 +0000807 (set -x; chmod 755 $GOPATH/bin/voltctl >>$LOG 2>&1) >>$LOG 2>&1
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700808 espin - $VERIFIED
809fi
David Bainbridgee87067b2019-08-12 22:00:12 +0000810if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +0000811 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +0000812fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700813
814bspin "Verify command PATH"
Test Userba1e7e72019-07-10 22:27:54 +0000815export PATH=$GOPATH/bin:$PATH
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700816espin $VERIFIED
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700817
David Bainbridgee87067b2019-08-12 22:00:12 +0000818STIME=$(date +%s)
Test Userba1e7e72019-07-10 22:27:54 +0000819if [ "$DEPLOY_K8S" == "yes" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000820 HAVE=$(kind get clusters | grep -c voltha-$NAME)
Test Userba1e7e72019-07-10 22:27:54 +0000821 bspin "Verify Kubernetes/Kind Cluster"
822 sspin
823 if [ $HAVE -eq 0 ]; then
David Bainbridge491b1bd2019-07-11 17:53:11 +0000824 espin $NOT_VERIFIED
825 bspin - "Verify cluster configuration"
David Bainbridge0774b232019-08-02 06:37:19 +0000826 if [ ! -r ./$NAME-cluster.cfg ]; then
David Bainbridge491b1bd2019-07-11 17:53:11 +0000827 espin - $NOT_VERIFIED
David Bainbridge0774b232019-08-02 06:37:19 +0000828 bspin - "Download cluster configuration: $TYPE-cluster.cfg to $NAME-cluster.cfg $DOWNLOAD"
David K. Bainbridgea00736b2020-01-08 14:33:17 -0800829 ERR_OUT=$(mktemp)
830 (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
831 if [ $? -ne 0 ]; then
832 espin - $THEX
833 echo -e "${RED}${BOLD}${ERROR}ERROR: $NAME-cluster.cfg${NORMAL}${RED} - $(cat $ERR_OUT)${NORMAL}"
834 echo "ERROR: $(cat $ERR_OUT)" >>$LOG
835 rm -rf $ERR_OUT ./$NAME-cluster.cfg
836 exit 1
837 fi
838 rm -rf $ERR_OUT
839 else
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700840 espin - $VERIFIED
David K. Bainbridgea00736b2020-01-08 14:33:17 -0800841 fi
David Bainbridge0774b232019-08-02 06:37:19 +0000842 kind create cluster --name voltha-$NAME --config $NAME-cluster.cfg
David Bainbridge491b1bd2019-07-11 17:53:11 +0000843 else
844 espin $VERIFIED
Test Userba1e7e72019-07-10 22:27:54 +0000845 fi
846
David Bainbridge0774b232019-08-02 06:37:19 +0000847 export KUBECONFIG="$(kind get kubeconfig-path --name="voltha-$NAME")"
Test Userba1e7e72019-07-10 22:27:54 +0000848 P="coredns-.* \
David Bainbridge0774b232019-08-02 06:37:19 +0000849 etcd-voltha-$NAME-control-plane \
Test Userba1e7e72019-07-10 22:27:54 +0000850 kindnet-.* \
David Bainbridge0774b232019-08-02 06:37:19 +0000851 kube-apiserver-voltha-$NAME-control-plane \
852 kube-controller-manager-voltha-$NAME-control-plane \
Test Userba1e7e72019-07-10 22:27:54 +0000853 kube-proxy-.* \
David Bainbridge0774b232019-08-02 06:37:19 +0000854 kube-scheduler-voltha-$NAME-control-plane"
Test Userba1e7e72019-07-10 22:27:54 +0000855
856 EXPECT=$(test "$TYPE" == "minimal" && echo "12" || echo "14")
David Bainbridge4f1b5562019-08-19 04:46:52 +0000857 wait_for_pods - "kube-system" $EXPECT "includes" -1 "Waiting for system PODs to start" $P
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700858fi
David Bainbridgee87067b2019-08-12 22:00:12 +0000859if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +0000860 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +0000861fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700862
David Bainbridgee87067b2019-08-12 22:00:12 +0000863STIME=$(date +%s)
David Bainbridge4c6289c2019-09-03 21:11:32 +0000864COUNT=$(count_pods "kube-system" ":Running:" "tiller-deploy-.*")
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700865bspin "Verify Helm"
Test Userba1e7e72019-07-10 22:27:54 +0000866if [ $COUNT -ne 1 ]; then
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700867 espin $NOT_VERIFIED
Test Userb5712372019-07-03 21:52:17 +0000868 echo -e "Configuring Helm $GEAR"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700869 if [ "$INSTALL_HELM" == "no" ]; then
870 bspin - "Skip Helm/Tiller Initialization"
871 espin - $NO_ENTRY
872 else
873 bspin - "Initialize Helm"
874 (set -x; helm init --upgrade >>$LOG 2>&1) >>$LOG 2>&1
875 espin - $VERIFIED
David Bainbridge4f1b5562019-08-19 04:46:52 +0000876 wait_for_pods - "kube-system" 1 "includes" -1 "Waiting for Tiller POD to start" "tiller-deploy-.*"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700877 fi
Test Userb5712372019-07-03 21:52:17 +0000878 bspin - "Add Google Incubator repository to Helm"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700879 (set -x; helm repo add incubator https://kubernetes-charts-incubator.storage.googleapis.com >>$LOG 2>&1) >>$LOG 2>&1
880 espin - $VERIFIED
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -0700881
Test Userba1e7e72019-07-10 22:27:54 +0000882 # HACK (sort-of) - the config for tiller is about to be patched, which will
883 # cause the tiller pod to be recreated. This can sometimes cause a timing
884 # issue with the "wait_for_pods" call on tiller as it may incorrectly
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -0700885 # identify the running/ready tiller pod that is soon to be terminated as
Test Userba1e7e72019-07-10 22:27:54 +0000886 # what it is waiting for. To avoid this issue we do a clean scale down and
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -0700887 # scale up of the pod so the script controlls when it should be expecting
Test Userba1e7e72019-07-10 22:27:54 +0000888 # things
889 (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 -0700890
Test Userb5712372019-07-03 21:52:17 +0000891 bspin - "Add Google Stable repository to Helm"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700892 (set -x; helm repo add stable https://kubernetes-charts.storage.googleapis.com >>$LOG 2>&1) >>$LOG 2>&1
893 espin - $VERIFIED
Test Userb5712372019-07-03 21:52:17 +0000894 bspin - "Add ONF repository to Helm"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700895 (set -x; helm repo add onf https://charts.opencord.org >>$LOG 2>&1) >>$LOG 2>&1
896 espin - $VERIFIED
Test Userb5712372019-07-03 21:52:17 +0000897 bspin - "Update Helm repository cache"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700898 (set -x; helm repo update >>$LOG 2>&1) >>$LOG 2>&1
899 espin - $VERIFIED
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -0700900
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700901 # Create and k8s service account so that Helm can create pods
Test Userb5712372019-07-03 21:52:17 +0000902 bspin - "Create Tiller ServiceAccount"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700903 (set -x; kubectl create serviceaccount --namespace kube-system tiller >>$LOG 2>&1) >>$LOG 2>&1
904 espin - $VERIFIED
Test Userb5712372019-07-03 21:52:17 +0000905 bspin - "Create Tiller ClusterRoleBinding"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700906 (set -x; kubectl create clusterrolebinding tiller-cluster-rule --clusterrole=cluster-admin --serviceaccount=kube-system:tiller >>$LOG 2>&1) >>$LOG 2>&1
907 espin - $VERIFIED
Test Userb5712372019-07-03 21:52:17 +0000908 bspin - "Update Tiller Manifest"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700909 (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 +0000910
911 # HACK (sort-of) - part to, spin it back up
912 (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 -0700913 espin - $VERIFIED
914else
915 espin $VERIFIED
David Bainbridge46505fb2019-10-01 21:13:20 +0000916 if [ "$UPDATE_HELM_REPOS" == "yes" ]; then
917 bspin - "Update Helm repository cache"
918 (set -x; helm repo update >>$LOG 2>&1) >>$LOG 2>&1
919 espin - $VERIFIED
920 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700921fi
David Bainbridge4f1b5562019-08-19 04:46:52 +0000922wait_for_pods - "kube-system" 1 "includes" -1 "Waiting for Tiller POD to start" "tiller-deploy-.*"
David Bainbridgee87067b2019-08-12 22:00:12 +0000923if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +0000924 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +0000925fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700926
David Bainbridgee87067b2019-08-12 22:00:12 +0000927STIME=$(date +%s)
David Bainbridge0774b232019-08-02 06:37:19 +0000928bspin "Verify Helm values file: $NAME-values.yaml"
929if [ ! -r "./$NAME-values.yaml" ]; then
Test Userba1e7e72019-07-10 22:27:54 +0000930 espin $NOT_VERIFIED
David Bainbridge0774b232019-08-02 06:37:19 +0000931 bspin - "Download Helm values file: $TYPE-values.yaml to $NAME-values.yaml $DOWNLOAD"
David K. Bainbridgea00736b2020-01-08 14:33:17 -0800932 ERR_OUT=$(mktemp)
933 (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
934 if [ $? -ne 0 ]; then
935 espin - $THEX
936 echo -e "${RED}${BOLD}${ERROR}ERROR: $NAME-values.yaml${NORMAL}${RED} - $(cat $ERR_OUT)${NORMAL}"
937 echo "ERROR: $(cat $ERR_OUT)" >>$LOG
938 rm -rf $ERR_OUT ./$NAME-values.yaml
939 exit 1
940 fi
941 rm -rf $ERR_OUT
Test Userba1e7e72019-07-10 22:27:54 +0000942 espin - $VERIFIED
943else
944 espin $VERIFIED
945fi
David Bainbridgee87067b2019-08-12 22:00:12 +0000946if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +0000947 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +0000948fi
Test Userba1e7e72019-07-10 22:27:54 +0000949
David Bainbridge99ac7a22019-08-31 02:26:43 +0000950STIME=$(date +%s)
951bspin "Verify or download chart specific values files $DOWNLOAD"
952VALUES_FILES="monkey-values.yaml"
David K. Bainbridgea00736b2020-01-08 14:33:17 -0800953ERR_OUT=$(mktemp)
David Bainbridge99ac7a22019-08-31 02:26:43 +0000954for i in $VALUES_FILES; do
955 if [ ! -r ./$i ]; then
David K. Bainbridgea00736b2020-01-08 14:33:17 -0800956 (set -x; curl --fail -o ./$i -sSL https://raw.githubusercontent.com/ciena/kind-voltha/$VK_RELEASE/$i >>$LOG 2>$ERR_OUT) >>$LOG 2>&1
957 if [ $? -ne 0 ]; then
958 espin $THEX
959 echo -e "${RED}${BOLD}${ERROR}ERROR: $i${NORMAL}${RED} - $(cat $ERR_OUT)${NORMAL}"
960 echo "ERROR: $i - $(cat $ERR_OUT)" >>$LOG
961 rm -rf $ERR_OUT ./$i
962 exit 1
963 fi
964 rm -rf $ERR_OUT
David Bainbridge99ac7a22019-08-31 02:26:43 +0000965 fi
966done
967espin $VERIFIED
968if [ "$WITH_TIMINGS" == "yes" ]; then
969 printtime $(expr $(date +%s) - $STIME)
970fi
971
972if [ "$WITH_CHAOS" == "yes" ]; then
973 bspin "Verify or clone kube-monkey helm chart $DOWNLOAD"
974 if [ -r ./kube-monkey ]; then
975 espin $VERIFIED
976 else
977 espin $NOT_VERIFIED
978 bspin - "GIT clone kube-monkey"
979 (set -x; git clone https://github.com/asobti/kube-monkey kube-monkey >>$LOG 2>&1) >>$LOG 2>&1
980 espin - $VERIFIED
981 fi
982fi
983
Test Userba1e7e72019-07-10 22:27:54 +0000984if [ "$JUST_K8S" == "yes" ]; then
985 echo "Environment deployed, not deploying VOLTHA artifacts as requested. Good bye."
986 echo ""
987 echo "Please issue the following commands in your terminal to ensure that you" | tee -a $LOG
988 echo "are accessing the correct Kubernetes/Kind cluster as well as have the " | tee -a $LOG
989 echo "tools required by VOLTHA in your command path. " | tee -a $LOG
990 echo "" | tee -a $LOG
991 echo -en $BOLD
992 if [ $DEPLOY_K8S == "yes" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000993 echo "export KUBECONFIG=\"\$(./bin/kind get kubeconfig-path --name=\"voltha-$NAME\")\"" | tee -a $LOG
Test Userba1e7e72019-07-10 22:27:54 +0000994 fi
995 echo "export PATH=$GOPATH/bin:\$PATH" | tee -a $LOG
996 echo -en $NORMAL
997 echo "" | tee -a $LOG
998 echo "Thank you for choosing kind-voltha for you quick cluster needs." | tee -a $LOG
999 exit 0
1000fi
1001
David Bainbridgee87067b2019-08-12 22:00:12 +00001002STIME=$(date +%s)
Test Userb5712372019-07-03 21:52:17 +00001003bspin "Verify ETCD Operator $OLD_KEY"
Test User7d866122019-07-09 17:52:35 +00001004if [ $(helm list --deployed --short --namespace voltha "^etcd-operator\$" | wc -l) -ne 1 ]; then
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001005 espin $NOT_VERIFIED
David Bainbridge90fd8e32019-08-21 23:32:47 +00001006 helm_install - voltha etcd-operator stable/etcd-operator latest "Install ETCD Operator"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001007else
1008 espin $VERIFIED
1009fi
Test User01ed0642019-07-03 20:17:06 +00001010EXPECT=$(test "$TYPE" == "minimal" && echo "1" || echo "3")
David Bainbridge4f1b5562019-08-19 04:46:52 +00001011wait_for_pods - "voltha" $EXPECT "includes" -1 "Waiting for ETCD Operator to start" "etcd-operator-.*"
David Bainbridgee87067b2019-08-12 22:00:12 +00001012if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +00001013 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +00001014fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001015
David Bainbridgee87067b2019-08-12 22:00:12 +00001016STIME=$(date +%s)
David Bainbridgeb270c202019-07-26 01:44:42 +00001017if [ $WITH_ONOS == "yes" ]; then
1018 bspin "Verify ONOS installed $BIRD"
1019 if [ $(helm list --deployed --short --namespace default "^onos\$" | wc -l) -ne 1 ]; then
1020 espin $NOT_VERIFIED
Andrea Campanella6afcb082019-12-18 16:51:30 -08001021 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 +00001022 else
1023 espin $VERIFIED
1024 fi
David Bainbridge4f1b5562019-08-19 04:46:52 +00001025 wait_for_pods - "default" 1 "includes" -1 "Waiting for ONOS to start" "onos-.*"
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001026
David Bainbridgeb270c202019-07-26 01:44:42 +00001027 bspin - "Forward ONOS API port $FORWARD"
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -08001028 kill_port_forward onos-ui
1029 port_forward default onos-ui $ONOS_API_PORT 8181
David Bainbridgeb270c202019-07-26 01:44:42 +00001030 espin - $VERIFIED
1031 bspin - "Forward ONOS SSH port $FORWARD"
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -08001032 kill_port_forward onos-ssh
1033 port_forward default onos-ssh $ONOS_SSH_PORT 8101
David Bainbridgeb270c202019-07-26 01:44:42 +00001034 espin - $VERIFIED
David Bainbridged31d6122019-08-13 19:37:59 +00001035 bspin - "Verify or download ONOS configuration support files $DOWNLOAD"
David Bainbridge2b19e832019-08-16 02:40:53 +00001036 ONOS_FILES="olt-onos-enableExtraneousRules.json olt-onos-olt-settings.json onos-aaa.json \
David Bainbridge90fd8e32019-08-21 23:32:47 +00001037 onos-dhcpl2relay.json onos-kafka.json onos-sadis-sample.json"
David Bainbridged31d6122019-08-13 19:37:59 +00001038 (set -x; mkdir -p ./onos-files >>$LOG 2>&1) >>$LOG 2>&1
David K. Bainbridgea00736b2020-01-08 14:33:17 -08001039 ERR_OUT=$(mktemp)
David Bainbridge2b19e832019-08-16 02:40:53 +00001040 for i in $ONOS_FILES; do
David Bainbridged31d6122019-08-13 19:37:59 +00001041 if [ ! -r ./onos-files/$i ]; then
David K. Bainbridgea00736b2020-01-08 14:33:17 -08001042 (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
1043 if [ $? -ne 0 ]; then
1044 espin - $THEX
1045 echo -e "${RED}${BOLD}${ERROR}ERROR: $i${NORMAL}${RED} - $(cat $ERR_OUT)${NORMAL}"
1046 echo "ERROR: $(cat $ERR_OUT)" >>$LOG
1047 rm -rf $ERR_OUT ./onos-files/$i
1048 exit 1
1049 fi
1050 rm -rf $ERR_OUT
David Bainbridged31d6122019-08-13 19:37:59 +00001051 fi
1052 done
Test Userba1e7e72019-07-10 22:27:54 +00001053 espin - $VERIFIED
David Bainbridge27790d62019-08-13 22:43:19 +00001054
1055 if [ $INSTALL_ONOS_APPS == "yes" ]; then
1056 bspin - "Installing custom ONOS applications"
1057 if [ -x onos-files/onos-apps -a $(ls -1 onos-files/onos-apps/*.oar 2>/dev/null | wc -l) -gt 0 ]; then
1058 for OAR in $(ls -1 onos-files/onos-apps/*.oar); do
1059 sspin - "Installing custom ONOS applications - $OAR$CEOL"
David Bainbridge2b19e832019-08-16 02:40:53 +00001060 override_onos_app $OAR
David Bainbridge27790d62019-08-13 22:43:19 +00001061 done
1062 espin - "$VERIFIED Installing custom ONOS applications$CEOL"
1063 else
1064 espin - "$NOT_VERIFIED Installing custom ONOS applications - None Found"
1065 fi
1066 fi
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001067
David Bainbridge2b19e832019-08-16 02:40:53 +00001068 push_onos_config "Push ONOS Kafka Configuration" "network/configuration/apps/org.opencord.kafka" "onos-files/onos-kafka.json"
1069 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 +00001070 push_onos_config "Enable VOLTHA ONOS DHCP provisioning" "configuration/org.opencord.olt.impl.Olt" "onos-files/olt-onos-olt-settings.json"
1071 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 +00001072 if [ -f onos-files/onos-sadis.json ]; then
1073 push_onos_config "[optional] Push ONOS SADIS Configuration" "network/configuration/apps/org.opencord.sadis" "onos-files/onos-sadis.json"
1074 elif [ "$CONFIG_SADIS" == "yes" ]; then
David Bainbridge90fd8e32019-08-21 23:32:47 +00001075 SADIS_CFG=onos-files/onos-sadis-sample.json
David Bainbridge2b19e832019-08-16 02:40:53 +00001076 push_onos_config "[optional] Push ONOS SADIS Configuration" "network/configuration/apps/org.opencord.sadis" "$SADIS_CFG"
1077 fi
Test Userba1e7e72019-07-10 22:27:54 +00001078fi
David Bainbridgee87067b2019-08-12 22:00:12 +00001079if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +00001080 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +00001081fi
Test Userba1e7e72019-07-10 22:27:54 +00001082
David Bainbridgee87067b2019-08-12 22:00:12 +00001083STIME=$(date +%s)
Test Userb5712372019-07-03 21:52:17 +00001084bspin "Verify VOLTHA installed $HIGH_VOLTAGE"
Test User7d866122019-07-09 17:52:35 +00001085if [ $(helm list --deployed --short --namespace voltha "^voltha\$" | wc -l) -ne 1 ]; then
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001086 espin $NOT_VERIFIED
David Bainbridge70c0ea82019-11-14 23:25:26 +00001087 if [ "$ONLY_ONE" == "yes" ]; then
1088 EXTRA_HELM_INSTALL_ARGS="--set therecanbeonlyone=true"=
1089 fi
David Bainbridge90fd8e32019-08-21 23:32:47 +00001090 helm_install - voltha voltha $VOLTHA_CHART $VOLTHA_CHART_VERSION "Install VOLTHA Core"
David Bainbridge70c0ea82019-11-14 23:25:26 +00001091 EXTRA_HELM_INSTALL_ARGS=
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001092else
1093 espin $VERIFIED
1094fi
Test Userba1e7e72019-07-10 22:27:54 +00001095
David Bainbridge90fd8e32019-08-21 23:32:47 +00001096VOLTHA="voltha-ofagent-.* \
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001097 ro-core.* \
1098 rw-core.* \
1099 voltha-api-server-.* \
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001100 voltha-etcd-cluster-.* \
1101 voltha-kafka-.* \
1102 voltha-zookeeper-.*"
David Bainbridge70c0ea82019-11-14 23:25:26 +00001103if [ "$ONLY_ONE" == "yes" ]; then
David Bainbridge1ba64f12019-12-18 00:40:13 +00001104 EXPECT=$(test "$TYPE" == "minimal" && echo "5" || echo "7")
David Bainbridge70c0ea82019-11-14 23:25:26 +00001105else
David Bainbridge1ba64f12019-12-18 00:40:13 +00001106 EXPECT=$(test "$TYPE" == "minimal" && echo "8" || echo "10")
David Bainbridge70c0ea82019-11-14 23:25:26 +00001107fi
David Bainbridge4f1b5562019-08-19 04:46:52 +00001108wait_for_pods - "voltha" $EXPECT "includes" -1 "Waiting for VOLTHA Core to start" $VOLTHA
David Bainbridgee87067b2019-08-12 22:00:12 +00001109if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +00001110 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +00001111fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001112
David Bainbridge46505fb2019-10-01 21:13:20 +00001113if [ "$WITH_ADAPTERS" == "yes" ]; then
1114 STIME=$(date +%s)
1115 EXPECT=0
1116 echo -e "Verify Adapters $PLUG"
1117 if [ "$WITH_SIM_ADAPTERS" == "yes" ]; then
1118 bspin - "Verify Simulated Adapters installed"
1119 if [ $(helm list --deployed --short --namespace voltha "^sim\$" | wc -l) -ne 1 ]; then
1120 espin - $NOT_VERIFIED
1121 helm_install - voltha sim $VOLTHA_ADAPTER_SIM_CHART $VOLTHA_ADAPTER_SIM_CHART_VERSION "Install Simulated Adapters"
1122 else
1123 espin - $VERIFIED
1124 fi
1125 EXPECT=$(expr $EXPECT + 2)
1126 fi
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001127
David Bainbridge46505fb2019-10-01 21:13:20 +00001128 if [ "$WITH_OPEN_ADAPTERS" == "yes" ]; then
1129 bspin - "Verify OpenOLT Adapter installed"
1130 if [ $(helm list --deployed --short --namespace voltha "^open-olt\$" | wc -l) -ne 1 ]; then
1131 espin - $NOT_VERIFIED
1132 helm_install - voltha open-olt $VOLTHA_ADAPTER_OPEN_OLT_CHART $VOLTHA_ADAPTER_OPEN_OLT_CHART_VERSION "Install OpenOLT Adapter"
1133 else
1134 espin - $VERIFIED
1135 fi
1136 bspin - "Verify OpenONU Adapter installed"
1137 if [ $(helm list --deployed --short --namespace voltha "^open-onu\$" | wc -l) -ne 1 ]; then
1138 espin - $NOT_VERIFIED
1139 helm_install - voltha open-onu $VOLTHA_ADAPTER_OPEN_ONU_CHART $VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION "Install OpenONU Adapter"
1140 else
1141 espin - $VERIFIED
1142 fi
1143 EXPECT=$(expr $EXPECT + 2)
1144 fi
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001145
David Bainbridge46505fb2019-10-01 21:13:20 +00001146 ADAPTERS="adapter-.*"
1147 wait_for_pods - "voltha" $EXPECT "includes" -1 "Waiting for adapters to start" $ADAPTERS
1148 if [ "$WITH_TIMINGS" == "yes" ]; then
1149 printtime $(expr $(date +%s) - $STIME)
1150 fi
David Bainbridgee87067b2019-08-12 22:00:12 +00001151fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001152
Test User7d866122019-07-09 17:52:35 +00001153if [ $WITH_BBSIM == "yes" ]; then
David Bainbridgee87067b2019-08-12 22:00:12 +00001154 STIME=$(date +%s)
Test User7d866122019-07-09 17:52:35 +00001155 echo -e "Verify BBSIM $PLUG"
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001156 bspin - "Verify BBSIM Installed"
Test User7d866122019-07-09 17:52:35 +00001157 if [ $(helm list --deployed --short --namespace voltha "^bbsim\$" | wc -l) -ne 1 ]; then
1158 espin - $NOT_VERIFIED
David Bainbridge90fd8e32019-08-21 23:32:47 +00001159 helm_install - voltha bbsim $VOLTHA_BBSIM_CHART $VOLTHA_BBSIM_CHART_VERSION "Install BBSIM"
Test User7d866122019-07-09 17:52:35 +00001160 else
1161 espin - $VERIFIED
1162 fi
David Bainbridge4f1b5562019-08-19 04:46:52 +00001163 wait_for_pods - "voltha" 1 "includes" -1 "Waiting for BBSIM to start" "bbsim-.*"
David Bainbridgee87067b2019-08-12 22:00:12 +00001164 if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +00001165 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +00001166 fi
Test User7d866122019-07-09 17:52:35 +00001167fi
1168
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001169if [ $WITH_RADIUS == "yes" ]; then
David Bainbridgee87067b2019-08-12 22:00:12 +00001170 STIME=$(date +%s)
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001171 echo -e "Verify RADIUS $LOCK"
1172 bspin - "Verify RADIUS Installed"
1173 if [ $(helm list --deployed --short --namespace voltha "^radius\$" | wc -l) -ne 1 ]; then
1174 espin - $NOT_VERIFIED
David Bainbridge90fd8e32019-08-21 23:32:47 +00001175 helm_install - voltha radius onf/freeradius latest "Install RADIUS"
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001176 else
1177 espin - $VERIFIED
1178 fi
David Bainbridge4f1b5562019-08-19 04:46:52 +00001179 wait_for_pods - "voltha" 1 "includes" -1 "Waiting for RADIUS to start" "radius-.*"
David Bainbridgee87067b2019-08-12 22:00:12 +00001180 if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +00001181 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +00001182 fi
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001183fi
1184
David Bainbridgee87067b2019-08-12 22:00:12 +00001185STIME=$(date +%s)
Test Userb5712372019-07-03 21:52:17 +00001186bspin - "Forward VOLTHA API port $FORWARD"
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -08001187kill_port_forward voltha-api
1188port_forward voltha voltha-api $VOLTHA_API_PORT 55555
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001189espin - $VERIFIED
David Bainbridgeac7f8072019-08-01 22:15:33 +00001190bspin - "Forward VOLTHA ETCD port $FORWARD"
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -08001191kill_port_forward voltha-etcd-cluster-client
1192port_forward voltha voltha-etcd-cluster-client $VOLTHA_ETCD_PORT 2379
David Bainbridgeac7f8072019-08-01 22:15:33 +00001193espin - $VERIFIED
David Bainbridgee87067b2019-08-12 22:00:12 +00001194if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +00001195 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +00001196fi
Test User3d7ad8e2019-07-03 06:15:44 +00001197
David Bainbridgeb270c202019-07-26 01:44:42 +00001198if [ $WITH_ONOS == "yes" -a $WITH_RADIUS == "yes" ]; then
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001199 bspin "Configure ONOS RADIUS Connection $GEAR"
Andy Bavier658ebef2019-11-05 17:22:56 -07001200 (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 +00001201 espin $VERIFIED
1202fi
1203
David Bainbridge99ac7a22019-08-31 02:26:43 +00001204if [ "$WITH_CHAOS" == "yes" ]; then
1205 STIME=$(date +%s)
1206 echo -e "Verify kube-monkey $LOCK"
1207 bspin - "Verify kube-monkey Installed"
1208 if [ $(helm list --deployed --short --namespace kube-monkey "^monkey\$" | wc -l) -ne 1 ]; then
1209 espin - $NOT_VERIFIED
1210 helm_install - kube-monkey monkey ./kube-monkey/helm/kubemonkey latest "Install Chaos Monkey"
1211 else
1212 espin - $VERIFIED
1213 fi
1214 wait_for_pods - "kube-monkey" 1 "includes" -1 "Waiting for Chaos to start" "monkey-.*"
1215 if [ "$WITH_TIMINGS" == "yes" ]; then
1216 printtime $(expr $(date +%s) - $STIME)
1217 fi
1218fi
1219
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001220bspin "Create voltctl configuration file"
Test User3d7ad8e2019-07-03 06:15:44 +00001221(set -x; mkdir -p $HOME/.volt >>$LOG 2>&1) >>$LOG 2>&1
David Bainbridge0774b232019-08-02 06:37:19 +00001222(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 +00001223espin $VERIFIED
Test User08ebbd92019-07-03 17:15:39 +00001224
David Bainbridge0774b232019-08-02 06:37:19 +00001225if [ ! -f "$NAME-env.sh" ]; then
1226 touch $NAME-env.sh
David Bainbridgeb07fdf72019-07-29 22:51:40 +00001227fi
1228
David Bainbridge596f30d2019-07-30 17:07:59 +00001229for O in $ALL_OPTIONS; do
1230 VAL=$(eval echo \$$O)
David Bainbridge0774b232019-08-02 06:37:19 +00001231 if [ ! -z "$VAL" -a $(grep -c "^export $O=" $NAME-env.sh) -eq 0 ]; then
1232 echo "export $O=\"$(eval echo \$$O)\"" >> $NAME-env.sh
David Bainbridgeb07fdf72019-07-29 22:51:40 +00001233 fi
1234done
1235
David Bainbridge0774b232019-08-02 06:37:19 +00001236if [ $DEPLOY_K8S == "yes" -a $(grep -c "^export KUBECONFIG=" $NAME-env.sh) -eq 0 ]; then
1237 echo "export KUBECONFIG=\"$(./bin/kind get kubeconfig-path --name=voltha-$NAME)\"" >> $NAME-env.sh
David Bainbridgeb07fdf72019-07-29 22:51:40 +00001238fi
1239
David Bainbridge0774b232019-08-02 06:37:19 +00001240if [ $(grep -c "^export VOLTCONFIG=" $NAME-env.sh) -eq 0 ]; then
1241 echo "export VOLTCONFIG=\"$HOME/.volt/config-$NAME\"" >> $NAME-env.sh
David Bainbridgeb07fdf72019-07-29 22:51:40 +00001242fi
1243
David Bainbridge0774b232019-08-02 06:37:19 +00001244if [ $(grep -c "^export PATH=" $NAME-env.sh) -eq 0 ]; then
1245 echo "export PATH=\"$GOPATH/bin:\$PATH\"" >> $NAME-env.sh
David Bainbridgeb07fdf72019-07-29 22:51:40 +00001246fi
1247
Test User7d866122019-07-09 17:52:35 +00001248echo ""
Test User08ebbd92019-07-03 17:15:39 +00001249echo "Please issue the following commands in your terminal to ensure that you" | tee -a $LOG
1250echo "are accessing the correct Kubernetes/Kind cluster as well as have the " | tee -a $LOG
1251echo "tools required by VOLTHA in your command path. " | tee -a $LOG
1252echo "" | tee -a $LOG
Test User7d866122019-07-09 17:52:35 +00001253echo -en $BOLD
Test Userba1e7e72019-07-10 22:27:54 +00001254if [ $DEPLOY_K8S == "yes" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +00001255 echo "export KUBECONFIG=\"\$(./bin/kind get kubeconfig-path --name=\"voltha-$NAME\")\"" | tee -a $LOG
Test Userba1e7e72019-07-10 22:27:54 +00001256fi
David Bainbridge0774b232019-08-02 06:37:19 +00001257echo "export VOLTCONFIG=\"$HOME/.volt/config-$NAME\"" | tee -a $LOG
Test Userba1e7e72019-07-10 22:27:54 +00001258echo "export PATH=$GOPATH/bin:\$PATH" | tee -a $LOG
Test User7d866122019-07-09 17:52:35 +00001259echo -en $NORMAL
Test User08ebbd92019-07-03 17:15:39 +00001260echo "" | tee -a $LOG
1261echo "Thank you for choosing kind-voltha for you quick cluster needs." | tee -a $LOG
1262
David Bainbridge712afb82019-08-14 19:55:58 +00001263if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridgef858a022019-08-14 21:25:11 +00001264 echo -e "$CLOCK ${BOLD}TOTAL: $(duration $(expr $(date +%s) - $TOTAL_START_TIME))${NORMAL}"
David Bainbridge712afb82019-08-14 19:55:58 +00001265fi