From 5dd018ecbe78dde95d86a4f3e9d8b56efdd44afa Mon Sep 17 00:00:00 2001 From: Tin Date: Wed, 24 Jun 2020 10:06:55 -0500 Subject: [PATCH] RFC: fix(cleanup): neutron Change-Id: I371da6b47ca6ef31c2909302b0aa71040f8930d9 Signed-off-by: Tin --- neutron/values.yaml | 44 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 36 insertions(+), 8 deletions(-) diff --git a/neutron/values.yaml b/neutron/values.yaml index a384bb4215..730d55d094 100644 --- a/neutron/values.yaml +++ b/neutron/values.yaml @@ -822,14 +822,42 @@ conf: force_project_purge: false run_tempest: false clean_up: | - ROUTERS=$(openstack router list -f value | awk '$2 ~ /^[sc]_rally_/ { print $1 }') - if [ -n "$ROUTERS" ]; then - echo $ROUTERS | xargs openstack router delete - fi - NETWORKS=$(openstack network list -f value | awk '$2 ~ /^[sc]_rally_/ { print $1 }') - if [ -n "$NETWORKS" ]; then - echo $NETWORKS | xargs openstack network delete - fi + # NOTE: We will make the best effort to clean up rally generated networks and routers, + # but should not block further automated deployment. + set +e + PATTERN="^[sc]_rally_" + + ROUTERS=$(openstack router list --format=value -c Name | grep -e $PATTERN | sort | tr -d '\r') + NETWORKS=$(openstack network list --format=value -c Name | grep -e $PATTERN | sort | tr -d '\r') + + for ROUTER in $ROUTERS + do + openstack router unset --external-gateway $ROUTER + openstack router set --disable --no-ha $ROUTER + + SUBNS=$(openstack router show $ROUTER -c interfaces_info --format=value | jq .[].subnet_id | tr -d '\r\"') + for SUBN in $SUBNS + do + openstack router remove subnet $ROUTER $SUBN + done + + for PORT in $(openstack port list --router $ROUTER --format=value -c ID | tr -d '\r') + do + openstack router remove port $ROUTER $PORT + done + + openstack router delete $ROUTER + done + + for NETWORK in $NETWORKS + do + for PORT in $(openstack port list --network $NETWORK --format=value -c ID | tr -d '\r') + do + openstack port delete $PORT + done + openstack network delete $NETWORK + done + set -e tests: NeutronNetworks.create_and_delete_networks: - args: