From c1247116c9541be38b615effdc05d9df92e6e14f Mon Sep 17 00:00:00 2001 From: Takashi Kajinami Date: Sun, 6 Oct 2024 00:40:38 +0900 Subject: [PATCH] Use oslo.utils implementation to parse server format ... to simplify the logic maintained specifically in this repo. Change-Id: Ie60f2c04dbd300695e5ad3abe33d7682ba3c843e --- zaqar/storage/redis/driver.py | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/zaqar/storage/redis/driver.py b/zaqar/storage/redis/driver.py index 173299008..b655e9692 100644 --- a/zaqar/storage/redis/driver.py +++ b/zaqar/storage/redis/driver.py @@ -13,6 +13,7 @@ # limitations under the License. from oslo_log import log as logging +from oslo_utils import netutils from osprofiler import profiler import redis import redis.sentinel @@ -96,24 +97,12 @@ 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(','): - 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: - port = int(port) - except ValueError: - msg = _('The Redis configuration URI contains an ' - 'invalid port') - raise errors.ConfigurationError(msg) - else: - port = SENTINEL_DEFAULT_PORT + try: + name, port = netutils.parse_host_port( + each_host, SENTINEL_DEFAULT_PORT) + except ValueError: + raise errors.ConfigurationError( + 'invalid redis server format %s' % each_host) self.sentinels.append((name, port))