Enable python34 tests for nova.tests.unit.pci.test_manager and test_stats
nova/objects/pci_device.py: The keys in no_changes were not popped out of the dictionary since map is lazily evaluated in python3. Changed the map/lambda to simple loop. nova/pci/manager.py: In python3 keys() returns an iterator instead of a list (copy of the keys). This was causing error "RuntimeError: dictionary changed size during iteration". nova/pci/stats.py: Python3 doesn't support cmp anymore. Use '==' operator instead. nova/tests/unit/pci/test_manager.py: keys() now returns dict_keys. Convert it to a list so that we can compare it with []. nova/tests/unit/pci/test_stats.py: Map are lazily evaluated, convert to basic loop. Partially Implements: blueprint nova-python3-newton Change-Id: I0b14f169118d87505a736daf46be7ed0af57279b
This commit is contained in:
parent
4c4591f2cd
commit
a24f5b3eb3
@ -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')
|
||||
|
@ -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:
|
||||
|
@ -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."""
|
||||
|
@ -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]
|
||||
|
@ -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'])
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user