blob: 7e268327d08394387bb3dd127fecc1d82c011f3d [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}
Test User08ebbd92019-07-03 17:15:39 +000035
David Bainbridge38dc1e82019-08-12 15:18:45 +000036BLACK=
37RED=
38GREEN=
39YELLOW=
40BLUE=
41MAGENTA=
42CYAN=
43WHITE=
44BOLD=
45NORMAL=
46ERROR=
47CEOL=
48CNORM=
49CIVIS=
50if [ $FANCY -eq 1 ]; then
51 BLACK=$(tput setaf 0)
52 RED=$(tput setaf 1)
53 GREEN=$(tput setaf 2)
54 YELLOW=$(tput setaf 3)
55 BLUE=$(tput setaf 4)
56 MAGENTA=$(tput setaf 5)
57 CYAN=$(tput setaf 6)
58 WHITE=$(tput setaf 7)
59 BOLD=$(tput bold)
60 NORMAL=$(tput sgr0)
61 ERROR="\xe2\x9c\x97\x20"
62 CEOL=$(tput el)
63 CNORM=$(tput cnorm)
64 CIVIS=$(tput civis)
65fi
Test User7d866122019-07-09 17:52:35 +000066
Test User3d7ad8e2019-07-03 06:15:44 +000067TYPE=${TYPE:-minimal}
David Bainbridge0774b232019-08-02 06:37:19 +000068NAME=${NAME:-$TYPE}
David Bainbridgee87067b2019-08-12 22:00:12 +000069WITH_TIMINGS=${WITH_TIMINGS:-no}
Test User7d866122019-07-09 17:52:35 +000070WITH_BBSIM=${WITH_BBSIM:-no}
David Bainbridge5b7b96b2019-07-25 20:29:13 +000071WITH_RADIUS=${WITH_RADIUS:-no}
David Bainbridgeb270c202019-07-26 01:44:42 +000072WITH_ONOS=${WITH_ONOS:-yes}
David Bainbridge99ac7a22019-08-31 02:26:43 +000073WITH_CHAOS=${WITH_CHAOS:-no}
David Bainbridge46505fb2019-10-01 21:13:20 +000074WITH_ADAPTERS=${WITH_ADAPTERS:-yes}
75WITH_SIM_ADAPTERS=${WITH_SIM_ADAPTERS:-yes}
76WITH_OPEN_ADAPTERS=${WITH_OPEN_ADAPTERS:-yes}
David Bainbridge05cd8822019-11-19 17:43:53 +000077ONLY_ONE=${ONLY_ONE:-yes}
David Bainbridge2b19e832019-08-16 02:40:53 +000078CONFIG_SADIS=${CONFIG_SADIS:-no}
David Bainbridge27790d62019-08-13 22:43:19 +000079INSTALL_ONOS_APPS=${INSTALL_ONOS_APPS:-no}
Test Userba1e7e72019-07-10 22:27:54 +000080JUST_K8S=${JUST_K8S:-no}
81DEPLOY_K8S=${DEPLOY_K8S:-yes}
David K. Bainbridge0e89cb92019-07-17 11:30:10 -070082INSTALL_KUBECTL=${INSTALL_KUBECTL:-yes}
83INSTALL_HELM=${INSTALL_HELM:-yes}
David Bainbridge46505fb2019-10-01 21:13:20 +000084UPDATE_HELM_REPOS=${UPDATE_HELM_REPOS:-yes}
David Bainbridge4f1b5562019-08-19 04:46:52 +000085WAIT_ON_DOWN=${WAIT_ON_DOWN:-no}
David Bainbridge5b7b96b2019-07-25 20:29:13 +000086VOLTHA_LOG_LEVEL=${VOLTHA_LOG_LEVEL:-WARN}
David Bainbridge90fd8e32019-08-21 23:32:47 +000087VOLTHA_CHART=${VOLTHA_CHART:-onf/voltha}
88VOLTHA_CHART_VERSION=${VOLTHA_CHART_VERSION:-latest}
89VOLTHA_BBSIM_CHART=${VOLTHA_BBSIM_CHART:-onf/bbsim}
Matteo Scandolodcd29f52019-10-07 15:42:42 -070090VOLTHA_BBSIM_CHART_VERSION=${VOLTHA_BBSIM_CHART_VERSION:-latest}
David Bainbridgee10f6d52019-07-25 00:28:13 +000091VOLTHA_ADAPTER_SIM_CHART=${VOLTHA_ADAPTER_SIM_CHART:-onf/voltha-adapter-simulated}
David Bainbridge90fd8e32019-08-21 23:32:47 +000092VOLTHA_ADAPTER_SIM_CHART_VERSION=${VOLTHA_ADAPTER_SIM_CHART_VERSION:-latest}
David Bainbridgee10f6d52019-07-25 00:28:13 +000093VOLTHA_ADAPTER_OPEN_OLT_CHART=${VOLTHA_ADAPTER_OPEN_OLT_CHART:-onf/voltha-adapter-openolt}
David Bainbridge90fd8e32019-08-21 23:32:47 +000094VOLTHA_ADAPTER_OPEN_OLT_CHART_VERSION=${VOLTHA_ADAPTER_OPEN_OLT_CHART_VERSION:-latest}
David Bainbridgee10f6d52019-07-25 00:28:13 +000095VOLTHA_ADAPTER_OPEN_ONU_CHART=${VOLTHA_ADAPTER_OPEN_ONU_CHART:-onf/voltha-adapter-openonu}
David Bainbridge90fd8e32019-08-21 23:32:47 +000096VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION=${VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION:-latest}
Andrea Campanella21323292019-12-18 11:44:19 -080097ONOS_CHART_VERSION=${ONOS_CHART_VERSION:-latest}
David Bainbridge70c0ea82019-11-14 23:25:26 +000098EXTRA_HELM_INSTALL_ARGS=
Test Userba1e7e72019-07-10 22:27:54 +000099
100HAVE_GO=$(which go >/dev/null 2>&1 && echo "yes" || echo "no")
101HOSTOS=$(uname -s | tr "[:upper:]" "[:lower:"])
102HOSTARCH=$(uname -m | tr "[:upper:]" "[:lower:"])
103if [ $HOSTARCH == "x86_64" ]; then
104 HOSTARCH="amd64"
105fi
Test User7d866122019-07-09 17:52:35 +0000106
107# Verify TYPE setting
108if [ $(echo ":minimal:full:" | grep -ic ":$TYPE:") -eq 0 ]; then
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700109 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} Invalid \$TYPE value of '$TYPE'. Should be 'minimal' or 'full'${NORMAL}"
Test User7d866122019-07-09 17:52:35 +0000110 exit 1
111fi
112
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000113# Used to verify configuration values are set to "yes" or "no" value or convert
114# equivalents to "yes" or "no"
115function verify_yes_no() {
116 local VAR=$1
117 local VAL=$(eval echo \$$VAR)
118 if [ $(echo ":y:yes:true:n:no:false:1:0:" | grep -ic ":$VAL:") -eq 0 ]; then
119 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} Invalid '$VAR' value of '$VAL'. Should be 'yes' or 'no'${NORMAL}"
120 echo "INVALID"
121 return 1
122 fi
123 if [ $(echo ":y:yes:true:1:" | grep -ic ":$VAL:") -eq 1 ]; then
124 echo "yes"
125 else
126 echo "no"
127 fi
128 return 0
129}
Test User7d866122019-07-09 17:52:35 +0000130
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000131ALL_YES_NO="\
132 WITH_TIMINGS \
133 WITH_BBSIM \
134 WITH_RADIUS \
135 WITH_ONOS \
David Bainbridge99ac7a22019-08-31 02:26:43 +0000136 WITH_CHAOS \
David Bainbridge46505fb2019-10-01 21:13:20 +0000137 WITH_ADAPTERS \
138 WITH_SIM_ADAPTERS \
139 WITH_OPEN_ADAPTERS \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000140 CONFIG_SADIS \
141 JUST_K8S \
142 DEPLOY_K8S \
143 INSTALL_ONOS_APPS \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000144 INSTALL_KUBECTL \
145 INSTALL_HELM \
David Bainbridge46505fb2019-10-01 21:13:20 +0000146 UPDATE_HELM_REPOS \
David Bainbridge4f1b5562019-08-19 04:46:52 +0000147 WAIT_ON_DOWN \
David Bainbridge70c0ea82019-11-14 23:25:26 +0000148 ONLY_ONE \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000149 "
David Bainbridge5b7b96b2019-07-25 20:29:13 +0000150
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000151ALL_OPTIONS="\
152 NAME \
153 TYPE \
154 $ALL_YES_NO \
155 VOLTHA_LOG_LEVEL \
156 VOLTHA_CHART \
David Bainbridge90fd8e32019-08-21 23:32:47 +0000157 VOLTHA_CHART_VERSION \
158 VOLTHA_BBSIM_CHART \
159 VOLTHA_BBSIM_CHART_VERSION \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000160 VOLTHA_ADAPTER_SIM_CHART \
David Bainbridge90fd8e32019-08-21 23:32:47 +0000161 VOLTHA_ADAPTER_SIM_CHART_VERSION \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000162 VOLTHA_ADAPTER_OPEN_OLT_CHART \
David Bainbridge90fd8e32019-08-21 23:32:47 +0000163 VOLTHA_ADAPTER_OPEN_OLT_CHART_VERSION \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000164 VOLTHA_ADAPTER_OPEN_ONU_CHART \
David Bainbridge90fd8e32019-08-21 23:32:47 +0000165 VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION \
Andrea Campanella21323292019-12-18 11:44:19 -0800166 ONOS_CHART_VERSION \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000167 ONOS_API_PORT \
168 ONOS_SSH_PORT \
169 VOLTHA_API_PORT \
170 VOLTHA_SSH_PORT \
171 VOLTHA_ETCD_PORT \
172 "
David Bainbridge01294952019-07-30 19:33:45 +0000173
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000174# Iterate over yes/no configuration options and validate
175for VAR in $ALL_YES_NO; do
176 eval $VAR=$(verify_yes_no $VAR)
177 if [ "$(eval echo \$$VAR)" == "INVALID" ]; then
178 exit 1;
179 fi
180done
David Bainbridgeb270c202019-07-26 01:44:42 +0000181
David Bainbridge0774b232019-08-02 06:37:19 +0000182mkdir -p .voltha
183touch .voltha/ports
184HAVE=$(grep $NAME .voltha/ports)
185if [ "$HAVE X" == " X" ]; then
186 # Find free port prefix
187 START=81
188 while true; do
189 if [ $(grep -c $START .voltha/ports) -eq 0 ]; then
190 break
191 fi
192 START=$(expr $START + 1)
193 done
194 DELTA=$(expr $START - 81)
David Bainbridgea2595422019-10-22 03:54:28 +0000195 ONOS_API_PORT=${ONOS_API_PORT:-${START}81}
196 ONOS_SSH_PORT=${ONOS_SSH_PORT:-${START}01}
197 VOLTHA_API_PORT=${VOLTHA_API_PORT:-5$(expr 55 + $DELTA)55}
198 VOLTHA_SSH_PORT=${VOLTHA_SSH_PORT:-$(expr 50 + $DELTA)22}
199 VOLTHA_ETCD_PORT=${VOLTHA_ETCD_PORT:-$(expr 23 + $DELTA)79}
Test User01ed0642019-07-03 20:17:06 +0000200else
David Bainbridge0774b232019-08-02 06:37:19 +0000201 VALUES=$(echo $HAVE | sed -e 's/\s//g' | cut -d= -f2)
David Bainbridgea2595422019-10-22 03:54:28 +0000202 ONOS_API_PORT=${ONOS_API_PORT:-$(echo $VALUES | cut -d, -f1)}
203 ONOS_SSH_PORT=${ONOS_SSH_PORT:-$(echo $VALUES | cut -d, -f2)}
204 VOLTHA_API_PORT=${VOLTHA_API_PORT:-$(echo $VALUES | cut -d, -f3)}
205 VOLTHA_SSH_PORT=${VOLTHA_SSH_PORT:-$(echo $VALUES | cut -d, -f4)}
206 VOLTHA_ETCD_PORT=${VOLTHA_ETCD_PORT:-$(echo $VALUES | cut -d, -f5)}
Test User01ed0642019-07-03 20:17:06 +0000207fi
208
David Bainbridge0774b232019-08-02 06:37:19 +0000209PORTTMP=$(mktemp -u)
210cat .voltha/ports | grep -v $NAME > $PORTTMP
211echo "$NAME=$ONOS_API_PORT,$ONOS_SSH_PORT,$VOLTHA_API_PORT,$VOLTHA_SSH_PORT,$VOLTHA_ETCD_PORT" >> $PORTTMP
212cp $PORTTMP .voltha/ports
213rm -f $PORTTMP
214
David Bainbridge27790d62019-08-13 22:43:19 +0000215export ONOS_API_PORT ONOS_SSH_PORT
David Bainbridge01294952019-07-30 19:33:45 +0000216
Test Userd87942b2019-07-03 07:20:24 +0000217IDX=1
David Bainbridgee87067b2019-08-12 22:00:12 +0000218CLOCK="TIME:"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000219SPIN_PARTS=
220NOT_VERIFIED=
David Bainbridgef858a022019-08-14 21:25:11 +0000221THEX=
222BUILD=
223CROSS=
224ENTER=
David Bainbridge38dc1e82019-08-12 15:18:45 +0000225VERIFIED=
226HELM=
227OLD_KEY=
228BIRD=
229HIGH_VOLTAGE=
230PLUG=
231RESTART=
232FORWARD=
233INSTALL=
234STOP=
235GO=
236DOWNLOAD=
237GEAR=
238NO_ENTRY=
239LOCK=
240
241if [ $FANCY -eq 1 ]; then
242 SPIN_PARTS="\
243 \xe2\xa2\x8e\xe2\xa1\xb0 \
244 \xe2\xa2\x8e\xe2\xa1\xa1 \
245 \xe2\xa2\x8e\xe2\xa1\x91 \
246 \xe2\xa2\x8e\xe2\xa0\xb1 \
247 \xe2\xa0\x8e\xe2\xa1\xb1 \
248 \xe2\xa2\x8a\xe2\xa1\xb1 \
249 \xe2\xa2\x8c\xe2\xa1\xb1 \
250 \xe2\xa2\x86\xe2\xa1\xb1 \
251 "
David Bainbridgee87067b2019-08-12 22:00:12 +0000252 CLOCK="\xe2\x8f\xb1"
David Bainbridgef858a022019-08-14 21:25:11 +0000253 THEX="${RED}${BOLD}\xe2\x9c\x97\x20${NORMAL}"
254 ENTER="${YELLOW}${BOLD}\xe2\x8e\x86${NORMAL}"
255 CROSS="${YELLOW}${BOLD}\xe2\x9c\x9a${NORMAL}"
256 BUILD="${YELLOW}${BOLD}\xf0\x9f\x8f\x97${NORMAL}"
257 NOT_VERIFIED="$BUILD"
258 VERIFIED="${GREEN}${BOLD}\xe2\x9c\x93\x20${NORMAL}"
259 HELM="${BLUE}${BOLD}\xE2\x8E\x88${NORMAL}"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000260 OLD_KEY="\xF0\x9F\x97\x9D"
261 BIRD="\xF0\x9F\x90\xA6"
262 HIGH_VOLTAGE="\xE2\x9A\xA1"
263 PLUG="\xF0\x9F\xa7\xa9"
264 RESTART="\xf0\x9f\x94\x84"
265 FORWARD="\xE2\x87\xA8"
266 INSTALL="\xF0\x9F\x8F\x97"
267 STOP="\xf0\x9f\x9b\x91"
268 GO="\xf0\x9f\x9a\x80"
269 DOWNLOAD="\xf0\x9f\x93\xa5"
270 GEAR="\xe2\x9a\x99"
271 NO_ENTRY="\xe2\x9b\x94"
272 LOCK="\xf0\x9f\x94\x92"
273fi
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700274
David Bainbridge712afb82019-08-14 19:55:58 +0000275duration() {
David Bainbridgee87067b2019-08-12 22:00:12 +0000276 local h=$(expr $1 / 3600)
277 local m=$(expr $1 % 3600 / 60)
278 local s=$(expr $1 % 60)
279 local t=""
280
281 if [ $h -gt 0 ]; then
282 t="$t${h}h"
283 fi
284 if [ $m -gt 0 ]; then
285 t="$t${m}m"
286 fi
David Bainbridge712afb82019-08-14 19:55:58 +0000287 echo "$t${s}s"
288}
289
290printtime() {
291 local INDENT=
292 if [ "$1" == "-" ]; then
293 INDENT=" "
294 shift
295 fi
296 echo -e "$INDENT $CLOCK $(duration $1)"
David Bainbridgee87067b2019-08-12 22:00:12 +0000297}
298
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700299bspin() {
Test Userd87942b2019-07-03 07:20:24 +0000300 IDX=1
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700301 local INDENT=
302 if [ "$1" == "-" ]; then
303 INDENT=" "
304 shift
305 fi
David Bainbridge38dc1e82019-08-12 15:18:45 +0000306 if [ $FANCY -eq 0 ]; then
307 LINE=$(echo $* | sed -e 's/[\s+-]//g')
308 if [ "$LINE X" == " X" ]; then
309 return
310 fi
311 echo -e "$CIVIS$INDENT$*"
312 else
313 echo -en "$CIVIS$INDENT $*"
314 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700315}
316
317sspin() {
318 local INDENT=
319 if [ "$1" == "-" ]; then
320 INDENT=" "
321 shift
322 fi
David Bainbridge38dc1e82019-08-12 15:18:45 +0000323 if [ $FANCY -eq 0 ]; then
324 LINE=$(echo $* | sed -e 's/[\s+-]//g')
325 if [ "$LINE X" == " X" ]; then
326 return
327 fi
328 echo -e "$INDENT$*"
329 else
330 C=$(echo $SPIN_PARTS | cut '-d ' -f $IDX)
331 echo -en "\r$INDENT$C $*"
332 IDX=$(expr $IDX + 1)
333 if [ $IDX -gt 8 ]; then
334 IDX=1
335 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700336 fi
337}
338
339espin() {
340 local INDENT=
341 if [ "$1" == "-" ]; then
342 INDENT=" "
343 shift
344 fi
David Bainbridge38dc1e82019-08-12 15:18:45 +0000345 if [ $FANCY -eq 0 ]; then
346 LINE=$(echo $* | sed -e 's/[\s+-]//g')
347 if [ "$LINE X" == " X" ]; then
348 return
349 fi
350 echo -e "$INDENT$*"
351 else
352 echo -e "\r$INDENT$*$CNORM"
353 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700354}
355
David Bainbridgeac7f8072019-08-01 22:15:33 +0000356if [ "$1" == "get" -a "$2" == "voltconfig" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000357 echo "$HOME/.volt/config-$NAME"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000358 exit
359fi
360
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -0700361if [ $# -ne 1 -o $(echo ":up:down:dump:" | grep -c ":$1:") -ne 1 ]; then
David Bainbridgeac7f8072019-08-01 22:15:33 +0000362 >&2 echo "What wouild you like to do today:"
363 >&2 echo " up - bring up voltha"
364 >&2 echo " down - tear down voltha"
365 >&2 echo " dump - create a debug dump of running system"
366 exit 1
367fi
368
David Bainbridge4f1b5562019-08-19 04:46:52 +0000369push_onos_config() {
370 local MSG=$1
371 local RESOURCE=$2
372 local DATA=$3
373
374 bspin - "$MSG $GEAR"
375 while true; do
376 (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
377 if [ $? -eq 0 ]; then
378 break
379 fi
380 sleep .2
381 sspin -
382 done
383 espin - $VERIFIED
384}
385
386override_onos_app() {
387 local APP=$1
388 local NAME=$(basename $APP | sed -e 's/^[0-9][0-9]*-//g' -e 's/-.*$//g')
389 while true; do
390 sspin -
391 # Attempt to delete old version (if it exists)
392 (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
393 sspin -
394 if [ $? -ne 0 ]; then
395 continue
396 fi
397 (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
398 if [ $? -eq 0 ]; then
399 break
400 fi
401 sleep .2
402 done
403}
404
405activate_onos_app() {
406 local MSG="$1"
407 local APP=$2
408
409 bspin - "$MSG $GO"
410 while true; do
411 sspin -
412 (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
413 if [ $? -eq 0 ]; then
414 break
415 fi
416 sleep .2
417 done
418 espin - "$VERIFIED"
419}
420
421count_pods() {
422 local NAMESPACE=$1; shift
423 if [ "$NAMESPACE" == "all-namespaces" ]; then
424 NAMESPACE="--all-namespaces"
425 else
426 NAMESPACE="-n $NAMESPACE"
427 fi
428 echo "$NAMESPACE" > /tmp/t
429 local STATES=$1; shift
430 echo "$STATES" >> /tmp/t
431 local PODS=$(kubectl get $NAMESPACE pod -o go-template="{{range .items}}{{.metadata.name}}/{{.status.phase}}/_{{range .status.containerStatuses}}{{.ready}}_{{end}} {{end}}")
432 local COUNT=0
433 local PATTERNS="$*"
434 for POD in $PODS; do
435 local NAME=$(echo $POD | cut -d/ -f 1)
436 local STATE=$(echo $POD | cut -d/ -f 2)
437 local CONTAINERS=$(echo $POD | cut -d/ -f 3 | sed -e 's/_/ /g')
438 if [ "$STATES" == "*" -o $(echo "$STATES" | grep -c ":$STATE:") -ne 0 ]; then
439 echo "IN WITH $POD" >> /tmp/t
440 local TOTAL=$(echo $CONTAINERS | wc -w)
441 local FOUND=$(echo $CONTAINERS | grep -o true | wc -l)
442 if [ $TOTAL -eq $FOUND ]; then
443 for PATTERN in $PATTERNS; do
444 echo "TEST $PATTERN AGAINST $NAME" >> /tmp/t
445 if [[ $NAME =~ $PATTERN ]]; then
446 echo "COUNT $NAME" >> /tmp/t
447 COUNT=$(expr $COUNT + 1)
448 break
449 fi
450 done
451 fi
452 fi
453 done
454 echo $COUNT >> /tmp/t
455 echo $COUNT
456}
457
458wait_for_pods() {
459 local INDENT=
460 if [ "$1" == "-" ]; then
461 INDENT=$1; shift
462 fi
463 local NAMESPACE=$1; shift
464 local EXPECT=$1; shift
465 local TYPE=$1; shift
466 local RETRY=$1; shift
467 local MESSAGE=$1; shift
468 local PATTERNS=$*
David Bainbridge99ac7a22019-08-31 02:26:43 +0000469 local STATES=":Running:"
470 if [ "$TYPE" == "not" ]; then
471 STATES="*"
472 fi
473 local HAVE=$(count_pods $NAMESPACE "$STATES" $PATTERNS)
David Bainbridge4f1b5562019-08-19 04:46:52 +0000474 local ALL=$HAVE
475 if [ "$TYPE" == "only" ]; then
476 ALL=$(count_pods "all-namespaces" "*" ".*")
477 fi
478 COUNT=$(expr 300 / 15)
479 bspin $INDENT $MESSAGE
480 sspin $INDENT
481 if [ $HAVE -ne $EXPECT -o $ALL -ne $HAVE ]; then
482 while [ $HAVE -ne $EXPECT -o $ALL -ne $HAVE ]; do
483 sspin $INDENT
484 COUNT=$(expr $COUNT - 1)
485 if [ $COUNT -eq 0 ]; then
David Bainbridge99ac7a22019-08-31 02:26:43 +0000486 HAVE=$(count_pods $NAMESPACE "$STATES" $PATTERNS)
David Bainbridge4f1b5562019-08-19 04:46:52 +0000487 ALL=$HAVE
488 if [ "$TYPE" == "only" ]; then
489 ALL=$(count_pods "all-namespaces" "*" ".*")
490 fi
491 COUNT=$(expr 300 / 15)
492 fi
493 sleep .15
494 done
495 fi
496 espin $INDENT $VERIFIED
497 if [ $HAVE -ne $EXPECT ]; then
498 return 1
499 fi
500 return 0
501}
502
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800503port_forward() {
504 local NS=$1
505 local SVC=$2
506 local FROM_PORT=$3
507 local TO_PORT=$4
508 local TAG=$SVC-$NAME
509
510 (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
511}
512
513kill_port_forward() {
514 local TAG=$1-$NAME
David Bainbridgec6871d22019-11-13 17:10:31 +0000515 local P_IDS=$(ps e -ww -A | grep "_TAG=$TAG" | grep -v grep | awk '{print $1}')
David Bainbridgebcf235b2019-11-12 21:33:58 +0000516 local PARENTS=
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800517 local KIDS=
David Bainbridgec6871d22019-11-13 17:10:31 +0000518 local UNKNOWN=
519 if [ ! -z "$P_IDS" ]; then
520 for P_ID in $P_IDS; do
521 local PP_ID=$(ps -o ppid $P_ID | tail -n +2)
522 if [ ! -z "$PP_ID" ]; then
523 if [ $PP_ID -eq 1 ]; then
524 PARENTS="$PARENTS $P_ID"
525 else
526 KIDS="$KIDS $P_ID"
527 fi
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800528 else
David Bainbridgec6871d22019-11-13 17:10:31 +0000529 UNKNOWN="$UNKNOWN $P_ID"
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800530 fi
531 done
David Bainbridgec6871d22019-11-13 17:10:31 +0000532 (set -x; kill -9 $PARENTS $KIDS $UNKNOWN >>$LOG 2>&1) >>$LOG 2>&1
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800533 fi
534}
535
David Bainbridgeac7f8072019-08-01 22:15:33 +0000536if [ "$1" == "down" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000537 echo "Tearing down voltha cluster $NAME"
538 LOG="down-$NAME.log"
539 echo $(date -u +"%Y%m%dT%H%M%SZ") >$LOG
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800540 bspin "Remove port-forwards: onos-ui-$NAME"
541 kill_port_forward onos-ui
542 sspin "Remove port-forwards: onos-ssh-$NAME$CEOL"
543 kill_port_forward onos-ssh
544 sspin "Remove port-forwards: voltha-api-$NAME$CEOL"
545 kill_port_forward voltha-api
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800546 sspin "Remove port-forwards: voltha-etcd-$NAME$CEOL"
547 kill_port_forward voltha-etcd-cluster-client
548 espin "$VERIFIED Remove port-forwards$CEOL"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000549 if [ $DEPLOY_K8S == "yes" ]; then
550 if [ -x ./bin/kind ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000551 bspin "Delete Kubernetes Kind Cluster"
552 (set -x; ./bin/kind delete cluster --name voltha-$NAME >>$LOG 2>&1) >>$LOG 2>&1
553 espin $VERIFIED
David Bainbridgeac7f8072019-08-01 22:15:33 +0000554 else
David Bainbridge0774b232019-08-02 06:37:19 +0000555 espin "$NO_ENTRY Delete Kubernetes Kind Cluster: kind command not found"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000556 fi
557 else
558 EXISTS=$(helm list -q)
559 EXPECT="etcd-operator onos open-olt open-onu sim voltha bbsim radius"
David Bainbridge0774b232019-08-02 06:37:19 +0000560 bspin "Remove Helm Deployments"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000561 for i in $EXISTS; do
562 if [ $(echo $EXPECT | grep -c $i) -eq 1 ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000563 sspin "Remove Helm Deployments: $i$CEOL"
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800564 (set -x; ./bin/helm delete --no-hooks --purge $i >>$LOG 2>&1) >>$LOG 2>&1
David Bainbridgeac7f8072019-08-01 22:15:33 +0000565 fi
566 done
David Bainbridge0774b232019-08-02 06:37:19 +0000567 espin "$VERIFIED Remove Helm Deployments$CEOL"
David Bainbridge4f1b5562019-08-19 04:46:52 +0000568 if [ "$WAIT_ON_DOWN" == "yes" ]; then
569 # There should only be 13 or 15 PODs in the kube-system name
570 # space and no other PODs
David Bainbridge4f1b5562019-08-19 04:46:52 +0000571 PODS="coredns-.* \
572 etcd-voltha-$NAME-control-plane \
573 kindnet-.* \
574 kube-apiserver-voltha-$NAME-control-plane \
575 kube-controller-manager-voltha-$NAME-control-plane \
576 kube-proxy-.* \
577 kube-scheduler-voltha-$NAME-control-plane \
578 tiller-deploy-.*"
579 EXPECT=$(test "$TYPE" == "minimal" && echo "13" || echo "15")
David Bainbridge99ac7a22019-08-31 02:26:43 +0000580 PODS="adapter-.* \
581 bbsim.* \
582 etcd-operator.* \
583 radius.* \
584 voltha-.*"
585 EXPECT=0
586
587 wait_for_pods "voltha" $EXPECT "not" -1 "Waiting for VOLTHA PODs to terminate" $PODS
David Bainbridge4f1b5562019-08-19 04:46:52 +0000588 fi
David Bainbridgeac7f8072019-08-01 22:15:33 +0000589 fi
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -0700590 exit
David Bainbridgeac7f8072019-08-01 22:15:33 +0000591fi
592
593if [ "$1" == "dump" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000594 LOG="dump-$NAME.log"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000595 TS=$(date -u +"%Y%m%dT%H%M%SZ")
David Bainbridge76514a02019-10-08 01:50:35 +0000596 if [ ! -z "$DUMP_FROM" ]; then
597 TS=$(echo $DUMP_FROM | sed -e 's/[:-]//g')
598 fi
David Bainbridgeac7f8072019-08-01 22:15:33 +0000599 WORK=$(mktemp -u -d)
David Bainbridge0774b232019-08-02 06:37:19 +0000600 DATA=$WORK/voltha-debug-dump-$NAME-$TS
David Bainbridgeac7f8072019-08-01 22:15:33 +0000601 mkdir -p $DATA
602 echo $TS > $LOG
David Bainbridge0774b232019-08-02 06:37:19 +0000603 echo -e "Capturing debug dump to voltha-debug-dump-$NAME-$TS.tgz"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000604 bspin - "Copy install log"
David Bainbridge0774b232019-08-02 06:37:19 +0000605 if [ -f install-$NAME.log ]; then
606 (set -x; cp install-$NAME.log $DATA/install-$NAME.log) >>$LOG 2>&1
David Bainbridgeac7f8072019-08-01 22:15:33 +0000607 espin - $VERIFIED
608 else
David Bainbridge0774b232019-08-02 06:37:19 +0000609 espin - "$NO_ENTRY Copy install log: install-$NAME.log not found"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000610 fi
611 bspin - "Dumping Kubernetes PODs"
612 (set -x; kubectl get --all-namespaces pods >> $DATA/all-pods.txt 2>&1) >>$LOG 2>&1
613 espin - $VERIFIED
614 bspin - "Dumping Kubernetes SERVICEs"
615 (set -x; kubectl get --all-namespaces svc >> $DATA/all-services.txt 2>&1) >>$LOG 2>&1
616 espin - $VERIFIED
617 bspin - "Dumping Kubernetes EVENTs"
618 (set -x; kubectl get --all-namespaces events >> $DATA/all-events.txt 2>&1) >>$LOG 2>&1
619 espin - $VERIFIED
620 bspin - "Dumping VOLTHA POD details"
Matteo Scandolodcd29f52019-10-07 15:42:42 -0700621 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 +0000622 SINCE=
623 if [ ! -z "$DUMP_FROM" ]; then
624 SINCE="--since-time=$DUMP_FROM"
625 fi
David Bainbridgeac7f8072019-08-01 22:15:33 +0000626 for POD in $PODS; do
David Bainbridge1f0655a2019-10-01 22:08:48 +0000627 NS=$(echo $POD | cut -d: -f1)
628 POD=$(echo $POD | cut -d: -f2)
David Bainbridgeac7f8072019-08-01 22:15:33 +0000629 sspin - "Dumping VOLTHA POD details: $POD$CEOL"
630 mkdir -p $DATA/$POD
David Bainbridge1f0655a2019-10-01 22:08:48 +0000631 (set -x; kubectl describe -n $NS $POD >> $DATA/$POD/describe.txt 2>&1) >>$LOG 2>&1
David Bainbridgeac7f8072019-08-01 22:15:33 +0000632 sspin - "Dumping VOLTHA POD details: $POD"
David Bainbridgecfd7ca12019-10-06 03:31:41 +0000633 (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 +0000634 sspin - "Dumping VOLTHA POD details: $POD"
David Bainbridgecfd7ca12019-10-06 03:31:41 +0000635 (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 +0000636 sspin - "Dumping VOLTHA POD details: $POD"
637 done
638 espin - "$VERIFIED Dumping VOLTHA POD details$CEOL"
639 bspin - "Dumping ETCD"
640 if [ "$(which etcdctl) X" != " X" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000641 (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 +0000642 espin - $VERIFIED
643 else
644 espin - "$NO_ENTRY Dumping ETCD: etcdctl command not available"
645 fi
David Bainbridge0774b232019-08-02 06:37:19 +0000646 bspin - "Creating compressed TAR: voltha-debug-dump-$NAME-$TS.tgz"
647 (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 +0000648 espin - $VERIFIED
649 bspin - "Cleanup"
650 (set -x; rm -rf $WORK) >>$LOG 2>&1
651 espin - $VERIFIED
David Bainbridge0774b232019-08-02 06:37:19 +0000652 bspin - "$(ls -l voltha-debug-dump-$NAME-$TS.tgz)"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000653 espin - $VERIFIED
654 exit
655fi
656
David Bainbridge0774b232019-08-02 06:37:19 +0000657LOG="install-$NAME.log"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000658date > $LOG
David Bainbridge0774b232019-08-02 06:37:19 +0000659echo "PORTS=$ONOS_API_PORT,$ONOS_SSH_PORT,$VOLTHA_API_PORT,$VOLTHA_SSH_PORT,$VOLTHA_ETCD_PORT" >> $LOG
David Bainbridgeac7f8072019-08-01 22:15:33 +0000660
661# Output install options to log
662echo "OPTIONS" >> $LOG
David Bainbridgeac7f8072019-08-01 22:15:33 +0000663for O in $ALL_OPTIONS; do
664 VAL=$(eval echo \$$O)
David Bainbridgeac7f8072019-08-01 22:15:33 +0000665 if [ ! -z "$VAL" ]; then
666 printf " %-30s = %s\n" $O $VAL >> $LOG
667 fi
668done
669
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -0700670helm_install() {
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700671 local INDENT=
672 if [ "$1" == "-" ]; then
673 INDENT=$1; shift
674 fi
675 local NAMESPACE=$1; shift
David Bainbridge0774b232019-08-02 06:37:19 +0000676 local INAME=$1; shift
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700677 local CHART=$1; shift
David Bainbridge90fd8e32019-08-21 23:32:47 +0000678 local CHART_VERSION=$1; shift
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700679 local MESSAGE=$*
680
David Bainbridge90fd8e32019-08-21 23:32:47 +0000681 if [ "$CHART_VERSION X" != " X" -a "$CHART_VERSION" != "latest" ]; then
682 CHART_VERSION="--version $CHART_VERSION"
683 else
684 CHART_VERSION=
685 fi
686
David Bainbridge99ac7a22019-08-31 02:26:43 +0000687 local CHART_ARGS=
688 if [ -r "${INAME}-values.yaml" ]; then
689 CHART_ARGS="-f ${INAME}-values.yaml"
690 fi
691
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700692 COUNT=$(expr 300 / 15)
693 bspin $INDENT $MESSAGE
David Bainbridge70c0ea82019-11-14 23:25:26 +0000694 (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 -0700695 SUCCESS=$?
696 while [ $SUCCESS -ne 0 ]; do
697 sspin $INDENT
698 COUNT=$(expr $COUNT - 1)
699 if [ $COUNT -eq 0 ]; then
Andy Baviere22ff252019-12-19 11:40:31 -0700700 (set -x; helm delete --purge $INAME >>$LOG 2>&1) >>$LOG 2>&1
David Bainbridge99ac7a22019-08-31 02:26:43 +0000701 (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 -0700702 SUCCESS=$?
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700703 COUNT=$(expr 300 / 15)
704 fi
705 sleep .15
706 done
707 espin $INDENT $VERIFIED
708}
709
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700710echo "INSTALL TYPE: $TYPE" >> $LOG
711
712bspin "Verify GOPATH"
713export GOPATH=$(pwd)
Test User3d7ad8e2019-07-03 06:15:44 +0000714mkdir -p $GOPATH/bin
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700715espin $VERIFIED
716
David Bainbridgee87067b2019-08-12 22:00:12 +0000717STIME=$(date +%s)
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700718if [ "$INSTALL_KUBECTL" == "no" ]; then
719 bspin "Skip kubectl install"
720 espin $NO_ENTRY
Test Userc13bdc92019-07-03 20:57:49 +0000721else
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700722 bspin "Verify kubectl $HELM"
723 if [ -x $GOPATH/bin/kubectl ]; then
724 espin $VERIFIED
725 else
726 espin $NOT_VERIFIED
727 bspin - "Download and install Kubernetes/kubectl $DOWNLOAD"
728 (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
729 (set -x; chmod 755 $GOPATH/bin/kubectl >>$LOG 2>&1) >>$LOG 2>&1
730 espin - $VERIFIED
731 fi
Test Userc13bdc92019-07-03 20:57:49 +0000732fi
David Bainbridgee87067b2019-08-12 22:00:12 +0000733if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +0000734 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +0000735fi
Test Userc13bdc92019-07-03 20:57:49 +0000736
David Bainbridgee87067b2019-08-12 22:00:12 +0000737STIME=$(date +%s)
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700738if [ "$DEPLOY_K8S" == "no" ]; then
739 bspin "Skip Kubernetes/Kind Deployment"
740 espin $NO_ENTRY
741else
Test Userba1e7e72019-07-10 22:27:54 +0000742 bspin "Verify Kubernetes/Kind $HELM"
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800743 IS_INSTALLED=0
744 OP_TYPE="install"
Test Userba1e7e72019-07-10 22:27:54 +0000745 if [ -x $GOPATH/bin/kind ]; then
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800746 OP_TYPE="upgrade"
747 if [ $($GOPATH/bin/kind --version | grep -c $KIND_VERSION) -eq 1 ]; then
748 IS_INSTALLED=1
749 espin $VERIFIED
750 fi
751 fi
752 if [ $IS_INSTALLED -eq 0 ]; then
Test Userba1e7e72019-07-10 22:27:54 +0000753 espin $NOT_VERIFIED
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800754 bspin - "Download and $OP_TYPE Kubernetes/kind $DOWNLOAD"
David Bainbridge9e2a6662019-07-11 17:07:57 +0000755 (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 +0000756 (set -x; chmod 755 $GOPATH/bin/kind >>$LOG 2>&1) >>$LOG 2>&1
757 espin - $VERIFIED
758 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700759fi
760
David Bainbridgee87067b2019-08-12 22:00:12 +0000761if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +0000762 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +0000763fi
764
765STIME=$(date +%s)
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700766if [ "$INSTALL_HELM" == "no" ]; then
767 bspin "Skip Helm Install"
768 espin $NO_ENTRY
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700769else
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700770 bspin "Verify Helm $HELM"
771 if [ -x $GOPATH/bin/helm ]; then
772 espin $VERIFIED
773 else
774 espin $NOT_VERIFIED
775 bspin - "Download and install Helm $DOWNLOAD"
David Bainbridgec6a6eb62019-10-18 22:50:07 +0000776 (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 -0700777 espin - $VERIFIED
778 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700779fi
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800780
David Bainbridgee87067b2019-08-12 22:00:12 +0000781if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +0000782 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +0000783fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700784
David Bainbridgee87067b2019-08-12 22:00:12 +0000785STIME=$(date +%s)
Test Userb5712372019-07-03 21:52:17 +0000786bspin "Verify voltctl $HIGH_VOLTAGE"
David Bainbridged2811972019-12-14 01:14:09 +0000787VOK=0
788VMESSAGE="install"
Test User3d7ad8e2019-07-03 06:15:44 +0000789if [ -x $GOPATH/bin/voltctl ]; then
David Bainbridge1ba64f12019-12-18 00:40:13 +0000790 VHAVE=$($GOPATH/bin/voltctl version --clientonly -o json | jq -r .version)
791 if [ $? -eq 0 -a "$VHAVE" == "$VOLTCTL_VERSION" ]; then
David Bainbridged2811972019-12-14 01:14:09 +0000792 VOK=1
David Bainbridge1ba64f12019-12-18 00:40:13 +0000793 espin $VERIFIED
794 else
795 VMESSAGE="upgrade"
David Bainbridged2811972019-12-14 01:14:09 +0000796 fi
797fi
798
David Bainbridge1ba64f12019-12-18 00:40:13 +0000799if [ $VOK -eq 0 ]; then
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700800 espin $NOT_VERIFIED
David Bainbridged2811972019-12-14 01:14:09 +0000801 bspin - "Download and $VMESSAGE voltctl $DOWNLOAD"
David Bainbridge28c64462019-12-12 22:25:26 +0000802 (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 +0000803 (set -x; chmod 755 $GOPATH/bin/voltctl >>$LOG 2>&1) >>$LOG 2>&1
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700804 espin - $VERIFIED
805fi
David Bainbridgee87067b2019-08-12 22:00:12 +0000806if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +0000807 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +0000808fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700809
810bspin "Verify command PATH"
Test Userba1e7e72019-07-10 22:27:54 +0000811export PATH=$GOPATH/bin:$PATH
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700812espin $VERIFIED
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700813
David Bainbridgee87067b2019-08-12 22:00:12 +0000814STIME=$(date +%s)
Test Userba1e7e72019-07-10 22:27:54 +0000815if [ "$DEPLOY_K8S" == "yes" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000816 HAVE=$(kind get clusters | grep -c voltha-$NAME)
Test Userba1e7e72019-07-10 22:27:54 +0000817 bspin "Verify Kubernetes/Kind Cluster"
818 sspin
819 if [ $HAVE -eq 0 ]; then
David Bainbridge491b1bd2019-07-11 17:53:11 +0000820 espin $NOT_VERIFIED
821 bspin - "Verify cluster configuration"
David Bainbridge0774b232019-08-02 06:37:19 +0000822 if [ ! -r ./$NAME-cluster.cfg ]; then
David Bainbridge491b1bd2019-07-11 17:53:11 +0000823 espin - $NOT_VERIFIED
David Bainbridge0774b232019-08-02 06:37:19 +0000824 bspin - "Download cluster configuration: $TYPE-cluster.cfg to $NAME-cluster.cfg $DOWNLOAD"
825 (set -x; curl -o ./$NAME-cluster.cfg -sSL https://raw.githubusercontent.com/ciena/kind-voltha/master/$TYPE-cluster.cfg >>$LOG 2>&1) >>$LOG 2>&1
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700826 espin - $VERIFIED
827 else
828 espin - $VERIFIED
829 fi
David Bainbridge0774b232019-08-02 06:37:19 +0000830 kind create cluster --name voltha-$NAME --config $NAME-cluster.cfg
David Bainbridge491b1bd2019-07-11 17:53:11 +0000831 else
832 espin $VERIFIED
Test Userba1e7e72019-07-10 22:27:54 +0000833 fi
834
David Bainbridge0774b232019-08-02 06:37:19 +0000835 export KUBECONFIG="$(kind get kubeconfig-path --name="voltha-$NAME")"
Test Userba1e7e72019-07-10 22:27:54 +0000836 P="coredns-.* \
David Bainbridge0774b232019-08-02 06:37:19 +0000837 etcd-voltha-$NAME-control-plane \
Test Userba1e7e72019-07-10 22:27:54 +0000838 kindnet-.* \
David Bainbridge0774b232019-08-02 06:37:19 +0000839 kube-apiserver-voltha-$NAME-control-plane \
840 kube-controller-manager-voltha-$NAME-control-plane \
Test Userba1e7e72019-07-10 22:27:54 +0000841 kube-proxy-.* \
David Bainbridge0774b232019-08-02 06:37:19 +0000842 kube-scheduler-voltha-$NAME-control-plane"
Test Userba1e7e72019-07-10 22:27:54 +0000843
844 EXPECT=$(test "$TYPE" == "minimal" && echo "12" || echo "14")
David Bainbridge4f1b5562019-08-19 04:46:52 +0000845 wait_for_pods - "kube-system" $EXPECT "includes" -1 "Waiting for system PODs to start" $P
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700846fi
David Bainbridgee87067b2019-08-12 22:00:12 +0000847if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +0000848 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +0000849fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700850
David Bainbridgee87067b2019-08-12 22:00:12 +0000851STIME=$(date +%s)
David Bainbridge4c6289c2019-09-03 21:11:32 +0000852COUNT=$(count_pods "kube-system" ":Running:" "tiller-deploy-.*")
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700853bspin "Verify Helm"
Test Userba1e7e72019-07-10 22:27:54 +0000854if [ $COUNT -ne 1 ]; then
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700855 espin $NOT_VERIFIED
Test Userb5712372019-07-03 21:52:17 +0000856 echo -e "Configuring Helm $GEAR"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700857 if [ "$INSTALL_HELM" == "no" ]; then
858 bspin - "Skip Helm/Tiller Initialization"
859 espin - $NO_ENTRY
860 else
861 bspin - "Initialize Helm"
862 (set -x; helm init --upgrade >>$LOG 2>&1) >>$LOG 2>&1
863 espin - $VERIFIED
David Bainbridge4f1b5562019-08-19 04:46:52 +0000864 wait_for_pods - "kube-system" 1 "includes" -1 "Waiting for Tiller POD to start" "tiller-deploy-.*"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700865 fi
Test Userb5712372019-07-03 21:52:17 +0000866 bspin - "Add Google Incubator repository to Helm"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700867 (set -x; helm repo add incubator https://kubernetes-charts-incubator.storage.googleapis.com >>$LOG 2>&1) >>$LOG 2>&1
868 espin - $VERIFIED
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -0700869
Test Userba1e7e72019-07-10 22:27:54 +0000870 # HACK (sort-of) - the config for tiller is about to be patched, which will
871 # cause the tiller pod to be recreated. This can sometimes cause a timing
872 # issue with the "wait_for_pods" call on tiller as it may incorrectly
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -0700873 # identify the running/ready tiller pod that is soon to be terminated as
Test Userba1e7e72019-07-10 22:27:54 +0000874 # what it is waiting for. To avoid this issue we do a clean scale down and
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -0700875 # scale up of the pod so the script controlls when it should be expecting
Test Userba1e7e72019-07-10 22:27:54 +0000876 # things
877 (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 -0700878
Test Userb5712372019-07-03 21:52:17 +0000879 bspin - "Add Google Stable repository to Helm"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700880 (set -x; helm repo add stable https://kubernetes-charts.storage.googleapis.com >>$LOG 2>&1) >>$LOG 2>&1
881 espin - $VERIFIED
Test Userb5712372019-07-03 21:52:17 +0000882 bspin - "Add ONF repository to Helm"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700883 (set -x; helm repo add onf https://charts.opencord.org >>$LOG 2>&1) >>$LOG 2>&1
884 espin - $VERIFIED
Test Userb5712372019-07-03 21:52:17 +0000885 bspin - "Update Helm repository cache"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700886 (set -x; helm repo update >>$LOG 2>&1) >>$LOG 2>&1
887 espin - $VERIFIED
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -0700888
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700889 # Create and k8s service account so that Helm can create pods
Test Userb5712372019-07-03 21:52:17 +0000890 bspin - "Create Tiller ServiceAccount"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700891 (set -x; kubectl create serviceaccount --namespace kube-system tiller >>$LOG 2>&1) >>$LOG 2>&1
892 espin - $VERIFIED
Test Userb5712372019-07-03 21:52:17 +0000893 bspin - "Create Tiller ClusterRoleBinding"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700894 (set -x; kubectl create clusterrolebinding tiller-cluster-rule --clusterrole=cluster-admin --serviceaccount=kube-system:tiller >>$LOG 2>&1) >>$LOG 2>&1
895 espin - $VERIFIED
Test Userb5712372019-07-03 21:52:17 +0000896 bspin - "Update Tiller Manifest"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700897 (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 +0000898
899 # HACK (sort-of) - part to, spin it back up
900 (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 -0700901 espin - $VERIFIED
902else
903 espin $VERIFIED
David Bainbridge46505fb2019-10-01 21:13:20 +0000904 if [ "$UPDATE_HELM_REPOS" == "yes" ]; then
905 bspin - "Update Helm repository cache"
906 (set -x; helm repo update >>$LOG 2>&1) >>$LOG 2>&1
907 espin - $VERIFIED
908 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700909fi
David Bainbridge4f1b5562019-08-19 04:46:52 +0000910wait_for_pods - "kube-system" 1 "includes" -1 "Waiting for Tiller POD to start" "tiller-deploy-.*"
David Bainbridgee87067b2019-08-12 22:00:12 +0000911if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +0000912 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +0000913fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700914
David Bainbridgee87067b2019-08-12 22:00:12 +0000915STIME=$(date +%s)
David Bainbridge0774b232019-08-02 06:37:19 +0000916bspin "Verify Helm values file: $NAME-values.yaml"
917if [ ! -r "./$NAME-values.yaml" ]; then
Test Userba1e7e72019-07-10 22:27:54 +0000918 espin $NOT_VERIFIED
David Bainbridge0774b232019-08-02 06:37:19 +0000919 bspin - "Download Helm values file: $TYPE-values.yaml to $NAME-values.yaml $DOWNLOAD"
920 (set -x; curl -o ./$NAME-values.yaml -sSL https://raw.githubusercontent.com/ciena/kind-voltha/master/$TYPE-values.yaml >>$LOG 2>&1) >>$LOG 2>&1
Test Userba1e7e72019-07-10 22:27:54 +0000921 espin - $VERIFIED
922else
923 espin $VERIFIED
924fi
David Bainbridgee87067b2019-08-12 22:00:12 +0000925if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +0000926 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +0000927fi
Test Userba1e7e72019-07-10 22:27:54 +0000928
David Bainbridge99ac7a22019-08-31 02:26:43 +0000929STIME=$(date +%s)
930bspin "Verify or download chart specific values files $DOWNLOAD"
931VALUES_FILES="monkey-values.yaml"
932for i in $VALUES_FILES; do
933 if [ ! -r ./$i ]; then
934 (set -x; curl -o ./$i -sSL https://raw.githubusercontent.com/ciena/kind-voltha/master/$i >>$LOG 2>&1) >>$LOG 2>&1
935 fi
936done
937espin $VERIFIED
938if [ "$WITH_TIMINGS" == "yes" ]; then
939 printtime $(expr $(date +%s) - $STIME)
940fi
941
942if [ "$WITH_CHAOS" == "yes" ]; then
943 bspin "Verify or clone kube-monkey helm chart $DOWNLOAD"
944 if [ -r ./kube-monkey ]; then
945 espin $VERIFIED
946 else
947 espin $NOT_VERIFIED
948 bspin - "GIT clone kube-monkey"
949 (set -x; git clone https://github.com/asobti/kube-monkey kube-monkey >>$LOG 2>&1) >>$LOG 2>&1
950 espin - $VERIFIED
951 fi
952fi
953
Test Userba1e7e72019-07-10 22:27:54 +0000954if [ "$JUST_K8S" == "yes" ]; then
955 echo "Environment deployed, not deploying VOLTHA artifacts as requested. Good bye."
956 echo ""
957 echo "Please issue the following commands in your terminal to ensure that you" | tee -a $LOG
958 echo "are accessing the correct Kubernetes/Kind cluster as well as have the " | tee -a $LOG
959 echo "tools required by VOLTHA in your command path. " | tee -a $LOG
960 echo "" | tee -a $LOG
961 echo -en $BOLD
962 if [ $DEPLOY_K8S == "yes" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000963 echo "export KUBECONFIG=\"\$(./bin/kind get kubeconfig-path --name=\"voltha-$NAME\")\"" | tee -a $LOG
Test Userba1e7e72019-07-10 22:27:54 +0000964 fi
965 echo "export PATH=$GOPATH/bin:\$PATH" | tee -a $LOG
966 echo -en $NORMAL
967 echo "" | tee -a $LOG
968 echo "Thank you for choosing kind-voltha for you quick cluster needs." | tee -a $LOG
969 exit 0
970fi
971
David Bainbridgee87067b2019-08-12 22:00:12 +0000972STIME=$(date +%s)
Test Userb5712372019-07-03 21:52:17 +0000973bspin "Verify ETCD Operator $OLD_KEY"
Test User7d866122019-07-09 17:52:35 +0000974if [ $(helm list --deployed --short --namespace voltha "^etcd-operator\$" | wc -l) -ne 1 ]; then
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -0700975 espin $NOT_VERIFIED
David Bainbridge90fd8e32019-08-21 23:32:47 +0000976 helm_install - voltha etcd-operator stable/etcd-operator latest "Install ETCD Operator"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700977else
978 espin $VERIFIED
979fi
Test User01ed0642019-07-03 20:17:06 +0000980EXPECT=$(test "$TYPE" == "minimal" && echo "1" || echo "3")
David Bainbridge4f1b5562019-08-19 04:46:52 +0000981wait_for_pods - "voltha" $EXPECT "includes" -1 "Waiting for ETCD Operator to start" "etcd-operator-.*"
David Bainbridgee87067b2019-08-12 22:00:12 +0000982if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +0000983 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +0000984fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700985
David Bainbridgee87067b2019-08-12 22:00:12 +0000986STIME=$(date +%s)
David Bainbridgeb270c202019-07-26 01:44:42 +0000987if [ $WITH_ONOS == "yes" ]; then
988 bspin "Verify ONOS installed $BIRD"
989 if [ $(helm list --deployed --short --namespace default "^onos\$" | wc -l) -ne 1 ]; then
990 espin $NOT_VERIFIED
Andrea Campanella6afcb082019-12-18 16:51:30 -0800991 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 +0000992 else
993 espin $VERIFIED
994 fi
David Bainbridge4f1b5562019-08-19 04:46:52 +0000995 wait_for_pods - "default" 1 "includes" -1 "Waiting for ONOS to start" "onos-.*"
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -0700996
David Bainbridgeb270c202019-07-26 01:44:42 +0000997 bspin - "Forward ONOS API port $FORWARD"
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800998 kill_port_forward onos-ui
999 port_forward default onos-ui $ONOS_API_PORT 8181
David Bainbridgeb270c202019-07-26 01:44:42 +00001000 espin - $VERIFIED
1001 bspin - "Forward ONOS SSH port $FORWARD"
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -08001002 kill_port_forward onos-ssh
1003 port_forward default onos-ssh $ONOS_SSH_PORT 8101
David Bainbridgeb270c202019-07-26 01:44:42 +00001004 espin - $VERIFIED
David Bainbridged31d6122019-08-13 19:37:59 +00001005 bspin - "Verify or download ONOS configuration support files $DOWNLOAD"
David Bainbridge2b19e832019-08-16 02:40:53 +00001006 ONOS_FILES="olt-onos-enableExtraneousRules.json olt-onos-olt-settings.json onos-aaa.json \
David Bainbridge90fd8e32019-08-21 23:32:47 +00001007 onos-dhcpl2relay.json onos-kafka.json onos-sadis-sample.json"
David Bainbridged31d6122019-08-13 19:37:59 +00001008 (set -x; mkdir -p ./onos-files >>$LOG 2>&1) >>$LOG 2>&1
David Bainbridge2b19e832019-08-16 02:40:53 +00001009 for i in $ONOS_FILES; do
David Bainbridged31d6122019-08-13 19:37:59 +00001010 if [ ! -r ./onos-files/$i ]; then
1011 (set -x; curl -o ./onos-files/$i -sSL https://raw.githubusercontent.com/ciena/kind-voltha/master/onos-files/$i >>$LOG 2>&1) >>$LOG 2>&1
1012 fi
1013 done
Test Userba1e7e72019-07-10 22:27:54 +00001014 espin - $VERIFIED
David Bainbridge27790d62019-08-13 22:43:19 +00001015
1016 if [ $INSTALL_ONOS_APPS == "yes" ]; then
1017 bspin - "Installing custom ONOS applications"
1018 if [ -x onos-files/onos-apps -a $(ls -1 onos-files/onos-apps/*.oar 2>/dev/null | wc -l) -gt 0 ]; then
1019 for OAR in $(ls -1 onos-files/onos-apps/*.oar); do
1020 sspin - "Installing custom ONOS applications - $OAR$CEOL"
David Bainbridge2b19e832019-08-16 02:40:53 +00001021 override_onos_app $OAR
David Bainbridge27790d62019-08-13 22:43:19 +00001022 done
1023 espin - "$VERIFIED Installing custom ONOS applications$CEOL"
1024 else
1025 espin - "$NOT_VERIFIED Installing custom ONOS applications - None Found"
1026 fi
1027 fi
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001028
David Bainbridge2b19e832019-08-16 02:40:53 +00001029 push_onos_config "Push ONOS Kafka Configuration" "network/configuration/apps/org.opencord.kafka" "onos-files/onos-kafka.json"
1030 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 +00001031 push_onos_config "Enable VOLTHA ONOS DHCP provisioning" "configuration/org.opencord.olt.impl.Olt" "onos-files/olt-onos-olt-settings.json"
1032 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 +00001033 if [ -f onos-files/onos-sadis.json ]; then
1034 push_onos_config "[optional] Push ONOS SADIS Configuration" "network/configuration/apps/org.opencord.sadis" "onos-files/onos-sadis.json"
1035 elif [ "$CONFIG_SADIS" == "yes" ]; then
David Bainbridge90fd8e32019-08-21 23:32:47 +00001036 SADIS_CFG=onos-files/onos-sadis-sample.json
David Bainbridge2b19e832019-08-16 02:40:53 +00001037 push_onos_config "[optional] Push ONOS SADIS Configuration" "network/configuration/apps/org.opencord.sadis" "$SADIS_CFG"
1038 fi
Test Userba1e7e72019-07-10 22:27:54 +00001039fi
David Bainbridgee87067b2019-08-12 22:00:12 +00001040if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +00001041 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +00001042fi
Test Userba1e7e72019-07-10 22:27:54 +00001043
David Bainbridgee87067b2019-08-12 22:00:12 +00001044STIME=$(date +%s)
Test Userb5712372019-07-03 21:52:17 +00001045bspin "Verify VOLTHA installed $HIGH_VOLTAGE"
Test User7d866122019-07-09 17:52:35 +00001046if [ $(helm list --deployed --short --namespace voltha "^voltha\$" | wc -l) -ne 1 ]; then
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001047 espin $NOT_VERIFIED
David Bainbridge70c0ea82019-11-14 23:25:26 +00001048 if [ "$ONLY_ONE" == "yes" ]; then
1049 EXTRA_HELM_INSTALL_ARGS="--set therecanbeonlyone=true"=
1050 fi
David Bainbridge90fd8e32019-08-21 23:32:47 +00001051 helm_install - voltha voltha $VOLTHA_CHART $VOLTHA_CHART_VERSION "Install VOLTHA Core"
David Bainbridge70c0ea82019-11-14 23:25:26 +00001052 EXTRA_HELM_INSTALL_ARGS=
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001053else
1054 espin $VERIFIED
1055fi
Test Userba1e7e72019-07-10 22:27:54 +00001056
David Bainbridge90fd8e32019-08-21 23:32:47 +00001057VOLTHA="voltha-ofagent-.* \
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001058 ro-core.* \
1059 rw-core.* \
1060 voltha-api-server-.* \
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001061 voltha-etcd-cluster-.* \
1062 voltha-kafka-.* \
1063 voltha-zookeeper-.*"
David Bainbridge70c0ea82019-11-14 23:25:26 +00001064if [ "$ONLY_ONE" == "yes" ]; then
David Bainbridge1ba64f12019-12-18 00:40:13 +00001065 EXPECT=$(test "$TYPE" == "minimal" && echo "5" || echo "7")
David Bainbridge70c0ea82019-11-14 23:25:26 +00001066else
David Bainbridge1ba64f12019-12-18 00:40:13 +00001067 EXPECT=$(test "$TYPE" == "minimal" && echo "8" || echo "10")
David Bainbridge70c0ea82019-11-14 23:25:26 +00001068fi
David Bainbridge4f1b5562019-08-19 04:46:52 +00001069wait_for_pods - "voltha" $EXPECT "includes" -1 "Waiting for VOLTHA Core to start" $VOLTHA
David Bainbridgee87067b2019-08-12 22:00:12 +00001070if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +00001071 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +00001072fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001073
David Bainbridge46505fb2019-10-01 21:13:20 +00001074if [ "$WITH_ADAPTERS" == "yes" ]; then
1075 STIME=$(date +%s)
1076 EXPECT=0
1077 echo -e "Verify Adapters $PLUG"
1078 if [ "$WITH_SIM_ADAPTERS" == "yes" ]; then
1079 bspin - "Verify Simulated Adapters installed"
1080 if [ $(helm list --deployed --short --namespace voltha "^sim\$" | wc -l) -ne 1 ]; then
1081 espin - $NOT_VERIFIED
1082 helm_install - voltha sim $VOLTHA_ADAPTER_SIM_CHART $VOLTHA_ADAPTER_SIM_CHART_VERSION "Install Simulated Adapters"
1083 else
1084 espin - $VERIFIED
1085 fi
1086 EXPECT=$(expr $EXPECT + 2)
1087 fi
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001088
David Bainbridge46505fb2019-10-01 21:13:20 +00001089 if [ "$WITH_OPEN_ADAPTERS" == "yes" ]; then
1090 bspin - "Verify OpenOLT Adapter installed"
1091 if [ $(helm list --deployed --short --namespace voltha "^open-olt\$" | wc -l) -ne 1 ]; then
1092 espin - $NOT_VERIFIED
1093 helm_install - voltha open-olt $VOLTHA_ADAPTER_OPEN_OLT_CHART $VOLTHA_ADAPTER_OPEN_OLT_CHART_VERSION "Install OpenOLT Adapter"
1094 else
1095 espin - $VERIFIED
1096 fi
1097 bspin - "Verify OpenONU Adapter installed"
1098 if [ $(helm list --deployed --short --namespace voltha "^open-onu\$" | wc -l) -ne 1 ]; then
1099 espin - $NOT_VERIFIED
1100 helm_install - voltha open-onu $VOLTHA_ADAPTER_OPEN_ONU_CHART $VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION "Install OpenONU Adapter"
1101 else
1102 espin - $VERIFIED
1103 fi
1104 EXPECT=$(expr $EXPECT + 2)
1105 fi
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001106
David Bainbridge46505fb2019-10-01 21:13:20 +00001107 ADAPTERS="adapter-.*"
1108 wait_for_pods - "voltha" $EXPECT "includes" -1 "Waiting for adapters to start" $ADAPTERS
1109 if [ "$WITH_TIMINGS" == "yes" ]; then
1110 printtime $(expr $(date +%s) - $STIME)
1111 fi
David Bainbridgee87067b2019-08-12 22:00:12 +00001112fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001113
Test User7d866122019-07-09 17:52:35 +00001114if [ $WITH_BBSIM == "yes" ]; then
David Bainbridgee87067b2019-08-12 22:00:12 +00001115 STIME=$(date +%s)
Test User7d866122019-07-09 17:52:35 +00001116 echo -e "Verify BBSIM $PLUG"
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001117 bspin - "Verify BBSIM Installed"
Test User7d866122019-07-09 17:52:35 +00001118 if [ $(helm list --deployed --short --namespace voltha "^bbsim\$" | wc -l) -ne 1 ]; then
1119 espin - $NOT_VERIFIED
David Bainbridge90fd8e32019-08-21 23:32:47 +00001120 helm_install - voltha bbsim $VOLTHA_BBSIM_CHART $VOLTHA_BBSIM_CHART_VERSION "Install BBSIM"
Test User7d866122019-07-09 17:52:35 +00001121 else
1122 espin - $VERIFIED
1123 fi
David Bainbridge4f1b5562019-08-19 04:46:52 +00001124 wait_for_pods - "voltha" 1 "includes" -1 "Waiting for BBSIM to start" "bbsim-.*"
David Bainbridgee87067b2019-08-12 22:00:12 +00001125 if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +00001126 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +00001127 fi
Test User7d866122019-07-09 17:52:35 +00001128fi
1129
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001130if [ $WITH_RADIUS == "yes" ]; then
David Bainbridgee87067b2019-08-12 22:00:12 +00001131 STIME=$(date +%s)
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001132 echo -e "Verify RADIUS $LOCK"
1133 bspin - "Verify RADIUS Installed"
1134 if [ $(helm list --deployed --short --namespace voltha "^radius\$" | wc -l) -ne 1 ]; then
1135 espin - $NOT_VERIFIED
David Bainbridge90fd8e32019-08-21 23:32:47 +00001136 helm_install - voltha radius onf/freeradius latest "Install RADIUS"
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001137 else
1138 espin - $VERIFIED
1139 fi
David Bainbridge4f1b5562019-08-19 04:46:52 +00001140 wait_for_pods - "voltha" 1 "includes" -1 "Waiting for RADIUS to start" "radius-.*"
David Bainbridgee87067b2019-08-12 22:00:12 +00001141 if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +00001142 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +00001143 fi
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001144fi
1145
David Bainbridgee87067b2019-08-12 22:00:12 +00001146STIME=$(date +%s)
Test Userb5712372019-07-03 21:52:17 +00001147bspin - "Forward VOLTHA API port $FORWARD"
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -08001148kill_port_forward voltha-api
1149port_forward voltha voltha-api $VOLTHA_API_PORT 55555
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001150espin - $VERIFIED
David Bainbridgeac7f8072019-08-01 22:15:33 +00001151bspin - "Forward VOLTHA ETCD port $FORWARD"
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -08001152kill_port_forward voltha-etcd-cluster-client
1153port_forward voltha voltha-etcd-cluster-client $VOLTHA_ETCD_PORT 2379
David Bainbridgeac7f8072019-08-01 22:15:33 +00001154espin - $VERIFIED
David Bainbridgee87067b2019-08-12 22:00:12 +00001155if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +00001156 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +00001157fi
Test User3d7ad8e2019-07-03 06:15:44 +00001158
David Bainbridgeb270c202019-07-26 01:44:42 +00001159if [ $WITH_ONOS == "yes" -a $WITH_RADIUS == "yes" ]; then
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001160 bspin "Configure ONOS RADIUS Connection $GEAR"
Andy Bavier658ebef2019-11-05 17:22:56 -07001161 (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 +00001162 espin $VERIFIED
1163fi
1164
David Bainbridge99ac7a22019-08-31 02:26:43 +00001165if [ "$WITH_CHAOS" == "yes" ]; then
1166 STIME=$(date +%s)
1167 echo -e "Verify kube-monkey $LOCK"
1168 bspin - "Verify kube-monkey Installed"
1169 if [ $(helm list --deployed --short --namespace kube-monkey "^monkey\$" | wc -l) -ne 1 ]; then
1170 espin - $NOT_VERIFIED
1171 helm_install - kube-monkey monkey ./kube-monkey/helm/kubemonkey latest "Install Chaos Monkey"
1172 else
1173 espin - $VERIFIED
1174 fi
1175 wait_for_pods - "kube-monkey" 1 "includes" -1 "Waiting for Chaos to start" "monkey-.*"
1176 if [ "$WITH_TIMINGS" == "yes" ]; then
1177 printtime $(expr $(date +%s) - $STIME)
1178 fi
1179fi
1180
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001181bspin "Create voltctl configuration file"
Test User3d7ad8e2019-07-03 06:15:44 +00001182(set -x; mkdir -p $HOME/.volt >>$LOG 2>&1) >>$LOG 2>&1
David Bainbridge0774b232019-08-02 06:37:19 +00001183(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 +00001184espin $VERIFIED
Test User08ebbd92019-07-03 17:15:39 +00001185
David Bainbridge0774b232019-08-02 06:37:19 +00001186if [ ! -f "$NAME-env.sh" ]; then
1187 touch $NAME-env.sh
David Bainbridgeb07fdf72019-07-29 22:51:40 +00001188fi
1189
David Bainbridge596f30d2019-07-30 17:07:59 +00001190for O in $ALL_OPTIONS; do
1191 VAL=$(eval echo \$$O)
David Bainbridge0774b232019-08-02 06:37:19 +00001192 if [ ! -z "$VAL" -a $(grep -c "^export $O=" $NAME-env.sh) -eq 0 ]; then
1193 echo "export $O=\"$(eval echo \$$O)\"" >> $NAME-env.sh
David Bainbridgeb07fdf72019-07-29 22:51:40 +00001194 fi
1195done
1196
David Bainbridge0774b232019-08-02 06:37:19 +00001197if [ $DEPLOY_K8S == "yes" -a $(grep -c "^export KUBECONFIG=" $NAME-env.sh) -eq 0 ]; then
1198 echo "export KUBECONFIG=\"$(./bin/kind get kubeconfig-path --name=voltha-$NAME)\"" >> $NAME-env.sh
David Bainbridgeb07fdf72019-07-29 22:51:40 +00001199fi
1200
David Bainbridge0774b232019-08-02 06:37:19 +00001201if [ $(grep -c "^export VOLTCONFIG=" $NAME-env.sh) -eq 0 ]; then
1202 echo "export VOLTCONFIG=\"$HOME/.volt/config-$NAME\"" >> $NAME-env.sh
David Bainbridgeb07fdf72019-07-29 22:51:40 +00001203fi
1204
David Bainbridge0774b232019-08-02 06:37:19 +00001205if [ $(grep -c "^export PATH=" $NAME-env.sh) -eq 0 ]; then
1206 echo "export PATH=\"$GOPATH/bin:\$PATH\"" >> $NAME-env.sh
David Bainbridgeb07fdf72019-07-29 22:51:40 +00001207fi
1208
Test User7d866122019-07-09 17:52:35 +00001209echo ""
Test User08ebbd92019-07-03 17:15:39 +00001210echo "Please issue the following commands in your terminal to ensure that you" | tee -a $LOG
1211echo "are accessing the correct Kubernetes/Kind cluster as well as have the " | tee -a $LOG
1212echo "tools required by VOLTHA in your command path. " | tee -a $LOG
1213echo "" | tee -a $LOG
Test User7d866122019-07-09 17:52:35 +00001214echo -en $BOLD
Test Userba1e7e72019-07-10 22:27:54 +00001215if [ $DEPLOY_K8S == "yes" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +00001216 echo "export KUBECONFIG=\"\$(./bin/kind get kubeconfig-path --name=\"voltha-$NAME\")\"" | tee -a $LOG
Test Userba1e7e72019-07-10 22:27:54 +00001217fi
David Bainbridge0774b232019-08-02 06:37:19 +00001218echo "export VOLTCONFIG=\"$HOME/.volt/config-$NAME\"" | tee -a $LOG
Test Userba1e7e72019-07-10 22:27:54 +00001219echo "export PATH=$GOPATH/bin:\$PATH" | tee -a $LOG
Test User7d866122019-07-09 17:52:35 +00001220echo -en $NORMAL
Test User08ebbd92019-07-03 17:15:39 +00001221echo "" | tee -a $LOG
1222echo "Thank you for choosing kind-voltha for you quick cluster needs." | tee -a $LOG
1223
David Bainbridge712afb82019-08-14 19:55:58 +00001224if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridgef858a022019-08-14 21:25:11 +00001225 echo -e "$CLOCK ${BOLD}TOTAL: $(duration $(expr $(date +%s) - $TOTAL_START_TIME))${NORMAL}"
David Bainbridge712afb82019-08-14 19:55:58 +00001226fi