diff --git a/releasenotes/notes/sentinel-use-redis-creds-63f58b12ad46a2b5.yaml b/releasenotes/notes/sentinel-use-redis-creds-63f58b12ad46a2b5.yaml new file mode 100644 index 000000000..aa4537a0c --- /dev/null +++ b/releasenotes/notes/sentinel-use-redis-creds-63f58b12ad46a2b5.yaml @@ -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``. diff --git a/taskflow/jobs/backends/impl_redis.py b/taskflow/jobs/backends/impl_redis.py index c7e538e1b..1beb42227 100644 --- a/taskflow/jobs/backends/impl_redis.py +++ b/taskflow/jobs/backends/impl_redis.py @@ -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: diff --git a/taskflow/tests/unit/jobs/test_redis_job.py b/taskflow/tests/unit/jobs/test_redis_job.py index f99a643c9..5a4a53b19 100644 --- a/taskflow/tests/unit/jobs/test_redis_job.py +++ b/taskflow/tests/unit/jobs/test_redis_job.py @@ -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')