Merge "ipv6_utils: delete get_ipv6_addr_by_EUI64"
This commit is contained in:
commit
70462de005
|
@ -19,41 +19,17 @@ IPv6-related utilities and helper functions.
|
|||
import os
|
||||
|
||||
from debtcollector import moves
|
||||
from debtcollector import removals
|
||||
import netaddr
|
||||
from neutron_lib import constants as const
|
||||
from oslo_log import log
|
||||
|
||||
from neutron._i18n import _, _LI
|
||||
from neutron._i18n import _LI
|
||||
|
||||
|
||||
LOG = log.getLogger(__name__)
|
||||
_IS_IPV6_ENABLED = None
|
||||
|
||||
|
||||
@removals.remove(
|
||||
message="use get_ipv6_addr_by_EUI64 from oslo_utils.netutils",
|
||||
version="Newton",
|
||||
removal_version="Ocata")
|
||||
def get_ipv6_addr_by_EUI64(prefix, mac):
|
||||
# Check if the prefix is IPv4 address
|
||||
isIPv4 = netaddr.valid_ipv4(prefix)
|
||||
if isIPv4:
|
||||
msg = _("Unable to generate IP address by EUI64 for IPv4 prefix")
|
||||
raise TypeError(msg)
|
||||
try:
|
||||
eui64 = int(netaddr.EUI(mac).eui64())
|
||||
prefix = netaddr.IPNetwork(prefix)
|
||||
return netaddr.IPAddress(prefix.first + eui64 ^ (1 << 57))
|
||||
except (ValueError, netaddr.AddrFormatError):
|
||||
raise TypeError(_('Bad prefix or mac format for generating IPv6 '
|
||||
'address by EUI-64: %(prefix)s, %(mac)s:')
|
||||
% {'prefix': prefix, 'mac': mac})
|
||||
except TypeError:
|
||||
raise TypeError(_('Bad prefix type for generate IPv6 address by '
|
||||
'EUI-64: %s') % prefix)
|
||||
|
||||
|
||||
def is_enabled_and_bind_by_default():
|
||||
"""Check if host has the IPv6 support and is configured to bind IPv6
|
||||
address to new interfaces by default.
|
||||
|
|
|
@ -22,39 +22,6 @@ from neutron.tests import base
|
|||
from neutron.tests import tools
|
||||
|
||||
|
||||
class IPv6byEUI64TestCase(base.BaseTestCase):
|
||||
"""Unit tests for generate IPv6 by EUI-64 operations."""
|
||||
|
||||
def test_generate_IPv6_by_EUI64(self):
|
||||
addr = ipv6_utils.get_ipv6_addr_by_EUI64('2001:db8::',
|
||||
'00:16:3e:33:44:55')
|
||||
self.assertEqual('2001:db8::216:3eff:fe33:4455', addr.format())
|
||||
|
||||
def test_generate_IPv6_with_IPv4_prefix(self):
|
||||
ipv4_prefix = '10.0.8'
|
||||
mac = '00:16:3e:33:44:55'
|
||||
self.assertRaises(TypeError, lambda:
|
||||
ipv6_utils.get_ipv6_addr_by_EUI64(ipv4_prefix, mac))
|
||||
|
||||
def test_generate_IPv6_with_bad_mac(self):
|
||||
bad_mac = '00:16:3e:33:44:5Z'
|
||||
prefix = '2001:db8::'
|
||||
self.assertRaises(TypeError, lambda:
|
||||
ipv6_utils.get_ipv6_addr_by_EUI64(prefix, bad_mac))
|
||||
|
||||
def test_generate_IPv6_with_bad_prefix(self):
|
||||
mac = '00:16:3e:33:44:55'
|
||||
bad_prefix = 'bb'
|
||||
self.assertRaises(TypeError, lambda:
|
||||
ipv6_utils.get_ipv6_addr_by_EUI64(bad_prefix, mac))
|
||||
|
||||
def test_generate_IPv6_with_error_prefix_type(self):
|
||||
mac = '00:16:3e:33:44:55'
|
||||
prefix = 123
|
||||
self.assertRaises(TypeError, lambda:
|
||||
ipv6_utils.get_ipv6_addr_by_EUI64(prefix, mac))
|
||||
|
||||
|
||||
class TestIsEnabledAndBindByDefault(base.BaseTestCase):
|
||||
|
||||
def setUp(self):
|
||||
|
@ -134,12 +101,6 @@ class TestIsEui64Address(base.BaseTestCase):
|
|||
self.assertEqual(expected, ipv6_utils.is_eui64_address(ip),
|
||||
"Error on %s" % ip)
|
||||
|
||||
def test_valid_eui64_addresses(self):
|
||||
ips = ('fffe::0cad:12ff:fe44:5566',
|
||||
ipv6_utils.get_ipv6_addr_by_EUI64('2001:db8::',
|
||||
'00:16:3e:33:44:55'))
|
||||
self._test_eui_64(ips, True)
|
||||
|
||||
def test_invalid_eui64_addresses(self):
|
||||
ips = ('192.168.1.1',
|
||||
'192.168.1.0',
|
||||
|
|
Loading…
Reference in New Issue