[placement] add name to resource provider create error

When a resource provider is created an ObjectActionError can
happen. The API handler for POST /resource_provider catches
this and sends out an error response. Prior to this change the
response only identified the resource provider by uuid. Since
it is possible to create a resource provider by only providing
a name, this error response may not be super useful.

This change adds the name of the proposed resource provider to
the message, to make sure things are clear.

However, it's worth noting that at the current time most
situations which would cause an ObjectActionError are not
possible from the API code path: they are caught by the
JSONSchema validation. The one clear path that is not caught,
and thus is the place where a validation of the response has
been done in a gabbit, is when a resource provider tries to
set its parent uuid to its own uuid. In order for the caller
to do this, the caller has to know its own uuid, so the
ambiguity problem is moot.

As we might make additional changes in the future, adding
the name seems the most flexible thing to do, so here it
is.

Change-Id: I7fee5344fc7cb2e4ba3f46e192ba0122edeb0605
Closes-Bug: #1735405
This commit is contained in:
Chris Dent 2017-12-08 15:28:15 +00:00
parent f942f45c1a
commit 885ad10edc
2 changed files with 4 additions and 2 deletions

View File

@ -176,8 +176,9 @@ def create_resource_provider(req):
{'duplicate': duplicate})
except exception.ObjectActionError as exc:
raise webob.exc.HTTPBadRequest(
_('Unable to create resource provider %(rp_uuid)s: %(error)s') %
{'rp_uuid': uuid, 'error': exc})
_('Unable to create resource provider "%(name)s", %(rp_uuid)s: '
'%(error)s') %
{'name': data['name'], 'rp_uuid': uuid, 'error': exc})
req.response.location = util.resource_provider_url(
req.environ, resource_provider)

View File

@ -264,6 +264,7 @@ tests:
status: 400
response_strings:
- 'parent provider UUID cannot be same as UUID'
- 'Unable to create resource provider \"child\", $ENVIRON["ALT_PARENT_PROVIDER_UUID"]:'
- name: update a parent provider UUID to non-existing provider
PUT: /resource_providers/$ENVIRON['RP_UUID']