Use is_valid_ipv4 in get_ipv6_addr_by_EUI64
In netaddr module, method valid_ipv4 raise exception AddrFormatError if parameter is specified as empty string. Method is_valid_ipv4 returns False in this case. We should use it to avoid raising exception AddrFormatError to caller. Change-Id: Ic983fcb7bcb9cb957333979a6604768b921e4969
This commit is contained in:
parent
98e24bedf3
commit
3f7808119c
@ -151,7 +151,7 @@ def get_ipv6_addr_by_EUI64(prefix, mac):
|
|||||||
.. versionadded:: 1.4
|
.. versionadded:: 1.4
|
||||||
"""
|
"""
|
||||||
# Check if the prefix is an IPv4 address
|
# Check if the prefix is an IPv4 address
|
||||||
if netaddr.valid_ipv4(prefix):
|
if is_valid_ipv4(prefix):
|
||||||
msg = _("Unable to generate IP address by EUI64 for IPv4 prefix")
|
msg = _("Unable to generate IP address by EUI64 for IPv4 prefix")
|
||||||
raise ValueError(msg)
|
raise ValueError(msg)
|
||||||
try:
|
try:
|
||||||
|
@ -317,6 +317,12 @@ class IPv6byEUI64TestCase(test_base.BaseTestCase):
|
|||||||
self.assertRaises(TypeError, lambda:
|
self.assertRaises(TypeError, lambda:
|
||||||
netutils.get_ipv6_addr_by_EUI64(prefix, mac))
|
netutils.get_ipv6_addr_by_EUI64(prefix, mac))
|
||||||
|
|
||||||
|
def test_generate_IPv6_with_empty_prefix(self):
|
||||||
|
mac = '00:16:3e:33:44:55'
|
||||||
|
prefix = ''
|
||||||
|
self.assertRaises(ValueError, lambda:
|
||||||
|
netutils.get_ipv6_addr_by_EUI64(prefix, mac))
|
||||||
|
|
||||||
|
|
||||||
@contextlib.contextmanager
|
@contextlib.contextmanager
|
||||||
def mock_file_content(content):
|
def mock_file_content(content):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user