diff --git a/nova/objects/resource_provider.py b/nova/objects/resource_provider.py index 640296a58838..4aba8626c520 100644 --- a/nova/objects/resource_provider.py +++ b/nova/objects/resource_provider.py @@ -1850,8 +1850,7 @@ class AllocationList(base.ObjectListBase, base.NovaObject): resource_class_id=rc_id, consumer_id=alloc.consumer_id, used=alloc.used) - result = conn.execute(ins_stmt) - alloc.id = result.lastrowid + conn.execute(ins_stmt) # Generation checking happens here. If the inventory for # this resource provider changed out from under us, diff --git a/nova/tests/functional/db/test_resource_provider.py b/nova/tests/functional/db/test_resource_provider.py index 4937c495fc9f..6fcdf9c9dd9e 100644 --- a/nova/tests/functional/db/test_resource_provider.py +++ b/nova/tests/functional/db/test_resource_provider.py @@ -841,7 +841,6 @@ class TestAllocation(ResourceProviderBaseCase): disk_allocation.used) self.assertEqual(DISK_ALLOCATION['consumer_id'], disk_allocation.consumer_id) - self.assertIsInstance(disk_allocation.id, int) allocations = objects.AllocationList.get_all_by_resource_provider_uuid( self.ctx, resource_provider.uuid) @@ -997,12 +996,13 @@ class TestAllocation(ResourceProviderBaseCase): allocations = objects.AllocationList.get_all_by_resource_provider_uuid( self.ctx, rp.uuid) self.assertEqual(1, len(allocations)) - objects.Allocation._destroy(self.ctx, allocation.id) + allocation_id = allocations[0].id + objects.Allocation._destroy(self.ctx, allocation_id) allocations = objects.AllocationList.get_all_by_resource_provider_uuid( self.ctx, rp.uuid) self.assertEqual(0, len(allocations)) self.assertRaises(exception.NotFound, objects.Allocation._destroy, - self.ctx, allocation.id) + self.ctx, allocation_id) def test_get_allocations_from_db(self): rp, allocation = self._make_allocation() diff --git a/nova/tests/unit/objects/test_resource_provider.py b/nova/tests/unit/objects/test_resource_provider.py index f0a43be78fba..dc69c1a7ce90 100644 --- a/nova/tests/unit/objects/test_resource_provider.py +++ b/nova/tests/unit/objects/test_resource_provider.py @@ -513,9 +513,13 @@ class TestAllocation(test_objects._LocalTest): consumer_id=uuids.fake_instance, used=8) alloc_list = objects.AllocationList(self.context, objects=[obj]) - self.assertNotIn("id", obj) alloc_list.create_all() - self.assertIn("id", obj) + + rp_al = resource_provider.AllocationList + saved_allocations = rp_al.get_all_by_resource_provider_uuid( + self.context, rp.uuid) + self.assertEqual(1, len(saved_allocations)) + self.assertEqual(obj.used, saved_allocations[0].used) def test_create_with_id_fails(self): rp = objects.ResourceProvider(context=self.context,