blob: 216b65871d5cbad0640f8a8680de8ddc7c3a33b3 [file] [log] [blame]
David K. Bainbridgeb7285432019-07-02 22:05:24 -07001#!/usr/bin/env bash
2# 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 User3d7ad8e2019-07-03 06:15:44 +000027TYPE=${TYPE:-minimal}
28# Only minimal cluster works in this script currently
29TYPE=minimal
30
David K. Bainbridgeb7285432019-07-02 22:05:24 -070031if [ $# -ne 1 -o $(echo ":up:down:" | grep -c ":$1:") -ne 1 ]; then
32 >&2 echo "up or down?"
33 exit 1
34fi
35
36if [ "$1" == "down" ]; then
Test Userd87942b2019-07-03 07:20:24 +000037 exec ./bin/kind delete cluster --name voltha-$TYPE
David K. Bainbridgeb7285432019-07-02 22:05:24 -070038 exit
39fi
40
41LOG="install.log"
42date > $LOG
43
44spin() {
Test Userd87942b2019-07-03 07:20:24 +000045 PARTS="\
46 \xe2\xa2\x8e\xe2\xa1\xb0 \
47 \xe2\xa2\x8e\xe2\xa1\xa1 \
48 \xe2\xa2\x8e\xe2\xa1\x91 \
49 \xe2\xa2\x8e\xe2\xa0\xb1 \
50 \xe2\xa0\x8e\xe2\xa1\xb1 \
51 \xe2\xa2\x8a\xe2\xa1\xb1 \
52 \xe2\xa2\x8c\xe2\xa1\xb1 \
53 \xe2\xa2\x86\xe2\xa1\xb1 \
54 "
55 IDX=1
David K. Bainbridgeb7285432019-07-02 22:05:24 -070056 tput civis
57 while true; do
Test Userd87942b2019-07-03 07:20:24 +000058 C=$(echo $PARTS | cut '-d ' -f $IDX)
59 echo -en "$C"
David K. Bainbridgeb7285432019-07-02 22:05:24 -070060 IDX=$(expr $IDX + 1)
Test Userd87942b2019-07-03 07:20:24 +000061 if [ $IDX -gt 8 ]; then
62 IDX=1
David K. Bainbridgeb7285432019-07-02 22:05:24 -070063 fi
64 sleep .15
65 echo -en "\r"
66 done
67}
68
Test Userd87942b2019-07-03 07:20:24 +000069SPIN_PARTS="\
70 \xe2\xa2\x8e\xe2\xa1\xb0 \
71 \xe2\xa2\x8e\xe2\xa1\xa1 \
72 \xe2\xa2\x8e\xe2\xa1\x91 \
73 \xe2\xa2\x8e\xe2\xa0\xb1 \
74 \xe2\xa0\x8e\xe2\xa1\xb1 \
75 \xe2\xa2\x8a\xe2\xa1\xb1 \
76 \xe2\xa2\x8c\xe2\xa1\xb1 \
77 \xe2\xa2\x86\xe2\xa1\xb1 \
78 "
79IDX=1
80NOT_VERIFIED="\xe2\x9c\x97\x20"
81VERIFIED="\xe2\x9c\x93\x20"
David K. Bainbridgeb7285432019-07-02 22:05:24 -070082bspin() {
83 tput civis
Test Userd87942b2019-07-03 07:20:24 +000084 IDX=1
David K. Bainbridgeb7285432019-07-02 22:05:24 -070085 local INDENT=
86 if [ "$1" == "-" ]; then
87 INDENT=" "
88 shift
89 fi
Test Userd87942b2019-07-03 07:20:24 +000090 echo -en "$INDENT $*"
David K. Bainbridgeb7285432019-07-02 22:05:24 -070091}
92
93sspin() {
94 local INDENT=
95 if [ "$1" == "-" ]; then
96 INDENT=" "
97 shift
98 fi
Test Userd87942b2019-07-03 07:20:24 +000099 C=$(echo $SPIN_PARTS | cut '-d ' -f $IDX)
100 echo -en "\r$INDENT$C $*"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700101 IDX=$(expr $IDX + 1)
Test Userd87942b2019-07-03 07:20:24 +0000102 if [ $IDX -gt 8 ]; then
103 IDX=1
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700104 fi
105}
106
107espin() {
108 local INDENT=
109 if [ "$1" == "-" ]; then
110 INDENT=" "
111 shift
112 fi
113 echo -e "\r$INDENT$*"
114 tput cnorm
115}
116
117count_pods() {
118 local NAMESPACE=$1; shift
119 local PODS=$(kubectl -n $NAMESPACE get pod -o go-template="{{range .items}}{{.metadata.name}}/{{.status.phase}}/_{{range .status.containerStatuses}}{{.ready}}_{{end}} {{end}}")
120 local COUNT=0
121 local PATTERNS=$*
122 for POD in $PODS; do
123 local NAME=$(echo $POD | cut -d/ -f 1)
124 local STATE=$(echo $POD | cut -d/ -f 2)
125 local CONTAINERS=$(echo $POD | cut -d/ -f 3 | sed -e 's/_/ /g')
126 if [ "$STATE" == "Running" ]; then
127 local TOTAL=$(echo $CONTAINERS | wc -w)
128 local FOUND=$(echo $CONTAINERS | grep -o true | wc -l)
129 if [ $TOTAL -eq $FOUND ]; then
130 for PATTERN in $PATTERNS; do
131 if [[ $NAME =~ $PATTERN ]]; then
132 COUNT=$(expr $COUNT + 1)
133 fi
134 done
135 fi
136 fi
137 done
138 echo $COUNT
139}
140
141wait_for_pods() {
142 local INDENT=
143 if [ "$1" == "-" ]; then
144 INDENT=$1; shift
145 fi
146 local NAMESPACE=$1; shift
147 local EXPECT=$1; shift
148 local RETRY=$1; shift
149 local MESSAGE=$1; shift
150 local PATTERNS=$*
151 local HAVE=$(count_pods $NAMESPACE $PATTERNS)
152 COUNT=$(expr 300 / 15)
153 bspin $INDENT $MESSAGE
154 sspin $INDENT
155 if [ $HAVE -ne $EXPECT ]; then
156 while [ $HAVE -ne $EXPECT ]; do
157 sspin $INDENT
158 COUNT=$(expr $COUNT - 1)
159 if [ $COUNT -eq 0 ]; then
160 HAVE=$(count_pods $NAMESPACE $PATTERNS)
161 COUNT=$(expr 300 / 15)
162 fi
163 sleep .15
164 done
165 fi
166 espin $INDENT $VERIFIED
167 if [ $HAVE -ne $EXPECT ]; then
168 return 1
169 fi
170 return 0
171}
172
173helm_install() {
174 local INDENT=
175 if [ "$1" == "-" ]; then
176 INDENT=$1; shift
177 fi
178 local NAMESPACE=$1; shift
179 local NAME=$1; shift
180 local CHART=$1; shift
181 local MESSAGE=$*
182
183 COUNT=$(expr 300 / 15)
184 bspin $INDENT $MESSAGE
185 (set -x; helm install -f $TYPE-values.yaml --namespace $NAMESPACE --name $NAME $CHART >>$LOG 2>&1) >>$LOG 2>&1
186 SUCCESS=$?
187 while [ $SUCCESS -ne 0 ]; do
188 sspin $INDENT
189 COUNT=$(expr $COUNT - 1)
190 if [ $COUNT -eq 0 ]; then
191 (set -x; helm install -f $TYPE-values.yaml --namespace $NAMESPACE --name $NAME $CHART >>$LOG 2>&1) >>$LOG 2>&1
192 COUNT=$(expr 300 / 15)
193 fi
194 sleep .15
195 done
196 espin $INDENT $VERIFIED
197}
198
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700199echo "INSTALL TYPE: $TYPE" >> $LOG
200
201bspin "Verify GOPATH"
202export GOPATH=$(pwd)
Test User3d7ad8e2019-07-03 06:15:44 +0000203mkdir -p $GOPATH/bin
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700204espin $VERIFIED
205
206bspin "Verify Kubernetes/Kind"
Test User3d7ad8e2019-07-03 06:15:44 +0000207if [ -x $GOPATH/bin/kind ]; then
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700208 espin $VERIFIED
209else
210 espin $NOT_VERIFIED
211 bspin - "Download and build Kubernetes/Kind"
212 (set -x; rm -rf $GOPATH/go.mod $GOPATH/go.sum >>$LOG 2>&1) >>$LOG 2>&1
Test User3d7ad8e2019-07-03 06:15:44 +0000213 (set -x; curl -o $GOPATH/bin/kind -sSL https://github.com/kubernetes-sigs/kind/releases/download/v0.4.0/kind-$(go env GOHOSTOS)-$(go env GOARCH) >>$LOG 2>&1) >>$LOG 2>&1
Test User7c2be412019-07-03 06:20:30 +0000214 (set -x; chmod 755 $GOPATH/bin/kind >>$LOG 2>&1) >>$LOG 2>&1
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700215 espin - $VERIFIED
216fi
217
218bspin "Verify Helm"
Test User3d7ad8e2019-07-03 06:15:44 +0000219if [ -x $GOPATH/bin/helm ]; then
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700220 espin $VERIFIED
221else
222 espin $NOT_VERIFIED
223 bspin - "Download and install Helm"
224 (set -x; rm -rf $GOPATH/go.mod $GOPATH/go.sum >>$LOG 2>&1) >>$LOG 2>&1
225 (set -x; curl -L https://git.io/get_helm.sh | HELM_INSTALL_DIR=$(go env GOPATH)/bin bash >>$LOG 2>&1) >>$LOG 2>&1
226 espin - $VERIFIED
227fi
228
229bspin "Verify voltctl"
Test User3d7ad8e2019-07-03 06:15:44 +0000230if [ -x $GOPATH/bin/voltctl ]; then
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700231 espin $VERIFIED
232else
233 espin $NOT_VERIFIED
234 bspin - "Download and build voltctl"
235 (set -x; rm -rf $GOPATH/go.mod $GOPATH/go.sum >>$LOG 2>&1) >>$LOG 2>&1
236 (set -x; go get github.com/ciena/voltctl/cmd/voltctl >>$LOG 2>&1) >>$LOG 2>&1
237 espin - $VERIFIED
238fi
239
240bspin "Verify command PATH"
241export PATH=$(go env GOPATH)/bin:$PATH
242espin $VERIFIED
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700243
244HAVE=$(kind get clusters | grep -c voltha-$TYPE)
245bspin "Verify Kubernetes/Kind Cluster"
246sspin
247if [ $HAVE -eq 0 ]; then
248 espin $NOT_VERIFIED
249 kind create cluster --name voltha-$TYPE --config $TYPE-cluster.cfg
250else
251 espin $VERIFIED
252fi
253
254export KUBECONFIG="$(kind get kubeconfig-path --name="voltha-$TYPE")"
255P="coredns-.* \
256 etcd-voltha-$TYPE-control-plane \
257 kindnet-.* \
258 kube-apiserver-voltha-$TYPE-control-plane \
259 kube-controller-manager-voltha-$TYPE-control-plane \
260 kube-proxy-.* \
261 kube-scheduler-voltha-$TYPE-control-plane"
262
263wait_for_pods - "kube-system" 12 -1 "Waiting for system PODs to start..." $P
264
265COUNT=$(count_pods "kube-system" "tiller-deploy-.*")
266bspin "Verify Helm"
267if [ $(count_pods "kube-system" "tiller-deploy-.*") -ne 1 ]; then
268 espin $NOT_VERIFIED
Test Userd87942b2019-07-03 07:20:24 +0000269 echo "Configuring Helm ..."
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700270 bspin - "Initialize Helm"
271 (set -x; helm init --upgrade >>$LOG 2>&1) >>$LOG 2>&1
272 espin - $VERIFIED
273 bspin - "Add Google Incubator repository to Helm ..."
274 (set -x; helm repo add incubator https://kubernetes-charts-incubator.storage.googleapis.com >>$LOG 2>&1) >>$LOG 2>&1
275 espin - $VERIFIED
276
277 bspin - "Add Google Stable repository to Helm ..."
278 (set -x; helm repo add stable https://kubernetes-charts.storage.googleapis.com >>$LOG 2>&1) >>$LOG 2>&1
279 espin - $VERIFIED
280 bspin - "Add ONF repository to Helm ..."
281 (set -x; helm repo add onf https://charts.opencord.org >>$LOG 2>&1) >>$LOG 2>&1
282 espin - $VERIFIED
283 bspin - "Update Helm repository cache ..."
284 (set -x; helm repo update >>$LOG 2>&1) >>$LOG 2>&1
285 espin - $VERIFIED
286
287 # Create and k8s service account so that Helm can create pods
288 bspin - "Create Tiller ServiceAccount ..."
289 (set -x; kubectl create serviceaccount --namespace kube-system tiller >>$LOG 2>&1) >>$LOG 2>&1
290 espin - $VERIFIED
291 bspin - "Create Tiller ClusterRoleBinding ..."
292 (set -x; kubectl create clusterrolebinding tiller-cluster-rule --clusterrole=cluster-admin --serviceaccount=kube-system:tiller >>$LOG 2>&1) >>$LOG 2>&1
293 espin - $VERIFIED
294 bspin - "Update Tiller Manifest ..."
295 (set -x; kubectl patch deploy --namespace kube-system tiller-deploy -p '{"spec":{"template":{"spec":{"serviceAccount":"tiller"}}}}' >>$LOG 2>&1) >>$LOG 2>&1
296 espin - $VERIFIED
297else
298 espin $VERIFIED
299fi
300wait_for_pods - "kube-system" 1 -1 "Waiting for Tiller POD to start..." "tiller-deploy-.*"
301
302bspin "Verify ETCD Operator"
303if [ $(helm list etcd-operator | grep -c DEPLOYED) -ne 1 ]; then
304 espin $NOT_VERIFIED
305 helm_install - voltha etcd-operator stable/etcd-operator "Install ETCD Operator"
306else
307 espin $VERIFIED
308fi
309wait_for_pods - "voltha" 1 -1 "Waiting for ETCD Operator to start..." "etcd-operator-.*"
310
311bspin "Verify ONOS installed"
312if [ $(helm list onos | grep -c DEPLOYED) -ne 1 ]; then
313 espin $NOT_VERIFIED
314 helm_install - default onos onf/onos "Install ONOS"
315else
316 espin $VERIFIED
317fi
318wait_for_pods - "default" 1 -1 "Waiting for ONOS to start..." "onos-.*"
319
320bspin - "Forward ONOS API port"
321(set -x; screen -p 0 -X -S onos-ui stuff $'\003' >>$LOG 2>&1) >>$LOG 2>&1
322(set -x; screen -dmS onos-ui kubectl port-forward service/onos-ui 8181:8181 >>$LOG 2>&1) >>$LOG 2>&1
323espin - $VERIFIED
324bspin - "Forward ONOS SSH port"
325(set -x; screen -p 0 -X -S onos-ssh stuff $'\003' >>$LOG 2>&1) >>$LOG 2>&1
326(set -x; screen -dmS onos-ssh kubectl port-forward service/onos-ssh 8101:8101 >>$LOG 2>&1) >>$LOG 2>&1
327espin - $VERIFIED
328bspin - "Install required ONOS applications"
329(set -x; ./onos-files/install-onos-applications.sh >>$LOG 2>&1) >>$LOG 2>&1
330espin - $VERIFIED
331
332bspin "Verify VOLTHA installed"
333if [ $(helm list voltha | grep -c DEPLOYED) -ne 1 ]; then
334 espin $NOT_VERIFIED
Test Userd87942b2019-07-03 07:20:24 +0000335 helm_install - voltha voltha onf/voltha "Install VOLTHA Core"
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700336else
337 espin $VERIFIED
338fi
339VOLTHA="ofagent-.* \
340 ro-core.* \
341 rw-core.* \
342 voltha-api-server-.* \
343 voltha-cli-server-.* \
344 voltha-etcd-cluster-.* \
345 voltha-kafka-.* \
346 voltha-zookeeper-.*"
Test Userd87942b2019-07-03 07:20:24 +0000347wait_for_pods - "voltha" 9 -1 "Waiting for VOLTHA Core to start..." $VOLTHA
David K. Bainbridgeb7285432019-07-02 22:05:24 -0700348
349echo "Verify Adapters"
350bspin - "Verify Simulated Adapters installed"
351if [ $(helm list sim | grep -c DEPLOYED) -ne 1 ]; then
352 espin - $NOT_VERIFIED
353 helm_install - voltha sim onf/voltha-adapter-simulated "Install Simulated Adapters"
354else
355 espin - $VERIFIED
356fi
357
358bspin - "Verify OpenOLT Adapter installed"
359if [ $(helm list open-olt | grep -c DEPLOYED) -ne 1 ]; then
360 espin - $NOT_VERIFIED
361 helm_install - voltha open-olt onf/voltha-adapter-openolt "Install OpenOLT Adapter"
362else
363 espin - $VERIFIED
364fi
365bspin - "Verify OpenONU Adapter installed"
366if [ $(helm list open-onu | grep -c DEPLOYED) -ne 1 ]; then
367 espin - $NOT_VERIFIED
368 helm_install - voltha open-onu onf/voltha-adapter-openonu "Install OpenONU Adapter"
369else
370 espin - $VERIFIED
371fi
372
373ADAPTERS="adapter-.*"
374wait_for_pods - "voltha" 4 -1 "Waiting for adapters to start..." $ADAPTERS
375
376echo "Restart VOLTHA API"
377API="voltha-api-server-.* ofagent-.*"
378(set -x; kubectl scale --replicas=0 deployment -n voltha voltha-api-server ofagent >>$LOG 2>&1) >>$LOG 2>&1
379wait_for_pods - "voltha" 0 -1 "Wait for API to stop" $API
380(set -x; kubectl scale --replicas=1 deployment -n voltha voltha-api-server ofagent >>$LOG 2>&1) >>$LOG 2>&1
381wait_for_pods - "voltha" 2 -1 "Wait for API to re-start ..." $API
382
383bspin - "Forward VOLTHA API port"
384(set -x; screen -p 0 -X -S voltha-api stuff $'\003' >>$LOG 2>&1) >>$LOG 2>&1
385(set -x; screen -dmS voltha-api kubectl port-forward -n voltha service/voltha-api 55555:55555 >>$LOG 2>&1) >>$LOG 2>&1
386espin - $VERIFIED
387bspin - "Forward VOLTHA SSH port"
388(set -x; screen -p 0 -X -S voltha-ssh stuff $'\003' 2>/dev/null >/dev/null >>$LOG 2>&1) >>$LOG 2>&1
389(set -x; screen -dmS voltha-ssh kubectl port-forward -n voltha service/voltha-cli 5022:5022 >>$LOG 2>&1) >>$LOG 2>&1
390espin - $VERIFIED
Test User3d7ad8e2019-07-03 06:15:44 +0000391
392bspin - "Create voltctl configuration file"
393(set -x; mkdir -p $HOME/.volt >>$LOG 2>&1) >>$LOG 2>&1
394(set -x; voltctl -a v2 -s localhost:55555 config > $HOME/.volt/config 2>>$LOG) >>$LOG 2>&1
395espin - $VERIFIED