2 virtualenv "/tmp/v/openstack"
3 # shellcheck source=/tmp/v/openstack/bin/activate disable=SC1091
4 source "/tmp/v/openstack/bin/activate"
5 pip install --upgrade pip
6 pip install --upgrade python-openstackclient python-heatclient
9 cd /builder/openstack-hot || exit 1
11 JOB_SUM=$(echo "$JOB_NAME" | sum | awk '{{ print $1 }}')
12 VM_NAME="$JOB_SUM-$BUILD_NUMBER"
14 OS_TIMEOUT=10 # Minutes to wait for OpenStack VM to come online
15 STACK_RETRIES=3 # Number of times to retry creating a stack before fully giving up
16 STACK_SUCCESSFUL=false
17 # seq X refers to waiting for X minutes for OpenStack to return
18 # a status that is not CREATE_IN_PROGRESS before giving up.
19 openstack limits show --absolute
20 openstack limits show --rate
21 echo "Trying up to $STACK_RETRIES times to create $STACK_NAME."
22 for try in $(seq $STACK_RETRIES); do
23 # shellcheck disable=SC1083
24 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"
25 echo "$try: Waiting for $OS_TIMEOUT minutes to create $STACK_NAME."
26 for i in $(seq $OS_TIMEOUT); do
28 OS_STATUS=$(openstack stack show -f json -c stack_status "$STACK_NAME" | jq -r '.stack_status')
33 echo "Stack initialized on infrastructure successful."
38 echo "ERROR: Failed to initialize infrastructure. Deleting stack and possibly retrying to create..."
39 openstack stack delete --yes "$STACK_NAME"
40 openstack stack show "$STACK_NAME"
41 # after stack delete, poll for 10m to know when stack is fully removed
42 # the logic here is that when "stack show $STACK_NAME" does not contain $STACK_NAME
43 # we assume it's successfully deleted and we can break to retry
44 for j in $(seq 20); do
46 STACK_SHOW=$(openstack stack show "$STACK_NAME")
47 echo "$j: $STACK_SHOW"
48 if [[ $STACK_SHOW == *"DELETE_FAILED"* ]]; then
49 echo "stack delete failed. trying to stack abandon now"
50 # stack abandon does not work on RS, therefore requires acquiring a token
51 # and using http delete method to abondon DELETE_FAILED stacks
52 # Todo: remove the change once RS fixes the issue upstream
53 # openstack stack abandon "$STACK_NAME"
54 STACK_ID=$(openstack stack show -f json -c "id" "$STACK_NAME" | jq -r '."id"')
55 TOKEN=$(openstack token issue -f json -c id | jq -r '.id')
56 curl -si -X DELETE -H "Content-Type: application/json" -H "Accept: application/json"\
57 -H "x-auth-token: $TOKEN"\
58 "https://dfw.orchestration.api.rackspacecloud.com/v1/904885/stacks/$STACK_NAME/$STACK_ID/abandon"
59 STACK_SHOW=$(openstack stack show "$STACK_NAME")
62 if [[ $STACK_SHOW != *"$STACK_NAME"* ]]; then
63 echo "stack show on $STACK_NAME came back empty. Assuming successful delete"
67 # if we still see $STACK_NAME in $STACK_SHOW it means the delete hasn't fully
68 # worked and we can exit forcefully
69 if [[ $STACK_SHOW == *"$STACK_NAME"* ]]; then
70 echo "stack $STACK_NAME still in stack show output after polling. Quitting!"
76 echo "Waiting to initialize infrastructure."
80 echo "Unexpected status: $OS_STATUS"
81 # DO NOT exit on unexpected status. Rackspace sometimes returns unexpected status
82 # before returning an expected status. Just print the message and loop until we have
83 # a confirmed state or timeout.
88 if $STACK_SUCCESSFUL; then
93 # capture stack info in console logs
94 openstack stack show "$STACK_NAME"
96 if ! $STACK_SUCCESSFUL; then