3 # Copyright 2018 Huawei Technologies Co., Ltd.
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
9 # http://www.apache.org/licenses/LICENSE-2.0
13 portal_hostname="portal.api.simpledemo.onap.org"
16 if [ -z "$WORKSPACE" ]; then
17 export WORKSPACE=`git rev-parse --show-toplevel`
21 echo "Usage: $0 [ -n <number of VMs {2-15}> ][ -s <stack name> ][ -m <manifest> ][ -d <domain> ][ -r ][ -q ] <env>" 1>&2;
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;
34 while getopts ":n:s:d:m:rq" o; do
37 if [[ ${OPTARG} =~ ^[0-9]+$ ]];then
38 if [ ${OPTARG} -ge 2 -a ${OPTARG} -le 15 ]; then
48 if [[ ! ${OPTARG} =~ ^[0-9]+$ ]];then
55 if [[ ! ${OPTARG} =~ ^[0-9]+$ ]];then
56 portal_hostname=${OPTARG}
62 if [ -f $WORKSPACE/version-manifest/src/main/resources/${OPTARG} ]; then
63 docker_manifest=${OPTARG}
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
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
76 if [ $answer2 = "y" ] || [ $answer2 = "Y" ] || [ $answer2 = "yes" ] || [ $answer2 = "Yes"]; then
97 if [ "$#" -ne 1 ]; then
103 if [ ! -f $ENV_FILE ];then
104 echo ENV file does not exist or was not given
110 SSH_KEY=~/.ssh/onap_key
112 source $WORKSPACE/test/ete/scripts/install_openstack_cli.sh
114 #Use new encryption method
115 pushd $WORKSPACE/deployment/heat/onap-rke/scripts
117 SO_ENCRYPTION_KEY=aa3871669d893c7fb8abbcda31b88b4f
118 export OS_PASSWORD_ENCRYPTED=$(java Crypto "$OS_PASSWORD" "$SO_ENCRYPTION_KEY")
121 for n in $(seq 1 5); do
122 if [ $full_deletion = true ] ; then
123 $WORKSPACE/test/ete/scripts/teardown-onap.sh -n $stack_name -q
125 $WORKSPACE/test/ete/scripts/teardown-onap.sh -n $stack_name
128 cd $WORKSPACE/deployment/heat/onap-rke
129 envsubst < $ENV_FILE > $ENV_FILE~
130 if [ -z "$vm_num" ]; then
131 cp onap-oom.yaml onap-oom.yaml~
133 ./scripts/gen-onap-oom-yaml.sh $vm_num > onap-oom.yaml~
136 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 while [ "CREATE_IN_PROGRESS" == "$(openstack stack show -c stack_status -f value $stack_name)" ]; do
144 STATUS=$(openstack stack show -c stack_status -f value $stack_name)
146 if [ "CREATE_COMPLETE" != "$STATUS" ]; then
150 for i in $(seq 1 30); do
152 RANCHER_IP=$(openstack stack output show $stack_name rancher_vm_ip -c output_value -f value)
153 K8S_IP=$(openstack stack output show $stack_name k8s_01_vm_ip -c output_value -f value)
154 timeout 1 ping -c 1 "$RANCHER_IP" && break
157 timeout 1 ping -c 1 "$RANCHER_IP" && break
159 echo Error: OpenStack infrastructure issue: unable to reach rancher "$RANCHER_IP"
163 if ! timeout 1 ping -c 1 "$RANCHER_IP"; then
167 # wait until all k8s VMs have fully initialized
168 for VM_NAME in $(grep _vm: ./onap-oom.yaml~ | cut -d: -f1); do
170 VM_IP=$(openstack stack output show $stack_name ${VM_NAME}_ip -c output_value -f value)
172 until ssh -o StrictHostKeychecking=no -i $SSH_KEY ubuntu@$VM_IP ls -ad /dockerdata-nfs/.git; do
177 cat > ./cluster.yml~ <<EOF
178 # GENERATED for $stack_name
182 for VM_NAME in $(grep -E 'k8s_.+_vm:' ./onap-oom.yaml~ | cut -d: -f1); do
184 VM_IP=$(openstack stack output show $stack_name ${VM_NAME}_ip -c output_value -f value)
185 VM_PRIVATE_IP=$(openstack stack output show $stack_name ${VM_NAME}_private_ip -c output_value -f value)
186 VM_HOSTNAME=$stack_name-$(echo $VM_NAME | tr '_' '-' | cut -d- -f1,2)
187 cat >> ./cluster.yml~ <<EOF
190 internal_address: $VM_PRIVATE_IP
193 hostname_override: "$VM_HOSTNAME"
195 ssh_key_path: "$SSH_KEY"
199 for VM_NAME in $(grep -E 'orch_.+_vm:' ./onap-oom.yaml~ | cut -d: -f1); do
201 VM_IP=$(openstack stack output show $stack_name ${VM_NAME}_ip -c output_value -f value)
202 VM_PRIVATE_IP=$(openstack stack output show $stack_name ${VM_NAME}_private_ip -c output_value -f value)
203 VM_HOSTNAME=$stack_name-$(echo $VM_NAME | tr '_' '-' | cut -d- -f1,2)
204 cat >> ./cluster.yml~ <<EOF
207 internal_address: $VM_PRIVATE_IP
211 hostname_override: "$VM_HOSTNAME"
213 ssh_key_path: "$SSH_KEY"
217 DOCKER_PROXY=$(openstack stack output show $stack_name docker_proxy -c output_value -f value)
219 cat >> ./cluster.yml~ <<EOF
222 service_cluster_ip_range: 10.43.0.0/16
223 pod_security_policy: false
224 always_pull_images: false
226 cluster_cidr: 10.42.0.0/16
227 service_cluster_ip_range: 10.43.0.0/16
229 cluster_domain: cluster.local
230 cluster_dns_server: 10.43.0.10
236 ssh_key_path: "$SSH_KEY"
237 ssh_agent_auth: false
240 ignore_docker_version: false
241 kubernetes_version: "v1.13.4-rancher1-2"
245 cluster_name: "$stack_name"
253 cp ./cluster.yml~ ./target/cluster.yml
256 # spin up k8s with RKE
262 scp ./kube_config_cluster.yml root@$RANCHER_IP:/root/.kube/config
267 ssh -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)"