Handle ValueError in canonical address convertion
netaddr.IPAddress raises ValueError for some unsupported address formats. This patch will catch this exception in addition to AddrFormatError. Closes-Bug: 1807394 Change-Id: I06eea42906f1fe4443fa4959e79a1993a9664efe
This commit is contained in:
parent
17707f50dd
commit
532b398b90
|
@ -192,7 +192,7 @@ def convert_ip_to_canonical_format(value):
|
|||
ip = netaddr.IPAddress(value)
|
||||
if ip.version == constants.IP_VERSION_6:
|
||||
return six.text_type(ip.format(dialect=netaddr.ipv6_compact))
|
||||
except netaddr.core.AddrFormatError:
|
||||
except (netaddr.core.AddrFormatError, ValueError):
|
||||
pass
|
||||
return value
|
||||
|
||||
|
|
|
@ -202,6 +202,12 @@ class TestConvertIPv6AddrCanonicalFormat(base.BaseTestCase):
|
|||
def test_convert_invalid_address(self):
|
||||
result = converters.convert_ip_to_canonical_format("on")
|
||||
self.assertEqual("on", result)
|
||||
result = converters.convert_ip_to_canonical_format(
|
||||
u'192.168.1.1/32')
|
||||
self.assertEqual(u'192.168.1.1/32', result)
|
||||
result = converters.convert_ip_to_canonical_format(
|
||||
u'2001:db8:0:1:1:1:1:1/128')
|
||||
self.assertEqual(u'2001:db8:0:1:1:1:1:1/128', result)
|
||||
|
||||
|
||||
class TestConvertIPv6CIDRCanonicalFormat(base.BaseTestCase):
|
||||
|
|
Loading…
Reference in New Issue