blob: 3258ba8b4a04116e88cc9a7fd350193db27bb5a4 [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 K. Bainbridge0e89cb92019-07-17 11:30:10 -070047INSTALL_KUBECTL=${INSTALL_KUBECTL:-yes}
48INSTALL_HELM=${INSTALL_HELM:-yes}
Test Userba1e7e72019-07-10 22:27:54 +000049
50HAVE_GO=$(which go >/dev/null 2>&1 && echo "yes" || echo "no")
51HOSTOS=$(uname -s | tr "[:upper:]" "[:lower:"])
52HOSTARCH=$(uname -m | tr "[:upper:]" "[:lower:"])
53if [ $HOSTARCH == "x86_64" ]; then
54 HOSTARCH="amd64"
55fi
Test User7d866122019-07-09 17:52:35 +000056
57# Verify TYPE setting
58if [ $(echo ":minimal:full:" | grep -ic ":$TYPE:") -eq 0 ]; then
David K. Bainbridge0e89cb92019-07-17 11:30:10 -070059 >&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 +000060 exit 1
61fi
62
63# Verify WITH_BBSIM settting and convert uniform value of yes or no
64if [ $(echo ":y:yes:true:n:no:false:1:0:" | grep -ic ":$WITH_BBSIM:") -eq 0 ]; then
David K. Bainbridge0e89cb92019-07-17 11:30:10 -070065 >&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 +000066 exit 1
67fi
68if [ $(echo ":y:yes:true:1:" | grep -ic ":$WITH_BBSIM:") -eq 1 ]; then
69 WITH_BBSIM=yes
70else
71 WITH_BBSIM=no
72fi
73
Test Userba1e7e72019-07-10 22:27:54 +000074# Verify JUST_K8S settting and convert uniform value of yes or no
75if [ $(echo ":y:yes:true:n:no:false:1:0:" | grep -ic ":$JUST_K8S:") -eq 0 ]; then
David K. Bainbridge0e89cb92019-07-17 11:30:10 -070076 >&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 +000077 exit 1
78fi
79if [ $(echo ":y:yes:true:1:" | grep -ic ":$JUST_K8S:") -eq 1 ]; then
80 JUST_K8S=yes
81else
82 JUST_K8S=no
83fi
84
85# Verify DEPLOY_K8S settting and convert uniform value of yes or no
86if [ $(echo ":y:yes:true:n:no:false:1:0:" | grep -ic ":$DEPLOY_K8S:") -eq 0 ]; then
David K. Bainbridge0e89cb92019-07-17 11:30:10 -070087 >&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 +000088 exit 1
89fi
90if [ $(echo ":y:yes:true:1:" | grep -ic ":$DEPLOY_K8S:") -eq 1 ]; then
91 DEPLOY_K8S=yes
92else
93 DEPLOY_K8S=no
94fi
Test User01ed0642019-07-03 20:17:06 +000095
David K. Bainbridge0e89cb92019-07-17 11:30:10 -070096# Verify INSTALL_KUBECTL settting and convert uniform value of yes or no
97if [ $(echo ":y:yes:true:n:no:false:1:0:" | grep -ic ":$INSTALL_KUBECTL:") -eq 0 ]; then
98 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} Invalid \$INSTALL_KUBECTL value of '$INSTALL_KUBECTL'. Should be 'yes' or 'no'${NORMAL}"
99 exit 1
100fi
101
102if [ $(echo ":y:yes:true:1:" | grep -ic ":$INSTALL_KUBECTL:") -eq 1 ]; then
103 INSTALL_KUBECTL=yes
104else
105 INSTALL_KUBECTL=no
106fi
107
108# Verify INSTALL_HELM settting and convert uniform value of yes or no
109if [ $(echo ":y:yes:true:n:no:false:1:0:" | grep -ic ":$INSTALL_HELM:") -eq 0 ]; then
110 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} Invalid \$INSTALL_HELM value of '$INSTALL_HELM'. Should be 'yes' or 'no'${NORMAL}"
111 exit 1
112fi
113
114if [ $(echo ":y:yes:true:1:" | grep -ic ":$INSTALL_HELM:") -eq 1 ]; then
115 INSTALL_HELM=yes
116else
117 INSTALL_HELM=no
118fi
119
Test User01ed0642019-07-03 20:17:06 +0000120if [ "$TYPE" == "full" ]; then
121 ONOS_API_PORT=${ONOS_API_PORT:-8182}
122 ONOS_SSH_PORT=${ONOS_SSH_PORT:-8102}
123 VOLTHA_API_PORT=${VOLTHA_API_PORT:-55556}
124 VOLTHA_SSH_PORT=${VOLTHA_SSH_PORT:-5023}
125else
126 ONOS_API_PORT=${ONOS_API_PORT:-8181}
127 ONOS_SSH_PORT=${ONOS_SSH_PORT:-8101}
128 VOLTHA_API_PORT=${VOLTHA_API_PORT:-55555}
129 VOLTHA_SSH_PORT=${VOLTHA_SSH_PORT:-5022}
130fi
131
132if [ "$1" == "get" -a "$2" == "voltconfig" ]; then
133 echo "$HOME/.volt/config-$TYPE"
134 exit
135fi
Test User3d7ad8e2019-07-03 06:15:44 +0000136
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700137if [ $# -ne 1 -o $(echo ":up:down:" | grep -c ":$1:") -ne 1 ]; then
138 >&2 echo "up or down?"
139 exit 1
140fi
141
142if [ "$1" == "down" ]; then
Test Userba1e7e72019-07-10 22:27:54 +0000143 if [ $DEPLOY_K8S == "yes" ]; then
144 if [ -x ./bin/kind ]; then
145 exec ./bin/kind delete cluster --name voltha-$TYPE
146 else
147 >&2 echo "Kind doesn't seem to be installed, so nothing to do. Bye."
148 fi
Test User08ebbd92019-07-03 17:15:39 +0000149 else
Test Userba1e7e72019-07-10 22:27:54 +0000150 EXISTS=$(helm list -q)
151 EXPECT="etcd-operator onos open-olt open-onu sim voltha"
152 INTERSECT=
153 for i in $EXISTS; do
154 if [ $(echo $EXPECT | grep -c $i) -eq 1 ]; then
155 HAVE="$HAVE $i"
156 fi
157 done
158 ./bin/helm delete --purge $HAVE
159fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700160 exit
161fi
162
Test User01ed0642019-07-03 20:17:06 +0000163LOG="install-$TYPE.log"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700164date > $LOG
165
166spin() {
Test Userd87942b2019-07-03 07:20:24 +0000167 PARTS="\
168 \xe2\xa2\x8e\xe2\xa1\xb0 \
169 \xe2\xa2\x8e\xe2\xa1\xa1 \
170 \xe2\xa2\x8e\xe2\xa1\x91 \
171 \xe2\xa2\x8e\xe2\xa0\xb1 \
172 \xe2\xa0\x8e\xe2\xa1\xb1 \
173 \xe2\xa2\x8a\xe2\xa1\xb1 \
174 \xe2\xa2\x8c\xe2\xa1\xb1 \
175 \xe2\xa2\x86\xe2\xa1\xb1 \
176 "
177 IDX=1
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700178 tput civis
179 while true; do
Test Userd87942b2019-07-03 07:20:24 +0000180 C=$(echo $PARTS | cut '-d ' -f $IDX)
181 echo -en "$C"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700182 IDX=$(expr $IDX + 1)
Test Userd87942b2019-07-03 07:20:24 +0000183 if [ $IDX -gt 8 ]; then
184 IDX=1
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700185 fi
186 sleep .15
187 echo -en "\r"
188 done
189}
190
Test Userd87942b2019-07-03 07:20:24 +0000191SPIN_PARTS="\
192 \xe2\xa2\x8e\xe2\xa1\xb0 \
193 \xe2\xa2\x8e\xe2\xa1\xa1 \
194 \xe2\xa2\x8e\xe2\xa1\x91 \
195 \xe2\xa2\x8e\xe2\xa0\xb1 \
196 \xe2\xa0\x8e\xe2\xa1\xb1 \
197 \xe2\xa2\x8a\xe2\xa1\xb1 \
198 \xe2\xa2\x8c\xe2\xa1\xb1 \
199 \xe2\xa2\x86\xe2\xa1\xb1 \
200 "
201IDX=1
202NOT_VERIFIED="\xe2\x9c\x97\x20"
203VERIFIED="\xe2\x9c\x93\x20"
Test Userb5712372019-07-03 21:52:17 +0000204HELM="\xE2\x8E\x88"
205OLD_KEY="\xF0\x9F\x97\x9D"
206BIRD="\xF0\x9F\x90\xA6"
207HIGH_VOLTAGE="\xE2\x9A\xA1"
208PLUG="\xF0\x9F\xa7\xa9"
209RESTART="\xf0\x9f\x94\x84"
210FORWARD="\xE2\x87\xA8"
211INSTALL="\xF0\x9F\x8F\x97"
212STOP="\xf0\x9f\x9b\x91"
213GO="\xf0\x9f\x9a\x80"
214DOWNLOAD="\xf0\x9f\x93\xa5"
215GEAR="\xe2\x9a\x99"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700216NO_ENTRY="\xe2\x9b\x94"
217
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700218bspin() {
219 tput civis
Test Userd87942b2019-07-03 07:20:24 +0000220 IDX=1
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700221 local INDENT=
222 if [ "$1" == "-" ]; then
223 INDENT=" "
224 shift
225 fi
Test Userd87942b2019-07-03 07:20:24 +0000226 echo -en "$INDENT $*"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700227}
228
229sspin() {
230 local INDENT=
231 if [ "$1" == "-" ]; then
232 INDENT=" "
233 shift
234 fi
Test Userd87942b2019-07-03 07:20:24 +0000235 C=$(echo $SPIN_PARTS | cut '-d ' -f $IDX)
236 echo -en "\r$INDENT$C $*"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700237 IDX=$(expr $IDX + 1)
Test Userd87942b2019-07-03 07:20:24 +0000238 if [ $IDX -gt 8 ]; then
239 IDX=1
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700240 fi
241}
242
243espin() {
244 local INDENT=
245 if [ "$1" == "-" ]; then
246 INDENT=" "
247 shift
248 fi
249 echo -e "\r$INDENT$*"
250 tput cnorm
251}
252
253count_pods() {
254 local NAMESPACE=$1; shift
255 local PODS=$(kubectl -n $NAMESPACE get pod -o go-template="{{range .items}}{{.metadata.name}}/{{.status.phase}}/_{{range .status.containerStatuses}}{{.ready}}_{{end}} {{end}}")
256 local COUNT=0
257 local PATTERNS=$*
258 for POD in $PODS; do
259 local NAME=$(echo $POD | cut -d/ -f 1)
260 local STATE=$(echo $POD | cut -d/ -f 2)
261 local CONTAINERS=$(echo $POD | cut -d/ -f 3 | sed -e 's/_/ /g')
262 if [ "$STATE" == "Running" ]; then
263 local TOTAL=$(echo $CONTAINERS | wc -w)
264 local FOUND=$(echo $CONTAINERS | grep -o true | wc -l)
265 if [ $TOTAL -eq $FOUND ]; then
266 for PATTERN in $PATTERNS; do
267 if [[ $NAME =~ $PATTERN ]]; then
268 COUNT=$(expr $COUNT + 1)
269 fi
270 done
271 fi
272 fi
273 done
274 echo $COUNT
275}
276
277wait_for_pods() {
278 local INDENT=
279 if [ "$1" == "-" ]; then
280 INDENT=$1; shift
281 fi
282 local NAMESPACE=$1; shift
283 local EXPECT=$1; shift
284 local RETRY=$1; shift
285 local MESSAGE=$1; shift
286 local PATTERNS=$*
287 local HAVE=$(count_pods $NAMESPACE $PATTERNS)
288 COUNT=$(expr 300 / 15)
289 bspin $INDENT $MESSAGE
290 sspin $INDENT
291 if [ $HAVE -ne $EXPECT ]; then
292 while [ $HAVE -ne $EXPECT ]; do
293 sspin $INDENT
294 COUNT=$(expr $COUNT - 1)
295 if [ $COUNT -eq 0 ]; then
296 HAVE=$(count_pods $NAMESPACE $PATTERNS)
297 COUNT=$(expr 300 / 15)
298 fi
299 sleep .15
300 done
301 fi
302 espin $INDENT $VERIFIED
303 if [ $HAVE -ne $EXPECT ]; then
304 return 1
305 fi
306 return 0
307}
308
309helm_install() {
310 local INDENT=
311 if [ "$1" == "-" ]; then
312 INDENT=$1; shift
313 fi
314 local NAMESPACE=$1; shift
315 local NAME=$1; shift
316 local CHART=$1; shift
317 local MESSAGE=$*
318
319 COUNT=$(expr 300 / 15)
320 bspin $INDENT $MESSAGE
321 (set -x; helm install -f $TYPE-values.yaml --namespace $NAMESPACE --name $NAME $CHART >>$LOG 2>&1) >>$LOG 2>&1
322 SUCCESS=$?
323 while [ $SUCCESS -ne 0 ]; do
324 sspin $INDENT
325 COUNT=$(expr $COUNT - 1)
326 if [ $COUNT -eq 0 ]; then
327 (set -x; helm install -f $TYPE-values.yaml --namespace $NAMESPACE --name $NAME $CHART >>$LOG 2>&1) >>$LOG 2>&1
328 COUNT=$(expr 300 / 15)
329 fi
330 sleep .15
331 done
332 espin $INDENT $VERIFIED
333}
334
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700335echo "INSTALL TYPE: $TYPE" >> $LOG
336
337bspin "Verify GOPATH"
338export GOPATH=$(pwd)
Test User3d7ad8e2019-07-03 06:15:44 +0000339mkdir -p $GOPATH/bin
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700340espin $VERIFIED
341
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700342if [ "$INSTALL_KUBECTL" == "no" ]; then
343 bspin "Skip kubectl install"
344 espin $NO_ENTRY
Test Userc13bdc92019-07-03 20:57:49 +0000345else
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700346 bspin "Verify kubectl $HELM"
347 if [ -x $GOPATH/bin/kubectl ]; then
348 espin $VERIFIED
349 else
350 espin $NOT_VERIFIED
351 bspin - "Download and install Kubernetes/kubectl $DOWNLOAD"
352 (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
353 (set -x; chmod 755 $GOPATH/bin/kubectl >>$LOG 2>&1) >>$LOG 2>&1
354 espin - $VERIFIED
355 fi
Test Userc13bdc92019-07-03 20:57:49 +0000356fi
357
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700358if [ "$DEPLOY_K8S" == "no" ]; then
359 bspin "Skip Kubernetes/Kind Deployment"
360 espin $NO_ENTRY
361else
Test Userba1e7e72019-07-10 22:27:54 +0000362 bspin "Verify Kubernetes/Kind $HELM"
363 if [ -x $GOPATH/bin/kind ]; then
364 espin $VERIFIED
365 else
366 espin $NOT_VERIFIED
367 bspin - "Download and install Kubernetes/kind $DOWNLOAD"
David Bainbridge9e2a6662019-07-11 17:07:57 +0000368 (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 +0000369 (set -x; chmod 755 $GOPATH/bin/kind >>$LOG 2>&1) >>$LOG 2>&1
370 espin - $VERIFIED
371 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700372fi
373
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700374if [ "$INSTALL_HELM" == "no" ]; then
375 bspin "Skip Helm Install"
376 espin $NO_ENTRY
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700377else
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700378 bspin "Verify Helm $HELM"
379 if [ -x $GOPATH/bin/helm ]; then
380 espin $VERIFIED
381 else
382 espin $NOT_VERIFIED
383 bspin - "Download and install Helm $DOWNLOAD"
384 (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
385 espin - $VERIFIED
386 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700387fi
388
Test Userb5712372019-07-03 21:52:17 +0000389bspin "Verify voltctl $HIGH_VOLTAGE"
Test User3d7ad8e2019-07-03 06:15:44 +0000390if [ -x $GOPATH/bin/voltctl ]; then
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700391 espin $VERIFIED
392else
393 espin $NOT_VERIFIED
Test Userb5712372019-07-03 21:52:17 +0000394 bspin - "Download and build voltctl $DOWNLOAD"
Test Userba1e7e72019-07-10 22:27:54 +0000395 (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 +0000396 (set -x; chmod 755 $GOPATH/bin/voltctl >>$LOG 2>&1) >>$LOG 2>&1
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700397 espin - $VERIFIED
398fi
399
400bspin "Verify command PATH"
Test Userba1e7e72019-07-10 22:27:54 +0000401export PATH=$GOPATH/bin:$PATH
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700402espin $VERIFIED
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700403
Test Userba1e7e72019-07-10 22:27:54 +0000404if [ "$DEPLOY_K8S" == "yes" ]; then
405 HAVE=$(kind get clusters | grep -c voltha-$TYPE)
406 bspin "Verify Kubernetes/Kind Cluster"
407 sspin
408 if [ $HAVE -eq 0 ]; then
David Bainbridge491b1bd2019-07-11 17:53:11 +0000409 espin $NOT_VERIFIED
410 bspin - "Verify cluster configuration"
411 if [ ! -r ./$TYPE-cluster.cfg ]; then
412 espin - $NOT_VERIFIED
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700413 bspin - "Download cluster configuration: $TYPE-cluster.cfg $DOWNLOAD"
David Bainbridge491b1bd2019-07-11 17:53:11 +0000414 (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 -0700415 espin - $VERIFIED
416 else
417 espin - $VERIFIED
418 fi
David Bainbridge491b1bd2019-07-11 17:53:11 +0000419 kind create cluster --name voltha-$TYPE --config $TYPE-cluster.cfg
420 else
421 espin $VERIFIED
Test Userba1e7e72019-07-10 22:27:54 +0000422 fi
423
424 export KUBECONFIG="$(kind get kubeconfig-path --name="voltha-$TYPE")"
425 P="coredns-.* \
426 etcd-voltha-$TYPE-control-plane \
427 kindnet-.* \
428 kube-apiserver-voltha-$TYPE-control-plane \
429 kube-controller-manager-voltha-$TYPE-control-plane \
430 kube-proxy-.* \
431 kube-scheduler-voltha-$TYPE-control-plane"
432
433 EXPECT=$(test "$TYPE" == "minimal" && echo "12" || echo "14")
434 wait_for_pods - "kube-system" $EXPECT -1 "Waiting for system PODs to start" $P
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700435fi
436
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700437COUNT=$(count_pods "kube-system" "tiller-deploy-.*")
438bspin "Verify Helm"
Test Userba1e7e72019-07-10 22:27:54 +0000439if [ $COUNT -ne 1 ]; then
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700440 espin $NOT_VERIFIED
Test Userb5712372019-07-03 21:52:17 +0000441 echo -e "Configuring Helm $GEAR"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700442 if [ "$INSTALL_HELM" == "no" ]; then
443 bspin - "Skip Helm/Tiller Initialization"
444 espin - $NO_ENTRY
445 else
446 bspin - "Initialize Helm"
447 (set -x; helm init --upgrade >>$LOG 2>&1) >>$LOG 2>&1
448 espin - $VERIFIED
449 wait_for_pods - "kube-system" 1 -1 "Waiting for Tiller POD to start" "tiller-deploy-.*"
450 fi
Test Userb5712372019-07-03 21:52:17 +0000451 bspin - "Add Google Incubator repository to Helm"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700452 (set -x; helm repo add incubator https://kubernetes-charts-incubator.storage.googleapis.com >>$LOG 2>&1) >>$LOG 2>&1
453 espin - $VERIFIED
Test Userba1e7e72019-07-10 22:27:54 +0000454
455 # HACK (sort-of) - the config for tiller is about to be patched, which will
456 # cause the tiller pod to be recreated. This can sometimes cause a timing
457 # issue with the "wait_for_pods" call on tiller as it may incorrectly
458 # identify the running/ready tiller pod that is soon to be terminated as
459 # what it is waiting for. To avoid this issue we do a clean scale down and
460 # scale up of the pod so the script controlls when it should be expecting
461 # things
462 (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 -0700463
Test Userb5712372019-07-03 21:52:17 +0000464 bspin - "Add Google Stable repository to Helm"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700465 (set -x; helm repo add stable https://kubernetes-charts.storage.googleapis.com >>$LOG 2>&1) >>$LOG 2>&1
466 espin - $VERIFIED
Test Userb5712372019-07-03 21:52:17 +0000467 bspin - "Add ONF repository to Helm"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700468 (set -x; helm repo add onf https://charts.opencord.org >>$LOG 2>&1) >>$LOG 2>&1
469 espin - $VERIFIED
Test Userb5712372019-07-03 21:52:17 +0000470 bspin - "Update Helm repository cache"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700471 (set -x; helm repo update >>$LOG 2>&1) >>$LOG 2>&1
472 espin - $VERIFIED
473
474 # Create and k8s service account so that Helm can create pods
Test Userb5712372019-07-03 21:52:17 +0000475 bspin - "Create Tiller ServiceAccount"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700476 (set -x; kubectl create serviceaccount --namespace kube-system tiller >>$LOG 2>&1) >>$LOG 2>&1
477 espin - $VERIFIED
Test Userb5712372019-07-03 21:52:17 +0000478 bspin - "Create Tiller ClusterRoleBinding"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700479 (set -x; kubectl create clusterrolebinding tiller-cluster-rule --clusterrole=cluster-admin --serviceaccount=kube-system:tiller >>$LOG 2>&1) >>$LOG 2>&1
480 espin - $VERIFIED
Test Userb5712372019-07-03 21:52:17 +0000481 bspin - "Update Tiller Manifest"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700482 (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 +0000483
484 # HACK (sort-of) - part to, spin it back up
485 (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 -0700486 espin - $VERIFIED
487else
488 espin $VERIFIED
489fi
Test Userb5712372019-07-03 21:52:17 +0000490wait_for_pods - "kube-system" 1 -1 "Waiting for Tiller POD to start" "tiller-deploy-.*"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700491
Test Userba1e7e72019-07-10 22:27:54 +0000492bspin "Verify Helm values file: $TYPE-values.yaml"
493if [ ! -r "./$TYPE-values.yaml" ]; then
494 espin $NOT_VERIFIED
495 bspin - "Download Helm values file: $TYPE-values.yaml $DOWNLOAD"
496 (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
497 espin - $VERIFIED
498else
499 espin $VERIFIED
500fi
501
502if [ "$JUST_K8S" == "yes" ]; then
503 echo "Environment deployed, not deploying VOLTHA artifacts as requested. Good bye."
504 echo ""
505 echo "Please issue the following commands in your terminal to ensure that you" | tee -a $LOG
506 echo "are accessing the correct Kubernetes/Kind cluster as well as have the " | tee -a $LOG
507 echo "tools required by VOLTHA in your command path. " | tee -a $LOG
508 echo "" | tee -a $LOG
509 echo -en $BOLD
510 if [ $DEPLOY_K8S == "yes" ]; then
511 echo "export KUBECONFIG=\"\$(./bin/kind get kubeconfig-path --name=\"voltha-$TYPE\")\"" | tee -a $LOG
512 fi
513 echo "export PATH=$GOPATH/bin:\$PATH" | tee -a $LOG
514 echo -en $NORMAL
515 echo "" | tee -a $LOG
516 echo "Thank you for choosing kind-voltha for you quick cluster needs." | tee -a $LOG
517 exit 0
518fi
519
Test Userb5712372019-07-03 21:52:17 +0000520bspin "Verify ETCD Operator $OLD_KEY"
Test User7d866122019-07-09 17:52:35 +0000521if [ $(helm list --deployed --short --namespace voltha "^etcd-operator\$" | wc -l) -ne 1 ]; then
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700522 espin $NOT_VERIFIED
523 helm_install - voltha etcd-operator stable/etcd-operator "Install ETCD Operator"
524else
525 espin $VERIFIED
526fi
Test User01ed0642019-07-03 20:17:06 +0000527EXPECT=$(test "$TYPE" == "minimal" && echo "1" || echo "3")
Test Userb5712372019-07-03 21:52:17 +0000528wait_for_pods - "voltha" $EXPECT -1 "Waiting for ETCD Operator to start" "etcd-operator-.*"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700529
Test Userb5712372019-07-03 21:52:17 +0000530bspin "Verify ONOS installed $BIRD"
Test User7d866122019-07-09 17:52:35 +0000531if [ $(helm list --deployed --short --namespace default "^onos\$" | wc -l) -ne 1 ]; then
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700532 espin $NOT_VERIFIED
533 helm_install - default onos onf/onos "Install ONOS"
534else
535 espin $VERIFIED
536fi
Test Userb5712372019-07-03 21:52:17 +0000537wait_for_pods - "default" 1 -1 "Waiting for ONOS to start" "onos-.*"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700538
Test Userb5712372019-07-03 21:52:17 +0000539bspin - "Forward ONOS API port $FORWARD"
Test User01ed0642019-07-03 20:17:06 +0000540(set -x; screen -p 0 -X -S onos-ui-$TYPE stuff $'\003' >>$LOG 2>&1) >>$LOG 2>&1
541(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 -0700542espin - $VERIFIED
Test Userb5712372019-07-03 21:52:17 +0000543bspin - "Forward ONOS SSH port $FORWARD"
Test User01ed0642019-07-03 20:17:06 +0000544(set -x; screen -p 0 -X -S onos-ssh-$TYPE stuff $'\003' >>$LOG 2>&1) >>$LOG 2>&1
545(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 -0700546espin - $VERIFIED
Test Userba1e7e72019-07-10 22:27:54 +0000547if [ ! -x ./onos-files/install-onos-applications.sh ]; then
548 bspin - "Verify or download ONOS configuration support files $DOWNLOAD"
549 (set -x; mkdir -p ./onos-files >>$LOG 2>&1) >>$LOG 2>&1
550 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
551 if [ ! -r ./onos-files/$i ]; then
552 (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
553 fi
554 done
555 (set -x; chmod 755 ./onos-files/install-onos-applications.sh >>$LOG 2>&1) >>$LOG 2>&1
556 espin - $VERIFIED
557fi
558
Test Userb5712372019-07-03 21:52:17 +0000559bspin - "Install required ONOS applications $INSTALL"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700560(set -x; ./onos-files/install-onos-applications.sh >>$LOG 2>&1) >>$LOG 2>&1
561espin - $VERIFIED
562
Test Userb5712372019-07-03 21:52:17 +0000563bspin "Verify VOLTHA installed $HIGH_VOLTAGE"
Test User7d866122019-07-09 17:52:35 +0000564if [ $(helm list --deployed --short --namespace voltha "^voltha\$" | wc -l) -ne 1 ]; then
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700565 espin $NOT_VERIFIED
Test Userd87942b2019-07-03 07:20:24 +0000566 helm_install - voltha voltha onf/voltha "Install VOLTHA Core"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700567else
568 espin $VERIFIED
569fi
Test Userba1e7e72019-07-10 22:27:54 +0000570
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700571VOLTHA="ofagent-.* \
572 ro-core.* \
573 rw-core.* \
574 voltha-api-server-.* \
575 voltha-cli-server-.* \
576 voltha-etcd-cluster-.* \
577 voltha-kafka-.* \
578 voltha-zookeeper-.*"
Test User01ed0642019-07-03 20:17:06 +0000579EXPECT=$(test "$TYPE" == "minimal" && echo "9" || echo "11")
Test Userb5712372019-07-03 21:52:17 +0000580wait_for_pods - "voltha" $EXPECT -1 "Waiting for VOLTHA Core to start" $VOLTHA
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700581
Test Userb5712372019-07-03 21:52:17 +0000582echo -e "Verify Adapters $PLUG"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700583bspin - "Verify Simulated Adapters installed"
Test User7d866122019-07-09 17:52:35 +0000584if [ $(helm list --deployed --short --namespace voltha "^sim\$" | wc -l) -ne 1 ]; then
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700585 espin - $NOT_VERIFIED
586 helm_install - voltha sim onf/voltha-adapter-simulated "Install Simulated Adapters"
587else
588 espin - $VERIFIED
589fi
590
591bspin - "Verify OpenOLT Adapter installed"
Test User7d866122019-07-09 17:52:35 +0000592if [ $(helm list --deployed --short --namespace voltha "^open-olt\$" | wc -l) -ne 1 ]; then
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700593 espin - $NOT_VERIFIED
594 helm_install - voltha open-olt onf/voltha-adapter-openolt "Install OpenOLT Adapter"
595else
596 espin - $VERIFIED
597fi
598bspin - "Verify OpenONU Adapter installed"
Test User7d866122019-07-09 17:52:35 +0000599if [ $(helm list --deployed --short --namespace voltha "^open-onu\$" | wc -l) -ne 1 ]; then
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700600 espin - $NOT_VERIFIED
601 helm_install - voltha open-onu onf/voltha-adapter-openonu "Install OpenONU Adapter"
602else
603 espin - $VERIFIED
604fi
605
606ADAPTERS="adapter-.*"
Test Userb5712372019-07-03 21:52:17 +0000607wait_for_pods - "voltha" 4 -1 "Waiting for adapters to start" $ADAPTERS
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700608
Test User7d866122019-07-09 17:52:35 +0000609if [ $WITH_BBSIM == "yes" ]; then
610 echo -e "Verify BBSIM $PLUG"
611 bspin - "Verify BBSIM Insalled"
612 if [ $(helm list --deployed --short --namespace voltha "^bbsim\$" | wc -l) -ne 1 ]; then
613 espin - $NOT_VERIFIED
614 helm_install - voltha bbsim onf/bbsim "Install BBSIM"
615 else
616 espin - $VERIFIED
617 fi
618 wait_for_pods - "voltha" 1 -1 "Waiting for BBSIM to start" "bbsim-.*"
619fi
620
Test Userb5712372019-07-03 21:52:17 +0000621echo -e "Restart VOLTHA API $RESTART"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700622API="voltha-api-server-.* ofagent-.*"
623(set -x; kubectl scale --replicas=0 deployment -n voltha voltha-api-server ofagent >>$LOG 2>&1) >>$LOG 2>&1
Test Userb5712372019-07-03 21:52:17 +0000624wait_for_pods - "voltha" 0 -1 "Wait for API to stop $STOP" $API
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700625(set -x; kubectl scale --replicas=1 deployment -n voltha voltha-api-server ofagent >>$LOG 2>&1) >>$LOG 2>&1
Test Userb5712372019-07-03 21:52:17 +0000626wait_for_pods - "voltha" 2 -1 "Wait for API to re-start $GO" $API
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700627
Test Userb5712372019-07-03 21:52:17 +0000628bspin - "Forward VOLTHA API port $FORWARD"
Test User01ed0642019-07-03 20:17:06 +0000629(set -x; screen -p 0 -X -S voltha-api-$TYPE stuff $'\003' >>$LOG 2>&1) >>$LOG 2>&1
630(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 -0700631espin - $VERIFIED
Test Userb5712372019-07-03 21:52:17 +0000632bspin - "Forward VOLTHA SSH port $FORWARD"
Test User01ed0642019-07-03 20:17:06 +0000633(set -x; screen -p 0 -X -S voltha-ssh-$TYPE stuff $'\003' 2>/dev/null >/dev/null >>$LOG 2>&1) >>$LOG 2>&1
634(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 -0700635espin - $VERIFIED
Test User3d7ad8e2019-07-03 06:15:44 +0000636
637bspin - "Create voltctl configuration file"
638(set -x; mkdir -p $HOME/.volt >>$LOG 2>&1) >>$LOG 2>&1
Test User01ed0642019-07-03 20:17:06 +0000639(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 +0000640espin - $VERIFIED
Test User08ebbd92019-07-03 17:15:39 +0000641
Test User7d866122019-07-09 17:52:35 +0000642echo ""
Test User08ebbd92019-07-03 17:15:39 +0000643echo "Please issue the following commands in your terminal to ensure that you" | tee -a $LOG
644echo "are accessing the correct Kubernetes/Kind cluster as well as have the " | tee -a $LOG
645echo "tools required by VOLTHA in your command path. " | tee -a $LOG
646echo "" | tee -a $LOG
Test User7d866122019-07-09 17:52:35 +0000647echo -en $BOLD
Test Userba1e7e72019-07-10 22:27:54 +0000648if [ $DEPLOY_K8S == "yes" ]; then
649 echo "export KUBECONFIG=\"\$(./bin/kind get kubeconfig-path --name=\"voltha-$TYPE\")\"" | tee -a $LOG
650fi
Test Userfa30f7f2019-07-03 20:35:19 +0000651echo "export VOLTCONFIG=\"$HOME/.volt/config-$TYPE\"" | tee -a $LOG
Test Userba1e7e72019-07-10 22:27:54 +0000652echo "export PATH=$GOPATH/bin:\$PATH" | tee -a $LOG
Test User7d866122019-07-09 17:52:35 +0000653echo -en $NORMAL
Test User08ebbd92019-07-03 17:15:39 +0000654echo "" | tee -a $LOG
655echo "Thank you for choosing kind-voltha for you quick cluster needs." | tee -a $LOG
656