diff --git a/neutron_lib/api/converters.py b/neutron_lib/api/converters.py index e6fe33dce..c0d9daf91 100644 --- a/neutron_lib/api/converters.py +++ b/neutron_lib/api/converters.py @@ -218,7 +218,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 c7c25907b..c4da496de 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 TestConvertAllocationPoolsCanonicalFormat(base.BaseTestCase):