From 28ad7c517d99e08b872c0c15f7ca5d156d438b7e Mon Sep 17 00:00:00 2001 From: Takashi Natsume Date: Wed, 13 May 2020 12:57:29 +0000 Subject: [PATCH] Remove six.iteritems/itervalues/iterkeys Replace the following items with Python 3 style code. - six.iteritems - six.itervalues - six.iterkeys Subsequent patches will replace other six usages. Change-Id: Id55de3a105bedcf61bcfc797aabe86d6e75709c8 Implements: blueprint six-removal Signed-off-by: Takashi Natsume --- nova/api/openstack/compute/hosts.py | 3 +-- nova/cmd/manage.py | 3 +-- nova/compute/provider_tree.py | 3 +-- nova/scheduler/host_manager.py | 3 +-- nova/test.py | 2 +- nova/tests/unit/api/openstack/compute/test_extended_ips.py | 3 +-- .../tests/unit/api/openstack/compute/test_extended_ips_mac.py | 3 +-- .../tests/unit/api/openstack/compute/test_instance_actions.py | 2 +- nova/tests/unit/api/openstack/test_wsgi.py | 3 +-- nova/tests/unit/db/test_db_api.py | 2 +- nova/tests/unit/objects/test_objects.py | 4 ++-- nova/virt/libvirt/driver.py | 4 ++-- 12 files changed, 14 insertions(+), 21 deletions(-) diff --git a/nova/api/openstack/compute/hosts.py b/nova/api/openstack/compute/hosts.py index a891ace1c7..14d1a2666a 100644 --- a/nova/api/openstack/compute/hosts.py +++ b/nova/api/openstack/compute/hosts.py @@ -16,7 +16,6 @@ """The hosts admin extension.""" from oslo_log import log as logging -import six import webob.exc from nova.api.openstack import common @@ -287,6 +286,6 @@ class HostController(wsgi.Controller): instances)) by_proj_resources = self._get_resources_by_project(host_name, instances) - for resource in six.itervalues(by_proj_resources): + for resource in by_proj_resources.values(): resources.append({'resource': resource}) return {'host': resources} diff --git a/nova/cmd/manage.py b/nova/cmd/manage.py index 2b42b9091e..d5682c6519 100644 --- a/nova/cmd/manage.py +++ b/nova/cmd/manage.py @@ -2584,8 +2584,7 @@ class PlacementCommands(object): raise # Verify every allocations for each consumer UUID - for consumer_uuid, consumer_resources in six.iteritems( - pallocs.allocations): + for consumer_uuid, consumer_resources in pallocs.allocations.items(): consumer_allocs = consumer_resources['resources'] if any(rc in NOVA_RCS for rc in consumer_allocs): diff --git a/nova/compute/provider_tree.py b/nova/compute/provider_tree.py index 42724bdd79..982dd79a3e 100644 --- a/nova/compute/provider_tree.py +++ b/nova/compute/provider_tree.py @@ -25,7 +25,6 @@ import os_traits from oslo_concurrency import lockutils from oslo_log import log as logging from oslo_utils import uuidutils -import six from nova.i18n import _ @@ -255,7 +254,7 @@ class ProviderTree(object): @property def roots(self): - return six.itervalues(self.roots_by_uuid) + return self.roots_by_uuid.values() def get_provider_uuids(self, name_or_uuid=None): """Return a list, in top-down traversable order, of the UUIDs of all diff --git a/nova/scheduler/host_manager.py b/nova/scheduler/host_manager.py index 9c5e2acccb..ea2b0d2949 100644 --- a/nova/scheduler/host_manager.py +++ b/nova/scheduler/host_manager.py @@ -29,7 +29,6 @@ except ImportError: import iso8601 from oslo_log import log as logging from oslo_utils import timeutils -import six import nova.conf from nova import context as context_module @@ -600,7 +599,7 @@ class HostManager(object): return name_to_cls_map.values() else: return [] - hosts = six.itervalues(name_to_cls_map) + hosts = name_to_cls_map.values() return self.filter_handler.get_filtered_objects(self.enabled_filters, hosts, spec_obj, index) diff --git a/nova/test.py b/nova/test.py index 9cf5a7fbbe..fc8b091451 100644 --- a/nova/test.py +++ b/nova/test.py @@ -549,7 +549,7 @@ class TestCase(base.BaseTestCase): self.assertEqual( expected_keys, observed_keys, 'path: %s. Dict keys are not equal' % path) - for key in list(six.iterkeys(expected)): + for key in expected: inner(expected[key], observed[key], path + '.%s' % key) elif (isinstance(expected, (list, tuple, set)) and isinstance(observed, (list, tuple, set))): diff --git a/nova/tests/unit/api/openstack/compute/test_extended_ips.py b/nova/tests/unit/api/openstack/compute/test_extended_ips.py index f26b925840..a5eabcf19f 100644 --- a/nova/tests/unit/api/openstack/compute/test_extended_ips.py +++ b/nova/tests/unit/api/openstack/compute/test_extended_ips.py @@ -14,7 +14,6 @@ # under the License. from oslo_serialization import jsonutils -import six from nova import objects from nova import test @@ -120,7 +119,7 @@ class ExtendedIpsTestV21(test.TestCase): return jsonutils.loads(body).get('servers') def _get_ips(self, server): - for network in six.itervalues(server['addresses']): + for network in server['addresses'].values(): for ip in network: yield ip diff --git a/nova/tests/unit/api/openstack/compute/test_extended_ips_mac.py b/nova/tests/unit/api/openstack/compute/test_extended_ips_mac.py index afaf60fc12..c797e9cc84 100644 --- a/nova/tests/unit/api/openstack/compute/test_extended_ips_mac.py +++ b/nova/tests/unit/api/openstack/compute/test_extended_ips_mac.py @@ -14,7 +14,6 @@ # under the License. from oslo_serialization import jsonutils -import six from nova import objects from nova import test @@ -125,7 +124,7 @@ class ExtendedIpsMacTestV21(test.TestCase): return jsonutils.loads(body).get('servers') def _get_ips(self, server): - for network in six.itervalues(server['addresses']): + for network in server['addresses'].values(): for ip in network: yield ip diff --git a/nova/tests/unit/api/openstack/compute/test_instance_actions.py b/nova/tests/unit/api/openstack/compute/test_instance_actions.py index 9a14233692..503ab1f6c1 100644 --- a/nova/tests/unit/api/openstack/compute/test_instance_actions.py +++ b/nova/tests/unit/api/openstack/compute/test_instance_actions.py @@ -129,7 +129,7 @@ class InstanceActionsTestV21(test.NoDBTestCase): def fake_get_actions(context, uuid, limit=None, marker=None, filters=None): actions = [] - for act in six.itervalues(self.fake_actions[uuid]): + for act in self.fake_actions[uuid].values(): action = models.InstanceAction() action.update(act) actions.append(action) diff --git a/nova/tests/unit/api/openstack/test_wsgi.py b/nova/tests/unit/api/openstack/test_wsgi.py index a80158f6e6..e0cf8f6fd8 100644 --- a/nova/tests/unit/api/openstack/test_wsgi.py +++ b/nova/tests/unit/api/openstack/test_wsgi.py @@ -12,7 +12,6 @@ import mock from oslo_serialization import jsonutils -import six import testscenarios import webob @@ -747,7 +746,7 @@ class ResourceTest(MicroversionedTest): req = webob.Request.blank('/tests') app = fakes.TestRouter(Controller()) response = req.get_response(app) - for val in six.itervalues(response.headers): + for val in response.headers.values(): # All headers must be utf8 self.assertThat(val, matchers.EncodedByUTF8()) self.assertEqual('1', response.headers['x-header1']) diff --git a/nova/tests/unit/db/test_db_api.py b/nova/tests/unit/db/test_db_api.py index f455f7a10f..92cd7871da 100644 --- a/nova/tests/unit/db/test_db_api.py +++ b/nova/tests/unit/db/test_db_api.py @@ -6327,7 +6327,7 @@ class ArchiveTestCase(test.TestCase, ModelsObjectComparatorMixin): def test_archive_deleted_rows_for_every_uuid_table(self): tablenames = [] - for model_class in six.itervalues(models.__dict__): + for model_class in models.__dict__.values(): if hasattr(model_class, "__tablename__"): tablenames.append(model_class.__tablename__) tablenames.sort() diff --git a/nova/tests/unit/objects/test_objects.py b/nova/tests/unit/objects/test_objects.py index 41ff810f9e..2c6812ae1f 100644 --- a/nova/tests/unit/objects/test_objects.py +++ b/nova/tests/unit/objects/test_objects.py @@ -956,11 +956,11 @@ class TestObjectSerializer(_BaseTestCase): thing = {'key': obj} primitive = ser.serialize_entity(self.context, thing) self.assertEqual(1, len(primitive)) - for item in six.itervalues(primitive): + for item in primitive.values(): self.assertNotIsInstance(item, base.NovaObject) thing2 = ser.deserialize_entity(self.context, primitive) self.assertEqual(1, len(thing2)) - for item in six.itervalues(thing2): + for item in thing2.values(): self.assertIsInstance(item, MyObj) # object-action updates dict case diff --git a/nova/virt/libvirt/driver.py b/nova/virt/libvirt/driver.py index 44e788895d..e93791f5fb 100644 --- a/nova/virt/libvirt/driver.py +++ b/nova/virt/libvirt/driver.py @@ -809,7 +809,7 @@ class LibvirtDriver(driver.ComputeDriver): # devices by looking up existing guest XMLs and doesn't use # the Placement API so it works with or without a vGPU reshape. mdevs = self._get_all_assigned_mediated_devices() - for (mdev_uuid, instance_uuid) in six.iteritems(mdevs): + for (mdev_uuid, instance_uuid) in mdevs.items(): if not self._is_existing_mdev(mdev_uuid): dev_name = libvirt_utils.mdev_uuid2name(mdev_uuid) dev_info = self._get_mediated_device_information(dev_name) @@ -7358,7 +7358,7 @@ class LibvirtDriver(driver.ComputeDriver): LOG.warning('More than one allocation was passed over to libvirt ' 'while at the moment libvirt only supports one. Only ' 'the first allocation will be looked up.') - rp_uuid, alloc = six.next(six.iteritems(vgpu_allocations)) + rp_uuid, alloc = next(iter(vgpu_allocations.items())) vgpus_asked = alloc['resources'][orc.VGPU] # Find if we allocated against a specific pGPU (and then the allocation