blob: 1a0d60826de2809e5ec15841f85d895b70935724 [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
16# trap ctrl-c and call ctrl_c()
17trap ctrl_c INT
18
19function ctrl_c() {
20 tput cnorm
21 echo ""
22 echo "ctrl-c trapped"
23 echo "Thank you for trying 'votlha up'"
24 exit
25}
26
Test User08ebbd92019-07-03 17:15:39 +000027VOLTCTL_VERSION=${VOLTCTL_VERSION:-0.0.5-dev}
28KIND_VERSION=${KIND_VERSION:-v0.4.0}
29_VOLTCTL_VERSION=$(echo $VOLTCTL_VERSION | sed -e 's/-/_/g')
30
Test User7d866122019-07-09 17:52:35 +000031BLACK=$(tput setaf 0)
32RED=$(tput setaf 1)
33GREEN=$(tput setaf 2)
34YELLOW=$(tput setaf 3)
35BLUE=$(tput setaf 4)
36MAGENTA=$(tput setaf 5)
37CYAN=$(tput setaf 6)
38WHITE=$(tput setaf 7)
39BOLD=$(tput bold)
40NORMAL=$(tput sgr0)
41ERROR="\xe2\x9c\x97\x20"
42
Test User3d7ad8e2019-07-03 06:15:44 +000043TYPE=${TYPE:-minimal}
Test User7d866122019-07-09 17:52:35 +000044WITH_BBSIM=${WITH_BBSIM:-no}
Test Userba1e7e72019-07-10 22:27:54 +000045JUST_K8S=${JUST_K8S:-no}
46DEPLOY_K8S=${DEPLOY_K8S:-yes}
David Bainbridgee10f6d52019-07-25 00:28:13 +000047SKIP_RESTART_API=${SKIP_RESTART_API:-no}
David K. Bainbridge0e89cb92019-07-17 11:30:10 -070048INSTALL_KUBECTL=${INSTALL_KUBECTL:-yes}
49INSTALL_HELM=${INSTALL_HELM:-yes}
David Bainbridgee10f6d52019-07-25 00:28:13 +000050VOLTHA_CHART=${VOLTHA_CHART:=onf/voltha}
51VOLTHA_ADAPTER_SIM_CHART=${VOLTHA_ADAPTER_SIM_CHART:-onf/voltha-adapter-simulated}
52VOLTHA_ADAPTER_OPEN_OLT_CHART=${VOLTHA_ADAPTER_OPEN_OLT_CHART:-onf/voltha-adapter-openolt}
53VOLTHA_ADAPTER_OPEN_ONU_CHART=${VOLTHA_ADAPTER_OPEN_ONU_CHART:-onf/voltha-adapter-openonu}
54VOLTHA_LOG_LEVEL=${VOLTHA_LOG_LEVEL:-WARN}
David Bainbridge1ceabc12019-07-25 17:21:05 +000055USE_GO=${USE_GO:-yes}
Test Userba1e7e72019-07-10 22:27:54 +000056
57HAVE_GO=$(which go >/dev/null 2>&1 && echo "yes" || echo "no")
58HOSTOS=$(uname -s | tr "[:upper:]" "[:lower:"])
59HOSTARCH=$(uname -m | tr "[:upper:]" "[:lower:"])
60if [ $HOSTARCH == "x86_64" ]; then
61 HOSTARCH="amd64"
62fi
Test User7d866122019-07-09 17:52:35 +000063
64# Verify TYPE setting
65if [ $(echo ":minimal:full:" | grep -ic ":$TYPE:") -eq 0 ]; then
David K. Bainbridge0e89cb92019-07-17 11:30:10 -070066 >&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 +000067 exit 1
68fi
69
70# Verify WITH_BBSIM settting and convert uniform value of yes or no
71if [ $(echo ":y:yes:true:n:no:false:1:0:" | grep -ic ":$WITH_BBSIM:") -eq 0 ]; then
David K. Bainbridge0e89cb92019-07-17 11:30:10 -070072 >&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 +000073 exit 1
74fi
75if [ $(echo ":y:yes:true:1:" | grep -ic ":$WITH_BBSIM:") -eq 1 ]; then
76 WITH_BBSIM=yes
77else
78 WITH_BBSIM=no
79fi
80
Test Userba1e7e72019-07-10 22:27:54 +000081# Verify JUST_K8S settting and convert uniform value of yes or no
82if [ $(echo ":y:yes:true:n:no:false:1:0:" | grep -ic ":$JUST_K8S:") -eq 0 ]; then
David K. Bainbridge0e89cb92019-07-17 11:30:10 -070083 >&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 +000084 exit 1
85fi
86if [ $(echo ":y:yes:true:1:" | grep -ic ":$JUST_K8S:") -eq 1 ]; then
87 JUST_K8S=yes
88else
89 JUST_K8S=no
90fi
91
92# Verify DEPLOY_K8S settting and convert uniform value of yes or no
93if [ $(echo ":y:yes:true:n:no:false:1:0:" | grep -ic ":$DEPLOY_K8S:") -eq 0 ]; then
David K. Bainbridge0e89cb92019-07-17 11:30:10 -070094 >&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 +000095 exit 1
96fi
97if [ $(echo ":y:yes:true:1:" | grep -ic ":$DEPLOY_K8S:") -eq 1 ]; then
98 DEPLOY_K8S=yes
99else
100 DEPLOY_K8S=no
101fi
Test User01ed0642019-07-03 20:17:06 +0000102
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700103# Verify INSTALL_KUBECTL settting and convert uniform value of yes or no
104if [ $(echo ":y:yes:true:n:no:false:1:0:" | grep -ic ":$INSTALL_KUBECTL:") -eq 0 ]; then
105 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} Invalid \$INSTALL_KUBECTL value of '$INSTALL_KUBECTL'. Should be 'yes' or 'no'${NORMAL}"
106 exit 1
107fi
108
109if [ $(echo ":y:yes:true:1:" | grep -ic ":$INSTALL_KUBECTL:") -eq 1 ]; then
110 INSTALL_KUBECTL=yes
111else
112 INSTALL_KUBECTL=no
113fi
114
David Bainbridgee10f6d52019-07-25 00:28:13 +0000115# Verify SKIP_RESTART_API settting and convert uniform value of yes or no
116if [ $(echo ":y:yes:true:n:no:false:1:0:" | grep -ic ":$SKIP_RESTART_API:") -eq 0 ]; then
117 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} Invalid \$SKIP_RESTART_API value of '$SKIP_RESTART_API'. Should be 'yes' or 'no'${NORMAL}"
118 exit 1
119fi
120if [ $(echo ":y:yes:true:1:" | grep -ic ":$SKIP_RESTART_API:") -eq 1 ]; then
121 SKIP_RESTART_API=yes
122else
123 SKIP_RESTART_API=no
124fi
125
David Bainbridge1ceabc12019-07-25 17:21:05 +0000126# Verify USE_GO settting and convert uniform value of yes or no
127if [ $(echo ":y:yes:true:n:no:false:1:0:" | grep -ic ":$USE_GO:") -eq 0 ]; then
128 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} Invalid \$USE_GO value of '$USE_GO'. Should be 'yes' or 'no'${NORMAL}"
129 exit 1
130fi
131if [ $(echo ":y:yes:true:1:" | grep -ic ":$USE_GO:") -eq 1 ]; then
132 USE_GO=true
133else
134 USE_GO=false
135fi
136
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700137# Verify INSTALL_HELM settting and convert uniform value of yes or no
138if [ $(echo ":y:yes:true:n:no:false:1:0:" | grep -ic ":$INSTALL_HELM:") -eq 0 ]; then
139 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} Invalid \$INSTALL_HELM value of '$INSTALL_HELM'. Should be 'yes' or 'no'${NORMAL}"
140 exit 1
141fi
142
143if [ $(echo ":y:yes:true:1:" | grep -ic ":$INSTALL_HELM:") -eq 1 ]; then
144 INSTALL_HELM=yes
145else
146 INSTALL_HELM=no
147fi
148
Test User01ed0642019-07-03 20:17:06 +0000149if [ "$TYPE" == "full" ]; then
150 ONOS_API_PORT=${ONOS_API_PORT:-8182}
151 ONOS_SSH_PORT=${ONOS_SSH_PORT:-8102}
152 VOLTHA_API_PORT=${VOLTHA_API_PORT:-55556}
153 VOLTHA_SSH_PORT=${VOLTHA_SSH_PORT:-5023}
154else
155 ONOS_API_PORT=${ONOS_API_PORT:-8181}
156 ONOS_SSH_PORT=${ONOS_SSH_PORT:-8101}
157 VOLTHA_API_PORT=${VOLTHA_API_PORT:-55555}
158 VOLTHA_SSH_PORT=${VOLTHA_SSH_PORT:-5022}
159fi
160
161if [ "$1" == "get" -a "$2" == "voltconfig" ]; then
162 echo "$HOME/.volt/config-$TYPE"
163 exit
164fi
Test User3d7ad8e2019-07-03 06:15:44 +0000165
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700166if [ $# -ne 1 -o $(echo ":up:down:" | grep -c ":$1:") -ne 1 ]; then
167 >&2 echo "up or down?"
168 exit 1
169fi
170
171if [ "$1" == "down" ]; then
Test Userba1e7e72019-07-10 22:27:54 +0000172 if [ $DEPLOY_K8S == "yes" ]; then
173 if [ -x ./bin/kind ]; then
174 exec ./bin/kind delete cluster --name voltha-$TYPE
175 else
176 >&2 echo "Kind doesn't seem to be installed, so nothing to do. Bye."
177 fi
Test User08ebbd92019-07-03 17:15:39 +0000178 else
Test Userba1e7e72019-07-10 22:27:54 +0000179 EXISTS=$(helm list -q)
180 EXPECT="etcd-operator onos open-olt open-onu sim voltha"
181 INTERSECT=
182 for i in $EXISTS; do
183 if [ $(echo $EXPECT | grep -c $i) -eq 1 ]; then
184 HAVE="$HAVE $i"
185 fi
186 done
187 ./bin/helm delete --purge $HAVE
188fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700189 exit
190fi
191
Test User01ed0642019-07-03 20:17:06 +0000192LOG="install-$TYPE.log"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700193date > $LOG
194
David Bainbridge1ceabc12019-07-25 17:21:05 +0000195# Output install options to log
196echo "OPTIONS" >> $LOG
197echo " TYPE = $TYPE" >> $LOG
198echo " WITH_BBSIM = $WITH_BBSIM" >> $LOG
199echo " JUST_K8S = $JUST_K8S" >> $LOG
200echo " DEPLOY_K8S = $DEPLOY_K8S" >> $LOG
201echo " SKIP_RESTART_API = $SKIP_RESTART_API" >> $LOG
202echo " INSTALL_KUBECTL = $INSTALL_KUBECTL" >> $LOG
203echo " INSTALL_HELM = $INSTALL_HELM" >> $LOG
204echo " VOLTHA_CHART = $VOLTHA_CHART" >> $LOG
205echo " VOLTHA_ADAPTER_SIM_CHART = $VOLTHA_ADAPTER_SIM_CHART" >> $LOG
206echo " VOLTHA_ADAPTER_OPEN_OLT_CHART = $VOLTHA_ADAPTER_OPEN_OLT_CHART" >> $LOG
207echo " VOLTHA_ADAPTER_OPEN_ONU_CHART = $VOLTHA_ADAPTER_OPEN_ONU_CHART" >> $LOG
208echo " VOLTHA_LOG_LEVEL = $VOLTHA_LOG_LEVEL" >> $LOG
209echo " USE_GO = $(echo $USE_GO | test $(grep -c true) -eq 1 && echo yes || echo no)" >> $LOG
210
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700211spin() {
Test Userd87942b2019-07-03 07:20:24 +0000212 PARTS="\
213 \xe2\xa2\x8e\xe2\xa1\xb0 \
214 \xe2\xa2\x8e\xe2\xa1\xa1 \
215 \xe2\xa2\x8e\xe2\xa1\x91 \
216 \xe2\xa2\x8e\xe2\xa0\xb1 \
217 \xe2\xa0\x8e\xe2\xa1\xb1 \
218 \xe2\xa2\x8a\xe2\xa1\xb1 \
219 \xe2\xa2\x8c\xe2\xa1\xb1 \
220 \xe2\xa2\x86\xe2\xa1\xb1 \
221 "
222 IDX=1
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700223 tput civis
224 while true; do
Test Userd87942b2019-07-03 07:20:24 +0000225 C=$(echo $PARTS | cut '-d ' -f $IDX)
226 echo -en "$C"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700227 IDX=$(expr $IDX + 1)
Test Userd87942b2019-07-03 07:20:24 +0000228 if [ $IDX -gt 8 ]; then
229 IDX=1
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700230 fi
231 sleep .15
232 echo -en "\r"
233 done
234}
235
Test Userd87942b2019-07-03 07:20:24 +0000236SPIN_PARTS="\
237 \xe2\xa2\x8e\xe2\xa1\xb0 \
238 \xe2\xa2\x8e\xe2\xa1\xa1 \
239 \xe2\xa2\x8e\xe2\xa1\x91 \
240 \xe2\xa2\x8e\xe2\xa0\xb1 \
241 \xe2\xa0\x8e\xe2\xa1\xb1 \
242 \xe2\xa2\x8a\xe2\xa1\xb1 \
243 \xe2\xa2\x8c\xe2\xa1\xb1 \
244 \xe2\xa2\x86\xe2\xa1\xb1 \
245 "
246IDX=1
247NOT_VERIFIED="\xe2\x9c\x97\x20"
248VERIFIED="\xe2\x9c\x93\x20"
Test Userb5712372019-07-03 21:52:17 +0000249HELM="\xE2\x8E\x88"
250OLD_KEY="\xF0\x9F\x97\x9D"
251BIRD="\xF0\x9F\x90\xA6"
252HIGH_VOLTAGE="\xE2\x9A\xA1"
253PLUG="\xF0\x9F\xa7\xa9"
254RESTART="\xf0\x9f\x94\x84"
255FORWARD="\xE2\x87\xA8"
256INSTALL="\xF0\x9F\x8F\x97"
257STOP="\xf0\x9f\x9b\x91"
258GO="\xf0\x9f\x9a\x80"
259DOWNLOAD="\xf0\x9f\x93\xa5"
260GEAR="\xe2\x9a\x99"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700261NO_ENTRY="\xe2\x9b\x94"
262
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700263bspin() {
264 tput civis
Test Userd87942b2019-07-03 07:20:24 +0000265 IDX=1
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700266 local INDENT=
267 if [ "$1" == "-" ]; then
268 INDENT=" "
269 shift
270 fi
Test Userd87942b2019-07-03 07:20:24 +0000271 echo -en "$INDENT $*"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700272}
273
274sspin() {
275 local INDENT=
276 if [ "$1" == "-" ]; then
277 INDENT=" "
278 shift
279 fi
Test Userd87942b2019-07-03 07:20:24 +0000280 C=$(echo $SPIN_PARTS | cut '-d ' -f $IDX)
281 echo -en "\r$INDENT$C $*"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700282 IDX=$(expr $IDX + 1)
Test Userd87942b2019-07-03 07:20:24 +0000283 if [ $IDX -gt 8 ]; then
284 IDX=1
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700285 fi
286}
287
288espin() {
289 local INDENT=
290 if [ "$1" == "-" ]; then
291 INDENT=" "
292 shift
293 fi
294 echo -e "\r$INDENT$*"
295 tput cnorm
296}
297
298count_pods() {
299 local NAMESPACE=$1; shift
300 local PODS=$(kubectl -n $NAMESPACE get pod -o go-template="{{range .items}}{{.metadata.name}}/{{.status.phase}}/_{{range .status.containerStatuses}}{{.ready}}_{{end}} {{end}}")
301 local COUNT=0
302 local PATTERNS=$*
303 for POD in $PODS; do
304 local NAME=$(echo $POD | cut -d/ -f 1)
305 local STATE=$(echo $POD | cut -d/ -f 2)
306 local CONTAINERS=$(echo $POD | cut -d/ -f 3 | sed -e 's/_/ /g')
307 if [ "$STATE" == "Running" ]; then
308 local TOTAL=$(echo $CONTAINERS | wc -w)
309 local FOUND=$(echo $CONTAINERS | grep -o true | wc -l)
310 if [ $TOTAL -eq $FOUND ]; then
311 for PATTERN in $PATTERNS; do
312 if [[ $NAME =~ $PATTERN ]]; then
313 COUNT=$(expr $COUNT + 1)
314 fi
315 done
316 fi
317 fi
318 done
319 echo $COUNT
320}
321
322wait_for_pods() {
323 local INDENT=
324 if [ "$1" == "-" ]; then
325 INDENT=$1; shift
326 fi
327 local NAMESPACE=$1; shift
328 local EXPECT=$1; shift
329 local RETRY=$1; shift
330 local MESSAGE=$1; shift
331 local PATTERNS=$*
332 local HAVE=$(count_pods $NAMESPACE $PATTERNS)
333 COUNT=$(expr 300 / 15)
334 bspin $INDENT $MESSAGE
335 sspin $INDENT
336 if [ $HAVE -ne $EXPECT ]; then
337 while [ $HAVE -ne $EXPECT ]; do
338 sspin $INDENT
339 COUNT=$(expr $COUNT - 1)
340 if [ $COUNT -eq 0 ]; then
341 HAVE=$(count_pods $NAMESPACE $PATTERNS)
342 COUNT=$(expr 300 / 15)
343 fi
344 sleep .15
345 done
346 fi
347 espin $INDENT $VERIFIED
348 if [ $HAVE -ne $EXPECT ]; then
349 return 1
350 fi
351 return 0
352}
353
354helm_install() {
355 local INDENT=
356 if [ "$1" == "-" ]; then
357 INDENT=$1; shift
358 fi
359 local NAMESPACE=$1; shift
360 local NAME=$1; shift
361 local CHART=$1; shift
362 local MESSAGE=$*
363
364 COUNT=$(expr 300 / 15)
365 bspin $INDENT $MESSAGE
David Bainbridge1ceabc12019-07-25 17:21:05 +0000366 (set -x; helm install -f $TYPE-values.yaml --set use_go=$USE_GO --set defaults.log_level=$VOLTHA_LOG_LEVEL --namespace $NAMESPACE --name $NAME $CHART >>$LOG 2>&1) >>$LOG 2>&1
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700367 SUCCESS=$?
368 while [ $SUCCESS -ne 0 ]; do
369 sspin $INDENT
370 COUNT=$(expr $COUNT - 1)
371 if [ $COUNT -eq 0 ]; then
David Bainbridgee10f6d52019-07-25 00:28:13 +0000372 (set -x; helm install -f $TYPE-values.yaml --set defaults.log_level=$VOLTHA_LOG_LEVEL --namespace $NAMESPACE --name $NAME $CHART >>$LOG 2>&1) >>$LOG 2>&1
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700373 COUNT=$(expr 300 / 15)
374 fi
375 sleep .15
376 done
377 espin $INDENT $VERIFIED
378}
379
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700380echo "INSTALL TYPE: $TYPE" >> $LOG
381
382bspin "Verify GOPATH"
383export GOPATH=$(pwd)
Test User3d7ad8e2019-07-03 06:15:44 +0000384mkdir -p $GOPATH/bin
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700385espin $VERIFIED
386
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700387if [ "$INSTALL_KUBECTL" == "no" ]; then
388 bspin "Skip kubectl install"
389 espin $NO_ENTRY
Test Userc13bdc92019-07-03 20:57:49 +0000390else
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700391 bspin "Verify kubectl $HELM"
392 if [ -x $GOPATH/bin/kubectl ]; then
393 espin $VERIFIED
394 else
395 espin $NOT_VERIFIED
396 bspin - "Download and install Kubernetes/kubectl $DOWNLOAD"
397 (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
398 (set -x; chmod 755 $GOPATH/bin/kubectl >>$LOG 2>&1) >>$LOG 2>&1
399 espin - $VERIFIED
400 fi
Test Userc13bdc92019-07-03 20:57:49 +0000401fi
402
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700403if [ "$DEPLOY_K8S" == "no" ]; then
404 bspin "Skip Kubernetes/Kind Deployment"
405 espin $NO_ENTRY
406else
Test Userba1e7e72019-07-10 22:27:54 +0000407 bspin "Verify Kubernetes/Kind $HELM"
408 if [ -x $GOPATH/bin/kind ]; then
409 espin $VERIFIED
410 else
411 espin $NOT_VERIFIED
412 bspin - "Download and install Kubernetes/kind $DOWNLOAD"
David Bainbridge9e2a6662019-07-11 17:07:57 +0000413 (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 +0000414 (set -x; chmod 755 $GOPATH/bin/kind >>$LOG 2>&1) >>$LOG 2>&1
415 espin - $VERIFIED
416 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700417fi
418
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700419if [ "$INSTALL_HELM" == "no" ]; then
420 bspin "Skip Helm Install"
421 espin $NO_ENTRY
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700422else
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700423 bspin "Verify Helm $HELM"
424 if [ -x $GOPATH/bin/helm ]; then
425 espin $VERIFIED
426 else
427 espin $NOT_VERIFIED
428 bspin - "Download and install Helm $DOWNLOAD"
429 (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
430 espin - $VERIFIED
431 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700432fi
433
Test Userb5712372019-07-03 21:52:17 +0000434bspin "Verify voltctl $HIGH_VOLTAGE"
Test User3d7ad8e2019-07-03 06:15:44 +0000435if [ -x $GOPATH/bin/voltctl ]; then
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700436 espin $VERIFIED
437else
438 espin $NOT_VERIFIED
Test Userb5712372019-07-03 21:52:17 +0000439 bspin - "Download and build voltctl $DOWNLOAD"
Test Userba1e7e72019-07-10 22:27:54 +0000440 (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 +0000441 (set -x; chmod 755 $GOPATH/bin/voltctl >>$LOG 2>&1) >>$LOG 2>&1
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700442 espin - $VERIFIED
443fi
444
445bspin "Verify command PATH"
Test Userba1e7e72019-07-10 22:27:54 +0000446export PATH=$GOPATH/bin:$PATH
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700447espin $VERIFIED
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700448
Test Userba1e7e72019-07-10 22:27:54 +0000449if [ "$DEPLOY_K8S" == "yes" ]; then
450 HAVE=$(kind get clusters | grep -c voltha-$TYPE)
451 bspin "Verify Kubernetes/Kind Cluster"
452 sspin
453 if [ $HAVE -eq 0 ]; then
David Bainbridge491b1bd2019-07-11 17:53:11 +0000454 espin $NOT_VERIFIED
455 bspin - "Verify cluster configuration"
456 if [ ! -r ./$TYPE-cluster.cfg ]; then
457 espin - $NOT_VERIFIED
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700458 bspin - "Download cluster configuration: $TYPE-cluster.cfg $DOWNLOAD"
David Bainbridge491b1bd2019-07-11 17:53:11 +0000459 (set -x; curl -o ./$TYPE-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 -0700460 espin - $VERIFIED
461 else
462 espin - $VERIFIED
463 fi
David Bainbridge491b1bd2019-07-11 17:53:11 +0000464 kind create cluster --name voltha-$TYPE --config $TYPE-cluster.cfg
465 else
466 espin $VERIFIED
Test Userba1e7e72019-07-10 22:27:54 +0000467 fi
468
469 export KUBECONFIG="$(kind get kubeconfig-path --name="voltha-$TYPE")"
470 P="coredns-.* \
471 etcd-voltha-$TYPE-control-plane \
472 kindnet-.* \
473 kube-apiserver-voltha-$TYPE-control-plane \
474 kube-controller-manager-voltha-$TYPE-control-plane \
475 kube-proxy-.* \
476 kube-scheduler-voltha-$TYPE-control-plane"
477
478 EXPECT=$(test "$TYPE" == "minimal" && echo "12" || echo "14")
479 wait_for_pods - "kube-system" $EXPECT -1 "Waiting for system PODs to start" $P
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700480fi
481
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700482COUNT=$(count_pods "kube-system" "tiller-deploy-.*")
483bspin "Verify Helm"
Test Userba1e7e72019-07-10 22:27:54 +0000484if [ $COUNT -ne 1 ]; then
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700485 espin $NOT_VERIFIED
Test Userb5712372019-07-03 21:52:17 +0000486 echo -e "Configuring Helm $GEAR"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700487 if [ "$INSTALL_HELM" == "no" ]; then
488 bspin - "Skip Helm/Tiller Initialization"
489 espin - $NO_ENTRY
490 else
491 bspin - "Initialize Helm"
492 (set -x; helm init --upgrade >>$LOG 2>&1) >>$LOG 2>&1
493 espin - $VERIFIED
494 wait_for_pods - "kube-system" 1 -1 "Waiting for Tiller POD to start" "tiller-deploy-.*"
495 fi
Test Userb5712372019-07-03 21:52:17 +0000496 bspin - "Add Google Incubator repository to Helm"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700497 (set -x; helm repo add incubator https://kubernetes-charts-incubator.storage.googleapis.com >>$LOG 2>&1) >>$LOG 2>&1
498 espin - $VERIFIED
Test Userba1e7e72019-07-10 22:27:54 +0000499
500 # HACK (sort-of) - the config for tiller is about to be patched, which will
501 # cause the tiller pod to be recreated. This can sometimes cause a timing
502 # issue with the "wait_for_pods" call on tiller as it may incorrectly
503 # identify the running/ready tiller pod that is soon to be terminated as
504 # what it is waiting for. To avoid this issue we do a clean scale down and
505 # scale up of the pod so the script controlls when it should be expecting
506 # things
507 (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 -0700508
Test Userb5712372019-07-03 21:52:17 +0000509 bspin - "Add Google Stable repository to Helm"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700510 (set -x; helm repo add stable https://kubernetes-charts.storage.googleapis.com >>$LOG 2>&1) >>$LOG 2>&1
511 espin - $VERIFIED
Test Userb5712372019-07-03 21:52:17 +0000512 bspin - "Add ONF repository to Helm"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700513 (set -x; helm repo add onf https://charts.opencord.org >>$LOG 2>&1) >>$LOG 2>&1
514 espin - $VERIFIED
Test Userb5712372019-07-03 21:52:17 +0000515 bspin - "Update Helm repository cache"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700516 (set -x; helm repo update >>$LOG 2>&1) >>$LOG 2>&1
517 espin - $VERIFIED
518
519 # Create and k8s service account so that Helm can create pods
Test Userb5712372019-07-03 21:52:17 +0000520 bspin - "Create Tiller ServiceAccount"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700521 (set -x; kubectl create serviceaccount --namespace kube-system tiller >>$LOG 2>&1) >>$LOG 2>&1
522 espin - $VERIFIED
Test Userb5712372019-07-03 21:52:17 +0000523 bspin - "Create Tiller ClusterRoleBinding"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700524 (set -x; kubectl create clusterrolebinding tiller-cluster-rule --clusterrole=cluster-admin --serviceaccount=kube-system:tiller >>$LOG 2>&1) >>$LOG 2>&1
525 espin - $VERIFIED
Test Userb5712372019-07-03 21:52:17 +0000526 bspin - "Update Tiller Manifest"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700527 (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 +0000528
529 # HACK (sort-of) - part to, spin it back up
530 (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 -0700531 espin - $VERIFIED
532else
533 espin $VERIFIED
534fi
Test Userb5712372019-07-03 21:52:17 +0000535wait_for_pods - "kube-system" 1 -1 "Waiting for Tiller POD to start" "tiller-deploy-.*"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700536
Test Userba1e7e72019-07-10 22:27:54 +0000537bspin "Verify Helm values file: $TYPE-values.yaml"
538if [ ! -r "./$TYPE-values.yaml" ]; then
539 espin $NOT_VERIFIED
540 bspin - "Download Helm values file: $TYPE-values.yaml $DOWNLOAD"
541 (set -x; curl -o ./$TYPE-values.yaml -sSL https://raw.githubusercontent.com/ciena/kind-voltha/master/$TYPE-values.yaml >>$LOG 2>&1) >>$LOG 2>&1
542 espin - $VERIFIED
543else
544 espin $VERIFIED
545fi
546
547if [ "$JUST_K8S" == "yes" ]; then
548 echo "Environment deployed, not deploying VOLTHA artifacts as requested. Good bye."
549 echo ""
550 echo "Please issue the following commands in your terminal to ensure that you" | tee -a $LOG
551 echo "are accessing the correct Kubernetes/Kind cluster as well as have the " | tee -a $LOG
552 echo "tools required by VOLTHA in your command path. " | tee -a $LOG
553 echo "" | tee -a $LOG
554 echo -en $BOLD
555 if [ $DEPLOY_K8S == "yes" ]; then
556 echo "export KUBECONFIG=\"\$(./bin/kind get kubeconfig-path --name=\"voltha-$TYPE\")\"" | tee -a $LOG
557 fi
558 echo "export PATH=$GOPATH/bin:\$PATH" | tee -a $LOG
559 echo -en $NORMAL
560 echo "" | tee -a $LOG
561 echo "Thank you for choosing kind-voltha for you quick cluster needs." | tee -a $LOG
562 exit 0
563fi
564
Test Userb5712372019-07-03 21:52:17 +0000565bspin "Verify ETCD Operator $OLD_KEY"
Test User7d866122019-07-09 17:52:35 +0000566if [ $(helm list --deployed --short --namespace voltha "^etcd-operator\$" | wc -l) -ne 1 ]; then
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700567 espin $NOT_VERIFIED
568 helm_install - voltha etcd-operator stable/etcd-operator "Install ETCD Operator"
569else
570 espin $VERIFIED
571fi
Test User01ed0642019-07-03 20:17:06 +0000572EXPECT=$(test "$TYPE" == "minimal" && echo "1" || echo "3")
Test Userb5712372019-07-03 21:52:17 +0000573wait_for_pods - "voltha" $EXPECT -1 "Waiting for ETCD Operator to start" "etcd-operator-.*"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700574
Test Userb5712372019-07-03 21:52:17 +0000575bspin "Verify ONOS installed $BIRD"
Test User7d866122019-07-09 17:52:35 +0000576if [ $(helm list --deployed --short --namespace default "^onos\$" | wc -l) -ne 1 ]; then
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700577 espin $NOT_VERIFIED
578 helm_install - default onos onf/onos "Install ONOS"
579else
580 espin $VERIFIED
581fi
Test Userb5712372019-07-03 21:52:17 +0000582wait_for_pods - "default" 1 -1 "Waiting for ONOS to start" "onos-.*"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700583
Test Userb5712372019-07-03 21:52:17 +0000584bspin - "Forward ONOS API port $FORWARD"
Test User01ed0642019-07-03 20:17:06 +0000585(set -x; screen -p 0 -X -S onos-ui-$TYPE stuff $'\003' >>$LOG 2>&1) >>$LOG 2>&1
586(set -x; screen -dmS onos-ui-$TYPE kubectl port-forward service/onos-ui $ONOS_API_PORT:8181 >>$LOG 2>&1) >>$LOG 2>&1
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700587espin - $VERIFIED
Test Userb5712372019-07-03 21:52:17 +0000588bspin - "Forward ONOS SSH port $FORWARD"
Test User01ed0642019-07-03 20:17:06 +0000589(set -x; screen -p 0 -X -S onos-ssh-$TYPE stuff $'\003' >>$LOG 2>&1) >>$LOG 2>&1
590(set -x; screen -dmS onos-ssh-$TYPE kubectl port-forward service/onos-ssh $ONOS_SSH_PORT:8101 >>$LOG 2>&1) >>$LOG 2>&1
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700591espin - $VERIFIED
Test Userba1e7e72019-07-10 22:27:54 +0000592if [ ! -x ./onos-files/install-onos-applications.sh ]; then
593 bspin - "Verify or download ONOS configuration support files $DOWNLOAD"
594 (set -x; mkdir -p ./onos-files >>$LOG 2>&1) >>$LOG 2>&1
595 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; do
596 if [ ! -r ./onos-files/$i ]; then
597 (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
598 fi
599 done
600 (set -x; chmod 755 ./onos-files/install-onos-applications.sh >>$LOG 2>&1) >>$LOG 2>&1
601 espin - $VERIFIED
602fi
603
Test Userb5712372019-07-03 21:52:17 +0000604bspin - "Install required ONOS applications $INSTALL"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700605(set -x; ./onos-files/install-onos-applications.sh >>$LOG 2>&1) >>$LOG 2>&1
606espin - $VERIFIED
607
Test Userb5712372019-07-03 21:52:17 +0000608bspin "Verify VOLTHA installed $HIGH_VOLTAGE"
Test User7d866122019-07-09 17:52:35 +0000609if [ $(helm list --deployed --short --namespace voltha "^voltha\$" | wc -l) -ne 1 ]; then
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700610 espin $NOT_VERIFIED
David Bainbridgee10f6d52019-07-25 00:28:13 +0000611 helm_install - voltha voltha $VOLTHA_CHART "Install VOLTHA Core"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700612else
613 espin $VERIFIED
614fi
Test Userba1e7e72019-07-10 22:27:54 +0000615
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700616VOLTHA="ofagent-.* \
617 ro-core.* \
618 rw-core.* \
619 voltha-api-server-.* \
620 voltha-cli-server-.* \
621 voltha-etcd-cluster-.* \
622 voltha-kafka-.* \
623 voltha-zookeeper-.*"
Test User01ed0642019-07-03 20:17:06 +0000624EXPECT=$(test "$TYPE" == "minimal" && echo "9" || echo "11")
Test Userb5712372019-07-03 21:52:17 +0000625wait_for_pods - "voltha" $EXPECT -1 "Waiting for VOLTHA Core to start" $VOLTHA
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700626
Test Userb5712372019-07-03 21:52:17 +0000627echo -e "Verify Adapters $PLUG"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700628bspin - "Verify Simulated Adapters installed"
Test User7d866122019-07-09 17:52:35 +0000629if [ $(helm list --deployed --short --namespace voltha "^sim\$" | wc -l) -ne 1 ]; then
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700630 espin - $NOT_VERIFIED
David Bainbridgee10f6d52019-07-25 00:28:13 +0000631 helm_install - voltha sim $VOLTHA_ADAPTER_SIM_CHART "Install Simulated Adapters"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700632else
633 espin - $VERIFIED
634fi
635
636bspin - "Verify OpenOLT Adapter installed"
Test User7d866122019-07-09 17:52:35 +0000637if [ $(helm list --deployed --short --namespace voltha "^open-olt\$" | wc -l) -ne 1 ]; then
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700638 espin - $NOT_VERIFIED
David Bainbridgee10f6d52019-07-25 00:28:13 +0000639 helm_install - voltha open-olt $VOLTHA_ADAPTER_OPEN_OLT_CHART "Install OpenOLT Adapter"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700640else
641 espin - $VERIFIED
642fi
643bspin - "Verify OpenONU Adapter installed"
Test User7d866122019-07-09 17:52:35 +0000644if [ $(helm list --deployed --short --namespace voltha "^open-onu\$" | wc -l) -ne 1 ]; then
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700645 espin - $NOT_VERIFIED
David Bainbridgee10f6d52019-07-25 00:28:13 +0000646 helm_install - voltha open-onu $VOLTHA_ADAPTER_OPEN_ONU_CHART "Install OpenONU Adapter"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700647else
648 espin - $VERIFIED
649fi
650
651ADAPTERS="adapter-.*"
Test Userb5712372019-07-03 21:52:17 +0000652wait_for_pods - "voltha" 4 -1 "Waiting for adapters to start" $ADAPTERS
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700653
Test User7d866122019-07-09 17:52:35 +0000654if [ $WITH_BBSIM == "yes" ]; then
655 echo -e "Verify BBSIM $PLUG"
656 bspin - "Verify BBSIM Insalled"
657 if [ $(helm list --deployed --short --namespace voltha "^bbsim\$" | wc -l) -ne 1 ]; then
658 espin - $NOT_VERIFIED
659 helm_install - voltha bbsim onf/bbsim "Install BBSIM"
660 else
661 espin - $VERIFIED
662 fi
663 wait_for_pods - "voltha" 1 -1 "Waiting for BBSIM to start" "bbsim-.*"
664fi
665
David Bainbridgee10f6d52019-07-25 00:28:13 +0000666if [ $SKIP_RESTART_API == "no" ]; then
667 echo -e "Restart VOLTHA API $RESTART"
668 API="voltha-api-server-.* ofagent-.*"
669 (set -x; kubectl scale --replicas=0 deployment -n voltha voltha-api-server ofagent >>$LOG 2>&1) >>$LOG 2>&1
670 wait_for_pods - "voltha" 0 -1 "Wait for API to stop $STOP" $API
671 (set -x; kubectl scale --replicas=1 deployment -n voltha voltha-api-server ofagent >>$LOG 2>&1) >>$LOG 2>&1
672 wait_for_pods - "voltha" 2 -1 "Wait for API to re-start $GO" $API
673else
674 bspin "Skip VOLTHA API Restart"
675 espin $NO_ENTRY
676fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700677
Test Userb5712372019-07-03 21:52:17 +0000678bspin - "Forward VOLTHA API port $FORWARD"
Test User01ed0642019-07-03 20:17:06 +0000679(set -x; screen -p 0 -X -S voltha-api-$TYPE stuff $'\003' >>$LOG 2>&1) >>$LOG 2>&1
680(set -x; screen -dmS voltha-api-$TYPE kubectl port-forward -n voltha service/voltha-api $VOLTHA_API_PORT:55555 >>$LOG 2>&1) >>$LOG 2>&1
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700681espin - $VERIFIED
Test Userb5712372019-07-03 21:52:17 +0000682bspin - "Forward VOLTHA SSH port $FORWARD"
Test User01ed0642019-07-03 20:17:06 +0000683(set -x; screen -p 0 -X -S voltha-ssh-$TYPE stuff $'\003' 2>/dev/null >/dev/null >>$LOG 2>&1) >>$LOG 2>&1
684(set -x; screen -dmS voltha-ssh-$TYPE kubectl port-forward -n voltha service/voltha-cli $VOLTHA_SSH_PORT:5022 >>$LOG 2>&1) >>$LOG 2>&1
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700685espin - $VERIFIED
Test User3d7ad8e2019-07-03 06:15:44 +0000686
687bspin - "Create voltctl configuration file"
688(set -x; mkdir -p $HOME/.volt >>$LOG 2>&1) >>$LOG 2>&1
Test User01ed0642019-07-03 20:17:06 +0000689(set -x; voltctl -a v2 -s localhost:$VOLTHA_API_PORT config > $HOME/.volt/config-$TYPE 2>>$LOG) >>$LOG 2>&1
Test User3d7ad8e2019-07-03 06:15:44 +0000690espin - $VERIFIED
Test User08ebbd92019-07-03 17:15:39 +0000691
Test User7d866122019-07-09 17:52:35 +0000692echo ""
Test User08ebbd92019-07-03 17:15:39 +0000693echo "Please issue the following commands in your terminal to ensure that you" | tee -a $LOG
694echo "are accessing the correct Kubernetes/Kind cluster as well as have the " | tee -a $LOG
695echo "tools required by VOLTHA in your command path. " | tee -a $LOG
696echo "" | tee -a $LOG
Test User7d866122019-07-09 17:52:35 +0000697echo -en $BOLD
Test Userba1e7e72019-07-10 22:27:54 +0000698if [ $DEPLOY_K8S == "yes" ]; then
699 echo "export KUBECONFIG=\"\$(./bin/kind get kubeconfig-path --name=\"voltha-$TYPE\")\"" | tee -a $LOG
700fi
Test Userfa30f7f2019-07-03 20:35:19 +0000701echo "export VOLTCONFIG=\"$HOME/.volt/config-$TYPE\"" | tee -a $LOG
Test Userba1e7e72019-07-10 22:27:54 +0000702echo "export PATH=$GOPATH/bin:\$PATH" | tee -a $LOG
Test User7d866122019-07-09 17:52:35 +0000703echo -en $NORMAL
Test User08ebbd92019-07-03 17:15:39 +0000704echo "" | tee -a $LOG
705echo "Thank you for choosing kind-voltha for you quick cluster needs." | tee -a $LOG
706