From 89b453be50d8ee6ec04009dfb1252f515db7d79d Mon Sep 17 00:00:00 2001 From: yfzhao Date: Thu, 30 Mar 2017 23:52:13 +0800 Subject: [PATCH] Replace six.iteritems() with .items() 1.As mentioned in [1], we should avoid using iteritems to achieve iterators. We can use dict.items instead, as it will return iterators in PY3 as well. And dict.items/keys will more readable. 2.In py2, the performance about list should be negligible, see the link [2]. [1] https://wiki.openstack.org/wiki/Python3 [2] http://lists.openstack.org/pipermail/openstack-dev/2015-June/066391.html Change-Id: I52b4ea9445143afc5e2f5f050373951a61a39327 --- manila/scheduler/host_manager.py | 2 +- manila/share/drivers/glusterfs/common.py | 2 +- manila/share/drivers/qnap/api.py | 4 ++-- manila/test.py | 2 +- manila/tests/data/test_helper.py | 3 +-- 5 files changed, 6 insertions(+), 7 deletions(-) diff --git a/manila/scheduler/host_manager.py b/manila/scheduler/host_manager.py index 88b62a93b2..5d412ce162 100644 --- a/manila/scheduler/host_manager.py +++ b/manila/scheduler/host_manager.py @@ -594,7 +594,7 @@ class HostManager(object): pool_key = '.'.join([host, pool.pool_name]) all_pools[pool_key] = pool - return six.itervalues(all_pools) + return all_pools.values() def get_pools(self, context, filters=None): """Returns a dict of all pools on all hosts HostManager knows about.""" diff --git a/manila/share/drivers/glusterfs/common.py b/manila/share/drivers/glusterfs/common.py index 91bce5e702..b4e21bc3fb 100644 --- a/manila/share/drivers/glusterfs/common.py +++ b/manila/share/drivers/glusterfs/common.py @@ -225,7 +225,7 @@ class GlusterManager(object): raise exception.GlusterfsException(_( 'GlusterFS command %(command)s on volume %(volume)s failed' ) % {'volume': self.volume, 'command': command}) - if list(six.itervalues(ret)) != [0, 0]: + if list(ret.values()) != [0, 0]: errdct = {'volume': self.volume, 'command': commandstr, 'opErrstr': volxml_get(xmlout, 'opErrstr', default=None)} errdct.update(ret) diff --git a/manila/share/drivers/qnap/api.py b/manila/share/drivers/qnap/api.py index 40cad06e0a..e3aa7ea1a6 100644 --- a/manila/share/drivers/qnap/api.py +++ b/manila/share/drivers/qnap/api.py @@ -298,7 +298,7 @@ class QnapAPIExecutor(object): @_connection_checker def get_share_info(self, pool_id, **kwargs): """Execute get_share_info API.""" - for key, value in six.iteritems(kwargs): + for key, value in kwargs.items(): LOG.debug('%(key)s = %(val)s', {'key': key, 'val': value}) @@ -609,7 +609,7 @@ class QnapAPIExecutorTS(QnapAPIExecutor): @_connection_checker def get_snapshot_info(self, **kwargs): """Execute get_snapshot_info API.""" - for key, value in six.iteritems(kwargs): + for key, value in kwargs.items(): LOG.debug('%(key)s = %(val)s', {'key': key, 'val': value}) diff --git a/manila/test.py b/manila/test.py index bf0054dbe1..b6e3487e5e 100644 --- a/manila/test.py +++ b/manila/test.py @@ -350,7 +350,7 @@ class TestCase(base_test.BaseTestCase): def _dict_from_object(self, obj, ignored_keys): if ignored_keys is None: ignored_keys = [] - return {k: v for k, v in obj.iteritems() + return {k: v for k, v in obj.items() if k not in ignored_keys} def _assertEqualListsOfObjects(self, objs1, objs2, ignored_keys=None): diff --git a/manila/tests/data/test_helper.py b/manila/tests/data/test_helper.py index 0f44e0dc31..6afa91246b 100644 --- a/manila/tests/data/test_helper.py +++ b/manila/tests/data/test_helper.py @@ -14,7 +14,6 @@ # under the License. import os -import six import ddt import mock @@ -127,7 +126,7 @@ class DataServiceHelperTestCase(test.TestCase): data_copy_helper.CONF.data_node_access_ip = 'fake' data_copy_helper.CONF.data_node_access_admin_user = 'fake' expected = [{ - 'access_type': six.next(six.iteritems(mapping))[0], + 'access_type': list(mapping.keys())[0], 'access_level': constants.ACCESS_LEVEL_RW, 'access_to': 'fake', }]