Port more unit tests to Python 3
* Replace string.find(a, b) with a.find(b) * NamedTemporaryFile: open file in text mode rather than opening it in binary mode. * Module.process_contents(): if contents is a Unicode string, first encode it to UTF-8 before hashing the content to MD5. * ClusterController: replace dict.items()[0] with next(iter(dict.items())) * tox: run the following tests on Python 3.4 - mysql/test_common.py - taskmanager/test_models.py - module/test_module_models.py - test_cluster_controller.py Partially implements: blueprint trove-python3 Change-Id: I5372520f9717b4f0279c4b436ca88c160ddf894b
This commit is contained in:
parent
f9df5af18d
commit
61614653d6
4
tox.ini
4
tox.ini
@ -38,6 +38,7 @@ commands =
|
|||||||
trove/tests/unittests/backup/test_backup_models.py \
|
trove/tests/unittests/backup/test_backup_models.py \
|
||||||
trove/tests/unittests/cluster/test_cassandra_cluster.py \
|
trove/tests/unittests/cluster/test_cassandra_cluster.py \
|
||||||
trove/tests/unittests/cluster/test_cluster.py \
|
trove/tests/unittests/cluster/test_cluster.py \
|
||||||
|
trove/tests/unittests/cluster/test_cluster_controller.py \
|
||||||
trove/tests/unittests/cluster/test_cluster_models.py \
|
trove/tests/unittests/cluster/test_cluster_models.py \
|
||||||
trove/tests/unittests/cluster/test_cluster_pxc_controller.py \
|
trove/tests/unittests/cluster/test_cluster_pxc_controller.py \
|
||||||
trove/tests/unittests/cluster/test_cluster_redis_controller.py \
|
trove/tests/unittests/cluster/test_cluster_redis_controller.py \
|
||||||
@ -81,7 +82,9 @@ commands =
|
|||||||
trove/tests/unittests/mgmt/test_datastores.py \
|
trove/tests/unittests/mgmt/test_datastores.py \
|
||||||
trove/tests/unittests/mgmt/test_models.py \
|
trove/tests/unittests/mgmt/test_models.py \
|
||||||
trove/tests/unittests/module/test_module_controller.py \
|
trove/tests/unittests/module/test_module_controller.py \
|
||||||
|
trove/tests/unittests/module/test_module_models.py \
|
||||||
trove/tests/unittests/module/test_module_views.py \
|
trove/tests/unittests/module/test_module_views.py \
|
||||||
|
trove/tests/unittests/mysql/test_common.py \
|
||||||
trove/tests/unittests/mysql/test_user_controller.py \
|
trove/tests/unittests/mysql/test_user_controller.py \
|
||||||
trove/tests/unittests/network/test_neutron_driver.py \
|
trove/tests/unittests/network/test_neutron_driver.py \
|
||||||
trove/tests/unittests/quota/test_quota.py \
|
trove/tests/unittests/quota/test_quota.py \
|
||||||
@ -91,6 +94,7 @@ commands =
|
|||||||
trove/tests/unittests/taskmanager/test_clusters.py \
|
trove/tests/unittests/taskmanager/test_clusters.py \
|
||||||
trove/tests/unittests/taskmanager/test_galera_clusters.py \
|
trove/tests/unittests/taskmanager/test_galera_clusters.py \
|
||||||
trove/tests/unittests/taskmanager/test_manager.py \
|
trove/tests/unittests/taskmanager/test_manager.py \
|
||||||
|
trove/tests/unittests/taskmanager/test_models.py \
|
||||||
trove/tests/unittests/taskmanager/test_vertica_clusters.py \
|
trove/tests/unittests/taskmanager/test_vertica_clusters.py \
|
||||||
trove/tests/unittests/upgrade/test_controller.py \
|
trove/tests/unittests/upgrade/test_controller.py \
|
||||||
trove/tests/unittests/upgrade/test_models.py
|
trove/tests/unittests/upgrade/test_models.py
|
||||||
|
@ -63,7 +63,7 @@ class ClusterController(wsgi.Controller):
|
|||||||
" one action specified in body"))
|
" one action specified in body"))
|
||||||
context = req.environ[wsgi.CONTEXT_KEY]
|
context = req.environ[wsgi.CONTEXT_KEY]
|
||||||
cluster = models.Cluster.load(context, id)
|
cluster = models.Cluster.load(context, id)
|
||||||
cluster.action(context, req, *body.items()[0])
|
cluster.action(context, req, *next(iter(body.items())))
|
||||||
|
|
||||||
view = views.load_view(cluster, req=req, load_servers=False)
|
view = views.load_view(cluster, req=req, load_servers=False)
|
||||||
wsgi_result = wsgi.Result(view.data(), 202)
|
wsgi_result = wsgi.Result(view.data(), 202)
|
||||||
|
@ -15,7 +15,6 @@
|
|||||||
|
|
||||||
import abc
|
import abc
|
||||||
import re
|
import re
|
||||||
import string
|
|
||||||
|
|
||||||
import netaddr
|
import netaddr
|
||||||
from six import u
|
from six import u
|
||||||
@ -573,7 +572,7 @@ class ValidatedMySQLDatabase(MySQLDatabase):
|
|||||||
if any([not value,
|
if any([not value,
|
||||||
not self._is_valid(value),
|
not self._is_valid(value),
|
||||||
not self.dbname.match(value),
|
not self.dbname.match(value),
|
||||||
string.find("%r" % value, "\\") != -1]):
|
("%r" % value).find("\\") != -1]):
|
||||||
raise ValueError(_("'%s' is not a valid database name.") % value)
|
raise ValueError(_("'%s' is not a valid database name.") % value)
|
||||||
elif len(value) > 64:
|
elif len(value) > 64:
|
||||||
msg = _("Database name '%s' is too long. Max length = 64.")
|
msg = _("Database name '%s' is too long. Max length = 64.")
|
||||||
@ -966,7 +965,7 @@ class MySQLUser(Base):
|
|||||||
def _is_valid(self, value):
|
def _is_valid(self, value):
|
||||||
if (not value or
|
if (not value or
|
||||||
self.not_supported_chars.search(value) or
|
self.not_supported_chars.search(value) or
|
||||||
string.find("%r" % value, "\\") != -1):
|
("%r" % value).find("\\") != -1):
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
return True
|
return True
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
import hashlib
|
import hashlib
|
||||||
|
import six
|
||||||
from sqlalchemy.sql.expression import or_
|
from sqlalchemy.sql.expression import or_
|
||||||
|
|
||||||
from trove.common import cfg
|
from trove.common import cfg
|
||||||
@ -217,7 +218,10 @@ class Module(object):
|
|||||||
# be stored in a text field in the Trove database.
|
# be stored in a text field in the Trove database.
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def process_contents(contents):
|
def process_contents(contents):
|
||||||
md5 = hashlib.md5(contents).hexdigest()
|
md5 = contents
|
||||||
|
if isinstance(md5, six.text_type):
|
||||||
|
md5 = md5.encode('utf-8')
|
||||||
|
md5 = hashlib.md5(md5).hexdigest()
|
||||||
encrypted_contents = crypto_utils.encrypt_data(
|
encrypted_contents = crypto_utils.encrypt_data(
|
||||||
contents, Modules.ENCRYPT_KEY)
|
contents, Modules.ENCRYPT_KEY)
|
||||||
return md5, crypto_utils.encode_data(encrypted_contents)
|
return md5, crypto_utils.encode_data(encrypted_contents)
|
||||||
|
@ -193,10 +193,11 @@ class FreshInstanceTasksTest(trove_testtools.TestCase):
|
|||||||
self.orig_DBI_find_by = DBInstance.find_by
|
self.orig_DBI_find_by = DBInstance.find_by
|
||||||
self.userdata = "hello moto"
|
self.userdata = "hello moto"
|
||||||
self.guestconfig_content = "guest config"
|
self.guestconfig_content = "guest config"
|
||||||
with NamedTemporaryFile(suffix=".cloudinit", delete=False) as f:
|
with NamedTemporaryFile(mode="w", suffix=".cloudinit",
|
||||||
|
delete=False) as f:
|
||||||
self.cloudinit = f.name
|
self.cloudinit = f.name
|
||||||
f.write(self.userdata)
|
f.write(self.userdata)
|
||||||
with NamedTemporaryFile(delete=False) as f:
|
with NamedTemporaryFile(mode="w", delete=False) as f:
|
||||||
self.guestconfig = f.name
|
self.guestconfig = f.name
|
||||||
f.write(self.guestconfig_content)
|
f.write(self.guestconfig_content)
|
||||||
self.freshinstancetasks = taskmanager_models.FreshInstanceTasks(
|
self.freshinstancetasks = taskmanager_models.FreshInstanceTasks(
|
||||||
|
Loading…
Reference in New Issue
Block a user