blob: 13389147ddc92493fd8aed8c57ddf6ae092194d9 [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)
David Bainbridge7831a662019-07-25 18:12:25 +0000180 EXPECT="etcd-operator onos open-olt open-onu sim voltha bbsim"
Test Userba1e7e72019-07-10 22:27:54 +0000181 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
David Bainbridge7831a662019-07-25 18:12:25 +0000187 if [ "$HAVE X" != " X" ]; then
188 ./bin/helm delete --purge $HAVE
189 fi
Test Userba1e7e72019-07-10 22:27:54 +0000190fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700191 exit
192fi
193
Test User01ed0642019-07-03 20:17:06 +0000194LOG="install-$TYPE.log"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700195date > $LOG
196
David Bainbridge1ceabc12019-07-25 17:21:05 +0000197# Output install options to log
198echo "OPTIONS" >> $LOG
199echo " TYPE = $TYPE" >> $LOG
200echo " WITH_BBSIM = $WITH_BBSIM" >> $LOG
201echo " JUST_K8S = $JUST_K8S" >> $LOG
202echo " DEPLOY_K8S = $DEPLOY_K8S" >> $LOG
203echo " SKIP_RESTART_API = $SKIP_RESTART_API" >> $LOG
204echo " INSTALL_KUBECTL = $INSTALL_KUBECTL" >> $LOG
205echo " INSTALL_HELM = $INSTALL_HELM" >> $LOG
206echo " VOLTHA_CHART = $VOLTHA_CHART" >> $LOG
207echo " VOLTHA_ADAPTER_SIM_CHART = $VOLTHA_ADAPTER_SIM_CHART" >> $LOG
208echo " VOLTHA_ADAPTER_OPEN_OLT_CHART = $VOLTHA_ADAPTER_OPEN_OLT_CHART" >> $LOG
209echo " VOLTHA_ADAPTER_OPEN_ONU_CHART = $VOLTHA_ADAPTER_OPEN_ONU_CHART" >> $LOG
210echo " VOLTHA_LOG_LEVEL = $VOLTHA_LOG_LEVEL" >> $LOG
211echo " USE_GO = $(echo $USE_GO | test $(grep -c true) -eq 1 && echo yes || echo no)" >> $LOG
212
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700213spin() {
Test Userd87942b2019-07-03 07:20:24 +0000214 PARTS="\
215 \xe2\xa2\x8e\xe2\xa1\xb0 \
216 \xe2\xa2\x8e\xe2\xa1\xa1 \
217 \xe2\xa2\x8e\xe2\xa1\x91 \
218 \xe2\xa2\x8e\xe2\xa0\xb1 \
219 \xe2\xa0\x8e\xe2\xa1\xb1 \
220 \xe2\xa2\x8a\xe2\xa1\xb1 \
221 \xe2\xa2\x8c\xe2\xa1\xb1 \
222 \xe2\xa2\x86\xe2\xa1\xb1 \
223 "
224 IDX=1
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700225 tput civis
226 while true; do
Test Userd87942b2019-07-03 07:20:24 +0000227 C=$(echo $PARTS | cut '-d ' -f $IDX)
228 echo -en "$C"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700229 IDX=$(expr $IDX + 1)
Test Userd87942b2019-07-03 07:20:24 +0000230 if [ $IDX -gt 8 ]; then
231 IDX=1
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700232 fi
233 sleep .15
234 echo -en "\r"
235 done
236}
237
Test Userd87942b2019-07-03 07:20:24 +0000238SPIN_PARTS="\
239 \xe2\xa2\x8e\xe2\xa1\xb0 \
240 \xe2\xa2\x8e\xe2\xa1\xa1 \
241 \xe2\xa2\x8e\xe2\xa1\x91 \
242 \xe2\xa2\x8e\xe2\xa0\xb1 \
243 \xe2\xa0\x8e\xe2\xa1\xb1 \
244 \xe2\xa2\x8a\xe2\xa1\xb1 \
245 \xe2\xa2\x8c\xe2\xa1\xb1 \
246 \xe2\xa2\x86\xe2\xa1\xb1 \
247 "
248IDX=1
249NOT_VERIFIED="\xe2\x9c\x97\x20"
250VERIFIED="\xe2\x9c\x93\x20"
Test Userb5712372019-07-03 21:52:17 +0000251HELM="\xE2\x8E\x88"
252OLD_KEY="\xF0\x9F\x97\x9D"
253BIRD="\xF0\x9F\x90\xA6"
254HIGH_VOLTAGE="\xE2\x9A\xA1"
255PLUG="\xF0\x9F\xa7\xa9"
256RESTART="\xf0\x9f\x94\x84"
257FORWARD="\xE2\x87\xA8"
258INSTALL="\xF0\x9F\x8F\x97"
259STOP="\xf0\x9f\x9b\x91"
260GO="\xf0\x9f\x9a\x80"
261DOWNLOAD="\xf0\x9f\x93\xa5"
262GEAR="\xe2\x9a\x99"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700263NO_ENTRY="\xe2\x9b\x94"
264
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700265bspin() {
266 tput civis
Test Userd87942b2019-07-03 07:20:24 +0000267 IDX=1
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700268 local INDENT=
269 if [ "$1" == "-" ]; then
270 INDENT=" "
271 shift
272 fi
Test Userd87942b2019-07-03 07:20:24 +0000273 echo -en "$INDENT $*"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700274}
275
276sspin() {
277 local INDENT=
278 if [ "$1" == "-" ]; then
279 INDENT=" "
280 shift
281 fi
Test Userd87942b2019-07-03 07:20:24 +0000282 C=$(echo $SPIN_PARTS | cut '-d ' -f $IDX)
283 echo -en "\r$INDENT$C $*"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700284 IDX=$(expr $IDX + 1)
Test Userd87942b2019-07-03 07:20:24 +0000285 if [ $IDX -gt 8 ]; then
286 IDX=1
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700287 fi
288}
289
290espin() {
291 local INDENT=
292 if [ "$1" == "-" ]; then
293 INDENT=" "
294 shift
295 fi
296 echo -e "\r$INDENT$*"
297 tput cnorm
298}
299
300count_pods() {
301 local NAMESPACE=$1; shift
302 local PODS=$(kubectl -n $NAMESPACE get pod -o go-template="{{range .items}}{{.metadata.name}}/{{.status.phase}}/_{{range .status.containerStatuses}}{{.ready}}_{{end}} {{end}}")
303 local COUNT=0
304 local PATTERNS=$*
305 for POD in $PODS; do
306 local NAME=$(echo $POD | cut -d/ -f 1)
307 local STATE=$(echo $POD | cut -d/ -f 2)
308 local CONTAINERS=$(echo $POD | cut -d/ -f 3 | sed -e 's/_/ /g')
309 if [ "$STATE" == "Running" ]; then
310 local TOTAL=$(echo $CONTAINERS | wc -w)
311 local FOUND=$(echo $CONTAINERS | grep -o true | wc -l)
312 if [ $TOTAL -eq $FOUND ]; then
313 for PATTERN in $PATTERNS; do
314 if [[ $NAME =~ $PATTERN ]]; then
315 COUNT=$(expr $COUNT + 1)
316 fi
317 done
318 fi
319 fi
320 done
321 echo $COUNT
322}
323
324wait_for_pods() {
325 local INDENT=
326 if [ "$1" == "-" ]; then
327 INDENT=$1; shift
328 fi
329 local NAMESPACE=$1; shift
330 local EXPECT=$1; shift
331 local RETRY=$1; shift
332 local MESSAGE=$1; shift
333 local PATTERNS=$*
334 local HAVE=$(count_pods $NAMESPACE $PATTERNS)
335 COUNT=$(expr 300 / 15)
336 bspin $INDENT $MESSAGE
337 sspin $INDENT
338 if [ $HAVE -ne $EXPECT ]; then
339 while [ $HAVE -ne $EXPECT ]; do
340 sspin $INDENT
341 COUNT=$(expr $COUNT - 1)
342 if [ $COUNT -eq 0 ]; then
343 HAVE=$(count_pods $NAMESPACE $PATTERNS)
344 COUNT=$(expr 300 / 15)
345 fi
346 sleep .15
347 done
348 fi
349 espin $INDENT $VERIFIED
350 if [ $HAVE -ne $EXPECT ]; then
351 return 1
352 fi
353 return 0
354}
355
356helm_install() {
357 local INDENT=
358 if [ "$1" == "-" ]; then
359 INDENT=$1; shift
360 fi
361 local NAMESPACE=$1; shift
362 local NAME=$1; shift
363 local CHART=$1; shift
364 local MESSAGE=$*
365
366 COUNT=$(expr 300 / 15)
367 bspin $INDENT $MESSAGE
David Bainbridge1ceabc12019-07-25 17:21:05 +0000368 (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 -0700369 SUCCESS=$?
370 while [ $SUCCESS -ne 0 ]; do
371 sspin $INDENT
372 COUNT=$(expr $COUNT - 1)
373 if [ $COUNT -eq 0 ]; then
David Bainbridgee10f6d52019-07-25 00:28:13 +0000374 (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 -0700375 COUNT=$(expr 300 / 15)
376 fi
377 sleep .15
378 done
379 espin $INDENT $VERIFIED
380}
381
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700382echo "INSTALL TYPE: $TYPE" >> $LOG
383
384bspin "Verify GOPATH"
385export GOPATH=$(pwd)
Test User3d7ad8e2019-07-03 06:15:44 +0000386mkdir -p $GOPATH/bin
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700387espin $VERIFIED
388
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700389if [ "$INSTALL_KUBECTL" == "no" ]; then
390 bspin "Skip kubectl install"
391 espin $NO_ENTRY
Test Userc13bdc92019-07-03 20:57:49 +0000392else
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700393 bspin "Verify kubectl $HELM"
394 if [ -x $GOPATH/bin/kubectl ]; then
395 espin $VERIFIED
396 else
397 espin $NOT_VERIFIED
398 bspin - "Download and install Kubernetes/kubectl $DOWNLOAD"
399 (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
400 (set -x; chmod 755 $GOPATH/bin/kubectl >>$LOG 2>&1) >>$LOG 2>&1
401 espin - $VERIFIED
402 fi
Test Userc13bdc92019-07-03 20:57:49 +0000403fi
404
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700405if [ "$DEPLOY_K8S" == "no" ]; then
406 bspin "Skip Kubernetes/Kind Deployment"
407 espin $NO_ENTRY
408else
Test Userba1e7e72019-07-10 22:27:54 +0000409 bspin "Verify Kubernetes/Kind $HELM"
410 if [ -x $GOPATH/bin/kind ]; then
411 espin $VERIFIED
412 else
413 espin $NOT_VERIFIED
414 bspin - "Download and install Kubernetes/kind $DOWNLOAD"
David Bainbridge9e2a6662019-07-11 17:07:57 +0000415 (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 +0000416 (set -x; chmod 755 $GOPATH/bin/kind >>$LOG 2>&1) >>$LOG 2>&1
417 espin - $VERIFIED
418 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700419fi
420
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700421if [ "$INSTALL_HELM" == "no" ]; then
422 bspin "Skip Helm Install"
423 espin $NO_ENTRY
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700424else
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700425 bspin "Verify Helm $HELM"
426 if [ -x $GOPATH/bin/helm ]; then
427 espin $VERIFIED
428 else
429 espin $NOT_VERIFIED
430 bspin - "Download and install Helm $DOWNLOAD"
431 (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
432 espin - $VERIFIED
433 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700434fi
435
Test Userb5712372019-07-03 21:52:17 +0000436bspin "Verify voltctl $HIGH_VOLTAGE"
Test User3d7ad8e2019-07-03 06:15:44 +0000437if [ -x $GOPATH/bin/voltctl ]; then
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700438 espin $VERIFIED
439else
440 espin $NOT_VERIFIED
Test Userb5712372019-07-03 21:52:17 +0000441 bspin - "Download and build voltctl $DOWNLOAD"
Test Userba1e7e72019-07-10 22:27:54 +0000442 (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 +0000443 (set -x; chmod 755 $GOPATH/bin/voltctl >>$LOG 2>&1) >>$LOG 2>&1
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700444 espin - $VERIFIED
445fi
446
447bspin "Verify command PATH"
Test Userba1e7e72019-07-10 22:27:54 +0000448export PATH=$GOPATH/bin:$PATH
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700449espin $VERIFIED
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700450
Test Userba1e7e72019-07-10 22:27:54 +0000451if [ "$DEPLOY_K8S" == "yes" ]; then
452 HAVE=$(kind get clusters | grep -c voltha-$TYPE)
453 bspin "Verify Kubernetes/Kind Cluster"
454 sspin
455 if [ $HAVE -eq 0 ]; then
David Bainbridge491b1bd2019-07-11 17:53:11 +0000456 espin $NOT_VERIFIED
457 bspin - "Verify cluster configuration"
458 if [ ! -r ./$TYPE-cluster.cfg ]; then
459 espin - $NOT_VERIFIED
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700460 bspin - "Download cluster configuration: $TYPE-cluster.cfg $DOWNLOAD"
David Bainbridge491b1bd2019-07-11 17:53:11 +0000461 (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 -0700462 espin - $VERIFIED
463 else
464 espin - $VERIFIED
465 fi
David Bainbridge491b1bd2019-07-11 17:53:11 +0000466 kind create cluster --name voltha-$TYPE --config $TYPE-cluster.cfg
467 else
468 espin $VERIFIED
Test Userba1e7e72019-07-10 22:27:54 +0000469 fi
470
471 export KUBECONFIG="$(kind get kubeconfig-path --name="voltha-$TYPE")"
472 P="coredns-.* \
473 etcd-voltha-$TYPE-control-plane \
474 kindnet-.* \
475 kube-apiserver-voltha-$TYPE-control-plane \
476 kube-controller-manager-voltha-$TYPE-control-plane \
477 kube-proxy-.* \
478 kube-scheduler-voltha-$TYPE-control-plane"
479
480 EXPECT=$(test "$TYPE" == "minimal" && echo "12" || echo "14")
481 wait_for_pods - "kube-system" $EXPECT -1 "Waiting for system PODs to start" $P
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700482fi
483
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700484COUNT=$(count_pods "kube-system" "tiller-deploy-.*")
485bspin "Verify Helm"
Test Userba1e7e72019-07-10 22:27:54 +0000486if [ $COUNT -ne 1 ]; then
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700487 espin $NOT_VERIFIED
Test Userb5712372019-07-03 21:52:17 +0000488 echo -e "Configuring Helm $GEAR"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700489 if [ "$INSTALL_HELM" == "no" ]; then
490 bspin - "Skip Helm/Tiller Initialization"
491 espin - $NO_ENTRY
492 else
493 bspin - "Initialize Helm"
494 (set -x; helm init --upgrade >>$LOG 2>&1) >>$LOG 2>&1
495 espin - $VERIFIED
496 wait_for_pods - "kube-system" 1 -1 "Waiting for Tiller POD to start" "tiller-deploy-.*"
497 fi
Test Userb5712372019-07-03 21:52:17 +0000498 bspin - "Add Google Incubator repository to Helm"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700499 (set -x; helm repo add incubator https://kubernetes-charts-incubator.storage.googleapis.com >>$LOG 2>&1) >>$LOG 2>&1
500 espin - $VERIFIED
Test Userba1e7e72019-07-10 22:27:54 +0000501
502 # HACK (sort-of) - the config for tiller is about to be patched, which will
503 # cause the tiller pod to be recreated. This can sometimes cause a timing
504 # issue with the "wait_for_pods" call on tiller as it may incorrectly
505 # identify the running/ready tiller pod that is soon to be terminated as
506 # what it is waiting for. To avoid this issue we do a clean scale down and
507 # scale up of the pod so the script controlls when it should be expecting
508 # things
509 (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 -0700510
Test Userb5712372019-07-03 21:52:17 +0000511 bspin - "Add Google Stable repository to Helm"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700512 (set -x; helm repo add stable https://kubernetes-charts.storage.googleapis.com >>$LOG 2>&1) >>$LOG 2>&1
513 espin - $VERIFIED
Test Userb5712372019-07-03 21:52:17 +0000514 bspin - "Add ONF repository to Helm"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700515 (set -x; helm repo add onf https://charts.opencord.org >>$LOG 2>&1) >>$LOG 2>&1
516 espin - $VERIFIED
Test Userb5712372019-07-03 21:52:17 +0000517 bspin - "Update Helm repository cache"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700518 (set -x; helm repo update >>$LOG 2>&1) >>$LOG 2>&1
519 espin - $VERIFIED
520
521 # Create and k8s service account so that Helm can create pods
Test Userb5712372019-07-03 21:52:17 +0000522 bspin - "Create Tiller ServiceAccount"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700523 (set -x; kubectl create serviceaccount --namespace kube-system tiller >>$LOG 2>&1) >>$LOG 2>&1
524 espin - $VERIFIED
Test Userb5712372019-07-03 21:52:17 +0000525 bspin - "Create Tiller ClusterRoleBinding"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700526 (set -x; kubectl create clusterrolebinding tiller-cluster-rule --clusterrole=cluster-admin --serviceaccount=kube-system:tiller >>$LOG 2>&1) >>$LOG 2>&1
527 espin - $VERIFIED
Test Userb5712372019-07-03 21:52:17 +0000528 bspin - "Update Tiller Manifest"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700529 (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 +0000530
531 # HACK (sort-of) - part to, spin it back up
532 (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 -0700533 espin - $VERIFIED
534else
535 espin $VERIFIED
536fi
Test Userb5712372019-07-03 21:52:17 +0000537wait_for_pods - "kube-system" 1 -1 "Waiting for Tiller POD to start" "tiller-deploy-.*"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700538
Test Userba1e7e72019-07-10 22:27:54 +0000539bspin "Verify Helm values file: $TYPE-values.yaml"
540if [ ! -r "./$TYPE-values.yaml" ]; then
541 espin $NOT_VERIFIED
542 bspin - "Download Helm values file: $TYPE-values.yaml $DOWNLOAD"
543 (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
544 espin - $VERIFIED
545else
546 espin $VERIFIED
547fi
548
549if [ "$JUST_K8S" == "yes" ]; then
550 echo "Environment deployed, not deploying VOLTHA artifacts as requested. Good bye."
551 echo ""
552 echo "Please issue the following commands in your terminal to ensure that you" | tee -a $LOG
553 echo "are accessing the correct Kubernetes/Kind cluster as well as have the " | tee -a $LOG
554 echo "tools required by VOLTHA in your command path. " | tee -a $LOG
555 echo "" | tee -a $LOG
556 echo -en $BOLD
557 if [ $DEPLOY_K8S == "yes" ]; then
558 echo "export KUBECONFIG=\"\$(./bin/kind get kubeconfig-path --name=\"voltha-$TYPE\")\"" | tee -a $LOG
559 fi
560 echo "export PATH=$GOPATH/bin:\$PATH" | tee -a $LOG
561 echo -en $NORMAL
562 echo "" | tee -a $LOG
563 echo "Thank you for choosing kind-voltha for you quick cluster needs." | tee -a $LOG
564 exit 0
565fi
566
Test Userb5712372019-07-03 21:52:17 +0000567bspin "Verify ETCD Operator $OLD_KEY"
Test User7d866122019-07-09 17:52:35 +0000568if [ $(helm list --deployed --short --namespace voltha "^etcd-operator\$" | wc -l) -ne 1 ]; then
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700569 espin $NOT_VERIFIED
570 helm_install - voltha etcd-operator stable/etcd-operator "Install ETCD Operator"
571else
572 espin $VERIFIED
573fi
Test User01ed0642019-07-03 20:17:06 +0000574EXPECT=$(test "$TYPE" == "minimal" && echo "1" || echo "3")
Test Userb5712372019-07-03 21:52:17 +0000575wait_for_pods - "voltha" $EXPECT -1 "Waiting for ETCD Operator to start" "etcd-operator-.*"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700576
Test Userb5712372019-07-03 21:52:17 +0000577bspin "Verify ONOS installed $BIRD"
Test User7d866122019-07-09 17:52:35 +0000578if [ $(helm list --deployed --short --namespace default "^onos\$" | wc -l) -ne 1 ]; then
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700579 espin $NOT_VERIFIED
580 helm_install - default onos onf/onos "Install ONOS"
581else
582 espin $VERIFIED
583fi
Test Userb5712372019-07-03 21:52:17 +0000584wait_for_pods - "default" 1 -1 "Waiting for ONOS to start" "onos-.*"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700585
Test Userb5712372019-07-03 21:52:17 +0000586bspin - "Forward ONOS API port $FORWARD"
Test User01ed0642019-07-03 20:17:06 +0000587(set -x; screen -p 0 -X -S onos-ui-$TYPE stuff $'\003' >>$LOG 2>&1) >>$LOG 2>&1
588(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 -0700589espin - $VERIFIED
Test Userb5712372019-07-03 21:52:17 +0000590bspin - "Forward ONOS SSH port $FORWARD"
Test User01ed0642019-07-03 20:17:06 +0000591(set -x; screen -p 0 -X -S onos-ssh-$TYPE stuff $'\003' >>$LOG 2>&1) >>$LOG 2>&1
592(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 -0700593espin - $VERIFIED
Test Userba1e7e72019-07-10 22:27:54 +0000594if [ ! -x ./onos-files/install-onos-applications.sh ]; then
595 bspin - "Verify or download ONOS configuration support files $DOWNLOAD"
596 (set -x; mkdir -p ./onos-files >>$LOG 2>&1) >>$LOG 2>&1
597 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
598 if [ ! -r ./onos-files/$i ]; then
599 (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
600 fi
601 done
602 (set -x; chmod 755 ./onos-files/install-onos-applications.sh >>$LOG 2>&1) >>$LOG 2>&1
603 espin - $VERIFIED
604fi
605
Test Userb5712372019-07-03 21:52:17 +0000606bspin - "Install required ONOS applications $INSTALL"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700607(set -x; ./onos-files/install-onos-applications.sh >>$LOG 2>&1) >>$LOG 2>&1
608espin - $VERIFIED
609
Test Userb5712372019-07-03 21:52:17 +0000610bspin "Verify VOLTHA installed $HIGH_VOLTAGE"
Test User7d866122019-07-09 17:52:35 +0000611if [ $(helm list --deployed --short --namespace voltha "^voltha\$" | wc -l) -ne 1 ]; then
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700612 espin $NOT_VERIFIED
David Bainbridgee10f6d52019-07-25 00:28:13 +0000613 helm_install - voltha voltha $VOLTHA_CHART "Install VOLTHA Core"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700614else
615 espin $VERIFIED
616fi
Test Userba1e7e72019-07-10 22:27:54 +0000617
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700618VOLTHA="ofagent-.* \
619 ro-core.* \
620 rw-core.* \
621 voltha-api-server-.* \
622 voltha-cli-server-.* \
623 voltha-etcd-cluster-.* \
624 voltha-kafka-.* \
625 voltha-zookeeper-.*"
Test User01ed0642019-07-03 20:17:06 +0000626EXPECT=$(test "$TYPE" == "minimal" && echo "9" || echo "11")
Test Userb5712372019-07-03 21:52:17 +0000627wait_for_pods - "voltha" $EXPECT -1 "Waiting for VOLTHA Core to start" $VOLTHA
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700628
Test Userb5712372019-07-03 21:52:17 +0000629echo -e "Verify Adapters $PLUG"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700630bspin - "Verify Simulated Adapters installed"
Test User7d866122019-07-09 17:52:35 +0000631if [ $(helm list --deployed --short --namespace voltha "^sim\$" | wc -l) -ne 1 ]; then
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700632 espin - $NOT_VERIFIED
David Bainbridgee10f6d52019-07-25 00:28:13 +0000633 helm_install - voltha sim $VOLTHA_ADAPTER_SIM_CHART "Install Simulated Adapters"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700634else
635 espin - $VERIFIED
636fi
637
638bspin - "Verify OpenOLT Adapter installed"
Test User7d866122019-07-09 17:52:35 +0000639if [ $(helm list --deployed --short --namespace voltha "^open-olt\$" | wc -l) -ne 1 ]; then
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700640 espin - $NOT_VERIFIED
David Bainbridgee10f6d52019-07-25 00:28:13 +0000641 helm_install - voltha open-olt $VOLTHA_ADAPTER_OPEN_OLT_CHART "Install OpenOLT Adapter"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700642else
643 espin - $VERIFIED
644fi
645bspin - "Verify OpenONU Adapter installed"
Test User7d866122019-07-09 17:52:35 +0000646if [ $(helm list --deployed --short --namespace voltha "^open-onu\$" | wc -l) -ne 1 ]; then
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700647 espin - $NOT_VERIFIED
David Bainbridgee10f6d52019-07-25 00:28:13 +0000648 helm_install - voltha open-onu $VOLTHA_ADAPTER_OPEN_ONU_CHART "Install OpenONU Adapter"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700649else
650 espin - $VERIFIED
651fi
652
653ADAPTERS="adapter-.*"
Test Userb5712372019-07-03 21:52:17 +0000654wait_for_pods - "voltha" 4 -1 "Waiting for adapters to start" $ADAPTERS
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700655
Test User7d866122019-07-09 17:52:35 +0000656if [ $WITH_BBSIM == "yes" ]; then
657 echo -e "Verify BBSIM $PLUG"
658 bspin - "Verify BBSIM Insalled"
659 if [ $(helm list --deployed --short --namespace voltha "^bbsim\$" | wc -l) -ne 1 ]; then
660 espin - $NOT_VERIFIED
661 helm_install - voltha bbsim onf/bbsim "Install BBSIM"
662 else
663 espin - $VERIFIED
664 fi
665 wait_for_pods - "voltha" 1 -1 "Waiting for BBSIM to start" "bbsim-.*"
666fi
667
David Bainbridgee10f6d52019-07-25 00:28:13 +0000668if [ $SKIP_RESTART_API == "no" ]; then
669 echo -e "Restart VOLTHA API $RESTART"
670 API="voltha-api-server-.* ofagent-.*"
671 (set -x; kubectl scale --replicas=0 deployment -n voltha voltha-api-server ofagent >>$LOG 2>&1) >>$LOG 2>&1
672 wait_for_pods - "voltha" 0 -1 "Wait for API to stop $STOP" $API
673 (set -x; kubectl scale --replicas=1 deployment -n voltha voltha-api-server ofagent >>$LOG 2>&1) >>$LOG 2>&1
674 wait_for_pods - "voltha" 2 -1 "Wait for API to re-start $GO" $API
675else
676 bspin "Skip VOLTHA API Restart"
677 espin $NO_ENTRY
678fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700679
Test Userb5712372019-07-03 21:52:17 +0000680bspin - "Forward VOLTHA API port $FORWARD"
Test User01ed0642019-07-03 20:17:06 +0000681(set -x; screen -p 0 -X -S voltha-api-$TYPE stuff $'\003' >>$LOG 2>&1) >>$LOG 2>&1
682(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 -0700683espin - $VERIFIED
Test Userb5712372019-07-03 21:52:17 +0000684bspin - "Forward VOLTHA SSH port $FORWARD"
Test User01ed0642019-07-03 20:17:06 +0000685(set -x; screen -p 0 -X -S voltha-ssh-$TYPE stuff $'\003' 2>/dev/null >/dev/null >>$LOG 2>&1) >>$LOG 2>&1
686(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 -0700687espin - $VERIFIED
Test User3d7ad8e2019-07-03 06:15:44 +0000688
689bspin - "Create voltctl configuration file"
690(set -x; mkdir -p $HOME/.volt >>$LOG 2>&1) >>$LOG 2>&1
Test User01ed0642019-07-03 20:17:06 +0000691(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 +0000692espin - $VERIFIED
Test User08ebbd92019-07-03 17:15:39 +0000693
Test User7d866122019-07-09 17:52:35 +0000694echo ""
Test User08ebbd92019-07-03 17:15:39 +0000695echo "Please issue the following commands in your terminal to ensure that you" | tee -a $LOG
696echo "are accessing the correct Kubernetes/Kind cluster as well as have the " | tee -a $LOG
697echo "tools required by VOLTHA in your command path. " | tee -a $LOG
698echo "" | tee -a $LOG
Test User7d866122019-07-09 17:52:35 +0000699echo -en $BOLD
Test Userba1e7e72019-07-10 22:27:54 +0000700if [ $DEPLOY_K8S == "yes" ]; then
701 echo "export KUBECONFIG=\"\$(./bin/kind get kubeconfig-path --name=\"voltha-$TYPE\")\"" | tee -a $LOG
702fi
Test Userfa30f7f2019-07-03 20:35:19 +0000703echo "export VOLTCONFIG=\"$HOME/.volt/config-$TYPE\"" | tee -a $LOG
Test Userba1e7e72019-07-10 22:27:54 +0000704echo "export PATH=$GOPATH/bin:\$PATH" | tee -a $LOG
Test User7d866122019-07-09 17:52:35 +0000705echo -en $NORMAL
Test User08ebbd92019-07-03 17:15:39 +0000706echo "" | tee -a $LOG
707echo "Thank you for choosing kind-voltha for you quick cluster needs." | tee -a $LOG
708