Merge "Cleanup of loadbalancers with force set" into mcp/caracal
diff --git a/octavia_tempest_plugin/config.py b/octavia_tempest_plugin/config.py
index 9e259d3..58ddf13 100644
--- a/octavia_tempest_plugin/config.py
+++ b/octavia_tempest_plugin/config.py
@@ -294,6 +294,9 @@
                      "specified in the tempest configuration."),
     cfg.BoolOpt('prometheus_listener_enabled', default=True,
                 help="Whether the PROMETHEUS listener tests will run."),
+    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 bf08c5a..5e2298c 100644
--- a/octavia_tempest_plugin/services/load_balancer/v2/base_client.py
+++ b/octavia_tempest_plugin/services/load_balancer/v2/base_client.py
@@ -419,10 +419,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)