diff --git a/neutron_lib/api/converters.py b/neutron_lib/api/converters.py index e8fd00d45..18d4ab835 100644 --- a/neutron_lib/api/converters.py +++ b/neutron_lib/api/converters.py @@ -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 diff --git a/neutron_lib/tests/unit/api/test_converters.py b/neutron_lib/tests/unit/api/test_converters.py index 469ff4a8b..0ab61c5d3 100644 --- a/neutron_lib/tests/unit/api/test_converters.py +++ b/neutron_lib/tests/unit/api/test_converters.py @@ -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):