Replace six.iteritems with dict.items

As [1] mentioned, we should use dict.items instead of six.iteritems.
Let's use dict.items as it should return iterators in PY3 as well.
(As for PY2, the performance about list should be negligible)

[1] https://wiki.openstack.org/wiki/Python3

Change-Id: I77b3a71faa71b5f671daff3415e2ae58289fd3ca
This commit is contained in:
guo yunxian 2016-08-21 20:03:10 +08:00 committed by Ken'ichi Ohmichi
parent 1b8f6f00ee
commit 7bbbec1ed9
17 changed files with 25 additions and 46 deletions

View File

@ -14,7 +14,6 @@
# under the License.
from oslo_log import log as logging
import six
from testtools import matchers
from tempest.api.compute import base
@ -175,7 +174,7 @@ class QuotaClassesAdminTestJSON(base.BaseV2ComputeAdminTest):
# restore the defaults when the test is done
self.addCleanup(self._restore_default_quotas, body.copy())
# increment all of the values for updating the default quota class
for quota, default in six.iteritems(body):
for quota, default in body.items():
# NOTE(sdague): we need to increment a lot, otherwise
# there is a real chance that we go from -1 (unlimited)
# to a very small number which causes issues.

View File

@ -13,8 +13,6 @@
# License for the specific language governing permissions and limitations
# under the License.
import six
from tempest.api.compute import base
from tempest import test
@ -50,7 +48,7 @@ class ServerAddressesTestJSON(base.BaseV2ComputeTest):
# We do not know the exact network configuration, but an instance
# should at least have a single public or private address
self.assertGreaterEqual(len(addresses), 1)
for network_name, network_addresses in six.iteritems(addresses):
for network_name, network_addresses in addresses.items():
self.assertGreaterEqual(len(network_addresses), 1)
for address in network_addresses:
self.assertTrue(address['addr'])

View File

@ -13,8 +13,6 @@
# License for the specific language governing permissions and limitations
# under the License.
import six
from tempest.api.network import base
from tempest.common.utils import data_utils
from tempest.lib.common.utils import test_utils
@ -57,7 +55,7 @@ class QuotasTest(base.BaseAdminNetworkTest):
project_id, **new_quotas)['quota']
self.addCleanup(test_utils.call_and_ignore_notfound_exc,
self.admin_quotas_client.reset_quotas, project_id)
for key, value in six.iteritems(new_quotas):
for key, value in new_quotas.items():
self.assertEqual(value, quota_set[key])
# Confirm our project is listed among projects with non default quotas
@ -71,7 +69,7 @@ class QuotasTest(base.BaseAdminNetworkTest):
# Confirm from API quotas were changed as requested for project
quota_set = self.admin_quotas_client.show_quotas(project_id)
quota_set = quota_set['quota']
for key, value in six.iteritems(new_quotas):
for key, value in new_quotas.items():
self.assertEqual(value, quota_set[key])
# Reset quotas to default and confirm

View File

@ -16,8 +16,6 @@
import netaddr
import random
import six
from tempest.api.network import base
from tempest.common.utils import data_utils
from tempest.common.utils import net_info
@ -126,7 +124,7 @@ class NetworksTestDHCPv6(base.BaseNetworkTest):
):
kwargs = {'ipv6_ra_mode': ra_mode,
'ipv6_address_mode': add_mode}
kwargs = dict((k, v) for k, v in six.iteritems(kwargs) if v)
kwargs = dict((k, v) for k, v in kwargs.items() if v)
real_ip, eui_ip = self._get_ips_from_subnet(**kwargs)
self._clean_network()
self.assertEqual(eui_ip, real_ip,
@ -269,7 +267,7 @@ class NetworksTestDHCPv6(base.BaseNetworkTest):
):
kwargs = {'ipv6_ra_mode': ra_mode,
'ipv6_address_mode': add_mode}
kwargs = dict((k, v) for k, v in six.iteritems(kwargs) if v)
kwargs = dict((k, v) for k, v in kwargs.items() if v)
subnet = self.create_subnet(self.network, **kwargs)
port = self.create_port(self.network)
port_ip = next(iter(port['fixed_ips']), None)['ip_address']
@ -291,7 +289,7 @@ class NetworksTestDHCPv6(base.BaseNetworkTest):
):
kwargs = {'ipv6_ra_mode': ra_mode,
'ipv6_address_mode': add_mode}
kwargs = dict((k, v) for k, v in six.iteritems(kwargs) if v)
kwargs = dict((k, v) for k, v in kwargs.items() if v)
subnet = self.create_subnet(self.network, **kwargs)
ip_range = netaddr.IPRange(subnet["allocation_pools"][0]["start"],
subnet["allocation_pools"][0]["end"])
@ -364,7 +362,7 @@ class NetworksTestDHCPv6(base.BaseNetworkTest):
):
kwargs = {'ipv6_ra_mode': ra_mode,
'ipv6_address_mode': add_mode}
kwargs = dict((k, v) for k, v in six.iteritems(kwargs) if v)
kwargs = dict((k, v) for k, v in kwargs.items() if v)
subnet, port = self._create_subnet_router(kwargs)
port_ip = next(iter(port['fixed_ips']), None)['ip_address']
self._clean_network()

