blob: 9b95959bbf7ec2ca7e6900c3a8b6209f69633696 [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}
Test Userba1e7e72019-07-10 22:27:54 +000055
56HAVE_GO=$(which go >/dev/null 2>&1 && echo "yes" || echo "no")
57HOSTOS=$(uname -s | tr "[:upper:]" "[:lower:"])
58HOSTARCH=$(uname -m | tr "[:upper:]" "[:lower:"])
59if [ $HOSTARCH == "x86_64" ]; then
60 HOSTARCH="amd64"
61fi
Test User7d866122019-07-09 17:52:35 +000062
63# Verify TYPE setting
64if [ $(echo ":minimal:full:" | grep -ic ":$TYPE:") -eq 0 ]; then
David K. Bainbridge0e89cb92019-07-17 11:30:10 -070065 >&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 +000066 exit 1
67fi
68
69# Verify WITH_BBSIM settting and convert uniform value of yes or no
70if [ $(echo ":y:yes:true:n:no:false:1:0:" | grep -ic ":$WITH_BBSIM:") -eq 0 ]; then
David K. Bainbridge0e89cb92019-07-17 11:30:10 -070071 >&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 +000072 exit 1
73fi
74if [ $(echo ":y:yes:true:1:" | grep -ic ":$WITH_BBSIM:") -eq 1 ]; then
75 WITH_BBSIM=yes
76else
77 WITH_BBSIM=no
78fi
79
Test Userba1e7e72019-07-10 22:27:54 +000080# Verify JUST_K8S settting and convert uniform value of yes or no
81if [ $(echo ":y:yes:true:n:no:false:1:0:" | grep -ic ":$JUST_K8S:") -eq 0 ]; then
David K. Bainbridge0e89cb92019-07-17 11:30:10 -070082 >&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 +000083 exit 1
84fi
85if [ $(echo ":y:yes:true:1:" | grep -ic ":$JUST_K8S:") -eq 1 ]; then
86 JUST_K8S=yes
87else
88 JUST_K8S=no
89fi
90
91# Verify DEPLOY_K8S settting and convert uniform value of yes or no
92if [ $(echo ":y:yes:true:n:no:false:1:0:" | grep -ic ":$DEPLOY_K8S:") -eq 0 ]; then
David K. Bainbridge0e89cb92019-07-17 11:30:10 -070093 >&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 +000094 exit 1
95fi
96if [ $(echo ":y:yes:true:1:" | grep -ic ":$DEPLOY_K8S:") -eq 1 ]; then
97 DEPLOY_K8S=yes
98else
99 DEPLOY_K8S=no
100fi
Test User01ed0642019-07-03 20:17:06 +0000101
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700102# Verify INSTALL_KUBECTL settting and convert uniform value of yes or no
103if [ $(echo ":y:yes:true:n:no:false:1:0:" | grep -ic ":$INSTALL_KUBECTL:") -eq 0 ]; then
104 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} Invalid \$INSTALL_KUBECTL value of '$INSTALL_KUBECTL'. Should be 'yes' or 'no'${NORMAL}"
105 exit 1
106fi
107
108if [ $(echo ":y:yes:true:1:" | grep -ic ":$INSTALL_KUBECTL:") -eq 1 ]; then
109 INSTALL_KUBECTL=yes
110else
111 INSTALL_KUBECTL=no
112fi
113
David Bainbridgee10f6d52019-07-25 00:28:13 +0000114# Verify SKIP_RESTART_API settting and convert uniform value of yes or no
115if [ $(echo ":y:yes:true:n:no:false:1:0:" | grep -ic ":$SKIP_RESTART_API:") -eq 0 ]; then
116 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} Invalid \$SKIP_RESTART_API value of '$SKIP_RESTART_API'. Should be 'yes' or 'no'${NORMAL}"
117 exit 1
118fi
119if [ $(echo ":y:yes:true:1:" | grep -ic ":$SKIP_RESTART_API:") -eq 1 ]; then
120 SKIP_RESTART_API=yes
121else
122 SKIP_RESTART_API=no
123fi
124
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700125# Verify INSTALL_HELM settting and convert uniform value of yes or no
126if [ $(echo ":y:yes:true:n:no:false:1:0:" | grep -ic ":$INSTALL_HELM:") -eq 0 ]; then
127 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} Invalid \$INSTALL_HELM value of '$INSTALL_HELM'. Should be 'yes' or 'no'${NORMAL}"
128 exit 1
129fi
130
131if [ $(echo ":y:yes:true:1:" | grep -ic ":$INSTALL_HELM:") -eq 1 ]; then
132 INSTALL_HELM=yes
133else
134 INSTALL_HELM=no
135fi
136
Test User01ed0642019-07-03 20:17:06 +0000137if [ "$TYPE" == "full" ]; then
138 ONOS_API_PORT=${ONOS_API_PORT:-8182}
139 ONOS_SSH_PORT=${ONOS_SSH_PORT:-8102}
140 VOLTHA_API_PORT=${VOLTHA_API_PORT:-55556}
141 VOLTHA_SSH_PORT=${VOLTHA_SSH_PORT:-5023}
142else
143 ONOS_API_PORT=${ONOS_API_PORT:-8181}
144 ONOS_SSH_PORT=${ONOS_SSH_PORT:-8101}
145 VOLTHA_API_PORT=${VOLTHA_API_PORT:-55555}
146 VOLTHA_SSH_PORT=${VOLTHA_SSH_PORT:-5022}
147fi
148
149if [ "$1" == "get" -a "$2" == "voltconfig" ]; then
150 echo "$HOME/.volt/config-$TYPE"
151 exit
152fi
Test User3d7ad8e2019-07-03 06:15:44 +0000153
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700154if [ $# -ne 1 -o $(echo ":up:down:" | grep -c ":$1:") -ne 1 ]; then
155 >&2 echo "up or down?"
156 exit 1
157fi
158
159if [ "$1" == "down" ]; then
Test Userba1e7e72019-07-10 22:27:54 +0000160 if [ $DEPLOY_K8S == "yes" ]; then
161 if [ -x ./bin/kind ]; then
162 exec ./bin/kind delete cluster --name voltha-$TYPE
163 else
164 >&2 echo "Kind doesn't seem to be installed, so nothing to do. Bye."
165 fi
Test User08ebbd92019-07-03 17:15:39 +0000166 else
Test Userba1e7e72019-07-10 22:27:54 +0000167 EXISTS=$(helm list -q)
168 EXPECT="etcd-operator onos open-olt open-onu sim voltha"
169 INTERSECT=
170 for i in $EXISTS; do
171 if [ $(echo $EXPECT | grep -c $i) -eq 1 ]; then
172 HAVE="$HAVE $i"
173 fi
174 done
175 ./bin/helm delete --purge $HAVE
176fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700177 exit
178fi
179
Test User01ed0642019-07-03 20:17:06 +0000180LOG="install-$TYPE.log"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700181date > $LOG
182
183spin() {
Test Userd87942b2019-07-03 07:20:24 +0000184 PARTS="\
185 \xe2\xa2\x8e\xe2\xa1\xb0 \
186 \xe2\xa2\x8e\xe2\xa1\xa1 \
187 \xe2\xa2\x8e\xe2\xa1\x91 \
188 \xe2\xa2\x8e\xe2\xa0\xb1 \
189 \xe2\xa0\x8e\xe2\xa1\xb1 \
190 \xe2\xa2\x8a\xe2\xa1\xb1 \
191 \xe2\xa2\x8c\xe2\xa1\xb1 \
192 \xe2\xa2\x86\xe2\xa1\xb1 \
193 "
194 IDX=1
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700195 tput civis
196 while true; do
Test Userd87942b2019-07-03 07:20:24 +0000197 C=$(echo $PARTS | cut '-d ' -f $IDX)
198 echo -en "$C"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700199 IDX=$(expr $IDX + 1)
Test Userd87942b2019-07-03 07:20:24 +0000200 if [ $IDX -gt 8 ]; then
201 IDX=1
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700202 fi
203 sleep .15
204 echo -en "\r"
205 done
206}
207
Test Userd87942b2019-07-03 07:20:24 +0000208SPIN_PARTS="\
209 \xe2\xa2\x8e\xe2\xa1\xb0 \
210 \xe2\xa2\x8e\xe2\xa1\xa1 \
211 \xe2\xa2\x8e\xe2\xa1\x91 \
212 \xe2\xa2\x8e\xe2\xa0\xb1 \
213 \xe2\xa0\x8e\xe2\xa1\xb1 \
214 \xe2\xa2\x8a\xe2\xa1\xb1 \
215 \xe2\xa2\x8c\xe2\xa1\xb1 \
216 \xe2\xa2\x86\xe2\xa1\xb1 \
217 "
218IDX=1
219NOT_VERIFIED="\xe2\x9c\x97\x20"
220VERIFIED="\xe2\x9c\x93\x20"
Test Userb5712372019-07-03 21:52:17 +0000221HELM="\xE2\x8E\x88"
222OLD_KEY="\xF0\x9F\x97\x9D"
223BIRD="\xF0\x9F\x90\xA6"
224HIGH_VOLTAGE="\xE2\x9A\xA1"
225PLUG="\xF0\x9F\xa7\xa9"
226RESTART="\xf0\x9f\x94\x84"
227FORWARD="\xE2\x87\xA8"
228INSTALL="\xF0\x9F\x8F\x97"
229STOP="\xf0\x9f\x9b\x91"
230GO="\xf0\x9f\x9a\x80"
231DOWNLOAD="\xf0\x9f\x93\xa5"
232GEAR="\xe2\x9a\x99"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700233NO_ENTRY="\xe2\x9b\x94"
234
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700235bspin() {
236 tput civis
Test Userd87942b2019-07-03 07:20:24 +0000237 IDX=1
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700238 local INDENT=
239 if [ "$1" == "-" ]; then
240 INDENT=" "
241 shift
242 fi
Test Userd87942b2019-07-03 07:20:24 +0000243 echo -en "$INDENT $*"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700244}
245
246sspin() {
247 local INDENT=
248 if [ "$1" == "-" ]; then
249 INDENT=" "
250 shift
251 fi
Test Userd87942b2019-07-03 07:20:24 +0000252 C=$(echo $SPIN_PARTS | cut '-d ' -f $IDX)
253 echo -en "\r$INDENT$C $*"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700254 IDX=$(expr $IDX + 1)
Test Userd87942b2019-07-03 07:20:24 +0000255 if [ $IDX -gt 8 ]; then
256 IDX=1
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700257 fi
258}
259
260espin() {
261 local INDENT=
262 if [ "$1" == "-" ]; then
263 INDENT=" "
264 shift
265 fi
266 echo -e "\r$INDENT$*"
267 tput cnorm
268}
269
270count_pods() {
271 local NAMESPACE=$1; shift
272 local PODS=$(kubectl -n $NAMESPACE get pod -o go-template="{{range .items}}{{.metadata.name}}/{{.status.phase}}/_{{range .status.containerStatuses}}{{.ready}}_{{end}} {{end}}")
273 local COUNT=0
274 local PATTERNS=$*
275 for POD in $PODS; do
276 local NAME=$(echo $POD | cut -d/ -f 1)
277 local STATE=$(echo $POD | cut -d/ -f 2)
278 local CONTAINERS=$(echo $POD | cut -d/ -f 3 | sed -e 's/_/ /g')
279 if [ "$STATE" == "Running" ]; then
280 local TOTAL=$(echo $CONTAINERS | wc -w)
281 local FOUND=$(echo $CONTAINERS | grep -o true | wc -l)
282 if [ $TOTAL -eq $FOUND ]; then
283 for PATTERN in $PATTERNS; do
284 if [[ $NAME =~ $PATTERN ]]; then
285 COUNT=$(expr $COUNT + 1)
286 fi
287 done
288 fi
289 fi
290 done
291 echo $COUNT
292}
293
294wait_for_pods() {
295 local INDENT=
296 if [ "$1" == "-" ]; then
297 INDENT=$1; shift
298 fi
299 local NAMESPACE=$1; shift
300 local EXPECT=$1; shift
301 local RETRY=$1; shift
302 local MESSAGE=$1; shift
303 local PATTERNS=$*
304 local HAVE=$(count_pods $NAMESPACE $PATTERNS)
305 COUNT=$(expr 300 / 15)
306 bspin $INDENT $MESSAGE
307 sspin $INDENT
308 if [ $HAVE -ne $EXPECT ]; then
309 while [ $HAVE -ne $EXPECT ]; do
310 sspin $INDENT
311 COUNT=$(expr $COUNT - 1)
312 if [ $COUNT -eq 0 ]; then
313 HAVE=$(count_pods $NAMESPACE $PATTERNS)
314 COUNT=$(expr 300 / 15)
315 fi
316 sleep .15
317 done
318 fi
319 espin $INDENT $VERIFIED
320 if [ $HAVE -ne $EXPECT ]; then
321 return 1
322 fi
323 return 0
324}
325
326helm_install() {
327 local INDENT=
328 if [ "$1" == "-" ]; then
329 INDENT=$1; shift
330 fi
331 local NAMESPACE=$1; shift
332 local NAME=$1; shift
333 local CHART=$1; shift
334 local MESSAGE=$*
335
336 COUNT=$(expr 300 / 15)
337 bspin $INDENT $MESSAGE
David Bainbridgee10f6d52019-07-25 00:28:13 +0000338 (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 -0700339 SUCCESS=$?
340 while [ $SUCCESS -ne 0 ]; do
341 sspin $INDENT
342 COUNT=$(expr $COUNT - 1)
343 if [ $COUNT -eq 0 ]; then
David Bainbridgee10f6d52019-07-25 00:28:13 +0000344 (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 -0700345 COUNT=$(expr 300 / 15)
346 fi
347 sleep .15
348 done
349 espin $INDENT $VERIFIED
350}
351
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700352echo "INSTALL TYPE: $TYPE" >> $LOG
353
354bspin "Verify GOPATH"
355export GOPATH=$(pwd)
Test User3d7ad8e2019-07-03 06:15:44 +0000356mkdir -p $GOPATH/bin
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700357espin $VERIFIED
358
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700359if [ "$INSTALL_KUBECTL" == "no" ]; then
360 bspin "Skip kubectl install"
361 espin $NO_ENTRY
Test Userc13bdc92019-07-03 20:57:49 +0000362else
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700363 bspin "Verify kubectl $HELM"
364 if [ -x $GOPATH/bin/kubectl ]; then
365 espin $VERIFIED
366 else
367 espin $NOT_VERIFIED
368 bspin - "Download and install Kubernetes/kubectl $DOWNLOAD"
369 (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
370 (set -x; chmod 755 $GOPATH/bin/kubectl >>$LOG 2>&1) >>$LOG 2>&1
371 espin - $VERIFIED
372 fi
Test Userc13bdc92019-07-03 20:57:49 +0000373fi
374
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700375if [ "$DEPLOY_K8S" == "no" ]; then
376 bspin "Skip Kubernetes/Kind Deployment"
377 espin $NO_ENTRY
378else
Test Userba1e7e72019-07-10 22:27:54 +0000379 bspin "Verify Kubernetes/Kind $HELM"
380 if [ -x $GOPATH/bin/kind ]; then
381 espin $VERIFIED
382 else
383 espin $NOT_VERIFIED
384 bspin - "Download and install Kubernetes/kind $DOWNLOAD"
David Bainbridge9e2a6662019-07-11 17:07:57 +0000385 (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 +0000386 (set -x; chmod 755 $GOPATH/bin/kind >>$LOG 2>&1) >>$LOG 2>&1
387 espin - $VERIFIED
388 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700389fi
390
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700391if [ "$INSTALL_HELM" == "no" ]; then
392 bspin "Skip Helm Install"
393 espin $NO_ENTRY
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700394else
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700395 bspin "Verify Helm $HELM"
396 if [ -x $GOPATH/bin/helm ]; then
397 espin $VERIFIED
398 else
399 espin $NOT_VERIFIED
400 bspin - "Download and install Helm $DOWNLOAD"
401 (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
402 espin - $VERIFIED
403 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700404fi
405
Test Userb5712372019-07-03 21:52:17 +0000406bspin "Verify voltctl $HIGH_VOLTAGE"
Test User3d7ad8e2019-07-03 06:15:44 +0000407if [ -x $GOPATH/bin/voltctl ]; then
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700408 espin $VERIFIED
409else
410 espin $NOT_VERIFIED
Test Userb5712372019-07-03 21:52:17 +0000411 bspin - "Download and build voltctl $DOWNLOAD"
Test Userba1e7e72019-07-10 22:27:54 +0000412 (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 +0000413 (set -x; chmod 755 $GOPATH/bin/voltctl >>$LOG 2>&1) >>$LOG 2>&1
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700414 espin - $VERIFIED
415fi
416
417bspin "Verify command PATH"
Test Userba1e7e72019-07-10 22:27:54 +0000418export PATH=$GOPATH/bin:$PATH
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700419espin $VERIFIED
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700420
Test Userba1e7e72019-07-10 22:27:54 +0000421if [ "$DEPLOY_K8S" == "yes" ]; then
422 HAVE=$(kind get clusters | grep -c voltha-$TYPE)
423 bspin "Verify Kubernetes/Kind Cluster"
424 sspin
425 if [ $HAVE -eq 0 ]; then
David Bainbridge491b1bd2019-07-11 17:53:11 +0000426 espin $NOT_VERIFIED
427 bspin - "Verify cluster configuration"
428 if [ ! -r ./$TYPE-cluster.cfg ]; then
429 espin - $NOT_VERIFIED
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700430 bspin - "Download cluster configuration: $TYPE-cluster.cfg $DOWNLOAD"
David Bainbridge491b1bd2019-07-11 17:53:11 +0000431 (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 -0700432 espin - $VERIFIED
433 else
434 espin - $VERIFIED
435 fi
David Bainbridge491b1bd2019-07-11 17:53:11 +0000436 kind create cluster --name voltha-$TYPE --config $TYPE-cluster.cfg
437 else
438 espin $VERIFIED
Test Userba1e7e72019-07-10 22:27:54 +0000439 fi
440
441 export KUBECONFIG="$(kind get kubeconfig-path --name="voltha-$TYPE")"
442 P="coredns-.* \
443 etcd-voltha-$TYPE-control-plane \
444 kindnet-.* \
445 kube-apiserver-voltha-$TYPE-control-plane \
446 kube-controller-manager-voltha-$TYPE-control-plane \
447 kube-proxy-.* \
448 kube-scheduler-voltha-$TYPE-control-plane"
449
450 EXPECT=$(test "$TYPE" == "minimal" && echo "12" || echo "14")
451 wait_for_pods - "kube-system" $EXPECT -1 "Waiting for system PODs to start" $P
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700452fi
453
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700454COUNT=$(count_pods "kube-system" "tiller-deploy-.*")
455bspin "Verify Helm"
Test Userba1e7e72019-07-10 22:27:54 +0000456if [ $COUNT -ne 1 ]; then
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700457 espin $NOT_VERIFIED
Test Userb5712372019-07-03 21:52:17 +0000458 echo -e "Configuring Helm $GEAR"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700459 if [ "$INSTALL_HELM" == "no" ]; then
460 bspin - "Skip Helm/Tiller Initialization"
461 espin - $NO_ENTRY
462 else
463 bspin - "Initialize Helm"
464 (set -x; helm init --upgrade >>$LOG 2>&1) >>$LOG 2>&1
465 espin - $VERIFIED
466 wait_for_pods - "kube-system" 1 -1 "Waiting for Tiller POD to start" "tiller-deploy-.*"
467 fi
Test Userb5712372019-07-03 21:52:17 +0000468 bspin - "Add Google Incubator repository to Helm"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700469 (set -x; helm repo add incubator https://kubernetes-charts-incubator.storage.googleapis.com >>$LOG 2>&1) >>$LOG 2>&1
470 espin - $VERIFIED
Test Userba1e7e72019-07-10 22:27:54 +0000471
472 # HACK (sort-of) - the config for tiller is about to be patched, which will
473 # cause the tiller pod to be recreated. This can sometimes cause a timing
474 # issue with the "wait_for_pods" call on tiller as it may incorrectly
475 # identify the running/ready tiller pod that is soon to be terminated as
476 # what it is waiting for. To avoid this issue we do a clean scale down and
477 # scale up of the pod so the script controlls when it should be expecting
478 # things
479 (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 -0700480
Test Userb5712372019-07-03 21:52:17 +0000481 bspin - "Add Google Stable repository to Helm"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700482 (set -x; helm repo add stable https://kubernetes-charts.storage.googleapis.com >>$LOG 2>&1) >>$LOG 2>&1
483 espin - $VERIFIED
Test Userb5712372019-07-03 21:52:17 +0000484 bspin - "Add ONF repository to Helm"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700485 (set -x; helm repo add onf https://charts.opencord.org >>$LOG 2>&1) >>$LOG 2>&1
486 espin - $VERIFIED
Test Userb5712372019-07-03 21:52:17 +0000487 bspin - "Update Helm repository cache"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700488 (set -x; helm repo update >>$LOG 2>&1) >>$LOG 2>&1
489 espin - $VERIFIED
490
491 # Create and k8s service account so that Helm can create pods
Test Userb5712372019-07-03 21:52:17 +0000492 bspin - "Create Tiller ServiceAccount"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700493 (set -x; kubectl create serviceaccount --namespace kube-system tiller >>$LOG 2>&1) >>$LOG 2>&1
494 espin - $VERIFIED
Test Userb5712372019-07-03 21:52:17 +0000495 bspin - "Create Tiller ClusterRoleBinding"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700496 (set -x; kubectl create clusterrolebinding tiller-cluster-rule --clusterrole=cluster-admin --serviceaccount=kube-system:tiller >>$LOG 2>&1) >>$LOG 2>&1
497 espin - $VERIFIED
Test Userb5712372019-07-03 21:52:17 +0000498 bspin - "Update Tiller Manifest"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700499 (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 +0000500
501 # HACK (sort-of) - part to, spin it back up
502 (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 -0700503 espin - $VERIFIED
504else
505 espin $VERIFIED
506fi
Test Userb5712372019-07-03 21:52:17 +0000507wait_for_pods - "kube-system" 1 -1 "Waiting for Tiller POD to start" "tiller-deploy-.*"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700508
Test Userba1e7e72019-07-10 22:27:54 +0000509bspin "Verify Helm values file: $TYPE-values.yaml"
510if [ ! -r "./$TYPE-values.yaml" ]; then
511 espin $NOT_VERIFIED
512 bspin - "Download Helm values file: $TYPE-values.yaml $DOWNLOAD"
513 (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
514 espin - $VERIFIED
515else
516 espin $VERIFIED
517fi
518
519if [ "$JUST_K8S" == "yes" ]; then
520 echo "Environment deployed, not deploying VOLTHA artifacts as requested. Good bye."
521 echo ""
522 echo "Please issue the following commands in your terminal to ensure that you" | tee -a $LOG
523 echo "are accessing the correct Kubernetes/Kind cluster as well as have the " | tee -a $LOG
524 echo "tools required by VOLTHA in your command path. " | tee -a $LOG
525 echo "" | tee -a $LOG
526 echo -en $BOLD
527 if [ $DEPLOY_K8S == "yes" ]; then
528 echo "export KUBECONFIG=\"\$(./bin/kind get kubeconfig-path --name=\"voltha-$TYPE\")\"" | tee -a $LOG
529 fi
530 echo "export PATH=$GOPATH/bin:\$PATH" | tee -a $LOG
531 echo -en $NORMAL
532 echo "" | tee -a $LOG
533 echo "Thank you for choosing kind-voltha for you quick cluster needs." | tee -a $LOG
534 exit 0
535fi
536
Test Userb5712372019-07-03 21:52:17 +0000537bspin "Verify ETCD Operator $OLD_KEY"
Test User7d866122019-07-09 17:52:35 +0000538if [ $(helm list --deployed --short --namespace voltha "^etcd-operator\$" | wc -l) -ne 1 ]; then
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700539 espin $NOT_VERIFIED
540 helm_install - voltha etcd-operator stable/etcd-operator "Install ETCD Operator"
541else
542 espin $VERIFIED
543fi
Test User01ed0642019-07-03 20:17:06 +0000544EXPECT=$(test "$TYPE" == "minimal" && echo "1" || echo "3")
Test Userb5712372019-07-03 21:52:17 +0000545wait_for_pods - "voltha" $EXPECT -1 "Waiting for ETCD Operator to start" "etcd-operator-.*"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700546
Test Userb5712372019-07-03 21:52:17 +0000547bspin "Verify ONOS installed $BIRD"
Test User7d866122019-07-09 17:52:35 +0000548if [ $(helm list --deployed --short --namespace default "^onos\$" | wc -l) -ne 1 ]; then
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700549 espin $NOT_VERIFIED
550 helm_install - default onos onf/onos "Install ONOS"
551else
552 espin $VERIFIED
553fi
Test Userb5712372019-07-03 21:52:17 +0000554wait_for_pods - "default" 1 -1 "Waiting for ONOS to start" "onos-.*"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700555
Test Userb5712372019-07-03 21:52:17 +0000556bspin - "Forward ONOS API port $FORWARD"
Test User01ed0642019-07-03 20:17:06 +0000557(set -x; screen -p 0 -X -S onos-ui-$TYPE stuff $'\003' >>$LOG 2>&1) >>$LOG 2>&1
558(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 -0700559espin - $VERIFIED
Test Userb5712372019-07-03 21:52:17 +0000560bspin - "Forward ONOS SSH port $FORWARD"
Test User01ed0642019-07-03 20:17:06 +0000561(set -x; screen -p 0 -X -S onos-ssh-$TYPE stuff $'\003' >>$LOG 2>&1) >>$LOG 2>&1
562(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 -0700563espin - $VERIFIED
Test Userba1e7e72019-07-10 22:27:54 +0000564if [ ! -x ./onos-files/install-onos-applications.sh ]; then
565 bspin - "Verify or download ONOS configuration support files $DOWNLOAD"
566 (set -x; mkdir -p ./onos-files >>$LOG 2>&1) >>$LOG 2>&1
567 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
568 if [ ! -r ./onos-files/$i ]; then
569 (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
570 fi
571 done
572 (set -x; chmod 755 ./onos-files/install-onos-applications.sh >>$LOG 2>&1) >>$LOG 2>&1
573 espin - $VERIFIED
574fi
575
Test Userb5712372019-07-03 21:52:17 +0000576bspin - "Install required ONOS applications $INSTALL"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700577(set -x; ./onos-files/install-onos-applications.sh >>$LOG 2>&1) >>$LOG 2>&1
578espin - $VERIFIED
579
Test Userb5712372019-07-03 21:52:17 +0000580bspin "Verify VOLTHA installed $HIGH_VOLTAGE"
Test User7d866122019-07-09 17:52:35 +0000581if [ $(helm list --deployed --short --namespace voltha "^voltha\$" | wc -l) -ne 1 ]; then
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700582 espin $NOT_VERIFIED
David Bainbridgee10f6d52019-07-25 00:28:13 +0000583 helm_install - voltha voltha $VOLTHA_CHART "Install VOLTHA Core"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700584else
585 espin $VERIFIED
586fi
Test Userba1e7e72019-07-10 22:27:54 +0000587
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700588VOLTHA="ofagent-.* \
589 ro-core.* \
590 rw-core.* \
591 voltha-api-server-.* \
592 voltha-cli-server-.* \
593 voltha-etcd-cluster-.* \
594 voltha-kafka-.* \
595 voltha-zookeeper-.*"
Test User01ed0642019-07-03 20:17:06 +0000596EXPECT=$(test "$TYPE" == "minimal" && echo "9" || echo "11")
Test Userb5712372019-07-03 21:52:17 +0000597wait_for_pods - "voltha" $EXPECT -1 "Waiting for VOLTHA Core to start" $VOLTHA
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700598
Test Userb5712372019-07-03 21:52:17 +0000599echo -e "Verify Adapters $PLUG"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700600bspin - "Verify Simulated Adapters installed"
Test User7d866122019-07-09 17:52:35 +0000601if [ $(helm list --deployed --short --namespace voltha "^sim\$" | wc -l) -ne 1 ]; then
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700602 espin - $NOT_VERIFIED
David Bainbridgee10f6d52019-07-25 00:28:13 +0000603 helm_install - voltha sim $VOLTHA_ADAPTER_SIM_CHART "Install Simulated Adapters"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700604else
605 espin - $VERIFIED
606fi
607
608bspin - "Verify OpenOLT Adapter installed"
Test User7d866122019-07-09 17:52:35 +0000609if [ $(helm list --deployed --short --namespace voltha "^open-olt\$" | 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 open-olt $VOLTHA_ADAPTER_OPEN_OLT_CHART "Install OpenOLT Adapter"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700612else
613 espin - $VERIFIED
614fi
615bspin - "Verify OpenONU Adapter installed"
Test User7d866122019-07-09 17:52:35 +0000616if [ $(helm list --deployed --short --namespace voltha "^open-onu\$" | wc -l) -ne 1 ]; then
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700617 espin - $NOT_VERIFIED
David Bainbridgee10f6d52019-07-25 00:28:13 +0000618 helm_install - voltha open-onu $VOLTHA_ADAPTER_OPEN_ONU_CHART "Install OpenONU Adapter"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700619else
620 espin - $VERIFIED
621fi
622
623ADAPTERS="adapter-.*"
Test Userb5712372019-07-03 21:52:17 +0000624wait_for_pods - "voltha" 4 -1 "Waiting for adapters to start" $ADAPTERS
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700625
Test User7d866122019-07-09 17:52:35 +0000626if [ $WITH_BBSIM == "yes" ]; then
627 echo -e "Verify BBSIM $PLUG"
628 bspin - "Verify BBSIM Insalled"
629 if [ $(helm list --deployed --short --namespace voltha "^bbsim\$" | wc -l) -ne 1 ]; then
630 espin - $NOT_VERIFIED
631 helm_install - voltha bbsim onf/bbsim "Install BBSIM"
632 else
633 espin - $VERIFIED
634 fi
635 wait_for_pods - "voltha" 1 -1 "Waiting for BBSIM to start" "bbsim-.*"
636fi
637
David Bainbridgee10f6d52019-07-25 00:28:13 +0000638if [ $SKIP_RESTART_API == "no" ]; then
639 echo -e "Restart VOLTHA API $RESTART"
640 API="voltha-api-server-.* ofagent-.*"
641 (set -x; kubectl scale --replicas=0 deployment -n voltha voltha-api-server ofagent >>$LOG 2>&1) >>$LOG 2>&1
642 wait_for_pods - "voltha" 0 -1 "Wait for API to stop $STOP" $API
643 (set -x; kubectl scale --replicas=1 deployment -n voltha voltha-api-server ofagent >>$LOG 2>&1) >>$LOG 2>&1
644 wait_for_pods - "voltha" 2 -1 "Wait for API to re-start $GO" $API
645else
646 bspin "Skip VOLTHA API Restart"
647 espin $NO_ENTRY
648fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700649
Test Userb5712372019-07-03 21:52:17 +0000650bspin - "Forward VOLTHA API port $FORWARD"
Test User01ed0642019-07-03 20:17:06 +0000651(set -x; screen -p 0 -X -S voltha-api-$TYPE stuff $'\003' >>$LOG 2>&1) >>$LOG 2>&1
652(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 -0700653espin - $VERIFIED
Test Userb5712372019-07-03 21:52:17 +0000654bspin - "Forward VOLTHA SSH port $FORWARD"
Test User01ed0642019-07-03 20:17:06 +0000655(set -x; screen -p 0 -X -S voltha-ssh-$TYPE stuff $'\003' 2>/dev/null >/dev/null >>$LOG 2>&1) >>$LOG 2>&1
656(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 -0700657espin - $VERIFIED
Test User3d7ad8e2019-07-03 06:15:44 +0000658
659bspin - "Create voltctl configuration file"
660(set -x; mkdir -p $HOME/.volt >>$LOG 2>&1) >>$LOG 2>&1
Test User01ed0642019-07-03 20:17:06 +0000661(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 +0000662espin - $VERIFIED
Test User08ebbd92019-07-03 17:15:39 +0000663
Test User7d866122019-07-09 17:52:35 +0000664echo ""
Test User08ebbd92019-07-03 17:15:39 +0000665echo "Please issue the following commands in your terminal to ensure that you" | tee -a $LOG
666echo "are accessing the correct Kubernetes/Kind cluster as well as have the " | tee -a $LOG
667echo "tools required by VOLTHA in your command path. " | tee -a $LOG
668echo "" | tee -a $LOG
Test User7d866122019-07-09 17:52:35 +0000669echo -en $BOLD
Test Userba1e7e72019-07-10 22:27:54 +0000670if [ $DEPLOY_K8S == "yes" ]; then
671 echo "export KUBECONFIG=\"\$(./bin/kind get kubeconfig-path --name=\"voltha-$TYPE\")\"" | tee -a $LOG
672fi
Test Userfa30f7f2019-07-03 20:35:19 +0000673echo "export VOLTCONFIG=\"$HOME/.volt/config-$TYPE\"" | tee -a $LOG
Test Userba1e7e72019-07-10 22:27:54 +0000674echo "export PATH=$GOPATH/bin:\$PATH" | tee -a $LOG
Test User7d866122019-07-09 17:52:35 +0000675echo -en $NORMAL
Test User08ebbd92019-07-03 17:15:39 +0000676echo "" | tee -a $LOG
677echo "Thank you for choosing kind-voltha for you quick cluster needs." | tee -a $LOG
678