From 532ae536241fe2183cf679cbe7c22e88b7ef32cd Mon Sep 17 00:00:00 2001
From: Thomas Goirand <zigo@debian.org>
Date: Tue, 18 Mar 2025 10:39:28 +0100
Subject: [PATCH] Add a rabbit_transient_queues_ttl and amqp_auto_delete params

Since transient_queues_ttl is also managed by oslo::messaging::rabbit,
there's no way to use cloudkitty_config to set it, so this patch is mandatory
for one to set rabbit_transient_queues_ttl in cloudkitty.conf.

Change-Id: Ie48519d40999b36baffa0b92151ef0d93ee3aed6
---

Index: puppet-module-cloudkitty/manifests/init.pp
===================================================================
--- puppet-module-cloudkitty.orig/manifests/init.pp
+++ puppet-module-cloudkitty/manifests/init.pp
@@ -45,6 +45,14 @@
 #   (Optional) Use quorum queues for transients queues in RabbitMQ.
 #   Defaults to $facts['os_service_default']
 #
+# [*rabbit_transient_queues_ttl*]
+#   (Optional) Positive integer representing duration in seconds for
+#   queue TTL (x-expires). Queues which are unused for the duration
+#   of the TTL are automatically deleted.
+#   The parameter affects only reply and fanout queues. (integer value)
+#   Min to 1
+#   Defaults to $facts['os_service_default']
+#
 # [*rabbit_quorum_delivery_limit*]
 #   (Optional) Each time a message is rdelivered to a consumer, a counter is
 #   incremented. Once the redelivery count exceeds the delivery limit
@@ -97,6 +105,10 @@
 #   more than one RabbitMQ node is provided in config. (string value)
 #   Defaults to $facts['os_service_default']
 #
+# [*amqp_auto_delete*]
+#   (Optional) Define if transient queues should be auto-deleted (boolean value)
+#   Defaults to $facts['os_service_default']
+#
 # [*kombu_compression*]
 #   (optional) Possible values are: gzip, bz2. If not set compression will not
 #   be used. This option may not be available in future versions. EXPERIMENTAL.
