blob: c3a73c763da55a1af55e3f839337a64746a4a399 [file] [log] [blame]
eHanan97b7a9c2018-09-05 14:09:19 +01001#!/bin/bash
Gary Wua3fb86f2018-06-04 16:23:54 -07002#
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#
Gary Wucbddc2b2018-01-22 13:33:21 -080011
eHanan97b7a9c2018-09-05 14:09:19 +010012stack_name="oom"
eHanan58ccb9d2018-08-07 14:09:26 +010013full_deletion=false
14
Gary Wucbddc2b2018-01-22 13:33:21 -080015if [ -z "$WORKSPACE" ]; then
16 export WORKSPACE=`git rev-parse --show-toplevel`
17fi
18
eHanan97b7a9c2018-09-05 14:09:19 +010019usage() {
Gary Wu03e724f2018-09-07 22:03:48 -070020 echo "Usage: $0 [ -n <number of VMs {2-15}> ][ -s <stack name> ][ -m <manifest> ][ -r ][ -q ] <env>" 1>&2;
eHanan97b7a9c2018-09-05 14:09:19 +010021
22 echo "n: Set the number of VM's that will be installed. This number must be between 2 and 15" 1>&2;
23 echo "s: Set the name to be used for stack. This name will be used for naming of resources" 1>&2;
Gary Wu03e724f2018-09-07 22:03:48 -070024 echo "m: The docker manifest to apply; must be either \"docker-manifest-staging.csv\" or \"docker-manifest.csv\"." 1>&2;
eHanan97b7a9c2018-09-05 14:09:19 +010025 echo "r: Delete all resources relating to ONAP within enviroment." 1>&2;
26 echo "q: Quiet Delete of all ONAP resources." 1>&2;
27
28 exit 1;
29}
eHanan58ccb9d2018-08-07 14:09:26 +010030
Gary Wucbddc2b2018-01-22 13:33:21 -080031
Gary Wu03e724f2018-09-07 22:03:48 -070032while getopts ":n:s:m:rq" o; do
eHanan58ccb9d2018-08-07 14:09:26 +010033 case "${o}" in
eHanan97b7a9c2018-09-05 14:09:19 +010034 n)
35 if [[ ${OPTARG} =~ ^[0-9]+$ ]];then
36 if [ ${OPTARG} -ge 2 -a ${OPTARG} -le 15 ]; then
37 vm_num=${OPTARG}
38 else
39 usage
40 fi
41 else
42 usage
43 fi
44 ;;
45 s)
46 if [[ ! ${OPTARG} =~ ^[0-9]+$ ]];then
47 stack_name=${OPTARG}
48 else
49 usage
50 fi
51 ;;
Gary Wu03e724f2018-09-07 22:03:48 -070052 m)
53 if [ -f $WORKSPACE/version-manifest/src/main/resources/${OPTARG} ]; then
54 docker_manifest=${OPTARG}
55 else
56 usage
57 fi
58 ;;
eHanan58ccb9d2018-08-07 14:09:26 +010059 r)
60 echo "The following command will delete all information relating to onap within your enviroment"
61 read -p "Are you certain this is what you want? (type y to confirm):" answer
62
63 if [ $answer = "y" ] || [ $answer = "Y" ] || [ $answer = "yes" ] || [ $answer = "Yes"]; then
64 echo "This may delete the work of other colleages within the same enviroment"
65 read -p "Are you certain this is what you want? (type y to confirm):" answer2
Gary Wu87aa8b52018-08-09 08:10:24 -070066
eHanan58ccb9d2018-08-07 14:09:26 +010067 if [ $answer2 = "y" ] || [ $answer2 = "Y" ] || [ $answer2 = "yes" ] || [ $answer2 = "Yes"]; then
68 full_deletion=true
Gary Wu87aa8b52018-08-09 08:10:24 -070069 else
eHanan58ccb9d2018-08-07 14:09:26 +010070 echo "Ending program"
71 exit 1
72 fi
Gary Wu87aa8b52018-08-09 08:10:24 -070073 else
eHanan58ccb9d2018-08-07 14:09:26 +010074 echo "Ending program"
75 exit 1
76 fi
77 ;;
78 q)
79 full_deletion=true
80 ;;
81 *)
82 usage
83 ;;
84 esac
85done
86shift $((OPTIND-1))
87
Gary Wu87aa8b52018-08-09 08:10:24 -070088if [ "$#" -ne 1 ]; then
89 usage
90fi
91
92ENV_FILE=$1
93
eHanan97b7a9c2018-09-05 14:09:19 +010094if [ ! -f $ENV_FILE ];then
95 echo ENV file does not exist or was not given
96 exit 1
97fi
98
99set -x
100
Gary Wu0d28fe62018-05-24 20:54:28 -0700101SSH_KEY=~/.ssh/onap_key
102
Gary Wu808b13d2018-02-13 18:28:37 -0800103source $WORKSPACE/test/ete/scripts/install_openstack_cli.sh
104
Gary Wu11c98742018-05-02 16:19:04 -0700105SO_ENCRYPTION_KEY=aa3871669d893c7fb8abbcda31b88b4f
106export OS_PASSWORD_ENCRYPTED=$(echo -n "$OS_PASSWORD" | openssl aes-128-ecb -e -K "$SO_ENCRYPTION_KEY" -nosalt | xxd -c 256 -p)
107
Gary Wucbddc2b2018-01-22 13:33:21 -0800108for n in $(seq 1 5); do
Gary Wu87aa8b52018-08-09 08:10:24 -0700109 if [ $full_deletion = true ] ; then
eHanan97b7a9c2018-09-05 14:09:19 +0100110 $WORKSPACE/test/ete/scripts/teardown-onap.sh -n $stack_name -q
Gary Wu87aa8b52018-08-09 08:10:24 -0700111 else
eHanan97b7a9c2018-09-05 14:09:19 +0100112 $WORKSPACE/test/ete/scripts/teardown-onap.sh -n $stack_name
eHanan58ccb9d2018-08-07 14:09:26 +0100113 fi
Gary Wucbddc2b2018-01-22 13:33:21 -0800114
115 cd $WORKSPACE/deployment/heat/onap-oom
Gary Wu374498a2018-02-06 17:31:04 -0800116 envsubst < $ENV_FILE > $ENV_FILE~
eHanan97b7a9c2018-09-05 14:09:19 +0100117 if [ -z "$vm_num" ]; then
118 cp onap-oom.yaml onap-oom.yaml~
119 else
120 ./scripts/gen-onap-oom-yaml.sh $vm_num > onap-oom.yaml~
121 fi
Gary Wud2579972018-05-23 12:36:46 -0700122
Gary Wu03e724f2018-09-07 22:03:48 -0700123 if ! openstack stack create -t ./onap-oom.yaml~ -e $ENV_FILE~ $stack_name --parameter docker_manifest=$docker_manifest; then
Gary Wud2579972018-05-23 12:36:46 -0700124 break
125 fi
126
eHanan97b7a9c2018-09-05 14:09:19 +0100127 while [ "CREATE_IN_PROGRESS" == "$(openstack stack show -c stack_status -f value $stack_name)" ]; do
Gary Wud2579972018-05-23 12:36:46 -0700128 sleep 20
129 done
130
eHanan97b7a9c2018-09-05 14:09:19 +0100131 STATUS=$(openstack stack show -c stack_status -f value $stack_name)
Gary Wud2579972018-05-23 12:36:46 -0700132 echo $STATUS
133 if [ "CREATE_COMPLETE" != "$STATUS" ]; then
134 break
135 fi
Gary Wucbddc2b2018-01-22 13:33:21 -0800136
Gary Wuae7c7642018-04-19 17:22:34 -0700137 for i in $(seq 1 30); do
138 sleep 30
eHanan97b7a9c2018-09-05 14:09:19 +0100139 RANCHER_IP=$(openstack stack output show $stack_name rancher_vm_ip -c output_value -f value)
140 K8S_IP=$(openstack stack output show $stack_name k8s_1_vm_ip -c output_value -f value)
Gary Wu14a6b302018-05-01 15:59:28 -0700141 timeout 1 ping -c 1 "$RANCHER_IP" && break
Gary Wucbddc2b2018-01-22 13:33:21 -0800142 done
143
Gary Wu14a6b302018-05-01 15:59:28 -0700144 timeout 1 ping -c 1 "$RANCHER_IP" && break
Gary Wucbddc2b2018-01-22 13:33:21 -0800145
Gary Wu14a6b302018-05-01 15:59:28 -0700146 echo Error: OpenStack infrastructure issue: unable to reach rancher "$RANCHER_IP"
Gary Wucbddc2b2018-01-22 13:33:21 -0800147 sleep 10
148done
149
Gary Wu14a6b302018-05-01 15:59:28 -0700150if ! timeout 1 ping -c 1 "$RANCHER_IP"; then
Gary Wucbddc2b2018-01-22 13:33:21 -0800151 exit 2
152fi
153
Gary Wud3337f02018-05-24 10:51:23 -0700154ssh-keygen -R $RANCHER_IP
155
Gary Wub0e36502018-10-16 11:01:07 -0700156sleep 2m
Gary Wu0d28fe62018-05-24 20:54:28 -0700157ssh -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)"
Gary Wud2579972018-05-23 12:36:46 -0700158
Gary Wu895a4ac2018-10-31 12:30:54 -0700159PREV_RESULT=0
160for n in $(seq 1 20); do
161 RESULT=$(ssh -i $SSH_KEY ubuntu@$RANCHER_IP 'sudo su -c "kubectl -n onap get pods"' | grep -vE 'Running|Complete|NAME' | wc -l)
162 if [[ $? -eq 0 && ( $RESULT -eq 0 || $RESULT -eq $PREV_RESULT ) ]]; then
163 break
164 fi
165 sleep 15m
166 PREV_RESULT=$RESULT
Gary Wucbddc2b2018-01-22 13:33:21 -0800167done
Gary Wu895a4ac2018-10-31 12:30:54 -0700168
169PREV_RESULT=0
170for n in $(seq 1 20); do
171 echo "Wait for HEALTHCHECK count $n of 10"
172 ROBOT_POD=$(ssh -i $SSH_KEY ubuntu@$RANCHER_IP 'sudo su -c "kubectl --namespace onap get pods"' | grep robot | sed 's/ .*//')
173 ssh -i $SSH_KEY ubuntu@$RANCHER_IP 'sudo su -l root -c "/root/oom/kubernetes/robot/ete-k8s.sh onap health"'
174 RESULT=$?
175 if [[ $RESULT -lt 10 && ( $RESULT -eq 0 || $RESULT -eq $PREV_RESULT ) ]]; then
176 break
177 fi
178 sleep 15m
179 PREV_RESULT=$RESULT
180done
Gary Wud2579972018-05-23 12:36:46 -0700181if [ "$ROBOT_POD" == "" ]; then
Gary Wu895a4ac2018-10-31 12:30:54 -0700182 exit 1
Gary Wud2579972018-05-23 12:36:46 -0700183fi
Gary Wu36e42dd2018-05-03 07:29:53 -0700184
Gary Wu43159fb2018-05-25 08:08:36 -0700185LOG_DIR=$(echo "kubectl exec -n onap $ROBOT_POD -- ls -1t /share/logs | grep health | head -1" | ssh -i $SSH_KEY ubuntu@$RANCHER_IP sudo su)
Gary Wud2579972018-05-23 12:36:46 -0700186echo "kubectl cp -n onap $ROBOT_POD:share/logs/$LOG_DIR /tmp/robot/logs/$LOG_DIR" | ssh -i $SSH_KEY ubuntu@$RANCHER_IP sudo su
Gary Wud2579972018-05-23 12:36:46 -0700187echo "Browse Robot results at http://$K8S_IP:30209/logs/$LOG_DIR/"
Gary Wu895a4ac2018-10-31 12:30:54 -0700188mkdir -p $WORKSPACE/archives/healthcheck
189rsync -e "ssh -i $SSH_KEY" -avtz ubuntu@$RANCHER_IP:/tmp/robot/logs/$LOG_DIR/ $WORKSPACE/archives/healthcheck
Gary Wud2579972018-05-23 12:36:46 -0700190
Gary Wucbddc2b2018-01-22 13:33:21 -0800191exit 0