blob: 298e3e706418ed348f629543b8bef717032359c6 [file] [log] [blame]
Gary Wu950a3232019-03-26 13:08:29 -07001#!/bin/bash
2#
3# Copyright 2018 Huawei Technologies Co., Ltd.
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11
Gary Wu0bc69832019-03-27 13:58:46 -070012stack_name="onap"
Gary Wu950a3232019-03-26 13:08:29 -070013portal_hostname="portal.api.simpledemo.onap.org"
14full_deletion=false
15
16if [ -z "$WORKSPACE" ]; then
17 export WORKSPACE=`git rev-parse --show-toplevel`
18fi
19
20usage() {
21 echo "Usage: $0 [ -n <number of VMs {2-15}> ][ -s <stack name> ][ -m <manifest> ][ -d <domain> ][ -r ][ -q ] <env>" 1>&2;
22
23 echo "n: Set the number of VM's that will be installed. This number must be between 2 and 15" 1>&2;
24 echo "s: Set the name to be used for stack. This name will be used for naming of resources" 1>&2;
25 echo "d: Set the base domain name to be used in portal UI URLs" 1>&2;
26 echo "m: The docker manifest to apply; must be either \"docker-manifest-staging.csv\" or \"docker-manifest.csv\"." 1>&2;
27 echo "r: Delete all resources relating to ONAP within enviroment." 1>&2;
28 echo "q: Quiet Delete of all ONAP resources." 1>&2;
29
30 exit 1;
31}
32
33
34while getopts ":n:s:d:m:rq" o; do
35 case "${o}" in
36 n)
37 if [[ ${OPTARG} =~ ^[0-9]+$ ]];then
38 if [ ${OPTARG} -ge 2 -a ${OPTARG} -le 15 ]; then
39 vm_num=${OPTARG}
40 else
41 usage
42 fi
43 else
44 usage
45 fi
46 ;;
47 s)
48 if [[ ! ${OPTARG} =~ ^[0-9]+$ ]];then
49 stack_name=${OPTARG}
50 else
51 usage
52 fi
53 ;;
54 d)
55 if [[ ! ${OPTARG} =~ ^[0-9]+$ ]];then
56 portal_hostname=${OPTARG}
57 else
58 usage
59 fi
60 ;;
61 m)
62 if [ -f $WORKSPACE/version-manifest/src/main/resources/${OPTARG} ]; then
63 docker_manifest=${OPTARG}
64 else
65 usage
66 fi
67 ;;
68 r)
69 echo "The following command will delete all information relating to onap within your enviroment"
70 read -p "Are you certain this is what you want? (type y to confirm):" answer
71
72 if [ $answer = "y" ] || [ $answer = "Y" ] || [ $answer = "yes" ] || [ $answer = "Yes"]; then
73 echo "This may delete the work of other colleages within the same enviroment"
74 read -p "Are you certain this is what you want? (type y to confirm):" answer2
75
76 if [ $answer2 = "y" ] || [ $answer2 = "Y" ] || [ $answer2 = "yes" ] || [ $answer2 = "Yes"]; then
77 full_deletion=true
78 else
79 echo "Ending program"
80 exit 1
81 fi
82 else
83 echo "Ending program"
84 exit 1
85 fi
86 ;;
87 q)
88 full_deletion=true
89 ;;
90 *)
91 usage
92 ;;
93 esac
94done
95shift $((OPTIND-1))
96
97if [ "$#" -ne 1 ]; then
98 usage
99fi
100
101ENV_FILE=$1
102
103if [ ! -f $ENV_FILE ];then
104 echo ENV file does not exist or was not given
105 exit 1
106fi
107
108set -x
109
110SSH_KEY=~/.ssh/onap_key
111
112source $WORKSPACE/test/ete/scripts/install_openstack_cli.sh
113
Gary Wu28c30b52019-04-05 14:01:10 -0700114SO_ENCRYPTION_KEY=aa3871669d893c7fb8abbcda31b88b4f
115export OS_PASSWORD_ENCRYPTED_FOR_ROBOT=$(echo -n "$OS_PASSWORD" | openssl aes-128-ecb -e -K "$SO_ENCRYPTION_KEY" -nosalt | xxd -c 256 -p)
116
Gary Wu950a3232019-03-26 13:08:29 -0700117#Use new encryption method
118pushd $WORKSPACE/deployment/heat/onap-rke/scripts
119javac Crypto.java
Gary Wu28c30b52019-04-05 14:01:10 -0700120#SO_ENCRYPTION_KEY=aa3871669d893c7fb8abbcda31b88b4f
Gary Wu950a3232019-03-26 13:08:29 -0700121export OS_PASSWORD_ENCRYPTED=$(java Crypto "$OS_PASSWORD" "$SO_ENCRYPTION_KEY")
122popd
123
124for n in $(seq 1 5); do
125 if [ $full_deletion = true ] ; then
126 $WORKSPACE/test/ete/scripts/teardown-onap.sh -n $stack_name -q
127 else
128 $WORKSPACE/test/ete/scripts/teardown-onap.sh -n $stack_name
129 fi
130
131 cd $WORKSPACE/deployment/heat/onap-rke
132 envsubst < $ENV_FILE > $ENV_FILE~
133 if [ -z "$vm_num" ]; then
134 cp onap-oom.yaml onap-oom.yaml~
135 else
136 ./scripts/gen-onap-oom-yaml.sh $vm_num > onap-oom.yaml~
137 fi
138
139 if ! openstack stack create -t ./onap-oom.yaml~ -e $ENV_FILE~ $stack_name --parameter docker_manifest=$docker_manifest --parameter portal_hostname=$portal_hostname; then
140 break
141 fi
142
143 while [ "CREATE_IN_PROGRESS" == "$(openstack stack show -c stack_status -f value $stack_name)" ]; do
144 sleep 20
145 done
146
147 STATUS=$(openstack stack show -c stack_status -f value $stack_name)
148 echo $STATUS
149 if [ "CREATE_COMPLETE" != "$STATUS" ]; then
150 break
151 fi
152
153 for i in $(seq 1 30); do
154 sleep 30
155 RANCHER_IP=$(openstack stack output show $stack_name rancher_vm_ip -c output_value -f value)
156 K8S_IP=$(openstack stack output show $stack_name k8s_01_vm_ip -c output_value -f value)
157 timeout 1 ping -c 1 "$RANCHER_IP" && break
158 done
159
160 timeout 1 ping -c 1 "$RANCHER_IP" && break
161
162 echo Error: OpenStack infrastructure issue: unable to reach rancher "$RANCHER_IP"
163 sleep 10
164done
165
166if ! timeout 1 ping -c 1 "$RANCHER_IP"; then
167 exit 2
168fi
169
170# wait until all k8s VMs have fully initialized
171for VM_NAME in $(grep _vm: ./onap-oom.yaml~ | cut -d: -f1); do
172 echo $VM_NAME
173 VM_IP=$(openstack stack output show $stack_name ${VM_NAME}_ip -c output_value -f value)
174 ssh-keygen -R $VM_IP
175 until ssh -o StrictHostKeychecking=no -i $SSH_KEY ubuntu@$VM_IP ls -ad /dockerdata-nfs/.git; do
176 sleep 1m
177 done
178done
179
180cat > ./cluster.yml~ <<EOF
Gary Wu0bc69832019-03-27 13:58:46 -0700181# GENERATED for $stack_name
Gary Wu950a3232019-03-26 13:08:29 -0700182nodes:
183EOF
184
185for VM_NAME in $(grep -E 'k8s_.+_vm:' ./onap-oom.yaml~ | cut -d: -f1); do
186 echo $VM_NAME
187 VM_IP=$(openstack stack output show $stack_name ${VM_NAME}_ip -c output_value -f value)
188 VM_PRIVATE_IP=$(openstack stack output show $stack_name ${VM_NAME}_private_ip -c output_value -f value)
189 VM_HOSTNAME=$stack_name-$(echo $VM_NAME | tr '_' '-' | cut -d- -f1,2)
190 cat >> ./cluster.yml~ <<EOF
191- address: $VM_IP
192 port: "22"
193 internal_address: $VM_PRIVATE_IP
194 role:
195 - worker
196 hostname_override: "$VM_HOSTNAME"
197 user: ubuntu
Gary Wu0bc69832019-03-27 13:58:46 -0700198 ssh_key_path: "$SSH_KEY"
Gary Wu950a3232019-03-26 13:08:29 -0700199EOF
200done
201
202for VM_NAME in $(grep -E 'orch_.+_vm:' ./onap-oom.yaml~ | cut -d: -f1); do
203 echo $VM_NAME
204 VM_IP=$(openstack stack output show $stack_name ${VM_NAME}_ip -c output_value -f value)
205 VM_PRIVATE_IP=$(openstack stack output show $stack_name ${VM_NAME}_private_ip -c output_value -f value)
206 VM_HOSTNAME=$stack_name-$(echo $VM_NAME | tr '_' '-' | cut -d- -f1,2)
207 cat >> ./cluster.yml~ <<EOF
208- address: $VM_IP
209 port: "22"
210 internal_address: $VM_PRIVATE_IP
211 role:
212 - controlplane
213 - etcd
214 hostname_override: "$VM_HOSTNAME"
215 user: ubuntu
Gary Wu0bc69832019-03-27 13:58:46 -0700216 ssh_key_path: "$SSH_KEY"
Gary Wu950a3232019-03-26 13:08:29 -0700217EOF
218done
219
Gary Wu0bc69832019-03-27 13:58:46 -0700220DOCKER_PROXY=$(openstack stack output show $stack_name docker_proxy -c output_value -f value)
221
Gary Wu950a3232019-03-26 13:08:29 -0700222cat >> ./cluster.yml~ <<EOF
223services:
Gary Wu950a3232019-03-26 13:08:29 -0700224 kube-api:
Gary Wu950a3232019-03-26 13:08:29 -0700225 service_cluster_ip_range: 10.43.0.0/16
Gary Wu950a3232019-03-26 13:08:29 -0700226 pod_security_policy: false
227 always_pull_images: false
228 kube-controller:
Gary Wu950a3232019-03-26 13:08:29 -0700229 cluster_cidr: 10.42.0.0/16
230 service_cluster_ip_range: 10.43.0.0/16
Gary Wu950a3232019-03-26 13:08:29 -0700231 kubelet:
Gary Wu950a3232019-03-26 13:08:29 -0700232 cluster_domain: cluster.local
Gary Wu950a3232019-03-26 13:08:29 -0700233 cluster_dns_server: 10.43.0.10
234 fail_swap_on: false
Gary Wu950a3232019-03-26 13:08:29 -0700235network:
236 plugin: canal
Gary Wu950a3232019-03-26 13:08:29 -0700237authentication:
238 strategy: x509
Gary Wu0bc69832019-03-27 13:58:46 -0700239ssh_key_path: "$SSH_KEY"
Gary Wu950a3232019-03-26 13:08:29 -0700240ssh_agent_auth: false
241authorization:
242 mode: rbac
Gary Wu950a3232019-03-26 13:08:29 -0700243ignore_docker_version: false
Gary Wu0bc69832019-03-27 13:58:46 -0700244kubernetes_version: "v1.13.4-rancher1-2"
245private_registries:
246- url: $DOCKER_PROXY
247 is_default: true
Gary Wu950a3232019-03-26 13:08:29 -0700248cluster_name: "$stack_name"
Gary Wu950a3232019-03-26 13:08:29 -0700249restore:
250 restore: false
251 snapshot_name: ""
Gary Wu950a3232019-03-26 13:08:29 -0700252EOF
253
254rm -rf ./target
255mkdir -p ./target
256cp ./cluster.yml~ ./target/cluster.yml
257pushd ./target
258
259# spin up k8s with RKE
260until rke up; do
261 sleep 1m
262 rke remove
263done
264
265scp ./kube_config_cluster.yml root@$RANCHER_IP:/root/.kube/config
266popd
267
268
269sleep 2m
270ssh -o StrictHostKeychecking=no -i $SSH_KEY ubuntu@$RANCHER_IP "sed -u '/Cloud-init.*finished/q' <(tail -n+0 -f /var/log/cloud-init-output.log)"
271
Gary Wu950a3232019-03-26 13:08:29 -0700272exit 0