From 55e4095c3a4d9a5d8d474482d7423557d68b632c Mon Sep 17 00:00:00 2001 From: Sagi Shnaidman Date: Thu, 5 Dec 2019 13:36:21 +0200 Subject: [PATCH] Run ports deletion as last part of cleanup 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 --- .../infra-cleanup/ovb-tenant-cleanup.sh | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/ci-scripts/infra-cleanup/ovb-tenant-cleanup.sh b/ci-scripts/infra-cleanup/ovb-tenant-cleanup.sh index ec6652ce6..c77bd1f29 100755 --- a/ci-scripts/infra-cleanup/ovb-tenant-cleanup.sh +++ b/ci-scripts/infra-cleanup/ovb-tenant-cleanup.sh @@ -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} @@ -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: @@ -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