blob: c9cd005c7310a584051021a39541711e748e511e [file] [log] [blame]
Gary Wucbddc2b2018-01-22 13:33:21 -08001#!/bin/bash -x
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
eHanan58ccb9d2018-08-07 14:09:26 +010012install_name="onap-oom"
13full_deletion=false
14
Gary Wucbddc2b2018-01-22 13:33:21 -080015if [ -z "$WORKSPACE" ]; then
16 export WORKSPACE=`git rev-parse --show-toplevel`
17fi
18
Gary Wu87aa8b52018-08-09 08:10:24 -070019usage() { echo "Usage: $0 [ -r ] <env-name>" 1>&2; exit 1; }
eHanan58ccb9d2018-08-07 14:09:26 +010020
Gary Wucbddc2b2018-01-22 13:33:21 -080021
Gary Wu87aa8b52018-08-09 08:10:24 -070022while getopts ":rq" o; do
eHanan58ccb9d2018-08-07 14:09:26 +010023 case "${o}" in
eHanan58ccb9d2018-08-07 14:09:26 +010024 r)
25 echo "The following command will delete all information relating to onap within your enviroment"
26 read -p "Are you certain this is what you want? (type y to confirm):" answer
27
28 if [ $answer = "y" ] || [ $answer = "Y" ] || [ $answer = "yes" ] || [ $answer = "Yes"]; then
29 echo "This may delete the work of other colleages within the same enviroment"
30 read -p "Are you certain this is what you want? (type y to confirm):" answer2
Gary Wu87aa8b52018-08-09 08:10:24 -070031
eHanan58ccb9d2018-08-07 14:09:26 +010032 if [ $answer2 = "y" ] || [ $answer2 = "Y" ] || [ $answer2 = "yes" ] || [ $answer2 = "Yes"]; then
33 full_deletion=true
Gary Wu87aa8b52018-08-09 08:10:24 -070034 else
eHanan58ccb9d2018-08-07 14:09:26 +010035 echo "Ending program"
36 exit 1
37 fi
Gary Wu87aa8b52018-08-09 08:10:24 -070038 else
eHanan58ccb9d2018-08-07 14:09:26 +010039 echo "Ending program"
40 exit 1
41 fi
42 ;;
43 q)
44 full_deletion=true
45 ;;
46 *)
47 usage
48 ;;
49 esac
50done
51shift $((OPTIND-1))
52
Gary Wu87aa8b52018-08-09 08:10:24 -070053if [ "$#" -ne 1 ]; then
54 usage
55fi
56
57ENV_FILE=$1
58
Gary Wu0d28fe62018-05-24 20:54:28 -070059SSH_KEY=~/.ssh/onap_key
60
Gary Wu808b13d2018-02-13 18:28:37 -080061source $WORKSPACE/test/ete/scripts/install_openstack_cli.sh
62
Gary Wu11c98742018-05-02 16:19:04 -070063SO_ENCRYPTION_KEY=aa3871669d893c7fb8abbcda31b88b4f
64export OS_PASSWORD_ENCRYPTED=$(echo -n "$OS_PASSWORD" | openssl aes-128-ecb -e -K "$SO_ENCRYPTION_KEY" -nosalt | xxd -c 256 -p)
65
Gary Wucbddc2b2018-01-22 13:33:21 -080066for n in $(seq 1 5); do
Gary Wu87aa8b52018-08-09 08:10:24 -070067 if [ $full_deletion = true ] ; then
eHanan58ccb9d2018-08-07 14:09:26 +010068 $WORKSPACE/test/ete/scripts/teardown-onap.sh -n $install_name -q
Gary Wu87aa8b52018-08-09 08:10:24 -070069 else
eHanan58ccb9d2018-08-07 14:09:26 +010070 $WORKSPACE/test/ete/scripts/teardown-onap.sh -n $install_name
71 fi
Gary Wucbddc2b2018-01-22 13:33:21 -080072
73 cd $WORKSPACE/deployment/heat/onap-oom
Gary Wu374498a2018-02-06 17:31:04 -080074 envsubst < $ENV_FILE > $ENV_FILE~
Gary Wud2579972018-05-23 12:36:46 -070075
eHanan58ccb9d2018-08-07 14:09:26 +010076 if ! openstack stack create -t ./$install_name.yaml -e $ENV_FILE~ $install_name; then
Gary Wud2579972018-05-23 12:36:46 -070077 break
78 fi
79
eHanan58ccb9d2018-08-07 14:09:26 +010080 while [ "CREATE_IN_PROGRESS" == "$(openstack stack show -c stack_status -f value $install_name)" ]; do
Gary Wud2579972018-05-23 12:36:46 -070081 sleep 20
82 done
83
eHanan58ccb9d2018-08-07 14:09:26 +010084 STATUS=$(openstack stack show -c stack_status -f value $install_name)
Gary Wud2579972018-05-23 12:36:46 -070085 echo $STATUS
86 if [ "CREATE_COMPLETE" != "$STATUS" ]; then
87 break
88 fi
Gary Wucbddc2b2018-01-22 13:33:21 -080089
Gary Wuae7c7642018-04-19 17:22:34 -070090 for i in $(seq 1 30); do
91 sleep 30
eHanan58ccb9d2018-08-07 14:09:26 +010092 RANCHER_IP=$(openstack stack output show $install_name rancher_vm_ip -c output_value -f value)
93 K8S_IP=$(openstack stack output show $install_name k8s_1_vm_ip -c output_value -f value)
Gary Wu14a6b302018-05-01 15:59:28 -070094 timeout 1 ping -c 1 "$RANCHER_IP" && break
Gary Wucbddc2b2018-01-22 13:33:21 -080095 done
96
Gary Wu14a6b302018-05-01 15:59:28 -070097 timeout 1 ping -c 1 "$RANCHER_IP" && break
Gary Wucbddc2b2018-01-22 13:33:21 -080098
Gary Wu14a6b302018-05-01 15:59:28 -070099 echo Error: OpenStack infrastructure issue: unable to reach rancher "$RANCHER_IP"
Gary Wucbddc2b2018-01-22 13:33:21 -0800100 sleep 10
101done
102
Gary Wu14a6b302018-05-01 15:59:28 -0700103if ! timeout 1 ping -c 1 "$RANCHER_IP"; then
Gary Wucbddc2b2018-01-22 13:33:21 -0800104 exit 2
105fi
106
Gary Wud3337f02018-05-24 10:51:23 -0700107ssh-keygen -R $RANCHER_IP
108
Gary Wu0d28fe62018-05-24 20:54:28 -0700109ssh -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 -0700110
Gary Wu5627a692018-05-08 19:13:59 -0700111for n in $(seq 1 6); do
Gary Wuc4749702018-06-26 14:27:41 -0700112 echo "Wait count $n of 6"
113 sleep 15m
Gary Wu0d28fe62018-05-24 20:54:28 -0700114 timeout 15m ssh -i $SSH_KEY ubuntu@$RANCHER_IP 'sudo su -l root -c "/root/oom/kubernetes/robot/ete-k8s.sh onap health"'
Gary Wucbddc2b2018-01-22 13:33:21 -0800115 RESULT=$?
116 if [ $RESULT -eq 0 ]; then
117 break
118 fi
Gary Wucbddc2b2018-01-22 13:33:21 -0800119done
Gary Wu0d28fe62018-05-24 20:54:28 -0700120ROBOT_POD=$(ssh -i $SSH_KEY ubuntu@$RANCHER_IP 'sudo su -c "kubectl --namespace onap get pods"' | grep robot | sed 's/ .*//')
Gary Wud2579972018-05-23 12:36:46 -0700121if [ "$ROBOT_POD" == "" ]; then
122 exit 1
123fi
Gary Wu36e42dd2018-05-03 07:29:53 -0700124
Gary Wu43159fb2018-05-25 08:08:36 -0700125LOG_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 -0700126if [ "$LOG_DIR" == "" ]; then
127 exit 1
128fi
129
130echo "kubectl cp -n onap $ROBOT_POD:share/logs/$LOG_DIR /tmp/robot/logs/$LOG_DIR" | ssh -i $SSH_KEY ubuntu@$RANCHER_IP sudo su
131rsync -e "ssh -i $SSH_KEY" -avtz ubuntu@$RANCHER_IP:/tmp/robot/logs/$LOG_DIR/ $WORKSPACE/archives/
132
133echo "Browse Robot results at http://$K8S_IP:30209/logs/$LOG_DIR/"
134
Gary Wucbddc2b2018-01-22 13:33:21 -0800135exit 0