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] 6cbc6ad9d2

Change-Id: I2f6c13050e30ef829c545e5019aca5fc4de97dbb
This commit is contained in:
Takashi Kajinami 2024-02-28 15:38:43 +09:00
parent e8de6c9ea5
commit adb551c05d
3 changed files with 4 additions and 15 deletions

View File

@ -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:

View File

@ -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'

View File

@ -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