Use consistent credential for Redis and Redis Sentinel
We generally expects that users enabled authentication both in Redis and Redis Sentinel at the same time, and it'd be more reasonable to use the same credential by default. This behavior is more consistent with the other libraries used in tooz or dogpile.cache, which are used in multiple OpenStack services. Change-Id: Ie8c96415f72bbd5f11f908bb9f96242d57b2bd4e
This commit is contained in:
parent
14444acab8
commit
3fbd05078f
@ -0,0 +1,11 @@
|
||||
---
|
||||
features:
|
||||
- |
|
||||
Now the redis driver uses the credential for redis servers in connections
|
||||
to Redis Sentinel servers.
|
||||
|
||||
upgrade:
|
||||
- |
|
||||
Now the redis driver uses the same credentials as redis by default. If
|
||||
a different credentials need to be used, override these via
|
||||
``sentinel_kwargs``.
|
@ -569,8 +569,12 @@ return cmsgpack.pack(result)
|
||||
client_conf[key] = conf[key]
|
||||
if conf.get('sentinel') is not None:
|
||||
sentinels = [(client_conf.pop('host'), client_conf.pop('port'))]
|
||||
sentinel_kwargs = conf.get('sentinel_kwargs', {})
|
||||
for key in ('username', 'password', 'socket_timeout'):
|
||||
if key in conf:
|
||||
sentinel_kwargs.setdefault(key, conf[key])
|
||||
s = sentinel.Sentinel(sentinels,
|
||||
sentinel_kwargs=conf.get('sentinel_kwargs'),
|
||||
sentinel_kwargs=sentinel_kwargs,
|
||||
**client_conf)
|
||||
return s.master_for(conf['sentinel'])
|
||||
else:
|
||||
|
@ -128,7 +128,7 @@ class RedisJobboardTest(test.TestCase, base.BoardTestMixin):
|
||||
'namespace': 'test',
|
||||
'sentinel': 'mymaster',
|
||||
'sentinel_kwargs': {
|
||||
'username': 'default',
|
||||
'username': 'sentineluser',
|
||||
'password': 'senitelsecret'
|
||||
}}
|
||||
with mock.patch('redis.sentinel.Sentinel') as mock_sentinel:
|
||||
@ -140,7 +140,7 @@ class RedisJobboardTest(test.TestCase, base.BoardTestMixin):
|
||||
mock_sentinel.assert_called_once_with(
|
||||
[('127.0.0.1', 26379)],
|
||||
sentinel_kwargs={
|
||||
'username': 'default',
|
||||
'username': 'sentineluser',
|
||||
'password': 'senitelsecret'
|
||||
},
|
||||
**test_conf)
|
||||
@ -153,7 +153,6 @@ class RedisJobboardTest(test.TestCase, base.BoardTestMixin):
|
||||
'password': 'secret',
|
||||
'namespace': 'test',
|
||||
'sentinel': 'mymaster',
|
||||
'sentinel_kwargs': {'password': 'senitelsecret'},
|
||||
'ssl': True,
|
||||
'ssl_ca_certs': '/etc/ssl/certs'}
|
||||
with mock.patch('redis.sentinel.Sentinel') as mock_sentinel:
|
||||
@ -166,6 +165,7 @@ class RedisJobboardTest(test.TestCase, base.BoardTestMixin):
|
||||
}
|
||||
mock_sentinel.assert_called_once_with(
|
||||
[('127.0.0.1', 26379)],
|
||||
sentinel_kwargs={'password': 'senitelsecret'},
|
||||
sentinel_kwargs={
|
||||
'username': 'default', 'password': 'secret'},
|
||||
**test_conf)
|
||||
mock_sentinel().master_for.assert_called_once_with('mymaster')
|
||||
|
Loading…
Reference in New Issue
Block a user