View File

@ -130,7 +130,7 @@ class BaseNetworkTestResources(base.BaseNetworkTest):
**kwargs)
compare_args_full = dict(gateway_ip=gateway, cidr=cidr,
mask_bits=mask_bits, **kwargs)
compare_args = dict((k, v) for k, v in six.iteritems(compare_args_full)
compare_args = dict((k, v) for k, v in compare_args_full.items()
if v is not None)
if 'dns_nameservers' in set(subnet).intersection(compare_args):

View File

@ -14,7 +14,6 @@
# under the License.
import netaddr
import six
from tempest.api.network import base_routers as base
from tempest.common.utils import data_utils
@ -163,7 +162,7 @@ class RoutersTest(base.BaseRouterTest):
self.assertIsNone(actual_ext_gw_info)
return
# Verify only keys passed in exp_ext_gw_info
for k, v in six.iteritems(exp_ext_gw_info):
for k, v in exp_ext_gw_info.items():
self.assertEqual(v, actual_ext_gw_info[k])
def _verify_gateway_port(self, router_id):

View File

@ -13,8 +13,6 @@
# License for the specific language governing permissions and limitations
# under the License.
import six
from tempest.api.network import base_security_groups as base
from tempest.common.utils import data_utils
from tempest import config
@ -62,7 +60,7 @@ class SecGroupTest(base.BaseSecGroupTest):
'port_range_max': port_range_max,
'remote_group_id': remote_group_id,
'remote_ip_prefix': remote_ip_prefix}
for key, value in six.iteritems(expected):
for key, value in expected.items():
self.assertEqual(value, sec_group_rule[key],
"Field %s of the created security group "
"rule does not match with %s." %
@ -131,7 +129,7 @@ class SecGroupTest(base.BaseSecGroupTest):
rule_create_body['security_group_rule']['id']
)
create_dict = rule_create_body['security_group_rule']
for key, value in six.iteritems(create_dict):
for key, value in create_dict.items():
self.assertEqual(value,
show_rule_body['security_group_rule'][key],
"%s does not match." % key)

View File

@ -19,8 +19,6 @@ import re
import time
import zlib
import six
from tempest.api.object_storage import base
from tempest.common import custom_matchers
from tempest.common.utils import data_utils
@ -865,7 +863,7 @@ class ObjectTest(base.BaseObjectTest):
expected = {'x-object-meta-test': '',
'x-object-meta-src': 'src_value',
'x-copied-from': self.container_name + "/" + src_obj_name}
for key, value in six.iteritems(expected):
for key, value in expected.items():
self.assertIn(key, resp)
self.assertEqual(value, resp[key])
@ -888,7 +886,7 @@ class ObjectTest(base.BaseObjectTest):
expected = {'x-object-meta-test': 'value',
'x-object-meta-src': 'src_value',
'x-copied-from': self.container_name + "/" + src_obj_name}
for key, value in six.iteritems(expected):
for key, value in expected.items():
self.assertIn(key, resp)
self.assertEqual(value, resp[key])

View File

@ -12,7 +12,6 @@
# License for the specific language governing permissions and limitations
# under the License.
import six
from tempest.api.volume import base
from tempest.common.utils import data_utils
from tempest.common import waiters
@ -63,7 +62,7 @@ class BaseVolumeQuotasAdminV2TestJSON(base.BaseVolumeAdminTest):
**new_quota_set)['quota_set']
cleanup_quota_set = dict(
(k, v) for k, v in six.iteritems(default_quota_set)
(k, v) for k, v in default_quota_set.items()
if k in QUOTA_KEYS)
self.addCleanup(self.admin_quotas_client.update_quota_set,
self.demo_tenant_id, **cleanup_quota_set)

