blob: ac8730cbe674a05011d7ac7755675307debb1964 [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.
15
David Bainbridge38dc1e82019-08-12 15:18:45 +000016FANCY=${FANCY:-1}
17if [ "$TERM X" == " X" ]; then
18 FANCY=0
19fi
20
David K. Bainbridgeb7285432019-07-02 22:05:24 -070021# trap ctrl-c and call ctrl_c()
22trap ctrl_c INT
23
24function ctrl_c() {
David Bainbridge38dc1e82019-08-12 15:18:45 +000025 echo -en $CNORM
David K. Bainbridgeb7285432019-07-02 22:05:24 -070026 echo ""
27 echo "ctrl-c trapped"
28 echo "Thank you for trying 'votlha up'"
29 exit
30}
31
Test User08ebbd92019-07-03 17:15:39 +000032VOLTCTL_VERSION=${VOLTCTL_VERSION:-0.0.5-dev}
33KIND_VERSION=${KIND_VERSION:-v0.4.0}
34_VOLTCTL_VERSION=$(echo $VOLTCTL_VERSION | sed -e 's/-/_/g')
35
David Bainbridge38dc1e82019-08-12 15:18:45 +000036BLACK=
37RED=
38GREEN=
39YELLOW=
40BLUE=
41MAGENTA=
42CYAN=
43WHITE=
44BOLD=
45NORMAL=
46ERROR=
47CEOL=
48CNORM=
49CIVIS=
50if [ $FANCY -eq 1 ]; then
51 BLACK=$(tput setaf 0)
52 RED=$(tput setaf 1)
53 GREEN=$(tput setaf 2)
54 YELLOW=$(tput setaf 3)
55 BLUE=$(tput setaf 4)
56 MAGENTA=$(tput setaf 5)
57 CYAN=$(tput setaf 6)
58 WHITE=$(tput setaf 7)
59 BOLD=$(tput bold)
60 NORMAL=$(tput sgr0)
61 ERROR="\xe2\x9c\x97\x20"
62 CEOL=$(tput el)
63 CNORM=$(tput cnorm)
64 CIVIS=$(tput civis)
65fi
Test User7d866122019-07-09 17:52:35 +000066
Test User3d7ad8e2019-07-03 06:15:44 +000067TYPE=${TYPE:-minimal}
David Bainbridge0774b232019-08-02 06:37:19 +000068NAME=${NAME:-$TYPE}
Test User7d866122019-07-09 17:52:35 +000069WITH_BBSIM=${WITH_BBSIM:-no}
David Bainbridge5b7b96b2019-07-25 20:29:13 +000070WITH_RADIUS=${WITH_RADIUS:-no}
David Bainbridgeb270c202019-07-26 01:44:42 +000071WITH_ONOS=${WITH_ONOS:-yes}
David Bainbridge01294952019-07-30 19:33:45 +000072WITH_TP=${WITH_TP:-yes}
Test Userba1e7e72019-07-10 22:27:54 +000073JUST_K8S=${JUST_K8S:-no}
74DEPLOY_K8S=${DEPLOY_K8S:-yes}
David Bainbridgee10f6d52019-07-25 00:28:13 +000075SKIP_RESTART_API=${SKIP_RESTART_API:-no}
David K. Bainbridge0e89cb92019-07-17 11:30:10 -070076INSTALL_KUBECTL=${INSTALL_KUBECTL:-yes}
77INSTALL_HELM=${INSTALL_HELM:-yes}
David Bainbridge5b7b96b2019-07-25 20:29:13 +000078USE_GO=${USE_GO:-yes}
79VOLTHA_LOG_LEVEL=${VOLTHA_LOG_LEVEL:-WARN}
David Bainbridgee10f6d52019-07-25 00:28:13 +000080VOLTHA_CHART=${VOLTHA_CHART:=onf/voltha}
81VOLTHA_ADAPTER_SIM_CHART=${VOLTHA_ADAPTER_SIM_CHART:-onf/voltha-adapter-simulated}
82VOLTHA_ADAPTER_OPEN_OLT_CHART=${VOLTHA_ADAPTER_OPEN_OLT_CHART:-onf/voltha-adapter-openolt}
83VOLTHA_ADAPTER_OPEN_ONU_CHART=${VOLTHA_ADAPTER_OPEN_ONU_CHART:-onf/voltha-adapter-openonu}
Test Userba1e7e72019-07-10 22:27:54 +000084
85HAVE_GO=$(which go >/dev/null 2>&1 && echo "yes" || echo "no")
86HOSTOS=$(uname -s | tr "[:upper:]" "[:lower:"])
87HOSTARCH=$(uname -m | tr "[:upper:]" "[:lower:"])
88if [ $HOSTARCH == "x86_64" ]; then
89 HOSTARCH="amd64"
90fi
Test User7d866122019-07-09 17:52:35 +000091
92# Verify TYPE setting
93if [ $(echo ":minimal:full:" | grep -ic ":$TYPE:") -eq 0 ]; then
David K. Bainbridge0e89cb92019-07-17 11:30:10 -070094 >&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 +000095 exit 1
96fi
97
98# Verify WITH_BBSIM settting and convert uniform value of yes or no
99if [ $(echo ":y:yes:true:n:no:false:1:0:" | grep -ic ":$WITH_BBSIM:") -eq 0 ]; then
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700100 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} Invalid \$WITH_BBSIM value of '$WITH_BBSIM'. Should be 'yes' or 'no'${NORMAL}"
Test User7d866122019-07-09 17:52:35 +0000101 exit 1
102fi
103if [ $(echo ":y:yes:true:1:" | grep -ic ":$WITH_BBSIM:") -eq 1 ]; then
104 WITH_BBSIM=yes
105else
106 WITH_BBSIM=no
107fi
108
David Bainbridge5b7b96b2019-07-25 20:29:13 +0000109# Verify WITH_RADIUS settting and convert uniform value of yes or no
110if [ $(echo ":y:yes:true:n:no:false:1:0:" | grep -ic ":$WITH_RADIUS:") -eq 0 ]; then
111 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} Invalid \$WITH_RADIUS value of '$WITH_RADIUS'. Should be 'yes' or 'no'${NORMAL}"
112 exit 1
113fi
114if [ $(echo ":y:yes:true:1:" | grep -ic ":$WITH_RADIUS:") -eq 1 ]; then
115 WITH_RADIUS=yes
116else
117 WITH_RADIUS=no
118fi
119
David Bainbridge01294952019-07-30 19:33:45 +0000120# Verify WITH_TP settting and convert uniform value of yes or no
121if [ $(echo ":y:yes:true:n:no:false:1:0:" | grep -ic ":$WITH_TP:") -eq 0 ]; then
122 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} Invalid \$WITH_TP value of '$WITH_TP'. Should be 'yes' or 'no'${NORMAL}"
123 exit 1
124fi
125if [ $(echo ":y:yes:true:1:" | grep -ic ":$WITH_TP:") -eq 1 ]; then
126 WITH_TP=yes
127else
128 WITH_TP=no
129fi
130
David Bainbridgeb270c202019-07-26 01:44:42 +0000131# Verify WITH_ONOS settting and convert uniform value of yes or no
132if [ $(echo ":y:yes:true:n:no:false:1:0:" | grep -ic ":$WITH_ONOS:") -eq 0 ]; then
133 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} Invalid \$WITH_ONOS value of '$WITH_ONOS'. Should be 'yes' or 'no'${NORMAL}"
134 exit 1
135fi
136if [ $(echo ":y:yes:true:1:" | grep -ic ":$WITH_ONOS:") -eq 1 ]; then
137 WITH_ONOS=yes
138else
139 WITH_ONOS=no
140fi
141
Test Userba1e7e72019-07-10 22:27:54 +0000142# Verify JUST_K8S settting and convert uniform value of yes or no
143if [ $(echo ":y:yes:true:n:no:false:1:0:" | grep -ic ":$JUST_K8S:") -eq 0 ]; then
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700144 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} Invalid \$JUST_K8S value of '$JUST_K8S'. Should be 'yes' or 'no'${NORMAL}"
Test Userba1e7e72019-07-10 22:27:54 +0000145 exit 1
146fi
147if [ $(echo ":y:yes:true:1:" | grep -ic ":$JUST_K8S:") -eq 1 ]; then
148 JUST_K8S=yes
149else
150 JUST_K8S=no
151fi
152
153# Verify DEPLOY_K8S settting and convert uniform value of yes or no
154if [ $(echo ":y:yes:true:n:no:false:1:0:" | grep -ic ":$DEPLOY_K8S:") -eq 0 ]; then
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700155 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} Invalid \$DEPLOY_K8S value of '$DEPLOY_K8S'. Should be 'yes' or 'no'${NORMAL}"
Test Userba1e7e72019-07-10 22:27:54 +0000156 exit 1
157fi
158if [ $(echo ":y:yes:true:1:" | grep -ic ":$DEPLOY_K8S:") -eq 1 ]; then
159 DEPLOY_K8S=yes
160else
161 DEPLOY_K8S=no
162fi
Test User01ed0642019-07-03 20:17:06 +0000163
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700164# Verify INSTALL_KUBECTL settting and convert uniform value of yes or no
165if [ $(echo ":y:yes:true:n:no:false:1:0:" | grep -ic ":$INSTALL_KUBECTL:") -eq 0 ]; then
166 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} Invalid \$INSTALL_KUBECTL value of '$INSTALL_KUBECTL'. Should be 'yes' or 'no'${NORMAL}"
167 exit 1
168fi
169
170if [ $(echo ":y:yes:true:1:" | grep -ic ":$INSTALL_KUBECTL:") -eq 1 ]; then
171 INSTALL_KUBECTL=yes
172else
173 INSTALL_KUBECTL=no
174fi
175
David Bainbridgee10f6d52019-07-25 00:28:13 +0000176# Verify SKIP_RESTART_API settting and convert uniform value of yes or no
177if [ $(echo ":y:yes:true:n:no:false:1:0:" | grep -ic ":$SKIP_RESTART_API:") -eq 0 ]; then
178 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} Invalid \$SKIP_RESTART_API value of '$SKIP_RESTART_API'. Should be 'yes' or 'no'${NORMAL}"
179 exit 1
180fi
181if [ $(echo ":y:yes:true:1:" | grep -ic ":$SKIP_RESTART_API:") -eq 1 ]; then
182 SKIP_RESTART_API=yes
183else
184 SKIP_RESTART_API=no
185fi
186
David Bainbridge1ceabc12019-07-25 17:21:05 +0000187# Verify USE_GO settting and convert uniform value of yes or no
188if [ $(echo ":y:yes:true:n:no:false:1:0:" | grep -ic ":$USE_GO:") -eq 0 ]; then
189 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} Invalid \$USE_GO value of '$USE_GO'. Should be 'yes' or 'no'${NORMAL}"
190 exit 1
191fi
192if [ $(echo ":y:yes:true:1:" | grep -ic ":$USE_GO:") -eq 1 ]; then
193 USE_GO=true
194else
195 USE_GO=false
196fi
197
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700198# Verify INSTALL_HELM settting and convert uniform value of yes or no
199if [ $(echo ":y:yes:true:n:no:false:1:0:" | grep -ic ":$INSTALL_HELM:") -eq 0 ]; then
200 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} Invalid \$INSTALL_HELM value of '$INSTALL_HELM'. Should be 'yes' or 'no'${NORMAL}"
201 exit 1
202fi
203
204if [ $(echo ":y:yes:true:1:" | grep -ic ":$INSTALL_HELM:") -eq 1 ]; then
205 INSTALL_HELM=yes
206else
207 INSTALL_HELM=no
208fi
209
David Bainbridge0774b232019-08-02 06:37:19 +0000210mkdir -p .voltha
211touch .voltha/ports
212HAVE=$(grep $NAME .voltha/ports)
213if [ "$HAVE X" == " X" ]; then
214 # Find free port prefix
215 START=81
216 while true; do
217 if [ $(grep -c $START .voltha/ports) -eq 0 ]; then
218 break
219 fi
220 START=$(expr $START + 1)
221 done
222 DELTA=$(expr $START - 81)
223 ONOS_API_PORT=${START}81
224 ONOS_SSH_PORT=${START}01
225 VOLTHA_API_PORT=5$(expr 55 + $DELTA)55
226 VOLTHA_SSH_PORT=$(expr 50 + $DELTA)22
227 VOLTHA_ETCD_PORT=$(expr 23 + $DELTA)79
Test User01ed0642019-07-03 20:17:06 +0000228else
David Bainbridge0774b232019-08-02 06:37:19 +0000229 VALUES=$(echo $HAVE | sed -e 's/\s//g' | cut -d= -f2)
230 ONOS_API_PORT=$(echo $VALUES | cut -d, -f1)
231 ONOS_SSH_PORT=$(echo $VALUES | cut -d, -f2)
232 VOLTHA_API_PORT=$(echo $VALUES | cut -d, -f3)
233 VOLTHA_SSH_PORT=$(echo $VALUES | cut -d, -f4)
234 VOLTHA_ETCD_PORT=$(echo $VALUES | cut -d, -f5)
Test User01ed0642019-07-03 20:17:06 +0000235fi
236
David Bainbridge0774b232019-08-02 06:37:19 +0000237PORTTMP=$(mktemp -u)
238cat .voltha/ports | grep -v $NAME > $PORTTMP
239echo "$NAME=$ONOS_API_PORT,$ONOS_SSH_PORT,$VOLTHA_API_PORT,$VOLTHA_SSH_PORT,$VOLTHA_ETCD_PORT" >> $PORTTMP
240cp $PORTTMP .voltha/ports
241rm -f $PORTTMP
242
David Bainbridge01294952019-07-30 19:33:45 +0000243if [ "$WITH_TP" == "yes" ]; then
244 SADIS_VER=3.1.0
245 OLT_VER=3.0.1
246 AAA_VER=1.9.0
247 DHCP_VER=1.6.0
248else
249 SADIS_VER=2.2.0
250 OLT_VER=2.1.0
251 AAA_VER=1.8.0
252 DHCP_VER=1.5.0
253fi
David Bainbridge0774b232019-08-02 06:37:19 +0000254export ONOS_API_PORT ONOS_SSH_PORT SADIS_VER OLT_VER AAA_VER DHCP_VER
David Bainbridge01294952019-07-30 19:33:45 +0000255
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700256spin() {
Test Userd87942b2019-07-03 07:20:24 +0000257 PARTS="\
258 \xe2\xa2\x8e\xe2\xa1\xb0 \
259 \xe2\xa2\x8e\xe2\xa1\xa1 \
260 \xe2\xa2\x8e\xe2\xa1\x91 \
261 \xe2\xa2\x8e\xe2\xa0\xb1 \
262 \xe2\xa0\x8e\xe2\xa1\xb1 \
263 \xe2\xa2\x8a\xe2\xa1\xb1 \
264 \xe2\xa2\x8c\xe2\xa1\xb1 \
265 \xe2\xa2\x86\xe2\xa1\xb1 \
266 "
267 IDX=1
David Bainbridge38dc1e82019-08-12 15:18:45 +0000268 echo -en $CIVIS
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700269 while true; do
Test Userd87942b2019-07-03 07:20:24 +0000270 C=$(echo $PARTS | cut '-d ' -f $IDX)
271 echo -en "$C"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700272 IDX=$(expr $IDX + 1)
Test Userd87942b2019-07-03 07:20:24 +0000273 if [ $IDX -gt 8 ]; then
274 IDX=1
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700275 fi
276 sleep .15
277 echo -en "\r"
278 done
279}
280
Test Userd87942b2019-07-03 07:20:24 +0000281IDX=1
David Bainbridge38dc1e82019-08-12 15:18:45 +0000282SPIN_PARTS=
283NOT_VERIFIED=
284VERIFIED=
285HELM=
286OLD_KEY=
287BIRD=
288HIGH_VOLTAGE=
289PLUG=
290RESTART=
291FORWARD=
292INSTALL=
293STOP=
294GO=
295DOWNLOAD=
296GEAR=
297NO_ENTRY=
298LOCK=
299
300if [ $FANCY -eq 1 ]; then
301 SPIN_PARTS="\
302 \xe2\xa2\x8e\xe2\xa1\xb0 \
303 \xe2\xa2\x8e\xe2\xa1\xa1 \
304 \xe2\xa2\x8e\xe2\xa1\x91 \
305 \xe2\xa2\x8e\xe2\xa0\xb1 \
306 \xe2\xa0\x8e\xe2\xa1\xb1 \
307 \xe2\xa2\x8a\xe2\xa1\xb1 \
308 \xe2\xa2\x8c\xe2\xa1\xb1 \
309 \xe2\xa2\x86\xe2\xa1\xb1 \
310 "
311 NOT_VERIFIED="\xe2\x9c\x97\x20"
312 VERIFIED="\xe2\x9c\x93\x20"
313 HELM="\xE2\x8E\x88"
314 OLD_KEY="\xF0\x9F\x97\x9D"
315 BIRD="\xF0\x9F\x90\xA6"
316 HIGH_VOLTAGE="\xE2\x9A\xA1"
317 PLUG="\xF0\x9F\xa7\xa9"
318 RESTART="\xf0\x9f\x94\x84"
319 FORWARD="\xE2\x87\xA8"
320 INSTALL="\xF0\x9F\x8F\x97"
321 STOP="\xf0\x9f\x9b\x91"
322 GO="\xf0\x9f\x9a\x80"
323 DOWNLOAD="\xf0\x9f\x93\xa5"
324 GEAR="\xe2\x9a\x99"
325 NO_ENTRY="\xe2\x9b\x94"
326 LOCK="\xf0\x9f\x94\x92"
327fi
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700328
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700329bspin() {
Test Userd87942b2019-07-03 07:20:24 +0000330 IDX=1
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700331 local INDENT=
332 if [ "$1" == "-" ]; then
333 INDENT=" "
334 shift
335 fi
David Bainbridge38dc1e82019-08-12 15:18:45 +0000336 if [ $FANCY -eq 0 ]; then
337 LINE=$(echo $* | sed -e 's/[\s+-]//g')
338 if [ "$LINE X" == " X" ]; then
339 return
340 fi
341 echo -e "$CIVIS$INDENT$*"
342 else
343 echo -en "$CIVIS$INDENT $*"
344 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700345}
346
347sspin() {
348 local INDENT=
349 if [ "$1" == "-" ]; then
350 INDENT=" "
351 shift
352 fi
David Bainbridge38dc1e82019-08-12 15:18:45 +0000353 if [ $FANCY -eq 0 ]; then
354 LINE=$(echo $* | sed -e 's/[\s+-]//g')
355 if [ "$LINE X" == " X" ]; then
356 return
357 fi
358 echo -e "$INDENT$*"
359 else
360 C=$(echo $SPIN_PARTS | cut '-d ' -f $IDX)
361 echo -en "\r$INDENT$C $*"
362 IDX=$(expr $IDX + 1)
363 if [ $IDX -gt 8 ]; then
364 IDX=1
365 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700366 fi
367}
368
369espin() {
370 local INDENT=
371 if [ "$1" == "-" ]; then
372 INDENT=" "
373 shift
374 fi
David Bainbridge38dc1e82019-08-12 15:18:45 +0000375 if [ $FANCY -eq 0 ]; then
376 LINE=$(echo $* | sed -e 's/[\s+-]//g')
377 if [ "$LINE X" == " X" ]; then
378 return
379 fi
380 echo -e "$INDENT$*"
381 else
382 echo -e "\r$INDENT$*$CNORM"
383 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700384}
385
David Bainbridgeac7f8072019-08-01 22:15:33 +0000386if [ "$1" == "get" -a "$2" == "voltconfig" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000387 echo "$HOME/.volt/config-$NAME"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000388 exit
389fi
390
391if [ $# -ne 1 -o $(echo ":up:down:dump:" | grep -c ":$1:") -ne 1 ]; then
392 >&2 echo "What wouild you like to do today:"
393 >&2 echo " up - bring up voltha"
394 >&2 echo " down - tear down voltha"
395 >&2 echo " dump - create a debug dump of running system"
396 exit 1
397fi
398
399if [ "$1" == "down" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000400 echo "Tearing down voltha cluster $NAME"
401 LOG="down-$NAME.log"
402 echo $(date -u +"%Y%m%dT%H%M%SZ") >$LOG
David Bainbridgeac7f8072019-08-01 22:15:33 +0000403 if [ $DEPLOY_K8S == "yes" ]; then
404 if [ -x ./bin/kind ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000405 bspin "Delete Kubernetes Kind Cluster"
406 (set -x; ./bin/kind delete cluster --name voltha-$NAME >>$LOG 2>&1) >>$LOG 2>&1
407 espin $VERIFIED
David Bainbridgeac7f8072019-08-01 22:15:33 +0000408 else
David Bainbridge0774b232019-08-02 06:37:19 +0000409 espin "$NO_ENTRY Delete Kubernetes Kind Cluster: kind command not found"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000410 fi
411 else
412 EXISTS=$(helm list -q)
413 EXPECT="etcd-operator onos open-olt open-onu sim voltha bbsim radius"
David Bainbridge0774b232019-08-02 06:37:19 +0000414 bspin "Remove Helm Deployments"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000415 for i in $EXISTS; do
416 if [ $(echo $EXPECT | grep -c $i) -eq 1 ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000417 sspin "Remove Helm Deployments: $i$CEOL"
418 (set -x; ./bin/helm delete --purge $i >>$LOG 2>&1) >>$LOG 2>&1
David Bainbridgeac7f8072019-08-01 22:15:33 +0000419 fi
420 done
David Bainbridge0774b232019-08-02 06:37:19 +0000421 espin "$VERIFIED Remove Helm Deployments$CEOL"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000422 fi
David Bainbridge0774b232019-08-02 06:37:19 +0000423 bspin "Remove port-forwards: onos-ui-$NAME"
424 for i in $(screen -ls | grep onos-ui-$NAME | awk '{print $1}'); do
425 sspin
426 (set -x; screen -X -S $i quit >>$LOG 2>&1) >>$LOG 2>&1
427 done
428 sspin "Remove port-forwards: onos-ssh-$NAME$CEOL"
429 for i in $(screen -ls | grep onos-ssh-$NAME | awk '{print $1}'); do
430 sspin
431 (set -x; screen -X -S $i quit >>$LOG 2>&1) >>$LOG 2>&1
432 done
433 sspin "Remove port-forwards: voltha-api-$NAME$CEOL"
434 for i in $(screen -ls | grep voltha-api-$NAME | awk '{print $1}'); do
435 sspin
436 (set -x; screen -X -S $i quit >>$LOG 2>&1) >>$LOG 2>&1
437 done
438 sspin "Remove port-forwards: voltha-ssh-$NAME$CEOL"
439 for i in $(screen -ls | grep voltha-ssh-$NAME | awk '{print $1}'); do
440 sspin
441 (set -x; screen -X -S $i quit >>$LOG 2>&1) >>$LOG 2>&1
442 done
443 sspin "Remove port-forwards: voltha-etcd-$NAME$CEOL"
444 for i in $(screen -ls | grep voltha-etcd-$NAME | awk '{print $1}'); do
445 sspin
446 (set -x; screen -X -S $i quit >>$LOG 2>&1) >>$LOG 2>&1
447 done
448 espin "$VERIFIED Remove port-forwards$CEOL"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000449 exit
450fi
451
452if [ "$1" == "dump" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000453 LOG="dump-$NAME.log"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000454 TS=$(date -u +"%Y%m%dT%H%M%SZ")
455 WORK=$(mktemp -u -d)
David Bainbridge0774b232019-08-02 06:37:19 +0000456 DATA=$WORK/voltha-debug-dump-$NAME-$TS
David Bainbridgeac7f8072019-08-01 22:15:33 +0000457 mkdir -p $DATA
458 echo $TS > $LOG
David Bainbridge0774b232019-08-02 06:37:19 +0000459 echo -e "Capturing debug dump to voltha-debug-dump-$NAME-$TS.tgz"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000460 bspin - "Copy install log"
David Bainbridge0774b232019-08-02 06:37:19 +0000461 if [ -f install-$NAME.log ]; then
462 (set -x; cp install-$NAME.log $DATA/install-$NAME.log) >>$LOG 2>&1
David Bainbridgeac7f8072019-08-01 22:15:33 +0000463 espin - $VERIFIED
464 else
David Bainbridge0774b232019-08-02 06:37:19 +0000465 espin - "$NO_ENTRY Copy install log: install-$NAME.log not found"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000466 fi
467 bspin - "Dumping Kubernetes PODs"
468 (set -x; kubectl get --all-namespaces pods >> $DATA/all-pods.txt 2>&1) >>$LOG 2>&1
469 espin - $VERIFIED
470 bspin - "Dumping Kubernetes SERVICEs"
471 (set -x; kubectl get --all-namespaces svc >> $DATA/all-services.txt 2>&1) >>$LOG 2>&1
472 espin - $VERIFIED
473 bspin - "Dumping Kubernetes EVENTs"
474 (set -x; kubectl get --all-namespaces events >> $DATA/all-events.txt 2>&1) >>$LOG 2>&1
475 espin - $VERIFIED
476 bspin - "Dumping VOLTHA POD details"
477 PODS=$(kubectl get -n voltha pod -o name)
478 for POD in $PODS; do
479 sspin - "Dumping VOLTHA POD details: $POD$CEOL"
480 mkdir -p $DATA/$POD
481 (set -x; kubectl describe -n voltha $POD >> $DATA/$POD/describe.txt 2>&1) >>$LOG 2>&1
482 sspin - "Dumping VOLTHA POD details: $POD"
483 (set -x; kubectl logs -n voltha --all-containers --previous $LOG_ARGS $POD >> $DATA/$POD/logs-previous.txt 2>&1) >>$LOG 2>&1
484 sspin - "Dumping VOLTHA POD details: $POD"
485 (set -x; kubectl logs -n voltha --all-containers $LOG_ARGS $POD >> $DATA/$POD/logs-current.txt 2>&1) >>$LOG 2>&1
486 sspin - "Dumping VOLTHA POD details: $POD"
487 done
488 espin - "$VERIFIED Dumping VOLTHA POD details$CEOL"
489 bspin - "Dumping ETCD"
490 if [ "$(which etcdctl) X" != " X" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000491 (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 +0000492 espin - $VERIFIED
493 else
494 espin - "$NO_ENTRY Dumping ETCD: etcdctl command not available"
495 fi
David Bainbridge0774b232019-08-02 06:37:19 +0000496 bspin - "Creating compressed TAR: voltha-debug-dump-$NAME-$TS.tgz"
497 (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 +0000498 espin - $VERIFIED
499 bspin - "Cleanup"
500 (set -x; rm -rf $WORK) >>$LOG 2>&1
501 espin - $VERIFIED
David Bainbridge0774b232019-08-02 06:37:19 +0000502 bspin - "$(ls -l voltha-debug-dump-$NAME-$TS.tgz)"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000503 espin - $VERIFIED
504 exit
505fi
506
507
David Bainbridge0774b232019-08-02 06:37:19 +0000508LOG="install-$NAME.log"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000509date > $LOG
David Bainbridge0774b232019-08-02 06:37:19 +0000510echo "PORTS=$ONOS_API_PORT,$ONOS_SSH_PORT,$VOLTHA_API_PORT,$VOLTHA_SSH_PORT,$VOLTHA_ETCD_PORT" >> $LOG
David Bainbridgeac7f8072019-08-01 22:15:33 +0000511
512# Output install options to log
513echo "OPTIONS" >> $LOG
David Bainbridge0774b232019-08-02 06:37:19 +0000514ALL_OPTIONS="NAME TYPE WITH_BBSIM WITH_RADIUS WITH_ONOS WITH_TP JUST_K8S DEPLOY_K8S \
David Bainbridgeac7f8072019-08-01 22:15:33 +0000515 SKIP_RESTART_API INSTALL_KUBECTL INSTALL_HELM USE_GO VOLTHA_LOG_LEVEL \
516 VOLTHA_CHART VOLTHA_ADAPTER_SIM_CHART VOLTHA_ADAPTER_OPEN_OLT_CHART \
David Bainbridge0774b232019-08-02 06:37:19 +0000517 VOLTHA_ADAPTER_OPEN_ONU_CHART SADIS_VER OLT_VER AAA_VER DHCP_VER \
518 ONOS_API_PORT ONOS_SSH_PORT VOLTHA_API_PORT VOLTHA_SSH_PORT VOLTHA_ETCD_PORT"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000519for O in $ALL_OPTIONS; do
520 VAL=$(eval echo \$$O)
521 if [ $O == "USE_GO" ]; then
522 VAL="$(echo $VAL| test $(grep -c true) -eq 1 && echo yes || echo no)"
523 fi
524 if [ ! -z "$VAL" ]; then
525 printf " %-30s = %s\n" $O $VAL >> $LOG
526 fi
527done
528
529
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700530count_pods() {
531 local NAMESPACE=$1; shift
532 local PODS=$(kubectl -n $NAMESPACE get pod -o go-template="{{range .items}}{{.metadata.name}}/{{.status.phase}}/_{{range .status.containerStatuses}}{{.ready}}_{{end}} {{end}}")
533 local COUNT=0
534 local PATTERNS=$*
535 for POD in $PODS; do
536 local NAME=$(echo $POD | cut -d/ -f 1)
537 local STATE=$(echo $POD | cut -d/ -f 2)
538 local CONTAINERS=$(echo $POD | cut -d/ -f 3 | sed -e 's/_/ /g')
539 if [ "$STATE" == "Running" ]; then
540 local TOTAL=$(echo $CONTAINERS | wc -w)
541 local FOUND=$(echo $CONTAINERS | grep -o true | wc -l)
542 if [ $TOTAL -eq $FOUND ]; then
543 for PATTERN in $PATTERNS; do
544 if [[ $NAME =~ $PATTERN ]]; then
545 COUNT=$(expr $COUNT + 1)
546 fi
547 done
548 fi
549 fi
550 done
551 echo $COUNT
552}
553
554wait_for_pods() {
555 local INDENT=
556 if [ "$1" == "-" ]; then
557 INDENT=$1; shift
558 fi
559 local NAMESPACE=$1; shift
560 local EXPECT=$1; shift
561 local RETRY=$1; shift
562 local MESSAGE=$1; shift
563 local PATTERNS=$*
564 local HAVE=$(count_pods $NAMESPACE $PATTERNS)
565 COUNT=$(expr 300 / 15)
566 bspin $INDENT $MESSAGE
567 sspin $INDENT
568 if [ $HAVE -ne $EXPECT ]; then
569 while [ $HAVE -ne $EXPECT ]; do
570 sspin $INDENT
571 COUNT=$(expr $COUNT - 1)
572 if [ $COUNT -eq 0 ]; then
573 HAVE=$(count_pods $NAMESPACE $PATTERNS)
574 COUNT=$(expr 300 / 15)
575 fi
576 sleep .15
577 done
578 fi
579 espin $INDENT $VERIFIED
580 if [ $HAVE -ne $EXPECT ]; then
581 return 1
582 fi
583 return 0
584}
585
586helm_install() {
587 local INDENT=
588 if [ "$1" == "-" ]; then
589 INDENT=$1; shift
590 fi
591 local NAMESPACE=$1; shift
David Bainbridge0774b232019-08-02 06:37:19 +0000592 local INAME=$1; shift
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700593 local CHART=$1; shift
594 local MESSAGE=$*
595
596 COUNT=$(expr 300 / 15)
597 bspin $INDENT $MESSAGE
David Bainbridge458bb662019-08-02 20:04:23 +0000598 (set -x; helm install -f $NAME-values.yaml --set use_go=$USE_GO --set defaults.log_level=$VOLTHA_LOG_LEVEL --namespace $NAMESPACE --name $INAME $EXTRA_HELM_FLAGS $CHART >>$LOG 2>&1) >>$LOG 2>&1
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700599 SUCCESS=$?
600 while [ $SUCCESS -ne 0 ]; do
601 sspin $INDENT
602 COUNT=$(expr $COUNT - 1)
603 if [ $COUNT -eq 0 ]; then
David Bainbridge458bb662019-08-02 20:04:23 +0000604 (set -x; helm install -f $NAME-values.yaml --set use_go=$USE_GO --set defaults.log_level=$VOLTHA_LOG_LEVEL --namespace $NAMESPACE --name $INAME $EXTRA_HELM_FLAGS $CHART >>$LOG 2>&1) >>$LOG 2>&1
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700605 COUNT=$(expr 300 / 15)
606 fi
607 sleep .15
608 done
609 espin $INDENT $VERIFIED
610}
611
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700612echo "INSTALL TYPE: $TYPE" >> $LOG
613
614bspin "Verify GOPATH"
615export GOPATH=$(pwd)
Test User3d7ad8e2019-07-03 06:15:44 +0000616mkdir -p $GOPATH/bin
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700617espin $VERIFIED
618
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700619if [ "$INSTALL_KUBECTL" == "no" ]; then
620 bspin "Skip kubectl install"
621 espin $NO_ENTRY
Test Userc13bdc92019-07-03 20:57:49 +0000622else
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700623 bspin "Verify kubectl $HELM"
624 if [ -x $GOPATH/bin/kubectl ]; then
625 espin $VERIFIED
626 else
627 espin $NOT_VERIFIED
628 bspin - "Download and install Kubernetes/kubectl $DOWNLOAD"
629 (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
630 (set -x; chmod 755 $GOPATH/bin/kubectl >>$LOG 2>&1) >>$LOG 2>&1
631 espin - $VERIFIED
632 fi
Test Userc13bdc92019-07-03 20:57:49 +0000633fi
634
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700635if [ "$DEPLOY_K8S" == "no" ]; then
636 bspin "Skip Kubernetes/Kind Deployment"
637 espin $NO_ENTRY
638else
Test Userba1e7e72019-07-10 22:27:54 +0000639 bspin "Verify Kubernetes/Kind $HELM"
640 if [ -x $GOPATH/bin/kind ]; then
641 espin $VERIFIED
642 else
643 espin $NOT_VERIFIED
644 bspin - "Download and install Kubernetes/kind $DOWNLOAD"
David Bainbridge9e2a6662019-07-11 17:07:57 +0000645 (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 +0000646 (set -x; chmod 755 $GOPATH/bin/kind >>$LOG 2>&1) >>$LOG 2>&1
647 espin - $VERIFIED
648 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700649fi
650
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700651if [ "$INSTALL_HELM" == "no" ]; then
652 bspin "Skip Helm Install"
653 espin $NO_ENTRY
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700654else
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700655 bspin "Verify Helm $HELM"
656 if [ -x $GOPATH/bin/helm ]; then
657 espin $VERIFIED
658 else
659 espin $NOT_VERIFIED
660 bspin - "Download and install Helm $DOWNLOAD"
661 (set -x; curl -sSL https://git.io/get_helm.sh | USE_SUDO=false HELM_INSTALL_DIR=$GOPATH/bin bash >>$LOG 2>&1) >>$LOG 2>&1
662 espin - $VERIFIED
663 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700664fi
665
Test Userb5712372019-07-03 21:52:17 +0000666bspin "Verify voltctl $HIGH_VOLTAGE"
Test User3d7ad8e2019-07-03 06:15:44 +0000667if [ -x $GOPATH/bin/voltctl ]; then
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700668 espin $VERIFIED
669else
670 espin $NOT_VERIFIED
Test Userb5712372019-07-03 21:52:17 +0000671 bspin - "Download and build voltctl $DOWNLOAD"
Test Userba1e7e72019-07-10 22:27:54 +0000672 (set -x; curl -o $GOPATH/bin/voltctl -sSL https://github.com/ciena/voltctl/releases/download/$VOLTCTL_VERSION/voltctl-$_VOLTCTL_VERSION-$HOSTOS-$HOSTARCH >>$LOG 2>&1) >>$LOG 2>&1
Test User08ebbd92019-07-03 17:15:39 +0000673 (set -x; chmod 755 $GOPATH/bin/voltctl >>$LOG 2>&1) >>$LOG 2>&1
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700674 espin - $VERIFIED
675fi
676
677bspin "Verify command PATH"
Test Userba1e7e72019-07-10 22:27:54 +0000678export PATH=$GOPATH/bin:$PATH
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700679espin $VERIFIED
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700680
Test Userba1e7e72019-07-10 22:27:54 +0000681if [ "$DEPLOY_K8S" == "yes" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000682 HAVE=$(kind get clusters | grep -c voltha-$NAME)
Test Userba1e7e72019-07-10 22:27:54 +0000683 bspin "Verify Kubernetes/Kind Cluster"
684 sspin
685 if [ $HAVE -eq 0 ]; then
David Bainbridge491b1bd2019-07-11 17:53:11 +0000686 espin $NOT_VERIFIED
687 bspin - "Verify cluster configuration"
David Bainbridge0774b232019-08-02 06:37:19 +0000688 if [ ! -r ./$NAME-cluster.cfg ]; then
David Bainbridge491b1bd2019-07-11 17:53:11 +0000689 espin - $NOT_VERIFIED
David Bainbridge0774b232019-08-02 06:37:19 +0000690 bspin - "Download cluster configuration: $TYPE-cluster.cfg to $NAME-cluster.cfg $DOWNLOAD"
691 (set -x; curl -o ./$NAME-cluster.cfg -sSL https://raw.githubusercontent.com/ciena/kind-voltha/master/$TYPE-cluster.cfg >>$LOG 2>&1) >>$LOG 2>&1
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700692 espin - $VERIFIED
693 else
694 espin - $VERIFIED
695 fi
David Bainbridge0774b232019-08-02 06:37:19 +0000696 kind create cluster --name voltha-$NAME --config $NAME-cluster.cfg
David Bainbridge491b1bd2019-07-11 17:53:11 +0000697 else
698 espin $VERIFIED
Test Userba1e7e72019-07-10 22:27:54 +0000699 fi
700
David Bainbridge0774b232019-08-02 06:37:19 +0000701 export KUBECONFIG="$(kind get kubeconfig-path --name="voltha-$NAME")"
Test Userba1e7e72019-07-10 22:27:54 +0000702 P="coredns-.* \
David Bainbridge0774b232019-08-02 06:37:19 +0000703 etcd-voltha-$NAME-control-plane \
Test Userba1e7e72019-07-10 22:27:54 +0000704 kindnet-.* \
David Bainbridge0774b232019-08-02 06:37:19 +0000705 kube-apiserver-voltha-$NAME-control-plane \
706 kube-controller-manager-voltha-$NAME-control-plane \
Test Userba1e7e72019-07-10 22:27:54 +0000707 kube-proxy-.* \
David Bainbridge0774b232019-08-02 06:37:19 +0000708 kube-scheduler-voltha-$NAME-control-plane"
Test Userba1e7e72019-07-10 22:27:54 +0000709
710 EXPECT=$(test "$TYPE" == "minimal" && echo "12" || echo "14")
711 wait_for_pods - "kube-system" $EXPECT -1 "Waiting for system PODs to start" $P
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700712fi
713
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700714COUNT=$(count_pods "kube-system" "tiller-deploy-.*")
715bspin "Verify Helm"
Test Userba1e7e72019-07-10 22:27:54 +0000716if [ $COUNT -ne 1 ]; then
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700717 espin $NOT_VERIFIED
Test Userb5712372019-07-03 21:52:17 +0000718 echo -e "Configuring Helm $GEAR"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700719 if [ "$INSTALL_HELM" == "no" ]; then
720 bspin - "Skip Helm/Tiller Initialization"
721 espin - $NO_ENTRY
722 else
723 bspin - "Initialize Helm"
724 (set -x; helm init --upgrade >>$LOG 2>&1) >>$LOG 2>&1
725 espin - $VERIFIED
726 wait_for_pods - "kube-system" 1 -1 "Waiting for Tiller POD to start" "tiller-deploy-.*"
727 fi
Test Userb5712372019-07-03 21:52:17 +0000728 bspin - "Add Google Incubator repository to Helm"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700729 (set -x; helm repo add incubator https://kubernetes-charts-incubator.storage.googleapis.com >>$LOG 2>&1) >>$LOG 2>&1
730 espin - $VERIFIED
Test Userba1e7e72019-07-10 22:27:54 +0000731
732 # HACK (sort-of) - the config for tiller is about to be patched, which will
733 # cause the tiller pod to be recreated. This can sometimes cause a timing
734 # issue with the "wait_for_pods" call on tiller as it may incorrectly
735 # identify the running/ready tiller pod that is soon to be terminated as
736 # what it is waiting for. To avoid this issue we do a clean scale down and
737 # scale up of the pod so the script controlls when it should be expecting
738 # things
739 (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 -0700740
Test Userb5712372019-07-03 21:52:17 +0000741 bspin - "Add Google Stable repository to Helm"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700742 (set -x; helm repo add stable https://kubernetes-charts.storage.googleapis.com >>$LOG 2>&1) >>$LOG 2>&1
743 espin - $VERIFIED
Test Userb5712372019-07-03 21:52:17 +0000744 bspin - "Add ONF repository to Helm"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700745 (set -x; helm repo add onf https://charts.opencord.org >>$LOG 2>&1) >>$LOG 2>&1
746 espin - $VERIFIED
Test Userb5712372019-07-03 21:52:17 +0000747 bspin - "Update Helm repository cache"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700748 (set -x; helm repo update >>$LOG 2>&1) >>$LOG 2>&1
749 espin - $VERIFIED
750
751 # Create and k8s service account so that Helm can create pods
Test Userb5712372019-07-03 21:52:17 +0000752 bspin - "Create Tiller ServiceAccount"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700753 (set -x; kubectl create serviceaccount --namespace kube-system tiller >>$LOG 2>&1) >>$LOG 2>&1
754 espin - $VERIFIED
Test Userb5712372019-07-03 21:52:17 +0000755 bspin - "Create Tiller ClusterRoleBinding"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700756 (set -x; kubectl create clusterrolebinding tiller-cluster-rule --clusterrole=cluster-admin --serviceaccount=kube-system:tiller >>$LOG 2>&1) >>$LOG 2>&1
757 espin - $VERIFIED
Test Userb5712372019-07-03 21:52:17 +0000758 bspin - "Update Tiller Manifest"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700759 (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 +0000760
761 # HACK (sort-of) - part to, spin it back up
762 (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 -0700763 espin - $VERIFIED
764else
765 espin $VERIFIED
766fi
Test Userb5712372019-07-03 21:52:17 +0000767wait_for_pods - "kube-system" 1 -1 "Waiting for Tiller POD to start" "tiller-deploy-.*"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700768
David Bainbridge0774b232019-08-02 06:37:19 +0000769bspin "Verify Helm values file: $NAME-values.yaml"
770if [ ! -r "./$NAME-values.yaml" ]; then
Test Userba1e7e72019-07-10 22:27:54 +0000771 espin $NOT_VERIFIED
David Bainbridge0774b232019-08-02 06:37:19 +0000772 bspin - "Download Helm values file: $TYPE-values.yaml to $NAME-values.yaml $DOWNLOAD"
773 (set -x; curl -o ./$NAME-values.yaml -sSL https://raw.githubusercontent.com/ciena/kind-voltha/master/$TYPE-values.yaml >>$LOG 2>&1) >>$LOG 2>&1
Test Userba1e7e72019-07-10 22:27:54 +0000774 espin - $VERIFIED
775else
776 espin $VERIFIED
777fi
778
779if [ "$JUST_K8S" == "yes" ]; then
780 echo "Environment deployed, not deploying VOLTHA artifacts as requested. Good bye."
781 echo ""
782 echo "Please issue the following commands in your terminal to ensure that you" | tee -a $LOG
783 echo "are accessing the correct Kubernetes/Kind cluster as well as have the " | tee -a $LOG
784 echo "tools required by VOLTHA in your command path. " | tee -a $LOG
785 echo "" | tee -a $LOG
786 echo -en $BOLD
787 if [ $DEPLOY_K8S == "yes" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000788 echo "export KUBECONFIG=\"\$(./bin/kind get kubeconfig-path --name=\"voltha-$NAME\")\"" | tee -a $LOG
Test Userba1e7e72019-07-10 22:27:54 +0000789 fi
790 echo "export PATH=$GOPATH/bin:\$PATH" | tee -a $LOG
791 echo -en $NORMAL
792 echo "" | tee -a $LOG
793 echo "Thank you for choosing kind-voltha for you quick cluster needs." | tee -a $LOG
794 exit 0
795fi
796
Test Userb5712372019-07-03 21:52:17 +0000797bspin "Verify ETCD Operator $OLD_KEY"
Test User7d866122019-07-09 17:52:35 +0000798if [ $(helm list --deployed --short --namespace voltha "^etcd-operator\$" | wc -l) -ne 1 ]; then
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700799 espin $NOT_VERIFIED
800 helm_install - voltha etcd-operator stable/etcd-operator "Install ETCD Operator"
801else
802 espin $VERIFIED
803fi
Test User01ed0642019-07-03 20:17:06 +0000804EXPECT=$(test "$TYPE" == "minimal" && echo "1" || echo "3")
Test Userb5712372019-07-03 21:52:17 +0000805wait_for_pods - "voltha" $EXPECT -1 "Waiting for ETCD Operator to start" "etcd-operator-.*"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700806
David Bainbridgeb270c202019-07-26 01:44:42 +0000807if [ $WITH_ONOS == "yes" ]; then
808 bspin "Verify ONOS installed $BIRD"
809 if [ $(helm list --deployed --short --namespace default "^onos\$" | wc -l) -ne 1 ]; then
810 espin $NOT_VERIFIED
811 helm_install - default onos onf/onos "Install ONOS"
812 else
813 espin $VERIFIED
814 fi
815 wait_for_pods - "default" 1 -1 "Waiting for ONOS to start" "onos-.*"
816
817 bspin - "Forward ONOS API port $FORWARD"
David Bainbridge0774b232019-08-02 06:37:19 +0000818 for i in $(screen -ls | grep onos-ui-$NAME | awk '{print $1}'); do
David Bainbridge82bd1212019-07-29 19:19:31 +0000819 (set -x; screen -X -S $i quit >>$LOG 2>&1) >>$LOG 2>&1
820 done
David Bainbridge0774b232019-08-02 06:37:19 +0000821 (set -x; screen -dmS onos-ui-$NAME bash -c "while true; do kubectl port-forward service/onos-ui $ONOS_API_PORT:8181; done" >>$LOG 2>&1) >>$LOG 2>&1
David Bainbridgeb270c202019-07-26 01:44:42 +0000822 espin - $VERIFIED
823 bspin - "Forward ONOS SSH port $FORWARD"
David Bainbridge0774b232019-08-02 06:37:19 +0000824 for i in $(screen -ls | grep onos-ssh-$NAME | awk '{print $1}'); do
David Bainbridge82bd1212019-07-29 19:19:31 +0000825 (set -x; screen -X -S $i quit >>$LOG 2>&1) >>$LOG 2>&1
826 done
David Bainbridge0774b232019-08-02 06:37:19 +0000827 (set -x; screen -dmS onos-ssh-$NAME bash -c "while true; do kubectl port-forward service/onos-ssh $ONOS_SSH_PORT:8101; done" >>$LOG 2>&1) >>$LOG 2>&1
David Bainbridgeb270c202019-07-26 01:44:42 +0000828 espin - $VERIFIED
829 if [ ! -x ./onos-files/install-onos-applications.sh ]; then
830 bspin - "Verify or download ONOS configuration support files $DOWNLOAD"
831 (set -x; mkdir -p ./onos-files >>$LOG 2>&1) >>$LOG 2>&1
832 for i in dhcp-to-controller-flow.json install-onos-applications.sh olt-onos-enableExtraneousRules.json olt-onos-netcfg.json olt-onos-olt-settings.json radius-config.json; do
833 if [ ! -r ./onos-files/$i ]; then
834 (set -x; curl -o ./onos-files/$i -sSL https://raw.githubusercontent.com/ciena/kind-voltha/master/onos-files/$i >>$LOG 2>&1) >>$LOG 2>&1
835 fi
836 done
837 (set -x; chmod 755 ./onos-files/install-onos-applications.sh >>$LOG 2>&1) >>$LOG 2>&1
838 espin - $VERIFIED
839 fi
840
841 bspin - "Install required ONOS applications $INSTALL"
842 (set -x; ./onos-files/install-onos-applications.sh >>$LOG 2>&1) >>$LOG 2>&1
Test Userba1e7e72019-07-10 22:27:54 +0000843 espin - $VERIFIED
844fi
845
Test Userb5712372019-07-03 21:52:17 +0000846bspin "Verify VOLTHA installed $HIGH_VOLTAGE"
Test User7d866122019-07-09 17:52:35 +0000847if [ $(helm list --deployed --short --namespace voltha "^voltha\$" | wc -l) -ne 1 ]; then
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700848 espin $NOT_VERIFIED
David Bainbridgee10f6d52019-07-25 00:28:13 +0000849 helm_install - voltha voltha $VOLTHA_CHART "Install VOLTHA Core"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700850else
851 espin $VERIFIED
852fi
Test Userba1e7e72019-07-10 22:27:54 +0000853
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700854VOLTHA="ofagent-.* \
855 ro-core.* \
856 rw-core.* \
857 voltha-api-server-.* \
858 voltha-cli-server-.* \
859 voltha-etcd-cluster-.* \
860 voltha-kafka-.* \
861 voltha-zookeeper-.*"
Test User01ed0642019-07-03 20:17:06 +0000862EXPECT=$(test "$TYPE" == "minimal" && echo "9" || echo "11")
Test Userb5712372019-07-03 21:52:17 +0000863wait_for_pods - "voltha" $EXPECT -1 "Waiting for VOLTHA Core to start" $VOLTHA
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700864
Test Userb5712372019-07-03 21:52:17 +0000865echo -e "Verify Adapters $PLUG"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700866bspin - "Verify Simulated Adapters installed"
Test User7d866122019-07-09 17:52:35 +0000867if [ $(helm list --deployed --short --namespace voltha "^sim\$" | wc -l) -ne 1 ]; then
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700868 espin - $NOT_VERIFIED
David Bainbridgee10f6d52019-07-25 00:28:13 +0000869 helm_install - voltha sim $VOLTHA_ADAPTER_SIM_CHART "Install Simulated Adapters"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700870else
871 espin - $VERIFIED
872fi
873
874bspin - "Verify OpenOLT Adapter installed"
Test User7d866122019-07-09 17:52:35 +0000875if [ $(helm list --deployed --short --namespace voltha "^open-olt\$" | wc -l) -ne 1 ]; then
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700876 espin - $NOT_VERIFIED
David Bainbridgee10f6d52019-07-25 00:28:13 +0000877 helm_install - voltha open-olt $VOLTHA_ADAPTER_OPEN_OLT_CHART "Install OpenOLT Adapter"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700878else
879 espin - $VERIFIED
880fi
881bspin - "Verify OpenONU Adapter installed"
Test User7d866122019-07-09 17:52:35 +0000882if [ $(helm list --deployed --short --namespace voltha "^open-onu\$" | wc -l) -ne 1 ]; then
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700883 espin - $NOT_VERIFIED
David Bainbridgee10f6d52019-07-25 00:28:13 +0000884 helm_install - voltha open-onu $VOLTHA_ADAPTER_OPEN_ONU_CHART "Install OpenONU Adapter"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700885else
886 espin - $VERIFIED
887fi
888
889ADAPTERS="adapter-.*"
Test Userb5712372019-07-03 21:52:17 +0000890wait_for_pods - "voltha" 4 -1 "Waiting for adapters to start" $ADAPTERS
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700891
Test User7d866122019-07-09 17:52:35 +0000892if [ $WITH_BBSIM == "yes" ]; then
893 echo -e "Verify BBSIM $PLUG"
David Bainbridge5b7b96b2019-07-25 20:29:13 +0000894 bspin - "Verify BBSIM Installed"
Test User7d866122019-07-09 17:52:35 +0000895 if [ $(helm list --deployed --short --namespace voltha "^bbsim\$" | wc -l) -ne 1 ]; then
896 espin - $NOT_VERIFIED
897 helm_install - voltha bbsim onf/bbsim "Install BBSIM"
898 else
899 espin - $VERIFIED
900 fi
901 wait_for_pods - "voltha" 1 -1 "Waiting for BBSIM to start" "bbsim-.*"
902fi
903
David Bainbridge5b7b96b2019-07-25 20:29:13 +0000904if [ $WITH_RADIUS == "yes" ]; then
905 echo -e "Verify RADIUS $LOCK"
906 bspin - "Verify RADIUS Installed"
907 if [ $(helm list --deployed --short --namespace voltha "^radius\$" | wc -l) -ne 1 ]; then
908 espin - $NOT_VERIFIED
909 helm_install - voltha radius onf/freeradius "Install RADIUS"
910 else
911 espin - $VERIFIED
912 fi
913 wait_for_pods - "voltha" 1 -1 "Waiting for RADIUS to start" "radius-.*"
914fi
915
David Bainbridgee10f6d52019-07-25 00:28:13 +0000916if [ $SKIP_RESTART_API == "no" ]; then
917 echo -e "Restart VOLTHA API $RESTART"
918 API="voltha-api-server-.* ofagent-.*"
919 (set -x; kubectl scale --replicas=0 deployment -n voltha voltha-api-server ofagent >>$LOG 2>&1) >>$LOG 2>&1
920 wait_for_pods - "voltha" 0 -1 "Wait for API to stop $STOP" $API
921 (set -x; kubectl scale --replicas=1 deployment -n voltha voltha-api-server ofagent >>$LOG 2>&1) >>$LOG 2>&1
922 wait_for_pods - "voltha" 2 -1 "Wait for API to re-start $GO" $API
923else
924 bspin "Skip VOLTHA API Restart"
925 espin $NO_ENTRY
926fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700927
Test Userb5712372019-07-03 21:52:17 +0000928bspin - "Forward VOLTHA API port $FORWARD"
David Bainbridge0774b232019-08-02 06:37:19 +0000929for i in $(screen -ls | grep voltha-api-$NAME | awk '{print $1}'); do
David Bainbridge82bd1212019-07-29 19:19:31 +0000930 (set -x; screen -X -S $i quit >>$LOG 2>&1) >>$LOG 2>&1
931done
David Bainbridge0774b232019-08-02 06:37:19 +0000932(set -x; screen -dmS voltha-api-$NAME bash -c "while true; do kubectl port-forward -n voltha service/voltha-api $VOLTHA_API_PORT:55555; done" >>$LOG 2>&1) >>$LOG 2>&1
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700933espin - $VERIFIED
Test Userb5712372019-07-03 21:52:17 +0000934bspin - "Forward VOLTHA SSH port $FORWARD"
David Bainbridge0774b232019-08-02 06:37:19 +0000935for i in $(screen -ls | grep voltha-ssh-$NAME | awk '{print $1}'); do
David Bainbridge82bd1212019-07-29 19:19:31 +0000936 (set -x; screen -X -S $i quit >>$LOG 2>&1) >>$LOG 2>&1
937done
David Bainbridge0774b232019-08-02 06:37:19 +0000938(set -x; screen -dmS voltha-ssh-$NAME bash -c "while true; do kubectl port-forward -n voltha service/voltha-cli $VOLTHA_SSH_PORT:5022; done" >>$LOG 2>&1) >>$LOG 2>&1
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700939espin - $VERIFIED
David Bainbridgeac7f8072019-08-01 22:15:33 +0000940bspin - "Forward VOLTHA ETCD port $FORWARD"
David Bainbridge0774b232019-08-02 06:37:19 +0000941for i in $(screen -ls | grep voltha-etcd-$NAME | awk '{print $1}'); do
David Bainbridgeac7f8072019-08-01 22:15:33 +0000942 (set -x; screen -X -S $i quit >>$LOG 2>&1) >>$LOG 2>&1
943done
David Bainbridge0774b232019-08-02 06:37:19 +0000944(set -x; screen -dmS voltha-etcd-$NAME bash -c "while true; do kubectl port-forward -n voltha service/voltha-etcd-cluster-client $VOLTHA_ETCD_PORT:2379; done" >>$LOG 2>&1) >>$LOG 2>&1
David Bainbridgeac7f8072019-08-01 22:15:33 +0000945espin - $VERIFIED
Test User3d7ad8e2019-07-03 06:15:44 +0000946
David Bainbridgeb270c202019-07-26 01:44:42 +0000947if [ $WITH_ONOS == "yes" -a $WITH_RADIUS == "yes" ]; then
David Bainbridge5b7b96b2019-07-25 20:29:13 +0000948 bspin "Configure ONOS RADIUS Connection $GEAR"
949 (set -x; cat onos-files/radius-config.json | sed -e "s/:RADIUS_IP:/$(kubectl -n voltha get service/radius -o jsonpath={.spec.clusterIP})/g" | curl -XPOST -sSL http://karaf:karaf@localhost:8181/onos/v1/network/configuration -H Content-type:application/json -d@- >>$LOG 2>&1) >>$LOG 2>&1
950 espin $VERIFIED
951fi
952
953bspin "Create voltctl configuration file"
Test User3d7ad8e2019-07-03 06:15:44 +0000954(set -x; mkdir -p $HOME/.volt >>$LOG 2>&1) >>$LOG 2>&1
David Bainbridge0774b232019-08-02 06:37:19 +0000955(set -x; voltctl -a v2 -s localhost:$VOLTHA_API_PORT config > $HOME/.volt/config-$NAME 2>>$LOG) >>$LOG 2>&1
David Bainbridge5b7b96b2019-07-25 20:29:13 +0000956espin $VERIFIED
Test User08ebbd92019-07-03 17:15:39 +0000957
David Bainbridge0774b232019-08-02 06:37:19 +0000958if [ ! -f "$NAME-env.sh" ]; then
959 touch $NAME-env.sh
David Bainbridgeb07fdf72019-07-29 22:51:40 +0000960fi
961
David Bainbridge596f30d2019-07-30 17:07:59 +0000962for O in $ALL_OPTIONS; do
963 VAL=$(eval echo \$$O)
964 if [ $O == "USE_GO" ]; then
965 VAL="$(echo $VAL| test $(grep -c true) -eq 1 && echo yes || echo no)"
966 fi
David Bainbridge0774b232019-08-02 06:37:19 +0000967 if [ ! -z "$VAL" -a $(grep -c "^export $O=" $NAME-env.sh) -eq 0 ]; then
968 echo "export $O=\"$(eval echo \$$O)\"" >> $NAME-env.sh
David Bainbridgeb07fdf72019-07-29 22:51:40 +0000969 fi
970done
971
David Bainbridge0774b232019-08-02 06:37:19 +0000972if [ $DEPLOY_K8S == "yes" -a $(grep -c "^export KUBECONFIG=" $NAME-env.sh) -eq 0 ]; then
973 echo "export KUBECONFIG=\"$(./bin/kind get kubeconfig-path --name=voltha-$NAME)\"" >> $NAME-env.sh
David Bainbridgeb07fdf72019-07-29 22:51:40 +0000974fi
975
David Bainbridge0774b232019-08-02 06:37:19 +0000976if [ $(grep -c "^export VOLTCONFIG=" $NAME-env.sh) -eq 0 ]; then
977 echo "export VOLTCONFIG=\"$HOME/.volt/config-$NAME\"" >> $NAME-env.sh
David Bainbridgeb07fdf72019-07-29 22:51:40 +0000978fi
979
David Bainbridge0774b232019-08-02 06:37:19 +0000980if [ $(grep -c "^export PATH=" $NAME-env.sh) -eq 0 ]; then
981 echo "export PATH=\"$GOPATH/bin:\$PATH\"" >> $NAME-env.sh
David Bainbridgeb07fdf72019-07-29 22:51:40 +0000982fi
983
Test User7d866122019-07-09 17:52:35 +0000984echo ""
Test User08ebbd92019-07-03 17:15:39 +0000985echo "Please issue the following commands in your terminal to ensure that you" | tee -a $LOG
986echo "are accessing the correct Kubernetes/Kind cluster as well as have the " | tee -a $LOG
987echo "tools required by VOLTHA in your command path. " | tee -a $LOG
988echo "" | tee -a $LOG
Test User7d866122019-07-09 17:52:35 +0000989echo -en $BOLD
Test Userba1e7e72019-07-10 22:27:54 +0000990if [ $DEPLOY_K8S == "yes" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000991 echo "export KUBECONFIG=\"\$(./bin/kind get kubeconfig-path --name=\"voltha-$NAME\")\"" | tee -a $LOG
Test Userba1e7e72019-07-10 22:27:54 +0000992fi
David Bainbridge0774b232019-08-02 06:37:19 +0000993echo "export VOLTCONFIG=\"$HOME/.volt/config-$NAME\"" | tee -a $LOG
Test Userba1e7e72019-07-10 22:27:54 +0000994echo "export PATH=$GOPATH/bin:\$PATH" | tee -a $LOG
Test User7d866122019-07-09 17:52:35 +0000995echo -en $NORMAL
Test User08ebbd92019-07-03 17:15:39 +0000996echo "" | tee -a $LOG
997echo "Thank you for choosing kind-voltha for you quick cluster needs." | tee -a $LOG
998