blob: 983882e90039631fdd1f91911743d95ce7cdce4e [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 Bainbridge5b7b96b2019-07-25 20:29:13 +000097VOLTHA_LOG_LEVEL=${VOLTHA_LOG_LEVEL:-WARN}
David Bainbridge90fd8e32019-08-21 23:32:47 +000098VOLTHA_CHART=${VOLTHA_CHART:-onf/voltha}
99VOLTHA_CHART_VERSION=${VOLTHA_CHART_VERSION:-latest}
100VOLTHA_BBSIM_CHART=${VOLTHA_BBSIM_CHART:-onf/bbsim}
Matteo Scandolodcd29f52019-10-07 15:42:42 -0700101VOLTHA_BBSIM_CHART_VERSION=${VOLTHA_BBSIM_CHART_VERSION:-latest}
David Bainbridgee10f6d52019-07-25 00:28:13 +0000102VOLTHA_ADAPTER_SIM_CHART=${VOLTHA_ADAPTER_SIM_CHART:-onf/voltha-adapter-simulated}
David Bainbridge90fd8e32019-08-21 23:32:47 +0000103VOLTHA_ADAPTER_SIM_CHART_VERSION=${VOLTHA_ADAPTER_SIM_CHART_VERSION:-latest}
David Bainbridgee10f6d52019-07-25 00:28:13 +0000104VOLTHA_ADAPTER_OPEN_OLT_CHART=${VOLTHA_ADAPTER_OPEN_OLT_CHART:-onf/voltha-adapter-openolt}
David Bainbridge90fd8e32019-08-21 23:32:47 +0000105VOLTHA_ADAPTER_OPEN_OLT_CHART_VERSION=${VOLTHA_ADAPTER_OPEN_OLT_CHART_VERSION:-latest}
David Bainbridgee10f6d52019-07-25 00:28:13 +0000106VOLTHA_ADAPTER_OPEN_ONU_CHART=${VOLTHA_ADAPTER_OPEN_ONU_CHART:-onf/voltha-adapter-openonu}
David Bainbridge90fd8e32019-08-21 23:32:47 +0000107VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION=${VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION:-latest}
David K. Bainbridgeda33d652020-03-06 10:31:23 -0800108ONOS_CHART=${ONOS_CHART:-onf/onos}
Andrea Campanella21323292019-12-18 11:44:19 -0800109ONOS_CHART_VERSION=${ONOS_CHART_VERSION:-latest}
David Bainbridge2eaf2cf2020-03-18 12:54:08 -0700110EXTRA_HELM_INSTALL_ARGS=${EXTRA_HELM_INSTALL_ARGS:-}
111INTERNAL_EXTRA_HELM_INSTALL_ARGS=
uottrembb16d3982020-02-28 08:34:36 +0100112NUM_OF_BBSIM=${NUM_OF_BBSIM:-1}
113MAX_NUM_OF_BBSIM=10
Test Userba1e7e72019-07-10 22:27:54 +0000114
115HAVE_GO=$(which go >/dev/null 2>&1 && echo "yes" || echo "no")
116HOSTOS=$(uname -s | tr "[:upper:]" "[:lower:"])
117HOSTARCH=$(uname -m | tr "[:upper:]" "[:lower:"])
118if [ $HOSTARCH == "x86_64" ]; then
119 HOSTARCH="amd64"
120fi
Test User7d866122019-07-09 17:52:35 +0000121
uottrembb16d3982020-02-28 08:34:36 +0100122# check number (range) of bbsim, max bbsim must not exceed 10 instances!
123# note: instances will be numbered from 0 to 9
124if [ "$1" == "up" ]; then
David K. Bainbridge43422402020-03-06 07:41:22 -0800125 if [ "$NUM_OF_BBSIM" -lt 1 ]; then
126 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} Invalid setting of BBSIM instances. NUM_OF_BBSIM is less than 1${NORMAL}"
127 exit 1
128 fi
129 if [ "$NUM_OF_BBSIM" -gt $MAX_NUM_OF_BBSIM ]; then
130 >&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}"
131 exit 1
132 fi
uottrembb16d3982020-02-28 08:34:36 +0100133fi
Test User7d866122019-07-09 17:52:35 +0000134# Verify TYPE setting
135if [ $(echo ":minimal:full:" | grep -ic ":$TYPE:") -eq 0 ]; then
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700136 >&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 +0000137 exit 1
138fi
139
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -0800140function get_service_ep() {
141 local NS=$1
142 local NAME=$2
143 kubectl -n $NS get service $NAME -o json | jq -r '.spec.clusterIP + ":" + (.spec.ports[0].port|tostring)'
144}
145
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000146# Used to verify configuration values are set to "yes" or "no" value or convert
147# equivalents to "yes" or "no"
148function verify_yes_no() {
149 local VAR=$1
150 local VAL=$(eval echo \$$VAR)
151 if [ $(echo ":y:yes:true:n:no:false:1:0:" | grep -ic ":$VAL:") -eq 0 ]; then
152 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} Invalid '$VAR' value of '$VAL'. Should be 'yes' or 'no'${NORMAL}"
153 echo "INVALID"
154 return 1
155 fi
156 if [ $(echo ":y:yes:true:1:" | grep -ic ":$VAL:") -eq 1 ]; then
157 echo "yes"
158 else
159 echo "no"
160 fi
161 return 0
162}
Test User7d866122019-07-09 17:52:35 +0000163
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000164ALL_YES_NO="\
David K. Bainbridge484d80c2020-03-05 21:44:34 -0800165 ENABLE_ONOS_EXTRANEOUS_RULES \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000166 WITH_TIMINGS \
167 WITH_BBSIM \
168 WITH_RADIUS \
Matteo Scandolo78dfee02020-02-13 16:18:03 -0800169 WITH_EAPOL \
170 WITH_DHCP \
171 WITH_IGMP \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000172 WITH_ONOS \
David Bainbridge99ac7a22019-08-31 02:26:43 +0000173 WITH_CHAOS \
David Bainbridge46505fb2019-10-01 21:13:20 +0000174 WITH_ADAPTERS \
175 WITH_SIM_ADAPTERS \
176 WITH_OPEN_ADAPTERS \
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -0800177 WITH_PORT_FORWARDS \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000178 JUST_K8S \
179 DEPLOY_K8S \
180 INSTALL_ONOS_APPS \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000181 INSTALL_KUBECTL \
182 INSTALL_HELM \
David Bainbridge46505fb2019-10-01 21:13:20 +0000183 UPDATE_HELM_REPOS \
David Bainbridge4f1b5562019-08-19 04:46:52 +0000184 WAIT_ON_DOWN \
David Bainbridge70c0ea82019-11-14 23:25:26 +0000185 ONLY_ONE \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000186 "
David Bainbridge5b7b96b2019-07-25 20:29:13 +0000187
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000188ALL_OPTIONS="\
189 NAME \
190 TYPE \
191 $ALL_YES_NO \
192 VOLTHA_LOG_LEVEL \
193 VOLTHA_CHART \
David Bainbridge90fd8e32019-08-21 23:32:47 +0000194 VOLTHA_CHART_VERSION \
195 VOLTHA_BBSIM_CHART \
196 VOLTHA_BBSIM_CHART_VERSION \
uottrembd5a20572020-03-06 09:15:01 +0100197 NUM_OF_BBSIM \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000198 VOLTHA_ADAPTER_SIM_CHART \
David Bainbridge90fd8e32019-08-21 23:32:47 +0000199 VOLTHA_ADAPTER_SIM_CHART_VERSION \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000200 VOLTHA_ADAPTER_OPEN_OLT_CHART \
David Bainbridge90fd8e32019-08-21 23:32:47 +0000201 VOLTHA_ADAPTER_OPEN_OLT_CHART_VERSION \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000202 VOLTHA_ADAPTER_OPEN_ONU_CHART \
David Bainbridge90fd8e32019-08-21 23:32:47 +0000203 VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION \
David K. Bainbridgeda33d652020-03-06 10:31:23 -0800204 ONOS_CHART \
Andrea Campanella21323292019-12-18 11:44:19 -0800205 ONOS_CHART_VERSION \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000206 ONOS_API_PORT \
207 ONOS_SSH_PORT \
David K. Bainbridgeb859e912020-03-13 14:07:52 -0700208 CONFIG_SADIS \
Hardik Windlassb3147602020-03-09 16:59:15 +0530209 SADIS_CFG \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000210 VOLTHA_API_PORT \
211 VOLTHA_SSH_PORT \
212 VOLTHA_ETCD_PORT \
David K. Bainbridge00ecd382020-02-28 12:31:58 -0800213 VOLTHA_KAFKA_PORT \
David K. Bainbridge8f7f30b2020-01-08 13:06:16 -0800214 VK_RELEASE \
215 KIND_VERSION \
216 VOLTCTL_VERSION \
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000217 "
David Bainbridge01294952019-07-30 19:33:45 +0000218
David Bainbridge2a0b8a42019-08-16 17:39:29 +0000219# Iterate over yes/no configuration options and validate
220for VAR in $ALL_YES_NO; do
221 eval $VAR=$(verify_yes_no $VAR)
222 if [ "$(eval echo \$$VAR)" == "INVALID" ]; then
223 exit 1;
224 fi
225done
David Bainbridgeb270c202019-07-26 01:44:42 +0000226
David K. Bainbridgeda33d652020-03-06 10:31:23 -0800227# Check for prerequiste tools
David K. Bainbridge726ff6a2020-03-06 11:09:50 -0800228TOOLS="curl sed jq"
David K. Bainbridgeda33d652020-03-06 10:31:23 -0800229if [ $DEPLOY_K8S == "yes" ]; then
230 TOOLS+=" docker"
231fi
232NOT_FOUND=""
233for T in $TOOLS; do
234 if [ -z "$(which $T)" ]; then
235 NOT_FOUND+=" $T"
236 fi
237done
238
239if [ ! -z "$NOT_FOUND" ]; then
240 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} The following required tools where not found, please install them:$NOT_FOUND"
241 exit 1
242fi
243
David Bainbridge0774b232019-08-02 06:37:19 +0000244mkdir -p .voltha
245touch .voltha/ports
246HAVE=$(grep $NAME .voltha/ports)
247if [ "$HAVE X" == " X" ]; then
248 # Find free port prefix
249 START=81
250 while true; do
251 if [ $(grep -c $START .voltha/ports) -eq 0 ]; then
252 break
253 fi
254 START=$(expr $START + 1)
255 done
256 DELTA=$(expr $START - 81)
David Bainbridgea2595422019-10-22 03:54:28 +0000257 ONOS_API_PORT=${ONOS_API_PORT:-${START}81}
258 ONOS_SSH_PORT=${ONOS_SSH_PORT:-${START}01}
259 VOLTHA_API_PORT=${VOLTHA_API_PORT:-5$(expr 55 + $DELTA)55}
260 VOLTHA_SSH_PORT=${VOLTHA_SSH_PORT:-$(expr 50 + $DELTA)22}
261 VOLTHA_ETCD_PORT=${VOLTHA_ETCD_PORT:-$(expr 23 + $DELTA)79}
David K. Bainbridge00ecd382020-02-28 12:31:58 -0800262 VOLTHA_KAFKA_PORT=${VOLTHA_KAFKA_PORT:-$(expr 90 + $DELTA)92}
Test User01ed0642019-07-03 20:17:06 +0000263else
David Bainbridge0774b232019-08-02 06:37:19 +0000264 VALUES=$(echo $HAVE | sed -e 's/\s//g' | cut -d= -f2)
David Bainbridgea2595422019-10-22 03:54:28 +0000265 ONOS_API_PORT=${ONOS_API_PORT:-$(echo $VALUES | cut -d, -f1)}
266 ONOS_SSH_PORT=${ONOS_SSH_PORT:-$(echo $VALUES | cut -d, -f2)}
267 VOLTHA_API_PORT=${VOLTHA_API_PORT:-$(echo $VALUES | cut -d, -f3)}
268 VOLTHA_SSH_PORT=${VOLTHA_SSH_PORT:-$(echo $VALUES | cut -d, -f4)}
269 VOLTHA_ETCD_PORT=${VOLTHA_ETCD_PORT:-$(echo $VALUES | cut -d, -f5)}
David K. Bainbridge00ecd382020-02-28 12:31:58 -0800270 VOLTHA_KAFKA_PORT=${VOLTHA_KAFKA_PORT:-$(echo $VALUES | cut -d, -f6)}
271
David K. Bainbridge00ecd382020-02-28 12:31:58 -0800272 # A bit of a hueristic required here as the KAFKA port forward was
273 # added after the .voltha/ports files was created. Basically, if
274 # the VOLTHA_KAFKA_PORT isn't in the file then calculate the original
275 # DELTA from the VOLTHA_SSH_PORT and apply it to the VOLTHA_KAFKA_PORT
276 if [ -z "$VOLTHA_KAFKA_PORT" ]; then
277 DELTA=$((VOLTHA_SSH_PORT/100-50))
278 VOLTHA_KAFKA_PORT=${VOLTHA_KAFKA_PORT:-$(expr 90 + $DELTA)92}
279 fi
Test User01ed0642019-07-03 20:17:06 +0000280fi
281
David Bainbridge0774b232019-08-02 06:37:19 +0000282PORTTMP=$(mktemp -u)
283cat .voltha/ports | grep -v $NAME > $PORTTMP
David K. Bainbridge00ecd382020-02-28 12:31:58 -0800284echo "$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 +0000285cp $PORTTMP .voltha/ports
286rm -f $PORTTMP
287
David Bainbridge27790d62019-08-13 22:43:19 +0000288export ONOS_API_PORT ONOS_SSH_PORT
David Bainbridge01294952019-07-30 19:33:45 +0000289
Test Userd87942b2019-07-03 07:20:24 +0000290IDX=1
David Bainbridgee87067b2019-08-12 22:00:12 +0000291CLOCK="TIME:"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000292SPIN_PARTS=
293NOT_VERIFIED=
David Bainbridgef858a022019-08-14 21:25:11 +0000294THEX=
295BUILD=
296CROSS=
297ENTER=
David Bainbridge38dc1e82019-08-12 15:18:45 +0000298VERIFIED=
299HELM=
300OLD_KEY=
301BIRD=
302HIGH_VOLTAGE=
303PLUG=
304RESTART=
305FORWARD=
306INSTALL=
307STOP=
308GO=
309DOWNLOAD=
310GEAR=
311NO_ENTRY=
312LOCK=
313
314if [ $FANCY -eq 1 ]; then
315 SPIN_PARTS="\
316 \xe2\xa2\x8e\xe2\xa1\xb0 \
317 \xe2\xa2\x8e\xe2\xa1\xa1 \
318 \xe2\xa2\x8e\xe2\xa1\x91 \
319 \xe2\xa2\x8e\xe2\xa0\xb1 \
320 \xe2\xa0\x8e\xe2\xa1\xb1 \
321 \xe2\xa2\x8a\xe2\xa1\xb1 \
322 \xe2\xa2\x8c\xe2\xa1\xb1 \
323 \xe2\xa2\x86\xe2\xa1\xb1 \
324 "
David Bainbridgee87067b2019-08-12 22:00:12 +0000325 CLOCK="\xe2\x8f\xb1"
David Bainbridgef858a022019-08-14 21:25:11 +0000326 THEX="${RED}${BOLD}\xe2\x9c\x97\x20${NORMAL}"
327 ENTER="${YELLOW}${BOLD}\xe2\x8e\x86${NORMAL}"
328 CROSS="${YELLOW}${BOLD}\xe2\x9c\x9a${NORMAL}"
329 BUILD="${YELLOW}${BOLD}\xf0\x9f\x8f\x97${NORMAL}"
330 NOT_VERIFIED="$BUILD"
331 VERIFIED="${GREEN}${BOLD}\xe2\x9c\x93\x20${NORMAL}"
332 HELM="${BLUE}${BOLD}\xE2\x8E\x88${NORMAL}"
David Bainbridge38dc1e82019-08-12 15:18:45 +0000333 OLD_KEY="\xF0\x9F\x97\x9D"
334 BIRD="\xF0\x9F\x90\xA6"
335 HIGH_VOLTAGE="\xE2\x9A\xA1"
336 PLUG="\xF0\x9F\xa7\xa9"
337 RESTART="\xf0\x9f\x94\x84"
338 FORWARD="\xE2\x87\xA8"
339 INSTALL="\xF0\x9F\x8F\x97"
340 STOP="\xf0\x9f\x9b\x91"
341 GO="\xf0\x9f\x9a\x80"
342 DOWNLOAD="\xf0\x9f\x93\xa5"
343 GEAR="\xe2\x9a\x99"
344 NO_ENTRY="\xe2\x9b\x94"
345 LOCK="\xf0\x9f\x94\x92"
346fi
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700347
David Bainbridge712afb82019-08-14 19:55:58 +0000348duration() {
David Bainbridgee87067b2019-08-12 22:00:12 +0000349 local h=$(expr $1 / 3600)
350 local m=$(expr $1 % 3600 / 60)
351 local s=$(expr $1 % 60)
352 local t=""
353
354 if [ $h -gt 0 ]; then
355 t="$t${h}h"
356 fi
357 if [ $m -gt 0 ]; then
358 t="$t${m}m"
359 fi
David Bainbridge712afb82019-08-14 19:55:58 +0000360 echo "$t${s}s"
361}
362
363printtime() {
364 local INDENT=
365 if [ "$1" == "-" ]; then
366 INDENT=" "
367 shift
368 fi
369 echo -e "$INDENT $CLOCK $(duration $1)"
David Bainbridgee87067b2019-08-12 22:00:12 +0000370}
371
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700372bspin() {
Test Userd87942b2019-07-03 07:20:24 +0000373 IDX=1
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700374 local INDENT=
375 if [ "$1" == "-" ]; then
376 INDENT=" "
377 shift
378 fi
David Bainbridge38dc1e82019-08-12 15:18:45 +0000379 if [ $FANCY -eq 0 ]; then
380 LINE=$(echo $* | sed -e 's/[\s+-]//g')
381 if [ "$LINE X" == " X" ]; then
382 return
383 fi
384 echo -e "$CIVIS$INDENT$*"
385 else
386 echo -en "$CIVIS$INDENT $*"
387 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700388}
389
390sspin() {
391 local INDENT=
392 if [ "$1" == "-" ]; then
393 INDENT=" "
394 shift
395 fi
David Bainbridge38dc1e82019-08-12 15:18:45 +0000396 if [ $FANCY -eq 0 ]; then
397 LINE=$(echo $* | sed -e 's/[\s+-]//g')
398 if [ "$LINE X" == " X" ]; then
399 return
400 fi
401 echo -e "$INDENT$*"
402 else
403 C=$(echo $SPIN_PARTS | cut '-d ' -f $IDX)
404 echo -en "\r$INDENT$C $*"
405 IDX=$(expr $IDX + 1)
406 if [ $IDX -gt 8 ]; then
407 IDX=1
408 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700409 fi
410}
411
412espin() {
413 local INDENT=
414 if [ "$1" == "-" ]; then
415 INDENT=" "
416 shift
417 fi
David Bainbridge38dc1e82019-08-12 15:18:45 +0000418 if [ $FANCY -eq 0 ]; then
419 LINE=$(echo $* | sed -e 's/[\s+-]//g')
420 if [ "$LINE X" == " X" ]; then
421 return
422 fi
423 echo -e "$INDENT$*"
424 else
425 echo -e "\r$INDENT$*$CNORM"
426 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700427}
428
David Bainbridgeac7f8072019-08-01 22:15:33 +0000429if [ "$1" == "get" -a "$2" == "voltconfig" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000430 echo "$HOME/.volt/config-$NAME"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000431 exit
432fi
433
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -0700434if [ $# -ne 1 -o $(echo ":up:down:dump:" | grep -c ":$1:") -ne 1 ]; then
David Bainbridgeac7f8072019-08-01 22:15:33 +0000435 >&2 echo "What wouild you like to do today:"
436 >&2 echo " up - bring up voltha"
437 >&2 echo " down - tear down voltha"
438 >&2 echo " dump - create a debug dump of running system"
439 exit 1
440fi
441
David Bainbridge4f1b5562019-08-19 04:46:52 +0000442push_onos_config() {
Matteo Scandolo78dfee02020-02-13 16:18:03 -0800443 local TYPE=$1
444 local MSG=$2
445 local RESOURCE=$3
446 local DATA=$4
David Bainbridge4f1b5562019-08-19 04:46:52 +0000447
David K. Bainbridgeb4b163b2020-02-19 15:55:06 -0800448 # Thanks to the latest version of ONOS using the return code 207 this gets a
449 # whole lot nastier. Can't thank them enough for doing this. So in order to
450 # capture the command and the output in the log file as well as capture the
451 # status code to verify it is 200 and not 207 mutltiple files and a bit of
452 # hackery must be used. Thanks again ONOS.
453 local CMD_ECHO=$(mktemp -u)
454 local CMD_OUTPUT=$(mktemp -u)
455 local SC_OUTPUT=$(mktemp -u)
456
David Bainbridge4f1b5562019-08-19 04:46:52 +0000457 bspin - "$MSG $GEAR"
458 while true; do
Matteo Scandolo78dfee02020-02-13 16:18:03 -0800459 if [ $TYPE == "file" ]; then
David K. Bainbridgeb859e912020-03-13 14:07:52 -0700460 (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
461 RESULT=$?
Matteo Scandolo78dfee02020-02-13 16:18:03 -0800462 fi
463 if [ $TYPE == "json" ]; then
David K. Bainbridgeb859e912020-03-13 14:07:52 -0700464 (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
465 RESULT=$?
Matteo Scandolo78dfee02020-02-13 16:18:03 -0800466 fi
David K. Bainbridgeb4b163b2020-02-19 15:55:06 -0800467 # Dump everything to the log
468 cat $CMD_ECHO >> $LOG
David K. Bainbridgeb859e912020-03-13 14:07:52 -0700469 test -r $CMD_OUTPUT && cat $CMD_OUTPUT >> $LOG
David K. Bainbridgeb4b163b2020-02-19 15:55:06 -0800470 SC=$(cat $SC_OUTPUT)
David K. Bainbridgeb859e912020-03-13 14:07:52 -0700471 echo "RESPONSE CODE: $SC" >> $LOG
472 echo "ERROR CODE: $RESULT" >> $LOG
David K. Bainbridgeb4b163b2020-02-19 15:55:06 -0800473
474 # clean up temp files
475 rm -f $CMD_ECHO $CMD_OUTPUT $SC_OUTPUT
476 if [ $RESULT -eq 0 -a "$SC" == "200" ]; then
David Bainbridge4f1b5562019-08-19 04:46:52 +0000477 break
478 fi
Matteo Scandolo9a77a732020-01-09 14:24:12 -0800479 sleep 1
David Bainbridge4f1b5562019-08-19 04:46:52 +0000480 sspin -
481 done
482 espin - $VERIFIED
483}
484
Matteo Scandolo9a77a732020-01-09 14:24:12 -0800485check_onos_app_active() {
486 local APP_ID=$1
487
488 bspin - "Checking that $APP_ID is active $CLOCK"
489 while true; do
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -0800490 (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 -0800491 if [ $? -eq 0 ]; then
492 break
493 fi
494 sleep 1
495 sspin -
496 done
497 sleep 5 # OSGI components take a little longer that the app to activate
498 espin - $VERIFIED
499}
500
David Bainbridge4f1b5562019-08-19 04:46:52 +0000501override_onos_app() {
502 local APP=$1
503 local NAME=$(basename $APP | sed -e 's/^[0-9][0-9]*-//g' -e 's/-.*$//g')
504 while true; do
505 sspin -
506 # Attempt to delete old version (if it exists)
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -0800507 (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 +0000508 sspin -
509 if [ $? -ne 0 ]; then
510 continue
511 fi
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -0800512 (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 +0000513 if [ $? -eq 0 ]; then
514 break
515 fi
516 sleep .2
517 done
518}
519
520activate_onos_app() {
521 local MSG="$1"
522 local APP=$2
523
524 bspin - "$MSG $GO"
525 while true; do
526 sspin -
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -0800527 (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 +0000528 if [ $? -eq 0 ]; then
529 break
530 fi
531 sleep .2
532 done
533 espin - "$VERIFIED"
534}
535
536count_pods() {
537 local NAMESPACE=$1; shift
538 if [ "$NAMESPACE" == "all-namespaces" ]; then
539 NAMESPACE="--all-namespaces"
540 else
541 NAMESPACE="-n $NAMESPACE"
542 fi
David Bainbridge4f1b5562019-08-19 04:46:52 +0000543 local STATES=$1; shift
David Bainbridge4f1b5562019-08-19 04:46:52 +0000544 local PODS=$(kubectl get $NAMESPACE pod -o go-template="{{range .items}}{{.metadata.name}}/{{.status.phase}}/_{{range .status.containerStatuses}}{{.ready}}_{{end}} {{end}}")
545 local COUNT=0
546 local PATTERNS="$*"
547 for POD in $PODS; do
548 local NAME=$(echo $POD | cut -d/ -f 1)
549 local STATE=$(echo $POD | cut -d/ -f 2)
550 local CONTAINERS=$(echo $POD | cut -d/ -f 3 | sed -e 's/_/ /g')
551 if [ "$STATES" == "*" -o $(echo "$STATES" | grep -c ":$STATE:") -ne 0 ]; then
David Bainbridge4f1b5562019-08-19 04:46:52 +0000552 local TOTAL=$(echo $CONTAINERS | wc -w)
553 local FOUND=$(echo $CONTAINERS | grep -o true | wc -l)
554 if [ $TOTAL -eq $FOUND ]; then
555 for PATTERN in $PATTERNS; do
David Bainbridge4f1b5562019-08-19 04:46:52 +0000556 if [[ $NAME =~ $PATTERN ]]; then
David Bainbridge4f1b5562019-08-19 04:46:52 +0000557 COUNT=$(expr $COUNT + 1)
558 break
559 fi
560 done
561 fi
562 fi
563 done
David Bainbridge4f1b5562019-08-19 04:46:52 +0000564 echo $COUNT
565}
566
567wait_for_pods() {
568 local INDENT=
569 if [ "$1" == "-" ]; then
570 INDENT=$1; shift
571 fi
572 local NAMESPACE=$1; shift
573 local EXPECT=$1; shift
574 local TYPE=$1; shift
575 local RETRY=$1; shift
576 local MESSAGE=$1; shift
577 local PATTERNS=$*
David Bainbridge99ac7a22019-08-31 02:26:43 +0000578 local STATES=":Running:"
579 if [ "$TYPE" == "not" ]; then
580 STATES="*"
581 fi
582 local HAVE=$(count_pods $NAMESPACE "$STATES" $PATTERNS)
David Bainbridge4f1b5562019-08-19 04:46:52 +0000583 local ALL=$HAVE
584 if [ "$TYPE" == "only" ]; then
585 ALL=$(count_pods "all-namespaces" "*" ".*")
586 fi
587 COUNT=$(expr 300 / 15)
588 bspin $INDENT $MESSAGE
589 sspin $INDENT
590 if [ $HAVE -ne $EXPECT -o $ALL -ne $HAVE ]; then
591 while [ $HAVE -ne $EXPECT -o $ALL -ne $HAVE ]; do
592 sspin $INDENT
593 COUNT=$(expr $COUNT - 1)
594 if [ $COUNT -eq 0 ]; then
David Bainbridge99ac7a22019-08-31 02:26:43 +0000595 HAVE=$(count_pods $NAMESPACE "$STATES" $PATTERNS)
David Bainbridge4f1b5562019-08-19 04:46:52 +0000596 ALL=$HAVE
597 if [ "$TYPE" == "only" ]; then
598 ALL=$(count_pods "all-namespaces" "*" ".*")
599 fi
600 COUNT=$(expr 300 / 15)
601 fi
602 sleep .15
603 done
604 fi
605 espin $INDENT $VERIFIED
606 if [ $HAVE -ne $EXPECT ]; then
607 return 1
608 fi
609 return 0
610}
611
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800612port_forward() {
613 local NS=$1
614 local SVC=$2
615 local FROM_PORT=$3
616 local TO_PORT=$4
617 local TAG=$SVC-$NAME
618
619 (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
620}
621
622kill_port_forward() {
623 local TAG=$1-$NAME
David Bainbridgec6871d22019-11-13 17:10:31 +0000624 local P_IDS=$(ps e -ww -A | grep "_TAG=$TAG" | grep -v grep | awk '{print $1}')
David Bainbridgebcf235b2019-11-12 21:33:58 +0000625 local PARENTS=
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800626 local KIDS=
David Bainbridgec6871d22019-11-13 17:10:31 +0000627 local UNKNOWN=
628 if [ ! -z "$P_IDS" ]; then
629 for P_ID in $P_IDS; do
630 local PP_ID=$(ps -o ppid $P_ID | tail -n +2)
631 if [ ! -z "$PP_ID" ]; then
632 if [ $PP_ID -eq 1 ]; then
633 PARENTS="$PARENTS $P_ID"
634 else
635 KIDS="$KIDS $P_ID"
636 fi
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800637 else
David Bainbridgec6871d22019-11-13 17:10:31 +0000638 UNKNOWN="$UNKNOWN $P_ID"
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800639 fi
640 done
David Bainbridgec6871d22019-11-13 17:10:31 +0000641 (set -x; kill -9 $PARENTS $KIDS $UNKNOWN >>$LOG 2>&1) >>$LOG 2>&1
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800642 fi
643}
644
David Bainbridgeac7f8072019-08-01 22:15:33 +0000645if [ "$1" == "down" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000646 echo "Tearing down voltha cluster $NAME"
647 LOG="down-$NAME.log"
648 echo $(date -u +"%Y%m%dT%H%M%SZ") >$LOG
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800649 bspin "Remove port-forwards: onos-ui-$NAME"
650 kill_port_forward onos-ui
651 sspin "Remove port-forwards: onos-ssh-$NAME$CEOL"
652 kill_port_forward onos-ssh
653 sspin "Remove port-forwards: voltha-api-$NAME$CEOL"
654 kill_port_forward voltha-api
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800655 sspin "Remove port-forwards: voltha-etcd-$NAME$CEOL"
656 kill_port_forward voltha-etcd-cluster-client
David K. Bainbridge00ecd382020-02-28 12:31:58 -0800657 sspin "Remove port-forwards: voltha-kafka-$NAME$CEOL"
658 kill_port_forward voltha-kafka
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800659 espin "$VERIFIED Remove port-forwards$CEOL"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000660 if [ $DEPLOY_K8S == "yes" ]; then
661 if [ -x ./bin/kind ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000662 bspin "Delete Kubernetes Kind Cluster"
663 (set -x; ./bin/kind delete cluster --name voltha-$NAME >>$LOG 2>&1) >>$LOG 2>&1
664 espin $VERIFIED
David Bainbridgeac7f8072019-08-01 22:15:33 +0000665 else
David Bainbridge0774b232019-08-02 06:37:19 +0000666 espin "$NO_ENTRY Delete Kubernetes Kind Cluster: kind command not found"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000667 fi
668 else
669 EXISTS=$(helm list -q)
670 EXPECT="etcd-operator onos open-olt open-onu sim voltha bbsim radius"
David Bainbridge0774b232019-08-02 06:37:19 +0000671 bspin "Remove Helm Deployments"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000672 for i in $EXISTS; do
David K. Bainbridge43422402020-03-06 07:41:22 -0800673 for j in $EXPECT; do
674 if [[ $i =~ $j ]]; then
675 sspin "Remove Helm Deployments: $i$CEOL"
676 (set -x; ./bin/helm delete --no-hooks --purge $i >>$LOG 2>&1) >>$LOG 2>&1
677 fi
678 done
uottrembb16d3982020-02-28 08:34:36 +0100679 done
David Bainbridge0774b232019-08-02 06:37:19 +0000680 espin "$VERIFIED Remove Helm Deployments$CEOL"
David Bainbridge4f1b5562019-08-19 04:46:52 +0000681 if [ "$WAIT_ON_DOWN" == "yes" ]; then
682 # There should only be 13 or 15 PODs in the kube-system name
683 # space and no other PODs
David Bainbridge4f1b5562019-08-19 04:46:52 +0000684 PODS="coredns-.* \
685 etcd-voltha-$NAME-control-plane \
686 kindnet-.* \
687 kube-apiserver-voltha-$NAME-control-plane \
688 kube-controller-manager-voltha-$NAME-control-plane \
689 kube-proxy-.* \
690 kube-scheduler-voltha-$NAME-control-plane \
691 tiller-deploy-.*"
692 EXPECT=$(test "$TYPE" == "minimal" && echo "13" || echo "15")
David Bainbridge99ac7a22019-08-31 02:26:43 +0000693 PODS="adapter-.* \
694 bbsim.* \
695 etcd-operator.* \
696 radius.* \
697 voltha-.*"
Matteo Scandolo73442f92020-01-29 09:53:22 -0800698
David Bainbridge99ac7a22019-08-31 02:26:43 +0000699 EXPECT=0
700
Matteo Scandolo73442f92020-01-29 09:53:22 -0800701 if [ "$WITH_ONOS" == "yes" ]; then
702 ONOS_PODS="onos-.*"
703 wait_for_pods "default" $EXPECT "not" -1 "Waiting for ONOS PODs to terminate" $ONOS_PODS
704 fi
David Bainbridge99ac7a22019-08-31 02:26:43 +0000705 wait_for_pods "voltha" $EXPECT "not" -1 "Waiting for VOLTHA PODs to terminate" $PODS
David Bainbridge4f1b5562019-08-19 04:46:52 +0000706 fi
David Bainbridgeac7f8072019-08-01 22:15:33 +0000707 fi
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -0700708 exit
David Bainbridgeac7f8072019-08-01 22:15:33 +0000709fi
710
711if [ "$1" == "dump" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000712 LOG="dump-$NAME.log"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000713 TS=$(date -u +"%Y%m%dT%H%M%SZ")
David Bainbridge76514a02019-10-08 01:50:35 +0000714 if [ ! -z "$DUMP_FROM" ]; then
715 TS=$(echo $DUMP_FROM | sed -e 's/[:-]//g')
716 fi
David Bainbridgeac7f8072019-08-01 22:15:33 +0000717 WORK=$(mktemp -u -d)
David Bainbridge0774b232019-08-02 06:37:19 +0000718 DATA=$WORK/voltha-debug-dump-$NAME-$TS
David Bainbridgeac7f8072019-08-01 22:15:33 +0000719 mkdir -p $DATA
720 echo $TS > $LOG
David Bainbridge0774b232019-08-02 06:37:19 +0000721 echo -e "Capturing debug dump to voltha-debug-dump-$NAME-$TS.tgz"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000722 bspin - "Copy install log"
David Bainbridge0774b232019-08-02 06:37:19 +0000723 if [ -f install-$NAME.log ]; then
724 (set -x; cp install-$NAME.log $DATA/install-$NAME.log) >>$LOG 2>&1
David Bainbridgeac7f8072019-08-01 22:15:33 +0000725 espin - $VERIFIED
726 else
David Bainbridge0774b232019-08-02 06:37:19 +0000727 espin - "$NO_ENTRY Copy install log: install-$NAME.log not found"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000728 fi
729 bspin - "Dumping Kubernetes PODs"
730 (set -x; kubectl get --all-namespaces pods >> $DATA/all-pods.txt 2>&1) >>$LOG 2>&1
731 espin - $VERIFIED
732 bspin - "Dumping Kubernetes SERVICEs"
733 (set -x; kubectl get --all-namespaces svc >> $DATA/all-services.txt 2>&1) >>$LOG 2>&1
734 espin - $VERIFIED
735 bspin - "Dumping Kubernetes EVENTs"
736 (set -x; kubectl get --all-namespaces events >> $DATA/all-events.txt 2>&1) >>$LOG 2>&1
737 espin - $VERIFIED
738 bspin - "Dumping VOLTHA POD details"
Matteo Scandolodcd29f52019-10-07 15:42:42 -0700739 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 +0000740 SINCE=
741 if [ ! -z "$DUMP_FROM" ]; then
742 SINCE="--since-time=$DUMP_FROM"
743 fi
David Bainbridgeac7f8072019-08-01 22:15:33 +0000744 for POD in $PODS; do
David Bainbridge1f0655a2019-10-01 22:08:48 +0000745 NS=$(echo $POD | cut -d: -f1)
746 POD=$(echo $POD | cut -d: -f2)
David Bainbridgeac7f8072019-08-01 22:15:33 +0000747 sspin - "Dumping VOLTHA POD details: $POD$CEOL"
748 mkdir -p $DATA/$POD
David Bainbridge1f0655a2019-10-01 22:08:48 +0000749 (set -x; kubectl describe -n $NS $POD >> $DATA/$POD/describe.txt 2>&1) >>$LOG 2>&1
David Bainbridgeac7f8072019-08-01 22:15:33 +0000750 sspin - "Dumping VOLTHA POD details: $POD"
David Bainbridgecfd7ca12019-10-06 03:31:41 +0000751 (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 +0000752 sspin - "Dumping VOLTHA POD details: $POD"
David Bainbridgecfd7ca12019-10-06 03:31:41 +0000753 (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 +0000754 sspin - "Dumping VOLTHA POD details: $POD"
755 done
756 espin - "$VERIFIED Dumping VOLTHA POD details$CEOL"
757 bspin - "Dumping ETCD"
758 if [ "$(which etcdctl) X" != " X" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000759 (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 +0000760 espin - $VERIFIED
761 else
762 espin - "$NO_ENTRY Dumping ETCD: etcdctl command not available"
763 fi
David Bainbridge0774b232019-08-02 06:37:19 +0000764 bspin - "Creating compressed TAR: voltha-debug-dump-$NAME-$TS.tgz"
765 (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 +0000766 espin - $VERIFIED
767 bspin - "Cleanup"
768 (set -x; rm -rf $WORK) >>$LOG 2>&1
769 espin - $VERIFIED
David Bainbridge0774b232019-08-02 06:37:19 +0000770 bspin - "$(ls -l voltha-debug-dump-$NAME-$TS.tgz)"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000771 espin - $VERIFIED
772 exit
773fi
774
David Bainbridge0774b232019-08-02 06:37:19 +0000775LOG="install-$NAME.log"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000776date > $LOG
David Bainbridge0774b232019-08-02 06:37:19 +0000777echo "PORTS=$ONOS_API_PORT,$ONOS_SSH_PORT,$VOLTHA_API_PORT,$VOLTHA_SSH_PORT,$VOLTHA_ETCD_PORT" >> $LOG
David Bainbridgeac7f8072019-08-01 22:15:33 +0000778
779# Output install options to log
780echo "OPTIONS" >> $LOG
David Bainbridgeac7f8072019-08-01 22:15:33 +0000781for O in $ALL_OPTIONS; do
782 VAL=$(eval echo \$$O)
David Bainbridgeac7f8072019-08-01 22:15:33 +0000783 if [ ! -z "$VAL" ]; then
784 printf " %-30s = %s\n" $O $VAL >> $LOG
785 fi
786done
787
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -0700788helm_install() {
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700789 local INDENT=
790 if [ "$1" == "-" ]; then
791 INDENT=$1; shift
792 fi
793 local NAMESPACE=$1; shift
David Bainbridge0774b232019-08-02 06:37:19 +0000794 local INAME=$1; shift
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700795 local CHART=$1; shift
David Bainbridge90fd8e32019-08-21 23:32:47 +0000796 local CHART_VERSION=$1; shift
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700797 local MESSAGE=$*
798
David Bainbridge90fd8e32019-08-21 23:32:47 +0000799 if [ "$CHART_VERSION X" != " X" -a "$CHART_VERSION" != "latest" ]; then
800 CHART_VERSION="--version $CHART_VERSION"
801 else
802 CHART_VERSION=
803 fi
804
David Bainbridge99ac7a22019-08-31 02:26:43 +0000805 local CHART_ARGS=
806 if [ -r "${INAME}-values.yaml" ]; then
807 CHART_ARGS="-f ${INAME}-values.yaml"
808 fi
809
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700810 COUNT=$(expr 300 / 15)
811 bspin $INDENT $MESSAGE
David Bainbridge2eaf2cf2020-03-18 12:54:08 -0700812 (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 -0700813 SUCCESS=$?
814 while [ $SUCCESS -ne 0 ]; do
815 sspin $INDENT
816 COUNT=$(expr $COUNT - 1)
817 if [ $COUNT -eq 0 ]; then
Andy Baviere22ff252019-12-19 11:40:31 -0700818 (set -x; helm delete --purge $INAME >>$LOG 2>&1) >>$LOG 2>&1
David Bainbridge2eaf2cf2020-03-18 12:54:08 -0700819 (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 -0700820 SUCCESS=$?
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700821 COUNT=$(expr 300 / 15)
822 fi
823 sleep .15
824 done
825 espin $INDENT $VERIFIED
826}
827
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700828echo "INSTALL TYPE: $TYPE" >> $LOG
829
830bspin "Verify GOPATH"
831export GOPATH=$(pwd)
Test User3d7ad8e2019-07-03 06:15:44 +0000832mkdir -p $GOPATH/bin
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700833espin $VERIFIED
834
David Bainbridgee87067b2019-08-12 22:00:12 +0000835STIME=$(date +%s)
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700836if [ "$INSTALL_KUBECTL" == "no" ]; then
837 bspin "Skip kubectl install"
838 espin $NO_ENTRY
Test Userc13bdc92019-07-03 20:57:49 +0000839else
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700840 bspin "Verify kubectl $HELM"
841 if [ -x $GOPATH/bin/kubectl ]; then
842 espin $VERIFIED
843 else
844 espin $NOT_VERIFIED
845 bspin - "Download and install Kubernetes/kubectl $DOWNLOAD"
846 (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
847 (set -x; chmod 755 $GOPATH/bin/kubectl >>$LOG 2>&1) >>$LOG 2>&1
848 espin - $VERIFIED
849 fi
Test Userc13bdc92019-07-03 20:57:49 +0000850fi
David Bainbridgee87067b2019-08-12 22:00:12 +0000851if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +0000852 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +0000853fi
Test Userc13bdc92019-07-03 20:57:49 +0000854
David Bainbridgee87067b2019-08-12 22:00:12 +0000855STIME=$(date +%s)
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700856if [ "$DEPLOY_K8S" == "no" ]; then
857 bspin "Skip Kubernetes/Kind Deployment"
858 espin $NO_ENTRY
859else
Test Userba1e7e72019-07-10 22:27:54 +0000860 bspin "Verify Kubernetes/Kind $HELM"
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800861 IS_INSTALLED=0
862 OP_TYPE="install"
Test Userba1e7e72019-07-10 22:27:54 +0000863 if [ -x $GOPATH/bin/kind ]; then
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800864 OP_TYPE="upgrade"
865 if [ $($GOPATH/bin/kind --version | grep -c $KIND_VERSION) -eq 1 ]; then
866 IS_INSTALLED=1
867 espin $VERIFIED
868 fi
869 fi
870 if [ $IS_INSTALLED -eq 0 ]; then
Test Userba1e7e72019-07-10 22:27:54 +0000871 espin $NOT_VERIFIED
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800872 bspin - "Download and $OP_TYPE Kubernetes/kind $DOWNLOAD"
David Bainbridge9e2a6662019-07-11 17:07:57 +0000873 (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 +0000874 (set -x; chmod 755 $GOPATH/bin/kind >>$LOG 2>&1) >>$LOG 2>&1
875 espin - $VERIFIED
876 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700877fi
878
David Bainbridgee87067b2019-08-12 22:00:12 +0000879if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +0000880 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +0000881fi
882
883STIME=$(date +%s)
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700884if [ "$INSTALL_HELM" == "no" ]; then
885 bspin "Skip Helm Install"
886 espin $NO_ENTRY
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700887else
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700888 bspin "Verify Helm $HELM"
889 if [ -x $GOPATH/bin/helm ]; then
890 espin $VERIFIED
891 else
892 espin $NOT_VERIFIED
893 bspin - "Download and install Helm $DOWNLOAD"
David Bainbridgec6a6eb62019-10-18 22:50:07 +0000894 (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 -0700895 espin - $VERIFIED
896 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700897fi
David K. Bainbridgefe1fa8a2019-11-12 12:03:21 -0800898
David Bainbridgee87067b2019-08-12 22:00:12 +0000899if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +0000900 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +0000901fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700902
David Bainbridgee87067b2019-08-12 22:00:12 +0000903STIME=$(date +%s)
Test Userb5712372019-07-03 21:52:17 +0000904bspin "Verify voltctl $HIGH_VOLTAGE"
David Bainbridged2811972019-12-14 01:14:09 +0000905VOK=0
906VMESSAGE="install"
David K. Bainbridgeebf38d92020-02-10 10:46:31 -0800907export VC_VERSION="$VOLTCTL_VERSION"
908if [ "$VC_VERSION" == "latest" ]; then
909 export VC_VERSION=$(curl -sSL https://api.github.com/repos/opencord/voltctl/releases/latest | jq -r .tag_name | sed -e 's/^v//g')
910fi
Test User3d7ad8e2019-07-03 06:15:44 +0000911if [ -x $GOPATH/bin/voltctl ]; then
David Bainbridge1ba64f12019-12-18 00:40:13 +0000912 VHAVE=$($GOPATH/bin/voltctl version --clientonly -o json | jq -r .version)
David K. Bainbridgeebf38d92020-02-10 10:46:31 -0800913 if [ $? -eq 0 -a "$VHAVE" == "$VC_VERSION" ]; then
David Bainbridged2811972019-12-14 01:14:09 +0000914 VOK=1
David Bainbridge1ba64f12019-12-18 00:40:13 +0000915 espin $VERIFIED
916 else
David K. Bainbridgeebf38d92020-02-10 10:46:31 -0800917 VCHECK=$(echo -e "$VHAVE\n$VC_VERSION" | sort -V | head -1)
918 if [ "$VCHECK" == "$VHAVE" ]; then
919 VMESSAGE="upgrade"
920 else
921 VMESSAGE="downgrade"
922 fi
David Bainbridged2811972019-12-14 01:14:09 +0000923 fi
924fi
925
David Bainbridge1ba64f12019-12-18 00:40:13 +0000926if [ $VOK -eq 0 ]; then
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700927 espin $NOT_VERIFIED
David Bainbridged2811972019-12-14 01:14:09 +0000928 bspin - "Download and $VMESSAGE voltctl $DOWNLOAD"
David K. Bainbridgeebf38d92020-02-10 10:46:31 -0800929 (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 +0000930 (set -x; chmod 755 $GOPATH/bin/voltctl >>$LOG 2>&1) >>$LOG 2>&1
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700931 espin - $VERIFIED
932fi
David Bainbridgee87067b2019-08-12 22:00:12 +0000933if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +0000934 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +0000935fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700936
937bspin "Verify command PATH"
Test Userba1e7e72019-07-10 22:27:54 +0000938export PATH=$GOPATH/bin:$PATH
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700939espin $VERIFIED
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700940
David Bainbridgee87067b2019-08-12 22:00:12 +0000941STIME=$(date +%s)
Test Userba1e7e72019-07-10 22:27:54 +0000942if [ "$DEPLOY_K8S" == "yes" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000943 HAVE=$(kind get clusters | grep -c voltha-$NAME)
Test Userba1e7e72019-07-10 22:27:54 +0000944 bspin "Verify Kubernetes/Kind Cluster"
945 sspin
946 if [ $HAVE -eq 0 ]; then
David Bainbridge491b1bd2019-07-11 17:53:11 +0000947 espin $NOT_VERIFIED
948 bspin - "Verify cluster configuration"
David Bainbridge0774b232019-08-02 06:37:19 +0000949 if [ ! -r ./$NAME-cluster.cfg ]; then
David Bainbridge491b1bd2019-07-11 17:53:11 +0000950 espin - $NOT_VERIFIED
David K. Bainbridge43422402020-03-06 07:41:22 -0800951 bspin - "Download cluster configuration: $TYPE-cluster.cfg to $NAME-cluster.cfg $DOWNLOAD"
David K. Bainbridgea00736b2020-01-08 14:33:17 -0800952 ERR_OUT=$(mktemp)
953 (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
954 if [ $? -ne 0 ]; then
955 espin - $THEX
956 echo -e "${RED}${BOLD}${ERROR}ERROR: $NAME-cluster.cfg${NORMAL}${RED} - $(cat $ERR_OUT)${NORMAL}"
957 echo "ERROR: $(cat $ERR_OUT)" >>$LOG
958 rm -rf $ERR_OUT ./$NAME-cluster.cfg
959 exit 1
960 fi
961 rm -rf $ERR_OUT
962 else
David K. Bainbridge43422402020-03-06 07:41:22 -0800963 espin - $VERIFIED
David K. Bainbridgea00736b2020-01-08 14:33:17 -0800964 fi
David Bainbridge0774b232019-08-02 06:37:19 +0000965 kind create cluster --name voltha-$NAME --config $NAME-cluster.cfg
David Bainbridge491b1bd2019-07-11 17:53:11 +0000966 else
967 espin $VERIFIED
Test Userba1e7e72019-07-10 22:27:54 +0000968 fi
969
David Bainbridge0774b232019-08-02 06:37:19 +0000970 export KUBECONFIG="$(kind get kubeconfig-path --name="voltha-$NAME")"
Test Userba1e7e72019-07-10 22:27:54 +0000971 P="coredns-.* \
David Bainbridge0774b232019-08-02 06:37:19 +0000972 etcd-voltha-$NAME-control-plane \
Test Userba1e7e72019-07-10 22:27:54 +0000973 kindnet-.* \
David Bainbridge0774b232019-08-02 06:37:19 +0000974 kube-apiserver-voltha-$NAME-control-plane \
975 kube-controller-manager-voltha-$NAME-control-plane \
Test Userba1e7e72019-07-10 22:27:54 +0000976 kube-proxy-.* \
David Bainbridge0774b232019-08-02 06:37:19 +0000977 kube-scheduler-voltha-$NAME-control-plane"
Test Userba1e7e72019-07-10 22:27:54 +0000978
979 EXPECT=$(test "$TYPE" == "minimal" && echo "12" || echo "14")
David Bainbridge4f1b5562019-08-19 04:46:52 +0000980 wait_for_pods - "kube-system" $EXPECT "includes" -1 "Waiting for system PODs to start" $P
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700981fi
David Bainbridgee87067b2019-08-12 22:00:12 +0000982if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +0000983 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +0000984fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700985
David Bainbridgee87067b2019-08-12 22:00:12 +0000986STIME=$(date +%s)
David Bainbridge4c6289c2019-09-03 21:11:32 +0000987COUNT=$(count_pods "kube-system" ":Running:" "tiller-deploy-.*")
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700988bspin "Verify Helm"
Test Userba1e7e72019-07-10 22:27:54 +0000989if [ $COUNT -ne 1 ]; then
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700990 espin $NOT_VERIFIED
Test Userb5712372019-07-03 21:52:17 +0000991 echo -e "Configuring Helm $GEAR"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700992 if [ "$INSTALL_HELM" == "no" ]; then
993 bspin - "Skip Helm/Tiller Initialization"
994 espin - $NO_ENTRY
995 else
996 bspin - "Initialize Helm"
997 (set -x; helm init --upgrade >>$LOG 2>&1) >>$LOG 2>&1
998 espin - $VERIFIED
David Bainbridge4f1b5562019-08-19 04:46:52 +0000999 wait_for_pods - "kube-system" 1 "includes" -1 "Waiting for Tiller POD to start" "tiller-deploy-.*"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -07001000 fi
Test Userb5712372019-07-03 21:52:17 +00001001 bspin - "Add Google Incubator repository to Helm"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001002 (set -x; helm repo add incubator https://kubernetes-charts-incubator.storage.googleapis.com >>$LOG 2>&1) >>$LOG 2>&1
1003 espin - $VERIFIED
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001004
Test Userba1e7e72019-07-10 22:27:54 +00001005 # HACK (sort-of) - the config for tiller is about to be patched, which will
1006 # cause the tiller pod to be recreated. This can sometimes cause a timing
1007 # issue with the "wait_for_pods" call on tiller as it may incorrectly
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001008 # identify the running/ready tiller pod that is soon to be terminated as
Test Userba1e7e72019-07-10 22:27:54 +00001009 # what it is waiting for. To avoid this issue we do a clean scale down and
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001010 # scale up of the pod so the script controlls when it should be expecting
Test Userba1e7e72019-07-10 22:27:54 +00001011 # things
1012 (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 -07001013
Test Userb5712372019-07-03 21:52:17 +00001014 bspin - "Add Google Stable repository to Helm"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001015 (set -x; helm repo add stable https://kubernetes-charts.storage.googleapis.com >>$LOG 2>&1) >>$LOG 2>&1
1016 espin - $VERIFIED
Test Userb5712372019-07-03 21:52:17 +00001017 bspin - "Add ONF repository to Helm"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001018 (set -x; helm repo add onf https://charts.opencord.org >>$LOG 2>&1) >>$LOG 2>&1
1019 espin - $VERIFIED
Test Userb5712372019-07-03 21:52:17 +00001020 bspin - "Update Helm repository cache"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001021 (set -x; helm repo update >>$LOG 2>&1) >>$LOG 2>&1
1022 espin - $VERIFIED
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001023
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001024 # Create and k8s service account so that Helm can create pods
Test Userb5712372019-07-03 21:52:17 +00001025 bspin - "Create Tiller ServiceAccount"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001026 (set -x; kubectl create serviceaccount --namespace kube-system tiller >>$LOG 2>&1) >>$LOG 2>&1
1027 espin - $VERIFIED
Test Userb5712372019-07-03 21:52:17 +00001028 bspin - "Create Tiller ClusterRoleBinding"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001029 (set -x; kubectl create clusterrolebinding tiller-cluster-rule --clusterrole=cluster-admin --serviceaccount=kube-system:tiller >>$LOG 2>&1) >>$LOG 2>&1
1030 espin - $VERIFIED
Test Userb5712372019-07-03 21:52:17 +00001031 bspin - "Update Tiller Manifest"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001032 (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 +00001033
1034 # HACK (sort-of) - part to, spin it back up
1035 (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 -07001036 espin - $VERIFIED
1037else
1038 espin $VERIFIED
David Bainbridge46505fb2019-10-01 21:13:20 +00001039 if [ "$UPDATE_HELM_REPOS" == "yes" ]; then
1040 bspin - "Update Helm repository cache"
1041 (set -x; helm repo update >>$LOG 2>&1) >>$LOG 2>&1
1042 espin - $VERIFIED
1043 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001044fi
David Bainbridge4f1b5562019-08-19 04:46:52 +00001045wait_for_pods - "kube-system" 1 "includes" -1 "Waiting for Tiller POD to start" "tiller-deploy-.*"
David Bainbridgee87067b2019-08-12 22:00:12 +00001046if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +00001047 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +00001048fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001049
David Bainbridgee87067b2019-08-12 22:00:12 +00001050STIME=$(date +%s)
David Bainbridge0774b232019-08-02 06:37:19 +00001051bspin "Verify Helm values file: $NAME-values.yaml"
1052if [ ! -r "./$NAME-values.yaml" ]; then
Test Userba1e7e72019-07-10 22:27:54 +00001053 espin $NOT_VERIFIED
David Bainbridge0774b232019-08-02 06:37:19 +00001054 bspin - "Download Helm values file: $TYPE-values.yaml to $NAME-values.yaml $DOWNLOAD"
David K. Bainbridgea00736b2020-01-08 14:33:17 -08001055 ERR_OUT=$(mktemp)
1056 (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
1057 if [ $? -ne 0 ]; then
1058 espin - $THEX
1059 echo -e "${RED}${BOLD}${ERROR}ERROR: $NAME-values.yaml${NORMAL}${RED} - $(cat $ERR_OUT)${NORMAL}"
1060 echo "ERROR: $(cat $ERR_OUT)" >>$LOG
1061 rm -rf $ERR_OUT ./$NAME-values.yaml
1062 exit 1
1063 fi
1064 rm -rf $ERR_OUT
Test Userba1e7e72019-07-10 22:27:54 +00001065 espin - $VERIFIED
1066else
1067 espin $VERIFIED
1068fi
David Bainbridgee87067b2019-08-12 22:00:12 +00001069if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +00001070 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +00001071fi
Test Userba1e7e72019-07-10 22:27:54 +00001072
David Bainbridge99ac7a22019-08-31 02:26:43 +00001073STIME=$(date +%s)
1074bspin "Verify or download chart specific values files $DOWNLOAD"
1075VALUES_FILES="monkey-values.yaml"
David K. Bainbridgea00736b2020-01-08 14:33:17 -08001076ERR_OUT=$(mktemp)
David Bainbridge99ac7a22019-08-31 02:26:43 +00001077for i in $VALUES_FILES; do
1078 if [ ! -r ./$i ]; then
David K. Bainbridgea00736b2020-01-08 14:33:17 -08001079 (set -x; curl --fail -o ./$i -sSL https://raw.githubusercontent.com/ciena/kind-voltha/$VK_RELEASE/$i >>$LOG 2>$ERR_OUT) >>$LOG 2>&1
1080 if [ $? -ne 0 ]; then
1081 espin $THEX
1082 echo -e "${RED}${BOLD}${ERROR}ERROR: $i${NORMAL}${RED} - $(cat $ERR_OUT)${NORMAL}"
1083 echo "ERROR: $i - $(cat $ERR_OUT)" >>$LOG
1084 rm -rf $ERR_OUT ./$i
1085 exit 1
1086 fi
1087 rm -rf $ERR_OUT
David Bainbridge99ac7a22019-08-31 02:26:43 +00001088 fi
1089done
1090espin $VERIFIED
1091if [ "$WITH_TIMINGS" == "yes" ]; then
1092 printtime $(expr $(date +%s) - $STIME)
1093fi
1094
1095if [ "$WITH_CHAOS" == "yes" ]; then
1096 bspin "Verify or clone kube-monkey helm chart $DOWNLOAD"
1097 if [ -r ./kube-monkey ]; then
1098 espin $VERIFIED
1099 else
1100 espin $NOT_VERIFIED
1101 bspin - "GIT clone kube-monkey"
1102 (set -x; git clone https://github.com/asobti/kube-monkey kube-monkey >>$LOG 2>&1) >>$LOG 2>&1
1103 espin - $VERIFIED
1104 fi
1105fi
1106
Test Userba1e7e72019-07-10 22:27:54 +00001107if [ "$JUST_K8S" == "yes" ]; then
1108 echo "Environment deployed, not deploying VOLTHA artifacts as requested. Good bye."
1109 echo ""
1110 echo "Please issue the following commands in your terminal to ensure that you" | tee -a $LOG
1111 echo "are accessing the correct Kubernetes/Kind cluster as well as have the " | tee -a $LOG
1112 echo "tools required by VOLTHA in your command path. " | tee -a $LOG
1113 echo "" | tee -a $LOG
1114 echo -en $BOLD
1115 if [ $DEPLOY_K8S == "yes" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +00001116 echo "export KUBECONFIG=\"\$(./bin/kind get kubeconfig-path --name=\"voltha-$NAME\")\"" | tee -a $LOG
Test Userba1e7e72019-07-10 22:27:54 +00001117 fi
1118 echo "export PATH=$GOPATH/bin:\$PATH" | tee -a $LOG
1119 echo -en $NORMAL
1120 echo "" | tee -a $LOG
1121 echo "Thank you for choosing kind-voltha for you quick cluster needs." | tee -a $LOG
1122 exit 0
1123fi
1124
David Bainbridgee87067b2019-08-12 22:00:12 +00001125STIME=$(date +%s)
Test Userb5712372019-07-03 21:52:17 +00001126bspin "Verify ETCD Operator $OLD_KEY"
Test User7d866122019-07-09 17:52:35 +00001127if [ $(helm list --deployed --short --namespace voltha "^etcd-operator\$" | wc -l) -ne 1 ]; then
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001128 espin $NOT_VERIFIED
David Bainbridge90fd8e32019-08-21 23:32:47 +00001129 helm_install - voltha etcd-operator stable/etcd-operator latest "Install ETCD Operator"
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001130else
1131 espin $VERIFIED
1132fi
Test User01ed0642019-07-03 20:17:06 +00001133EXPECT=$(test "$TYPE" == "minimal" && echo "1" || echo "3")
David Bainbridge4f1b5562019-08-19 04:46:52 +00001134wait_for_pods - "voltha" $EXPECT "includes" -1 "Waiting for ETCD Operator to start" "etcd-operator-.*"
David Bainbridgee87067b2019-08-12 22:00:12 +00001135if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +00001136 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +00001137fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001138
David Bainbridgee87067b2019-08-12 22:00:12 +00001139STIME=$(date +%s)
David Bainbridgeb270c202019-07-26 01:44:42 +00001140if [ $WITH_ONOS == "yes" ]; then
1141 bspin "Verify ONOS installed $BIRD"
1142 if [ $(helm list --deployed --short --namespace default "^onos\$" | wc -l) -ne 1 ]; then
1143 espin $NOT_VERIFIED
David K. Bainbridgeda33d652020-03-06 10:31:23 -08001144 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 +00001145 else
1146 espin $VERIFIED
1147 fi
David Bainbridge4f1b5562019-08-19 04:46:52 +00001148 wait_for_pods - "default" 1 "includes" -1 "Waiting for ONOS to start" "onos-.*"
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001149
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -08001150 if [ $WITH_PORT_FORWARDS == "yes" ]; then
1151 bspin - "Forward ONOS API port $FORWARD"
1152 kill_port_forward onos-ui
1153 port_forward default onos-ui $ONOS_API_PORT 8181
1154 espin - $VERIFIED
1155 bspin - "Forward ONOS SSH port $FORWARD"
1156 kill_port_forward onos-ssh
1157 port_forward default onos-ssh $ONOS_SSH_PORT 8101
1158 espin - $VERIFIED
1159 _ONOS_API_EP="127.0.0.1:$ONOS_API_PORT"
1160 else
1161 _ONOS_API_EP=$(get_service_ep default onos-ui)
1162 fi
David Bainbridged31d6122019-08-13 19:37:59 +00001163 bspin - "Verify or download ONOS configuration support files $DOWNLOAD"
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001164 ONOS_FILES="olt-onos-enableExtraneousRules.json onos-aaa.json \
David Bainbridge90fd8e32019-08-21 23:32:47 +00001165 onos-dhcpl2relay.json onos-kafka.json onos-sadis-sample.json"
David Bainbridged31d6122019-08-13 19:37:59 +00001166 (set -x; mkdir -p ./onos-files >>$LOG 2>&1) >>$LOG 2>&1
David K. Bainbridgea00736b2020-01-08 14:33:17 -08001167 ERR_OUT=$(mktemp)
David Bainbridge2b19e832019-08-16 02:40:53 +00001168 for i in $ONOS_FILES; do
David Bainbridged31d6122019-08-13 19:37:59 +00001169 if [ ! -r ./onos-files/$i ]; then
David K. Bainbridgea00736b2020-01-08 14:33:17 -08001170 (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
1171 if [ $? -ne 0 ]; then
1172 espin - $THEX
1173 echo -e "${RED}${BOLD}${ERROR}ERROR: $i${NORMAL}${RED} - $(cat $ERR_OUT)${NORMAL}"
1174 echo "ERROR: $(cat $ERR_OUT)" >>$LOG
1175 rm -rf $ERR_OUT ./onos-files/$i
1176 exit 1
1177 fi
1178 rm -rf $ERR_OUT
David Bainbridged31d6122019-08-13 19:37:59 +00001179 fi
1180 done
Test Userba1e7e72019-07-10 22:27:54 +00001181 espin - $VERIFIED
David Bainbridge27790d62019-08-13 22:43:19 +00001182
1183 if [ $INSTALL_ONOS_APPS == "yes" ]; then
1184 bspin - "Installing custom ONOS applications"
1185 if [ -x onos-files/onos-apps -a $(ls -1 onos-files/onos-apps/*.oar 2>/dev/null | wc -l) -gt 0 ]; then
1186 for OAR in $(ls -1 onos-files/onos-apps/*.oar); do
1187 sspin - "Installing custom ONOS applications - $OAR$CEOL"
David Bainbridge2b19e832019-08-16 02:40:53 +00001188 override_onos_app $OAR
David Bainbridge27790d62019-08-13 22:43:19 +00001189 done
1190 espin - "$VERIFIED Installing custom ONOS applications$CEOL"
1191 else
1192 espin - "$NOT_VERIFIED Installing custom ONOS applications - None Found"
1193 fi
1194 fi
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001195
Matteo Scandolo9a77a732020-01-09 14:24:12 -08001196 check_onos_app_active org.opencord.kafka
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001197 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 -08001198 check_onos_app_active org.opencord.dhcpl2relay
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001199 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 -08001200 check_onos_app_active org.opencord.olt
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001201 # FIXME use WITH_DHCP and WITH_EAPOL flags to configre OLT App
Hardik Windlassa7501fb2020-02-17 14:28:20 +00001202 # Default value for "enableEapol" is true in OLT App
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001203 if [ $WITH_EAPOL == "yes" ]; then
1204 push_onos_config "json" "Enable VOLTHA ONOS EAPOL provisioning" "configuration/org.opencord.olt.impl.OltFlowService" '{"enableEapol":true}'
Hardik Windlassa7501fb2020-02-17 14:28:20 +00001205 elif [ $WITH_EAPOL == "no" ]; then
1206 push_onos_config "json" "Disable VOLTHA ONOS EAPOL provisioning" "configuration/org.opencord.olt.impl.OltFlowService" '{"enableEapol":false}'
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001207 fi
Hardik Windlassa7501fb2020-02-17 14:28:20 +00001208 # Default value for "enableDhcpOnProvisioning" is false and for "enableDhcpV4" is true in OLT App
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001209 if [ $WITH_DHCP == "yes" ]; then
1210 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 +00001211 elif [ $WITH_DHCP == "no" ]; then
1212 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 -08001213 fi
Hardik Windlassa7501fb2020-02-17 14:28:20 +00001214 # Default value for "enableIgmpOnProvisioning" is false in OLT App
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001215 if [ $WITH_IGMP == "yes" ]; then
1216 push_onos_config "json" "Enable VOLTHA ONOS IGMP provisioning" "configuration/org.opencord.olt.impl.OltFlowService" '{"enableIgmpOnProvisioning":true}'
Hardik Windlassa7501fb2020-02-17 14:28:20 +00001217 elif [ $WITH_IGMP == "no" ]; then
1218 push_onos_config "json" "Disable VOLTHA ONOS IGMP provisioning" "configuration/org.opencord.olt.impl.OltFlowService" '{"enableIgmpOnProvisioning":false}'
Matteo Scandolo78dfee02020-02-13 16:18:03 -08001219 fi
David K. Bainbridge484d80c2020-03-05 21:44:34 -08001220 if [ $ENABLE_ONOS_EXTRANEOUS_RULES == "yes" ]; then
1221 push_onos_config "file" "Enabling extraneous rules for ONOS" "configuration/org.onosproject.net.flow.impl.FlowRuleManager" "onos-files/olt-onos-enableExtraneousRules.json"
1222 fi
David K. Bainbridgeb859e912020-03-13 14:07:52 -07001223 if [ $(echo ":yes:file:" | grep -c ":$CONFIG_SADIS:") -eq 1 ]; then
Matteo Scandolo9a77a732020-01-09 14:24:12 -08001224 check_onos_app_active org.opencord.sadis
Hardik Windlassb3147602020-03-09 16:59:15 +05301225 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 -07001226 elif [ "$CONFIG_SADIS" == "bbsim" ]; then
1227 push_onos_config "json" \
1228 "[optional] Push ONOS configuration for BBSIM SADIS servers" \
1229 "network/configuration/apps/org.opencord.sadis" \
1230 "$(echo $(cat <<EOJ
1231{
1232 "sadis": {
1233 "integration": {
1234 "url": "http://bbsim.voltha.svc.cluster.local:50074/v2/subscribers/%s",
1235 "cache": {
1236 "enabled": true,
1237 "maxsize": 50,
1238 "ttl": "PT1m"
1239 }
1240 }
1241 },
1242 "bandwidthprofile": {
1243 "integration": {
1244 "url": "http://bbsim.voltha.svc.cluster.local:50074/v2/bandwidthprofiles/%s",
1245 "cache": {
1246 "enabled": true,
1247 "maxsize": 50,
1248 "ttl": "PT1m"
1249 }
1250 }
1251 }
1252}
1253EOJ
1254) | tr -d '[:space:]')"
1255 elif [ "$CONFIG_SADIS" == "url" ]; then
1256 push_onos_config "json" \
1257 "[optional] Push ONOS configuration for custom SADIS and Bandwidth Profile servers" \
1258 "network/configuration/apps/org.opencord.sadis" \
1259 "$(echo $(cat <<EOJ
1260{
1261 "sadis": {
1262 "integration": {
1263 "url": "$SADIS_SUBSCRIBERS",
1264 "cache": {
1265 "enabled": true,
1266 "maxsize": 50,
1267 "ttl": "PT1m"
1268 }
1269 }
1270 },
1271 "bandwidthprofile": {
1272 "integration": {
1273 "url": "$SADIS_BANDWIDTH_PROFILES",
1274 "cache": {
1275 "enabled": true,
1276 "maxsize": 50,
1277 "ttl": "PT1m"
1278 }
1279 }
1280 }
1281}
1282EOJ
1283) | tr -d '[:space:]')"
David Bainbridge2b19e832019-08-16 02:40:53 +00001284 fi
Test Userba1e7e72019-07-10 22:27:54 +00001285fi
David Bainbridgee87067b2019-08-12 22:00:12 +00001286if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +00001287 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +00001288fi
Test Userba1e7e72019-07-10 22:27:54 +00001289
David Bainbridgee87067b2019-08-12 22:00:12 +00001290STIME=$(date +%s)
Test Userb5712372019-07-03 21:52:17 +00001291bspin "Verify VOLTHA installed $HIGH_VOLTAGE"
Test User7d866122019-07-09 17:52:35 +00001292if [ $(helm list --deployed --short --namespace voltha "^voltha\$" | wc -l) -ne 1 ]; then
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001293 espin $NOT_VERIFIED
David Bainbridge70c0ea82019-11-14 23:25:26 +00001294 if [ "$ONLY_ONE" == "yes" ]; then
David Bainbridge2eaf2cf2020-03-18 12:54:08 -07001295 INTERNAL_EXTRA_HELM_INSTALL_ARGS="--set therecanbeonlyone=true"
David Bainbridge70c0ea82019-11-14 23:25:26 +00001296 fi
David Bainbridge90fd8e32019-08-21 23:32:47 +00001297 helm_install - voltha voltha $VOLTHA_CHART $VOLTHA_CHART_VERSION "Install VOLTHA Core"
David Bainbridge2eaf2cf2020-03-18 12:54:08 -07001298 INTERNAL_EXTRA_HELM_INSTALL_ARGS=
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001299else
1300 espin $VERIFIED
1301fi
Test Userba1e7e72019-07-10 22:27:54 +00001302
David Bainbridge90fd8e32019-08-21 23:32:47 +00001303VOLTHA="voltha-ofagent-.* \
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001304 ro-core.* \
1305 rw-core.* \
1306 voltha-api-server-.* \
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001307 voltha-etcd-cluster-.* \
1308 voltha-kafka-.* \
1309 voltha-zookeeper-.*"
David Bainbridge70c0ea82019-11-14 23:25:26 +00001310if [ "$ONLY_ONE" == "yes" ]; then
David Bainbridgefce8af42020-03-17 12:50:39 -07001311 EXPECT=$(test "$TYPE" == "minimal" && echo "5" || echo "9")
David Bainbridge70c0ea82019-11-14 23:25:26 +00001312else
David Bainbridgefce8af42020-03-17 12:50:39 -07001313 EXPECT=$(test "$TYPE" == "minimal" && echo "8" || echo "12")
David Bainbridge70c0ea82019-11-14 23:25:26 +00001314fi
David Bainbridge4f1b5562019-08-19 04:46:52 +00001315wait_for_pods - "voltha" $EXPECT "includes" -1 "Waiting for VOLTHA Core to start" $VOLTHA
David Bainbridgee87067b2019-08-12 22:00:12 +00001316if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +00001317 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +00001318fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001319
David Bainbridge46505fb2019-10-01 21:13:20 +00001320if [ "$WITH_ADAPTERS" == "yes" ]; then
1321 STIME=$(date +%s)
1322 EXPECT=0
1323 echo -e "Verify Adapters $PLUG"
1324 if [ "$WITH_SIM_ADAPTERS" == "yes" ]; then
1325 bspin - "Verify Simulated Adapters installed"
1326 if [ $(helm list --deployed --short --namespace voltha "^sim\$" | wc -l) -ne 1 ]; then
1327 espin - $NOT_VERIFIED
1328 helm_install - voltha sim $VOLTHA_ADAPTER_SIM_CHART $VOLTHA_ADAPTER_SIM_CHART_VERSION "Install Simulated Adapters"
1329 else
1330 espin - $VERIFIED
1331 fi
1332 EXPECT=$(expr $EXPECT + 2)
1333 fi
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001334
David Bainbridge46505fb2019-10-01 21:13:20 +00001335 if [ "$WITH_OPEN_ADAPTERS" == "yes" ]; then
1336 bspin - "Verify OpenOLT Adapter installed"
1337 if [ $(helm list --deployed --short --namespace voltha "^open-olt\$" | wc -l) -ne 1 ]; then
1338 espin - $NOT_VERIFIED
1339 helm_install - voltha open-olt $VOLTHA_ADAPTER_OPEN_OLT_CHART $VOLTHA_ADAPTER_OPEN_OLT_CHART_VERSION "Install OpenOLT Adapter"
1340 else
1341 espin - $VERIFIED
1342 fi
1343 bspin - "Verify OpenONU Adapter installed"
1344 if [ $(helm list --deployed --short --namespace voltha "^open-onu\$" | wc -l) -ne 1 ]; then
1345 espin - $NOT_VERIFIED
1346 helm_install - voltha open-onu $VOLTHA_ADAPTER_OPEN_ONU_CHART $VOLTHA_ADAPTER_OPEN_ONU_CHART_VERSION "Install OpenONU Adapter"
1347 else
1348 espin - $VERIFIED
1349 fi
1350 EXPECT=$(expr $EXPECT + 2)
1351 fi
Matteo Scandolo7ef6ba52019-10-04 09:20:37 -07001352
David Bainbridge46505fb2019-10-01 21:13:20 +00001353 ADAPTERS="adapter-.*"
1354 wait_for_pods - "voltha" $EXPECT "includes" -1 "Waiting for adapters to start" $ADAPTERS
1355 if [ "$WITH_TIMINGS" == "yes" ]; then
1356 printtime $(expr $(date +%s) - $STIME)
1357 fi
David Bainbridgee87067b2019-08-12 22:00:12 +00001358fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001359
Test User7d866122019-07-09 17:52:35 +00001360if [ $WITH_BBSIM == "yes" ]; then
David Bainbridgee87067b2019-08-12 22:00:12 +00001361 STIME=$(date +%s)
Test User7d866122019-07-09 17:52:35 +00001362 echo -e "Verify BBSIM $PLUG"
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001363 bspin - "Verify BBSIM Installed"
David K. Bainbridge43422402020-03-06 07:41:22 -08001364 for instance in $(seq 0 $(($NUM_OF_BBSIM-1))); do
1365 if [ $instance -eq 0 ]; then
1366 instance_num=""
1367 else
1368 instance_num=$instance
1369 fi
1370 if [ $(helm list --deployed --short --namespace voltha "^bbsim${instance_num}\$" | wc -l) -ne 1 ]; then
1371 espin - $NOT_VERIFIED
David Bainbridge2eaf2cf2020-03-18 12:54:08 -07001372 INTERNAL_EXTRA_HELM_INSTALL_ARGS="--set olt_id=$instance"
David K. Bainbridge43422402020-03-06 07:41:22 -08001373 helm_install - voltha bbsim${instance_num} $VOLTHA_BBSIM_CHART $VOLTHA_BBSIM_CHART_VERSION "Install BBSIM${instance_num}"
David Bainbridge2eaf2cf2020-03-18 12:54:08 -07001374 INTERNAL_EXTRA_HELM_INSTALL_ARGS=
David K. Bainbridge43422402020-03-06 07:41:22 -08001375 else
1376 espin - $VERIFIED
1377 fi
1378 done
uottrembb16d3982020-02-28 08:34:36 +01001379 wait_for_pods - "voltha" $NUM_OF_BBSIM "includes" -1 "Waiting for BBSIM to start" "bbsim*"
David Bainbridgee87067b2019-08-12 22:00:12 +00001380 if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +00001381 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +00001382 fi
Test User7d866122019-07-09 17:52:35 +00001383fi
1384
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001385if [ $WITH_RADIUS == "yes" ]; then
David Bainbridgee87067b2019-08-12 22:00:12 +00001386 STIME=$(date +%s)
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001387 echo -e "Verify RADIUS $LOCK"
1388 bspin - "Verify RADIUS Installed"
1389 if [ $(helm list --deployed --short --namespace voltha "^radius\$" | wc -l) -ne 1 ]; then
1390 espin - $NOT_VERIFIED
David Bainbridge90fd8e32019-08-21 23:32:47 +00001391 helm_install - voltha radius onf/freeradius latest "Install RADIUS"
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001392 else
1393 espin - $VERIFIED
1394 fi
David Bainbridge4f1b5562019-08-19 04:46:52 +00001395 wait_for_pods - "voltha" 1 "includes" -1 "Waiting for RADIUS to start" "radius-.*"
David Bainbridgee87067b2019-08-12 22:00:12 +00001396 if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridge712afb82019-08-14 19:55:58 +00001397 printtime $(expr $(date +%s) - $STIME)
David Bainbridgee87067b2019-08-12 22:00:12 +00001398 fi
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001399fi
1400
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -08001401if [ $WITH_PORT_FORWARDS == "yes" ]; then
1402 STIME=$(date +%s)
1403 bspin - "Forward VOLTHA API port $FORWARD"
1404 kill_port_forward voltha-api
1405 port_forward voltha voltha-api $VOLTHA_API_PORT 55555
1406 espin - $VERIFIED
1407 bspin - "Forward VOLTHA ETCD port $FORWARD"
1408 kill_port_forward voltha-etcd-cluster-client
1409 port_forward voltha voltha-etcd-cluster-client $VOLTHA_ETCD_PORT 2379
1410 espin - $VERIFIED
1411 bspin - "Forward VOLTHA Kafka port $FORWARD"
1412 kill_port_forward voltha-kafka
1413 port_forward voltha voltha-kafka $VOLTHA_KAFKA_PORT 9092
1414 espin - $VERIFIED
1415 if [ "$WITH_TIMINGS" == "yes" ]; then
1416 printtime $(expr $(date +%s) - $STIME)
1417 fi
David Bainbridgee87067b2019-08-12 22:00:12 +00001418fi
Test User3d7ad8e2019-07-03 06:15:44 +00001419
David Bainbridgeb270c202019-07-26 01:44:42 +00001420if [ $WITH_ONOS == "yes" -a $WITH_RADIUS == "yes" ]; then
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001421 bspin "Configure ONOS RADIUS Connection $GEAR"
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -08001422 (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 +00001423 espin $VERIFIED
1424fi
1425
David Bainbridge99ac7a22019-08-31 02:26:43 +00001426if [ "$WITH_CHAOS" == "yes" ]; then
1427 STIME=$(date +%s)
1428 echo -e "Verify kube-monkey $LOCK"
1429 bspin - "Verify kube-monkey Installed"
1430 if [ $(helm list --deployed --short --namespace kube-monkey "^monkey\$" | wc -l) -ne 1 ]; then
1431 espin - $NOT_VERIFIED
1432 helm_install - kube-monkey monkey ./kube-monkey/helm/kubemonkey latest "Install Chaos Monkey"
1433 else
1434 espin - $VERIFIED
1435 fi
1436 wait_for_pods - "kube-monkey" 1 "includes" -1 "Waiting for Chaos to start" "monkey-.*"
1437 if [ "$WITH_TIMINGS" == "yes" ]; then
1438 printtime $(expr $(date +%s) - $STIME)
1439 fi
1440fi
1441
David Bainbridge5b7b96b2019-07-25 20:29:13 +00001442bspin "Create voltctl configuration file"
Test User3d7ad8e2019-07-03 06:15:44 +00001443(set -x; mkdir -p $HOME/.volt >>$LOG 2>&1) >>$LOG 2>&1
David K. Bainbridgeb859e912020-03-13 14:07:52 -07001444MIN_VC_VERSION=$(echo -e "1.0.15\n$VC_VERSION" | sort -V | head -1)
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -08001445if [ $WITH_PORT_FORWARDS == "yes" ]; then
David K. Bainbridgeb859e912020-03-13 14:07:52 -07001446 KAFKA_FLAG="-k localhost:$VOLTHA_KAFKA_PORT"
1447 SERVER_FLAG="-s localhost:$VOLTHA_API_PORT"
1448 ETCD_FLAG=
1449 if [ "$MIN_VC_VERSION" == "1.0.15" ]; then
1450 ETCD_FLAG="-e localhost:$VOLTHA_ETCD_PORT"
1451 fi
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -08001452else
David K. Bainbridgeb859e912020-03-13 14:07:52 -07001453 KAFKA_FLAG="-k $(get_service_ep voltha voltha-kafka)"
1454 SERVER_FLAG="-s $(get_service_ep voltha voltha-api)"
1455 ETCD_FLAG=
1456 if [ "$MIN_VC_VERSION" == "1.0.15" ]; then
1457 ETCD_FLAG="-e $(get_service_ep voltha voltha-etcd-client)"
1458 fi
David K. Bainbridge4a06a4a2020-03-02 14:15:23 -08001459fi
David K. Bainbridgeb859e912020-03-13 14:07:52 -07001460(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 +00001461espin $VERIFIED
Test User08ebbd92019-07-03 17:15:39 +00001462
David Bainbridge0774b232019-08-02 06:37:19 +00001463if [ ! -f "$NAME-env.sh" ]; then
1464 touch $NAME-env.sh
David Bainbridgeb07fdf72019-07-29 22:51:40 +00001465fi
1466
David Bainbridge596f30d2019-07-30 17:07:59 +00001467for O in $ALL_OPTIONS; do
1468 VAL=$(eval echo \$$O)
David Bainbridge0774b232019-08-02 06:37:19 +00001469 if [ ! -z "$VAL" -a $(grep -c "^export $O=" $NAME-env.sh) -eq 0 ]; then
1470 echo "export $O=\"$(eval echo \$$O)\"" >> $NAME-env.sh
David Bainbridgeb07fdf72019-07-29 22:51:40 +00001471 fi
1472done
1473
David Bainbridge0774b232019-08-02 06:37:19 +00001474if [ $DEPLOY_K8S == "yes" -a $(grep -c "^export KUBECONFIG=" $NAME-env.sh) -eq 0 ]; then
1475 echo "export KUBECONFIG=\"$(./bin/kind get kubeconfig-path --name=voltha-$NAME)\"" >> $NAME-env.sh
David Bainbridgeb07fdf72019-07-29 22:51:40 +00001476fi
1477
David Bainbridge0774b232019-08-02 06:37:19 +00001478if [ $(grep -c "^export VOLTCONFIG=" $NAME-env.sh) -eq 0 ]; then
1479 echo "export VOLTCONFIG=\"$HOME/.volt/config-$NAME\"" >> $NAME-env.sh
David Bainbridgeb07fdf72019-07-29 22:51:40 +00001480fi
1481
David Bainbridge0774b232019-08-02 06:37:19 +00001482if [ $(grep -c "^export PATH=" $NAME-env.sh) -eq 0 ]; then
1483 echo "export PATH=\"$GOPATH/bin:\$PATH\"" >> $NAME-env.sh
David Bainbridgeb07fdf72019-07-29 22:51:40 +00001484fi
1485
Test User7d866122019-07-09 17:52:35 +00001486echo ""
Test User08ebbd92019-07-03 17:15:39 +00001487echo "Please issue the following commands in your terminal to ensure that you" | tee -a $LOG
1488echo "are accessing the correct Kubernetes/Kind cluster as well as have the " | tee -a $LOG
1489echo "tools required by VOLTHA in your command path. " | tee -a $LOG
1490echo "" | tee -a $LOG
Test User7d866122019-07-09 17:52:35 +00001491echo -en $BOLD
Test Userba1e7e72019-07-10 22:27:54 +00001492if [ $DEPLOY_K8S == "yes" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +00001493 echo "export KUBECONFIG=\"\$(./bin/kind get kubeconfig-path --name=\"voltha-$NAME\")\"" | tee -a $LOG
Test Userba1e7e72019-07-10 22:27:54 +00001494fi
David Bainbridge0774b232019-08-02 06:37:19 +00001495echo "export VOLTCONFIG=\"$HOME/.volt/config-$NAME\"" | tee -a $LOG
Test Userba1e7e72019-07-10 22:27:54 +00001496echo "export PATH=$GOPATH/bin:\$PATH" | tee -a $LOG
Test User7d866122019-07-09 17:52:35 +00001497echo -en $NORMAL
Test User08ebbd92019-07-03 17:15:39 +00001498echo "" | tee -a $LOG
1499echo "Thank you for choosing kind-voltha for you quick cluster needs." | tee -a $LOG
1500
David Bainbridge712afb82019-08-14 19:55:58 +00001501if [ "$WITH_TIMINGS" == "yes" ]; then
David Bainbridgef858a022019-08-14 21:25:11 +00001502 echo -e "$CLOCK ${BOLD}TOTAL: $(duration $(expr $(date +%s) - $TOTAL_START_TIME))${NORMAL}"
David Bainbridge712afb82019-08-14 19:55:58 +00001503fi