2 # SPDX-License-Identifier: EPL-1.0
3 ##############################################################################
4 # Copyright (c) 2017 The Linux Foundation and others.
6 # All rights reserved. This program and the accompanying materials
7 # are made available under the terms of the Eclipse Public License v1.0
8 # which accompanies this distribution, and is available at
9 # http://www.eclipse.org/legal/epl-v10.html
10 ##############################################################################
12 virtualenv "/tmp/v/openstack"
13 # shellcheck source=/tmp/v/openstack/bin/activate disable=SC1091
14 source "/tmp/v/openstack/bin/activate"
15 pip install --upgrade "pip<10.0.0" setuptools
16 # hardcoding cmd2 version as the most recent version seems to be broken.
17 # reference: https://pypi.org/project/cmd2/#history
18 pip install --upgrade cmd2==0.8.5 python-openstackclient python-heatclient
21 # TODO: Remove the if-statement once we have fully migrated to /opt/ciman
22 if [ -d "/opt/ciman" ]; then
23 cd /opt/ciman || exit 1
25 cd /builder/openstack-hot || exit 1
28 JOB_SUM=$(echo "$JOB_NAME" | sum | awk '{{ print $1 }}')
29 VM_NAME="$JOB_SUM-$BUILD_NUMBER"
31 OS_TIMEOUT=15 # Minutes to wait for OpenStack VM to come online
32 STACK_RETRIES=2 # Number of times to retry creating a stack before fully giving up
33 STACK_SUCCESSFUL=false
34 # seq X refers to waiting for X minutes for OpenStack to return
35 # a status that is not CREATE_IN_PROGRESS before giving up.
36 openstack limits show --absolute
37 openstack limits show --rate
38 echo "Trying up to $STACK_RETRIES times to create $STACK_NAME."
39 for try in $(seq $STACK_RETRIES); do
40 # shellcheck disable=SC1083
41 openstack stack create --timeout "$OS_TIMEOUT" -t {stack-template} -e "$WORKSPACE/opendaylight-infra-environment.yaml" --parameter "job_name=$VM_NAME" --parameter "silo=$SILO" "$STACK_NAME"
42 echo "$try: Waiting for $OS_TIMEOUT minutes to create $STACK_NAME."
43 for i in $(seq $OS_TIMEOUT); do
45 OS_STATUS=$(openstack stack show -f value -c stack_status "$STACK_NAME")
50 echo "Stack initialized on infrastructure successful."
55 reason=$(openstack stack show "$STACK_NAME" -f value -c stack_status_reason)
56 echo "ERROR: Failed to initialize infrastructure. Reason: $reason"
57 openstack stack resource list -n 25 "$STACK_NAME"
59 echo "Deleting stack and possibly retrying to create..."
60 openstack stack delete --yes "$STACK_NAME"
62 # after stack delete, poll for 10m to know when stack is fully removed
63 # the logic here is that when "stack show $STACK_NAME" does not contain $STACK_NAME
64 # we assume it's successfully deleted and we can break to retry
65 for j in $(seq 20); do
67 delete_status=$(openstack stack show "$STACK_NAME" -f value -c stack_status)
68 echo "$j: $delete_status"
69 if [[ $delete_status == "DELETE_FAILED" ]]; then
70 reason=$(openstack stack show "$STACK_NAME" -f value -c stack_status_reason)
71 echo "ERROR: Failed to delete $STACK_NAME. Reason: $reason"
73 # Abandon is not supported in Vexxhost so let's keep trying to
75 # echo "Stack delete failed, trying to stack abandon now."
76 # openstack stack abandon "$STACK_NAME"
77 echo "Deleting failed stack: $STACK_NAME"
78 openstack stack delete --yes "$STACK_NAME"
81 if ! openstack stack show "$STACK_NAME" -f value -c stack_status; then
82 echo "Stack show on $STACK_NAME came back empty. Assuming successful delete"
87 # If we still see $STACK_NAME in `openstack stack show` it means the delete hasn't fully
88 # worked and we can exit forcefully
89 if openstack stack show "$STACK_NAME" -f value -c stack_status; then
90 echo "Stack $STACK_NAME still in cloud output after polling. Quitting!"
96 echo "Waiting to initialize infrastructure."
100 echo "Unexpected status: $OS_STATUS"
101 # DO NOT exit on unexpected status. Rackspace sometimes returns unexpected status
102 # before returning an expected status. Just print the message and loop until we have
103 # a confirmed state or timeout.
108 if $STACK_SUCCESSFUL; then
113 # capture stack info in console logs
114 echo "------------------------------------"
116 echo "------------------------------------"
117 openstack stack show "$STACK_NAME" -f yaml
118 echo "------------------------------------"
120 if ! $STACK_SUCCESSFUL; then