Correct the IPv6 address and port parsing
There can be lot of possibility for IPv6 address with port,
for example [::1]:80 or [2001:db8:85a3::8a2e:370]:7334.
Parsing that in more standard way is provided by oslo_uilts.netutils
parse_host_port() method[1].
Also unquote '[]' the SERVICE_HOST in case of IPv6 case so that
DB can listen on correct address.
Story: #2006309
Task: #36028
[1] 1b8bafb391/oslo_utils/netutils.py (L37)
Change-Id: I2d0ef40ab71f60564549d031185f99bc7eec40a7
This commit is contained in:

committed by
Witold Bedyk

parent
ce93e00050
commit
159bc64f41
@@ -837,8 +837,8 @@ function configure_monasca_api_python {
|
|||||||
# databases
|
# databases
|
||||||
iniset "$MONASCA_API_CONF" database connection $dbAlarmUrl
|
iniset "$MONASCA_API_CONF" database connection $dbAlarmUrl
|
||||||
iniset "$MONASCA_API_CONF" repositories metrics_driver $dbMetricDriver
|
iniset "$MONASCA_API_CONF" repositories metrics_driver $dbMetricDriver
|
||||||
iniset "$MONASCA_API_CONF" cassandra contact_points $SERVICE_HOST
|
iniset "$MONASCA_API_CONF" cassandra contact_points $(ipv6_unquote $SERVICE_HOST)
|
||||||
iniset "$MONASCA_API_CONF" influxdb ip_address $SERVICE_HOST
|
iniset "$MONASCA_API_CONF" influxdb ip_address $(ipv6_unquote $SERVICE_HOST)
|
||||||
iniset "$MONASCA_API_CONF" influxdb port 8086
|
iniset "$MONASCA_API_CONF" influxdb port 8086
|
||||||
|
|
||||||
# keystone & security
|
# keystone & security
|
||||||
|
@@ -14,6 +14,7 @@
|
|||||||
|
|
||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
from oslo_config import types
|
from oslo_config import types
|
||||||
|
from oslo_utils import netutils
|
||||||
|
|
||||||
|
|
||||||
class HostAddressPortOpt(cfg.Opt):
|
class HostAddressPortOpt(cfg.Opt):
|
||||||
@@ -36,7 +37,11 @@ class HostAddressPortType(types.HostAddress):
|
|||||||
super(HostAddressPortType, self).__init__(version, type_name=type_name)
|
super(HostAddressPortType, self).__init__(version, type_name=type_name)
|
||||||
|
|
||||||
def __call__(self, value):
|
def __call__(self, value):
|
||||||
addr, port = value.split(':')
|
addr, port = netutils.parse_host_port(value)
|
||||||
|
# NOTE(gmann): parse_host_port() return port as None if no port is
|
||||||
|
# supplied in value so setting port as string for correct
|
||||||
|
# parsing and error otherwise it will not be parsed for NoneType.
|
||||||
|
port = 'None' if port is None else port
|
||||||
addr = self.validate_addr(addr)
|
addr = self.validate_addr(addr)
|
||||||
port = self._validate_port(port)
|
port = self._validate_port(port)
|
||||||
if not addr and not port:
|
if not addr and not port:
|
||||||
|
@@ -30,6 +30,13 @@ class TestHostAddressPortType(base.BaseTestCase):
|
|||||||
def test_hostname(self):
|
def test_hostname(self):
|
||||||
self.assertEqual('localhost:2121', self.types('localhost:2121'))
|
self.assertEqual('localhost:2121', self.types('localhost:2121'))
|
||||||
|
|
||||||
|
def test_ipv6_address(self):
|
||||||
|
self.assertEqual('2001:db8:85a3::8a2e:370:2121',
|
||||||
|
self.types('[2001:db8:85a3::8a2e:370]:2121'))
|
||||||
|
|
||||||
|
def test_ipv6_hostname(self):
|
||||||
|
self.assertEqual('::1:2121', self.types('[::1]:2121'))
|
||||||
|
|
||||||
# failure scenario
|
# failure scenario
|
||||||
def test_missing_port(self):
|
def test_missing_port(self):
|
||||||
self.assertRaises(ValueError, self.types, '127.0.0.1')
|
self.assertRaises(ValueError, self.types, '127.0.0.1')
|
||||||
@@ -40,6 +47,9 @@ class TestHostAddressPortType(base.BaseTestCase):
|
|||||||
def test_incorrect_ip(self):
|
def test_incorrect_ip(self):
|
||||||
self.assertRaises(ValueError, self.types, '127.surprise.0.1:2121')
|
self.assertRaises(ValueError, self.types, '127.surprise.0.1:2121')
|
||||||
|
|
||||||
|
def test_incorrect_ipv6(self):
|
||||||
|
self.assertRaises(ValueError, self.types, '[2001:db8:8a2e:370]:2121')
|
||||||
|
|
||||||
def test_incorrect_port(self):
|
def test_incorrect_port(self):
|
||||||
self.assertRaises(ValueError, self.types, '127.0.0.1:65536')
|
self.assertRaises(ValueError, self.types, '127.0.0.1:65536')
|
||||||
self.assertRaises(ValueError, self.types, '127.0.0.1:sample')
|
self.assertRaises(ValueError, self.types, '127.0.0.1:sample')
|
||||||
|
Reference in New Issue
Block a user