Remove method get_ipv6_addr_by_EUI64
oslo_utils.netutils provides same method get_ipv6_addr_by_EUI64 Change-Id: Ibc615d652be4594748188170764adb5d9fd0473b
This commit is contained in:
parent
b39e6b25c9
commit
712dafab0d
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
upgrade:
|
||||||
|
- |
|
||||||
|
Remove deprecated get_ipv6_addr_by_EUI64 method from data_utils.
|
||||||
|
Use the same method from oslo_utils.netutils.
|
@ -18,9 +18,6 @@ import random
|
|||||||
import string
|
import string
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from debtcollector import removals
|
|
||||||
import netaddr
|
|
||||||
from oslo_utils import netutils
|
|
||||||
from oslo_utils import uuidutils
|
from oslo_utils import uuidutils
|
||||||
import six.moves
|
import six.moves
|
||||||
|
|
||||||
@ -177,36 +174,6 @@ def random_bytes(size=1024):
|
|||||||
for i in range(size)])
|
for i in range(size)])
|
||||||
|
|
||||||
|
|
||||||
@removals.remove(
|
|
||||||
message="use get_ipv6_addr_by_EUI64 from oslo_utils.netutils",
|
|
||||||
version="Newton",
|
|
||||||
removal_version="Ocata")
|
|
||||||
def get_ipv6_addr_by_EUI64(cidr, mac):
|
|
||||||
"""Generate a IPv6 addr by EUI-64 with CIDR and MAC
|
|
||||||
|
|
||||||
:param str cidr: a IPv6 CIDR
|
|
||||||
:param str mac: a MAC address
|
|
||||||
:return: an IPv6 Address
|
|
||||||
:rtype: netaddr.IPAddress
|
|
||||||
"""
|
|
||||||
# Check if the prefix is IPv4 address
|
|
||||||
is_ipv4 = netutils.is_valid_ipv4(cidr)
|
|
||||||
if is_ipv4:
|
|
||||||
msg = "Unable to generate IP address by EUI64 for IPv4 prefix"
|
|
||||||
raise TypeError(msg)
|
|
||||||
try:
|
|
||||||
eui64 = int(netaddr.EUI(mac).eui64())
|
|
||||||
prefix = netaddr.IPNetwork(cidr)
|
|
||||||
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': cidr, 'mac': mac})
|
|
||||||
except TypeError:
|
|
||||||
raise TypeError('Bad prefix type for generate IPv6 address by '
|
|
||||||
'EUI-64: %s' % cidr)
|
|
||||||
|
|
||||||
|
|
||||||
# Courtesy of http://stackoverflow.com/a/312464
|
# Courtesy of http://stackoverflow.com/a/312464
|
||||||
def chunkify(sequence, chunksize):
|
def chunkify(sequence, chunksize):
|
||||||
"""Yield successive chunks from `sequence`."""
|
"""Yield successive chunks from `sequence`."""
|
||||||
|
@ -13,8 +13,6 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import netaddr
|
|
||||||
|
|
||||||
from tempest.lib.common.utils import data_utils
|
from tempest.lib.common.utils import data_utils
|
||||||
from tempest.tests import base
|
from tempest.tests import base
|
||||||
|
|
||||||
@ -137,43 +135,6 @@ class TestDataUtils(base.TestCase):
|
|||||||
actual = data_utils.random_bytes(size=2048)
|
actual = data_utils.random_bytes(size=2048)
|
||||||
self.assertEqual(2048, len(actual))
|
self.assertEqual(2048, len(actual))
|
||||||
|
|
||||||
def test_get_ipv6_addr_by_EUI64(self):
|
|
||||||
actual = data_utils.get_ipv6_addr_by_EUI64('2001:db8::',
|
|
||||||
'00:16:3e:33:44:55')
|
|
||||||
self.assertIsInstance(actual, netaddr.IPAddress)
|
|
||||||
self.assertEqual(actual,
|
|
||||||
netaddr.IPAddress('2001:db8::216:3eff:fe33:4455'))
|
|
||||||
|
|
||||||
def test_get_ipv6_addr_by_EUI64_with_IPv4_prefix(self):
|
|
||||||
ipv4_prefix = '10.0.8'
|
|
||||||
mac = '00:16:3e:33:44:55'
|
|
||||||
self.assertRaises(TypeError, data_utils.get_ipv6_addr_by_EUI64,
|
|
||||||
ipv4_prefix, mac)
|
|
||||||
|
|
||||||
def test_get_ipv6_addr_by_EUI64_bad_cidr_type(self):
|
|
||||||
bad_cidr = 123
|
|
||||||
mac = '00:16:3e:33:44:55'
|
|
||||||
self.assertRaises(TypeError, data_utils.get_ipv6_addr_by_EUI64,
|
|
||||||
bad_cidr, mac)
|
|
||||||
|
|
||||||
def test_get_ipv6_addr_by_EUI64_bad_cidr_value(self):
|
|
||||||
bad_cidr = 'bb'
|
|
||||||
mac = '00:16:3e:33:44:55'
|
|
||||||
self.assertRaises(TypeError, data_utils.get_ipv6_addr_by_EUI64,
|
|
||||||
bad_cidr, mac)
|
|
||||||
|
|
||||||
def test_get_ipv6_addr_by_EUI64_bad_mac_value(self):
|
|
||||||
cidr = '2001:db8::'
|
|
||||||
bad_mac = '00:16:3e:33:44:5Z'
|
|
||||||
self.assertRaises(TypeError, data_utils.get_ipv6_addr_by_EUI64,
|
|
||||||
cidr, bad_mac)
|
|
||||||
|
|
||||||
def test_get_ipv6_addr_by_EUI64_bad_mac_type(self):
|
|
||||||
cidr = '2001:db8::'
|
|
||||||
bad_mac = 99999999999999999999
|
|
||||||
self.assertRaises(TypeError, data_utils.get_ipv6_addr_by_EUI64,
|
|
||||||
cidr, bad_mac)
|
|
||||||
|
|
||||||
def test_chunkify(self):
|
def test_chunkify(self):
|
||||||
data = "aaa"
|
data = "aaa"
|
||||||
chunks = data_utils.chunkify(data, 2)
|
chunks = data_utils.chunkify(data, 2)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user