Skip to content

Commit

Permalink
Run ports deletion as last part of cleanup
Browse files Browse the repository at this point in the history
Port checking and deleting is very time consuming operation,
servers and stacks deletions can be skipped because of it.
Run it last to clean more efficiently.
Increase timeout to 6 hours, not to break long jobs.

Change-Id: I26684a8b58b3c6aa794db4d904b2fb7b3f9f760e
  • Loading branch information
sshnaidm committed Dec 5, 2019
1 parent 787dbe9 commit 55e4095
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions ci-scripts/infra-cleanup/ovb-tenant-cleanup.sh
Expand Up @@ -19,7 +19,7 @@
# Use the nuclear option with caution. All non-marked ports will be deleted.

: ${LONG_RUNNING:1}
: ${TIME_EXPIRED:=300}
: ${TIME_EXPIRED:=360}
: ${STACK_LIST:=""}
: ${NUCLEAR:=0}
: ${DRY_RUN:=0}
Expand Down Expand Up @@ -160,23 +160,6 @@ else
STACK_LIST=$(openstack stack list -f json | jq --arg date_time_expired "$DATE_TIME_EXPIRED" -r '.[]| select(.["Creation Time"] <= $date_time_expired) | .["ID"]')
fi

# DOWN port cleanup
PORT_TIME_EXPIRED=300
DATE_TIME_EXPIRED=$(`which gdate date|head -n1` -d " $PORT_TIME_EXPIRED minutes ago" -u "+%Y-%m-%dT%H:%M:%SZ")
# Get a list of ports which are DOWN
echo "INFO: Getting a list of ports which are DOWN"
DOWN_PORT_LIST=$(openstack port list -f json | jq -r '.[]| select(.["Status"] == "DOWN") | .["ID"]')
# Get a list of ports which are down for 5 hours
for PORT in $DOWN_PORT_LIST; do
DOWN_PORT=$(openstack port show $PORT -f json | jq --arg date_time_expired "$DATE_TIME_EXPIRED" -r '. |select(.updated_at <= $date_time_expired)| .id')
if [[ -n "$DOWN_PORT" && "$DOWN_PORT" != "null" ]]; then
echo "INFO: Deleting Down Port $DOWN_PORT"
if [[ "$DRY_RUN" == "0" ]]; then
openstack port delete $DOWN_PORT
fi
fi
done


if [[ "$DRY_RUN" == "1" ]]; then
echo "INFO: DRY RUN - Stack list to delete:
Expand Down Expand Up @@ -311,3 +294,20 @@ else
done
fi
fi

# DOWN port cleanup
PORT_TIME_EXPIRED=${PORT_TIME_EXPIRED:-360}
DATE_TIME_EXPIRED=$(`which gdate date|head -n1` -d " $PORT_TIME_EXPIRED minutes ago" -u "+%Y-%m-%dT%H:%M:%SZ")
# Get a list of ports which are DOWN
echo "INFO: Getting a list of ports which are DOWN"
DOWN_PORT_LIST=$(openstack port list -f json | jq -r '.[]| select(.["Status"] == "DOWN") | .["ID"]')
# Get a list of ports which are down for 5 hours
for PORT in $DOWN_PORT_LIST; do
DOWN_PORT=$(openstack port show $PORT -f json | jq --arg date_time_expired "$DATE_TIME_EXPIRED" -r '. |select(.updated_at <= $date_time_expired)| .id')
if [[ -n "$DOWN_PORT" && "$DOWN_PORT" != "null" ]]; then
echo "INFO: Deleting Down Port $DOWN_PORT"
if [[ "$DRY_RUN" == "0" ]]; then
openstack port delete $DOWN_PORT
fi
fi
done

0 comments on commit 55e4095

Please sign in to comment.