eHanan | 97b7a9c | 2018-09-05 14:09:19 +0100 | [diff] [blame] | 1 | #!/bin/bash |
Gary Wu | a3fb86f | 2018-06-04 16:23:54 -0700 | [diff] [blame] | 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 | # |
Gary Wu | cbddc2b | 2018-01-22 13:33:21 -0800 | [diff] [blame] | 11 | |
eHanan | 97b7a9c | 2018-09-05 14:09:19 +0100 | [diff] [blame] | 12 | stack_name="oom" |
Gary Wu | 4a69d51 | 2018-12-10 11:31:24 -0800 | [diff] [blame] | 13 | portal_hostname="portal.api.simpledemo.onap.org" |
eHanan | 58ccb9d | 2018-08-07 14:09:26 +0100 | [diff] [blame] | 14 | full_deletion=false |
| 15 | |
Gary Wu | cbddc2b | 2018-01-22 13:33:21 -0800 | [diff] [blame] | 16 | if [ -z "$WORKSPACE" ]; then |
| 17 | export WORKSPACE=`git rev-parse --show-toplevel` |
| 18 | fi |
| 19 | |
eHanan | 97b7a9c | 2018-09-05 14:09:19 +0100 | [diff] [blame] | 20 | usage() { |
Gary Wu | 4a69d51 | 2018-12-10 11:31:24 -0800 | [diff] [blame] | 21 | echo "Usage: $0 [ -n <number of VMs {2-15}> ][ -s <stack name> ][ -m <manifest> ][ -d <domain> ][ -r ][ -q ] <env>" 1>&2; |
eHanan | 97b7a9c | 2018-09-05 14:09:19 +0100 | [diff] [blame] | 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; |
Gary Wu | 4a69d51 | 2018-12-10 11:31:24 -0800 | [diff] [blame] | 25 | echo "d: Set the base domain name to be used in portal UI URLs" 1>&2; |
Gary Wu | 03e724f | 2018-09-07 22:03:48 -0700 | [diff] [blame] | 26 | echo "m: The docker manifest to apply; must be either \"docker-manifest-staging.csv\" or \"docker-manifest.csv\"." 1>&2; |
eHanan | 97b7a9c | 2018-09-05 14:09:19 +0100 | [diff] [blame] | 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 | } |
eHanan | 58ccb9d | 2018-08-07 14:09:26 +0100 | [diff] [blame] | 32 | |
Gary Wu | cbddc2b | 2018-01-22 13:33:21 -0800 | [diff] [blame] | 33 | |
Gary Wu | 4a69d51 | 2018-12-10 11:31:24 -0800 | [diff] [blame] | 34 | while getopts ":n:s:d:m:rq" o; do |
eHanan | 58ccb9d | 2018-08-07 14:09:26 +0100 | [diff] [blame] | 35 | case "${o}" in |
eHanan | 97b7a9c | 2018-09-05 14:09:19 +0100 | [diff] [blame] | 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 | ;; |
Gary Wu | 4a69d51 | 2018-12-10 11:31:24 -0800 | [diff] [blame] | 54 | d) |
| 55 | if [[ ! ${OPTARG} =~ ^[0-9]+$ ]];then |
| 56 | portal_hostname=${OPTARG} |
| 57 | else |
| 58 | usage |
| 59 | fi |
| 60 | ;; |
Gary Wu | 03e724f | 2018-09-07 22:03:48 -0700 | [diff] [blame] | 61 | m) |
| 62 | if [ -f $WORKSPACE/version-manifest/src/main/resources/${OPTARG} ]; then |
| 63 | docker_manifest=${OPTARG} |
| 64 | else |
| 65 | usage |
| 66 | fi |
| 67 | ;; |
eHanan | 58ccb9d | 2018-08-07 14:09:26 +0100 | [diff] [blame] | 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 |
Gary Wu | 87aa8b5 | 2018-08-09 08:10:24 -0700 | [diff] [blame] | 75 | |
eHanan | 58ccb9d | 2018-08-07 14:09:26 +0100 | [diff] [blame] | 76 | if [ $answer2 = "y" ] || [ $answer2 = "Y" ] || [ $answer2 = "yes" ] || [ $answer2 = "Yes"]; then |
| 77 | full_deletion=true |
Gary Wu | 87aa8b5 | 2018-08-09 08:10:24 -0700 | [diff] [blame] | 78 | else |
eHanan | 58ccb9d | 2018-08-07 14:09:26 +0100 | [diff] [blame] | 79 | echo "Ending program" |
| 80 | exit 1 |
| 81 | fi |
Gary Wu | 87aa8b5 | 2018-08-09 08:10:24 -0700 | [diff] [blame] | 82 | else |
eHanan | 58ccb9d | 2018-08-07 14:09:26 +0100 | [diff] [blame] | 83 | echo "Ending program" |
| 84 | exit 1 |
| 85 | fi |
| 86 | ;; |
| 87 | q) |
| 88 | full_deletion=true |
| 89 | ;; |
| 90 | *) |
| 91 | usage |
| 92 | ;; |
| 93 | esac |
| 94 | done |
| 95 | shift $((OPTIND-1)) |
| 96 | |
Gary Wu | 87aa8b5 | 2018-08-09 08:10:24 -0700 | [diff] [blame] | 97 | if [ "$#" -ne 1 ]; then |
| 98 | usage |
| 99 | fi |
| 100 | |
| 101 | ENV_FILE=$1 |
| 102 | |
eHanan | 97b7a9c | 2018-09-05 14:09:19 +0100 | [diff] [blame] | 103 | if [ ! -f $ENV_FILE ];then |
| 104 | echo ENV file does not exist or was not given |
| 105 | exit 1 |
| 106 | fi |
| 107 | |
| 108 | set -x |
| 109 | |
Gary Wu | 0d28fe6 | 2018-05-24 20:54:28 -0700 | [diff] [blame] | 110 | SSH_KEY=~/.ssh/onap_key |
| 111 | |
Gary Wu | 808b13d | 2018-02-13 18:28:37 -0800 | [diff] [blame] | 112 | source $WORKSPACE/test/ete/scripts/install_openstack_cli.sh |
| 113 | |
Marco Platania | 469b46f | 2019-04-04 17:10:31 -0700 | [diff] [blame^] | 114 | SO_ENCRYPTION_KEY=aa3871669d893c7fb8abbcda31b88b4f |
| 115 | export OS_PASSWORD_ENCRYPTED_FOR_ROBOT=$(echo -n "$OS_PASSWORD" | openssl aes-128-ecb -e -K "$SO_ENCRYPTION_KEY" -nosalt | xxd -c 256 -p) |
Marco Platania | ab8cd68 | 2019-03-19 15:22:58 -0400 | [diff] [blame] | 116 | |
| 117 | #Use new encryption method |
| 118 | pushd $WORKSPACE/deployment/heat/onap-oom/scripts |
| 119 | javac Crypto.java |
Marco Platania | 469b46f | 2019-04-04 17:10:31 -0700 | [diff] [blame^] | 120 | #SO_ENCRYPTION_KEY=aa3871669d893c7fb8abbcda31b88b4f |
Marco Platania | ab8cd68 | 2019-03-19 15:22:58 -0400 | [diff] [blame] | 121 | export OS_PASSWORD_ENCRYPTED=$(java Crypto "$OS_PASSWORD" "$SO_ENCRYPTION_KEY") |
| 122 | popd |
Gary Wu | 11c9874 | 2018-05-02 16:19:04 -0700 | [diff] [blame] | 123 | |
Gary Wu | cbddc2b | 2018-01-22 13:33:21 -0800 | [diff] [blame] | 124 | for n in $(seq 1 5); do |
Gary Wu | 87aa8b5 | 2018-08-09 08:10:24 -0700 | [diff] [blame] | 125 | if [ $full_deletion = true ] ; then |
eHanan | 97b7a9c | 2018-09-05 14:09:19 +0100 | [diff] [blame] | 126 | $WORKSPACE/test/ete/scripts/teardown-onap.sh -n $stack_name -q |
Gary Wu | 87aa8b5 | 2018-08-09 08:10:24 -0700 | [diff] [blame] | 127 | else |
eHanan | 97b7a9c | 2018-09-05 14:09:19 +0100 | [diff] [blame] | 128 | $WORKSPACE/test/ete/scripts/teardown-onap.sh -n $stack_name |
eHanan | 58ccb9d | 2018-08-07 14:09:26 +0100 | [diff] [blame] | 129 | fi |
Gary Wu | cbddc2b | 2018-01-22 13:33:21 -0800 | [diff] [blame] | 130 | |
| 131 | cd $WORKSPACE/deployment/heat/onap-oom |
Gary Wu | 374498a | 2018-02-06 17:31:04 -0800 | [diff] [blame] | 132 | envsubst < $ENV_FILE > $ENV_FILE~ |
eHanan | 97b7a9c | 2018-09-05 14:09:19 +0100 | [diff] [blame] | 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 |
Gary Wu | d257997 | 2018-05-23 12:36:46 -0700 | [diff] [blame] | 138 | |
Gary Wu | 4a69d51 | 2018-12-10 11:31:24 -0800 | [diff] [blame] | 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 |
Gary Wu | d257997 | 2018-05-23 12:36:46 -0700 | [diff] [blame] | 140 | break |
| 141 | fi |
| 142 | |
eHanan | 97b7a9c | 2018-09-05 14:09:19 +0100 | [diff] [blame] | 143 | while [ "CREATE_IN_PROGRESS" == "$(openstack stack show -c stack_status -f value $stack_name)" ]; do |
Gary Wu | d257997 | 2018-05-23 12:36:46 -0700 | [diff] [blame] | 144 | sleep 20 |
| 145 | done |
| 146 | |
eHanan | 97b7a9c | 2018-09-05 14:09:19 +0100 | [diff] [blame] | 147 | STATUS=$(openstack stack show -c stack_status -f value $stack_name) |
Gary Wu | d257997 | 2018-05-23 12:36:46 -0700 | [diff] [blame] | 148 | echo $STATUS |
| 149 | if [ "CREATE_COMPLETE" != "$STATUS" ]; then |
| 150 | break |
| 151 | fi |
Gary Wu | cbddc2b | 2018-01-22 13:33:21 -0800 | [diff] [blame] | 152 | |
Gary Wu | ae7c764 | 2018-04-19 17:22:34 -0700 | [diff] [blame] | 153 | for i in $(seq 1 30); do |
| 154 | sleep 30 |
eHanan | 97b7a9c | 2018-09-05 14:09:19 +0100 | [diff] [blame] | 155 | RANCHER_IP=$(openstack stack output show $stack_name rancher_vm_ip -c output_value -f value) |
Gary Wu | 48a3294 | 2018-11-08 07:34:49 -0800 | [diff] [blame] | 156 | K8S_IP=$(openstack stack output show $stack_name k8s_01_vm_ip -c output_value -f value) |
Gary Wu | 14a6b30 | 2018-05-01 15:59:28 -0700 | [diff] [blame] | 157 | timeout 1 ping -c 1 "$RANCHER_IP" && break |
Gary Wu | cbddc2b | 2018-01-22 13:33:21 -0800 | [diff] [blame] | 158 | done |
| 159 | |
Gary Wu | 14a6b30 | 2018-05-01 15:59:28 -0700 | [diff] [blame] | 160 | timeout 1 ping -c 1 "$RANCHER_IP" && break |
Gary Wu | cbddc2b | 2018-01-22 13:33:21 -0800 | [diff] [blame] | 161 | |
Gary Wu | 14a6b30 | 2018-05-01 15:59:28 -0700 | [diff] [blame] | 162 | echo Error: OpenStack infrastructure issue: unable to reach rancher "$RANCHER_IP" |
Gary Wu | cbddc2b | 2018-01-22 13:33:21 -0800 | [diff] [blame] | 163 | sleep 10 |
| 164 | done |
| 165 | |
Gary Wu | 14a6b30 | 2018-05-01 15:59:28 -0700 | [diff] [blame] | 166 | if ! timeout 1 ping -c 1 "$RANCHER_IP"; then |
Gary Wu | cbddc2b | 2018-01-22 13:33:21 -0800 | [diff] [blame] | 167 | exit 2 |
| 168 | fi |
| 169 | |
Gary Wu | d3337f0 | 2018-05-24 10:51:23 -0700 | [diff] [blame] | 170 | ssh-keygen -R $RANCHER_IP |
| 171 | |
Gary Wu | b0e3650 | 2018-10-16 11:01:07 -0700 | [diff] [blame] | 172 | sleep 2m |
Gary Wu | 0d28fe6 | 2018-05-24 20:54:28 -0700 | [diff] [blame] | 173 | 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)" |
Gary Wu | d257997 | 2018-05-23 12:36:46 -0700 | [diff] [blame] | 174 | |
Gary Wu | 895a4ac | 2018-10-31 12:30:54 -0700 | [diff] [blame] | 175 | PREV_RESULT=0 |
| 176 | for n in $(seq 1 20); do |
| 177 | RESULT=$(ssh -i $SSH_KEY ubuntu@$RANCHER_IP 'sudo su -c "kubectl -n onap get pods"' | grep -vE 'Running|Complete|NAME' | wc -l) |
| 178 | if [[ $? -eq 0 && ( $RESULT -eq 0 || $RESULT -eq $PREV_RESULT ) ]]; then |
| 179 | break |
| 180 | fi |
| 181 | sleep 15m |
| 182 | PREV_RESULT=$RESULT |
Gary Wu | cbddc2b | 2018-01-22 13:33:21 -0800 | [diff] [blame] | 183 | done |
Gary Wu | 895a4ac | 2018-10-31 12:30:54 -0700 | [diff] [blame] | 184 | |
| 185 | PREV_RESULT=0 |
| 186 | for n in $(seq 1 20); do |
| 187 | echo "Wait for HEALTHCHECK count $n of 10" |
| 188 | ROBOT_POD=$(ssh -i $SSH_KEY ubuntu@$RANCHER_IP 'sudo su -c "kubectl --namespace onap get pods"' | grep robot | sed 's/ .*//') |
| 189 | ssh -i $SSH_KEY ubuntu@$RANCHER_IP 'sudo su -l root -c "/root/oom/kubernetes/robot/ete-k8s.sh onap health"' |
| 190 | RESULT=$? |
| 191 | if [[ $RESULT -lt 10 && ( $RESULT -eq 0 || $RESULT -eq $PREV_RESULT ) ]]; then |
| 192 | break |
| 193 | fi |
| 194 | sleep 15m |
| 195 | PREV_RESULT=$RESULT |
| 196 | done |
Gary Wu | d257997 | 2018-05-23 12:36:46 -0700 | [diff] [blame] | 197 | if [ "$ROBOT_POD" == "" ]; then |
Gary Wu | 895a4ac | 2018-10-31 12:30:54 -0700 | [diff] [blame] | 198 | exit 1 |
Gary Wu | d257997 | 2018-05-23 12:36:46 -0700 | [diff] [blame] | 199 | fi |
Gary Wu | 36e42dd | 2018-05-03 07:29:53 -0700 | [diff] [blame] | 200 | |
Gary Wu | 43159fb | 2018-05-25 08:08:36 -0700 | [diff] [blame] | 201 | LOG_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 Wu | d257997 | 2018-05-23 12:36:46 -0700 | [diff] [blame] | 202 | echo "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 Wu | d257997 | 2018-05-23 12:36:46 -0700 | [diff] [blame] | 203 | echo "Browse Robot results at http://$K8S_IP:30209/logs/$LOG_DIR/" |
Gary Wu | 895a4ac | 2018-10-31 12:30:54 -0700 | [diff] [blame] | 204 | mkdir -p $WORKSPACE/archives/healthcheck |
| 205 | rsync -e "ssh -i $SSH_KEY" -avtz ubuntu@$RANCHER_IP:/tmp/robot/logs/$LOG_DIR/ $WORKSPACE/archives/healthcheck |
Gary Wu | d257997 | 2018-05-23 12:36:46 -0700 | [diff] [blame] | 206 | |
Gary Wu | cbddc2b | 2018-01-22 13:33:21 -0800 | [diff] [blame] | 207 | exit 0 |