Skip to content

Commit

Permalink
Use oslo.utils method to parse server format
Browse files Browse the repository at this point in the history
The oslo.utils library is already required via some of the current
dependencies (eg. tooz). Use the utility method from it to parse
host:port format instead of carrying our own method.
  • Loading branch information
kajinamit committed Oct 1, 2024
1 parent abd2359 commit e578745
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
16 changes: 5 additions & 11 deletions gnocchi/common/redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@
# License for the specific language governing permissions and limitations
# under the License.

import re

from oslo_config import cfg
from oslo_utils import netutils
from urllib import parse

try:
Expand Down Expand Up @@ -120,15 +119,10 @@


def _parse_sentinel(sentinel):
# IPv6 (eg. [::1]:6379 )
match = re.search(r'^\[(\S+)\]:(\d+)$', sentinel)
if match:
return (match[1], int(match[2]))
# IPv4 or hostname (eg. 127.0.0.1:6379 or localhost:6379)
match = re.search(r'^(\S+):(\d+)$', sentinel)
if match:
return (match[1], int(match[2]))
raise ValueError('Malformed sentinel server format')
host, port = netutils.parse_host_port(sentinel)
if host is None or port is None:
raise ValueError('Malformed sentinel server format')
return (host, port)


def get_client(conf, scripts=None):
Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ install_requires =
oslo.config>=3.22.0
oslo.policy>=3.5.0
oslo.middleware>=3.22.0
oslo.utils>=1.1.1
pytimeparse
pecan>=0.9
jsonpatch
Expand Down

0 comments on commit e578745

Please sign in to comment.