diff --git a/nova/objects/pci_device.py b/nova/objects/pci_device.py index 34056604caba..6c80143ff5ad 100644 --- a/nova/objects/pci_device.py +++ b/nova/objects/pci_device.py @@ -157,8 +157,8 @@ class PciDevice(base.NovaPersistentObject, base.NovaObject): # functions like claim/allocate etc. The id is allocated by # database. The extra_info is created by the object. no_changes = ('status', 'instance_uuid', 'id', 'extra_info') - map(lambda x: dev_dict.pop(x, None), - [key for key in no_changes]) + for key in no_changes: + dev_dict.pop(key, None) # NOTE(ndipanov): This needs to be set as it's accessed when matching dev_dict.setdefault('parent_addr') diff --git a/nova/pci/manager.py b/nova/pci/manager.py index eea8480cb35b..5e8d3d97d3ec 100644 --- a/nova/pci/manager.py +++ b/nova/pci/manager.py @@ -312,12 +312,14 @@ class PciDevTracker(object): existed |= set(mig['instance_uuid'] for mig in migrations) existed |= set(inst['uuid'] for inst in orphans) - for uuid in self.claims.keys(): + # need to copy keys, because the dict is modified in the loop body + for uuid in list(self.claims): if uuid not in existed: devs = self.claims.pop(uuid, []) for dev in devs: self._free_device(dev) - for uuid in self.allocations.keys(): + # need to copy keys, because the dict is modified in the loop body + for uuid in list(self.allocations): if uuid not in existed: devs = self.allocations.pop(uuid, []) for dev in devs: diff --git a/nova/pci/stats.py b/nova/pci/stats.py index cd713499d50f..3ca70cfd3378 100644 --- a/nova/pci/stats.py +++ b/nova/pci/stats.py @@ -296,10 +296,11 @@ class PciDeviceStats(object): self.pools = [] def __eq__(self, other): - return cmp(self.pools, other.pools) == 0 + return self.pools == other.pools - def __ne__(self, other): - return not (self == other) + if six.PY2: + def __ne__(self, other): + return not (self == other) def to_device_pools_obj(self): """Return the contents of the pools as a PciDevicePoolList object.""" diff --git a/nova/tests/unit/pci/test_manager.py b/nova/tests/unit/pci/test_manager.py index 49fa4076fce4..250941a6fc5f 100644 --- a/nova/tests/unit/pci/test_manager.py +++ b/nova/tests/unit/pci/test_manager.py @@ -157,7 +157,7 @@ class PciDevTrackerTestCase(test.NoDBTestCase): self.assertEqual(len(self.tracker.pci_devs), 3) free_devs = self.tracker.pci_stats.get_free_devs() self.assertEqual(len(free_devs), 3) - self.assertEqual(self.tracker.stale.keys(), []) + self.assertEqual(list(self.tracker.stale), []) self.assertEqual(len(self.tracker.stats.pools), 3) self.assertEqual(self.tracker.node_id, 1) for dev in self.tracker.pci_devs: @@ -170,7 +170,7 @@ class PciDevTrackerTestCase(test.NoDBTestCase): self.assertEqual(len(self.tracker.pci_devs), 3) free_devs = self.tracker.pci_stats.get_free_devs() self.assertEqual(len(free_devs), 3) - self.assertEqual(self.tracker.stale.keys(), []) + self.assertEqual(list(self.tracker.stale), []) self.assertEqual(len(self.tracker.stats.pools), 2) self.assertEqual(self.tracker.node_id, 1) pf = [dev for dev in self.tracker.pci_devs @@ -190,7 +190,7 @@ class PciDevTrackerTestCase(test.NoDBTestCase): self.assertEqual(len(self.tracker.pci_devs), 1) free_devs = self.tracker.pci_stats.get_free_devs() self.assertEqual(len(free_devs), 1) - self.assertEqual(self.tracker.stale.keys(), []) + self.assertEqual(list(self.tracker.stale), []) self.assertEqual(len(self.tracker.stats.pools), 1) self.assertEqual(self.tracker.node_id, 1) pf = self.tracker.pci_devs[0] @@ -203,7 +203,7 @@ class PciDevTrackerTestCase(test.NoDBTestCase): self.assertEqual(len(self.tracker.pci_devs), 1) free_devs = self.tracker.pci_stats.get_free_devs() self.assertEqual(len(free_devs), 1) - self.assertEqual(self.tracker.stale.keys(), []) + self.assertEqual(list(self.tracker.stale), []) self.assertEqual(len(self.tracker.stats.pools), 1) self.assertEqual(self.tracker.node_id, 1) vf = self.tracker.pci_devs[0] diff --git a/nova/tests/unit/pci/test_stats.py b/nova/tests/unit/pci/test_stats.py index ce3e9bc26902..e6beb20a6666 100644 --- a/nova/tests/unit/pci/test_stats.py +++ b/nova/tests/unit/pci/test_stats.py @@ -73,9 +73,9 @@ class PciDeviceStatsTestCase(test.NoDBTestCase): self.fake_dev_3 = objects.PciDevice.create(None, fake_pci_3) self.fake_dev_4 = objects.PciDevice.create(None, fake_pci_4) - map(self.pci_stats.add_device, - [self.fake_dev_1, self.fake_dev_2, - self.fake_dev_3, self.fake_dev_4]) + for dev in [self.fake_dev_1, self.fake_dev_2, + self.fake_dev_3, self.fake_dev_4]: + self.pci_stats.add_device(dev) def setUp(self): super(PciDeviceStatsTestCase, self).setUp() @@ -106,17 +106,19 @@ class PciDeviceStatsTestCase(test.NoDBTestCase): def test_pci_stats_equivalent(self): pci_stats2 = stats.PciDeviceStats() - map(pci_stats2.add_device, [self.fake_dev_1, - self.fake_dev_2, - self.fake_dev_3, - self.fake_dev_4]) + for dev in [self.fake_dev_1, + self.fake_dev_2, + self.fake_dev_3, + self.fake_dev_4]: + pci_stats2.add_device(dev) self.assertEqual(self.pci_stats, pci_stats2) def test_pci_stats_not_equivalent(self): pci_stats2 = stats.PciDeviceStats() - map(pci_stats2.add_device, [self.fake_dev_1, - self.fake_dev_2, - self.fake_dev_3]) + for dev in [self.fake_dev_1, + self.fake_dev_2, + self.fake_dev_3]: + pci_stats2.add_device(dev) self.assertNotEqual(self.pci_stats, pci_stats2) def test_object_create(self): @@ -258,8 +260,11 @@ class PciDeviceStatsWithTagsTestCase(test.NoDBTestCase): self.pci_untagged_devices.append(objects.PciDevice.create(None, pci_dev)) - map(self.pci_stats.add_device, self.pci_tagged_devices) - map(self.pci_stats.add_device, self.pci_untagged_devices) + for dev in self.pci_tagged_devices: + self.pci_stats.add_device(dev) + + for dev in self.pci_untagged_devices: + self.pci_stats.add_device(dev) def _assertPoolContent(self, pool, vendor_id, product_id, count, **tags): self.assertEqual(vendor_id, pool['vendor_id']) diff --git a/tests-py3.txt b/tests-py3.txt index c513f6e2f43b..ac650a2ddaa3 100644 --- a/tests-py3.txt +++ b/tests-py3.txt @@ -53,9 +53,6 @@ nova.tests.unit.db.test_migrations.TestNovaMigrationsPostgreSQL nova.tests.unit.db.test_migrations.TestNovaMigrationsSQLite nova.tests.unit.image.test_fake.FakeImageServiceTestCase nova.tests.unit.network.test_manager.LdapDNSTestCase -nova.tests.unit.pci.test_manager.PciDevTrackerTestCase -nova.tests.unit.pci.test_stats.PciDeviceStatsTestCase -nova.tests.unit.pci.test_stats.PciDeviceStatsWithTagsTestCase nova.tests.unit.test_bdm.BlockDeviceMappingEc2CloudTestCase nova.tests.unit.test_configdrive2.ConfigDriveTestCase nova.tests.unit.test_hacking.HackingTestCase