blob: 8617ce2da41b18f0d68f9928a428c3ba95269e32 [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"
David Bainbridgeac7f8072019-08-01 22:15:33 +000042CEOL=$(tput el)
Test User7d866122019-07-09 17:52:35 +000043
Test User3d7ad8e2019-07-03 06:15:44 +000044TYPE=${TYPE:-minimal}
David Bainbridge0774b232019-08-02 06:37:19 +000045NAME=${NAME:-$TYPE}
Test User7d866122019-07-09 17:52:35 +000046WITH_BBSIM=${WITH_BBSIM:-no}
David Bainbridge5b7b96b2019-07-25 20:29:13 +000047WITH_RADIUS=${WITH_RADIUS:-no}
David Bainbridgeb270c202019-07-26 01:44:42 +000048WITH_ONOS=${WITH_ONOS:-yes}
David Bainbridge01294952019-07-30 19:33:45 +000049WITH_TP=${WITH_TP:-yes}
Test Userba1e7e72019-07-10 22:27:54 +000050JUST_K8S=${JUST_K8S:-no}
51DEPLOY_K8S=${DEPLOY_K8S:-yes}
David Bainbridgee10f6d52019-07-25 00:28:13 +000052SKIP_RESTART_API=${SKIP_RESTART_API:-no}
David K. Bainbridge0e89cb92019-07-17 11:30:10 -070053INSTALL_KUBECTL=${INSTALL_KUBECTL:-yes}
54INSTALL_HELM=${INSTALL_HELM:-yes}
David Bainbridge5b7b96b2019-07-25 20:29:13 +000055USE_GO=${USE_GO:-yes}
56VOLTHA_LOG_LEVEL=${VOLTHA_LOG_LEVEL:-WARN}
David Bainbridgee10f6d52019-07-25 00:28:13 +000057VOLTHA_CHART=${VOLTHA_CHART:=onf/voltha}
58VOLTHA_ADAPTER_SIM_CHART=${VOLTHA_ADAPTER_SIM_CHART:-onf/voltha-adapter-simulated}
59VOLTHA_ADAPTER_OPEN_OLT_CHART=${VOLTHA_ADAPTER_OPEN_OLT_CHART:-onf/voltha-adapter-openolt}
60VOLTHA_ADAPTER_OPEN_ONU_CHART=${VOLTHA_ADAPTER_OPEN_ONU_CHART:-onf/voltha-adapter-openonu}
Test Userba1e7e72019-07-10 22:27:54 +000061
62HAVE_GO=$(which go >/dev/null 2>&1 && echo "yes" || echo "no")
63HOSTOS=$(uname -s | tr "[:upper:]" "[:lower:"])
64HOSTARCH=$(uname -m | tr "[:upper:]" "[:lower:"])
65if [ $HOSTARCH == "x86_64" ]; then
66 HOSTARCH="amd64"
67fi
Test User7d866122019-07-09 17:52:35 +000068
69# Verify TYPE setting
70if [ $(echo ":minimal:full:" | grep -ic ":$TYPE:") -eq 0 ]; then
David K. Bainbridge0e89cb92019-07-17 11:30:10 -070071 >&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 +000072 exit 1
73fi
74
75# Verify WITH_BBSIM settting and convert uniform value of yes or no
76if [ $(echo ":y:yes:true:n:no:false:1:0:" | grep -ic ":$WITH_BBSIM:") -eq 0 ]; then
David K. Bainbridge0e89cb92019-07-17 11:30:10 -070077 >&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 +000078 exit 1
79fi
80if [ $(echo ":y:yes:true:1:" | grep -ic ":$WITH_BBSIM:") -eq 1 ]; then
81 WITH_BBSIM=yes
82else
83 WITH_BBSIM=no
84fi
85
David Bainbridge5b7b96b2019-07-25 20:29:13 +000086# Verify WITH_RADIUS settting and convert uniform value of yes or no
87if [ $(echo ":y:yes:true:n:no:false:1:0:" | grep -ic ":$WITH_RADIUS:") -eq 0 ]; then
88 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} Invalid \$WITH_RADIUS value of '$WITH_RADIUS'. Should be 'yes' or 'no'${NORMAL}"
89 exit 1
90fi
91if [ $(echo ":y:yes:true:1:" | grep -ic ":$WITH_RADIUS:") -eq 1 ]; then
92 WITH_RADIUS=yes
93else
94 WITH_RADIUS=no
95fi
96
David Bainbridge01294952019-07-30 19:33:45 +000097# Verify WITH_TP settting and convert uniform value of yes or no
98if [ $(echo ":y:yes:true:n:no:false:1:0:" | grep -ic ":$WITH_TP:") -eq 0 ]; then
99 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} Invalid \$WITH_TP value of '$WITH_TP'. Should be 'yes' or 'no'${NORMAL}"
100 exit 1
101fi
102if [ $(echo ":y:yes:true:1:" | grep -ic ":$WITH_TP:") -eq 1 ]; then
103 WITH_TP=yes
104else
105 WITH_TP=no
106fi
107
David Bainbridgeb270c202019-07-26 01:44:42 +0000108# Verify WITH_ONOS settting and convert uniform value of yes or no
109if [ $(echo ":y:yes:true:n:no:false:1:0:" | grep -ic ":$WITH_ONOS:") -eq 0 ]; then
110 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} Invalid \$WITH_ONOS value of '$WITH_ONOS'. Should be 'yes' or 'no'${NORMAL}"
111 exit 1
112fi
113if [ $(echo ":y:yes:true:1:" | grep -ic ":$WITH_ONOS:") -eq 1 ]; then
114 WITH_ONOS=yes
115else
116 WITH_ONOS=no
117fi
118
Test Userba1e7e72019-07-10 22:27:54 +0000119# Verify JUST_K8S settting and convert uniform value of yes or no
120if [ $(echo ":y:yes:true:n:no:false:1:0:" | grep -ic ":$JUST_K8S:") -eq 0 ]; then
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700121 >&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 +0000122 exit 1
123fi
124if [ $(echo ":y:yes:true:1:" | grep -ic ":$JUST_K8S:") -eq 1 ]; then
125 JUST_K8S=yes
126else
127 JUST_K8S=no
128fi
129
130# Verify DEPLOY_K8S settting and convert uniform value of yes or no
131if [ $(echo ":y:yes:true:n:no:false:1:0:" | grep -ic ":$DEPLOY_K8S:") -eq 0 ]; then
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700132 >&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 +0000133 exit 1
134fi
135if [ $(echo ":y:yes:true:1:" | grep -ic ":$DEPLOY_K8S:") -eq 1 ]; then
136 DEPLOY_K8S=yes
137else
138 DEPLOY_K8S=no
139fi
Test User01ed0642019-07-03 20:17:06 +0000140
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700141# Verify INSTALL_KUBECTL settting and convert uniform value of yes or no
142if [ $(echo ":y:yes:true:n:no:false:1:0:" | grep -ic ":$INSTALL_KUBECTL:") -eq 0 ]; then
143 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} Invalid \$INSTALL_KUBECTL value of '$INSTALL_KUBECTL'. Should be 'yes' or 'no'${NORMAL}"
144 exit 1
145fi
146
147if [ $(echo ":y:yes:true:1:" | grep -ic ":$INSTALL_KUBECTL:") -eq 1 ]; then
148 INSTALL_KUBECTL=yes
149else
150 INSTALL_KUBECTL=no
151fi
152
David Bainbridgee10f6d52019-07-25 00:28:13 +0000153# Verify SKIP_RESTART_API settting and convert uniform value of yes or no
154if [ $(echo ":y:yes:true:n:no:false:1:0:" | grep -ic ":$SKIP_RESTART_API:") -eq 0 ]; then
155 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} Invalid \$SKIP_RESTART_API value of '$SKIP_RESTART_API'. Should be 'yes' or 'no'${NORMAL}"
156 exit 1
157fi
158if [ $(echo ":y:yes:true:1:" | grep -ic ":$SKIP_RESTART_API:") -eq 1 ]; then
159 SKIP_RESTART_API=yes
160else
161 SKIP_RESTART_API=no
162fi
163
David Bainbridge1ceabc12019-07-25 17:21:05 +0000164# Verify USE_GO settting and convert uniform value of yes or no
165if [ $(echo ":y:yes:true:n:no:false:1:0:" | grep -ic ":$USE_GO:") -eq 0 ]; then
166 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} Invalid \$USE_GO value of '$USE_GO'. Should be 'yes' or 'no'${NORMAL}"
167 exit 1
168fi
169if [ $(echo ":y:yes:true:1:" | grep -ic ":$USE_GO:") -eq 1 ]; then
170 USE_GO=true
171else
172 USE_GO=false
173fi
174
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700175# Verify INSTALL_HELM settting and convert uniform value of yes or no
176if [ $(echo ":y:yes:true:n:no:false:1:0:" | grep -ic ":$INSTALL_HELM:") -eq 0 ]; then
177 >&2 echo -e "${RED}${BOLD}${ERROR}ERROR:${NORMAL}${RED} Invalid \$INSTALL_HELM value of '$INSTALL_HELM'. Should be 'yes' or 'no'${NORMAL}"
178 exit 1
179fi
180
181if [ $(echo ":y:yes:true:1:" | grep -ic ":$INSTALL_HELM:") -eq 1 ]; then
182 INSTALL_HELM=yes
183else
184 INSTALL_HELM=no
185fi
186
David Bainbridge0774b232019-08-02 06:37:19 +0000187mkdir -p .voltha
188touch .voltha/ports
189HAVE=$(grep $NAME .voltha/ports)
190if [ "$HAVE X" == " X" ]; then
191 # Find free port prefix
192 START=81
193 while true; do
194 if [ $(grep -c $START .voltha/ports) -eq 0 ]; then
195 break
196 fi
197 START=$(expr $START + 1)
198 done
199 DELTA=$(expr $START - 81)
200 ONOS_API_PORT=${START}81
201 ONOS_SSH_PORT=${START}01
202 VOLTHA_API_PORT=5$(expr 55 + $DELTA)55
203 VOLTHA_SSH_PORT=$(expr 50 + $DELTA)22
204 VOLTHA_ETCD_PORT=$(expr 23 + $DELTA)79
Test User01ed0642019-07-03 20:17:06 +0000205else
David Bainbridge0774b232019-08-02 06:37:19 +0000206 VALUES=$(echo $HAVE | sed -e 's/\s//g' | cut -d= -f2)
207 ONOS_API_PORT=$(echo $VALUES | cut -d, -f1)
208 ONOS_SSH_PORT=$(echo $VALUES | cut -d, -f2)
209 VOLTHA_API_PORT=$(echo $VALUES | cut -d, -f3)
210 VOLTHA_SSH_PORT=$(echo $VALUES | cut -d, -f4)
211 VOLTHA_ETCD_PORT=$(echo $VALUES | cut -d, -f5)
Test User01ed0642019-07-03 20:17:06 +0000212fi
213
David Bainbridge0774b232019-08-02 06:37:19 +0000214PORTTMP=$(mktemp -u)
215cat .voltha/ports | grep -v $NAME > $PORTTMP
216echo "$NAME=$ONOS_API_PORT,$ONOS_SSH_PORT,$VOLTHA_API_PORT,$VOLTHA_SSH_PORT,$VOLTHA_ETCD_PORT" >> $PORTTMP
217cp $PORTTMP .voltha/ports
218rm -f $PORTTMP
219
David Bainbridge01294952019-07-30 19:33:45 +0000220if [ "$WITH_TP" == "yes" ]; then
221 SADIS_VER=3.1.0
222 OLT_VER=3.0.1
223 AAA_VER=1.9.0
224 DHCP_VER=1.6.0
225else
226 SADIS_VER=2.2.0
227 OLT_VER=2.1.0
228 AAA_VER=1.8.0
229 DHCP_VER=1.5.0
230fi
David Bainbridge0774b232019-08-02 06:37:19 +0000231export ONOS_API_PORT ONOS_SSH_PORT SADIS_VER OLT_VER AAA_VER DHCP_VER
David Bainbridge01294952019-07-30 19:33:45 +0000232
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700233spin() {
Test Userd87942b2019-07-03 07:20:24 +0000234 PARTS="\
235 \xe2\xa2\x8e\xe2\xa1\xb0 \
236 \xe2\xa2\x8e\xe2\xa1\xa1 \
237 \xe2\xa2\x8e\xe2\xa1\x91 \
238 \xe2\xa2\x8e\xe2\xa0\xb1 \
239 \xe2\xa0\x8e\xe2\xa1\xb1 \
240 \xe2\xa2\x8a\xe2\xa1\xb1 \
241 \xe2\xa2\x8c\xe2\xa1\xb1 \
242 \xe2\xa2\x86\xe2\xa1\xb1 \
243 "
244 IDX=1
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700245 tput civis
246 while true; do
Test Userd87942b2019-07-03 07:20:24 +0000247 C=$(echo $PARTS | cut '-d ' -f $IDX)
248 echo -en "$C"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700249 IDX=$(expr $IDX + 1)
Test Userd87942b2019-07-03 07:20:24 +0000250 if [ $IDX -gt 8 ]; then
251 IDX=1
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700252 fi
253 sleep .15
254 echo -en "\r"
255 done
256}
257
Test Userd87942b2019-07-03 07:20:24 +0000258SPIN_PARTS="\
259 \xe2\xa2\x8e\xe2\xa1\xb0 \
260 \xe2\xa2\x8e\xe2\xa1\xa1 \
261 \xe2\xa2\x8e\xe2\xa1\x91 \
262 \xe2\xa2\x8e\xe2\xa0\xb1 \
263 \xe2\xa0\x8e\xe2\xa1\xb1 \
264 \xe2\xa2\x8a\xe2\xa1\xb1 \
265 \xe2\xa2\x8c\xe2\xa1\xb1 \
266 \xe2\xa2\x86\xe2\xa1\xb1 \
267 "
268IDX=1
269NOT_VERIFIED="\xe2\x9c\x97\x20"
270VERIFIED="\xe2\x9c\x93\x20"
Test Userb5712372019-07-03 21:52:17 +0000271HELM="\xE2\x8E\x88"
272OLD_KEY="\xF0\x9F\x97\x9D"
273BIRD="\xF0\x9F\x90\xA6"
274HIGH_VOLTAGE="\xE2\x9A\xA1"
275PLUG="\xF0\x9F\xa7\xa9"
276RESTART="\xf0\x9f\x94\x84"
277FORWARD="\xE2\x87\xA8"
278INSTALL="\xF0\x9F\x8F\x97"
279STOP="\xf0\x9f\x9b\x91"
280GO="\xf0\x9f\x9a\x80"
281DOWNLOAD="\xf0\x9f\x93\xa5"
282GEAR="\xe2\x9a\x99"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700283NO_ENTRY="\xe2\x9b\x94"
David Bainbridge5b7b96b2019-07-25 20:29:13 +0000284LOCK="\xf0\x9f\x94\x92"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700285
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700286bspin() {
287 tput civis
Test Userd87942b2019-07-03 07:20:24 +0000288 IDX=1
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700289 local INDENT=
290 if [ "$1" == "-" ]; then
291 INDENT=" "
292 shift
293 fi
Test Userd87942b2019-07-03 07:20:24 +0000294 echo -en "$INDENT $*"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700295}
296
297sspin() {
298 local INDENT=
299 if [ "$1" == "-" ]; then
300 INDENT=" "
301 shift
302 fi
Test Userd87942b2019-07-03 07:20:24 +0000303 C=$(echo $SPIN_PARTS | cut '-d ' -f $IDX)
304 echo -en "\r$INDENT$C $*"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700305 IDX=$(expr $IDX + 1)
Test Userd87942b2019-07-03 07:20:24 +0000306 if [ $IDX -gt 8 ]; then
307 IDX=1
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700308 fi
309}
310
311espin() {
312 local INDENT=
313 if [ "$1" == "-" ]; then
314 INDENT=" "
315 shift
316 fi
317 echo -e "\r$INDENT$*"
318 tput cnorm
319}
320
David Bainbridgeac7f8072019-08-01 22:15:33 +0000321if [ "$1" == "get" -a "$2" == "voltconfig" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000322 echo "$HOME/.volt/config-$NAME"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000323 exit
324fi
325
326if [ $# -ne 1 -o $(echo ":up:down:dump:" | grep -c ":$1:") -ne 1 ]; then
327 >&2 echo "What wouild you like to do today:"
328 >&2 echo " up - bring up voltha"
329 >&2 echo " down - tear down voltha"
330 >&2 echo " dump - create a debug dump of running system"
331 exit 1
332fi
333
334if [ "$1" == "down" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000335 echo "Tearing down voltha cluster $NAME"
336 LOG="down-$NAME.log"
337 echo $(date -u +"%Y%m%dT%H%M%SZ") >$LOG
David Bainbridgeac7f8072019-08-01 22:15:33 +0000338 if [ $DEPLOY_K8S == "yes" ]; then
339 if [ -x ./bin/kind ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000340 bspin "Delete Kubernetes Kind Cluster"
341 (set -x; ./bin/kind delete cluster --name voltha-$NAME >>$LOG 2>&1) >>$LOG 2>&1
342 espin $VERIFIED
David Bainbridgeac7f8072019-08-01 22:15:33 +0000343 else
David Bainbridge0774b232019-08-02 06:37:19 +0000344 espin "$NO_ENTRY Delete Kubernetes Kind Cluster: kind command not found"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000345 fi
346 else
347 EXISTS=$(helm list -q)
348 EXPECT="etcd-operator onos open-olt open-onu sim voltha bbsim radius"
David Bainbridge0774b232019-08-02 06:37:19 +0000349 bspin "Remove Helm Deployments"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000350 for i in $EXISTS; do
351 if [ $(echo $EXPECT | grep -c $i) -eq 1 ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000352 sspin "Remove Helm Deployments: $i$CEOL"
353 (set -x; ./bin/helm delete --purge $i >>$LOG 2>&1) >>$LOG 2>&1
David Bainbridgeac7f8072019-08-01 22:15:33 +0000354 fi
355 done
David Bainbridge0774b232019-08-02 06:37:19 +0000356 espin "$VERIFIED Remove Helm Deployments$CEOL"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000357 fi
David Bainbridge0774b232019-08-02 06:37:19 +0000358 bspin "Remove port-forwards: onos-ui-$NAME"
359 for i in $(screen -ls | grep onos-ui-$NAME | awk '{print $1}'); do
360 sspin
361 (set -x; screen -X -S $i quit >>$LOG 2>&1) >>$LOG 2>&1
362 done
363 sspin "Remove port-forwards: onos-ssh-$NAME$CEOL"
364 for i in $(screen -ls | grep onos-ssh-$NAME | awk '{print $1}'); do
365 sspin
366 (set -x; screen -X -S $i quit >>$LOG 2>&1) >>$LOG 2>&1
367 done
368 sspin "Remove port-forwards: voltha-api-$NAME$CEOL"
369 for i in $(screen -ls | grep voltha-api-$NAME | awk '{print $1}'); do
370 sspin
371 (set -x; screen -X -S $i quit >>$LOG 2>&1) >>$LOG 2>&1
372 done
373 sspin "Remove port-forwards: voltha-ssh-$NAME$CEOL"
374 for i in $(screen -ls | grep voltha-ssh-$NAME | awk '{print $1}'); do
375 sspin
376 (set -x; screen -X -S $i quit >>$LOG 2>&1) >>$LOG 2>&1
377 done
378 sspin "Remove port-forwards: voltha-etcd-$NAME$CEOL"
379 for i in $(screen -ls | grep voltha-etcd-$NAME | awk '{print $1}'); do
380 sspin
381 (set -x; screen -X -S $i quit >>$LOG 2>&1) >>$LOG 2>&1
382 done
383 espin "$VERIFIED Remove port-forwards$CEOL"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000384 exit
385fi
386
387if [ "$1" == "dump" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000388 LOG="dump-$NAME.log"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000389 TS=$(date -u +"%Y%m%dT%H%M%SZ")
390 WORK=$(mktemp -u -d)
David Bainbridge0774b232019-08-02 06:37:19 +0000391 DATA=$WORK/voltha-debug-dump-$NAME-$TS
David Bainbridgeac7f8072019-08-01 22:15:33 +0000392 mkdir -p $DATA
393 echo $TS > $LOG
David Bainbridge0774b232019-08-02 06:37:19 +0000394 echo -e "Capturing debug dump to voltha-debug-dump-$NAME-$TS.tgz"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000395 bspin - "Copy install log"
David Bainbridge0774b232019-08-02 06:37:19 +0000396 if [ -f install-$NAME.log ]; then
397 (set -x; cp install-$NAME.log $DATA/install-$NAME.log) >>$LOG 2>&1
David Bainbridgeac7f8072019-08-01 22:15:33 +0000398 espin - $VERIFIED
399 else
David Bainbridge0774b232019-08-02 06:37:19 +0000400 espin - "$NO_ENTRY Copy install log: install-$NAME.log not found"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000401 fi
402 bspin - "Dumping Kubernetes PODs"
403 (set -x; kubectl get --all-namespaces pods >> $DATA/all-pods.txt 2>&1) >>$LOG 2>&1
404 espin - $VERIFIED
405 bspin - "Dumping Kubernetes SERVICEs"
406 (set -x; kubectl get --all-namespaces svc >> $DATA/all-services.txt 2>&1) >>$LOG 2>&1
407 espin - $VERIFIED
408 bspin - "Dumping Kubernetes EVENTs"
409 (set -x; kubectl get --all-namespaces events >> $DATA/all-events.txt 2>&1) >>$LOG 2>&1
410 espin - $VERIFIED
411 bspin - "Dumping VOLTHA POD details"
412 PODS=$(kubectl get -n voltha pod -o name)
413 for POD in $PODS; do
414 sspin - "Dumping VOLTHA POD details: $POD$CEOL"
415 mkdir -p $DATA/$POD
416 (set -x; kubectl describe -n voltha $POD >> $DATA/$POD/describe.txt 2>&1) >>$LOG 2>&1
417 sspin - "Dumping VOLTHA POD details: $POD"
418 (set -x; kubectl logs -n voltha --all-containers --previous $LOG_ARGS $POD >> $DATA/$POD/logs-previous.txt 2>&1) >>$LOG 2>&1
419 sspin - "Dumping VOLTHA POD details: $POD"
420 (set -x; kubectl logs -n voltha --all-containers $LOG_ARGS $POD >> $DATA/$POD/logs-current.txt 2>&1) >>$LOG 2>&1
421 sspin - "Dumping VOLTHA POD details: $POD"
422 done
423 espin - "$VERIFIED Dumping VOLTHA POD details$CEOL"
424 bspin - "Dumping ETCD"
425 if [ "$(which etcdctl) X" != " X" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000426 (set -x; ETCDCTL_API=3 etcdctl --endpoints localhost:$VOLTHA_ETCD_PORT get --prefix service/voltha | hexdump -C >> $DATA/etcd.hex 2>&1) >>$LOG 2>&1
David Bainbridgeac7f8072019-08-01 22:15:33 +0000427 espin - $VERIFIED
428 else
429 espin - "$NO_ENTRY Dumping ETCD: etcdctl command not available"
430 fi
David Bainbridge0774b232019-08-02 06:37:19 +0000431 bspin - "Creating compressed TAR: voltha-debug-dump-$NAME-$TS.tgz"
432 (set -x; tar -C $WORK -zcf voltha-debug-dump-$NAME-$TS.tgz ./voltha-debug-dump-$NAME-$TS) >>$LOG 2>&1
David Bainbridgeac7f8072019-08-01 22:15:33 +0000433 espin - $VERIFIED
434 bspin - "Cleanup"
435 (set -x; rm -rf $WORK) >>$LOG 2>&1
436 espin - $VERIFIED
David Bainbridge0774b232019-08-02 06:37:19 +0000437 bspin - "$(ls -l voltha-debug-dump-$NAME-$TS.tgz)"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000438 espin - $VERIFIED
439 exit
440fi
441
442
David Bainbridge0774b232019-08-02 06:37:19 +0000443LOG="install-$NAME.log"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000444date > $LOG
David Bainbridge0774b232019-08-02 06:37:19 +0000445echo "PORTS=$ONOS_API_PORT,$ONOS_SSH_PORT,$VOLTHA_API_PORT,$VOLTHA_SSH_PORT,$VOLTHA_ETCD_PORT" >> $LOG
David Bainbridgeac7f8072019-08-01 22:15:33 +0000446
447# Output install options to log
448echo "OPTIONS" >> $LOG
David Bainbridge0774b232019-08-02 06:37:19 +0000449ALL_OPTIONS="NAME TYPE WITH_BBSIM WITH_RADIUS WITH_ONOS WITH_TP JUST_K8S DEPLOY_K8S \
David Bainbridgeac7f8072019-08-01 22:15:33 +0000450 SKIP_RESTART_API INSTALL_KUBECTL INSTALL_HELM USE_GO VOLTHA_LOG_LEVEL \
451 VOLTHA_CHART VOLTHA_ADAPTER_SIM_CHART VOLTHA_ADAPTER_OPEN_OLT_CHART \
David Bainbridge0774b232019-08-02 06:37:19 +0000452 VOLTHA_ADAPTER_OPEN_ONU_CHART SADIS_VER OLT_VER AAA_VER DHCP_VER \
453 ONOS_API_PORT ONOS_SSH_PORT VOLTHA_API_PORT VOLTHA_SSH_PORT VOLTHA_ETCD_PORT"
David Bainbridgeac7f8072019-08-01 22:15:33 +0000454for O in $ALL_OPTIONS; do
455 VAL=$(eval echo \$$O)
456 if [ $O == "USE_GO" ]; then
457 VAL="$(echo $VAL| test $(grep -c true) -eq 1 && echo yes || echo no)"
458 fi
459 if [ ! -z "$VAL" ]; then
460 printf " %-30s = %s\n" $O $VAL >> $LOG
461 fi
462done
463
464
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700465count_pods() {
466 local NAMESPACE=$1; shift
467 local PODS=$(kubectl -n $NAMESPACE get pod -o go-template="{{range .items}}{{.metadata.name}}/{{.status.phase}}/_{{range .status.containerStatuses}}{{.ready}}_{{end}} {{end}}")
468 local COUNT=0
469 local PATTERNS=$*
470 for POD in $PODS; do
471 local NAME=$(echo $POD | cut -d/ -f 1)
472 local STATE=$(echo $POD | cut -d/ -f 2)
473 local CONTAINERS=$(echo $POD | cut -d/ -f 3 | sed -e 's/_/ /g')
474 if [ "$STATE" == "Running" ]; then
475 local TOTAL=$(echo $CONTAINERS | wc -w)
476 local FOUND=$(echo $CONTAINERS | grep -o true | wc -l)
477 if [ $TOTAL -eq $FOUND ]; then
478 for PATTERN in $PATTERNS; do
479 if [[ $NAME =~ $PATTERN ]]; then
480 COUNT=$(expr $COUNT + 1)
481 fi
482 done
483 fi
484 fi
485 done
486 echo $COUNT
487}
488
489wait_for_pods() {
490 local INDENT=
491 if [ "$1" == "-" ]; then
492 INDENT=$1; shift
493 fi
494 local NAMESPACE=$1; shift
495 local EXPECT=$1; shift
496 local RETRY=$1; shift
497 local MESSAGE=$1; shift
498 local PATTERNS=$*
499 local HAVE=$(count_pods $NAMESPACE $PATTERNS)
500 COUNT=$(expr 300 / 15)
501 bspin $INDENT $MESSAGE
502 sspin $INDENT
503 if [ $HAVE -ne $EXPECT ]; then
504 while [ $HAVE -ne $EXPECT ]; do
505 sspin $INDENT
506 COUNT=$(expr $COUNT - 1)
507 if [ $COUNT -eq 0 ]; then
508 HAVE=$(count_pods $NAMESPACE $PATTERNS)
509 COUNT=$(expr 300 / 15)
510 fi
511 sleep .15
512 done
513 fi
514 espin $INDENT $VERIFIED
515 if [ $HAVE -ne $EXPECT ]; then
516 return 1
517 fi
518 return 0
519}
520
521helm_install() {
522 local INDENT=
523 if [ "$1" == "-" ]; then
524 INDENT=$1; shift
525 fi
526 local NAMESPACE=$1; shift
David Bainbridge0774b232019-08-02 06:37:19 +0000527 local INAME=$1; shift
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700528 local CHART=$1; shift
529 local MESSAGE=$*
530
531 COUNT=$(expr 300 / 15)
532 bspin $INDENT $MESSAGE
David Bainbridge458bb662019-08-02 20:04:23 +0000533 (set -x; helm install -f $NAME-values.yaml --set use_go=$USE_GO --set defaults.log_level=$VOLTHA_LOG_LEVEL --namespace $NAMESPACE --name $INAME $EXTRA_HELM_FLAGS $CHART >>$LOG 2>&1) >>$LOG 2>&1
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700534 SUCCESS=$?
535 while [ $SUCCESS -ne 0 ]; do
536 sspin $INDENT
537 COUNT=$(expr $COUNT - 1)
538 if [ $COUNT -eq 0 ]; then
David Bainbridge458bb662019-08-02 20:04:23 +0000539 (set -x; helm install -f $NAME-values.yaml --set use_go=$USE_GO --set defaults.log_level=$VOLTHA_LOG_LEVEL --namespace $NAMESPACE --name $INAME $EXTRA_HELM_FLAGS $CHART >>$LOG 2>&1) >>$LOG 2>&1
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700540 COUNT=$(expr 300 / 15)
541 fi
542 sleep .15
543 done
544 espin $INDENT $VERIFIED
545}
546
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700547echo "INSTALL TYPE: $TYPE" >> $LOG
548
549bspin "Verify GOPATH"
550export GOPATH=$(pwd)
Test User3d7ad8e2019-07-03 06:15:44 +0000551mkdir -p $GOPATH/bin
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700552espin $VERIFIED
553
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700554if [ "$INSTALL_KUBECTL" == "no" ]; then
555 bspin "Skip kubectl install"
556 espin $NO_ENTRY
Test Userc13bdc92019-07-03 20:57:49 +0000557else
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700558 bspin "Verify kubectl $HELM"
559 if [ -x $GOPATH/bin/kubectl ]; then
560 espin $VERIFIED
561 else
562 espin $NOT_VERIFIED
563 bspin - "Download and install Kubernetes/kubectl $DOWNLOAD"
564 (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
565 (set -x; chmod 755 $GOPATH/bin/kubectl >>$LOG 2>&1) >>$LOG 2>&1
566 espin - $VERIFIED
567 fi
Test Userc13bdc92019-07-03 20:57:49 +0000568fi
569
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700570if [ "$DEPLOY_K8S" == "no" ]; then
571 bspin "Skip Kubernetes/Kind Deployment"
572 espin $NO_ENTRY
573else
Test Userba1e7e72019-07-10 22:27:54 +0000574 bspin "Verify Kubernetes/Kind $HELM"
575 if [ -x $GOPATH/bin/kind ]; then
576 espin $VERIFIED
577 else
578 espin $NOT_VERIFIED
579 bspin - "Download and install Kubernetes/kind $DOWNLOAD"
David Bainbridge9e2a6662019-07-11 17:07:57 +0000580 (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 +0000581 (set -x; chmod 755 $GOPATH/bin/kind >>$LOG 2>&1) >>$LOG 2>&1
582 espin - $VERIFIED
583 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700584fi
585
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700586if [ "$INSTALL_HELM" == "no" ]; then
587 bspin "Skip Helm Install"
588 espin $NO_ENTRY
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700589else
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700590 bspin "Verify Helm $HELM"
591 if [ -x $GOPATH/bin/helm ]; then
592 espin $VERIFIED
593 else
594 espin $NOT_VERIFIED
595 bspin - "Download and install Helm $DOWNLOAD"
596 (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
597 espin - $VERIFIED
598 fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700599fi
600
Test Userb5712372019-07-03 21:52:17 +0000601bspin "Verify voltctl $HIGH_VOLTAGE"
Test User3d7ad8e2019-07-03 06:15:44 +0000602if [ -x $GOPATH/bin/voltctl ]; then
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700603 espin $VERIFIED
604else
605 espin $NOT_VERIFIED
Test Userb5712372019-07-03 21:52:17 +0000606 bspin - "Download and build voltctl $DOWNLOAD"
Test Userba1e7e72019-07-10 22:27:54 +0000607 (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 +0000608 (set -x; chmod 755 $GOPATH/bin/voltctl >>$LOG 2>&1) >>$LOG 2>&1
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700609 espin - $VERIFIED
610fi
611
612bspin "Verify command PATH"
Test Userba1e7e72019-07-10 22:27:54 +0000613export PATH=$GOPATH/bin:$PATH
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700614espin $VERIFIED
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700615
Test Userba1e7e72019-07-10 22:27:54 +0000616if [ "$DEPLOY_K8S" == "yes" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000617 HAVE=$(kind get clusters | grep -c voltha-$NAME)
Test Userba1e7e72019-07-10 22:27:54 +0000618 bspin "Verify Kubernetes/Kind Cluster"
619 sspin
620 if [ $HAVE -eq 0 ]; then
David Bainbridge491b1bd2019-07-11 17:53:11 +0000621 espin $NOT_VERIFIED
622 bspin - "Verify cluster configuration"
David Bainbridge0774b232019-08-02 06:37:19 +0000623 if [ ! -r ./$NAME-cluster.cfg ]; then
David Bainbridge491b1bd2019-07-11 17:53:11 +0000624 espin - $NOT_VERIFIED
David Bainbridge0774b232019-08-02 06:37:19 +0000625 bspin - "Download cluster configuration: $TYPE-cluster.cfg to $NAME-cluster.cfg $DOWNLOAD"
626 (set -x; curl -o ./$NAME-cluster.cfg -sSL https://raw.githubusercontent.com/ciena/kind-voltha/master/$TYPE-cluster.cfg >>$LOG 2>&1) >>$LOG 2>&1
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700627 espin - $VERIFIED
628 else
629 espin - $VERIFIED
630 fi
David Bainbridge0774b232019-08-02 06:37:19 +0000631 kind create cluster --name voltha-$NAME --config $NAME-cluster.cfg
David Bainbridge491b1bd2019-07-11 17:53:11 +0000632 else
633 espin $VERIFIED
Test Userba1e7e72019-07-10 22:27:54 +0000634 fi
635
David Bainbridge0774b232019-08-02 06:37:19 +0000636 export KUBECONFIG="$(kind get kubeconfig-path --name="voltha-$NAME")"
Test Userba1e7e72019-07-10 22:27:54 +0000637 P="coredns-.* \
David Bainbridge0774b232019-08-02 06:37:19 +0000638 etcd-voltha-$NAME-control-plane \
Test Userba1e7e72019-07-10 22:27:54 +0000639 kindnet-.* \
David Bainbridge0774b232019-08-02 06:37:19 +0000640 kube-apiserver-voltha-$NAME-control-plane \
641 kube-controller-manager-voltha-$NAME-control-plane \
Test Userba1e7e72019-07-10 22:27:54 +0000642 kube-proxy-.* \
David Bainbridge0774b232019-08-02 06:37:19 +0000643 kube-scheduler-voltha-$NAME-control-plane"
Test Userba1e7e72019-07-10 22:27:54 +0000644
645 EXPECT=$(test "$TYPE" == "minimal" && echo "12" || echo "14")
646 wait_for_pods - "kube-system" $EXPECT -1 "Waiting for system PODs to start" $P
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700647fi
648
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700649COUNT=$(count_pods "kube-system" "tiller-deploy-.*")
650bspin "Verify Helm"
Test Userba1e7e72019-07-10 22:27:54 +0000651if [ $COUNT -ne 1 ]; then
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700652 espin $NOT_VERIFIED
Test Userb5712372019-07-03 21:52:17 +0000653 echo -e "Configuring Helm $GEAR"
David K. Bainbridge0e89cb92019-07-17 11:30:10 -0700654 if [ "$INSTALL_HELM" == "no" ]; then
655 bspin - "Skip Helm/Tiller Initialization"
656 espin - $NO_ENTRY
657 else
658 bspin - "Initialize Helm"
659 (set -x; helm init --upgrade >>$LOG 2>&1) >>$LOG 2>&1
660 espin - $VERIFIED
661 wait_for_pods - "kube-system" 1 -1 "Waiting for Tiller POD to start" "tiller-deploy-.*"
662 fi
Test Userb5712372019-07-03 21:52:17 +0000663 bspin - "Add Google Incubator repository to Helm"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700664 (set -x; helm repo add incubator https://kubernetes-charts-incubator.storage.googleapis.com >>$LOG 2>&1) >>$LOG 2>&1
665 espin - $VERIFIED
Test Userba1e7e72019-07-10 22:27:54 +0000666
667 # HACK (sort-of) - the config for tiller is about to be patched, which will
668 # cause the tiller pod to be recreated. This can sometimes cause a timing
669 # issue with the "wait_for_pods" call on tiller as it may incorrectly
670 # identify the running/ready tiller pod that is soon to be terminated as
671 # what it is waiting for. To avoid this issue we do a clean scale down and
672 # scale up of the pod so the script controlls when it should be expecting
673 # things
674 (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 -0700675
Test Userb5712372019-07-03 21:52:17 +0000676 bspin - "Add Google Stable repository to Helm"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700677 (set -x; helm repo add stable https://kubernetes-charts.storage.googleapis.com >>$LOG 2>&1) >>$LOG 2>&1
678 espin - $VERIFIED
Test Userb5712372019-07-03 21:52:17 +0000679 bspin - "Add ONF repository to Helm"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700680 (set -x; helm repo add onf https://charts.opencord.org >>$LOG 2>&1) >>$LOG 2>&1
681 espin - $VERIFIED
Test Userb5712372019-07-03 21:52:17 +0000682 bspin - "Update Helm repository cache"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700683 (set -x; helm repo update >>$LOG 2>&1) >>$LOG 2>&1
684 espin - $VERIFIED
685
686 # Create and k8s service account so that Helm can create pods
Test Userb5712372019-07-03 21:52:17 +0000687 bspin - "Create Tiller ServiceAccount"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700688 (set -x; kubectl create serviceaccount --namespace kube-system tiller >>$LOG 2>&1) >>$LOG 2>&1
689 espin - $VERIFIED
Test Userb5712372019-07-03 21:52:17 +0000690 bspin - "Create Tiller ClusterRoleBinding"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700691 (set -x; kubectl create clusterrolebinding tiller-cluster-rule --clusterrole=cluster-admin --serviceaccount=kube-system:tiller >>$LOG 2>&1) >>$LOG 2>&1
692 espin - $VERIFIED
Test Userb5712372019-07-03 21:52:17 +0000693 bspin - "Update Tiller Manifest"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700694 (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 +0000695
696 # HACK (sort-of) - part to, spin it back up
697 (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 -0700698 espin - $VERIFIED
699else
700 espin $VERIFIED
701fi
Test Userb5712372019-07-03 21:52:17 +0000702wait_for_pods - "kube-system" 1 -1 "Waiting for Tiller POD to start" "tiller-deploy-.*"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700703
David Bainbridge0774b232019-08-02 06:37:19 +0000704bspin "Verify Helm values file: $NAME-values.yaml"
705if [ ! -r "./$NAME-values.yaml" ]; then
Test Userba1e7e72019-07-10 22:27:54 +0000706 espin $NOT_VERIFIED
David Bainbridge0774b232019-08-02 06:37:19 +0000707 bspin - "Download Helm values file: $TYPE-values.yaml to $NAME-values.yaml $DOWNLOAD"
708 (set -x; curl -o ./$NAME-values.yaml -sSL https://raw.githubusercontent.com/ciena/kind-voltha/master/$TYPE-values.yaml >>$LOG 2>&1) >>$LOG 2>&1
Test Userba1e7e72019-07-10 22:27:54 +0000709 espin - $VERIFIED
710else
711 espin $VERIFIED
712fi
713
714if [ "$JUST_K8S" == "yes" ]; then
715 echo "Environment deployed, not deploying VOLTHA artifacts as requested. Good bye."
716 echo ""
717 echo "Please issue the following commands in your terminal to ensure that you" | tee -a $LOG
718 echo "are accessing the correct Kubernetes/Kind cluster as well as have the " | tee -a $LOG
719 echo "tools required by VOLTHA in your command path. " | tee -a $LOG
720 echo "" | tee -a $LOG
721 echo -en $BOLD
722 if [ $DEPLOY_K8S == "yes" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000723 echo "export KUBECONFIG=\"\$(./bin/kind get kubeconfig-path --name=\"voltha-$NAME\")\"" | tee -a $LOG
Test Userba1e7e72019-07-10 22:27:54 +0000724 fi
725 echo "export PATH=$GOPATH/bin:\$PATH" | tee -a $LOG
726 echo -en $NORMAL
727 echo "" | tee -a $LOG
728 echo "Thank you for choosing kind-voltha for you quick cluster needs." | tee -a $LOG
729 exit 0
730fi
731
Test Userb5712372019-07-03 21:52:17 +0000732bspin "Verify ETCD Operator $OLD_KEY"
Test User7d866122019-07-09 17:52:35 +0000733if [ $(helm list --deployed --short --namespace voltha "^etcd-operator\$" | wc -l) -ne 1 ]; then
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700734 espin $NOT_VERIFIED
735 helm_install - voltha etcd-operator stable/etcd-operator "Install ETCD Operator"
736else
737 espin $VERIFIED
738fi
Test User01ed0642019-07-03 20:17:06 +0000739EXPECT=$(test "$TYPE" == "minimal" && echo "1" || echo "3")
Test Userb5712372019-07-03 21:52:17 +0000740wait_for_pods - "voltha" $EXPECT -1 "Waiting for ETCD Operator to start" "etcd-operator-.*"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700741
David Bainbridgeb270c202019-07-26 01:44:42 +0000742if [ $WITH_ONOS == "yes" ]; then
743 bspin "Verify ONOS installed $BIRD"
744 if [ $(helm list --deployed --short --namespace default "^onos\$" | wc -l) -ne 1 ]; then
745 espin $NOT_VERIFIED
746 helm_install - default onos onf/onos "Install ONOS"
747 else
748 espin $VERIFIED
749 fi
750 wait_for_pods - "default" 1 -1 "Waiting for ONOS to start" "onos-.*"
751
752 bspin - "Forward ONOS API port $FORWARD"
David Bainbridge0774b232019-08-02 06:37:19 +0000753 for i in $(screen -ls | grep onos-ui-$NAME | awk '{print $1}'); do
David Bainbridge82bd1212019-07-29 19:19:31 +0000754 (set -x; screen -X -S $i quit >>$LOG 2>&1) >>$LOG 2>&1
755 done
David Bainbridge0774b232019-08-02 06:37:19 +0000756 (set -x; screen -dmS onos-ui-$NAME bash -c "while true; do kubectl port-forward service/onos-ui $ONOS_API_PORT:8181; done" >>$LOG 2>&1) >>$LOG 2>&1
David Bainbridgeb270c202019-07-26 01:44:42 +0000757 espin - $VERIFIED
758 bspin - "Forward ONOS SSH port $FORWARD"
David Bainbridge0774b232019-08-02 06:37:19 +0000759 for i in $(screen -ls | grep onos-ssh-$NAME | awk '{print $1}'); do
David Bainbridge82bd1212019-07-29 19:19:31 +0000760 (set -x; screen -X -S $i quit >>$LOG 2>&1) >>$LOG 2>&1
761 done
David Bainbridge0774b232019-08-02 06:37:19 +0000762 (set -x; screen -dmS onos-ssh-$NAME bash -c "while true; do kubectl port-forward service/onos-ssh $ONOS_SSH_PORT:8101; done" >>$LOG 2>&1) >>$LOG 2>&1
David Bainbridgeb270c202019-07-26 01:44:42 +0000763 espin - $VERIFIED
764 if [ ! -x ./onos-files/install-onos-applications.sh ]; then
765 bspin - "Verify or download ONOS configuration support files $DOWNLOAD"
766 (set -x; mkdir -p ./onos-files >>$LOG 2>&1) >>$LOG 2>&1
767 for i in dhcp-to-controller-flow.json install-onos-applications.sh olt-onos-enableExtraneousRules.json olt-onos-netcfg.json olt-onos-olt-settings.json radius-config.json; do
768 if [ ! -r ./onos-files/$i ]; then
769 (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
770 fi
771 done
772 (set -x; chmod 755 ./onos-files/install-onos-applications.sh >>$LOG 2>&1) >>$LOG 2>&1
773 espin - $VERIFIED
774 fi
775
776 bspin - "Install required ONOS applications $INSTALL"
777 (set -x; ./onos-files/install-onos-applications.sh >>$LOG 2>&1) >>$LOG 2>&1
Test Userba1e7e72019-07-10 22:27:54 +0000778 espin - $VERIFIED
779fi
780
Test Userb5712372019-07-03 21:52:17 +0000781bspin "Verify VOLTHA installed $HIGH_VOLTAGE"
Test User7d866122019-07-09 17:52:35 +0000782if [ $(helm list --deployed --short --namespace voltha "^voltha\$" | wc -l) -ne 1 ]; then
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700783 espin $NOT_VERIFIED
David Bainbridgee10f6d52019-07-25 00:28:13 +0000784 helm_install - voltha voltha $VOLTHA_CHART "Install VOLTHA Core"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700785else
786 espin $VERIFIED
787fi
Test Userba1e7e72019-07-10 22:27:54 +0000788
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700789VOLTHA="ofagent-.* \
790 ro-core.* \
791 rw-core.* \
792 voltha-api-server-.* \
793 voltha-cli-server-.* \
794 voltha-etcd-cluster-.* \
795 voltha-kafka-.* \
796 voltha-zookeeper-.*"
Test User01ed0642019-07-03 20:17:06 +0000797EXPECT=$(test "$TYPE" == "minimal" && echo "9" || echo "11")
Test Userb5712372019-07-03 21:52:17 +0000798wait_for_pods - "voltha" $EXPECT -1 "Waiting for VOLTHA Core to start" $VOLTHA
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700799
Test Userb5712372019-07-03 21:52:17 +0000800echo -e "Verify Adapters $PLUG"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700801bspin - "Verify Simulated Adapters installed"
Test User7d866122019-07-09 17:52:35 +0000802if [ $(helm list --deployed --short --namespace voltha "^sim\$" | wc -l) -ne 1 ]; then
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700803 espin - $NOT_VERIFIED
David Bainbridgee10f6d52019-07-25 00:28:13 +0000804 helm_install - voltha sim $VOLTHA_ADAPTER_SIM_CHART "Install Simulated Adapters"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700805else
806 espin - $VERIFIED
807fi
808
809bspin - "Verify OpenOLT Adapter installed"
Test User7d866122019-07-09 17:52:35 +0000810if [ $(helm list --deployed --short --namespace voltha "^open-olt\$" | wc -l) -ne 1 ]; then
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700811 espin - $NOT_VERIFIED
David Bainbridgee10f6d52019-07-25 00:28:13 +0000812 helm_install - voltha open-olt $VOLTHA_ADAPTER_OPEN_OLT_CHART "Install OpenOLT Adapter"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700813else
814 espin - $VERIFIED
815fi
816bspin - "Verify OpenONU Adapter installed"
Test User7d866122019-07-09 17:52:35 +0000817if [ $(helm list --deployed --short --namespace voltha "^open-onu\$" | wc -l) -ne 1 ]; then
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700818 espin - $NOT_VERIFIED
David Bainbridgee10f6d52019-07-25 00:28:13 +0000819 helm_install - voltha open-onu $VOLTHA_ADAPTER_OPEN_ONU_CHART "Install OpenONU Adapter"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700820else
821 espin - $VERIFIED
822fi
823
824ADAPTERS="adapter-.*"
Test Userb5712372019-07-03 21:52:17 +0000825wait_for_pods - "voltha" 4 -1 "Waiting for adapters to start" $ADAPTERS
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700826
Test User7d866122019-07-09 17:52:35 +0000827if [ $WITH_BBSIM == "yes" ]; then
828 echo -e "Verify BBSIM $PLUG"
David Bainbridge5b7b96b2019-07-25 20:29:13 +0000829 bspin - "Verify BBSIM Installed"
Test User7d866122019-07-09 17:52:35 +0000830 if [ $(helm list --deployed --short --namespace voltha "^bbsim\$" | wc -l) -ne 1 ]; then
831 espin - $NOT_VERIFIED
832 helm_install - voltha bbsim onf/bbsim "Install BBSIM"
833 else
834 espin - $VERIFIED
835 fi
836 wait_for_pods - "voltha" 1 -1 "Waiting for BBSIM to start" "bbsim-.*"
837fi
838
David Bainbridge5b7b96b2019-07-25 20:29:13 +0000839if [ $WITH_RADIUS == "yes" ]; then
840 echo -e "Verify RADIUS $LOCK"
841 bspin - "Verify RADIUS Installed"
842 if [ $(helm list --deployed --short --namespace voltha "^radius\$" | wc -l) -ne 1 ]; then
843 espin - $NOT_VERIFIED
844 helm_install - voltha radius onf/freeradius "Install RADIUS"
845 else
846 espin - $VERIFIED
847 fi
848 wait_for_pods - "voltha" 1 -1 "Waiting for RADIUS to start" "radius-.*"
849fi
850
David Bainbridgee10f6d52019-07-25 00:28:13 +0000851if [ $SKIP_RESTART_API == "no" ]; then
852 echo -e "Restart VOLTHA API $RESTART"
853 API="voltha-api-server-.* ofagent-.*"
854 (set -x; kubectl scale --replicas=0 deployment -n voltha voltha-api-server ofagent >>$LOG 2>&1) >>$LOG 2>&1
855 wait_for_pods - "voltha" 0 -1 "Wait for API to stop $STOP" $API
856 (set -x; kubectl scale --replicas=1 deployment -n voltha voltha-api-server ofagent >>$LOG 2>&1) >>$LOG 2>&1
857 wait_for_pods - "voltha" 2 -1 "Wait for API to re-start $GO" $API
858else
859 bspin "Skip VOLTHA API Restart"
860 espin $NO_ENTRY
861fi
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700862
Test Userb5712372019-07-03 21:52:17 +0000863bspin - "Forward VOLTHA API port $FORWARD"
David Bainbridge0774b232019-08-02 06:37:19 +0000864for i in $(screen -ls | grep voltha-api-$NAME | awk '{print $1}'); do
David Bainbridge82bd1212019-07-29 19:19:31 +0000865 (set -x; screen -X -S $i quit >>$LOG 2>&1) >>$LOG 2>&1
866done
David Bainbridge0774b232019-08-02 06:37:19 +0000867(set -x; screen -dmS voltha-api-$NAME bash -c "while true; do kubectl port-forward -n voltha service/voltha-api $VOLTHA_API_PORT:55555; done" >>$LOG 2>&1) >>$LOG 2>&1
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700868espin - $VERIFIED
Test Userb5712372019-07-03 21:52:17 +0000869bspin - "Forward VOLTHA SSH port $FORWARD"
David Bainbridge0774b232019-08-02 06:37:19 +0000870for i in $(screen -ls | grep voltha-ssh-$NAME | awk '{print $1}'); do
David Bainbridge82bd1212019-07-29 19:19:31 +0000871 (set -x; screen -X -S $i quit >>$LOG 2>&1) >>$LOG 2>&1
872done
David Bainbridge0774b232019-08-02 06:37:19 +0000873(set -x; screen -dmS voltha-ssh-$NAME bash -c "while true; do kubectl port-forward -n voltha service/voltha-cli $VOLTHA_SSH_PORT:5022; done" >>$LOG 2>&1) >>$LOG 2>&1
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700874espin - $VERIFIED
David Bainbridgeac7f8072019-08-01 22:15:33 +0000875bspin - "Forward VOLTHA ETCD port $FORWARD"
David Bainbridge0774b232019-08-02 06:37:19 +0000876for i in $(screen -ls | grep voltha-etcd-$NAME | awk '{print $1}'); do
David Bainbridgeac7f8072019-08-01 22:15:33 +0000877 (set -x; screen -X -S $i quit >>$LOG 2>&1) >>$LOG 2>&1
878done
David Bainbridge0774b232019-08-02 06:37:19 +0000879(set -x; screen -dmS voltha-etcd-$NAME bash -c "while true; do kubectl port-forward -n voltha service/voltha-etcd-cluster-client $VOLTHA_ETCD_PORT:2379; done" >>$LOG 2>&1) >>$LOG 2>&1
David Bainbridgeac7f8072019-08-01 22:15:33 +0000880espin - $VERIFIED
Test User3d7ad8e2019-07-03 06:15:44 +0000881
David Bainbridgeb270c202019-07-26 01:44:42 +0000882if [ $WITH_ONOS == "yes" -a $WITH_RADIUS == "yes" ]; then
David Bainbridge5b7b96b2019-07-25 20:29:13 +0000883 bspin "Configure ONOS RADIUS Connection $GEAR"
884 (set -x; cat onos-files/radius-config.json | sed -e "s/:RADIUS_IP:/$(kubectl -n voltha get service/radius -o jsonpath={.spec.clusterIP})/g" | curl -XPOST -sSL http://karaf:karaf@localhost:8181/onos/v1/network/configuration -H Content-type:application/json -d@- >>$LOG 2>&1) >>$LOG 2>&1
885 espin $VERIFIED
886fi
887
888bspin "Create voltctl configuration file"
Test User3d7ad8e2019-07-03 06:15:44 +0000889(set -x; mkdir -p $HOME/.volt >>$LOG 2>&1) >>$LOG 2>&1
David Bainbridge0774b232019-08-02 06:37:19 +0000890(set -x; voltctl -a v2 -s localhost:$VOLTHA_API_PORT config > $HOME/.volt/config-$NAME 2>>$LOG) >>$LOG 2>&1
David Bainbridge5b7b96b2019-07-25 20:29:13 +0000891espin $VERIFIED
Test User08ebbd92019-07-03 17:15:39 +0000892
David Bainbridge0774b232019-08-02 06:37:19 +0000893if [ ! -f "$NAME-env.sh" ]; then
894 touch $NAME-env.sh
David Bainbridgeb07fdf72019-07-29 22:51:40 +0000895fi
896
David Bainbridge596f30d2019-07-30 17:07:59 +0000897for O in $ALL_OPTIONS; do
898 VAL=$(eval echo \$$O)
899 if [ $O == "USE_GO" ]; then
900 VAL="$(echo $VAL| test $(grep -c true) -eq 1 && echo yes || echo no)"
901 fi
David Bainbridge0774b232019-08-02 06:37:19 +0000902 if [ ! -z "$VAL" -a $(grep -c "^export $O=" $NAME-env.sh) -eq 0 ]; then
903 echo "export $O=\"$(eval echo \$$O)\"" >> $NAME-env.sh
David Bainbridgeb07fdf72019-07-29 22:51:40 +0000904 fi
905done
906
David Bainbridge0774b232019-08-02 06:37:19 +0000907if [ $DEPLOY_K8S == "yes" -a $(grep -c "^export KUBECONFIG=" $NAME-env.sh) -eq 0 ]; then
908 echo "export KUBECONFIG=\"$(./bin/kind get kubeconfig-path --name=voltha-$NAME)\"" >> $NAME-env.sh
David Bainbridgeb07fdf72019-07-29 22:51:40 +0000909fi
910
David Bainbridge0774b232019-08-02 06:37:19 +0000911if [ $(grep -c "^export VOLTCONFIG=" $NAME-env.sh) -eq 0 ]; then
912 echo "export VOLTCONFIG=\"$HOME/.volt/config-$NAME\"" >> $NAME-env.sh
David Bainbridgeb07fdf72019-07-29 22:51:40 +0000913fi
914
David Bainbridge0774b232019-08-02 06:37:19 +0000915if [ $(grep -c "^export PATH=" $NAME-env.sh) -eq 0 ]; then
916 echo "export PATH=\"$GOPATH/bin:\$PATH\"" >> $NAME-env.sh
David Bainbridgeb07fdf72019-07-29 22:51:40 +0000917fi
918
Test User7d866122019-07-09 17:52:35 +0000919echo ""
Test User08ebbd92019-07-03 17:15:39 +0000920echo "Please issue the following commands in your terminal to ensure that you" | tee -a $LOG
921echo "are accessing the correct Kubernetes/Kind cluster as well as have the " | tee -a $LOG
922echo "tools required by VOLTHA in your command path. " | tee -a $LOG
923echo "" | tee -a $LOG
Test User7d866122019-07-09 17:52:35 +0000924echo -en $BOLD
Test Userba1e7e72019-07-10 22:27:54 +0000925if [ $DEPLOY_K8S == "yes" ]; then
David Bainbridge0774b232019-08-02 06:37:19 +0000926 echo "export KUBECONFIG=\"\$(./bin/kind get kubeconfig-path --name=\"voltha-$NAME\")\"" | tee -a $LOG
Test Userba1e7e72019-07-10 22:27:54 +0000927fi
David Bainbridge0774b232019-08-02 06:37:19 +0000928echo "export VOLTCONFIG=\"$HOME/.volt/config-$NAME\"" | tee -a $LOG
Test Userba1e7e72019-07-10 22:27:54 +0000929echo "export PATH=$GOPATH/bin:\$PATH" | tee -a $LOG
Test User7d866122019-07-09 17:52:35 +0000930echo -en $NORMAL
Test User08ebbd92019-07-03 17:15:39 +0000931echo "" | tee -a $LOG
932echo "Thank you for choosing kind-voltha for you quick cluster needs." | tee -a $LOG
933