Added deleting load balancers in the cleanup.py
Deleting the LBs via openstacksdk lib, but in case
the LB is in some transition PENDING_* state, doing
the deletion with the "force" flag implemented in
MOS Octavia.
This force option is not implemented in the current
upstream openstacksdk lib, so doing the raw request.
Related-PROD: PROD-37187
Change-Id: I2cb5781c5a291dea98f6d686cdd4f104219781dd
diff --git a/cleanup.py b/cleanup.py
index ad567f2..a8431d6 100644
--- a/cleanup.py
+++ b/cleanup.py
@@ -25,6 +25,7 @@
orchestration = cloud.orchestration
object_store = cloud.object_store
volume = cloud.volume
+load_balancer = cloud.load_balancer
mask = "cvp|s_rally|rally_|tempest-|tempest_|spt|fio"
full_mask = f"^(?!.*(manual|-static-)).*({mask}).*$"
@@ -63,6 +64,17 @@
log.info(f"... deleting {name} (id={id_}) {type_}")
+def _force_delete_load_balancer(id_):
+ log.info(f"... ... force deleting {id_} load balancer")
+ lb_ep = load_balancer.get_endpoint()
+ lb_uri = f"{lb_ep}/lbaas/loadbalancers/{id_}"
+ headers = {'X-Auth-Token': cloud.session.get_token(),
+ 'Content-Type': 'application/json'}
+ params = {'cascade': 'true', 'force': 'true'}
+ cloud.session.request(url=lb_uri, method='DELETE',
+ headers=headers, params=params)
+
+
def cleanup_users():
users = identity.users()
users_to_delete = _filter_test_resources(users, 'name')
@@ -318,6 +330,23 @@
network.delete_network(id_)
+def cleanup_load_balancers():
+ lbs = load_balancer.load_balancers()
+ lbs_to_delete = _filter_test_resources(lbs, 'name')
+ _log_resources_count(len(lbs_to_delete), 'load_balancer(s)')
+ if args.dry_run:
+ return
+ for id_ in lbs_to_delete:
+ _log_resource_delete(id_, lbs_to_delete[id_], 'load_balancer')
+ try:
+ load_balancer.delete_load_balancer(id_, cascade=True)
+ except openstack.exceptions.ConflictException:
+ # force delete the LB in case it is in some PENDING_* state
+ _force_delete_load_balancer(id_)
+ except Exception as e:
+ log.info(f"... ... could not delete {id_} load balancer: {e}")
+
+
if __name__ == "__main__":
parser = argparse.ArgumentParser(
description='OpenStack test resources cleanup script')
@@ -364,6 +393,7 @@
cleanup_routers()
cleanup_networks()
cleanup_containers()
+ cleanup_load_balancers()
if args.projects:
cleanup_projects()