Merge "[placement] Disambiguate resource provider conflict message"

This commit is contained in:
Jenkins 2017-08-25 11:33:47 +00:00 committed by Gerrit Code Review
commit 42e83eed3e
3 changed files with 59 additions and 4 deletions

View File

@ -130,9 +130,14 @@ def create_resource_provider(req):
context, name=data['name'], uuid=uuid)
resource_provider.create()
except db_exc.DBDuplicateEntry as exc:
# Whether exc.columns has one or two entries (in the event
# of both fields being duplicates) appears to be database
# dependent, so going with the complete solution here.
duplicate = ', '.join(['%s: %s' % (column, data[column])
for column in exc.columns])
raise webob.exc.HTTPConflict(
_('Conflicting resource provider %(name)s already exists.') %
{'name': data['name']})
_('Conflicting resource provider %(duplicate)s already exists.') %
{'duplicate': duplicate})
except exception.ObjectActionError as exc:
raise webob.exc.HTTPBadRequest(
_('Unable to create resource provider %(rp_uuid)s: %(error)s') %

View File

@ -0,0 +1,48 @@
# Verify different error messages was attempting to create a
# resource provider with a duplicated name or UUID.
fixtures:
- APIFixture
defaults:
request_headers:
x-auth-token: admin
accept: application/json
content-type: application/json
tests:
- name: post new resource provider
POST: /resource_providers
data:
name: shared disk
uuid: $ENVIRON['RP_UUID']
status: 201
- name: same uuid different name
POST: /resource_providers
data:
name: shared disk X
uuid: $ENVIRON['RP_UUID']
status: 409
response_strings:
- "Conflicting resource provider uuid: $ENVIRON['RP_UUID']"
- name: same name different uuid
POST: /resource_providers
data:
name: shared disk
uuid: 2c2059d8-005c-4f5c-82b1-b1701b1a29b7
status: 409
response_strings:
- 'Conflicting resource provider name: shared disk'
# On this one, don't test for which field was a duplicate because
# that depends on how the database reports columns.
- name: same name same uuid
POST: /resource_providers
data:
name: $ENVIRON['RP_NAME']
uuid: $ENVIRON['RP_UUID']
status: 409
response_strings:
- Conflicting resource provider

View File

@ -45,6 +45,8 @@ tests:
response_forbidden_headers:
- content-type
# On this one, don't test for which field was a duplicate because
# that depends on how the database reports columns.
- name: try to create same all again
POST: /resource_providers
request_headers:
@ -54,7 +56,7 @@ tests:
uuid: $ENVIRON['RP_UUID']
status: 409
response_strings:
- Conflicting resource provider $ENVIRON['RP_NAME'] already exists
- Conflicting resource provider
response_json_paths:
$.errors[0].title: Conflict
@ -67,7 +69,7 @@ tests:
uuid: ada30fb5-566d-4fe1-b43b-28a9e988790c
status: 409
response_strings:
- Conflicting resource provider $ENVIRON['RP_NAME'] already exists
- "Conflicting resource provider name: $ENVIRON['RP_NAME'] already exists"
response_json_paths:
$.errors[0].title: Conflict