Add placement.concurrent_udpate to generation pre-checks

We have two kinds of generation conflicts that happen (for both
resource providers and consumers). In
I5a164a0ee298846231113ad7b62b82a3e8f1f409 error codes are added for
conflicts that happen when incrementing the generation in the database.s

In this change the codes are added for those situations where in code we
are checking an incoming generation against the stored generation.

Since there are incoming genearations in this case, we can add tests
so this does, via gabbi.

Change-Id: I5ed005068c1c19194ed67556376604ae90727412
This commit is contained in:
Chris Dent 2018-07-11 15:56:12 +01:00
parent c5cdef24ed
commit dd13c2784b
8 changed files with 25 additions and 6 deletions

View File

@ -122,7 +122,8 @@ def set_aggregates(req):
if resource_provider.generation != rp_gen:
raise webob.exc.HTTPConflict(
_("Resource provider's generation already changed. Please "
"update the generation and try again."))
"update the generation and try again."),
comment=errors.CONCURRENT_UPDATE)
aggregate_uuids = data['aggregates']
else:
aggregate_uuids = data

View File

@ -331,7 +331,8 @@ def set_inventories(req):
data = _extract_inventories(req.body, schema.PUT_INVENTORY_SCHEMA)
if data['resource_provider_generation'] != resource_provider.generation:
raise webob.exc.HTTPConflict(
_('resource provider generation conflict'))
_('resource provider generation conflict'),
comment=errors.CONCURRENT_UPDATE)
inv_list = []
for res_class, inventory_data in data['inventories'].items():
@ -436,7 +437,8 @@ def update_inventory(req):
data = _extract_inventory(req.body, schema.BASE_INVENTORY_SCHEMA)
if data['resource_provider_generation'] != resource_provider.generation:
raise webob.exc.HTTPConflict(
_('resource provider generation conflict'))
_('resource provider generation conflict'),
comment=errors.CONCURRENT_UPDATE)
inventory = _make_inventory_object(resource_provider,
resource_class,

View File

@ -226,7 +226,8 @@ def update_traits_for_resource_provider(req):
raise webob.exc.HTTPConflict(
_("Resource provider's generation already changed. Please update "
"the generation and try again."),
json_formatter=util.json_error_formatter)
json_formatter=util.json_error_formatter,
comment=errors.CONCURRENT_UPDATE)
trait_objs = rp_obj.TraitList.get_all(
context, filters={'name_in': traits})

View File

@ -639,7 +639,8 @@ def ensure_consumer(ctx, consumer_uuid, project_id, user_id,
{
'expected_gen': consumer.generation,
'got_gen': consumer_generation,
})
},
comment=errors.CONCURRENT_UPDATE)
# NOTE(jaypipes): The user may have specified a different project and
# user external ID than the one that we had for the consumer. If this
# is the case, go ahead and modify the consumer record with the
@ -681,7 +682,8 @@ def ensure_consumer(ctx, consumer_uuid, project_id, user_id,
if consumer_generation is not None:
raise webob.exc.HTTPConflict(
_('consumer generation conflict - '
'expected null but got %s') % consumer_generation)
'expected null but got %s') % consumer_generation,
comment=errors.CONCURRENT_UPDATE)
# No such consumer. This is common for new allocations. Create the
# consumer record
try:

View File

@ -116,6 +116,8 @@ tests:
resource_provider_generation: 0
aggregates: []
status: 409
response_json_paths:
$.errors[0].code: placement.concurrent_update
- name: clear those aggregates
PUT: $LAST_URL

View File

@ -64,6 +64,8 @@ tests:
response_strings:
- consumer generation conflict
- expected null but got 5
response_json_paths:
$.errors[0].code: placement.concurrent_update
- name: new version gen is None no existing
PUT: /allocations/22222222-2222-2222-2222-222222222222
@ -147,6 +149,8 @@ tests:
status: 409
response_strings:
- consumer generation conflict
response_json_paths:
$.errors[0].code: placement.concurrent_update
- name: old version no gen existing
PUT: /allocations/44444444-4444-4444-4444-444444444444

View File

@ -220,6 +220,7 @@ tests:
PUT: $LAST_URL
request_headers:
content-type: application/json
openstack-api-version: placement 1.23
data:
resource_provider_generation: 5
total: 2048
@ -228,6 +229,7 @@ tests:
- resource provider generation conflict
response_json_paths:
$.errors[0].title: Conflict
$.errors[0].code: placement.concurrent_update
- name: modify inventory no such resource class in inventory
PUT: /resource_providers/$ENVIRON['RP_UUID']/inventories/MEMORY_MB
@ -467,6 +469,7 @@ tests:
PUT: /resource_providers/$ENVIRON['RP_UUID']/inventories
request_headers:
content-type: application/json
openstack-api-version: placement 1.23
data:
resource_provider_generation: 99
inventories:
@ -477,6 +480,7 @@ tests:
- resource provider generation conflict
response_json_paths:
$.errors[0].title: Conflict
$.errors[0].code: placement.concurrent_update
- name: put all inventory unknown resource class
PUT: /resource_providers/$ENVIRON['RP_UUID']/inventories

View File

@ -325,6 +325,7 @@ tests:
PUT: /resource_providers/$ENVIRON['RP_UUID']/traits
request_headers:
content-type: application/json
openstack-api-version: placement 1.23
status: 409
data:
traits:
@ -332,6 +333,8 @@ tests:
resource_provider_generation: 5
response_strings:
- Resource provider's generation already changed. Please update the generation and try again.
response_json_paths:
$.errors[0].code: placement.concurrent_update
- name: set non existed traits for resource provider
PUT: /resource_providers/$ENVIRON['RP_UUID']/traits