Merge "Catch all exceptions in convert_ip_to_canonical_format"

This commit is contained in:
Zuul
2024-05-30 21:24:22 +00:00
committed by Gerrit Code Review
2 changed files with 11 additions and 1 deletions

View File

@@ -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

View File

@@ -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):