Catch all exceptions in convert_ip_to_canonical_format
Recent netaddr started to raise AttributeError for subnetpools values like [{'start': ..., 'end': ...}]. The converter is meant to be graceful towards inputs that are not proper ip addresses. Instead of adding another exception type to the list and hope that the list of expected types covers everything netaddr may raise, this patch makes the converter catch all exceptions. Change-Id: I967032c1dea690cd9da95ad3a8e382671186d971
This commit is contained in:
@@ -196,7 +196,12 @@ def convert_ip_to_canonical_format(value):
|
||||
ip = netaddr.IPAddress(value)
|
||||
if ip.version == constants.IP_VERSION_6:
|
||||
return str(ip.format(dialect=netaddr.ipv6_compact))
|
||||
except (netaddr.core.AddrFormatError, ValueError):
|
||||
except Exception: # nosec B110
|
||||
# netaddr may raise all kinds of exceptions (ValueError,
|
||||
# AttributeError...) if the input is not a valid IP address. Instead of
|
||||
# catching them one by one, just catch all exceptions at once.
|
||||
# Obviously, it would be better if netaddr raised a particular
|
||||
# exception specific to the library. But we don't control it.
|
||||
pass
|
||||
return value
|
||||
|
||||
|
@@ -209,6 +209,11 @@ class TestConvertIPv6AddrCanonicalFormat(base.BaseTestCase):
|
||||
'2001:db8:0:1:1:1:1:1/128')
|
||||
self.assertEqual('2001:db8:0:1:1:1:1:1/128', result)
|
||||
|
||||
def test_convert_subnetpools(self):
|
||||
pools = [{'start': '1.1.1.1', 'end': '1.1.1.100'}]
|
||||
result = converters.convert_ip_to_canonical_format(pools)
|
||||
self.assertEqual(pools, result)
|
||||
|
||||
|
||||
class TestConvertIPv6CIDRCanonicalFormat(base.BaseTestCase):
|
||||
|
||||
|
Reference in New Issue
Block a user