Port test_ipv6 to py3 and simplify to_global()
* ipv6.account_identifier.to_global(): on Python 3, encode project_id to UTF-8. * Simplify also to_global(): replace netaddr.EUI(mac).words with netaddr.EUI.value to avoid conversions (int => str (hex) => int). * tests-py3.txt: run nova.tests.unit.test_ipv6 on Python 3 Partially-Implements: blueprint nova-python3-newton Change-Id: I6f6f711fd00980de8cdccbdfe2d636f21440aea7
This commit is contained in:
parent
76e857cade
commit
3204a46232
@ -20,19 +20,24 @@
|
||||
import hashlib
|
||||
|
||||
import netaddr
|
||||
import six
|
||||
|
||||
from nova.i18n import _
|
||||
|
||||
|
||||
def to_global(prefix, mac, project_id):
|
||||
project_hash = netaddr.IPAddress(
|
||||
int(hashlib.sha1(project_id).hexdigest()[:8], 16) << 32)
|
||||
addr = project_id
|
||||
if isinstance(addr, six.text_type):
|
||||
addr = addr.encode('utf-8')
|
||||
addr = hashlib.sha1(addr)
|
||||
addr = int(addr.hexdigest()[:8], 16) << 32
|
||||
|
||||
project_hash = netaddr.IPAddress(addr)
|
||||
static_num = netaddr.IPAddress(0xff << 24)
|
||||
|
||||
try:
|
||||
mac_suffix = netaddr.EUI(mac).words[3:]
|
||||
int_addr = int(''.join(['%02x' % i for i in mac_suffix]), 16)
|
||||
mac_addr = netaddr.IPAddress(int_addr)
|
||||
mac_suffix = netaddr.EUI(mac).value & 0xffffff
|
||||
mac_addr = netaddr.IPAddress(mac_suffix)
|
||||
maskIP = netaddr.IPNetwork(prefix).ip
|
||||
return (project_hash ^ static_num ^ mac_addr | maskIP).format()
|
||||
except netaddr.AddrFormatError:
|
||||
|
@ -60,7 +60,6 @@ nova.tests.unit.test_api_validation.Base64TestCase
|
||||
nova.tests.unit.test_bdm.BlockDeviceMappingEc2CloudTestCase
|
||||
nova.tests.unit.test_configdrive2.ConfigDriveTestCase
|
||||
nova.tests.unit.test_hacking.HackingTestCase
|
||||
nova.tests.unit.test_ipv6.IPv6AccountIdentiferTestCase
|
||||
nova.tests.unit.test_matchers.TestDictMatches
|
||||
nova.tests.unit.test_metadata.MetadataHandlerTestCase
|
||||
nova.tests.unit.test_metadata.MetadataPasswordTestCase
|
||||
|
Loading…
Reference in New Issue
Block a user