Handle stacks with status DELETE_FAILED 52/56652/5
authorAnil Belur <abelur@linuxfoundation.org>
Thu, 4 May 2017 22:51:47 +0000 (08:51 +1000)
committerAnil Belur <abelur@linuxfoundation.org>
Tue, 16 May 2017 08:29:40 +0000 (08:29 +0000)
Use the delete method for abandoning stacks with DELETE_FAILED status
as recommended by RS. This change can be reverted once issue is resolved
using the $(openstack stack abandon) with the CLI

Change-Id: I94d5d42f92adc0915f6b040a29cef023258768ad
Signed-off-by: Anil Belur <abelur@linuxfoundation.org>
jjb/opendaylight-infra-cleanup-stale-stacks.sh
jjb/opendaylight-infra-stack.sh

index 05949eec1ce021b3d0670a002acc9757771b02c2..2d7c928b9d979e8d8225455a733ecf252803340f 100644 (file)
@@ -32,14 +32,28 @@ done
 ##########################
 ## DELETE UNUSED STACKS ##
 ##########################
-# Search for stacks taht are not in use by either releng or sandbox silos and
+# Search for stacks that are not in use by either releng or sandbox silos and
 # delete them.
-for stack in "${OS_STACKS[@]}"; do
-    if [[ "${ACTIVE_BUILDS[@]}" =~ $stack ]]; then
+for STACK_NAME in "${OS_STACKS[@]}"; do
+    STACK_STATUS=$(openstack stack show -f json -c "stack_status" "$STACK_NAME" | jq -r '."stack_status"')
+    if [[ "${ACTIVE_BUILDS[@]}" =~ $STACK_NAME ]]; then
         # No need to delete stacks if there exists an active build for them
         continue
+    elif [[ "$STACK_STATUS" =~ DELETE_FAILED ]]; then
+        echo "Stack delete failed, trying to stack abandon now."
+        # stack abandon does not work on RS, therefore requires acquiring a token
+        # and using http delete method to abondon DELETE_FAILED stacks
+        # Todo: remove the change once RS fixes the issue upstream
+        # openstack stack abandon "$STACK_NAME"
+        STACK_ID=$(openstack stack show -f json -c "id" "$STACK_NAME" | jq -r '."id"')
+        TOKEN=$(openstack token issue -f json -c id | jq -r '.id')
+        curl -si -X DELETE -H "Content-Type: application/json" -H "Accept: application/json"\
+            -H "x-auth-token: $TOKEN"\
+            "https://dfw.orchestration.api.rackspacecloud.com/v1/904885/stacks/$STACK_NAME/$STACK_ID/abandon"
+        STACK_SHOW=$(openstack stack show "$STACK_NAME")
+        echo "$STACK_SHOW"
     else
-        echo "Deleting orphaned stack: $stack"
-        openstack stack delete --yes "$stack"
+        echo "Deleting orphaned stack: $STACK_NAME"
+        openstack stack delete --yes "$STACK_NAME"
     fi
 done
index bb411f54e44943bab51cbf96e4e782bfebc14120..45eaae9f4c5b13ea623af4584aed9b6f568ef597 100644 (file)
@@ -47,7 +47,15 @@ for try in $(seq $STACK_RETRIES); do
                     echo "$j: $STACK_SHOW"
                     if [[ $STACK_SHOW == *"DELETE_FAILED"* ]]; then
                         echo "stack delete failed. trying to stack abandon now"
-                        openstack stack abandon "$STACK_NAME"
+                        # stack abandon does not work on RS, therefore requires acquiring a token
+                        # and using http delete method to abondon DELETE_FAILED stacks
+                        # Todo: remove the change once RS fixes the issue upstream
+                        # openstack stack abandon "$STACK_NAME"
+                        STACK_ID=$(openstack stack show -f json -c "id" "$STACK_NAME" | jq -r '."id"')
+                        TOKEN=$(openstack token issue -f json -c id | jq -r '.id')
+                        curl -si -X DELETE -H "Content-Type: application/json" -H "Accept: application/json"\
+                            -H "x-auth-token: $TOKEN"\
+                            "https://dfw.orchestration.api.rackspacecloud.com/v1/904885/stacks/$STACK_NAME/$STACK_ID/abandon"
                         STACK_SHOW=$(openstack stack show "$STACK_NAME")
                         echo "$STACK_SHOW"
                     fi