Fix invalid parsing of IPv6 address in sentinel server
Ensure IPv6 address is not incorrectly split to look up port, in case the address is surrounded by []. Change-Id: I0750838b0ab00c5cbabb16e177906335f369ab5d
This commit is contained in:
parent
b59385e3f8
commit
70d2f725fe
@ -36,7 +36,7 @@ STRATEGY_SENTINEL = 3
|
||||
|
||||
|
||||
class ConnectionURI(object):
|
||||
def __init__(self, uri):
|
||||
def __init__(self, uri): # noqa: C901
|
||||
# TODO(prashanthr_): Add SSL support
|
||||
try:
|
||||
parsed_url = urllib.parse.urlparse(uri)
|
||||
@ -89,7 +89,14 @@ class ConnectionURI(object):
|
||||
# NOTE(kgriffs): Have to parse list of sentinel hosts ourselves
|
||||
# since urllib doesn't support it.
|
||||
for each_host in netloc.split(','):
|
||||
name, sep, port = each_host.partition(':')
|
||||
if not each_host.endswith(']') and ':' in each_host:
|
||||
name, sep, port = each_host.rpartition(':')
|
||||
else:
|
||||
name = each_host
|
||||
port = None
|
||||
|
||||
if name.startswith('[') and name.endswith(']'):
|
||||
name = name[1:-1]
|
||||
|
||||
if port:
|
||||
try:
|
||||
@ -98,7 +105,6 @@ class ConnectionURI(object):
|
||||
msg = _('The Redis configuration URI contains an '
|
||||
'invalid port')
|
||||
raise errors.ConfigurationError(msg)
|
||||
|
||||
else:
|
||||
port = SENTINEL_DEFAULT_PORT
|
||||
|
||||
|
@ -290,6 +290,13 @@ class RedisDriverTest(testing.TestBase):
|
||||
self.assertEqual('dumbledore', uri.master)
|
||||
self.assertEqual(0.1, uri.socket_timeout)
|
||||
|
||||
uri = driver.ConnectionURI(
|
||||
'redis://[::1]:26389,[::2]?master=dumbledore')
|
||||
self.assertEqual(driver.STRATEGY_SENTINEL, uri.strategy)
|
||||
self.assertEqual([('::1', 26389), ('::2', 26379)], uri.sentinels)
|
||||
self.assertEqual('dumbledore', uri.master)
|
||||
self.assertEqual(0.1, uri.socket_timeout)
|
||||
|
||||
uri = driver.ConnectionURI(
|
||||
'redis://s1?master=dumbledore&socket_timeout=0.5')
|
||||
self.assertEqual(driver.STRATEGY_SENTINEL, uri.strategy)
|
||||
|
Loading…
Reference in New Issue
Block a user