From adb551c05d5b41af10b1c21b814669b7570154da Mon Sep 17 00:00:00 2001 From: Takashi Kajinami Date: Wed, 28 Feb 2024 15:38:43 +0900 Subject: [PATCH] Redis Sentinel: Use dogpile.cache interface for username digpile.cache 1.3.1 introduced the new username argument to the Redis Sentinel backend[1]. This interface can be used instead of directly injecting username into connection/sentinel_kwargs. [1] https://github.com/sqlalchemy/dogpile.cache/commit/6cbc6ad9d2c0900e102b3a46690380c4a6505b86 Change-Id: I2f6c13050e30ef829c545e5019aca5fc4de97dbb --- oslo_cache/core.py | 9 +-------- oslo_cache/tests/unit/test_cache_basics.py | 8 ++------ requirements.txt | 2 +- 3 files changed, 4 insertions(+), 15 deletions(-) diff --git a/oslo_cache/core.py b/oslo_cache/core.py index a97780d3..e8b10bc5 100644 --- a/oslo_cache/core.py +++ b/oslo_cache/core.py @@ -175,16 +175,9 @@ def _build_cache_config(conf): value = getattr(conf.cache, 'redis_' + arg) conf_dict['%s.arguments.%s' % (prefix, arg)] = value elif conf.cache.backend == 'dogpile.cache.redis_sentinel': - for arg in ('password', 'socket_timeout'): + for arg in ('username', 'password', 'socket_timeout'): value = getattr(conf.cache, 'redis_' + arg) conf_dict['%s.arguments.%s' % (prefix, arg)] = value - if conf.cache.redis_username: - # TODO(tkajinam): Update dogpile.cache to add username argument, - # similarly to password. - conf_dict['%s.arguments.connection_kwargs' % prefix] = \ - {'username': conf.cache.redis_username} - conf_dict['%s.arguments.sentinel_kwargs' % prefix] = \ - {'username': conf.cache.redis_username} conf_dict['%s.arguments.service_name' % prefix] = \ conf.cache.redis_sentinel_service_name if conf.cache.redis_sentinels: diff --git a/oslo_cache/tests/unit/test_cache_basics.py b/oslo_cache/tests/unit/test_cache_basics.py index aa51a071..083dc5ce 100644 --- a/oslo_cache/tests/unit/test_cache_basics.py +++ b/oslo_cache/tests/unit/test_cache_basics.py @@ -830,14 +830,10 @@ class CacheRegionTest(test_cache.BaseTestCase): ('::1', 26379), ('localhost', 26379), ], config_dict['test_prefix.arguments.sentinels']) + self.assertEqual( + 'user', config_dict['test_prefix.arguments.username']) self.assertEqual( 'secrete', config_dict['test_prefix.arguments.password']) - self.assertEqual({ - 'username': 'user' - }, config_dict['test_prefix.arguments.connection_kwargs']) - self.assertEqual({ - 'username': 'user' - }, config_dict['test_prefix.arguments.sentinel_kwargs']) def test_cache_debug_proxy(self): single_value = 'Test Value' diff --git a/requirements.txt b/requirements.txt index 410731a3..fa24c25c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -dogpile.cache>=1.1.5 # BSD +dogpile.cache>=1.3.1 # BSD oslo.config>=8.1.0 # Apache-2.0 oslo.i18n>=5.0.0 # Apache-2.0 oslo.log>=4.2.1 # Apache-2.0