2 virtualenv "$WORKSPACE/.venv-openstack"
3 # shellcheck disable=SC1090
4 source "$WORKSPACE/.venv-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 openstack stack abandon "$STACK_NAME"
51 STACK_SHOW=$(openstack stack show "$STACK_NAME")
54 if [[ $STACK_SHOW != *"$STACK_NAME"* ]]; then
55 echo "stack show on $STACK_NAME came back empty. Assuming successful delete"
59 # if we still see $STACK_NAME in $STACK_SHOW it means the delete hasn't fully
60 # worked and we can exit forcefully
61 if [[ $STACK_SHOW == *"$STACK_NAME"* ]]; then
62 echo "stack $STACK_NAME still in stack show output after polling. Quitting!"
68 echo "Waiting to initialize infrastructure."
72 echo "Unexpected status: $OS_STATUS"
77 if $STACK_SUCCESSFUL; then
82 # capture stack info in console logs
83 openstack stack show "$STACK_NAME"
85 if ! $STACK_SUCCESSFUL; then