Port designate code to Python 3
* Replace map() with list-comprehension to get a list on Python 3. * Unicode dance: encode text to UTF-8 for MD5, decode Base32 from ASCII to get text. * tox.ini: test_designate_driver and test_datastore_versions to Python 3.4 Partially implements: blueprint trove-python3 Change-Id: I1aa5387908b3f108487ed731cee5f7d9bbfd7d69
This commit is contained in:
parent
79f350852e
commit
bdf664bbdf
5
tox.ini
5
tox.ini
@ -40,7 +40,10 @@ commands =
|
||||
trove/tests/unittests/common/test_stream_codecs.py \
|
||||
trove/tests/unittests/common/test_template.py \
|
||||
trove/tests/unittests/common/test_utils.py \
|
||||
trove/tests/unittests/common/test_wsgi.py
|
||||
trove/tests/unittests/common/test_wsgi.py \
|
||||
trove/tests/unittests/datastore/test_datastore_versions.py \
|
||||
trove/tests/unittests/dns/test_designate_driver.py
|
||||
|
||||
|
||||
[testenv:debug]
|
||||
commands = oslo_debug_helper {posargs}
|
||||
|
@ -131,7 +131,7 @@ class Capabilities(object):
|
||||
# right back.
|
||||
return cap
|
||||
|
||||
self.capabilities = map(override, capability_defaults)
|
||||
self.capabilities = [override(obj) for obj in capability_defaults]
|
||||
|
||||
LOG.debug('Capabilities for datastore %(ds_id)s: %(capabilities)s' %
|
||||
{'ds_id': self.datastore_version_id,
|
||||
|
@ -23,6 +23,8 @@ import hashlib
|
||||
from designateclient.v1 import Client
|
||||
from designateclient.v1.records import Record
|
||||
from oslo_log import log as logging
|
||||
from oslo_utils import encodeutils
|
||||
import six
|
||||
|
||||
from trove.common import cfg
|
||||
from trove.common import exception
|
||||
@ -142,7 +144,11 @@ class DesignateInstanceEntryFactory(driver.DnsInstanceEntryFactory):
|
||||
def create_entry(self, instance_id):
|
||||
zone = DesignateDnsZone(id=DNS_DOMAIN_ID, name=DNS_DOMAIN_NAME)
|
||||
# Constructing the hostname by hashing the instance ID.
|
||||
name = base64.b32encode(hashlib.md5(instance_id).digest())[:11].lower()
|
||||
name = encodeutils.to_utf8(instance_id)
|
||||
name = hashlib.md5(name).digest()
|
||||
name = base64.b32encode(name)[:11].lower()
|
||||
if six.PY3:
|
||||
name = name.decode('ascii')
|
||||
hostname = ("%s.%s" % (name, zone.name))
|
||||
# Removing the leading dot if present
|
||||
if hostname.endswith('.'):
|
||||
|
@ -18,6 +18,7 @@ from designateclient.v1.domains import Domain
|
||||
from designateclient.v1.records import Record
|
||||
from mock import MagicMock
|
||||
from mock import patch
|
||||
import six
|
||||
|
||||
from trove.dns.designate import driver
|
||||
from trove.tests.unittests import trove_testtools
|
||||
@ -185,7 +186,10 @@ class DesignateInstanceEntryFactoryTest(trove_testtools.TestCase):
|
||||
driver.DNS_DOMAIN_ID = '00000000-0000-0000-0000-000000000000'
|
||||
driver.DNS_DOMAIN_NAME = 'trove.com'
|
||||
driver.DNS_TTL = 3600
|
||||
hashed_id = base64.b32encode(hashlib.md5(instance_id).digest())
|
||||
hashed_id = hashlib.md5(instance_id.encode()).digest()
|
||||
hashed_id = base64.b32encode(hashed_id)
|
||||
if six.PY3:
|
||||
hashed_id = hashed_id.decode('ascii')
|
||||
hashed_id_concat = hashed_id[:11].lower()
|
||||
exp_hostname = ("%s.%s" % (hashed_id_concat, driver.DNS_DOMAIN_NAME))
|
||||
factory = driver.DesignateInstanceEntryFactory()
|
||||
@ -202,7 +206,10 @@ class DesignateInstanceEntryFactoryTest(trove_testtools.TestCase):
|
||||
driver.DNS_DOMAIN_ID = '00000000-0000-0000-0000-000000000000'
|
||||
driver.DNS_DOMAIN_NAME = 'trove.com.'
|
||||
driver.DNS_TTL = 3600
|
||||
hashed_id = base64.b32encode(hashlib.md5(instance_id).digest())
|
||||
hashed_id = hashlib.md5(instance_id.encode()).digest()
|
||||
hashed_id = base64.b32encode(hashed_id)
|
||||
if six.PY3:
|
||||
hashed_id = hashed_id.decode('ascii')
|
||||
hashed_id_concat = hashed_id[:11].lower()
|
||||
exp_hostname = ("%s.%s" %
|
||||
(hashed_id_concat, driver.DNS_DOMAIN_NAME))[:-1]
|
||||
|
Loading…
x
Reference in New Issue
Block a user