View File

@ -14,7 +14,6 @@
import re
import six
from testtools import helpers
@ -217,7 +216,7 @@ class AreAllWellFormatted(object):
"""
def match(self, actual):
for key, value in six.iteritems(actual):
for key, value in actual.items():
if key in ('content-length', 'x-account-bytes-used',
'x-account-container-count', 'x-account-object-count',
'x-container-bytes-used', 'x-container-object-count')\

View File

@ -15,8 +15,6 @@
import copy
import six
def get_image_meta_from_headers(resp):
meta = {'properties': {}}
@ -55,13 +53,13 @@ def image_meta_to_headers(**metadata):
if copy_from is not None:
headers['x-glance-api-copy-from'] = copy_from
for key, value in six.iteritems(fields_copy.pop('properties', {})):
for key, value in fields_copy.pop('properties', {}).items():
headers['x-image-meta-property-%s' % key] = str(value)
for key, value in six.iteritems(fields_copy.pop('api', {})):
for key, value in fields_copy.pop('api', {}).items():
headers['x-glance-api-property-%s' % key] = str(value)
for key, value in six.iteritems(fields_copy):
for key, value in fields_copy.items():
headers['x-image-meta-%s' % key] = str(value)
return headers

View File

@ -120,7 +120,7 @@ class PreProvisionedCredentialProvider(cred_provider.CredentialProvider):
if 'resources' in account:
resources = account.pop('resources')
temp_hash = hashlib.md5()
account_for_hash = dict((k, v) for (k, v) in six.iteritems(account)
account_for_hash = dict((k, v) for (k, v) in account.items()
if k in cls.HASH_CRED_FIELDS)
temp_hash.update(six.text_type(account_for_hash).encode('utf-8'))
temp_hash_key = temp_hash.hexdigest()

View File

@ -20,7 +20,6 @@ import netaddr
from oslo_log import log
from oslo_serialization import jsonutils as json
from oslo_utils import netutils
import six
from tempest.common import compute
from tempest.common import image as common_image
@ -920,7 +919,7 @@ class NetworkScenarioTest(ScenarioTest):
# The target login is assumed to have been configured for
# key-based authentication by cloud-init.
try:
for net_name, ip_addresses in six.iteritems(server['addresses']):
for net_name, ip_addresses in server['addresses'].items():
for ip_address in ip_addresses:
self.check_vm_connectivity(ip_address['addr'],
username,

View File

@ -14,8 +14,6 @@
# under the License.
import functools
import six
from tempest import config
from tempest.lib.common.utils import test_utils
from tempest.scenario import manager
@ -112,7 +110,7 @@ class TestGettingAddress(manager.NetworkScenarioTest):
@staticmethod
def define_server_ips(srv):
ips = {'4': None, '6': []}
for net_name, nics in six.iteritems(srv['addresses']):
for net_name, nics in srv['addresses'].items():
for nic in nics:
if nic['version'] == 6:
ips['6'].append(nic['addr'])

View File

@ -13,7 +13,6 @@
# License for the specific language governing permissions and limitations
# under the License.
import six
from six.moves import http_client as httplib
from six.moves.urllib import parse as urlparse
@ -189,7 +188,7 @@ class ObjectClient(rest_client.RestClient):
# Send the PUT request and the headers including the "Expect" header
conn.putrequest('PUT', path)
for header, value in six.iteritems(headers):
for header, value in headers.items():
conn.putheader(header, value)
conn.endheaders()

View File

@ -101,7 +101,7 @@ class TestPreProvisionedCredentials(base.TestCase):
preprov_creds.PreProvisionedCredentialProvider.HASH_CRED_FIELDS)
for account in accounts_list:
hash = hashlib.md5()
account_for_hash = dict((k, v) for (k, v) in six.iteritems(account)
account_for_hash = dict((k, v) for (k, v) in account.items()
if k in hash_fields)
hash.update(six.text_type(account_for_hash).encode('utf-8'))
temp_hash = hash.hexdigest()

View File

@ -15,7 +15,6 @@
import mock
import six
from tempest.lib import exceptions
from tempest.services.object_storage import object_client
@ -85,7 +84,7 @@ class TestObjectClient(base.TestCase):
# Verify that headers were written, including "Expect:100-continue"
calls = []
for header, value in six.iteritems(expected_hdrs):
for header, value in expected_hdrs.items():
calls.append(mock.call(header, value))
mock_poc.return_value.putheader.assert_has_calls(calls, False)