Replace dict.itervalues() with six.itervalues(dict)

The Python 2 itervalues() method of dictionaries was renamed to values()
in Python 3. Replace dict.itervalues() with six.itervalues(dict) to get
code working on Python 2 and Python 3.

This patch was generated by the following tool (revision fcbf8ad0ec7a)
with the "itervalues" operation:
https://bitbucket.org/haypo/misc/src/tip/python/sixer.py

Blueprint nova-python3
Change-Id: Ied9a76447fbdc933369f926cb19aab9d8896ab92
This commit is contained in:
Victor Stinner 2015-05-04 23:36:02 +02:00
parent e8707aa3b5
commit cfaa22ed6e
14 changed files with 30 additions and 19 deletions

View File

@ -16,6 +16,7 @@
"""The hosts admin extension."""
from oslo_log import log as logging
import six
import webob.exc
from nova.api.openstack import extensions
@ -293,7 +294,7 @@ class HostController(object):
instances))
by_proj_resources = self._get_resources_by_project(host_name,
instances)
for resource in by_proj_resources.itervalues():
for resource in six.itervalues(by_proj_resources):
resources.append({'resource': resource})
return {'host': resources}

View File

@ -16,6 +16,7 @@
"""The hosts admin extension."""
from oslo_log import log as logging
import six
import webob.exc
from nova.api.openstack.compute.schemas.v3 import hosts
@ -282,7 +283,7 @@ class HostController(wsgi.Controller):
instances))
by_proj_resources = self._get_resources_by_project(host_name,
instances)
for resource in by_proj_resources.itervalues():
for resource in six.itervalues(by_proj_resources):
resources.append({'resource': resource})
return {'host': resources}

View File

@ -27,6 +27,7 @@ from oslo_log import log as logging
from oslo_serialization import jsonutils
from oslo_utils import timeutils
from oslo_utils import units
import six
from nova.cells import rpc_driver
from nova import context
@ -328,9 +329,9 @@ class CellStateManager(base.Base):
def get_cell_info_for_neighbors(self):
"""Return cell information for all neighbor cells."""
cell_list = [cell.get_cell_info()
for cell in self.child_cells.itervalues()]
for cell in six.itervalues(self.child_cells)]
cell_list.extend([cell.get_cell_info()
for cell in self.parent_cells.itervalues()])
for cell in six.itervalues(self.parent_cells)])
return cell_list
@sync_before

View File

@ -5964,7 +5964,7 @@ def archive_deleted_rows(context, max_rows=None):
"""
# The context argument is only used for the decorator.
tablenames = []
for model_class in models.__dict__.itervalues():
for model_class in six.itervalues(models.__dict__):
if hasattr(model_class, "__tablename__"):
tablenames.append(model_class.__tablename__)
rows_archived = 0

View File

@ -426,11 +426,11 @@ class IptablesManager(object):
self.apply()
def dirty(self):
for table in self.ipv4.itervalues():
for table in six.itervalues(self.ipv4):
if table.dirty:
return True
if CONF.use_ipv6:
for table in self.ipv6.itervalues():
for table in six.itervalues(self.ipv6):
if table.dirty:
return True
return False

View File

@ -26,6 +26,7 @@ from oslo_config import cfg
from oslo_log import log as logging
from oslo_serialization import jsonutils
from oslo_utils import timeutils
import six
from nova.compute import task_states
from nova.compute import vm_states
@ -512,7 +513,7 @@ class HostManager(object):
# NOTE(deva): Skip filters when forcing host or node
if name_to_cls_map:
return name_to_cls_map.values()
hosts = name_to_cls_map.itervalues()
hosts = six.itervalues(name_to_cls_map)
return self.filter_handler.get_filtered_objects(filters,
hosts, filter_properties, index)
@ -569,7 +570,7 @@ class HostManager(object):
"from scheduler"), {'host': host, 'node': node})
del self.host_state_map[state_key]
return self.host_state_map.itervalues()
return six.itervalues(self.host_state_map)
def _add_instance_info(self, context, compute, host_state):
"""Adds the host instance info to the host_state object.

View File

