summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZuul <zuul@review.opendev.org>2020-08-24 23:51:33 +0000
committerGerrit Code Review <review@openstack.org>2020-08-24 23:51:33 +0000
commit24ae51f3286655af37489c672776d04e69cc2185 (patch)
treecf796fb11b77e3ce49c19bc4ae59e9a97cd1d6c9
parentc32454213e5aa1b6cda770f56ddef18f06c2c3c2 (diff)
parentf17252de50e857140c389f768caaff831e509ee7 (diff)
downloadtaskflow-24ae51f3286655af37489c672776d04e69cc2185.tar.gz
Merge "Add sentinel redis support"4.4.0
-rw-r--r--releasenotes/notes/add-sentinel-redis-support-9fd16e2a5dd5c0c9.yaml6
-rw-r--r--taskflow/jobs/backends/impl_redis.py15
-rw-r--r--taskflow/tests/unit/jobs/test_redis_job.py34
3 files changed, 54 insertions, 1 deletions
diff --git a/releasenotes/notes/add-sentinel-redis-support-9fd16e2a5dd5c0c9.yaml b/releasenotes/notes/add-sentinel-redis-support-9fd16e2a5dd5c0c9.yaml
new file mode 100644
index 0000000..9409fce
--- /dev/null
+++ b/releasenotes/notes/add-sentinel-redis-support-9fd16e2a5dd5c0c9.yaml
@@ -0,0 +1,6 @@
+---
+features:
+ - |
+ Allow to use Sentinel for Redis connections. New variable *sentinel* can be
+ passed to Redis jobboard. It is None by default, Sentinel name should be passed
+ to enable this functionality.
diff --git a/taskflow/jobs/backends/impl_redis.py b/taskflow/jobs/backends/impl_redis.py
index 7a006e2..66133fe 100644
--- a/taskflow/jobs/backends/impl_redis.py
+++ b/taskflow/jobs/backends/impl_redis.py
@@ -29,6 +29,7 @@ from oslo_utils import strutils
from oslo_utils import timeutils
from oslo_utils import uuidutils
from redis import exceptions as redis_exceptions
+from redis import sentinel
import six
from six.moves import range as compat_range
@@ -567,7 +568,19 @@ return cmsgpack.pack(result)
client_conf[key] = value_type_converter(conf[key])
else:
client_conf[key] = conf[key]
- return ru.RedisClient(**client_conf)
+ if conf.get('sentinel') is not None:
+ sentinel_conf = {}
+ # sentinel do not have ssl kwargs
+ for key in client_conf:
+ if 'ssl' not in key:
+ sentinel_conf[key] = client_conf[key]
+ s = sentinel.Sentinel([(sentinel_conf.pop('host'),
+ sentinel_conf.pop('port'))],
+ sentinel_kwargs=conf.get('sentinel_kwargs'),
+ **sentinel_conf)
+ return s.master_for(conf['sentinel'])
+ else:
+ return ru.RedisClient(**client_conf)
def __init__(self, name, conf,
client=None, persistence=None):
diff --git a/taskflow/tests/unit/jobs/test_redis_job.py b/taskflow/tests/unit/jobs/test_redis_job.py
index 2bde77f..9e6bdc7 100644
--- a/taskflow/tests/unit/jobs/test_redis_job.py
+++ b/taskflow/tests/unit/jobs/test_redis_job.py
@@ -15,6 +15,7 @@
# under the License.
import time
+from unittest import mock
from oslo_utils import uuidutils
import six
@@ -102,3 +103,36 @@ class RedisJobboardTest(test.TestCase, base.BoardTestMixin):
def setUp(self):
super(RedisJobboardTest, self).setUp()
self.client, self.board = self.create_board()
+
+ def test__make_client(self):
+ conf = {'host': '127.0.0.1',
+ 'port': 6379,
+ 'password': 'secret',
+ 'namespace': 'test'
+ }
+ test_conf = {
+ 'host': '127.0.0.1',
+ 'port': 6379,
+ 'password': 'secret',
+ }
+ with mock.patch('taskflow.utils.redis_utils.RedisClient') as mock_ru:
+ impl_redis.RedisJobBoard('test-board', conf)
+ mock_ru.assert_called_once_with(**test_conf)
+
+ def test__make_client_sentinel(self):
+ conf = {'host': '127.0.0.1',
+ 'port': 26379,
+ 'password': 'secret',
+ 'namespace': 'test',
+ 'sentinel': 'mymaster',
+ 'sentinel_kwargs': {'password': 'senitelsecret'}}
+ with mock.patch('redis.sentinel.Sentinel') as mock_sentinel:
+ impl_redis.RedisJobBoard('test-board', conf)
+ test_conf = {
+ 'password': 'secret',
+ }
+ mock_sentinel.assert_called_once_with(
+ [('127.0.0.1', 26379)],
+ sentinel_kwargs={'password': 'senitelsecret'},
+ **test_conf)
+ mock_sentinel().master_for.assert_called_once_with('mymaster')