Cleanup of loadbalancers with force set
Related-Bug: PRODX-21132
Change-Id: I47c81210e68d828e27d649be3709284ba98a6fd8
diff --git a/octavia_tempest_plugin/config.py b/octavia_tempest_plugin/config.py
index 929a912..c48e257 100644
--- a/octavia_tempest_plugin/config.py
+++ b/octavia_tempest_plugin/config.py
@@ -288,6 +288,9 @@
help="Whether the log offload tests will run. These require "
"the tempest instance have access to the log files "
"specified in the tempest configuration."),
+ cfg.BoolOpt('force_cleanup_enabled',
+ default=False,
+ help="Whether to delete loadbalancers with force on cleanup."),
]
# Extending this enforce_scope group defined in tempest
diff --git a/octavia_tempest_plugin/services/load_balancer/v2/base_client.py b/octavia_tempest_plugin/services/load_balancer/v2/base_client.py
index 831582d..ce3aa55 100644
--- a/octavia_tempest_plugin/services/load_balancer/v2/base_client.py
+++ b/octavia_tempest_plugin/services/load_balancer/v2/base_client.py
@@ -422,10 +422,18 @@
LOG.error("Cleanup encountered an unknown exception while waiting "
"for %s %s: %s", wait_client.root_tag, wait_id, e)
- if cascade:
- uri = '{0}/{1}?cascade=true'.format(uri, obj_id)
- else:
- uri = '{0}/{1}'.format(uri, obj_id)
+ uri = "{0}/{1}".format(uri, obj_id)
+ query_params = {"cascade": cascade}
+ if (
+ CONF.loadbalancer_feature_enabled.force_cleanup_enabled
+ and self.root_tag == const.LOADBALANCER
+ ):
+ query_params.update({"force": True, "cascade": True})
+ query_string = "&".join(
+ [f"{k}={v}" for k, v in query_params.items() if v]
+ )
+ if query_string:
+ uri += f"?{query_string}"
LOG.info("Cleaning up %s %s...", self.root_tag, obj_id)
return_status = test_utils.call_and_ignore_notfound_exc(
self.delete, uri)