[2/3]Replace six.iteritems() with .items()

1.As mentioned in [1], we should avoid using
six.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

The patch list:
    1. cells.
    2. compute api.
    3. image.
    4. network.
    5. objects.
    6. scheduler.
    7. virt.
    8. other resources.

Partial-Implements: blueprint replace-iteritems-with-items

Change-Id: Ic6e469eb80ee1774de1374bb36f38b5134b6b311
This commit is contained in:
Spencer Yu 2016-12-20 23:43:53 -08:00
parent 3d23b55ddb
commit f159d6da21
5 changed files with 11 additions and 11 deletions

View File

@ -2742,7 +2742,7 @@ def _instance_update(context, instance_uuid, values, expected, original=None):
else:
# Coerce all single values to singleton lists
expected = {k: [None] if v is None else sqlalchemyutils.to_list(v)
for (k, v) in six.iteritems(expected)}
for (k, v) in expected.items()}
# Extract 'expected_' values from values dict, as these aren't actually
# updates
@ -2798,7 +2798,7 @@ def _instance_update(context, instance_uuid, values, expected, original=None):
conflicts_expected = {}
conflicts_actual = {}
for (field, expected_values) in six.iteritems(expected):
for (field, expected_values) in expected.items():
actual = original[field]
if actual not in expected_values:
conflicts_expected[field] = expected_values

View File

@ -14,7 +14,7 @@
# under the License.
from oslo_log import log as logging
import six
import nova.conf
from nova.i18n import _LW
@ -44,7 +44,7 @@ class AggregateImagePropertiesIsolation(filters.BaseHostFilter):
image_props = spec_obj.image.properties if spec_obj.image else {}
metadata = utils.aggregate_metadata_get_by_host(host_state)
for key, options in six.iteritems(metadata):
for key, options in metadata.items():
if (cfg_namespace and
not key.startswith(cfg_namespace + cfg_separator)):
continue

View File

@ -15,7 +15,7 @@
# under the License.
from oslo_log import log as logging
import six
from nova.scheduler import filters
from nova.scheduler.filters import extra_specs_ops
@ -48,7 +48,7 @@ class AggregateInstanceExtraSpecsFilter(filters.BaseHostFilter):
metadata = utils.aggregate_metadata_get_by_host(host_state)
for key, req in six.iteritems(instance_type.extra_specs):
for key, req in instance_type.extra_specs.items():
# Either not scope format, or aggregate_instance_extra_specs scope
scope = key.split(':', 1)
if len(scope) > 1:

View File

@ -336,7 +336,7 @@ class TestCase(testtools.TestCase):
def flags(self, **kw):
"""Override flag variables for a test."""
group = kw.pop('group', None)
for k, v in six.iteritems(kw):
for k, v in kw.items():
CONF.set_override(k, v, group, enforce_type=True)
def start_service(self, name, host=None, **kwargs):

View File

@ -928,7 +928,7 @@ def metadata_to_dict(metadata, include_deleted=False):
def dict_to_metadata(metadata):
result = []
for key, value in six.iteritems(metadata):
for key, value in metadata.items():
result.append(dict(key=key, value=value))
return result
@ -1133,7 +1133,7 @@ def get_system_metadata_from_image(image_meta, flavor=None):
system_meta = {}
prefix_format = SM_IMAGE_PROP_PREFIX + '%s'
for key, value in six.iteritems(image_meta.get('properties', {})):
for key, value in image_meta.get('properties', {}).items():
if key in SM_SKIP_KEYS:
continue
@ -1164,7 +1164,7 @@ def get_image_from_system_metadata(system_meta):
if not isinstance(system_meta, dict):
system_meta = metadata_to_dict(system_meta, include_deleted=True)
for key, value in six.iteritems(system_meta):
for key, value in system_meta.items():
if value is None:
continue
@ -1295,7 +1295,7 @@ def filter_and_format_resource_metadata(resource_type, resource_list,
if ids and _get_id(resource) not in ids:
return {}
for k, v in six.iteritems(input_metadata):
for k, v in input_metadata.items():
# Both keys and value defined -- AND
if (keys_filter and values_filter and
not _match_any(keys_filter, k) and