From 27d43512f9005f330787480617b583980cd2e1d3 Mon Sep 17 00:00:00 2001
From: Takashi Kajinami <kajinamit@oss.nttdata.com>
Date: Wed, 13 Mar 2024 01:30:38 +0900
Subject: [PATCH] cache: Support new redis options

The oslo.cache 3.7.0 release introduced some options for redis backend
and redis sentinel backend. This introduces for these parameters.

Depneds-on: https://review.opendev.org/910629
Change-Id: I6e017f7349096fd298fd1b6f63de57046f0067d0
---
 manifests/cache.pp                            | 36 +++++++++++++++++++
 .../cache-redis-opts-d6ebee69d2a12f84.yaml    | 12 +++++++
 spec/classes/trove_cache_spec.rb              | 18 ++++++++++
 3 files changed, 66 insertions(+)
 create mode 100644 releasenotes/notes/cache-redis-opts-d6ebee69d2a12f84.yaml

diff --git a/manifests/cache.pp b/manifests/cache.pp
index 499d07ec..9e2797a7 100644
--- a/manifests/cache.pp
+++ b/manifests/cache.pp
@@ -120,6 +120,30 @@
 #   (Optional) The password for the memcached with SASL enabled
 #   Defaults to $facts['os_service_default']
 #
+# [*redis_server*]
+#   (Optional) Redis server in the format of "host:port".
+#   Defaults to $facts['os_service_default']
+#
+# [*redis_username*]
+#   (Optional) The user name for redis
+#   Defaults to $facts['os_service_default']
+#
+# [*redis_password*]
+#   (Optional) The password for redis
+#   Defaults to $facts['os_service_default']
+#
+# [*redis_sentinels*]
+#   (Optional) Redis sentinel servers in the format of host:port
+#   Defaults to $facts['os_service_default']
+#
+# [*redis_socket_timeout*]
+#   (Optional) Timeout in seconds for every call to a server
+#   Defaults to $facts['os_service_default']
+#
+# [*redis_sentinel_service_name*]
+#   (Optional) Service name of the redis sentinel cluster.
+#   Defaults to $facts['os_service_default']
+#
 # [*tls_enabled*]
 #   (Optional) Global toggle for TLS usage when communicating with
 #   the caching servers.
@@ -210,6 +234,12 @@ class trove::cache (
   $memcache_sasl_enabled                = $facts['os_service_default'],
   $memcache_username                    = $facts['os_service_default'],
   $memcache_password                    = $facts['os_service_default'],
+  $redis_server                         = $facts['os_service_default'],
+  $redis_username                       = $facts['os_service_default'],
+  $redis_password                       = $facts['os_service_default'],
+  $redis_sentinels                      = $facts['os_service_default'],
+  $redis_socket_timeout                 = $facts['os_service_default'],
+  $redis_sentinel_service_name          = $facts['os_service_default'],
   $tls_enabled                          = $facts['os_service_default'],
   $tls_cafile                           = $facts['os_service_default'],
   $tls_certfile                         = $facts['os_service_default'],
@@ -248,6 +278,12 @@ class trove::cache (
     memcache_sasl_enabled                => $memcache_sasl_enabled,
     memcache_username                    => $memcache_username,
     memcache_password                    => $memcache_password,
+    redis_server                         => $redis_server,
+    redis_username                       => $redis_username,
+    redis_password                       => $redis_password,
+    redis_sentinels                      => $redis_sentinels,
+    redis_socket_timeout                 => $redis_socket_timeout,
+    redis_sentinel_service_name          => $redis_sentinel_service_name,
     tls_enabled                          => $tls_enabled,
     tls_cafile                           => $tls_cafile,
     tls_certfile                         => $tls_certfile,
diff --git a/releasenotes/notes/cache-redis-opts-d6ebee69d2a12f84.yaml b/releasenotes/notes/cache-redis-opts-d6ebee69d2a12f84.yaml
new file mode 100644
index 00000000..37eb892f
--- /dev/null
+++ b/releasenotes/notes/cache-redis-opts-d6ebee69d2a12f84.yaml
@@ -0,0 +1,12 @@
+---
+features:
+  - |
+    The ``trove::cache`` class now supports the following new options for
+    Redis backend and Redis Sentinel backend.
+
+    - ``redis_server``
+    - ``redis_username``
+    - ``redis_password``
+    - ``redis_sentinels``
+    - ``redis_socket_timeout``
+    - ``redis_sentinel_service_name``
diff --git a/spec/classes/trove_cache_spec.rb b/spec/classes/trove_cache_spec.rb
index aeb2ceb8..de407c69 100644
--- a/spec/classes/trove_cache_spec.rb
+++ b/spec/classes/trove_cache_spec.rb
@@ -32,6 +32,12 @@ describe 'trove::cache' do
           :memcache_sasl_enabled                => '<SERVICE DEFAULT>',
           :memcache_username                    => '<SERVICE DEFAULT>',
           :memcache_password                    => '<SERVICE DEFAULT>',
+          :redis_server                         => '<SERVICE DEFAULT>',
+          :redis_username                       => '<SERVICE DEFAULT>',
+          :redis_password                       => '<SERVICE DEFAULT>',
+          :redis_sentinels                      => '<SERVICE DEFAULT>',
+          :redis_socket_timeout                 => '<SERVICE DEFAULT>',
+          :redis_sentinel_service_name          => '<SERVICE DEFAULT>',
           :tls_enabled                          => '<SERVICE DEFAULT>',
           :tls_cafile                           => '<SERVICE DEFAULT>',
           :tls_certfile                         => '<SERVICE DEFAULT>',
@@ -71,6 +77,12 @@ describe 'trove::cache' do
           :memcache_sasl_enabled                => false,
           :memcache_username                    => 'sasluser',
           :memcache_password                    => 'saslpass',
+          :redis_server                         => 'localhost:6379',
+          :redis_username                       => 'redisuser',
+          :redis_password                       => 'redispass',
+          :redis_sentinels                      => ['host1:26379', 'host2:26379'],
+          :redis_socket_timeout                 => 1.0,
+          :redis_sentinel_service_name          => 'mymaster',
           :tls_enabled                          => false,
           :enable_retry_client                  => false,
           :retry_attempts                       => 2,
@@ -105,6 +117,12 @@ describe 'trove::cache' do
           :memcache_sasl_enabled                => false,
           :memcache_username                    => 'sasluser',
           :memcache_password                    => 'saslpass',
+          :redis_server                         => 'localhost:6379',
+          :redis_username                       => 'redisuser',
+          :redis_password                       => 'redispass',
+          :redis_sentinels                      => ['host1:26379', 'host2:26379'],
+          :redis_socket_timeout                 => 1.0,
+          :redis_sentinel_service_name          => 'mymaster',
           :tls_enabled                          => false,
           :tls_cafile                           => '<SERVICE DEFAULT>',
           :tls_certfile                         => '<SERVICE DEFAULT>',