@@ -204,6 +216,7 @@ class cloudkitty(
   $rabbit_heartbeat_in_pthread        = $facts['os_service_default'],
   $rabbit_ha_queues                   = $facts['os_service_default'],
   $rabbit_quorum_queue                = $facts['os_service_default'],
+  $rabbit_transient_queues_ttl        = $facts['os_service_default'],
   $rabbit_transient_quorum_queue      = $facts['os_service_default'],
   $rabbit_quorum_delivery_limit       = $facts['os_service_default'],
   $rabbit_quorum_max_memory_length    = $facts['os_service_default'],
@@ -217,6 +230,7 @@ class cloudkitty(
   $kombu_failover_strategy            = $facts['os_service_default'],
   $kombu_compression                  = $facts['os_service_default'],
   $amqp_durable_queues                = $facts['os_service_default'],
+  $amqp_auto_delete                   = $facts['os_service_default'],
   $default_transport_url              = $facts['os_service_default'],
   $rpc_response_timeout               = $facts['os_service_default'],
   $control_exchange                   = $facts['os_service_default'],
@@ -258,6 +272,7 @@ class cloudkitty(
     rabbit_ha_queues                => $rabbit_ha_queues,
     rabbit_use_ssl                  => $rabbit_use_ssl,
     amqp_durable_queues             => $amqp_durable_queues,
+    amqp_auto_delete                => $amqp_auto_delete,
     heartbeat_timeout_threshold     => $rabbit_heartbeat_timeout_threshold,
     heartbeat_rate                  => $rabbit_heartbeat_rate,
     heartbeat_in_pthread            => $rabbit_heartbeat_in_pthread,
@@ -270,6 +285,7 @@ class cloudkitty(
     kombu_compression               => $kombu_compression,
     rabbit_quorum_queue             => $rabbit_quorum_queue,
     rabbit_transient_quorum_queue   => $rabbit_transient_quorum_queue,
+    rabbit_transient_queues_ttl     => $rabbit_transient_queues_ttl,
     rabbit_quorum_delivery_limit    => $rabbit_quorum_delivery_limit,
     rabbit_quorum_max_memory_length => $rabbit_quorum_max_memory_length,
     rabbit_quorum_max_memory_bytes  => $rabbit_quorum_max_memory_bytes,
Index: puppet-module-cloudkitty/releasenotes/notes/amqp_auto_delete-b31f2692f860936b.yaml
===================================================================
--- /dev/null
+++ puppet-module-cloudkitty/releasenotes/notes/amqp_auto_delete-b31f2692f860936b.yaml
@@ -0,0 +1,5 @@
+---
+features:
+  - |
+    Add a new ``amqp_auto_delete`` parameter, so that transient queues are
+    automatically deleted.
Index: puppet-module-cloudkitty/releasenotes/notes/rabbit_transient_queues_ttl-fece011cafe302d4.yaml
===================================================================
--- /dev/null
+++ puppet-module-cloudkitty/releasenotes/notes/rabbit_transient_queues_ttl-fece011cafe302d4.yaml
@@ -0,0 +1,6 @@
+---
+features:
+  - |
+    A new parameter ``rabbit_transient_queues_ttl`` has been added to the
+    cloudkitty class to configure how long transtient queue should stay until
+    they are automatically deleted.
Index: puppet-module-cloudkitty/spec/classes/cloudkitty_init_spec.rb
===================================================================
--- puppet-module-cloudkitty.orig/spec/classes/cloudkitty_init_spec.rb
+++ puppet-module-cloudkitty/spec/classes/cloudkitty_init_spec.rb
@@ -35,6 +35,7 @@ describe 'cloudkitty' do
           :kombu_reconnect_delay           => '<SERVICE DEFAULT>',
           :kombu_failover_strategy         => '<SERVICE DEFAULT>',
           :amqp_durable_queues             => '<SERVICE DEFAULT>',
+          :amqp_auto_delete                => '<SERVICE DEFAULT>',
           :kombu_compression               => '<SERVICE DEFAULT>',
           :kombu_ssl_ca_certs              => '<SERVICE DEFAULT>',
           :kombu_ssl_certfile              => '<SERVICE DEFAULT>',
@@ -44,6 +45,7 @@ describe 'cloudkitty' do
           :rabbit_retry_interval           => '<SERVICE DEFAULT>',
           :rabbit_quorum_queue             => '<SERVICE DEFAULT>',
           :rabbit_transient_quorum_queue   => '<SERVICE DEFAULT>',
+          :rabbit_transient_queues_ttl     => '<SERVICE DEFAULT>',
           :rabbit_quorum_delivery_limit    => '<SERVICE DEFAULT>',
           :rabbit_quorum_max_memory_length => '<SERVICE DEFAULT>',
           :rabbit_quorum_max_memory_bytes  => '<SERVICE DEFAULT>',
@@ -79,12 +81,14 @@ describe 'cloudkitty' do
           :rabbit_heartbeat_in_pthread        => true,
           :rabbit_quorum_queue                => true,
           :rabbit_transient_quorum_queue      => false,
+          :rabbit_transient_queues_ttl        => 60,
           :rabbit_quorum_delivery_limit       => 3,
           :rabbit_quorum_max_memory_length    => 5,
           :rabbit_quorum_max_memory_bytes     => 1073741824,
           :rabbit_enable_cancel_on_failover   => false,
           :kombu_reconnect_delay              => 5.0,
           :amqp_durable_queues                => true,
+          :amqp_auto_delete                   => true,
           :kombu_compression                  => 'gzip',
           :package_ensure                     => '2012.1.1-15.el6',
           :default_transport_url              => 'rabbit://rabbit_user:password@localhost:5673',
@@ -111,10 +115,12 @@ describe 'cloudkitty' do
           :heartbeat_in_pthread            => true,
           :kombu_reconnect_delay           => 5.0,
           :amqp_durable_queues             => true,
+          :amqp_auto_delete                => true,
           :kombu_compression               => 'gzip',
           :rabbit_ha_queues                => true,
           :rabbit_quorum_queue             => true,
           :rabbit_transient_quorum_queue   => false,
+          :rabbit_transient_queues_ttl     => 60,
           :rabbit_quorum_delivery_limit    => 3,
           :rabbit_quorum_max_memory_length => 5,
           :rabbit_quorum_max_memory_bytes  => 1073741824,
