Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redis Transport: Small improvements of SentinelChannel #1253

Merged
merged 2 commits into from
Sep 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion kombu/transport/redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -1148,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,
Expand Down
12 changes: 12 additions & 0 deletions t/unit/transport/test_redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -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/;'
Expand All @@ -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),
Expand Down Expand Up @@ -1472,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]