From f3c6c1965e5fd04defd5733ab69e08f8b4c17525 Mon Sep 17 00:00:00 2001 From: Matus Valo Date: Thu, 24 Sep 2020 01:39:45 +0200 Subject: [PATCH 1/2] Redis Sentinel connection string now supports default sentinel port --- kombu/transport/redis.py | 3 ++- t/unit/transport/test_redis.py | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/kombu/transport/redis.py b/kombu/transport/redis.py index f8ce7b46c..e3ce8d372 100644 --- a/kombu/transport/redis.py +++ b/kombu/transport/redis.py @@ -1134,7 +1134,8 @@ def _sentinel_managed_pool(self, asynchronous=False): for url in self.connection.client.alt: url = _parse_url(url) if url.scheme == 'sentinel': - sentinels.append((url.hostname, url.port)) + port = url.port or self.connection.default_port + sentinels.append((url.hostname, port)) # Fallback for when only one sentinel is provided. if not sentinels: diff --git a/t/unit/transport/test_redis.py b/t/unit/transport/test_redis.py index 59c95acf7..1ae9051b2 100644 --- a/t/unit/transport/test_redis.py +++ b/t/unit/transport/test_redis.py @@ -1410,6 +1410,7 @@ def test_method_called(self): def test_getting_master_from_sentinel(self): with patch('redis.sentinel.Sentinel') as patched: connection = Connection( + 'sentinel://localhost/;' 'sentinel://localhost:65532/;' 'sentinel://user@localhost:65533/;' 'sentinel://:password@localhost:65534/;' @@ -1422,6 +1423,7 @@ def test_getting_master_from_sentinel(self): connection.channel() patched.assert_called_once_with( [ + ('localhost', 26379), ('localhost', 65532), ('localhost', 65533), ('localhost', 65534), From 81c1401b16a69e9400b5870e69112582142eb743 Mon Sep 17 00:00:00 2001 From: Matus Valo Date: Thu, 24 Sep 2020 01:54:06 +0200 Subject: [PATCH 2/2] Raise ValueError when SentinelChannel is missing master_name transport option --- kombu/transport/redis.py | 5 +++++ t/unit/transport/test_redis.py | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/kombu/transport/redis.py b/kombu/transport/redis.py index e3ce8d372..52aed58b4 100644 --- a/kombu/transport/redis.py +++ b/kombu/transport/redis.py @@ -1149,6 +1149,11 @@ def _sentinel_managed_pool(self, asynchronous=False): master_name = getattr(self, 'master_name', None) + if master_name is None: + raise ValueError( + "'master_name' transport option must be specified." + ) + return sentinel_inst.master_for( master_name, self.Client, diff --git a/t/unit/transport/test_redis.py b/t/unit/transport/test_redis.py index 1ae9051b2..43a1efa1a 100644 --- a/t/unit/transport/test_redis.py +++ b/t/unit/transport/test_redis.py @@ -1474,3 +1474,13 @@ def test_can_create_connection(self): ) with pytest.raises(ConnectionError): connection.channel() + + def test_missing_master_name_transport_option(self): + connection = Connection( + 'sentinel://localhost:65534/', + ) + with patch('redis.sentinel.Sentinel'), \ + pytest.raises(ValueError) as excinfo: + connection.connect() + expected = "'master_name' transport option must be specified." + assert expected == excinfo.value.args[0]