blob: 17175104f8cc1f67b3cd93c0569af7bd2748659e [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 Bainbridged049a612020-03-16 17:22:54 -070015set -f
David Bainbridge712afb82019-08-14 19:55:58 +000016TOTAL_START_TIME=$(date +%s)
David K. Bainbridgeb7285432019-07-02 22:05:24 -070017
David Bainbridge38dc1e82019-08-12 15:18:45 +000018FANCY=${FANCY:-1}
19if [ "$TERM X" == " X" ]; then
20 FANCY=0
21fi
22
David K. Bainbridgeb7285432019-07-02 22:05:24 -070023# trap ctrl-c and call ctrl_c()
24trap ctrl_c INT
25
26function ctrl_c() {
David Bainbridge38dc1e82019-08-12 15:18:45 +000027 echo -en $CNORM
David K. Bainbridgeb7285432019-07-02 22:05:24 -070028 echo ""
29 echo "ctrl-c trapped"
David Bainbridgec6a6eb62019-10-18 22:50:07 +000030 echo "Thank you for trying 'voltha up'"
David K. Bainbridgeb7285432019-07-02 22:05:24 -070031 exit
32}
33
David K. Bainbridgeebf38d92020-02-10 10:46:31 -080034VOLTCTL_VERSION=${VOLTCTL_VERSION:-latest}
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -080035KIND_VERSION=${KIND_VERSION:-v0.5.1}
David K. Bainbridgeb3a99372020-01-08 14:39:06 -080036VK_RELEASE=${VK_RELEASE:-master}
Test User08ebbd92019-07-03 17:15:39 +000037
David Bainbridge38dc1e82019-08-12 15:18:45 +000038BLACK=
39RED=
40GREEN=
41YELLOW=
42BLUE=
43MAGENTA=
44CYAN=
45WHITE=
46BOLD=
47NORMAL=
48ERROR=
49CEOL=
50CNORM=
51CIVIS=
52if [ $FANCY -eq 1 ]; then
53 BLACK=$(tput setaf 0)
54 RED=$(tput setaf 1)
55 GREEN=$(tput setaf 2)
56 YELLOW=$(tput setaf 3)
57 BLUE=$(tput setaf 4)
58 MAGENTA=$(tput setaf 5)
59 CYAN=$(tput setaf 6)
60 WHITE=$(tput setaf 7)
61 BOLD=$(tput bold)
62 NORMAL=$(tput sgr0)
63 ERROR="\xe2\x9c\x97\x20"
64 CEOL=$(tput el)
65 CNORM=$(tput cnorm)
66 CIVIS=$(tput civis)
67fi
Test User7d866122019-07-09 17:52:35 +000068
Test User3d7ad8e2019-07-03 06:15:44 +000069TYPE=${TYPE:-minimal}
David Bainbridge0774b232019-08-02 06:37:19 +000070NAME=${NAME:-$TYPE}
David K. Bainbridge484d80c2020-03-05 21:44:34 -080071
72ENABLE_ONOS_EXTRANEOUS_RULES=${ENABLE_ONOS_EXTRANEOUS_RULES:-no}
David Bainbridgee87067b2019-08-12 22:00:12 +000073WITH_TIMINGS=${WITH_TIMINGS:-no}
Test User7d866122019-07-09 17:52:35 +000074WITH_BBSIM=${WITH_BBSIM:-no}
David Bainbridge5b7b96b2019-07-25 20:29:13 +000075WITH_RADIUS=${WITH_RADIUS:-no}
Matteo Scandolo78dfee02020-02-13 16:18:03 -080076WITH_EAPOL=${WITH_EAPOL:-yes}
77WITH_DHCP=${WITH_DHCP:-yes}
78WITH_IGMP=${WITH_IGMP:-no}
David Bainbridgeb270c202019-07-26 01:44:42 +000079WITH_ONOS=${WITH_ONOS:-yes}
David Bainbridge99ac7a22019-08-31 02:26:43 +000080WITH_CHAOS=${WITH_CHAOS:-no}
David Bainbridge46505fb2019-10-01 21:13:20 +000081WITH_ADAPTERS=${WITH_ADAPTERS:-yes}
David K. Bainbridgeda33d652020-03-06 10:31:23 -080082WITH_SIM_ADAPTERS=${WITH_SIM_ADAPTERS:-no}
David Bainbridge46505fb2019-10-01 21:13:20 +000083WITH_OPEN_ADAPTERS=${WITH_OPEN_ADAPTERS:-yes}
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -080084WITH_PORT_FORWARDS=${WITH_PORT_FORWARDS:-yes}
David Bainbridge05cd8822019-11-19 17:43:53 +000085ONLY_ONE=${ONLY_ONE:-yes}
David K. Bainbridgeb859e912020-03-13 14:07:52 -070086CONFIG_SADIS=${CONFIG_SADIS:-no} # yes | no | file | bbsim | URL
87SADIS_SUBSCRIBERS=${SADIS_SUBSCRIBERS:-http://bbsim.voltha.svc:50074/v2/subscribers/%s}
88SADIS_BANDWIDTH_PROFILES=${SADIS_BANDWIDTH_PROFILES:-http://bbsim.voltha.svc:50074/v2/bandwidthprofiles/%s}
Hardik Windlassb3147602020-03-09 16:59:15 +053089SADIS_CFG=${SADIS_CFG:-onos-files/onos-sadis-sample.json}
David Bainbridge27790d62019-08-13 22:43:19 +000090INSTALL_ONOS_APPS=${INSTALL_ONOS_APPS:-no}
Test Userba1e7e72019-07-10 22:27:54 +000091JUST_K8S=${JUST_K8S:-no}
92DEPLOY_K8S=${DEPLOY_K8S:-yes}
David K. Bainbridge0e89cb92019-07-17 11:30:10 -070093INSTALL_KUBECTL=${INSTALL_KUBECTL:-yes}
94INSTALL_HELM=${INSTALL_HELM:-yes}
David Bainbridge46505fb2019-10-01 21:13:20 +000095UPDATE_HELM_REPOS=${UPDATE_HELM_REPOS:-yes}
Matteo Scandolofab98622020-01-28 15:17:20 -080096WAIT_ON_DOWN=${WAIT_ON_DOWN:-yes}
David Bainbridge52e6e9d2020-03-23 13:48:27 -070097WAIT_TIMEOUT=${WAIT_TIMEOUT:-30m}
98VOLTHA_DOWN_ON_TIMEOUT=${VOLTHA_DOWN_ON_TIMEOUT:-no}
David Bainbridge5b7b96b2019-07-25 20:29:13 +000099VOLTHA_LOG_LEVEL=${VOLTHA_LOG_LEVEL:-WARN}
David Bainbridge90fd8e32019-08-21 23:32:47 +0000100VOLTHA_CHART=${VOLTHA_CHART:-onf/voltha}
101VOLTHA_CHART_VERSION=${VOLTHA_CHART_VERSION:-latest}
102VOLTHA_BBSIM_CHART=${VOLTHA_BBSIM_CHART:-onf/bbsim}
Matteo Scandolodcd29f52019-10-07 15:42:42 -0700103VOLTHA_BBSIM_CHART_VERSION=${VOLTHA_BBSIM_CHART_VERSION:-latest}
David Bainbridgee10f6d52019-07-25 00:28:13 +0000104VOLTHA_ADAPTER_SIM_CHART=${VOLTHA_ADAPTER_SIM_CHART:-onf/voltha-adapter-simulated}
David Bainbridge90fd8e32019-08-21 23:32:47 +0000105VOLTHA_ADAPTER_SIM_CHART_VERSION=${VOLTHA_ADAPTER_SIM_CHART_VERSION:-latest}
David Bainbridgee10f6d52019-07-25 00:28:13 +0000106VOLTHA_ADAPTER_OPEN_OLT_CHART=${VOLTHA_ADAPTER_OPEN_OLT_CHART:-onf/voltha-adapter-openolt}
David Bainbridge90fd8e32019-08-21 23:32:47 +0000107VOLTHA_ADAPTER_OPEN_OLT_CHART_VERSION=${VOLTHA_ADAPTER_OPEN_OLT_CHART_VERSION:-latest}
David Bainbridgee10f6d52019-07-25 00:28:13 +0000108VOLTHA_ADAPTER_OPEN_ONU_CHART=${VOLTHA_ADAPTER_OPEN_ONU_CHART:-onf/voltha-adapter-openonu}
David Bainbridge90fd8e32019-08-21 23:32:47 +0000109VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION=${VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION:-latest}
David K. Bainbridgeda33d652020-03-06 10:31:23 -0800110ONOS_CHART=${ONOS_CHART:-onf/onos}
Andrea Campanella21323292019-12-18 11:44:19 -0800111ONOS_CHART_VERSION=${ONOS_CHART_VERSION:-latest}
David Bainbridge2eaf2cf2020-03-18 12:54:08 -0700112EXTRA_HELM_INSTALL_ARGS=${EXTRA_HELM_INSTALL_ARGS:-}
113INTERNAL_EXTRA_HELM_INSTALL_ARGS=
uottrembb16d3982020-02-28 08:34:36 +0100114NUM_OF_BBSIM=${NUM_OF_BBSIM:-1}
115MAX_NUM_OF_BBSIM=10
Test Userba1e7e72019-07-10 22:27:54 +0000116
117HAVE_GO=$(which go >/dev/null 2>&1 && echo "yes" || echo "no")
118HOSTOS=$(uname -s | tr "[:upper:]" "[:lower:"])
119HOSTARCH=$(uname -m | tr "[:upper:]" "[:lower:"])
120if [ $HOSTARCH == "x86_64" ]; then
121 HOSTARCH="amd64"
122fi
Test User7d866122019-07-09 17:52:35 +0000123
uottrembb16d3982020-02-28 08:34:36 +0100124# check number (range) of bbsim, max bbsim must not exceed 10 instances!
125# note: instances will be numbered from 0 to 9
126if [ "$1" == "up" ]; then
David K. Bainbridge43422402020-03-06 07:41:22 -0800127 if [ "$NUM_OF_BBSIM" -lt 1 ]; then
128 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} Invalid setting of BBSIM instances. NUM_OF_BBSIM is less than 1${NORMAL}"
129 exit 1
130 fi
131 if [ "$NUM_OF_BBSIM" -gt $MAX_NUM_OF_BBSIM ]; then
132 >&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}"
133 exit 1
134 fi
uottrembb16d3982020-02-28 08:34:36 +0100135fi
Test User7d866122019-07-09 17:52:35 +0000136# Verify TYPE setting
137if [ $(echo ":minimal:full:" | grep -ic ":$TYPE:") -eq 0 ]; then
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700138 >&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 +0000139 exit 1
140fi
141
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700142function parseDuration() {
143 local DUR=$1
144 local RESULT=0
David Bainbridge6cdb6462020-03-25 10:24:38 -0700145 local TERMS=$(echo $DUR | sed -Ee 's/([sSmMhHdD])/\1 /g' -e 's/,$//g')
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700146 for TERM in $TERMS; do
David Bainbridge6cdb6462020-03-25 10:24:38 -0700147 local VALUE=$(echo $TERM | sed -Ee 's/([0-9]+)[sSmMhHdD]/\1/')
148 local UNIT=$(echo $TERM | sed -Ee 's/[0-9]+([sSmMhHdD])/\1/')
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700149 case $UNIT in
150 s|S)
151 RESULT=$(($RESULT + $VALUE)) ;;
152 m|M)
153 RESULT=$(($RESULT + ($VALUE * 60))) ;;
154 h|H)
155 RESULT=$(($RESULT + ($VALUE * 3600))) ;;
156 d|D)
157 RESULT=$(($RESULT + ($VALUE * 86400))) ;;
158 *) ;;
159 esac
160 done
161 echo $RESULT
162}
163
164function doTimeout() {
165 local MSG=$1
166 2>&1 echo -e "\n${RED}${BOLD}${ERROR}TIMEOUT:${NORMAL}${RED} Operation timed out after '$WAIT_TIMEOUT': $MSG"
167 exit 125
168}
169
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -0800170function get_service_ep() {
171 local NS=$1
172 local NAME=$2
173 kubectl -n $NS get service $NAME -o json | jq -r '.spec.clusterIP + ":" + (.spec.ports[0].port|tostring)'
174}
175
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000176# Used to verify configuration values are set to "yes" or "no" value or convert
177# equivalents to "yes" or "no"
178function verify_yes_no() {
179 local VAR=$1
180 local VAL=$(eval echo \$$VAR)
181 if [ $(echo ":y:yes:true:n:no:false:1:0:" | grep -ic ":$VAL:") -eq 0 ]; then
182 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} Invalid '$VAR' value of '$VAL'. Should be 'yes' or 'no'${NORMAL}"
183 echo "INVALID"
184 return 1
185 fi
186 if [ $(echo ":y:yes:true:1:" | grep -ic ":$VAL:") -eq 1 ]; then
187 echo "yes"
188 else
189 echo "no"
190 fi
191 return 0
192}
Test User7d866122019-07-09 17:52:35 +0000193
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000194ALL_YES_NO="\
David K. Bainbridge484d80c2020-03-05 21:44:34 -0800195 ENABLE_ONOS_EXTRANEOUS_RULES \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000196 WITH_TIMINGS \
197 WITH_BBSIM \
198 WITH_RADIUS \
Matteo Scandolo78dfee02020-02-13 16:18:03 -0800199 WITH_EAPOL \
200 WITH_DHCP \
201 WITH_IGMP \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000202 WITH_ONOS \
David Bainbridge99ac7a22019-08-31 02:26:43 +0000203 WITH_CHAOS \
David Bainbridge46505fb2019-10-01 21:13:20 +0000204 WITH_ADAPTERS \
205 WITH_SIM_ADAPTERS \
206 WITH_OPEN_ADAPTERS \
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -0800207 WITH_PORT_FORWARDS \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000208 JUST_K8S \
209 DEPLOY_K8S \
210 INSTALL_ONOS_APPS \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000211 INSTALL_KUBECTL \
212 INSTALL_HELM \
David Bainbridge46505fb2019-10-01 21:13:20 +0000213 UPDATE_HELM_REPOS \
David Bainbridge4f1b5562019-08-19 04:46:52 +0000214 WAIT_ON_DOWN \
David Bainbridge70c0ea82019-11-14 23:25:26 +0000215 ONLY_ONE \
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700216 VOLTHA_DOWN_ON_TIMEOUT \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000217 "
David Bainbridge5b7b96b2019-07-25 20:29:13 +0000218
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000219ALL_OPTIONS="\
220 NAME \
221 TYPE \
222 $ALL_YES_NO \
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700223 WAIT_TIMEOUT \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000224 VOLTHA_LOG_LEVEL \
225 VOLTHA_CHART \
David Bainbridge90fd8e32019-08-21 23:32:47 +0000226 VOLTHA_CHART_VERSION \
227 VOLTHA_BBSIM_CHART \
228 VOLTHA_BBSIM_CHART_VERSION \
uottrembd5a20572020-03-06 09:15:01 +0100229 NUM_OF_BBSIM \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000230 VOLTHA_ADAPTER_SIM_CHART \
David Bainbridge90fd8e32019-08-21 23:32:47 +0000231 VOLTHA_ADAPTER_SIM_CHART_VERSION \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000232 VOLTHA_ADAPTER_OPEN_OLT_CHART \
David Bainbridge90fd8e32019-08-21 23:32:47 +0000233 VOLTHA_ADAPTER_OPEN_OLT_CHART_VERSION \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000234 VOLTHA_ADAPTER_OPEN_ONU_CHART \
David Bainbridge90fd8e32019-08-21 23:32:47 +0000235 VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION \
David K. Bainbridgeda33d652020-03-06 10:31:23 -0800236 ONOS_CHART \
Andrea Campanella21323292019-12-18 11:44:19 -0800237 ONOS_CHART_VERSION \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000238 ONOS_API_PORT \
239 ONOS_SSH_PORT \
David K. Bainbridgeb859e912020-03-13 14:07:52 -0700240 CONFIG_SADIS \
Hardik Windlassb3147602020-03-09 16:59:15 +0530241 SADIS_CFG \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000242 VOLTHA_API_PORT \
243 VOLTHA_SSH_PORT \
244 VOLTHA_ETCD_PORT \
David K. Bainbridge00ecd382020-02-28 12:31:58 -0800245 VOLTHA_KAFKA_PORT \
David K. Bainbridge8f7f30b2020-01-08 13:06:16 -0800246 VK_RELEASE \
247 KIND_VERSION \
248 VOLTCTL_VERSION \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000249 "
David Bainbridge01294952019-07-30 19:33:45 +0000250
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000251# Iterate over yes/no configuration options and validate
252for VAR in $ALL_YES_NO; do
253 eval $VAR=$(verify_yes_no $VAR)
254 if [ "$(eval echo \$$VAR)" == "INVALID" ]; then
255 exit 1;
256 fi
257done
David Bainbridgeb270c202019-07-26 01:44:42 +0000258
David Bainbridge15f6f232020-03-30 09:15:43 -0700259# Special case for CONFIG_SADIS
260if [ $(echo ":y:yes:true:1:" | grep -ic ":$CONFIG_SADIS:") -eq 1 ]; then
261 CONFIG_SADIS="yes"
262fi
263if [ $(echo ":n:no:false:0:" | grep -ic ":$CONFIG_SADIS:") -eq 1 ]; then
264 CONFIG_SADIS="no"
265fi
266
David K. Bainbridgeda33d652020-03-06 10:31:23 -0800267# Check for prerequiste tools
David K. Bainbridge726ff6a2020-03-06 11:09:50 -0800268TOOLS="curl sed jq"
David K. Bainbridgeda33d652020-03-06 10:31:23 -0800269if [ $DEPLOY_K8S == "yes" ]; then
270 TOOLS+=" docker"
271fi
272NOT_FOUND=""
273for T in $TOOLS; do
274 if [ -z "$(which $T)" ]; then
275 NOT_FOUND+=" $T"
276 fi
277done
278
279if [ ! -z "$NOT_FOUND" ]; then
280 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} The following required tools where not found, please install them:$NOT_FOUND"
281 exit 1
282fi
283
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700284TIMEOUT_SECONDS=$(parseDuration $WAIT_TIMEOUT)
285
David Bainbridge0774b232019-08-02 06:37:19 +0000286mkdir -p .voltha
287touch .voltha/ports
288HAVE=$(grep $NAME .voltha/ports)
289if [ "$HAVE X" == " X" ]; then
290 # Find free port prefix
291 START=81
292 while true; do
293 if [ $(grep -c $START .voltha/ports) -eq 0 ]; then
294 break
295 fi
296 START=$(expr $START + 1)
297 done
298 DELTA=$(expr $START - 81)
David Bainbridgea2595422019-10-22 03:54:28 +0000299 ONOS_API_PORT=${ONOS_API_PORT:-${START}81}
300 ONOS_SSH_PORT=${ONOS_SSH_PORT:-${START}01}
301 VOLTHA_API_PORT=${VOLTHA_API_PORT:-5$(expr 55 + $DELTA)55}
302 VOLTHA_SSH_PORT=${VOLTHA_SSH_PORT:-$(expr 50 + $DELTA)22}
303 VOLTHA_ETCD_PORT=${VOLTHA_ETCD_PORT:-$(expr 23 + $DELTA)79}
David K. Bainbridge00ecd382020-02-28 12:31:58 -0800304 VOLTHA_KAFKA_PORT=${VOLTHA_KAFKA_PORT:-$(expr 90 + $DELTA)92}
Test User01ed0642019-07-03 20:17:06 +0000305else
David Bainbridge0774b232019-08-02 06:37:19 +0000306 VALUES=$(echo $HAVE | sed -e 's/\s//g' | cut -d= -f2)
David Bainbridgea2595422019-10-22 03:54:28 +0000307 ONOS_API_PORT=${ONOS_API_PORT:-$(echo $VALUES | cut -d, -f1)}
308 ONOS_SSH_PORT=${ONOS_SSH_PORT:-$(echo $VALUES | cut -d, -f2)}
309 VOLTHA_API_PORT=${VOLTHA_API_PORT:-$(echo $VALUES | cut -d, -f3)}
310 VOLTHA_SSH_PORT=${VOLTHA_SSH_PORT:-$(echo $VALUES | cut -d, -f4)}
311 VOLTHA_ETCD_PORT=${VOLTHA_ETCD_PORT:-$(echo $VALUES | cut -d, -f5)}
David K. Bainbridge00ecd382020-02-28 12:31:58 -0800312 VOLTHA_KAFKA_PORT=${VOLTHA_KAFKA_PORT:-$(echo $VALUES | cut -d, -f6)}
313
David K. Bainbridge00ecd382020-02-28 12:31:58 -0800314 # A bit of a hueristic required here as the KAFKA port forward was
315 # added after the .voltha/ports files was created. Basically, if
316 # the VOLTHA_KAFKA_PORT isn't in the file then calculate the original
317 # DELTA from the VOLTHA_SSH_PORT and apply it to the VOLTHA_KAFKA_PORT
318 if [ -z "$VOLTHA_KAFKA_PORT" ]; then
319 DELTA=$((VOLTHA_SSH_PORT/100-50))
320 VOLTHA_KAFKA_PORT=${VOLTHA_KAFKA_PORT:-$(expr 90 + $DELTA)92}
321 fi
Test User01ed0642019-07-03 20:17:06 +0000322fi
323
David Bainbridge0774b232019-08-02 06:37:19 +0000324PORTTMP=$(mktemp -u)
325cat .voltha/ports | grep -v $NAME > $PORTTMP
David K. Bainbridge00ecd382020-02-28 12:31:58 -0800326echo "$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 +0000327cp $PORTTMP .voltha/ports
328rm -f $PORTTMP
329
David Bainbridge27790d62019-08-13 22:43:19 +0000330export ONOS_API_PORT ONOS_SSH_PORT
David Bainbridge01294952019-07-30 19:33:45 +0000331
Test Userd87942b2019-07-03 07:20:24 +0000332IDX=1
David Bainbridgee87067b2019-08-12 22:00:12 +0000333CLOCK="TIME:"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000334SPIN_PARTS=
335NOT_VERIFIED=
David Bainbridgef858a022019-08-14 21:25:11 +0000336THEX=
337BUILD=
338CROSS=
339ENTER=
David Bainbridge38dc1e82019-08-12 15:18:45 +0000340VERIFIED=
341HELM=
342OLD_KEY=
343BIRD=
344HIGH_VOLTAGE=
345PLUG=
346RESTART=
347FORWARD=
348INSTALL=
349STOP=
350GO=
351DOWNLOAD=
352GEAR=
353NO_ENTRY=
354LOCK=
355
356if [ $FANCY -eq 1 ]; then
357 SPIN_PARTS="\
358 \xe2\xa2\x8e\xe2\xa1\xb0 \
359 \xe2\xa2\x8e\xe2\xa1\xa1 \
360 \xe2\xa2\x8e\xe2\xa1\x91 \
361 \xe2\xa2\x8e\xe2\xa0\xb1 \
362 \xe2\xa0\x8e\xe2\xa1\xb1 \
363 \xe2\xa2\x8a\xe2\xa1\xb1 \
364 \xe2\xa2\x8c\xe2\xa1\xb1 \
365 \xe2\xa2\x86\xe2\xa1\xb1 \
366 "
David Bainbridgee87067b2019-08-12 22:00:12 +0000367 CLOCK="\xe2\x8f\xb1"
David Bainbridgef858a022019-08-14 21:25:11 +0000368 THEX="${RED}${BOLD}\xe2\x9c\x97\x20${NORMAL}"
369 ENTER="${YELLOW}${BOLD}\xe2\x8e\x86${NORMAL}"
370 CROSS="${YELLOW}${BOLD}\xe2\x9c\x9a${NORMAL}"
371 BUILD="${YELLOW}${BOLD}\xf0\x9f\x8f\x97${NORMAL}"
372 NOT_VERIFIED="$BUILD"
373 VERIFIED="${GREEN}${BOLD}\xe2\x9c\x93\x20${NORMAL}"
374 HELM="${BLUE}${BOLD}\xE2\x8E\x88${NORMAL}"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000375 OLD_KEY="\xF0\x9F\x97\x9D"
376 BIRD="\xF0\x9F\x90\xA6"
377 HIGH_VOLTAGE="\xE2\x9A\xA1"
378 PLUG="\xF0\x9F\xa7\xa9"
379 RESTART="\xf0\x9f\x94\x84"
380 FORWARD="\xE2\x87\xA8"
381 INSTALL="\xF0\x9F\x8F\x97"
382 STOP="\xf0\x9f\x9b\x91"
383 GO="\xf0\x9f\x9a\x80"
384 DOWNLOAD="\xf0\x9f\x93\xa5"
385 GEAR="\xe2\x9a\x99"
386 NO_ENTRY="\xe2\x9b\x94"
387 LOCK="\xf0\x9f\x94\x92"
388fi
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700389
David Bainbridge712afb82019-08-14 19:55:58 +0000390duration() {
David Bainbridgee87067b2019-08-12 22:00:12 +0000391 local h=$(expr $1 / 3600)
392 local m=$(expr $1 % 3600 / 60)
393 local s=$(expr $1 % 60)
394 local t=""
395
396 if [ $h -gt 0 ]; then
397 t="$t${h}h"
398 fi
399 if [ $m -gt 0 ]; then
400 t="$t${m}m"
401 fi
David Bainbridge712afb82019-08-14 19:55:58 +0000402 echo "$t${s}s"
403}
404
405printtime() {
406 local INDENT=
407 if [ "$1" == "-" ]; then
408 INDENT=" "
409 shift
410 fi
411 echo -e "$INDENT $CLOCK $(duration $1)"
David Bainbridgee87067b2019-08-12 22:00:12 +0000412}
413
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700414bspin() {
Test Userd87942b2019-07-03 07:20:24 +0000415 IDX=1
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700416 local INDENT=
417 if [ "$1" == "-" ]; then
418 INDENT=" "
419 shift
420 fi
David Bainbridge38dc1e82019-08-12 15:18:45 +0000421 if [ $FANCY -eq 0 ]; then
422 LINE=$(echo $* | sed -e 's/[\s+-]//g')
423 if [ "$LINE X" == " X" ]; then
424 return
425 fi
426 echo -e "$CIVIS$INDENT$*"
427 else
428 echo -en "$CIVIS$INDENT $*"
429 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700430}
431
432sspin() {
433 local INDENT=
434 if [ "$1" == "-" ]; then
435 INDENT=" "
436 shift
437 fi
David Bainbridge38dc1e82019-08-12 15:18:45 +0000438 if [ $FANCY -eq 0 ]; then
439 LINE=$(echo $* | sed -e 's/[\s+-]//g')
440 if [ "$LINE X" == " X" ]; then
441 return
442 fi
443 echo -e "$INDENT$*"
444 else
445 C=$(echo $SPIN_PARTS | cut '-d ' -f $IDX)
446 echo -en "\r$INDENT$C $*"
447 IDX=$(expr $IDX + 1)
448 if [ $IDX -gt 8 ]; then
449 IDX=1
450 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700451 fi
452}
453
454espin() {
455 local INDENT=
456 if [ "$1" == "-" ]; then
457 INDENT=" "
458 shift
459 fi
David Bainbridge38dc1e82019-08-12 15:18:45 +0000460 if [ $FANCY -eq 0 ]; then
461 LINE=$(echo $* | sed -e 's/[\s+-]//g')
462 if [ "$LINE X" == " X" ]; then
463 return
464 fi
465 echo -e "$INDENT$*"
466 else
467 echo -e "\r$INDENT$*$CNORM"
468 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700469}
470
David Bainbridgeac7f8072019-08-01 22:15:33 +0000471if [ "$1" == "get" -a "$2" == "voltconfig" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000472 echo "$HOME/.volt/config-$NAME"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000473 exit
474fi
475
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -0700476if [ $# -ne 1 -o $(echo ":up:down:dump:" | grep -c ":$1:") -ne 1 ]; then
David Bainbridgeac7f8072019-08-01 22:15:33 +0000477 >&2 echo "What wouild you like to do today:"
478 >&2 echo " up - bring up voltha"
479 >&2 echo " down - tear down voltha"
480 >&2 echo " dump - create a debug dump of running system"
481 exit 1
482fi
483
David Bainbridge4f1b5562019-08-19 04:46:52 +0000484push_onos_config() {
Matteo Scandolo78dfee02020-02-13 16:18:03 -0800485 local TYPE=$1
486 local MSG=$2
487 local RESOURCE=$3
488 local DATA=$4
David Bainbridge4f1b5562019-08-19 04:46:52 +0000489
David K. Bainbridgeb4b163b2020-02-19 15:55:06 -0800490 # Thanks to the latest version of ONOS using the return code 207 this gets a
491 # whole lot nastier. Can't thank them enough for doing this. So in order to
492 # capture the command and the output in the log file as well as capture the
493 # status code to verify it is 200 and not 207 mutltiple files and a bit of
494 # hackery must be used. Thanks again ONOS.
495 local CMD_ECHO=$(mktemp -u)
496 local CMD_OUTPUT=$(mktemp -u)
497 local SC_OUTPUT=$(mktemp -u)
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700498 local WAIT_START=$(date +%s)
David K. Bainbridgeb4b163b2020-02-19 15:55:06 -0800499
David Bainbridge4f1b5562019-08-19 04:46:52 +0000500 bspin - "$MSG $GEAR"
501 while true; do
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700502 if [ $(($(date +%s) - $WAIT_START)) -gt $TIMEOUT_SECONDS ]; then
503 espin - "$THEX"
504 doTimeout "waiting for ONOS config push on $RESOURCE"
505 fi
Matteo Scandolo78dfee02020-02-13 16:18:03 -0800506 if [ $TYPE == "file" ]; then
David K. Bainbridgeb859e912020-03-13 14:07:52 -0700507 (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
508 RESULT=$?
Matteo Scandolo78dfee02020-02-13 16:18:03 -0800509 fi
510 if [ $TYPE == "json" ]; then
David K. Bainbridgeb859e912020-03-13 14:07:52 -0700511 (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
512 RESULT=$?
Matteo Scandolo78dfee02020-02-13 16:18:03 -0800513 fi
David K. Bainbridgeb4b163b2020-02-19 15:55:06 -0800514 # Dump everything to the log
515 cat $CMD_ECHO >> $LOG
David K. Bainbridgeb859e912020-03-13 14:07:52 -0700516 test -r $CMD_OUTPUT && cat $CMD_OUTPUT >> $LOG
David K. Bainbridgeb4b163b2020-02-19 15:55:06 -0800517 SC=$(cat $SC_OUTPUT)
David K. Bainbridgeb859e912020-03-13 14:07:52 -0700518 echo "RESPONSE CODE: $SC" >> $LOG
519 echo "ERROR CODE: $RESULT" >> $LOG
David K. Bainbridgeb4b163b2020-02-19 15:55:06 -0800520
521 # clean up temp files
522 rm -f $CMD_ECHO $CMD_OUTPUT $SC_OUTPUT
523 if [ $RESULT -eq 0 -a "$SC" == "200" ]; then
David Bainbridge4f1b5562019-08-19 04:46:52 +0000524 break
525 fi
Matteo Scandolo9a77a732020-01-09 14:24:12 -0800526 sleep 1
David Bainbridge4f1b5562019-08-19 04:46:52 +0000527 sspin -
528 done
529 espin - $VERIFIED
530}
531
Matteo Scandolo9a77a732020-01-09 14:24:12 -0800532check_onos_app_active() {
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700533 local APP_ID=$1
534 local WAIT_START=$(date +%s)
Matteo Scandolo9a77a732020-01-09 14:24:12 -0800535
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700536 bspin - "Checking that $APP_ID is active $CLOCK"
537 while true; do
538 if [ $(($(date +%s) - $WAIT_START)) -gt $TIMEOUT_SECONDS ]; then
539 espin - "$THEX"
540 doTimeout "waiting for ONOS application activation '$APP_ID'"
541 fi
542 (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
543 if [ $? -eq 0 ]; then
544 break
545 fi
546 sleep 1
547 sspin -
548 done
549 sleep 5 # OSGI components take a little longer that the app to activate
550 espin - $VERIFIED
Matteo Scandolo9a77a732020-01-09 14:24:12 -0800551}
552
David Bainbridge4f1b5562019-08-19 04:46:52 +0000553override_onos_app() {
554 local APP=$1
555 local NAME=$(basename $APP | sed -e 's/^[0-9][0-9]*-//g' -e 's/-.*$//g')
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700556 local WAIT_START=$(date +%s)
557
David Bainbridge4f1b5562019-08-19 04:46:52 +0000558 while true; do
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700559 if [ $(($(date +%s) - $WAIT_START)) -gt $TIMEOUT_SECONDS ]; then
560 espin - "$THEX"
561 doTimeout "waiting to overwrite ONOS application '$APP'"
562 fi
David Bainbridge4f1b5562019-08-19 04:46:52 +0000563 sspin -
564 # Attempt to delete old version (if it exists)
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -0800565 (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 +0000566 sspin -
567 if [ $? -ne 0 ]; then
568 continue
569 fi
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -0800570 (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 +0000571 if [ $? -eq 0 ]; then
572 break
573 fi
574 sleep .2
575 done
576}
577
578activate_onos_app() {
579 local MSG="$1"
580 local APP=$2
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700581 local WAIT_START=$(date +%s)
David Bainbridge4f1b5562019-08-19 04:46:52 +0000582
583 bspin - "$MSG $GO"
584 while true; do
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700585 if [ $(($(date +%s) - $WAIT_START)) -gt $TIMEOUT_SECONDS ]; then
586 espin - "$THEX"
587 doTimeout "waiting to activate ONOS application '$APP'"
588 fi
David Bainbridge4f1b5562019-08-19 04:46:52 +0000589 sspin -
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -0800590 (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 +0000591 if [ $? -eq 0 ]; then
592 break
593 fi
594 sleep .2
595 done
596 espin - "$VERIFIED"
597}
598
599count_pods() {
600 local NAMESPACE=$1; shift
601 if [ "$NAMESPACE" == "all-namespaces" ]; then
602 NAMESPACE="--all-namespaces"
603 else
604 NAMESPACE="-n $NAMESPACE"
605 fi
David Bainbridge4f1b5562019-08-19 04:46:52 +0000606 local STATES=$1; shift
David Bainbridge4f1b5562019-08-19 04:46:52 +0000607 local PODS=$(kubectl get $NAMESPACE pod -o go-template="{{range .items}}{{.metadata.name}}/{{.status.phase}}/_{{range .status.containerStatuses}}{{.ready}}_{{end}} {{end}}")
608 local COUNT=0
609 local PATTERNS="$*"
610 for POD in $PODS; do
611 local NAME=$(echo $POD | cut -d/ -f 1)
612 local STATE=$(echo $POD | cut -d/ -f 2)
613 local CONTAINERS=$(echo $POD | cut -d/ -f 3 | sed -e 's/_/ /g')
614 if [ "$STATES" == "*" -o $(echo "$STATES" | grep -c ":$STATE:") -ne 0 ]; then
David Bainbridge4f1b5562019-08-19 04:46:52 +0000615 local TOTAL=$(echo $CONTAINERS | wc -w)
616 local FOUND=$(echo $CONTAINERS | grep -o true | wc -l)
617 if [ $TOTAL -eq $FOUND ]; then
618 for PATTERN in $PATTERNS; do
David Bainbridge4f1b5562019-08-19 04:46:52 +0000619 if [[ $NAME =~ $PATTERN ]]; then
David Bainbridge4f1b5562019-08-19 04:46:52 +0000620 COUNT=$(expr $COUNT + 1)
621 break
622 fi
623 done
624 fi
625 fi
626 done
David Bainbridge4f1b5562019-08-19 04:46:52 +0000627 echo $COUNT
628}
629
630wait_for_pods() {
631 local INDENT=
632 if [ "$1" == "-" ]; then
633 INDENT=$1; shift
634 fi
635 local NAMESPACE=$1; shift
636 local EXPECT=$1; shift
637 local TYPE=$1; shift
638 local RETRY=$1; shift
639 local MESSAGE=$1; shift
640 local PATTERNS=$*
David Bainbridge99ac7a22019-08-31 02:26:43 +0000641 local STATES=":Running:"
642 if [ "$TYPE" == "not" ]; then
643 STATES="*"
644 fi
645 local HAVE=$(count_pods $NAMESPACE "$STATES" $PATTERNS)
David Bainbridge4f1b5562019-08-19 04:46:52 +0000646 local ALL=$HAVE
647 if [ "$TYPE" == "only" ]; then
648 ALL=$(count_pods "all-namespaces" "*" ".*")
649 fi
650 COUNT=$(expr 300 / 15)
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700651 local WAIT_START=$(date +%s)
David Bainbridge4f1b5562019-08-19 04:46:52 +0000652 bspin $INDENT $MESSAGE
653 sspin $INDENT
654 if [ $HAVE -ne $EXPECT -o $ALL -ne $HAVE ]; then
655 while [ $HAVE -ne $EXPECT -o $ALL -ne $HAVE ]; do
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700656 if [ $(($(date +%s) - $WAIT_START)) -gt $TIMEOUT_SECONDS ]; then
657 espin $INDENT "$THEX"
658 doTimeout "waiting for PODs to start"
659 fi
David Bainbridge4f1b5562019-08-19 04:46:52 +0000660 sspin $INDENT
661 COUNT=$(expr $COUNT - 1)
662 if [ $COUNT -eq 0 ]; then
David Bainbridge99ac7a22019-08-31 02:26:43 +0000663 HAVE=$(count_pods $NAMESPACE "$STATES" $PATTERNS)
David Bainbridge4f1b5562019-08-19 04:46:52 +0000664 ALL=$HAVE
665 if [ "$TYPE" == "only" ]; then
666 ALL=$(count_pods "all-namespaces" "*" ".*")
667 fi
668 COUNT=$(expr 300 / 15)
669 fi
670 sleep .15
671 done
672 fi
673 espin $INDENT $VERIFIED
674 if [ $HAVE -ne $EXPECT ]; then
675 return 1
676 fi
677 return 0
678}
679
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800680port_forward() {
681 local NS=$1
682 local SVC=$2
683 local FROM_PORT=$3
684 local TO_PORT=$4
685 local TAG=$SVC-$NAME
686
687 (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
688}
689
690kill_port_forward() {
691 local TAG=$1-$NAME
David Bainbridgec6871d22019-11-13 17:10:31 +0000692 local P_IDS=$(ps e -ww -A | grep "_TAG=$TAG" | grep -v grep | awk '{print $1}')
David Bainbridgebcf235b2019-11-12 21:33:58 +0000693 local PARENTS=
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800694 local KIDS=
David Bainbridgec6871d22019-11-13 17:10:31 +0000695 local UNKNOWN=
696 if [ ! -z "$P_IDS" ]; then
697 for P_ID in $P_IDS; do
698 local PP_ID=$(ps -o ppid $P_ID | tail -n +2)
699 if [ ! -z "$PP_ID" ]; then
700 if [ $PP_ID -eq 1 ]; then
701 PARENTS="$PARENTS $P_ID"
702 else
703 KIDS="$KIDS $P_ID"
704 fi
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800705 else
David Bainbridgec6871d22019-11-13 17:10:31 +0000706 UNKNOWN="$UNKNOWN $P_ID"
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800707 fi
708 done
David Bainbridgec6871d22019-11-13 17:10:31 +0000709 (set -x; kill -9 $PARENTS $KIDS $UNKNOWN >>$LOG 2>&1) >>$LOG 2>&1
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800710 fi
711}
712
David Bainbridgeac7f8072019-08-01 22:15:33 +0000713if [ "$1" == "down" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000714 echo "Tearing down voltha cluster $NAME"
715 LOG="down-$NAME.log"
716 echo $(date -u +"%Y%m%dT%H%M%SZ") >$LOG
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800717 bspin "Remove port-forwards: onos-ui-$NAME"
718 kill_port_forward onos-ui
719 sspin "Remove port-forwards: onos-ssh-$NAME$CEOL"
720 kill_port_forward onos-ssh
721 sspin "Remove port-forwards: voltha-api-$NAME$CEOL"
722 kill_port_forward voltha-api
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800723 sspin "Remove port-forwards: voltha-etcd-$NAME$CEOL"
724 kill_port_forward voltha-etcd-cluster-client
David K. Bainbridge00ecd382020-02-28 12:31:58 -0800725 sspin "Remove port-forwards: voltha-kafka-$NAME$CEOL"
726 kill_port_forward voltha-kafka
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800727 espin "$VERIFIED Remove port-forwards$CEOL"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000728 if [ $DEPLOY_K8S == "yes" ]; then
729 if [ -x ./bin/kind ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000730 bspin "Delete Kubernetes Kind Cluster"
731 (set -x; ./bin/kind delete cluster --name voltha-$NAME >>$LOG 2>&1) >>$LOG 2>&1
732 espin $VERIFIED
David Bainbridgeac7f8072019-08-01 22:15:33 +0000733 else
David Bainbridge0774b232019-08-02 06:37:19 +0000734 espin "$NO_ENTRY Delete Kubernetes Kind Cluster: kind command not found"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000735 fi
736 else
737 EXISTS=$(helm list -q)
738 EXPECT="etcd-operator onos open-olt open-onu sim voltha bbsim radius"
David Bainbridge0774b232019-08-02 06:37:19 +0000739 bspin "Remove Helm Deployments"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000740 for i in $EXISTS; do
David K. Bainbridge43422402020-03-06 07:41:22 -0800741 for j in $EXPECT; do
742 if [[ $i =~ $j ]]; then
743 sspin "Remove Helm Deployments: $i$CEOL"
744 (set -x; ./bin/helm delete --no-hooks --purge $i >>$LOG 2>&1) >>$LOG 2>&1
745 fi
746 done
uottrembb16d3982020-02-28 08:34:36 +0100747 done
David Bainbridge0774b232019-08-02 06:37:19 +0000748 espin "$VERIFIED Remove Helm Deployments$CEOL"
David Bainbridge4f1b5562019-08-19 04:46:52 +0000749 if [ "$WAIT_ON_DOWN" == "yes" ]; then
750 # There should only be 13 or 15 PODs in the kube-system name
751 # space and no other PODs
David Bainbridge4f1b5562019-08-19 04:46:52 +0000752 PODS="coredns-.* \
753 etcd-voltha-$NAME-control-plane \
754 kindnet-.* \
755 kube-apiserver-voltha-$NAME-control-plane \
756 kube-controller-manager-voltha-$NAME-control-plane \
757 kube-proxy-.* \
758 kube-scheduler-voltha-$NAME-control-plane \
759 tiller-deploy-.*"
760 EXPECT=$(test "$TYPE" == "minimal" && echo "13" || echo "15")
David Bainbridge99ac7a22019-08-31 02:26:43 +0000761 PODS="adapter-.* \
762 bbsim.* \
763 etcd-operator.* \
764 radius.* \
765 voltha-.*"
Matteo Scandolo73442f92020-01-29 09:53:22 -0800766
David Bainbridge99ac7a22019-08-31 02:26:43 +0000767 EXPECT=0
768
Matteo Scandolo73442f92020-01-29 09:53:22 -0800769 if [ "$WITH_ONOS" == "yes" ]; then
770 ONOS_PODS="onos-.*"
771 wait_for_pods "default" $EXPECT "not" -1 "Waiting for ONOS PODs to terminate" $ONOS_PODS
772 fi
David Bainbridge99ac7a22019-08-31 02:26:43 +0000773 wait_for_pods "voltha" $EXPECT "not" -1 "Waiting for VOLTHA PODs to terminate" $PODS
David Bainbridge4f1b5562019-08-19 04:46:52 +0000774 fi
David Bainbridgeac7f8072019-08-01 22:15:33 +0000775 fi
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -0700776 exit
David Bainbridgeac7f8072019-08-01 22:15:33 +0000777fi
778
779if [ "$1" == "dump" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000780 LOG="dump-$NAME.log"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000781 TS=$(date -u +"%Y%m%dT%H%M%SZ")
David Bainbridge76514a02019-10-08 01:50:35 +0000782 if [ ! -z "$DUMP_FROM" ]; then
783 TS=$(echo $DUMP_FROM | sed -e 's/[:-]//g')
784 fi
David Bainbridgeac7f8072019-08-01 22:15:33 +0000785 WORK=$(mktemp -u -d)
David Bainbridge0774b232019-08-02 06:37:19 +0000786 DATA=$WORK/voltha-debug-dump-$NAME-$TS
David Bainbridgeac7f8072019-08-01 22:15:33 +0000787 mkdir -p $DATA
788 echo $TS > $LOG
David Bainbridge0774b232019-08-02 06:37:19 +0000789 echo -e "Capturing debug dump to voltha-debug-dump-$NAME-$TS.tgz"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000790 bspin - "Copy install log"
David Bainbridge0774b232019-08-02 06:37:19 +0000791 if [ -f install-$NAME.log ]; then
792 (set -x; cp install-$NAME.log $DATA/install-$NAME.log) >>$LOG 2>&1
David Bainbridgeac7f8072019-08-01 22:15:33 +0000793 espin - $VERIFIED
794 else
David Bainbridge0774b232019-08-02 06:37:19 +0000795 espin - "$NO_ENTRY Copy install log: install-$NAME.log not found"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000796 fi
797 bspin - "Dumping Kubernetes PODs"
798 (set -x; kubectl get --all-namespaces pods >> $DATA/all-pods.txt 2>&1) >>$LOG 2>&1
799 espin - $VERIFIED
800 bspin - "Dumping Kubernetes SERVICEs"
801 (set -x; kubectl get --all-namespaces svc >> $DATA/all-services.txt 2>&1) >>$LOG 2>&1
802 espin - $VERIFIED
803 bspin - "Dumping Kubernetes EVENTs"
804 (set -x; kubectl get --all-namespaces events >> $DATA/all-events.txt 2>&1) >>$LOG 2>&1
805 espin - $VERIFIED
806 bspin - "Dumping VOLTHA POD details"
Matteo Scandolodcd29f52019-10-07 15:42:42 -0700807 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 +0000808 SINCE=
809 if [ ! -z "$DUMP_FROM" ]; then
810 SINCE="--since-time=$DUMP_FROM"
811 fi
David Bainbridgeac7f8072019-08-01 22:15:33 +0000812 for POD in $PODS; do
David Bainbridge1f0655a2019-10-01 22:08:48 +0000813 NS=$(echo $POD | cut -d: -f1)
814 POD=$(echo $POD | cut -d: -f2)
David Bainbridgeac7f8072019-08-01 22:15:33 +0000815 sspin - "Dumping VOLTHA POD details: $POD$CEOL"
816 mkdir -p $DATA/$POD
David Bainbridge1f0655a2019-10-01 22:08:48 +0000817 (set -x; kubectl describe -n $NS $POD >> $DATA/$POD/describe.txt 2>&1) >>$LOG 2>&1
David Bainbridgeac7f8072019-08-01 22:15:33 +0000818 sspin - "Dumping VOLTHA POD details: $POD"
David Bainbridgecfd7ca12019-10-06 03:31:41 +0000819 (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 +0000820 sspin - "Dumping VOLTHA POD details: $POD"
David Bainbridgecfd7ca12019-10-06 03:31:41 +0000821 (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 +0000822 sspin - "Dumping VOLTHA POD details: $POD"
823 done
824 espin - "$VERIFIED Dumping VOLTHA POD details$CEOL"
825 bspin - "Dumping ETCD"
826 if [ "$(which etcdctl) X" != " X" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000827 (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 +0000828 espin - $VERIFIED
829 else
830 espin - "$NO_ENTRY Dumping ETCD: etcdctl command not available"
831 fi
David Bainbridge0774b232019-08-02 06:37:19 +0000832 bspin - "Creating compressed TAR: voltha-debug-dump-$NAME-$TS.tgz"
833 (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 +0000834 espin - $VERIFIED
835 bspin - "Cleanup"
836 (set -x; rm -rf $WORK) >>$LOG 2>&1
837 espin - $VERIFIED
David Bainbridge0774b232019-08-02 06:37:19 +0000838 bspin - "$(ls -l voltha-debug-dump-$NAME-$TS.tgz)"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000839 espin - $VERIFIED
840 exit
841fi
842
David Bainbridge0774b232019-08-02 06:37:19 +0000843LOG="install-$NAME.log"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000844date > $LOG
David Bainbridge0774b232019-08-02 06:37:19 +0000845echo "PORTS=$ONOS_API_PORT,$ONOS_SSH_PORT,$VOLTHA_API_PORT,$VOLTHA_SSH_PORT,$VOLTHA_ETCD_PORT" >> $LOG
David Bainbridgeac7f8072019-08-01 22:15:33 +0000846
847# Output install options to log
848echo "OPTIONS" >> $LOG
David Bainbridgeac7f8072019-08-01 22:15:33 +0000849for O in $ALL_OPTIONS; do
850 VAL=$(eval echo \$$O)
David Bainbridgeac7f8072019-08-01 22:15:33 +0000851 if [ ! -z "$VAL" ]; then
852 printf " %-30s = %s\n" $O $VAL >> $LOG
853 fi
854done
855
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -0700856helm_install() {
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700857 local INDENT=
858 if [ "$1" == "-" ]; then
859 INDENT=$1; shift
860 fi
861 local NAMESPACE=$1; shift
David Bainbridge0774b232019-08-02 06:37:19 +0000862 local INAME=$1; shift
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700863 local CHART=$1; shift
David Bainbridge90fd8e32019-08-21 23:32:47 +0000864 local CHART_VERSION=$1; shift
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700865 local MESSAGE=$*
866
David Bainbridge90fd8e32019-08-21 23:32:47 +0000867 if [ "$CHART_VERSION X" != " X" -a "$CHART_VERSION" != "latest" ]; then
868 CHART_VERSION="--version $CHART_VERSION"
869 else
870 CHART_VERSION=
871 fi
872
David Bainbridge99ac7a22019-08-31 02:26:43 +0000873 local CHART_ARGS=
874 if [ -r "${INAME}-values.yaml" ]; then
875 CHART_ARGS="-f ${INAME}-values.yaml"
876 fi
877
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700878 local WAIT_START=$(date +%s)
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700879 COUNT=$(expr 300 / 15)
880 bspin $INDENT $MESSAGE
David Bainbridge2eaf2cf2020-03-18 12:54:08 -0700881 (set -x; helm install -f $NAME-values.yaml $CHART_ARGS $INTERNAL_EXTRA_HELM_INSTALL_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 -0700882 SUCCESS=$?
883 while [ $SUCCESS -ne 0 ]; do
David Bainbridge52e6e9d2020-03-23 13:48:27 -0700884 if [ $(($(date +%s) - $WAIT_START)) -gt $TIMEOUT_SECONDS ]; then
885 espin "$THEX"
886 doTimeout "waiting for helm install $CHART"
887 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700888 sspin $INDENT
889 COUNT=$(expr $COUNT - 1)
890 if [ $COUNT -eq 0 ]; then
Andy Baviere22ff252019-12-19 11:40:31 -0700891 (set -x; helm delete --purge $INAME >>$LOG 2>&1) >>$LOG 2>&1
David Bainbridge2eaf2cf2020-03-18 12:54:08 -0700892 (set -x; helm install -f $NAME-values.yaml $CHART_ARGS $INTERNAL_EXTRA_HELM_INSTALL_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
Andy Baviere22ff252019-12-19 11:40:31 -0700893 SUCCESS=$?
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700894 COUNT=$(expr 300 / 15)
895 fi
896 sleep .15
897 done
898 espin $INDENT $VERIFIED
899}
900
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700901echo "INSTALL TYPE: $TYPE" >> $LOG
902
903bspin "Verify GOPATH"
904export GOPATH=$(pwd)
Test User3d7ad8e2019-07-03 06:15:44 +0000905mkdir -p $GOPATH/bin
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700906espin $VERIFIED
907
David Bainbridgee87067b2019-08-12 22:00:12 +0000908STIME=$(date +%s)
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700909if [ "$INSTALL_KUBECTL" == "no" ]; then
910 bspin "Skip kubectl install"
911 espin $NO_ENTRY
Test Userc13bdc92019-07-03 20:57:49 +0000912else
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700913 bspin "Verify kubectl $HELM"
914 if [ -x $GOPATH/bin/kubectl ]; then
915 espin $VERIFIED
916 else
917 espin $NOT_VERIFIED
918 bspin - "Download and install Kubernetes/kubectl $DOWNLOAD"
919 (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
920 (set -x; chmod 755 $GOPATH/bin/kubectl >>$LOG 2>&1) >>$LOG 2>&1
921 espin - $VERIFIED
922 fi
Test Userc13bdc92019-07-03 20:57:49 +0000923fi
David Bainbridgee87067b2019-08-12 22:00:12 +0000924if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +0000925 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +0000926fi
Test Userc13bdc92019-07-03 20:57:49 +0000927
David Bainbridgee87067b2019-08-12 22:00:12 +0000928STIME=$(date +%s)
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700929if [ "$DEPLOY_K8S" == "no" ]; then
930 bspin "Skip Kubernetes/Kind Deployment"
931 espin $NO_ENTRY
932else
Test Userba1e7e72019-07-10 22:27:54 +0000933 bspin "Verify Kubernetes/Kind $HELM"
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800934 IS_INSTALLED=0
935 OP_TYPE="install"
Test Userba1e7e72019-07-10 22:27:54 +0000936 if [ -x $GOPATH/bin/kind ]; then
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800937 OP_TYPE="upgrade"
938 if [ $($GOPATH/bin/kind --version | grep -c $KIND_VERSION) -eq 1 ]; then
939 IS_INSTALLED=1
940 espin $VERIFIED
941 fi
942 fi
943 if [ $IS_INSTALLED -eq 0 ]; then
Test Userba1e7e72019-07-10 22:27:54 +0000944 espin $NOT_VERIFIED
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800945 bspin - "Download and $OP_TYPE Kubernetes/kind $DOWNLOAD"
David Bainbridge9e2a6662019-07-11 17:07:57 +0000946 (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 +0000947 (set -x; chmod 755 $GOPATH/bin/kind >>$LOG 2>&1) >>$LOG 2>&1
948 espin - $VERIFIED
949 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700950fi
951
David Bainbridgee87067b2019-08-12 22:00:12 +0000952if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +0000953 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +0000954fi
955
956STIME=$(date +%s)
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700957if [ "$INSTALL_HELM" == "no" ]; then
958 bspin "Skip Helm Install"
959 espin $NO_ENTRY
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700960else
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700961 bspin "Verify Helm $HELM"
962 if [ -x $GOPATH/bin/helm ]; then
963 espin $VERIFIED
964 else
965 espin $NOT_VERIFIED
966 bspin - "Download and install Helm $DOWNLOAD"
David Bainbridgec6a6eb62019-10-18 22:50:07 +0000967 (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 -0700968 espin - $VERIFIED
969 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700970fi
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800971
David Bainbridgee87067b2019-08-12 22:00:12 +0000972if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +0000973 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +0000974fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700975
David Bainbridgee87067b2019-08-12 22:00:12 +0000976STIME=$(date +%s)
Test Userb5712372019-07-03 21:52:17 +0000977bspin "Verify voltctl $HIGH_VOLTAGE"
David Bainbridged2811972019-12-14 01:14:09 +0000978VOK=0
979VMESSAGE="install"
David K. Bainbridgeebf38d92020-02-10 10:46:31 -0800980export VC_VERSION="$VOLTCTL_VERSION"
981if [ "$VC_VERSION" == "latest" ]; then
982 export VC_VERSION=$(curl -sSL https://api.github.com/repos/opencord/voltctl/releases/latest | jq -r .tag_name | sed -e 's/^v//g')
983fi
Test User3d7ad8e2019-07-03 06:15:44 +0000984if [ -x $GOPATH/bin/voltctl ]; then
David Bainbridge1ba64f12019-12-18 00:40:13 +0000985 VHAVE=$($GOPATH/bin/voltctl version --clientonly -o json | jq -r .version)
David K. Bainbridgeebf38d92020-02-10 10:46:31 -0800986 if [ $? -eq 0 -a "$VHAVE" == "$VC_VERSION" ]; then
David Bainbridged2811972019-12-14 01:14:09 +0000987 VOK=1
David Bainbridge1ba64f12019-12-18 00:40:13 +0000988 espin $VERIFIED
989 else
David K. Bainbridgeebf38d92020-02-10 10:46:31 -0800990 VCHECK=$(echo -e "$VHAVE\n$VC_VERSION" | sort -V | head -1)
991 if [ "$VCHECK" == "$VHAVE" ]; then
992 VMESSAGE="upgrade"
993 else
994 VMESSAGE="downgrade"
995 fi
David Bainbridged2811972019-12-14 01:14:09 +0000996 fi
997fi
998
David Bainbridge1ba64f12019-12-18 00:40:13 +0000999if [ $VOK -eq 0 ]; then
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001000 espin $NOT_VERIFIED
David Bainbridged2811972019-12-14 01:14:09 +00001001 bspin - "Download and $VMESSAGE voltctl $DOWNLOAD"
David K. Bainbridgeebf38d92020-02-10 10:46:31 -08001002 (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 +00001003 (set -x; chmod 755 $GOPATH/bin/voltctl >>$LOG 2>&1) >>$LOG 2>&1
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001004 espin - $VERIFIED
1005fi
David Bainbridgee87067b2019-08-12 22:00:12 +00001006if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +00001007 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +00001008fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001009
1010bspin "Verify command PATH"
Test Userba1e7e72019-07-10 22:27:54 +00001011export PATH=$GOPATH/bin:$PATH
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001012espin $VERIFIED
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001013
David Bainbridgee87067b2019-08-12 22:00:12 +00001014STIME=$(date +%s)
Test Userba1e7e72019-07-10 22:27:54 +00001015if [ "$DEPLOY_K8S" == "yes" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +00001016 HAVE=$(kind get clusters | grep -c voltha-$NAME)
Test Userba1e7e72019-07-10 22:27:54 +00001017 bspin "Verify Kubernetes/Kind Cluster"
1018 sspin
1019 if [ $HAVE -eq 0 ]; then
David Bainbridge491b1bd2019-07-11 17:53:11 +00001020 espin $NOT_VERIFIED
1021 bspin - "Verify cluster configuration"
David Bainbridge0774b232019-08-02 06:37:19 +00001022 if [ ! -r ./$NAME-cluster.cfg ]; then
David Bainbridge491b1bd2019-07-11 17:53:11 +00001023 espin - $NOT_VERIFIED
David K. Bainbridge43422402020-03-06 07:41:22 -08001024 bspin - "Download cluster configuration: $TYPE-cluster.cfg to $NAME-cluster.cfg $DOWNLOAD"
David K. Bainbridgea00736b2020-01-08 14:33:17 -08001025 ERR_OUT=$(mktemp)
1026 (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
1027 if [ $? -ne 0 ]; then
1028 espin - $THEX
1029 echo -e "${RED}${BOLD}${ERROR}ERROR: $NAME-cluster.cfg${NORMAL}${RED} - $(cat $ERR_OUT)${NORMAL}"
1030 echo "ERROR: $(cat $ERR_OUT)" >>$LOG
1031 rm -rf $ERR_OUT ./$NAME-cluster.cfg
1032 exit 1
1033 fi
1034 rm -rf $ERR_OUT
1035 else
David K. Bainbridge43422402020-03-06 07:41:22 -08001036 espin - $VERIFIED
David K. Bainbridgea00736b2020-01-08 14:33:17 -08001037 fi
David Bainbridge0774b232019-08-02 06:37:19 +00001038 kind create cluster --name voltha-$NAME --config $NAME-cluster.cfg
David Bainbridge491b1bd2019-07-11 17:53:11 +00001039 else
1040 espin $VERIFIED
Test Userba1e7e72019-07-10 22:27:54 +00001041 fi
1042
David Bainbridge0774b232019-08-02 06:37:19 +00001043 export KUBECONFIG="$(kind get kubeconfig-path --name="voltha-$NAME")"
Test Userba1e7e72019-07-10 22:27:54 +00001044 P="coredns-.* \
David Bainbridge0774b232019-08-02 06:37:19 +00001045 etcd-voltha-$NAME-control-plane \
Test Userba1e7e72019-07-10 22:27:54 +00001046 kindnet-.* \
David Bainbridge0774b232019-08-02 06:37:19 +00001047 kube-apiserver-voltha-$NAME-control-plane \
1048 kube-controller-manager-voltha-$NAME-control-plane \
Test Userba1e7e72019-07-10 22:27:54 +00001049 kube-proxy-.* \
David Bainbridge0774b232019-08-02 06:37:19 +00001050 kube-scheduler-voltha-$NAME-control-plane"
Test Userba1e7e72019-07-10 22:27:54 +00001051
1052 EXPECT=$(test "$TYPE" == "minimal" && echo "12" || echo "14")
David Bainbridge4f1b5562019-08-19 04:46:52 +00001053 wait_for_pods - "kube-system" $EXPECT "includes" -1 "Waiting for system PODs to start" $P
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001054fi
David Bainbridgee87067b2019-08-12 22:00:12 +00001055if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +00001056 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +00001057fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001058
David Bainbridgee87067b2019-08-12 22:00:12 +00001059STIME=$(date +%s)
David Bainbridge4c6289c2019-09-03 21:11:32 +00001060COUNT=$(count_pods "kube-system" ":Running:" "tiller-deploy-.*")
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001061bspin "Verify Helm"
Test Userba1e7e72019-07-10 22:27:54 +00001062if [ $COUNT -ne 1 ]; then
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001063 espin $NOT_VERIFIED
Test Userb5712372019-07-03 21:52:17 +00001064 echo -e "Configuring Helm $GEAR"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001065 if [ "$INSTALL_HELM" == "no" ]; then
1066 bspin - "Skip Helm/Tiller Initialization"
1067 espin - $NO_ENTRY
1068 else
1069 bspin - "Initialize Helm"
1070 (set -x; helm init --upgrade >>$LOG 2>&1) >>$LOG 2>&1
1071 espin - $VERIFIED
David Bainbridge4f1b5562019-08-19 04:46:52 +00001072 wait_for_pods - "kube-system" 1 "includes" -1 "Waiting for Tiller POD to start" "tiller-deploy-.*"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001073 fi
Test Userb5712372019-07-03 21:52:17 +00001074 bspin - "Add Google Incubator repository to Helm"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001075 (set -x; helm repo add incubator https://kubernetes-charts-incubator.storage.googleapis.com >>$LOG 2>&1) >>$LOG 2>&1
1076 espin - $VERIFIED
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001077
Test Userba1e7e72019-07-10 22:27:54 +00001078 # HACK (sort-of) - the config for tiller is about to be patched, which will
1079 # cause the tiller pod to be recreated. This can sometimes cause a timing
1080 # issue with the "wait_for_pods" call on tiller as it may incorrectly
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001081 # identify the running/ready tiller pod that is soon to be terminated as
Test Userba1e7e72019-07-10 22:27:54 +00001082 # what it is waiting for. To avoid this issue we do a clean scale down and
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001083 # scale up of the pod so the script controlls when it should be expecting
Test Userba1e7e72019-07-10 22:27:54 +00001084 # things
1085 (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 -07001086
Test Userb5712372019-07-03 21:52:17 +00001087 bspin - "Add Google Stable repository to Helm"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001088 (set -x; helm repo add stable https://kubernetes-charts.storage.googleapis.com >>$LOG 2>&1) >>$LOG 2>&1
1089 espin - $VERIFIED
Test Userb5712372019-07-03 21:52:17 +00001090 bspin - "Add ONF repository to Helm"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001091 (set -x; helm repo add onf https://charts.opencord.org >>$LOG 2>&1) >>$LOG 2>&1
1092 espin - $VERIFIED
Test Userb5712372019-07-03 21:52:17 +00001093 bspin - "Update Helm repository cache"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001094 (set -x; helm repo update >>$LOG 2>&1) >>$LOG 2>&1
1095 espin - $VERIFIED
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001096
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001097 # Create and k8s service account so that Helm can create pods
Test Userb5712372019-07-03 21:52:17 +00001098 bspin - "Create Tiller ServiceAccount"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001099 (set -x; kubectl create serviceaccount --namespace kube-system tiller >>$LOG 2>&1) >>$LOG 2>&1
1100 espin - $VERIFIED
Test Userb5712372019-07-03 21:52:17 +00001101 bspin - "Create Tiller ClusterRoleBinding"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001102 (set -x; kubectl create clusterrolebinding tiller-cluster-rule --clusterrole=cluster-admin --serviceaccount=kube-system:tiller >>$LOG 2>&1) >>$LOG 2>&1
1103 espin - $VERIFIED
Test Userb5712372019-07-03 21:52:17 +00001104 bspin - "Update Tiller Manifest"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001105 (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 +00001106
1107 # HACK (sort-of) - part to, spin it back up
1108 (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 -07001109 espin - $VERIFIED
1110else
1111 espin $VERIFIED
David Bainbridge46505fb2019-10-01 21:13:20 +00001112 if [ "$UPDATE_HELM_REPOS" == "yes" ]; then
1113 bspin - "Update Helm repository cache"
1114 (set -x; helm repo update >>$LOG 2>&1) >>$LOG 2>&1
1115 espin - $VERIFIED
1116 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001117fi
David Bainbridge4f1b5562019-08-19 04:46:52 +00001118wait_for_pods - "kube-system" 1 "includes" -1 "Waiting for Tiller POD to start" "tiller-deploy-.*"
David Bainbridgee87067b2019-08-12 22:00:12 +00001119if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +00001120 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +00001121fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001122
David Bainbridgee87067b2019-08-12 22:00:12 +00001123STIME=$(date +%s)
David Bainbridge0774b232019-08-02 06:37:19 +00001124bspin "Verify Helm values file: $NAME-values.yaml"
1125if [ ! -r "./$NAME-values.yaml" ]; then
Test Userba1e7e72019-07-10 22:27:54 +00001126 espin $NOT_VERIFIED
David Bainbridge0774b232019-08-02 06:37:19 +00001127 bspin - "Download Helm values file: $TYPE-values.yaml to $NAME-values.yaml $DOWNLOAD"
David K. Bainbridgea00736b2020-01-08 14:33:17 -08001128 ERR_OUT=$(mktemp)
1129 (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
1130 if [ $? -ne 0 ]; then
1131 espin - $THEX
1132 echo -e "${RED}${BOLD}${ERROR}ERROR: $NAME-values.yaml${NORMAL}${RED} - $(cat $ERR_OUT)${NORMAL}"
1133 echo "ERROR: $(cat $ERR_OUT)" >>$LOG
1134 rm -rf $ERR_OUT ./$NAME-values.yaml
1135 exit 1
1136 fi
1137 rm -rf $ERR_OUT
Test Userba1e7e72019-07-10 22:27:54 +00001138 espin - $VERIFIED
1139else
1140 espin $VERIFIED
1141fi
David Bainbridgee87067b2019-08-12 22:00:12 +00001142if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +00001143 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +00001144fi
Test Userba1e7e72019-07-10 22:27:54 +00001145
David Bainbridge99ac7a22019-08-31 02:26:43 +00001146STIME=$(date +%s)
1147bspin "Verify or download chart specific values files $DOWNLOAD"
1148VALUES_FILES="monkey-values.yaml"
David K. Bainbridgea00736b2020-01-08 14:33:17 -08001149ERR_OUT=$(mktemp)
David Bainbridge99ac7a22019-08-31 02:26:43 +00001150for i in $VALUES_FILES; do
1151 if [ ! -r ./$i ]; then
David K. Bainbridgea00736b2020-01-08 14:33:17 -08001152 (set -x; curl --fail -o ./$i -sSL https://raw.githubusercontent.com/ciena/kind-voltha/$VK_RELEASE/$i >>$LOG 2>$ERR_OUT) >>$LOG 2>&1
1153 if [ $? -ne 0 ]; then
1154 espin $THEX
1155 echo -e "${RED}${BOLD}${ERROR}ERROR: $i${NORMAL}${RED} - $(cat $ERR_OUT)${NORMAL}"
1156 echo "ERROR: $i - $(cat $ERR_OUT)" >>$LOG
1157 rm -rf $ERR_OUT ./$i
1158 exit 1
1159 fi
1160 rm -rf $ERR_OUT
David Bainbridge99ac7a22019-08-31 02:26:43 +00001161 fi
1162done
1163espin $VERIFIED
1164if [ "$WITH_TIMINGS" == "yes" ]; then
1165 printtime $(expr $(date +%s) - $STIME)
1166fi
1167
1168if [ "$WITH_CHAOS" == "yes" ]; then
1169 bspin "Verify or clone kube-monkey helm chart $DOWNLOAD"
1170 if [ -r ./kube-monkey ]; then
1171 espin $VERIFIED
1172 else
1173 espin $NOT_VERIFIED
1174 bspin - "GIT clone kube-monkey"
1175 (set -x; git clone https://github.com/asobti/kube-monkey kube-monkey >>$LOG 2>&1) >>$LOG 2>&1
1176 espin - $VERIFIED
1177 fi
1178fi
1179
Test Userba1e7e72019-07-10 22:27:54 +00001180if [ "$JUST_K8S" == "yes" ]; then
1181 echo "Environment deployed, not deploying VOLTHA artifacts as requested. Good bye."
1182 echo ""
1183 echo "Please issue the following commands in your terminal to ensure that you" | tee -a $LOG
1184 echo "are accessing the correct Kubernetes/Kind cluster as well as have the " | tee -a $LOG
1185 echo "tools required by VOLTHA in your command path. " | tee -a $LOG
1186 echo "" | tee -a $LOG
1187 echo -en $BOLD
1188 if [ $DEPLOY_K8S == "yes" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +00001189 echo "export KUBECONFIG=\"\$(./bin/kind get kubeconfig-path --name=\"voltha-$NAME\")\"" | tee -a $LOG
Test Userba1e7e72019-07-10 22:27:54 +00001190 fi
1191 echo "export PATH=$GOPATH/bin:\$PATH" | tee -a $LOG
1192 echo -en $NORMAL
1193 echo "" | tee -a $LOG
1194 echo "Thank you for choosing kind-voltha for you quick cluster needs." | tee -a $LOG
1195 exit 0
1196fi
1197
David Bainbridgee87067b2019-08-12 22:00:12 +00001198STIME=$(date +%s)
Test Userb5712372019-07-03 21:52:17 +00001199bspin "Verify ETCD Operator $OLD_KEY"
Test User7d866122019-07-09 17:52:35 +00001200if [ $(helm list --deployed --short --namespace voltha "^etcd-operator\$" | wc -l) -ne 1 ]; then
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001201 espin $NOT_VERIFIED
David Bainbridge90fd8e32019-08-21 23:32:47 +00001202 helm_install - voltha etcd-operator stable/etcd-operator latest "Install ETCD Operator"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001203else
1204 espin $VERIFIED
1205fi
Test User01ed0642019-07-03 20:17:06 +00001206EXPECT=$(test "$TYPE" == "minimal" && echo "1" || echo "3")
David Bainbridge4f1b5562019-08-19 04:46:52 +00001207wait_for_pods - "voltha" $EXPECT "includes" -1 "Waiting for ETCD Operator to start" "etcd-operator-.*"
David Bainbridgee87067b2019-08-12 22:00:12 +00001208if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +00001209 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +00001210fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001211
David Bainbridgee87067b2019-08-12 22:00:12 +00001212STIME=$(date +%s)
David Bainbridgeb270c202019-07-26 01:44:42 +00001213if [ $WITH_ONOS == "yes" ]; then
1214 bspin "Verify ONOS installed $BIRD"
1215 if [ $(helm list --deployed --short --namespace default "^onos\$" | wc -l) -ne 1 ]; then
1216 espin $NOT_VERIFIED
David K. Bainbridgeda33d652020-03-06 10:31:23 -08001217 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 +00001218 else
1219 espin $VERIFIED
1220 fi
David Bainbridge4f1b5562019-08-19 04:46:52 +00001221 wait_for_pods - "default" 1 "includes" -1 "Waiting for ONOS to start" "onos-.*"
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001222
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -08001223 if [ $WITH_PORT_FORWARDS == "yes" ]; then
1224 bspin - "Forward ONOS API port $FORWARD"
1225 kill_port_forward onos-ui
1226 port_forward default onos-ui $ONOS_API_PORT 8181
1227 espin - $VERIFIED
1228 bspin - "Forward ONOS SSH port $FORWARD"
1229 kill_port_forward onos-ssh
1230 port_forward default onos-ssh $ONOS_SSH_PORT 8101
1231 espin - $VERIFIED
1232 _ONOS_API_EP="127.0.0.1:$ONOS_API_PORT"
1233 else
1234 _ONOS_API_EP=$(get_service_ep default onos-ui)
1235 fi
David Bainbridged31d6122019-08-13 19:37:59 +00001236 bspin - "Verify or download ONOS configuration support files $DOWNLOAD"
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001237 ONOS_FILES="olt-onos-enableExtraneousRules.json onos-aaa.json \
David Bainbridge90fd8e32019-08-21 23:32:47 +00001238 onos-dhcpl2relay.json onos-kafka.json onos-sadis-sample.json"
David Bainbridged31d6122019-08-13 19:37:59 +00001239 (set -x; mkdir -p ./onos-files >>$LOG 2>&1) >>$LOG 2>&1
David K. Bainbridgea00736b2020-01-08 14:33:17 -08001240 ERR_OUT=$(mktemp)
David Bainbridge2b19e832019-08-16 02:40:53 +00001241 for i in $ONOS_FILES; do
David Bainbridged31d6122019-08-13 19:37:59 +00001242 if [ ! -r ./onos-files/$i ]; then
David K. Bainbridgea00736b2020-01-08 14:33:17 -08001243 (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
1244 if [ $? -ne 0 ]; then
1245 espin - $THEX
1246 echo -e "${RED}${BOLD}${ERROR}ERROR: $i${NORMAL}${RED} - $(cat $ERR_OUT)${NORMAL}"
1247 echo "ERROR: $(cat $ERR_OUT)" >>$LOG
1248 rm -rf $ERR_OUT ./onos-files/$i
1249 exit 1
1250 fi
1251 rm -rf $ERR_OUT
David Bainbridged31d6122019-08-13 19:37:59 +00001252 fi
1253 done
Test Userba1e7e72019-07-10 22:27:54 +00001254 espin - $VERIFIED
David Bainbridge27790d62019-08-13 22:43:19 +00001255
1256 if [ $INSTALL_ONOS_APPS == "yes" ]; then
1257 bspin - "Installing custom ONOS applications"
1258 if [ -x onos-files/onos-apps -a $(ls -1 onos-files/onos-apps/*.oar 2>/dev/null | wc -l) -gt 0 ]; then
1259 for OAR in $(ls -1 onos-files/onos-apps/*.oar); do
1260 sspin - "Installing custom ONOS applications - $OAR$CEOL"
David Bainbridge2b19e832019-08-16 02:40:53 +00001261 override_onos_app $OAR
David Bainbridge27790d62019-08-13 22:43:19 +00001262 done
1263 espin - "$VERIFIED Installing custom ONOS applications$CEOL"
1264 else
1265 espin - "$NOT_VERIFIED Installing custom ONOS applications - None Found"
1266 fi
1267 fi
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001268
Matteo Scandolo9a77a732020-01-09 14:24:12 -08001269 check_onos_app_active org.opencord.kafka
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001270 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 -08001271 check_onos_app_active org.opencord.dhcpl2relay
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001272 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 -08001273 check_onos_app_active org.opencord.olt
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001274 # FIXME use WITH_DHCP and WITH_EAPOL flags to configre OLT App
Hardik Windlassa7501fb2020-02-17 14:28:20 +00001275 # Default value for "enableEapol" is true in OLT App
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001276 if [ $WITH_EAPOL == "yes" ]; then
1277 push_onos_config "json" "Enable VOLTHA ONOS EAPOL provisioning" "configuration/org.opencord.olt.impl.OltFlowService" '{"enableEapol":true}'
Hardik Windlassa7501fb2020-02-17 14:28:20 +00001278 elif [ $WITH_EAPOL == "no" ]; then
1279 push_onos_config "json" "Disable VOLTHA ONOS EAPOL provisioning" "configuration/org.opencord.olt.impl.OltFlowService" '{"enableEapol":false}'
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001280 fi
Hardik Windlassa7501fb2020-02-17 14:28:20 +00001281 # Default value for "enableDhcpOnProvisioning" is false and for "enableDhcpV4" is true in OLT App
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001282 if [ $WITH_DHCP == "yes" ]; then
1283 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 +00001284 elif [ $WITH_DHCP == "no" ]; then
1285 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 -08001286 fi
Hardik Windlassa7501fb2020-02-17 14:28:20 +00001287 # Default value for "enableIgmpOnProvisioning" is false in OLT App
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001288 if [ $WITH_IGMP == "yes" ]; then
1289 push_onos_config "json" "Enable VOLTHA ONOS IGMP provisioning" "configuration/org.opencord.olt.impl.OltFlowService" '{"enableIgmpOnProvisioning":true}'
Hardik Windlassa7501fb2020-02-17 14:28:20 +00001290 elif [ $WITH_IGMP == "no" ]; then
1291 push_onos_config "json" "Disable VOLTHA ONOS IGMP provisioning" "configuration/org.opencord.olt.impl.OltFlowService" '{"enableIgmpOnProvisioning":false}'
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001292 fi
David K. Bainbridge484d80c2020-03-05 21:44:34 -08001293 if [ $ENABLE_ONOS_EXTRANEOUS_RULES == "yes" ]; then
1294 push_onos_config "file" "Enabling extraneous rules for ONOS" "configuration/org.onosproject.net.flow.impl.FlowRuleManager" "onos-files/olt-onos-enableExtraneousRules.json"
1295 fi
David K. Bainbridgeb859e912020-03-13 14:07:52 -07001296 if [ $(echo ":yes:file:" | grep -c ":$CONFIG_SADIS:") -eq 1 ]; then
Matteo Scandolo9a77a732020-01-09 14:24:12 -08001297 check_onos_app_active org.opencord.sadis
Hardik Windlassb3147602020-03-09 16:59:15 +05301298 push_onos_config "file" "[optional] Push ONOS SADIS Configuration: $SADIS_CFG" "network/configuration/apps/org.opencord.sadis" "$SADIS_CFG"
David K. Bainbridgeb859e912020-03-13 14:07:52 -07001299 elif [ "$CONFIG_SADIS" == "bbsim" ]; then
1300 push_onos_config "json" \
1301 "[optional] Push ONOS configuration for BBSIM SADIS servers" \
1302 "network/configuration/apps/org.opencord.sadis" \
1303 "$(echo $(cat <<EOJ
1304{
1305 "sadis": {
1306 "integration": {
1307 "url": "http://bbsim.voltha.svc.cluster.local:50074/v2/subscribers/%s",
1308 "cache": {
1309 "enabled": true,
1310 "maxsize": 50,
1311 "ttl": "PT1m"
1312 }
1313 }
1314 },
1315 "bandwidthprofile": {
1316 "integration": {
1317 "url": "http://bbsim.voltha.svc.cluster.local:50074/v2/bandwidthprofiles/%s",
1318 "cache": {
1319 "enabled": true,
1320 "maxsize": 50,
1321 "ttl": "PT1m"
1322 }
1323 }
1324 }
1325}
1326EOJ
1327) | tr -d '[:space:]')"
1328 elif [ "$CONFIG_SADIS" == "url" ]; then
1329 push_onos_config "json" \
1330 "[optional] Push ONOS configuration for custom SADIS and Bandwidth Profile servers" \
1331 "network/configuration/apps/org.opencord.sadis" \
1332 "$(echo $(cat <<EOJ
1333{
1334 "sadis": {
1335 "integration": {
1336 "url": "$SADIS_SUBSCRIBERS",
1337 "cache": {
1338 "enabled": true,
1339 "maxsize": 50,
1340 "ttl": "PT1m"
1341 }
1342 }
1343 },
1344 "bandwidthprofile": {
1345 "integration": {
1346 "url": "$SADIS_BANDWIDTH_PROFILES",
1347 "cache": {
1348 "enabled": true,
1349 "maxsize": 50,
1350 "ttl": "PT1m"
1351 }
1352 }
1353 }
1354}
1355EOJ
1356) | tr -d '[:space:]')"
David Bainbridge2b19e832019-08-16 02:40:53 +00001357 fi
Test Userba1e7e72019-07-10 22:27:54 +00001358fi
David Bainbridgee87067b2019-08-12 22:00:12 +00001359if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +00001360 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +00001361fi
Test Userba1e7e72019-07-10 22:27:54 +00001362
David Bainbridgee87067b2019-08-12 22:00:12 +00001363STIME=$(date +%s)
Test Userb5712372019-07-03 21:52:17 +00001364bspin "Verify VOLTHA installed $HIGH_VOLTAGE"
Test User7d866122019-07-09 17:52:35 +00001365if [ $(helm list --deployed --short --namespace voltha "^voltha\$" | wc -l) -ne 1 ]; then
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001366 espin $NOT_VERIFIED
David Bainbridge70c0ea82019-11-14 23:25:26 +00001367 if [ "$ONLY_ONE" == "yes" ]; then
David Bainbridge2eaf2cf2020-03-18 12:54:08 -07001368 INTERNAL_EXTRA_HELM_INSTALL_ARGS="--set therecanbeonlyone=true"
David Bainbridge70c0ea82019-11-14 23:25:26 +00001369 fi
David Bainbridge90fd8e32019-08-21 23:32:47 +00001370 helm_install - voltha voltha $VOLTHA_CHART $VOLTHA_CHART_VERSION "Install VOLTHA Core"
David Bainbridge2eaf2cf2020-03-18 12:54:08 -07001371 INTERNAL_EXTRA_HELM_INSTALL_ARGS=
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001372else
1373 espin $VERIFIED
1374fi
Test Userba1e7e72019-07-10 22:27:54 +00001375
David Bainbridge90fd8e32019-08-21 23:32:47 +00001376VOLTHA="voltha-ofagent-.* \
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001377 ro-core.* \
1378 rw-core.* \
1379 voltha-api-server-.* \
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001380 voltha-etcd-cluster-.* \
1381 voltha-kafka-.* \
1382 voltha-zookeeper-.*"
David Bainbridge70c0ea82019-11-14 23:25:26 +00001383if [ "$ONLY_ONE" == "yes" ]; then
David Bainbridgefce8af42020-03-17 12:50:39 -07001384 EXPECT=$(test "$TYPE" == "minimal" && echo "5" || echo "9")
David Bainbridge70c0ea82019-11-14 23:25:26 +00001385else
David Bainbridgefce8af42020-03-17 12:50:39 -07001386 EXPECT=$(test "$TYPE" == "minimal" && echo "8" || echo "12")
David Bainbridge70c0ea82019-11-14 23:25:26 +00001387fi
David Bainbridge4f1b5562019-08-19 04:46:52 +00001388wait_for_pods - "voltha" $EXPECT "includes" -1 "Waiting for VOLTHA Core to start" $VOLTHA
David Bainbridgee87067b2019-08-12 22:00:12 +00001389if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +00001390 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +00001391fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001392
David Bainbridge46505fb2019-10-01 21:13:20 +00001393if [ "$WITH_ADAPTERS" == "yes" ]; then
1394 STIME=$(date +%s)
1395 EXPECT=0
1396 echo -e "Verify Adapters $PLUG"
1397 if [ "$WITH_SIM_ADAPTERS" == "yes" ]; then
1398 bspin - "Verify Simulated Adapters installed"
1399 if [ $(helm list --deployed --short --namespace voltha "^sim\$" | wc -l) -ne 1 ]; then
1400 espin - $NOT_VERIFIED
1401 helm_install - voltha sim $VOLTHA_ADAPTER_SIM_CHART $VOLTHA_ADAPTER_SIM_CHART_VERSION "Install Simulated Adapters"
1402 else
1403 espin - $VERIFIED
1404 fi
1405 EXPECT=$(expr $EXPECT + 2)
1406 fi
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001407
David Bainbridge46505fb2019-10-01 21:13:20 +00001408 if [ "$WITH_OPEN_ADAPTERS" == "yes" ]; then
1409 bspin - "Verify OpenOLT Adapter installed"
1410 if [ $(helm list --deployed --short --namespace voltha "^open-olt\$" | wc -l) -ne 1 ]; then
1411 espin - $NOT_VERIFIED
1412 helm_install - voltha open-olt $VOLTHA_ADAPTER_OPEN_OLT_CHART $VOLTHA_ADAPTER_OPEN_OLT_CHART_VERSION "Install OpenOLT Adapter"
1413 else
1414 espin - $VERIFIED
1415 fi
1416 bspin - "Verify OpenONU Adapter installed"
1417 if [ $(helm list --deployed --short --namespace voltha "^open-onu\$" | wc -l) -ne 1 ]; then
1418 espin - $NOT_VERIFIED
1419 helm_install - voltha open-onu $VOLTHA_ADAPTER_OPEN_ONU_CHART $VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION "Install OpenONU Adapter"
1420 else
1421 espin - $VERIFIED
1422 fi
1423 EXPECT=$(expr $EXPECT + 2)
1424 fi
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001425
David Bainbridge46505fb2019-10-01 21:13:20 +00001426 ADAPTERS="adapter-.*"
1427 wait_for_pods - "voltha" $EXPECT "includes" -1 "Waiting for adapters to start" $ADAPTERS
1428 if [ "$WITH_TIMINGS" == "yes" ]; then
1429 printtime $(expr $(date +%s) - $STIME)
1430 fi
David Bainbridgee87067b2019-08-12 22:00:12 +00001431fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001432
Test User7d866122019-07-09 17:52:35 +00001433if [ $WITH_BBSIM == "yes" ]; then
David Bainbridgee87067b2019-08-12 22:00:12 +00001434 STIME=$(date +%s)
Test User7d866122019-07-09 17:52:35 +00001435 echo -e "Verify BBSIM $PLUG"
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001436 bspin - "Verify BBSIM Installed"
David K. Bainbridge43422402020-03-06 07:41:22 -08001437 for instance in $(seq 0 $(($NUM_OF_BBSIM-1))); do
1438 if [ $instance -eq 0 ]; then
1439 instance_num=""
1440 else
1441 instance_num=$instance
1442 fi
1443 if [ $(helm list --deployed --short --namespace voltha "^bbsim${instance_num}\$" | wc -l) -ne 1 ]; then
1444 espin - $NOT_VERIFIED
David Bainbridge2eaf2cf2020-03-18 12:54:08 -07001445 INTERNAL_EXTRA_HELM_INSTALL_ARGS="--set olt_id=$instance"
David K. Bainbridge43422402020-03-06 07:41:22 -08001446 helm_install - voltha bbsim${instance_num} $VOLTHA_BBSIM_CHART $VOLTHA_BBSIM_CHART_VERSION "Install BBSIM${instance_num}"
David Bainbridge2eaf2cf2020-03-18 12:54:08 -07001447 INTERNAL_EXTRA_HELM_INSTALL_ARGS=
David K. Bainbridge43422402020-03-06 07:41:22 -08001448 else
1449 espin - $VERIFIED
1450 fi
1451 done
uottrembb16d3982020-02-28 08:34:36 +01001452 wait_for_pods - "voltha" $NUM_OF_BBSIM "includes" -1 "Waiting for BBSIM to start" "bbsim*"
David Bainbridgee87067b2019-08-12 22:00:12 +00001453 if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +00001454 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +00001455 fi
Test User7d866122019-07-09 17:52:35 +00001456fi
1457
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001458if [ $WITH_RADIUS == "yes" ]; then
David Bainbridgee87067b2019-08-12 22:00:12 +00001459 STIME=$(date +%s)
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001460 echo -e "Verify RADIUS $LOCK"
1461 bspin - "Verify RADIUS Installed"
1462 if [ $(helm list --deployed --short --namespace voltha "^radius\$" | wc -l) -ne 1 ]; then
1463 espin - $NOT_VERIFIED
David Bainbridge90fd8e32019-08-21 23:32:47 +00001464 helm_install - voltha radius onf/freeradius latest "Install RADIUS"
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001465 else
1466 espin - $VERIFIED
1467 fi
David Bainbridge4f1b5562019-08-19 04:46:52 +00001468 wait_for_pods - "voltha" 1 "includes" -1 "Waiting for RADIUS to start" "radius-.*"
David Bainbridgee87067b2019-08-12 22:00:12 +00001469 if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +00001470 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +00001471 fi
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001472fi
1473
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -08001474if [ $WITH_PORT_FORWARDS == "yes" ]; then
1475 STIME=$(date +%s)
1476 bspin - "Forward VOLTHA API port $FORWARD"
1477 kill_port_forward voltha-api
1478 port_forward voltha voltha-api $VOLTHA_API_PORT 55555
1479 espin - $VERIFIED
1480 bspin - "Forward VOLTHA ETCD port $FORWARD"
1481 kill_port_forward voltha-etcd-cluster-client
1482 port_forward voltha voltha-etcd-cluster-client $VOLTHA_ETCD_PORT 2379
1483 espin - $VERIFIED
1484 bspin - "Forward VOLTHA Kafka port $FORWARD"
1485 kill_port_forward voltha-kafka
1486 port_forward voltha voltha-kafka $VOLTHA_KAFKA_PORT 9092
1487 espin - $VERIFIED
1488 if [ "$WITH_TIMINGS" == "yes" ]; then
1489 printtime $(expr $(date +%s) - $STIME)
1490 fi
David Bainbridgee87067b2019-08-12 22:00:12 +00001491fi
Test User3d7ad8e2019-07-03 06:15:44 +00001492
David Bainbridgeb270c202019-07-26 01:44:42 +00001493if [ $WITH_ONOS == "yes" -a $WITH_RADIUS == "yes" ]; then
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001494 bspin "Configure ONOS RADIUS Connection $GEAR"
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -08001495 (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 +00001496 espin $VERIFIED
1497fi
1498
David Bainbridge99ac7a22019-08-31 02:26:43 +00001499if [ "$WITH_CHAOS" == "yes" ]; then
1500 STIME=$(date +%s)
1501 echo -e "Verify kube-monkey $LOCK"
1502 bspin - "Verify kube-monkey Installed"
1503 if [ $(helm list --deployed --short --namespace kube-monkey "^monkey\$" | wc -l) -ne 1 ]; then
1504 espin - $NOT_VERIFIED
1505 helm_install - kube-monkey monkey ./kube-monkey/helm/kubemonkey latest "Install Chaos Monkey"
1506 else
1507 espin - $VERIFIED
1508 fi
1509 wait_for_pods - "kube-monkey" 1 "includes" -1 "Waiting for Chaos to start" "monkey-.*"
1510 if [ "$WITH_TIMINGS" == "yes" ]; then
1511 printtime $(expr $(date +%s) - $STIME)
1512 fi
1513fi
1514
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001515bspin "Create voltctl configuration file"
Test User3d7ad8e2019-07-03 06:15:44 +00001516(set -x; mkdir -p $HOME/.volt >>$LOG 2>&1) >>$LOG 2>&1
David K. Bainbridgeb859e912020-03-13 14:07:52 -07001517MIN_VC_VERSION=$(echo -e "1.0.15\n$VC_VERSION" | sort -V | head -1)
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -08001518if [ $WITH_PORT_FORWARDS == "yes" ]; then
David K. Bainbridgeb859e912020-03-13 14:07:52 -07001519 KAFKA_FLAG="-k localhost:$VOLTHA_KAFKA_PORT"
1520 SERVER_FLAG="-s localhost:$VOLTHA_API_PORT"
1521 ETCD_FLAG=
1522 if [ "$MIN_VC_VERSION" == "1.0.15" ]; then
1523 ETCD_FLAG="-e localhost:$VOLTHA_ETCD_PORT"
1524 fi
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -08001525else
David K. Bainbridgeb859e912020-03-13 14:07:52 -07001526 KAFKA_FLAG="-k $(get_service_ep voltha voltha-kafka)"
1527 SERVER_FLAG="-s $(get_service_ep voltha voltha-api)"
1528 ETCD_FLAG=
1529 if [ "$MIN_VC_VERSION" == "1.0.15" ]; then
1530 ETCD_FLAG="-e $(get_service_ep voltha voltha-etcd-client)"
1531 fi
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -08001532fi
David K. Bainbridgeb859e912020-03-13 14:07:52 -07001533(set -x; voltctl -a v3 $KAFKA_FLAG $SERVER_FLAG $ETCD_FLAG config > $HOME/.volt/config-$NAME 2>>$LOG) >>$LOG 2>&1
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001534espin $VERIFIED
Test User08ebbd92019-07-03 17:15:39 +00001535
David Bainbridge0774b232019-08-02 06:37:19 +00001536if [ ! -f "$NAME-env.sh" ]; then
1537 touch $NAME-env.sh
David Bainbridgeb07fdf72019-07-29 22:51:40 +00001538fi
1539
David Bainbridge596f30d2019-07-30 17:07:59 +00001540for O in $ALL_OPTIONS; do
1541 VAL=$(eval echo \$$O)
David Bainbridge0774b232019-08-02 06:37:19 +00001542 if [ ! -z "$VAL" -a $(grep -c "^export $O=" $NAME-env.sh) -eq 0 ]; then
1543 echo "export $O=\"$(eval echo \$$O)\"" >> $NAME-env.sh
David Bainbridgeb07fdf72019-07-29 22:51:40 +00001544 fi
1545done
1546
David Bainbridge0774b232019-08-02 06:37:19 +00001547if [ $DEPLOY_K8S == "yes" -a $(grep -c "^export KUBECONFIG=" $NAME-env.sh) -eq 0 ]; then
1548 echo "export KUBECONFIG=\"$(./bin/kind get kubeconfig-path --name=voltha-$NAME)\"" >> $NAME-env.sh
David Bainbridgeb07fdf72019-07-29 22:51:40 +00001549fi
1550
David Bainbridge0774b232019-08-02 06:37:19 +00001551if [ $(grep -c "^export VOLTCONFIG=" $NAME-env.sh) -eq 0 ]; then
1552 echo "export VOLTCONFIG=\"$HOME/.volt/config-$NAME\"" >> $NAME-env.sh
David Bainbridgeb07fdf72019-07-29 22:51:40 +00001553fi
1554
David Bainbridge0774b232019-08-02 06:37:19 +00001555if [ $(grep -c "^export PATH=" $NAME-env.sh) -eq 0 ]; then
1556 echo "export PATH=\"$GOPATH/bin:\$PATH\"" >> $NAME-env.sh
David Bainbridgeb07fdf72019-07-29 22:51:40 +00001557fi
1558
Test User7d866122019-07-09 17:52:35 +00001559echo ""
Test User08ebbd92019-07-03 17:15:39 +00001560echo "Please issue the following commands in your terminal to ensure that you" | tee -a $LOG
1561echo "are accessing the correct Kubernetes/Kind cluster as well as have the " | tee -a $LOG
1562echo "tools required by VOLTHA in your command path. " | tee -a $LOG
1563echo "" | tee -a $LOG
Test User7d866122019-07-09 17:52:35 +00001564echo -en $BOLD
Test Userba1e7e72019-07-10 22:27:54 +00001565if [ $DEPLOY_K8S == "yes" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +00001566 echo "export KUBECONFIG=\"\$(./bin/kind get kubeconfig-path --name=\"voltha-$NAME\")\"" | tee -a $LOG
Test Userba1e7e72019-07-10 22:27:54 +00001567fi
David Bainbridge0774b232019-08-02 06:37:19 +00001568echo "export VOLTCONFIG=\"$HOME/.volt/config-$NAME\"" | tee -a $LOG
Test Userba1e7e72019-07-10 22:27:54 +00001569echo "export PATH=$GOPATH/bin:\$PATH" | tee -a $LOG
Test User7d866122019-07-09 17:52:35 +00001570echo -en $NORMAL
Test User08ebbd92019-07-03 17:15:39 +00001571echo "" | tee -a $LOG
1572echo "Thank you for choosing kind-voltha for you quick cluster needs." | tee -a $LOG
1573
David Bainbridge712afb82019-08-14 19:55:58 +00001574if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridgef858a022019-08-14 21:25:11 +00001575 echo -e "$CLOCK ${BOLD}TOTAL: $(duration $(expr $(date +%s) - $TOTAL_START_TIME))${NORMAL}"
David Bainbridge712afb82019-08-14 19:55:58 +00001576fi