From c1d918bf98e3d4fb5f520a79079944248e651608 Mon Sep 17 00:00:00 2001
From: Thomas Goirand <zigo@debian.org>
Date: Tue, 18 Mar 2025 09:23:11 +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 magnum_config to set it, so this patch is mandatory
for one to set rabbit_transient_queues_ttl in magnum.conf.

Change-Id: Ie5612a156c0d428df7efbe8e762f467050c3e3d6
---

Index: puppet-module-magnum/manifests/init.pp
===================================================================
--- puppet-module-magnum.orig/manifests/init.pp
+++ puppet-module-magnum/manifests/init.pp
@@ -85,6 +85,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
@@ -147,6 +155,10 @@
 #   (Optional) Use durable queues in amqp.
 #   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']
+#
 # [*purge_config*]
 #  (Optional) Whether to set only the specified config options
 #  in the magnum config.
@@ -167,6 +179,7 @@ class magnum(
   $rabbit_heartbeat_in_pthread        = $facts['os_service_default'],
   $rabbit_qos_prefetch_count          = $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'],
@@ -181,6 +194,7 @@ class magnum(
   $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'],
   Boolean $purge_config               = false,
 ) {
 
@@ -213,9 +227,11 @@ class magnum(
     kombu_ssl_certfile              => $kombu_ssl_certfile,
     kombu_ssl_ca_certs              => $kombu_ssl_ca_certs,
     amqp_durable_queues             => $amqp_durable_queues,
+    amqp_auto_delete                => $amqp_auto_delete,
     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-magnum/releasenotes/notes/amqp_auto_delete-9b88003515741593.yaml
===================================================================
--- /dev/null
+++ puppet-module-magnum/releasenotes/notes/amqp_auto_delete-9b88003515741593.yaml
@@ -0,0 +1,5 @@
+---
+features:
+  - |
+    Add a new ``amqp_auto_delete`` parameter, so that transient queues are
+    automatically deleted.
Index: puppet-module-magnum/releasenotes/notes/rabbit_transient_queues_ttl-483107926cbdf369.yaml
===================================================================
--- /dev/null
+++ puppet-module-magnum/releasenotes/notes/rabbit_transient_queues_ttl-483107926cbdf369.yaml
@@ -0,0 +1,6 @@
+---
+features:
+  - |
+    A new parameter ``rabbit_transient_queues_ttl`` has been added to the
+    magnum class to configure how long transtient queue should stay until
+    they are automatically deleted.
Index: puppet-module-magnum/spec/classes/magnum_init_spec.rb
===================================================================
--- puppet-module-magnum.orig/spec/classes/magnum_init_spec.rb
+++ puppet-module-magnum/spec/classes/magnum_init_spec.rb
@@ -45,9 +45,11 @@ describe 'magnum' do
           :kombu_ssl_certfile              => '<SERVICE DEFAULT>',
           :kombu_ssl_ca_certs              => '<SERVICE DEFAULT>',
           :amqp_durable_queues             => '<SERVICE DEFAULT>',
+          :amqp_auto_delete                => '<SERVICE DEFAULT>',
           :kombu_compression               => '<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>',
@@ -83,8 +85,10 @@ describe 'magnum' do
           :rabbit_heartbeat_in_pthread        => true,
           :rabbit_qos_prefetch_count          => 0,
           :amqp_durable_queues                => true,
+          :amqp_auto_delete                   => true,
           :rabbit_quorum_queue                => true,
           :rabbit_transient_quorum_queue      => true,
+          :rabbit_transient_queues_ttl        => 60,
           :rabbit_quorum_delivery_limit       => 3,
           :rabbit_quorum_max_memory_length    => 5,
           :rabbit_quorum_max_memory_bytes     => 1073741824,
@@ -120,9 +124,11 @@ describe 'magnum' do
           :kombu_ssl_certfile              => '<SERVICE DEFAULT>',
           :kombu_ssl_ca_certs              => '<SERVICE DEFAULT>',
           :amqp_durable_queues             => true,
+          :amqp_auto_delete                => true,
           :kombu_compression               => '<SERVICE DEFAULT>',
           :rabbit_quorum_queue             => true,
           :rabbit_transient_quorum_queue   => true,
+          :rabbit_transient_queues_ttl     => 60,
           :rabbit_quorum_delivery_limit    => 3,
           :rabbit_quorum_max_memory_length => 5,
           :rabbit_quorum_max_memory_bytes  => 1073741824,
