Added cleanup of free floating ip addresses
Deleting only free (not associated) FIPs which were
created inside the projects that can beleted (tempest, cvp,
etc).
Known issue: when run in -t dry-run mode, the servers are not
deleted yet, so the potential FIPs are still associated,
and the dry run log will not include them (if any).
Related-PROD: PROD-37187
Change-Id: I306d7bf63c11a7026ba5a8bd4ca9690541893911
diff --git a/cleanup.py b/cleanup.py
index 8767588..9b52b96 100644
--- a/cleanup.py
+++ b/cleanup.py
@@ -362,6 +362,24 @@
log.info(f"... ... could not delete {id_} load balancer: {e}")
+def cleanup_floating_ips():
+ projects = identity.projects()
+ list_projects_to_delete = list(_filter_test_resources(projects, 'name'))
+ floating_ips = network.ips()
+ fips_to_delete = {}
+ for ip in floating_ips:
+ # filter only non-associated IPs, only inside target projects
+ if (ip.status == 'DOWN') and (ip.fixed_ip_address is None):
+ if ip.project_id in list_projects_to_delete:
+ fips_to_delete[ip.id] = ip.floating_ip_address
+ _log_resources_count(len(fips_to_delete), 'floating ip(s)')
+ if args.dry_run:
+ return
+ for id_ in fips_to_delete:
+ _log_resource_delete(id_, fips_to_delete[id_], 'floating ip')
+ network.delete_ip(id_)
+
+
if __name__ == "__main__":
parser = argparse.ArgumentParser(
description='OpenStack test resources cleanup script')
@@ -410,6 +428,7 @@
cleanup_networks()
cleanup_containers()
cleanup_load_balancers()
+ cleanup_floating_ips()
if args.projects:
cleanup_projects()