@ -16,6 +16,7 @@
import copy
from oslo_config import cfg
import six
from nova.compute import api as compute_api
from nova import db
@ -55,7 +56,7 @@ class ServerActionsSampleJsonTest(api_sample_base.ApiSampleTestBaseV3):
def fake_server_actions_get(context, uuid):
return [copy.deepcopy(value) for value in
self.actions[uuid].itervalues()]
six.itervalues(self.actions[uuid])]
def fake_instance_action_events_get(context, action_id):
return copy.deepcopy(self.events[action_id])

View File

@ -14,6 +14,7 @@
# under the License.
from oslo_serialization import jsonutils
import six
import webob
from nova import compute
@ -126,7 +127,7 @@ class ExtendedIpsTestV21(test.TestCase):
return jsonutils.loads(body).get('servers')
def _get_ips(self, server):
for network in server['addresses'].itervalues():
for network in six.itervalues(server['addresses']):
for ip in network:
yield ip

View File

@ -14,6 +14,7 @@
# under the License.
from oslo_serialization import jsonutils
import six
import webob
from nova.api.openstack.compute.contrib import extended_ips_mac
@ -132,7 +133,7 @@ class ExtendedIpsMacTestV21(test.TestCase):
return jsonutils.loads(body).get('servers')
def _get_ips(self, server):
for network in server['addresses'].itervalues():
for network in six.itervalues(server['addresses']):
for ip in network:
yield ip

View File

@ -16,6 +16,7 @@
import copy
import uuid
import six
from webob import exc
from nova.api.openstack.compute.contrib import instance_actions \
@ -163,7 +164,7 @@ class InstanceActionsTestV21(test.NoDBTestCase):
def test_list_actions(self):
def fake_get_actions(context, uuid):
actions = []
for act in self.fake_actions[uuid].itervalues():
for act in six.itervalues(self.fake_actions[uuid]):
action = models.InstanceAction()
action.update(act)
actions.append(action)

View File

@ -7828,7 +7828,7 @@ class ArchiveTestCase(test.TestCase):
def test_archive_deleted_rows_for_every_uuid_table(self):
tablenames = []
for model_class in models.__dict__.itervalues():
for model_class in six.itervalues(models.__dict__):
if hasattr(model_class, "__tablename__"):
tablenames.append(model_class.__tablename__)
tablenames.sort()

View File

@ -1170,11 +1170,11 @@ class TestObjectSerializer(_BaseTestCase):
thing = {'key': obj}
primitive = ser.serialize_entity(self.context, thing)
self.assertEqual(1, len(primitive))
for item in primitive.itervalues():
for item in six.itervalues(primitive):
self.assertNotIsInstance(item, base.NovaObject)
thing2 = ser.deserialize_entity(self.context, primitive)
self.assertEqual(1, len(thing2))
for item in thing2.itervalues():
for item in six.itervalues(thing2):
self.assertIsInstance(item, MyObj)
# object-action updates dict case

View File

@ -15,6 +15,8 @@
# under the License.
"""Unit Tests for network code."""
import six
from nova.network import linux_net
from nova import test
@ -100,9 +102,9 @@ class IptablesManagerTestCase(test.NoDBTestCase):
self.assertFalse(table.dirty)
def test_clean_tables_no_apply(self):
for table in self.manager.ipv4.itervalues():
for table in six.itervalues(self.manager.ipv4):
table.dirty = False
for table in self.manager.ipv6.itervalues():
for table in six.itervalues(self.manager.ipv6):
table.dirty = False
def error_apply():

View File

@ -33,6 +33,7 @@ from oslo_utils import netutils
from oslo_utils import strutils
from oslo_utils import timeutils
from oslo_utils import units
import six
from nova import block_device
from nova import compute
@ -359,7 +360,7 @@ class VMOps(object):
vdis.update(create_image_vdis)
# Fetch VDI refs now so we don't have to fetch the ref multiple times
for vdi in vdis.itervalues():
for vdi in six.itervalues(vdis):
vdi['ref'] = self._session.call_xenapi('VDI.get_by_uuid',
vdi['uuid'])
return vdis