Merge "Fix missing RP generation update"

This commit is contained in:
Jenkins 2017-01-16 00:40:25 +00:00 committed by Gerrit Code Review
commit 46b8cdfd00
2 changed files with 16 additions and 5 deletions

View File

@ -1071,10 +1071,7 @@ def _check_capacity_exceeded(conn, allocs):
resource_class=alloc.resource_class,
resource_provider=rp_uuid)
if rp_uuid not in res_providers:
rp = ResourceProvider(id=usage['resource_provider_id'],
uuid=rp_uuid,
generation=usage['generation'])
res_providers[rp_uuid] = rp
res_providers[rp_uuid] = alloc.resource_provider
return list(res_providers.values())
@ -1162,7 +1159,7 @@ class AllocationList(base.ObjectListBase, base.NovaObject):
# by the caller to choose to try again. It will also rollback the
# transaction so that these changes always happen atomically.
for rp in before_gens:
_increment_provider_generation(conn, rp)
rp.generation = _increment_provider_generation(conn, rp)
@classmethod
def get_all_by_resource_provider_uuid(cls, context, rp_uuid):

View File

@ -503,6 +503,20 @@ class ResourceProviderTestCase(ResourceProviderBaseCase):
self.assertIn("on resource provider '%s'."
% rp.uuid, str(error))
def test_add_allocation_increments_generation(self):
rp = objects.ResourceProvider(context=self.context,
uuid=uuidsentinel.inventory_resource_provider, name='foo')
rp.create()
inv = objects.Inventory(context=self.context, resource_provider=rp,
**DISK_INVENTORY)
inv.create()
expected_gen = rp.generation + 1
alloc = objects.Allocation(context=self.context, resource_provider=rp,
**DISK_ALLOCATION)
alloc_list = objects.AllocationList(self.context, objects=[alloc])
alloc_list.create_all()
self.assertEqual(expected_gen, rp.generation)
class ResourceProviderListTestCase(ResourceProviderBaseCase):
def setUp(self):