blob: 79862f0b865b797b466d12b75a822c3b19141c73 [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 K. Bainbridgeebf38d92020-02-10 10:46:31 -080033VOLTCTL_VERSION=${VOLTCTL_VERSION:-latest}
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 K. Bainbridge484d80c2020-03-05 21:44:34 -080070
71ENABLE_ONOS_EXTRANEOUS_RULES=${ENABLE_ONOS_EXTRANEOUS_RULES:-no}
David Bainbridgee87067b2019-08-12 22:00:12 +000072WITH_TIMINGS=${WITH_TIMINGS:-no}
Test User7d866122019-07-09 17:52:35 +000073WITH_BBSIM=${WITH_BBSIM:-no}
David Bainbridge5b7b96b2019-07-25 20:29:13 +000074WITH_RADIUS=${WITH_RADIUS:-no}
Matteo Scandolo78dfee02020-02-13 16:18:03 -080075WITH_EAPOL=${WITH_EAPOL:-yes}
76WITH_DHCP=${WITH_DHCP:-yes}
77WITH_IGMP=${WITH_IGMP:-no}
David Bainbridgeb270c202019-07-26 01:44:42 +000078WITH_ONOS=${WITH_ONOS:-yes}
David Bainbridge99ac7a22019-08-31 02:26:43 +000079WITH_CHAOS=${WITH_CHAOS:-no}
David Bainbridge46505fb2019-10-01 21:13:20 +000080WITH_ADAPTERS=${WITH_ADAPTERS:-yes}
David K. Bainbridgeda33d652020-03-06 10:31:23 -080081WITH_SIM_ADAPTERS=${WITH_SIM_ADAPTERS:-no}
David Bainbridge46505fb2019-10-01 21:13:20 +000082WITH_OPEN_ADAPTERS=${WITH_OPEN_ADAPTERS:-yes}
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -080083WITH_PORT_FORWARDS=${WITH_PORT_FORWARDS:-yes}
David Bainbridge05cd8822019-11-19 17:43:53 +000084ONLY_ONE=${ONLY_ONE:-yes}
David Bainbridge2b19e832019-08-16 02:40:53 +000085CONFIG_SADIS=${CONFIG_SADIS:-no}
David Bainbridge27790d62019-08-13 22:43:19 +000086INSTALL_ONOS_APPS=${INSTALL_ONOS_APPS:-no}
Test Userba1e7e72019-07-10 22:27:54 +000087JUST_K8S=${JUST_K8S:-no}
88DEPLOY_K8S=${DEPLOY_K8S:-yes}
David K. Bainbridge0e89cb92019-07-17 11:30:10 -070089INSTALL_KUBECTL=${INSTALL_KUBECTL:-yes}
90INSTALL_HELM=${INSTALL_HELM:-yes}
David Bainbridge46505fb2019-10-01 21:13:20 +000091UPDATE_HELM_REPOS=${UPDATE_HELM_REPOS:-yes}
Matteo Scandolofab98622020-01-28 15:17:20 -080092WAIT_ON_DOWN=${WAIT_ON_DOWN:-yes}
David Bainbridge5b7b96b2019-07-25 20:29:13 +000093VOLTHA_LOG_LEVEL=${VOLTHA_LOG_LEVEL:-WARN}
David Bainbridge90fd8e32019-08-21 23:32:47 +000094VOLTHA_CHART=${VOLTHA_CHART:-onf/voltha}
95VOLTHA_CHART_VERSION=${VOLTHA_CHART_VERSION:-latest}
96VOLTHA_BBSIM_CHART=${VOLTHA_BBSIM_CHART:-onf/bbsim}
Matteo Scandolodcd29f52019-10-07 15:42:42 -070097VOLTHA_BBSIM_CHART_VERSION=${VOLTHA_BBSIM_CHART_VERSION:-latest}
David Bainbridgee10f6d52019-07-25 00:28:13 +000098VOLTHA_ADAPTER_SIM_CHART=${VOLTHA_ADAPTER_SIM_CHART:-onf/voltha-adapter-simulated}
David Bainbridge90fd8e32019-08-21 23:32:47 +000099VOLTHA_ADAPTER_SIM_CHART_VERSION=${VOLTHA_ADAPTER_SIM_CHART_VERSION:-latest}
David Bainbridgee10f6d52019-07-25 00:28:13 +0000100VOLTHA_ADAPTER_OPEN_OLT_CHART=${VOLTHA_ADAPTER_OPEN_OLT_CHART:-onf/voltha-adapter-openolt}
David Bainbridge90fd8e32019-08-21 23:32:47 +0000101VOLTHA_ADAPTER_OPEN_OLT_CHART_VERSION=${VOLTHA_ADAPTER_OPEN_OLT_CHART_VERSION:-latest}
David Bainbridgee10f6d52019-07-25 00:28:13 +0000102VOLTHA_ADAPTER_OPEN_ONU_CHART=${VOLTHA_ADAPTER_OPEN_ONU_CHART:-onf/voltha-adapter-openonu}
David Bainbridge90fd8e32019-08-21 23:32:47 +0000103VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION=${VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION:-latest}
David K. Bainbridgeda33d652020-03-06 10:31:23 -0800104ONOS_CHART=${ONOS_CHART:-onf/onos}
Andrea Campanella21323292019-12-18 11:44:19 -0800105ONOS_CHART_VERSION=${ONOS_CHART_VERSION:-latest}
David Bainbridge70c0ea82019-11-14 23:25:26 +0000106EXTRA_HELM_INSTALL_ARGS=
uottrembb16d3982020-02-28 08:34:36 +0100107NUM_OF_BBSIM=${NUM_OF_BBSIM:-1}
108MAX_NUM_OF_BBSIM=10
Test Userba1e7e72019-07-10 22:27:54 +0000109
110HAVE_GO=$(which go >/dev/null 2>&1 && echo "yes" || echo "no")
111HOSTOS=$(uname -s | tr "[:upper:]" "[:lower:"])
112HOSTARCH=$(uname -m | tr "[:upper:]" "[:lower:"])
113if [ $HOSTARCH == "x86_64" ]; then
114 HOSTARCH="amd64"
115fi
Test User7d866122019-07-09 17:52:35 +0000116
uottrembb16d3982020-02-28 08:34:36 +0100117# check number (range) of bbsim, max bbsim must not exceed 10 instances!
118# note: instances will be numbered from 0 to 9
119if [ "$1" == "up" ]; then
David K. Bainbridge43422402020-03-06 07:41:22 -0800120 if [ "$NUM_OF_BBSIM" -lt 1 ]; then
121 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} Invalid setting of BBSIM instances. NUM_OF_BBSIM is less than 1${NORMAL}"
122 exit 1
123 fi
124 if [ "$NUM_OF_BBSIM" -gt $MAX_NUM_OF_BBSIM ]; then
125 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} Invalid setting of BBSIM instances. NUM_OF_BBSIM is greater than $MAX_NUM_OF_BBSIM${NORMAL}"
126 exit 1
127 fi
uottrembb16d3982020-02-28 08:34:36 +0100128fi
Test User7d866122019-07-09 17:52:35 +0000129# Verify TYPE setting
130if [ $(echo ":minimal:full:" | grep -ic ":$TYPE:") -eq 0 ]; then
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700131 >&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 +0000132 exit 1
133fi
134
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -0800135function get_service_ep() {
136 local NS=$1
137 local NAME=$2
138 kubectl -n $NS get service $NAME -o json | jq -r '.spec.clusterIP + ":" + (.spec.ports[0].port|tostring)'
139}
140
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000141# Used to verify configuration values are set to "yes" or "no" value or convert
142# equivalents to "yes" or "no"
143function verify_yes_no() {
144 local VAR=$1
145 local VAL=$(eval echo \$$VAR)
146 if [ $(echo ":y:yes:true:n:no:false:1:0:" | grep -ic ":$VAL:") -eq 0 ]; then
147 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} Invalid '$VAR' value of '$VAL'. Should be 'yes' or 'no'${NORMAL}"
148 echo "INVALID"
149 return 1
150 fi
151 if [ $(echo ":y:yes:true:1:" | grep -ic ":$VAL:") -eq 1 ]; then
152 echo "yes"
153 else
154 echo "no"
155 fi
156 return 0
157}
Test User7d866122019-07-09 17:52:35 +0000158
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000159ALL_YES_NO="\
David K. Bainbridge484d80c2020-03-05 21:44:34 -0800160 ENABLE_ONOS_EXTRANEOUS_RULES \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000161 WITH_TIMINGS \
162 WITH_BBSIM \
163 WITH_RADIUS \
Matteo Scandolo78dfee02020-02-13 16:18:03 -0800164 WITH_EAPOL \
165 WITH_DHCP \
166 WITH_IGMP \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000167 WITH_ONOS \
David Bainbridge99ac7a22019-08-31 02:26:43 +0000168 WITH_CHAOS \
David Bainbridge46505fb2019-10-01 21:13:20 +0000169 WITH_ADAPTERS \
170 WITH_SIM_ADAPTERS \
171 WITH_OPEN_ADAPTERS \
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -0800172 WITH_PORT_FORWARDS \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000173 CONFIG_SADIS \
174 JUST_K8S \
175 DEPLOY_K8S \
176 INSTALL_ONOS_APPS \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000177 INSTALL_KUBECTL \
178 INSTALL_HELM \
David Bainbridge46505fb2019-10-01 21:13:20 +0000179 UPDATE_HELM_REPOS \
David Bainbridge4f1b5562019-08-19 04:46:52 +0000180 WAIT_ON_DOWN \
David Bainbridge70c0ea82019-11-14 23:25:26 +0000181 ONLY_ONE \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000182 "
David Bainbridge5b7b96b2019-07-25 20:29:13 +0000183
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000184ALL_OPTIONS="\
185 NAME \
186 TYPE \
187 $ALL_YES_NO \
188 VOLTHA_LOG_LEVEL \
189 VOLTHA_CHART \
David Bainbridge90fd8e32019-08-21 23:32:47 +0000190 VOLTHA_CHART_VERSION \
191 VOLTHA_BBSIM_CHART \
192 VOLTHA_BBSIM_CHART_VERSION \
uottrembd5a20572020-03-06 09:15:01 +0100193 NUM_OF_BBSIM \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000194 VOLTHA_ADAPTER_SIM_CHART \
David Bainbridge90fd8e32019-08-21 23:32:47 +0000195 VOLTHA_ADAPTER_SIM_CHART_VERSION \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000196 VOLTHA_ADAPTER_OPEN_OLT_CHART \
David Bainbridge90fd8e32019-08-21 23:32:47 +0000197 VOLTHA_ADAPTER_OPEN_OLT_CHART_VERSION \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000198 VOLTHA_ADAPTER_OPEN_ONU_CHART \
David Bainbridge90fd8e32019-08-21 23:32:47 +0000199 VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION \
David K. Bainbridgeda33d652020-03-06 10:31:23 -0800200 ONOS_CHART \
Andrea Campanella21323292019-12-18 11:44:19 -0800201 ONOS_CHART_VERSION \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000202 ONOS_API_PORT \
203 ONOS_SSH_PORT \
204 VOLTHA_API_PORT \
205 VOLTHA_SSH_PORT \
206 VOLTHA_ETCD_PORT \
David K. Bainbridge00ecd382020-02-28 12:31:58 -0800207 VOLTHA_KAFKA_PORT \
David K. Bainbridge8f7f30b2020-01-08 13:06:16 -0800208 VK_RELEASE \
209 KIND_VERSION \
210 VOLTCTL_VERSION \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000211 "
David Bainbridge01294952019-07-30 19:33:45 +0000212
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000213# Iterate over yes/no configuration options and validate
214for VAR in $ALL_YES_NO; do
215 eval $VAR=$(verify_yes_no $VAR)
216 if [ "$(eval echo \$$VAR)" == "INVALID" ]; then
217 exit 1;
218 fi
219done
David Bainbridgeb270c202019-07-26 01:44:42 +0000220
David K. Bainbridgeda33d652020-03-06 10:31:23 -0800221# Check for prerequiste tools
222TOOLS="go curl sed jq"
223if [ $DEPLOY_K8S == "yes" ]; then
224 TOOLS+=" docker"
225fi
226NOT_FOUND=""
227for T in $TOOLS; do
228 if [ -z "$(which $T)" ]; then
229 NOT_FOUND+=" $T"
230 fi
231done
232
233if [ ! -z "$NOT_FOUND" ]; then
234 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} The following required tools where not found, please install them:$NOT_FOUND"
235 exit 1
236fi
237
David Bainbridge0774b232019-08-02 06:37:19 +0000238mkdir -p .voltha
239touch .voltha/ports
240HAVE=$(grep $NAME .voltha/ports)
241if [ "$HAVE X" == " X" ]; then
242 # Find free port prefix
243 START=81
244 while true; do
245 if [ $(grep -c $START .voltha/ports) -eq 0 ]; then
246 break
247 fi
248 START=$(expr $START + 1)
249 done
250 DELTA=$(expr $START - 81)
David Bainbridgea2595422019-10-22 03:54:28 +0000251 ONOS_API_PORT=${ONOS_API_PORT:-${START}81}
252 ONOS_SSH_PORT=${ONOS_SSH_PORT:-${START}01}
253 VOLTHA_API_PORT=${VOLTHA_API_PORT:-5$(expr 55 + $DELTA)55}
254 VOLTHA_SSH_PORT=${VOLTHA_SSH_PORT:-$(expr 50 + $DELTA)22}
255 VOLTHA_ETCD_PORT=${VOLTHA_ETCD_PORT:-$(expr 23 + $DELTA)79}
David K. Bainbridge00ecd382020-02-28 12:31:58 -0800256 VOLTHA_KAFKA_PORT=${VOLTHA_KAFKA_PORT:-$(expr 90 + $DELTA)92}
Test User01ed0642019-07-03 20:17:06 +0000257else
David Bainbridge0774b232019-08-02 06:37:19 +0000258 VALUES=$(echo $HAVE | sed -e 's/\s//g' | cut -d= -f2)
David Bainbridgea2595422019-10-22 03:54:28 +0000259 ONOS_API_PORT=${ONOS_API_PORT:-$(echo $VALUES | cut -d, -f1)}
260 ONOS_SSH_PORT=${ONOS_SSH_PORT:-$(echo $VALUES | cut -d, -f2)}
261 VOLTHA_API_PORT=${VOLTHA_API_PORT:-$(echo $VALUES | cut -d, -f3)}
262 VOLTHA_SSH_PORT=${VOLTHA_SSH_PORT:-$(echo $VALUES | cut -d, -f4)}
263 VOLTHA_ETCD_PORT=${VOLTHA_ETCD_PORT:-$(echo $VALUES | cut -d, -f5)}
David K. Bainbridge00ecd382020-02-28 12:31:58 -0800264 VOLTHA_KAFKA_PORT=${VOLTHA_KAFKA_PORT:-$(echo $VALUES | cut -d, -f6)}
265
David K. Bainbridge00ecd382020-02-28 12:31:58 -0800266 # A bit of a hueristic required here as the KAFKA port forward was
267 # added after the .voltha/ports files was created. Basically, if
268 # the VOLTHA_KAFKA_PORT isn't in the file then calculate the original
269 # DELTA from the VOLTHA_SSH_PORT and apply it to the VOLTHA_KAFKA_PORT
270 if [ -z "$VOLTHA_KAFKA_PORT" ]; then
271 DELTA=$((VOLTHA_SSH_PORT/100-50))
272 VOLTHA_KAFKA_PORT=${VOLTHA_KAFKA_PORT:-$(expr 90 + $DELTA)92}
273 fi
Test User01ed0642019-07-03 20:17:06 +0000274fi
275
David Bainbridge0774b232019-08-02 06:37:19 +0000276PORTTMP=$(mktemp -u)
277cat .voltha/ports | grep -v $NAME > $PORTTMP
David K. Bainbridge00ecd382020-02-28 12:31:58 -0800278echo "$NAME=$ONOS_API_PORT,$ONOS_SSH_PORT,$VOLTHA_API_PORT,$VOLTHA_SSH_PORT,$VOLTHA_ETCD_PORT,$VOLTHA_KAFKA_PORT" >> $PORTTMP
David Bainbridge0774b232019-08-02 06:37:19 +0000279cp $PORTTMP .voltha/ports
280rm -f $PORTTMP
281
David Bainbridge27790d62019-08-13 22:43:19 +0000282export ONOS_API_PORT ONOS_SSH_PORT
David Bainbridge01294952019-07-30 19:33:45 +0000283
Test Userd87942b2019-07-03 07:20:24 +0000284IDX=1
David Bainbridgee87067b2019-08-12 22:00:12 +0000285CLOCK="TIME:"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000286SPIN_PARTS=
287NOT_VERIFIED=
David Bainbridgef858a022019-08-14 21:25:11 +0000288THEX=
289BUILD=
290CROSS=
291ENTER=
David Bainbridge38dc1e82019-08-12 15:18:45 +0000292VERIFIED=
293HELM=
294OLD_KEY=
295BIRD=
296HIGH_VOLTAGE=
297PLUG=
298RESTART=
299FORWARD=
300INSTALL=
301STOP=
302GO=
303DOWNLOAD=
304GEAR=
305NO_ENTRY=
306LOCK=
307
308if [ $FANCY -eq 1 ]; then
309 SPIN_PARTS="\
310 \xe2\xa2\x8e\xe2\xa1\xb0 \
311 \xe2\xa2\x8e\xe2\xa1\xa1 \
312 \xe2\xa2\x8e\xe2\xa1\x91 \
313 \xe2\xa2\x8e\xe2\xa0\xb1 \
314 \xe2\xa0\x8e\xe2\xa1\xb1 \
315 \xe2\xa2\x8a\xe2\xa1\xb1 \
316 \xe2\xa2\x8c\xe2\xa1\xb1 \
317 \xe2\xa2\x86\xe2\xa1\xb1 \
318 "
David Bainbridgee87067b2019-08-12 22:00:12 +0000319 CLOCK="\xe2\x8f\xb1"
David Bainbridgef858a022019-08-14 21:25:11 +0000320 THEX="${RED}${BOLD}\xe2\x9c\x97\x20${NORMAL}"
321 ENTER="${YELLOW}${BOLD}\xe2\x8e\x86${NORMAL}"
322 CROSS="${YELLOW}${BOLD}\xe2\x9c\x9a${NORMAL}"
323 BUILD="${YELLOW}${BOLD}\xf0\x9f\x8f\x97${NORMAL}"
324 NOT_VERIFIED="$BUILD"
325 VERIFIED="${GREEN}${BOLD}\xe2\x9c\x93\x20${NORMAL}"
326 HELM="${BLUE}${BOLD}\xE2\x8E\x88${NORMAL}"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000327 OLD_KEY="\xF0\x9F\x97\x9D"
328 BIRD="\xF0\x9F\x90\xA6"
329 HIGH_VOLTAGE="\xE2\x9A\xA1"
330 PLUG="\xF0\x9F\xa7\xa9"
331 RESTART="\xf0\x9f\x94\x84"
332 FORWARD="\xE2\x87\xA8"
333 INSTALL="\xF0\x9F\x8F\x97"
334 STOP="\xf0\x9f\x9b\x91"
335 GO="\xf0\x9f\x9a\x80"
336 DOWNLOAD="\xf0\x9f\x93\xa5"
337 GEAR="\xe2\x9a\x99"
338 NO_ENTRY="\xe2\x9b\x94"
339 LOCK="\xf0\x9f\x94\x92"
340fi
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700341
David Bainbridge712afb82019-08-14 19:55:58 +0000342duration() {
David Bainbridgee87067b2019-08-12 22:00:12 +0000343 local h=$(expr $1 / 3600)
344 local m=$(expr $1 % 3600 / 60)
345 local s=$(expr $1 % 60)
346 local t=""
347
348 if [ $h -gt 0 ]; then
349 t="$t${h}h"
350 fi
351 if [ $m -gt 0 ]; then
352 t="$t${m}m"
353 fi
David Bainbridge712afb82019-08-14 19:55:58 +0000354 echo "$t${s}s"
355}
356
357printtime() {
358 local INDENT=
359 if [ "$1" == "-" ]; then
360 INDENT=" "
361 shift
362 fi
363 echo -e "$INDENT $CLOCK $(duration $1)"
David Bainbridgee87067b2019-08-12 22:00:12 +0000364}
365
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700366bspin() {
Test Userd87942b2019-07-03 07:20:24 +0000367 IDX=1
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700368 local INDENT=
369 if [ "$1" == "-" ]; then
370 INDENT=" "
371 shift
372 fi
David Bainbridge38dc1e82019-08-12 15:18:45 +0000373 if [ $FANCY -eq 0 ]; then
374 LINE=$(echo $* | sed -e 's/[\s+-]//g')
375 if [ "$LINE X" == " X" ]; then
376 return
377 fi
378 echo -e "$CIVIS$INDENT$*"
379 else
380 echo -en "$CIVIS$INDENT $*"
381 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700382}
383
384sspin() {
385 local INDENT=
386 if [ "$1" == "-" ]; then
387 INDENT=" "
388 shift
389 fi
David Bainbridge38dc1e82019-08-12 15:18:45 +0000390 if [ $FANCY -eq 0 ]; then
391 LINE=$(echo $* | sed -e 's/[\s+-]//g')
392 if [ "$LINE X" == " X" ]; then
393 return
394 fi
395 echo -e "$INDENT$*"
396 else
397 C=$(echo $SPIN_PARTS | cut '-d ' -f $IDX)
398 echo -en "\r$INDENT$C $*"
399 IDX=$(expr $IDX + 1)
400 if [ $IDX -gt 8 ]; then
401 IDX=1
402 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700403 fi
404}
405
406espin() {
407 local INDENT=
408 if [ "$1" == "-" ]; then
409 INDENT=" "
410 shift
411 fi
David Bainbridge38dc1e82019-08-12 15:18:45 +0000412 if [ $FANCY -eq 0 ]; then
413 LINE=$(echo $* | sed -e 's/[\s+-]//g')
414 if [ "$LINE X" == " X" ]; then
415 return
416 fi
417 echo -e "$INDENT$*"
418 else
419 echo -e "\r$INDENT$*$CNORM"
420 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700421}
422
David Bainbridgeac7f8072019-08-01 22:15:33 +0000423if [ "$1" == "get" -a "$2" == "voltconfig" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000424 echo "$HOME/.volt/config-$NAME"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000425 exit
426fi
427
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -0700428if [ $# -ne 1 -o $(echo ":up:down:dump:" | grep -c ":$1:") -ne 1 ]; then
David Bainbridgeac7f8072019-08-01 22:15:33 +0000429 >&2 echo "What wouild you like to do today:"
430 >&2 echo " up - bring up voltha"
431 >&2 echo " down - tear down voltha"
432 >&2 echo " dump - create a debug dump of running system"
433 exit 1
434fi
435
David Bainbridge4f1b5562019-08-19 04:46:52 +0000436push_onos_config() {
Matteo Scandolo78dfee02020-02-13 16:18:03 -0800437 local TYPE=$1
438 local MSG=$2
439 local RESOURCE=$3
440 local DATA=$4
David Bainbridge4f1b5562019-08-19 04:46:52 +0000441
David K. Bainbridgeb4b163b2020-02-19 15:55:06 -0800442 # Thanks to the latest version of ONOS using the return code 207 this gets a
443 # whole lot nastier. Can't thank them enough for doing this. So in order to
444 # capture the command and the output in the log file as well as capture the
445 # status code to verify it is 200 and not 207 mutltiple files and a bit of
446 # hackery must be used. Thanks again ONOS.
447 local CMD_ECHO=$(mktemp -u)
448 local CMD_OUTPUT=$(mktemp -u)
449 local SC_OUTPUT=$(mktemp -u)
450
David Bainbridge4f1b5562019-08-19 04:46:52 +0000451 bspin - "$MSG $GEAR"
452 while true; do
Matteo Scandolo78dfee02020-02-13 16:18:03 -0800453 if [ $TYPE == "file" ]; then
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -0800454 (set -x; curl --fail -sSL --user karaf:karaf -w "%{http_code}" -o $CMD_OUTPUT -X POST -H Content-Type:application/json http://$_ONOS_API_EP/onos/v1/$RESOURCE --data @$DATA >$SC_OUTPUT 2>/dev/null) >>$CMD_ECHO 2>&1
Matteo Scandolo78dfee02020-02-13 16:18:03 -0800455 fi
456 if [ $TYPE == "json" ]; then
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -0800457 (set -x; curl --fail -sSL --user karaf:karaf -w "%{http_code}" -o $CMD_OUTPUT -X POST -H Content-Type:application/json http://$_ONOS_API_EP/onos/v1/$RESOURCE --data $DATA >$SC_OUTPUT 2>/dev/null) >>$CMD_ECHO 2>&1
Matteo Scandolo78dfee02020-02-13 16:18:03 -0800458 fi
David K. Bainbridgeb4b163b2020-02-19 15:55:06 -0800459 RESULT=$?
460 # Dump everything to the log
461 cat $CMD_ECHO >> $LOG
462 cat $CMD_OUTPUT >> $LOG
463 SC=$(cat $SC_OUTPUT)
464
465 # clean up temp files
466 rm -f $CMD_ECHO $CMD_OUTPUT $SC_OUTPUT
467 if [ $RESULT -eq 0 -a "$SC" == "200" ]; then
David Bainbridge4f1b5562019-08-19 04:46:52 +0000468 break
469 fi
Matteo Scandolo9a77a732020-01-09 14:24:12 -0800470 sleep 1
David Bainbridge4f1b5562019-08-19 04:46:52 +0000471 sspin -
472 done
473 espin - $VERIFIED
474}
475
Matteo Scandolo9a77a732020-01-09 14:24:12 -0800476check_onos_app_active() {
477 local APP_ID=$1
478
479 bspin - "Checking that $APP_ID is active $CLOCK"
480 while true; do
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -0800481 (set -x; curl --fail -sSL --user karaf:karaf -X GET http://$_ONOS_API_EP/onos/v1/applications/$APP_ID | grep ACTIVE >>$LOG 2>&1) >>$LOG 2>&1
Matteo Scandolo9a77a732020-01-09 14:24:12 -0800482 if [ $? -eq 0 ]; then
483 break
484 fi
485 sleep 1
486 sspin -
487 done
488 sleep 5 # OSGI components take a little longer that the app to activate
489 espin - $VERIFIED
490}
491
David Bainbridge4f1b5562019-08-19 04:46:52 +0000492override_onos_app() {
493 local APP=$1
494 local NAME=$(basename $APP | sed -e 's/^[0-9][0-9]*-//g' -e 's/-.*$//g')
495 while true; do
496 sspin -
497 # Attempt to delete old version (if it exists)
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -0800498 (set -x; curl --fail -sSL --user karaf:karaf -X DELETE http://$_ONOS_API_EP/onos/v1/applications/$NAME >>$LOG 2>&1) >>$LOG 2>&1
David Bainbridge4f1b5562019-08-19 04:46:52 +0000499 sspin -
500 if [ $? -ne 0 ]; then
501 continue
502 fi
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -0800503 (set -x; curl --fail -sSL --user karaf:karaf -X POST -H Content-Type:application/octet-stream http://$_ONOS_API_EP/onos/v1/applications?activate=true --data-binary @$APP >>$LOG 2>&1) >>$LOG 2>&1
David Bainbridge4f1b5562019-08-19 04:46:52 +0000504 if [ $? -eq 0 ]; then
505 break
506 fi
507 sleep .2
508 done
509}
510
511activate_onos_app() {
512 local MSG="$1"
513 local APP=$2
514
515 bspin - "$MSG $GO"
516 while true; do
517 sspin -
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -0800518 (set -x; curl --fail -sSL --user karaf:karaf -X POST http://$_ONOS_API_EP/onos/v1/applications/$APP/active >>$LOG 2>&1) >>$LOG 2>&1
David Bainbridge4f1b5562019-08-19 04:46:52 +0000519 if [ $? -eq 0 ]; then
520 break
521 fi
522 sleep .2
523 done
524 espin - "$VERIFIED"
525}
526
527count_pods() {
528 local NAMESPACE=$1; shift
529 if [ "$NAMESPACE" == "all-namespaces" ]; then
530 NAMESPACE="--all-namespaces"
531 else
532 NAMESPACE="-n $NAMESPACE"
533 fi
534 echo "$NAMESPACE" > /tmp/t
535 local STATES=$1; shift
536 echo "$STATES" >> /tmp/t
537 local PODS=$(kubectl get $NAMESPACE pod -o go-template="{{range .items}}{{.metadata.name}}/{{.status.phase}}/_{{range .status.containerStatuses}}{{.ready}}_{{end}} {{end}}")
538 local COUNT=0
539 local PATTERNS="$*"
540 for POD in $PODS; do
541 local NAME=$(echo $POD | cut -d/ -f 1)
542 local STATE=$(echo $POD | cut -d/ -f 2)
543 local CONTAINERS=$(echo $POD | cut -d/ -f 3 | sed -e 's/_/ /g')
544 if [ "$STATES" == "*" -o $(echo "$STATES" | grep -c ":$STATE:") -ne 0 ]; then
545 echo "IN WITH $POD" >> /tmp/t
546 local TOTAL=$(echo $CONTAINERS | wc -w)
547 local FOUND=$(echo $CONTAINERS | grep -o true | wc -l)
548 if [ $TOTAL -eq $FOUND ]; then
549 for PATTERN in $PATTERNS; do
550 echo "TEST $PATTERN AGAINST $NAME" >> /tmp/t
551 if [[ $NAME =~ $PATTERN ]]; then
552 echo "COUNT $NAME" >> /tmp/t
553 COUNT=$(expr $COUNT + 1)
554 break
555 fi
556 done
557 fi
558 fi
559 done
560 echo $COUNT >> /tmp/t
561 echo $COUNT
562}
563
564wait_for_pods() {
565 local INDENT=
566 if [ "$1" == "-" ]; then
567 INDENT=$1; shift
568 fi
569 local NAMESPACE=$1; shift
570 local EXPECT=$1; shift
571 local TYPE=$1; shift
572 local RETRY=$1; shift
573 local MESSAGE=$1; shift
574 local PATTERNS=$*
David Bainbridge99ac7a22019-08-31 02:26:43 +0000575 local STATES=":Running:"
576 if [ "$TYPE" == "not" ]; then
577 STATES="*"
578 fi
579 local HAVE=$(count_pods $NAMESPACE "$STATES" $PATTERNS)
David Bainbridge4f1b5562019-08-19 04:46:52 +0000580 local ALL=$HAVE
581 if [ "$TYPE" == "only" ]; then
582 ALL=$(count_pods "all-namespaces" "*" ".*")
583 fi
584 COUNT=$(expr 300 / 15)
585 bspin $INDENT $MESSAGE
586 sspin $INDENT
587 if [ $HAVE -ne $EXPECT -o $ALL -ne $HAVE ]; then
588 while [ $HAVE -ne $EXPECT -o $ALL -ne $HAVE ]; do
589 sspin $INDENT
590 COUNT=$(expr $COUNT - 1)
591 if [ $COUNT -eq 0 ]; then
David Bainbridge99ac7a22019-08-31 02:26:43 +0000592 HAVE=$(count_pods $NAMESPACE "$STATES" $PATTERNS)
David Bainbridge4f1b5562019-08-19 04:46:52 +0000593 ALL=$HAVE
594 if [ "$TYPE" == "only" ]; then
595 ALL=$(count_pods "all-namespaces" "*" ".*")
596 fi
597 COUNT=$(expr 300 / 15)
598 fi
599 sleep .15
600 done
601 fi
602 espin $INDENT $VERIFIED
603 if [ $HAVE -ne $EXPECT ]; then
604 return 1
605 fi
606 return 0
607}
608
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800609port_forward() {
610 local NS=$1
611 local SVC=$2
612 local FROM_PORT=$3
613 local TO_PORT=$4
614 local TAG=$SVC-$NAME
615
616 (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
617}
618
619kill_port_forward() {
620 local TAG=$1-$NAME
David Bainbridgec6871d22019-11-13 17:10:31 +0000621 local P_IDS=$(ps e -ww -A | grep "_TAG=$TAG" | grep -v grep | awk '{print $1}')
David Bainbridgebcf235b2019-11-12 21:33:58 +0000622 local PARENTS=
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800623 local KIDS=
David Bainbridgec6871d22019-11-13 17:10:31 +0000624 local UNKNOWN=
625 if [ ! -z "$P_IDS" ]; then
626 for P_ID in $P_IDS; do
627 local PP_ID=$(ps -o ppid $P_ID | tail -n +2)
628 if [ ! -z "$PP_ID" ]; then
629 if [ $PP_ID -eq 1 ]; then
630 PARENTS="$PARENTS $P_ID"
631 else
632 KIDS="$KIDS $P_ID"
633 fi
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800634 else
David Bainbridgec6871d22019-11-13 17:10:31 +0000635 UNKNOWN="$UNKNOWN $P_ID"
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800636 fi
637 done
David Bainbridgec6871d22019-11-13 17:10:31 +0000638 (set -x; kill -9 $PARENTS $KIDS $UNKNOWN >>$LOG 2>&1) >>$LOG 2>&1
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800639 fi
640}
641
David Bainbridgeac7f8072019-08-01 22:15:33 +0000642if [ "$1" == "down" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000643 echo "Tearing down voltha cluster $NAME"
644 LOG="down-$NAME.log"
645 echo $(date -u +"%Y%m%dT%H%M%SZ") >$LOG
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800646 bspin "Remove port-forwards: onos-ui-$NAME"
647 kill_port_forward onos-ui
648 sspin "Remove port-forwards: onos-ssh-$NAME$CEOL"
649 kill_port_forward onos-ssh
650 sspin "Remove port-forwards: voltha-api-$NAME$CEOL"
651 kill_port_forward voltha-api
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800652 sspin "Remove port-forwards: voltha-etcd-$NAME$CEOL"
653 kill_port_forward voltha-etcd-cluster-client
David K. Bainbridge00ecd382020-02-28 12:31:58 -0800654 sspin "Remove port-forwards: voltha-kafka-$NAME$CEOL"
655 kill_port_forward voltha-kafka
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800656 espin "$VERIFIED Remove port-forwards$CEOL"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000657 if [ $DEPLOY_K8S == "yes" ]; then
658 if [ -x ./bin/kind ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000659 bspin "Delete Kubernetes Kind Cluster"
660 (set -x; ./bin/kind delete cluster --name voltha-$NAME >>$LOG 2>&1) >>$LOG 2>&1
661 espin $VERIFIED
David Bainbridgeac7f8072019-08-01 22:15:33 +0000662 else
David Bainbridge0774b232019-08-02 06:37:19 +0000663 espin "$NO_ENTRY Delete Kubernetes Kind Cluster: kind command not found"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000664 fi
665 else
666 EXISTS=$(helm list -q)
667 EXPECT="etcd-operator onos open-olt open-onu sim voltha bbsim radius"
David Bainbridge0774b232019-08-02 06:37:19 +0000668 bspin "Remove Helm Deployments"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000669 for i in $EXISTS; do
David K. Bainbridge43422402020-03-06 07:41:22 -0800670 for j in $EXPECT; do
671 if [[ $i =~ $j ]]; then
672 sspin "Remove Helm Deployments: $i$CEOL"
673 (set -x; ./bin/helm delete --no-hooks --purge $i >>$LOG 2>&1) >>$LOG 2>&1
674 fi
675 done
uottrembb16d3982020-02-28 08:34:36 +0100676 done
David Bainbridge0774b232019-08-02 06:37:19 +0000677 espin "$VERIFIED Remove Helm Deployments$CEOL"
David Bainbridge4f1b5562019-08-19 04:46:52 +0000678 if [ "$WAIT_ON_DOWN" == "yes" ]; then
679 # There should only be 13 or 15 PODs in the kube-system name
680 # space and no other PODs
David Bainbridge4f1b5562019-08-19 04:46:52 +0000681 PODS="coredns-.* \
682 etcd-voltha-$NAME-control-plane \
683 kindnet-.* \
684 kube-apiserver-voltha-$NAME-control-plane \
685 kube-controller-manager-voltha-$NAME-control-plane \
686 kube-proxy-.* \
687 kube-scheduler-voltha-$NAME-control-plane \
688 tiller-deploy-.*"
689 EXPECT=$(test "$TYPE" == "minimal" && echo "13" || echo "15")
David Bainbridge99ac7a22019-08-31 02:26:43 +0000690 PODS="adapter-.* \
691 bbsim.* \
692 etcd-operator.* \
693 radius.* \
694 voltha-.*"
Matteo Scandolo73442f92020-01-29 09:53:22 -0800695
David Bainbridge99ac7a22019-08-31 02:26:43 +0000696 EXPECT=0
697
Matteo Scandolo73442f92020-01-29 09:53:22 -0800698 if [ "$WITH_ONOS" == "yes" ]; then
699 ONOS_PODS="onos-.*"
700 wait_for_pods "default" $EXPECT "not" -1 "Waiting for ONOS PODs to terminate" $ONOS_PODS
701 fi
David Bainbridge99ac7a22019-08-31 02:26:43 +0000702 wait_for_pods "voltha" $EXPECT "not" -1 "Waiting for VOLTHA PODs to terminate" $PODS
David Bainbridge4f1b5562019-08-19 04:46:52 +0000703 fi
David Bainbridgeac7f8072019-08-01 22:15:33 +0000704 fi
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -0700705 exit
David Bainbridgeac7f8072019-08-01 22:15:33 +0000706fi
707
708if [ "$1" == "dump" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000709 LOG="dump-$NAME.log"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000710 TS=$(date -u +"%Y%m%dT%H%M%SZ")
David Bainbridge76514a02019-10-08 01:50:35 +0000711 if [ ! -z "$DUMP_FROM" ]; then
712 TS=$(echo $DUMP_FROM | sed -e 's/[:-]//g')
713 fi
David Bainbridgeac7f8072019-08-01 22:15:33 +0000714 WORK=$(mktemp -u -d)
David Bainbridge0774b232019-08-02 06:37:19 +0000715 DATA=$WORK/voltha-debug-dump-$NAME-$TS
David Bainbridgeac7f8072019-08-01 22:15:33 +0000716 mkdir -p $DATA
717 echo $TS > $LOG
David Bainbridge0774b232019-08-02 06:37:19 +0000718 echo -e "Capturing debug dump to voltha-debug-dump-$NAME-$TS.tgz"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000719 bspin - "Copy install log"
David Bainbridge0774b232019-08-02 06:37:19 +0000720 if [ -f install-$NAME.log ]; then
721 (set -x; cp install-$NAME.log $DATA/install-$NAME.log) >>$LOG 2>&1
David Bainbridgeac7f8072019-08-01 22:15:33 +0000722 espin - $VERIFIED
723 else
David Bainbridge0774b232019-08-02 06:37:19 +0000724 espin - "$NO_ENTRY Copy install log: install-$NAME.log not found"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000725 fi
726 bspin - "Dumping Kubernetes PODs"
727 (set -x; kubectl get --all-namespaces pods >> $DATA/all-pods.txt 2>&1) >>$LOG 2>&1
728 espin - $VERIFIED
729 bspin - "Dumping Kubernetes SERVICEs"
730 (set -x; kubectl get --all-namespaces svc >> $DATA/all-services.txt 2>&1) >>$LOG 2>&1
731 espin - $VERIFIED
732 bspin - "Dumping Kubernetes EVENTs"
733 (set -x; kubectl get --all-namespaces events >> $DATA/all-events.txt 2>&1) >>$LOG 2>&1
734 espin - $VERIFIED
735 bspin - "Dumping VOLTHA POD details"
Matteo Scandolodcd29f52019-10-07 15:42:42 -0700736 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 +0000737 SINCE=
738 if [ ! -z "$DUMP_FROM" ]; then
739 SINCE="--since-time=$DUMP_FROM"
740 fi
David Bainbridgeac7f8072019-08-01 22:15:33 +0000741 for POD in $PODS; do
David Bainbridge1f0655a2019-10-01 22:08:48 +0000742 NS=$(echo $POD | cut -d: -f1)
743 POD=$(echo $POD | cut -d: -f2)
David Bainbridgeac7f8072019-08-01 22:15:33 +0000744 sspin - "Dumping VOLTHA POD details: $POD$CEOL"
745 mkdir -p $DATA/$POD
David Bainbridge1f0655a2019-10-01 22:08:48 +0000746 (set -x; kubectl describe -n $NS $POD >> $DATA/$POD/describe.txt 2>&1) >>$LOG 2>&1
David Bainbridgeac7f8072019-08-01 22:15:33 +0000747 sspin - "Dumping VOLTHA POD details: $POD"
David Bainbridgecfd7ca12019-10-06 03:31:41 +0000748 (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 +0000749 sspin - "Dumping VOLTHA POD details: $POD"
David Bainbridgecfd7ca12019-10-06 03:31:41 +0000750 (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 +0000751 sspin - "Dumping VOLTHA POD details: $POD"
752 done
753 espin - "$VERIFIED Dumping VOLTHA POD details$CEOL"
754 bspin - "Dumping ETCD"
755 if [ "$(which etcdctl) X" != " X" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000756 (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 +0000757 espin - $VERIFIED
758 else
759 espin - "$NO_ENTRY Dumping ETCD: etcdctl command not available"
760 fi
David Bainbridge0774b232019-08-02 06:37:19 +0000761 bspin - "Creating compressed TAR: voltha-debug-dump-$NAME-$TS.tgz"
762 (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 +0000763 espin - $VERIFIED
764 bspin - "Cleanup"
765 (set -x; rm -rf $WORK) >>$LOG 2>&1
766 espin - $VERIFIED
David Bainbridge0774b232019-08-02 06:37:19 +0000767 bspin - "$(ls -l voltha-debug-dump-$NAME-$TS.tgz)"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000768 espin - $VERIFIED
769 exit
770fi
771
David Bainbridge0774b232019-08-02 06:37:19 +0000772LOG="install-$NAME.log"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000773date > $LOG
David Bainbridge0774b232019-08-02 06:37:19 +0000774echo "PORTS=$ONOS_API_PORT,$ONOS_SSH_PORT,$VOLTHA_API_PORT,$VOLTHA_SSH_PORT,$VOLTHA_ETCD_PORT" >> $LOG
David Bainbridgeac7f8072019-08-01 22:15:33 +0000775
776# Output install options to log
777echo "OPTIONS" >> $LOG
David Bainbridgeac7f8072019-08-01 22:15:33 +0000778for O in $ALL_OPTIONS; do
779 VAL=$(eval echo \$$O)
David Bainbridgeac7f8072019-08-01 22:15:33 +0000780 if [ ! -z "$VAL" ]; then
781 printf " %-30s = %s\n" $O $VAL >> $LOG
782 fi
783done
784
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -0700785helm_install() {
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700786 local INDENT=
787 if [ "$1" == "-" ]; then
788 INDENT=$1; shift
789 fi
790 local NAMESPACE=$1; shift
David Bainbridge0774b232019-08-02 06:37:19 +0000791 local INAME=$1; shift
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700792 local CHART=$1; shift
David Bainbridge90fd8e32019-08-21 23:32:47 +0000793 local CHART_VERSION=$1; shift
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700794 local MESSAGE=$*
795
David Bainbridge90fd8e32019-08-21 23:32:47 +0000796 if [ "$CHART_VERSION X" != " X" -a "$CHART_VERSION" != "latest" ]; then
797 CHART_VERSION="--version $CHART_VERSION"
798 else
799 CHART_VERSION=
800 fi
801
David Bainbridge99ac7a22019-08-31 02:26:43 +0000802 local CHART_ARGS=
803 if [ -r "${INAME}-values.yaml" ]; then
804 CHART_ARGS="-f ${INAME}-values.yaml"
805 fi
806
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700807 COUNT=$(expr 300 / 15)
808 bspin $INDENT $MESSAGE
David Bainbridge70c0ea82019-11-14 23:25:26 +0000809 (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 -0700810 SUCCESS=$?
811 while [ $SUCCESS -ne 0 ]; do
812 sspin $INDENT
813 COUNT=$(expr $COUNT - 1)
814 if [ $COUNT -eq 0 ]; then
Andy Baviere22ff252019-12-19 11:40:31 -0700815 (set -x; helm delete --purge $INAME >>$LOG 2>&1) >>$LOG 2>&1
David Bainbridge99ac7a22019-08-31 02:26:43 +0000816 (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 -0700817 SUCCESS=$?
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700818 COUNT=$(expr 300 / 15)
819 fi
820 sleep .15
821 done
822 espin $INDENT $VERIFIED
823}
824
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700825echo "INSTALL TYPE: $TYPE" >> $LOG
826
827bspin "Verify GOPATH"
828export GOPATH=$(pwd)
Test User3d7ad8e2019-07-03 06:15:44 +0000829mkdir -p $GOPATH/bin
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700830espin $VERIFIED
831
David Bainbridgee87067b2019-08-12 22:00:12 +0000832STIME=$(date +%s)
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700833if [ "$INSTALL_KUBECTL" == "no" ]; then
834 bspin "Skip kubectl install"
835 espin $NO_ENTRY
Test Userc13bdc92019-07-03 20:57:49 +0000836else
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700837 bspin "Verify kubectl $HELM"
838 if [ -x $GOPATH/bin/kubectl ]; then
839 espin $VERIFIED
840 else
841 espin $NOT_VERIFIED
842 bspin - "Download and install Kubernetes/kubectl $DOWNLOAD"
843 (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
844 (set -x; chmod 755 $GOPATH/bin/kubectl >>$LOG 2>&1) >>$LOG 2>&1
845 espin - $VERIFIED
846 fi
Test Userc13bdc92019-07-03 20:57:49 +0000847fi
David Bainbridgee87067b2019-08-12 22:00:12 +0000848if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +0000849 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +0000850fi
Test Userc13bdc92019-07-03 20:57:49 +0000851
David Bainbridgee87067b2019-08-12 22:00:12 +0000852STIME=$(date +%s)
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700853if [ "$DEPLOY_K8S" == "no" ]; then
854 bspin "Skip Kubernetes/Kind Deployment"
855 espin $NO_ENTRY
856else
Test Userba1e7e72019-07-10 22:27:54 +0000857 bspin "Verify Kubernetes/Kind $HELM"
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800858 IS_INSTALLED=0
859 OP_TYPE="install"
Test Userba1e7e72019-07-10 22:27:54 +0000860 if [ -x $GOPATH/bin/kind ]; then
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800861 OP_TYPE="upgrade"
862 if [ $($GOPATH/bin/kind --version | grep -c $KIND_VERSION) -eq 1 ]; then
863 IS_INSTALLED=1
864 espin $VERIFIED
865 fi
866 fi
867 if [ $IS_INSTALLED -eq 0 ]; then
Test Userba1e7e72019-07-10 22:27:54 +0000868 espin $NOT_VERIFIED
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800869 bspin - "Download and $OP_TYPE Kubernetes/kind $DOWNLOAD"
David Bainbridge9e2a6662019-07-11 17:07:57 +0000870 (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 +0000871 (set -x; chmod 755 $GOPATH/bin/kind >>$LOG 2>&1) >>$LOG 2>&1
872 espin - $VERIFIED
873 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700874fi
875
David Bainbridgee87067b2019-08-12 22:00:12 +0000876if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +0000877 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +0000878fi
879
880STIME=$(date +%s)
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700881if [ "$INSTALL_HELM" == "no" ]; then
882 bspin "Skip Helm Install"
883 espin $NO_ENTRY
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700884else
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700885 bspin "Verify Helm $HELM"
886 if [ -x $GOPATH/bin/helm ]; then
887 espin $VERIFIED
888 else
889 espin $NOT_VERIFIED
890 bspin - "Download and install Helm $DOWNLOAD"
David Bainbridgec6a6eb62019-10-18 22:50:07 +0000891 (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 -0700892 espin - $VERIFIED
893 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700894fi
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800895
David Bainbridgee87067b2019-08-12 22:00:12 +0000896if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +0000897 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +0000898fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700899
David Bainbridgee87067b2019-08-12 22:00:12 +0000900STIME=$(date +%s)
Test Userb5712372019-07-03 21:52:17 +0000901bspin "Verify voltctl $HIGH_VOLTAGE"
David Bainbridged2811972019-12-14 01:14:09 +0000902VOK=0
903VMESSAGE="install"
David K. Bainbridgeebf38d92020-02-10 10:46:31 -0800904export VC_VERSION="$VOLTCTL_VERSION"
905if [ "$VC_VERSION" == "latest" ]; then
906 export VC_VERSION=$(curl -sSL https://api.github.com/repos/opencord/voltctl/releases/latest | jq -r .tag_name | sed -e 's/^v//g')
907fi
Test User3d7ad8e2019-07-03 06:15:44 +0000908if [ -x $GOPATH/bin/voltctl ]; then
David Bainbridge1ba64f12019-12-18 00:40:13 +0000909 VHAVE=$($GOPATH/bin/voltctl version --clientonly -o json | jq -r .version)
David K. Bainbridgeebf38d92020-02-10 10:46:31 -0800910 if [ $? -eq 0 -a "$VHAVE" == "$VC_VERSION" ]; then
David Bainbridged2811972019-12-14 01:14:09 +0000911 VOK=1
David Bainbridge1ba64f12019-12-18 00:40:13 +0000912 espin $VERIFIED
913 else
David K. Bainbridgeebf38d92020-02-10 10:46:31 -0800914 VCHECK=$(echo -e "$VHAVE\n$VC_VERSION" | sort -V | head -1)
915 if [ "$VCHECK" == "$VHAVE" ]; then
916 VMESSAGE="upgrade"
917 else
918 VMESSAGE="downgrade"
919 fi
David Bainbridged2811972019-12-14 01:14:09 +0000920 fi
921fi
922
David Bainbridge1ba64f12019-12-18 00:40:13 +0000923if [ $VOK -eq 0 ]; then
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700924 espin $NOT_VERIFIED
David Bainbridged2811972019-12-14 01:14:09 +0000925 bspin - "Download and $VMESSAGE voltctl $DOWNLOAD"
David K. Bainbridgeebf38d92020-02-10 10:46:31 -0800926 (set -x; curl -o $GOPATH/bin/voltctl -sSL https://github.com/opencord/voltctl/releases/download/v$VC_VERSION/voltctl-$VC_VERSION-$HOSTOS-$HOSTARCH >>$LOG 2>&1) >>$LOG 2>&1
Test User08ebbd92019-07-03 17:15:39 +0000927 (set -x; chmod 755 $GOPATH/bin/voltctl >>$LOG 2>&1) >>$LOG 2>&1
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700928 espin - $VERIFIED
929fi
David Bainbridgee87067b2019-08-12 22:00:12 +0000930if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +0000931 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +0000932fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700933
934bspin "Verify command PATH"
Test Userba1e7e72019-07-10 22:27:54 +0000935export PATH=$GOPATH/bin:$PATH
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700936espin $VERIFIED
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700937
David Bainbridgee87067b2019-08-12 22:00:12 +0000938STIME=$(date +%s)
Test Userba1e7e72019-07-10 22:27:54 +0000939if [ "$DEPLOY_K8S" == "yes" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000940 HAVE=$(kind get clusters | grep -c voltha-$NAME)
Test Userba1e7e72019-07-10 22:27:54 +0000941 bspin "Verify Kubernetes/Kind Cluster"
942 sspin
943 if [ $HAVE -eq 0 ]; then
David Bainbridge491b1bd2019-07-11 17:53:11 +0000944 espin $NOT_VERIFIED
945 bspin - "Verify cluster configuration"
David Bainbridge0774b232019-08-02 06:37:19 +0000946 if [ ! -r ./$NAME-cluster.cfg ]; then
David Bainbridge491b1bd2019-07-11 17:53:11 +0000947 espin - $NOT_VERIFIED
David K. Bainbridge43422402020-03-06 07:41:22 -0800948 bspin - "Download cluster configuration: $TYPE-cluster.cfg to $NAME-cluster.cfg $DOWNLOAD"
David K. Bainbridgea00736b2020-01-08 14:33:17 -0800949 ERR_OUT=$(mktemp)
950 (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
951 if [ $? -ne 0 ]; then
952 espin - $THEX
953 echo -e "${RED}${BOLD}${ERROR}ERROR: $NAME-cluster.cfg${NORMAL}${RED} - $(cat $ERR_OUT)${NORMAL}"
954 echo "ERROR: $(cat $ERR_OUT)" >>$LOG
955 rm -rf $ERR_OUT ./$NAME-cluster.cfg
956 exit 1
957 fi
958 rm -rf $ERR_OUT
959 else
David K. Bainbridge43422402020-03-06 07:41:22 -0800960 espin - $VERIFIED
David K. Bainbridgea00736b2020-01-08 14:33:17 -0800961 fi
David Bainbridge0774b232019-08-02 06:37:19 +0000962 kind create cluster --name voltha-$NAME --config $NAME-cluster.cfg
David Bainbridge491b1bd2019-07-11 17:53:11 +0000963 else
964 espin $VERIFIED
Test Userba1e7e72019-07-10 22:27:54 +0000965 fi
966
David Bainbridge0774b232019-08-02 06:37:19 +0000967 export KUBECONFIG="$(kind get kubeconfig-path --name="voltha-$NAME")"
Test Userba1e7e72019-07-10 22:27:54 +0000968 P="coredns-.* \
David Bainbridge0774b232019-08-02 06:37:19 +0000969 etcd-voltha-$NAME-control-plane \
Test Userba1e7e72019-07-10 22:27:54 +0000970 kindnet-.* \
David Bainbridge0774b232019-08-02 06:37:19 +0000971 kube-apiserver-voltha-$NAME-control-plane \
972 kube-controller-manager-voltha-$NAME-control-plane \
Test Userba1e7e72019-07-10 22:27:54 +0000973 kube-proxy-.* \
David Bainbridge0774b232019-08-02 06:37:19 +0000974 kube-scheduler-voltha-$NAME-control-plane"
Test Userba1e7e72019-07-10 22:27:54 +0000975
976 EXPECT=$(test "$TYPE" == "minimal" && echo "12" || echo "14")
David Bainbridge4f1b5562019-08-19 04:46:52 +0000977 wait_for_pods - "kube-system" $EXPECT "includes" -1 "Waiting for system PODs to start" $P
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700978fi
David Bainbridgee87067b2019-08-12 22:00:12 +0000979if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +0000980 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +0000981fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700982
David Bainbridgee87067b2019-08-12 22:00:12 +0000983STIME=$(date +%s)
David Bainbridge4c6289c2019-09-03 21:11:32 +0000984COUNT=$(count_pods "kube-system" ":Running:" "tiller-deploy-.*")
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700985bspin "Verify Helm"
Test Userba1e7e72019-07-10 22:27:54 +0000986if [ $COUNT -ne 1 ]; then
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700987 espin $NOT_VERIFIED
Test Userb5712372019-07-03 21:52:17 +0000988 echo -e "Configuring Helm $GEAR"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700989 if [ "$INSTALL_HELM" == "no" ]; then
990 bspin - "Skip Helm/Tiller Initialization"
991 espin - $NO_ENTRY
992 else
993 bspin - "Initialize Helm"
994 (set -x; helm init --upgrade >>$LOG 2>&1) >>$LOG 2>&1
995 espin - $VERIFIED
David Bainbridge4f1b5562019-08-19 04:46:52 +0000996 wait_for_pods - "kube-system" 1 "includes" -1 "Waiting for Tiller POD to start" "tiller-deploy-.*"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700997 fi
Test Userb5712372019-07-03 21:52:17 +0000998 bspin - "Add Google Incubator repository to Helm"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700999 (set -x; helm repo add incubator https://kubernetes-charts-incubator.storage.googleapis.com >>$LOG 2>&1) >>$LOG 2>&1
1000 espin - $VERIFIED
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001001
Test Userba1e7e72019-07-10 22:27:54 +00001002 # HACK (sort-of) - the config for tiller is about to be patched, which will
1003 # cause the tiller pod to be recreated. This can sometimes cause a timing
1004 # issue with the "wait_for_pods" call on tiller as it may incorrectly
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001005 # identify the running/ready tiller pod that is soon to be terminated as
Test Userba1e7e72019-07-10 22:27:54 +00001006 # what it is waiting for. To avoid this issue we do a clean scale down and
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001007 # scale up of the pod so the script controlls when it should be expecting
Test Userba1e7e72019-07-10 22:27:54 +00001008 # things
1009 (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 -07001010
Test Userb5712372019-07-03 21:52:17 +00001011 bspin - "Add Google Stable repository to Helm"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001012 (set -x; helm repo add stable https://kubernetes-charts.storage.googleapis.com >>$LOG 2>&1) >>$LOG 2>&1
1013 espin - $VERIFIED
Test Userb5712372019-07-03 21:52:17 +00001014 bspin - "Add ONF repository to Helm"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001015 (set -x; helm repo add onf https://charts.opencord.org >>$LOG 2>&1) >>$LOG 2>&1
1016 espin - $VERIFIED
Test Userb5712372019-07-03 21:52:17 +00001017 bspin - "Update Helm repository cache"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001018 (set -x; helm repo update >>$LOG 2>&1) >>$LOG 2>&1
1019 espin - $VERIFIED
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001020
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001021 # Create and k8s service account so that Helm can create pods
Test Userb5712372019-07-03 21:52:17 +00001022 bspin - "Create Tiller ServiceAccount"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001023 (set -x; kubectl create serviceaccount --namespace kube-system tiller >>$LOG 2>&1) >>$LOG 2>&1
1024 espin - $VERIFIED
Test Userb5712372019-07-03 21:52:17 +00001025 bspin - "Create Tiller ClusterRoleBinding"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001026 (set -x; kubectl create clusterrolebinding tiller-cluster-rule --clusterrole=cluster-admin --serviceaccount=kube-system:tiller >>$LOG 2>&1) >>$LOG 2>&1
1027 espin - $VERIFIED
Test Userb5712372019-07-03 21:52:17 +00001028 bspin - "Update Tiller Manifest"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001029 (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 +00001030
1031 # HACK (sort-of) - part to, spin it back up
1032 (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 -07001033 espin - $VERIFIED
1034else
1035 espin $VERIFIED
David Bainbridge46505fb2019-10-01 21:13:20 +00001036 if [ "$UPDATE_HELM_REPOS" == "yes" ]; then
1037 bspin - "Update Helm repository cache"
1038 (set -x; helm repo update >>$LOG 2>&1) >>$LOG 2>&1
1039 espin - $VERIFIED
1040 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001041fi
David Bainbridge4f1b5562019-08-19 04:46:52 +00001042wait_for_pods - "kube-system" 1 "includes" -1 "Waiting for Tiller POD to start" "tiller-deploy-.*"
David Bainbridgee87067b2019-08-12 22:00:12 +00001043if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +00001044 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +00001045fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001046
David Bainbridgee87067b2019-08-12 22:00:12 +00001047STIME=$(date +%s)
David Bainbridge0774b232019-08-02 06:37:19 +00001048bspin "Verify Helm values file: $NAME-values.yaml"
1049if [ ! -r "./$NAME-values.yaml" ]; then
Test Userba1e7e72019-07-10 22:27:54 +00001050 espin $NOT_VERIFIED
David Bainbridge0774b232019-08-02 06:37:19 +00001051 bspin - "Download Helm values file: $TYPE-values.yaml to $NAME-values.yaml $DOWNLOAD"
David K. Bainbridgea00736b2020-01-08 14:33:17 -08001052 ERR_OUT=$(mktemp)
1053 (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
1054 if [ $? -ne 0 ]; then
1055 espin - $THEX
1056 echo -e "${RED}${BOLD}${ERROR}ERROR: $NAME-values.yaml${NORMAL}${RED} - $(cat $ERR_OUT)${NORMAL}"
1057 echo "ERROR: $(cat $ERR_OUT)" >>$LOG
1058 rm -rf $ERR_OUT ./$NAME-values.yaml
1059 exit 1
1060 fi
1061 rm -rf $ERR_OUT
Test Userba1e7e72019-07-10 22:27:54 +00001062 espin - $VERIFIED
1063else
1064 espin $VERIFIED
1065fi
David Bainbridgee87067b2019-08-12 22:00:12 +00001066if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +00001067 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +00001068fi
Test Userba1e7e72019-07-10 22:27:54 +00001069
David Bainbridge99ac7a22019-08-31 02:26:43 +00001070STIME=$(date +%s)
1071bspin "Verify or download chart specific values files $DOWNLOAD"
1072VALUES_FILES="monkey-values.yaml"
David K. Bainbridgea00736b2020-01-08 14:33:17 -08001073ERR_OUT=$(mktemp)
David Bainbridge99ac7a22019-08-31 02:26:43 +00001074for i in $VALUES_FILES; do
1075 if [ ! -r ./$i ]; then
David K. Bainbridgea00736b2020-01-08 14:33:17 -08001076 (set -x; curl --fail -o ./$i -sSL https://raw.githubusercontent.com/ciena/kind-voltha/$VK_RELEASE/$i >>$LOG 2>$ERR_OUT) >>$LOG 2>&1
1077 if [ $? -ne 0 ]; then
1078 espin $THEX
1079 echo -e "${RED}${BOLD}${ERROR}ERROR: $i${NORMAL}${RED} - $(cat $ERR_OUT)${NORMAL}"
1080 echo "ERROR: $i - $(cat $ERR_OUT)" >>$LOG
1081 rm -rf $ERR_OUT ./$i
1082 exit 1
1083 fi
1084 rm -rf $ERR_OUT
David Bainbridge99ac7a22019-08-31 02:26:43 +00001085 fi
1086done
1087espin $VERIFIED
1088if [ "$WITH_TIMINGS" == "yes" ]; then
1089 printtime $(expr $(date +%s) - $STIME)
1090fi
1091
1092if [ "$WITH_CHAOS" == "yes" ]; then
1093 bspin "Verify or clone kube-monkey helm chart $DOWNLOAD"
1094 if [ -r ./kube-monkey ]; then
1095 espin $VERIFIED
1096 else
1097 espin $NOT_VERIFIED
1098 bspin - "GIT clone kube-monkey"
1099 (set -x; git clone https://github.com/asobti/kube-monkey kube-monkey >>$LOG 2>&1) >>$LOG 2>&1
1100 espin - $VERIFIED
1101 fi
1102fi
1103
Test Userba1e7e72019-07-10 22:27:54 +00001104if [ "$JUST_K8S" == "yes" ]; then
1105 echo "Environment deployed, not deploying VOLTHA artifacts as requested. Good bye."
1106 echo ""
1107 echo "Please issue the following commands in your terminal to ensure that you" | tee -a $LOG
1108 echo "are accessing the correct Kubernetes/Kind cluster as well as have the " | tee -a $LOG
1109 echo "tools required by VOLTHA in your command path. " | tee -a $LOG
1110 echo "" | tee -a $LOG
1111 echo -en $BOLD
1112 if [ $DEPLOY_K8S == "yes" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +00001113 echo "export KUBECONFIG=\"\$(./bin/kind get kubeconfig-path --name=\"voltha-$NAME\")\"" | tee -a $LOG
Test Userba1e7e72019-07-10 22:27:54 +00001114 fi
1115 echo "export PATH=$GOPATH/bin:\$PATH" | tee -a $LOG
1116 echo -en $NORMAL
1117 echo "" | tee -a $LOG
1118 echo "Thank you for choosing kind-voltha for you quick cluster needs." | tee -a $LOG
1119 exit 0
1120fi
1121
David Bainbridgee87067b2019-08-12 22:00:12 +00001122STIME=$(date +%s)
Test Userb5712372019-07-03 21:52:17 +00001123bspin "Verify ETCD Operator $OLD_KEY"
Test User7d866122019-07-09 17:52:35 +00001124if [ $(helm list --deployed --short --namespace voltha "^etcd-operator\$" | wc -l) -ne 1 ]; then
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001125 espin $NOT_VERIFIED
David Bainbridge90fd8e32019-08-21 23:32:47 +00001126 helm_install - voltha etcd-operator stable/etcd-operator latest "Install ETCD Operator"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001127else
1128 espin $VERIFIED
1129fi
Test User01ed0642019-07-03 20:17:06 +00001130EXPECT=$(test "$TYPE" == "minimal" && echo "1" || echo "3")
David Bainbridge4f1b5562019-08-19 04:46:52 +00001131wait_for_pods - "voltha" $EXPECT "includes" -1 "Waiting for ETCD Operator to start" "etcd-operator-.*"
David Bainbridgee87067b2019-08-12 22:00:12 +00001132if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +00001133 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +00001134fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001135
David Bainbridgee87067b2019-08-12 22:00:12 +00001136STIME=$(date +%s)
David Bainbridgeb270c202019-07-26 01:44:42 +00001137if [ $WITH_ONOS == "yes" ]; then
1138 bspin "Verify ONOS installed $BIRD"
1139 if [ $(helm list --deployed --short --namespace default "^onos\$" | wc -l) -ne 1 ]; then
1140 espin $NOT_VERIFIED
David K. Bainbridgeda33d652020-03-06 10:31:23 -08001141 EXTRA_HELM_FLAGS="$SET_TAG $EXTRA_HELM_FLAGS" helm_install - default onos $ONOS_CHART $ONOS_CHART_VERSION "Install ONOS"
David Bainbridgeb270c202019-07-26 01:44:42 +00001142 else
1143 espin $VERIFIED
1144 fi
David Bainbridge4f1b5562019-08-19 04:46:52 +00001145 wait_for_pods - "default" 1 "includes" -1 "Waiting for ONOS to start" "onos-.*"
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001146
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -08001147 if [ $WITH_PORT_FORWARDS == "yes" ]; then
1148 bspin - "Forward ONOS API port $FORWARD"
1149 kill_port_forward onos-ui
1150 port_forward default onos-ui $ONOS_API_PORT 8181
1151 espin - $VERIFIED
1152 bspin - "Forward ONOS SSH port $FORWARD"
1153 kill_port_forward onos-ssh
1154 port_forward default onos-ssh $ONOS_SSH_PORT 8101
1155 espin - $VERIFIED
1156 _ONOS_API_EP="127.0.0.1:$ONOS_API_PORT"
1157 else
1158 _ONOS_API_EP=$(get_service_ep default onos-ui)
1159 fi
David Bainbridged31d6122019-08-13 19:37:59 +00001160 bspin - "Verify or download ONOS configuration support files $DOWNLOAD"
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001161 ONOS_FILES="olt-onos-enableExtraneousRules.json onos-aaa.json \
David Bainbridge90fd8e32019-08-21 23:32:47 +00001162 onos-dhcpl2relay.json onos-kafka.json onos-sadis-sample.json"
David Bainbridged31d6122019-08-13 19:37:59 +00001163 (set -x; mkdir -p ./onos-files >>$LOG 2>&1) >>$LOG 2>&1
David K. Bainbridgea00736b2020-01-08 14:33:17 -08001164 ERR_OUT=$(mktemp)
David Bainbridge2b19e832019-08-16 02:40:53 +00001165 for i in $ONOS_FILES; do
David Bainbridged31d6122019-08-13 19:37:59 +00001166 if [ ! -r ./onos-files/$i ]; then
David K. Bainbridgea00736b2020-01-08 14:33:17 -08001167 (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
1168 if [ $? -ne 0 ]; then
1169 espin - $THEX
1170 echo -e "${RED}${BOLD}${ERROR}ERROR: $i${NORMAL}${RED} - $(cat $ERR_OUT)${NORMAL}"
1171 echo "ERROR: $(cat $ERR_OUT)" >>$LOG
1172 rm -rf $ERR_OUT ./onos-files/$i
1173 exit 1
1174 fi
1175 rm -rf $ERR_OUT
David Bainbridged31d6122019-08-13 19:37:59 +00001176 fi
1177 done
Test Userba1e7e72019-07-10 22:27:54 +00001178 espin - $VERIFIED
David Bainbridge27790d62019-08-13 22:43:19 +00001179
1180 if [ $INSTALL_ONOS_APPS == "yes" ]; then
1181 bspin - "Installing custom ONOS applications"
1182 if [ -x onos-files/onos-apps -a $(ls -1 onos-files/onos-apps/*.oar 2>/dev/null | wc -l) -gt 0 ]; then
1183 for OAR in $(ls -1 onos-files/onos-apps/*.oar); do
1184 sspin - "Installing custom ONOS applications - $OAR$CEOL"
David Bainbridge2b19e832019-08-16 02:40:53 +00001185 override_onos_app $OAR
David Bainbridge27790d62019-08-13 22:43:19 +00001186 done
1187 espin - "$VERIFIED Installing custom ONOS applications$CEOL"
1188 else
1189 espin - "$NOT_VERIFIED Installing custom ONOS applications - None Found"
1190 fi
1191 fi
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001192
Matteo Scandolo9a77a732020-01-09 14:24:12 -08001193 check_onos_app_active org.opencord.kafka
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001194 push_onos_config "file" "Push ONOS Kafka Configuration" "network/configuration/apps/org.opencord.kafka" "onos-files/onos-kafka.json"
Matteo Scandolo9a77a732020-01-09 14:24:12 -08001195 check_onos_app_active org.opencord.dhcpl2relay
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001196 push_onos_config "file" "Push ONOS DHCP L2 Relay Configuration" "network/configuration/apps/org.opencord.dhcpl2relay" "onos-files/onos-dhcpl2relay.json"
Matteo Scandolo9a77a732020-01-09 14:24:12 -08001197 check_onos_app_active org.opencord.olt
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001198 # FIXME use WITH_DHCP and WITH_EAPOL flags to configre OLT App
Hardik Windlassa7501fb2020-02-17 14:28:20 +00001199 # Default value for "enableEapol" is true in OLT App
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001200 if [ $WITH_EAPOL == "yes" ]; then
1201 push_onos_config "json" "Enable VOLTHA ONOS EAPOL provisioning" "configuration/org.opencord.olt.impl.OltFlowService" '{"enableEapol":true}'
Hardik Windlassa7501fb2020-02-17 14:28:20 +00001202 elif [ $WITH_EAPOL == "no" ]; then
1203 push_onos_config "json" "Disable VOLTHA ONOS EAPOL provisioning" "configuration/org.opencord.olt.impl.OltFlowService" '{"enableEapol":false}'
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001204 fi
Hardik Windlassa7501fb2020-02-17 14:28:20 +00001205 # Default value for "enableDhcpOnProvisioning" is false and for "enableDhcpV4" is true in OLT App
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001206 if [ $WITH_DHCP == "yes" ]; then
1207 push_onos_config "json" "Enable VOLTHA ONOS DHCP provisioning" "configuration/org.opencord.olt.impl.OltFlowService" '{"enableDhcpOnProvisioning":true,"enableDhcpV4":true}'
Hardik Windlassa7501fb2020-02-17 14:28:20 +00001208 elif [ $WITH_DHCP == "no" ]; then
1209 push_onos_config "json" "Disable VOLTHA ONOS DHCP provisioning" "configuration/org.opencord.olt.impl.OltFlowService" '{"enableDhcpOnProvisioning":false,"enableDhcpV4":false}'
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001210 fi
Hardik Windlassa7501fb2020-02-17 14:28:20 +00001211 # Default value for "enableIgmpOnProvisioning" is false in OLT App
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001212 if [ $WITH_IGMP == "yes" ]; then
1213 push_onos_config "json" "Enable VOLTHA ONOS IGMP provisioning" "configuration/org.opencord.olt.impl.OltFlowService" '{"enableIgmpOnProvisioning":true}'
Hardik Windlassa7501fb2020-02-17 14:28:20 +00001214 elif [ $WITH_IGMP == "no" ]; then
1215 push_onos_config "json" "Disable VOLTHA ONOS IGMP provisioning" "configuration/org.opencord.olt.impl.OltFlowService" '{"enableIgmpOnProvisioning":false}'
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001216 fi
David K. Bainbridge484d80c2020-03-05 21:44:34 -08001217 if [ $ENABLE_ONOS_EXTRANEOUS_RULES == "yes" ]; then
1218 push_onos_config "file" "Enabling extraneous rules for ONOS" "configuration/org.onosproject.net.flow.impl.FlowRuleManager" "onos-files/olt-onos-enableExtraneousRules.json"
1219 fi
David Bainbridge2b19e832019-08-16 02:40:53 +00001220 if [ -f onos-files/onos-sadis.json ]; then
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001221 push_onos_config "file" "[optional] Push ONOS SADIS Configuration" "network/configuration/apps/org.opencord.sadis" "onos-files/onos-sadis.json"
David Bainbridge2b19e832019-08-16 02:40:53 +00001222 elif [ "$CONFIG_SADIS" == "yes" ]; then
David Bainbridge90fd8e32019-08-21 23:32:47 +00001223 SADIS_CFG=onos-files/onos-sadis-sample.json
Matteo Scandolo9a77a732020-01-09 14:24:12 -08001224 check_onos_app_active org.opencord.sadis
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001225 push_onos_config "file" "[optional] Push ONOS SADIS Configuration" "network/configuration/apps/org.opencord.sadis" "$SADIS_CFG"
David Bainbridge2b19e832019-08-16 02:40:53 +00001226 fi
Test Userba1e7e72019-07-10 22:27:54 +00001227fi
David Bainbridgee87067b2019-08-12 22:00:12 +00001228if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +00001229 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +00001230fi
Test Userba1e7e72019-07-10 22:27:54 +00001231
David Bainbridgee87067b2019-08-12 22:00:12 +00001232STIME=$(date +%s)
Test Userb5712372019-07-03 21:52:17 +00001233bspin "Verify VOLTHA installed $HIGH_VOLTAGE"
Test User7d866122019-07-09 17:52:35 +00001234if [ $(helm list --deployed --short --namespace voltha "^voltha\$" | wc -l) -ne 1 ]; then
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001235 espin $NOT_VERIFIED
David Bainbridge70c0ea82019-11-14 23:25:26 +00001236 if [ "$ONLY_ONE" == "yes" ]; then
1237 EXTRA_HELM_INSTALL_ARGS="--set therecanbeonlyone=true"=
1238 fi
David Bainbridge90fd8e32019-08-21 23:32:47 +00001239 helm_install - voltha voltha $VOLTHA_CHART $VOLTHA_CHART_VERSION "Install VOLTHA Core"
David Bainbridge70c0ea82019-11-14 23:25:26 +00001240 EXTRA_HELM_INSTALL_ARGS=
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001241else
1242 espin $VERIFIED
1243fi
Test Userba1e7e72019-07-10 22:27:54 +00001244
David Bainbridge90fd8e32019-08-21 23:32:47 +00001245VOLTHA="voltha-ofagent-.* \
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001246 ro-core.* \
1247 rw-core.* \
1248 voltha-api-server-.* \
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001249 voltha-etcd-cluster-.* \
1250 voltha-kafka-.* \
1251 voltha-zookeeper-.*"
David Bainbridge70c0ea82019-11-14 23:25:26 +00001252if [ "$ONLY_ONE" == "yes" ]; then
David Bainbridge1ba64f12019-12-18 00:40:13 +00001253 EXPECT=$(test "$TYPE" == "minimal" && echo "5" || echo "7")
David Bainbridge70c0ea82019-11-14 23:25:26 +00001254else
David Bainbridge1ba64f12019-12-18 00:40:13 +00001255 EXPECT=$(test "$TYPE" == "minimal" && echo "8" || echo "10")
David Bainbridge70c0ea82019-11-14 23:25:26 +00001256fi
David Bainbridge4f1b5562019-08-19 04:46:52 +00001257wait_for_pods - "voltha" $EXPECT "includes" -1 "Waiting for VOLTHA Core to start" $VOLTHA
David Bainbridgee87067b2019-08-12 22:00:12 +00001258if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +00001259 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +00001260fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001261
David Bainbridge46505fb2019-10-01 21:13:20 +00001262if [ "$WITH_ADAPTERS" == "yes" ]; then
1263 STIME=$(date +%s)
1264 EXPECT=0
1265 echo -e "Verify Adapters $PLUG"
1266 if [ "$WITH_SIM_ADAPTERS" == "yes" ]; then
1267 bspin - "Verify Simulated Adapters installed"
1268 if [ $(helm list --deployed --short --namespace voltha "^sim\$" | wc -l) -ne 1 ]; then
1269 espin - $NOT_VERIFIED
1270 helm_install - voltha sim $VOLTHA_ADAPTER_SIM_CHART $VOLTHA_ADAPTER_SIM_CHART_VERSION "Install Simulated Adapters"
1271 else
1272 espin - $VERIFIED
1273 fi
1274 EXPECT=$(expr $EXPECT + 2)
1275 fi
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001276
David Bainbridge46505fb2019-10-01 21:13:20 +00001277 if [ "$WITH_OPEN_ADAPTERS" == "yes" ]; then
1278 bspin - "Verify OpenOLT Adapter installed"
1279 if [ $(helm list --deployed --short --namespace voltha "^open-olt\$" | wc -l) -ne 1 ]; then
1280 espin - $NOT_VERIFIED
1281 helm_install - voltha open-olt $VOLTHA_ADAPTER_OPEN_OLT_CHART $VOLTHA_ADAPTER_OPEN_OLT_CHART_VERSION "Install OpenOLT Adapter"
1282 else
1283 espin - $VERIFIED
1284 fi
1285 bspin - "Verify OpenONU Adapter installed"
1286 if [ $(helm list --deployed --short --namespace voltha "^open-onu\$" | wc -l) -ne 1 ]; then
1287 espin - $NOT_VERIFIED
1288 helm_install - voltha open-onu $VOLTHA_ADAPTER_OPEN_ONU_CHART $VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION "Install OpenONU Adapter"
1289 else
1290 espin - $VERIFIED
1291 fi
1292 EXPECT=$(expr $EXPECT + 2)
1293 fi
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001294
David Bainbridge46505fb2019-10-01 21:13:20 +00001295 ADAPTERS="adapter-.*"
1296 wait_for_pods - "voltha" $EXPECT "includes" -1 "Waiting for adapters to start" $ADAPTERS
1297 if [ "$WITH_TIMINGS" == "yes" ]; then
1298 printtime $(expr $(date +%s) - $STIME)
1299 fi
David Bainbridgee87067b2019-08-12 22:00:12 +00001300fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001301
Test User7d866122019-07-09 17:52:35 +00001302if [ $WITH_BBSIM == "yes" ]; then
David Bainbridgee87067b2019-08-12 22:00:12 +00001303 STIME=$(date +%s)
Test User7d866122019-07-09 17:52:35 +00001304 echo -e "Verify BBSIM $PLUG"
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001305 bspin - "Verify BBSIM Installed"
David K. Bainbridge43422402020-03-06 07:41:22 -08001306 for instance in $(seq 0 $(($NUM_OF_BBSIM-1))); do
1307 if [ $instance -eq 0 ]; then
1308 instance_num=""
1309 else
1310 instance_num=$instance
1311 fi
1312 if [ $(helm list --deployed --short --namespace voltha "^bbsim${instance_num}\$" | wc -l) -ne 1 ]; then
1313 espin - $NOT_VERIFIED
1314 helm_install - voltha bbsim${instance_num} $VOLTHA_BBSIM_CHART $VOLTHA_BBSIM_CHART_VERSION "Install BBSIM${instance_num}"
1315 else
1316 espin - $VERIFIED
1317 fi
1318 done
uottrembb16d3982020-02-28 08:34:36 +01001319 wait_for_pods - "voltha" $NUM_OF_BBSIM "includes" -1 "Waiting for BBSIM to start" "bbsim*"
David Bainbridgee87067b2019-08-12 22:00:12 +00001320 if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +00001321 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +00001322 fi
Test User7d866122019-07-09 17:52:35 +00001323fi
1324
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001325if [ $WITH_RADIUS == "yes" ]; then
David Bainbridgee87067b2019-08-12 22:00:12 +00001326 STIME=$(date +%s)
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001327 echo -e "Verify RADIUS $LOCK"
1328 bspin - "Verify RADIUS Installed"
1329 if [ $(helm list --deployed --short --namespace voltha "^radius\$" | wc -l) -ne 1 ]; then
1330 espin - $NOT_VERIFIED
David Bainbridge90fd8e32019-08-21 23:32:47 +00001331 helm_install - voltha radius onf/freeradius latest "Install RADIUS"
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001332 else
1333 espin - $VERIFIED
1334 fi
David Bainbridge4f1b5562019-08-19 04:46:52 +00001335 wait_for_pods - "voltha" 1 "includes" -1 "Waiting for RADIUS to start" "radius-.*"
David Bainbridgee87067b2019-08-12 22:00:12 +00001336 if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +00001337 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +00001338 fi
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001339fi
1340
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -08001341if [ $WITH_PORT_FORWARDS == "yes" ]; then
1342 STIME=$(date +%s)
1343 bspin - "Forward VOLTHA API port $FORWARD"
1344 kill_port_forward voltha-api
1345 port_forward voltha voltha-api $VOLTHA_API_PORT 55555
1346 espin - $VERIFIED
1347 bspin - "Forward VOLTHA ETCD port $FORWARD"
1348 kill_port_forward voltha-etcd-cluster-client
1349 port_forward voltha voltha-etcd-cluster-client $VOLTHA_ETCD_PORT 2379
1350 espin - $VERIFIED
1351 bspin - "Forward VOLTHA Kafka port $FORWARD"
1352 kill_port_forward voltha-kafka
1353 port_forward voltha voltha-kafka $VOLTHA_KAFKA_PORT 9092
1354 espin - $VERIFIED
1355 if [ "$WITH_TIMINGS" == "yes" ]; then
1356 printtime $(expr $(date +%s) - $STIME)
1357 fi
David Bainbridgee87067b2019-08-12 22:00:12 +00001358fi
Test User3d7ad8e2019-07-03 06:15:44 +00001359
David Bainbridgeb270c202019-07-26 01:44:42 +00001360if [ $WITH_ONOS == "yes" -a $WITH_RADIUS == "yes" ]; then
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001361 bspin "Configure ONOS RADIUS Connection $GEAR"
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -08001362 (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://$_ONOS_API_EP/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 +00001363 espin $VERIFIED
1364fi
1365
David Bainbridge99ac7a22019-08-31 02:26:43 +00001366if [ "$WITH_CHAOS" == "yes" ]; then
1367 STIME=$(date +%s)
1368 echo -e "Verify kube-monkey $LOCK"
1369 bspin - "Verify kube-monkey Installed"
1370 if [ $(helm list --deployed --short --namespace kube-monkey "^monkey\$" | wc -l) -ne 1 ]; then
1371 espin - $NOT_VERIFIED
1372 helm_install - kube-monkey monkey ./kube-monkey/helm/kubemonkey latest "Install Chaos Monkey"
1373 else
1374 espin - $VERIFIED
1375 fi
1376 wait_for_pods - "kube-monkey" 1 "includes" -1 "Waiting for Chaos to start" "monkey-.*"
1377 if [ "$WITH_TIMINGS" == "yes" ]; then
1378 printtime $(expr $(date +%s) - $STIME)
1379 fi
1380fi
1381
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001382bspin "Create voltctl configuration file"
Test User3d7ad8e2019-07-03 06:15:44 +00001383(set -x; mkdir -p $HOME/.volt >>$LOG 2>&1) >>$LOG 2>&1
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -08001384if [ $WITH_PORT_FORWARDS == "yes" ]; then
1385 (set -x; voltctl -a v3 -k localhost:$VOLTHA_KAFKA_PORT -s localhost:$VOLTHA_API_PORT config > $HOME/.volt/config-$NAME 2>>$LOG) >>$LOG 2>&1
1386else
1387 (set -x; voltctl -a v3 -k $(get_service_ep voltha voltha-kafka) -s $(get_service_ep voltha voltha-api) config > $HOME/.volt/config-$NAME 2>>$LOG) >>$LOG 2>&1
1388fi
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001389espin $VERIFIED
Test User08ebbd92019-07-03 17:15:39 +00001390
David Bainbridge0774b232019-08-02 06:37:19 +00001391if [ ! -f "$NAME-env.sh" ]; then
1392 touch $NAME-env.sh
David Bainbridgeb07fdf72019-07-29 22:51:40 +00001393fi
1394
David Bainbridge596f30d2019-07-30 17:07:59 +00001395for O in $ALL_OPTIONS; do
1396 VAL=$(eval echo \$$O)
David Bainbridge0774b232019-08-02 06:37:19 +00001397 if [ ! -z "$VAL" -a $(grep -c "^export $O=" $NAME-env.sh) -eq 0 ]; then
1398 echo "export $O=\"$(eval echo \$$O)\"" >> $NAME-env.sh
David Bainbridgeb07fdf72019-07-29 22:51:40 +00001399 fi
1400done
1401
David Bainbridge0774b232019-08-02 06:37:19 +00001402if [ $DEPLOY_K8S == "yes" -a $(grep -c "^export KUBECONFIG=" $NAME-env.sh) -eq 0 ]; then
1403 echo "export KUBECONFIG=\"$(./bin/kind get kubeconfig-path --name=voltha-$NAME)\"" >> $NAME-env.sh
David Bainbridgeb07fdf72019-07-29 22:51:40 +00001404fi
1405
David Bainbridge0774b232019-08-02 06:37:19 +00001406if [ $(grep -c "^export VOLTCONFIG=" $NAME-env.sh) -eq 0 ]; then
1407 echo "export VOLTCONFIG=\"$HOME/.volt/config-$NAME\"" >> $NAME-env.sh
David Bainbridgeb07fdf72019-07-29 22:51:40 +00001408fi
1409
David Bainbridge0774b232019-08-02 06:37:19 +00001410if [ $(grep -c "^export PATH=" $NAME-env.sh) -eq 0 ]; then
1411 echo "export PATH=\"$GOPATH/bin:\$PATH\"" >> $NAME-env.sh
David Bainbridgeb07fdf72019-07-29 22:51:40 +00001412fi
1413
Test User7d866122019-07-09 17:52:35 +00001414echo ""
Test User08ebbd92019-07-03 17:15:39 +00001415echo "Please issue the following commands in your terminal to ensure that you" | tee -a $LOG
1416echo "are accessing the correct Kubernetes/Kind cluster as well as have the " | tee -a $LOG
1417echo "tools required by VOLTHA in your command path. " | tee -a $LOG
1418echo "" | tee -a $LOG
Test User7d866122019-07-09 17:52:35 +00001419echo -en $BOLD
Test Userba1e7e72019-07-10 22:27:54 +00001420if [ $DEPLOY_K8S == "yes" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +00001421 echo "export KUBECONFIG=\"\$(./bin/kind get kubeconfig-path --name=\"voltha-$NAME\")\"" | tee -a $LOG
Test Userba1e7e72019-07-10 22:27:54 +00001422fi
David Bainbridge0774b232019-08-02 06:37:19 +00001423echo "export VOLTCONFIG=\"$HOME/.volt/config-$NAME\"" | tee -a $LOG
Test Userba1e7e72019-07-10 22:27:54 +00001424echo "export PATH=$GOPATH/bin:\$PATH" | tee -a $LOG
Test User7d866122019-07-09 17:52:35 +00001425echo -en $NORMAL
Test User08ebbd92019-07-03 17:15:39 +00001426echo "" | tee -a $LOG
1427echo "Thank you for choosing kind-voltha for you quick cluster needs." | tee -a $LOG
1428
David Bainbridge712afb82019-08-14 19:55:58 +00001429if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridgef858a022019-08-14 21:25:11 +00001430 echo -e "$CLOCK ${BOLD}TOTAL: $(duration $(expr $(date +%s) - $TOTAL_START_TIME))${NORMAL}"
David Bainbridge712afb82019-08-14 19:55:58 +00001431fi