Merge "Placement api: 404 response do not indicate what was not found"

This commit is contained in:
Jenkins 2016-11-16 11:41:05 +00:00 committed by Gerrit Code Review
commit 625a539358
5 changed files with 35 additions and 5 deletions

View File

@ -284,12 +284,23 @@ def delete_allocations(req):
allocations = objects.AllocationList.get_all_by_consumer_id(
context, consumer_uuid)
if not allocations:
if allocations:
try:
allocations.delete_all()
# NOTE(pumaranikar): Following NotFound exception added in the case
# when allocation is deleted from allocations list by some other
# activity. In that case, delete_all() will throw a NotFound exception.
except exception.NotFound as exc:
raise webob.exc.HTPPNotFound(
_("Allocation for consumer with id %(id)s not found."
"error: %(error)s") %
{'id': consumer_uuid, 'error': exc},
json_formatter=util.json_error_formatter)
else:
raise webob.exc.HTTPNotFound(
_("No allocations for consumer '%(consumer_uuid)s'") %
{'consumer_uuid': consumer_uuid},
json_formatter=util.json_error_formatter)
allocations.delete_all()
LOG.debug("Successfully deleted allocations %s", allocations)
req.response.status = 204

View File

@ -114,15 +114,18 @@ def delete_resource_provider(req):
uuid = util.wsgi_path_item(req.environ, 'uuid')
context = req.environ['placement.context']
# The containing application will catch a not found here.
resource_provider = objects.ResourceProvider.get_by_uuid(
context, uuid)
try:
resource_provider = objects.ResourceProvider.get_by_uuid(
context, uuid)
resource_provider.destroy()
except exception.ResourceProviderInUse as exc:
raise webob.exc.HTTPConflict(
_('Unable to delete resource provider %(rp_uuid)s: %(error)s') %
{'rp_uuid': uuid, 'error': exc},
json_formatter=util.json_error_formatter)
except exception.NotFound as exc:
raise webob.exc.HTTPNotFound(
_("No resource provider with uuid %s found for delete") % uuid)
req.response.status = 204
req.response.content_type = None
return req.response

View File

@ -431,7 +431,9 @@ class ResourceProvider(base.NovaObject):
result = context.session.query(models.ResourceProvider).filter_by(
uuid=uuid).first()
if not result:
raise exception.NotFound()
raise exception.NotFound(
'No resource provider with uuid %s found'
% uuid)
return result

View File

@ -153,6 +153,8 @@ tests:
- name: delete allocation again
DELETE: /allocations/599ffd2d-526a-4b2e-8683-f13ad25f9958
status: 404
response_strings:
- No allocations for consumer '599ffd2d-526a-4b2e-8683-f13ad25f9958'
- name: delete allocation of unknown consumer id
DELETE: /allocations/da78521f-bf7e-4e6e-9901-3f79bd94d55d

View File

@ -86,6 +86,12 @@ tests:
response_json_paths:
$.uuid: $ENVIRON['RP_UUID']
- name: get non-existing resource provider
GET: /resource_providers/d67370b5-4dc0-470d-a4fa-85e8e89abc6c
status: 404
response_strings:
- No resource provider with uuid d67370b5-4dc0-470d-a4fa-85e8e89abc6c found
- name: list one resource providers
GET: /resource_providers
response_json_paths:
@ -213,6 +219,12 @@ tests:
GET: /resource_providers/random_sauce
status: 404
- name: delete non-existing resource provider
DELETE: /resource_providers/d67370b5-4dc0-470d-a4fa-85e8e89abc6c
status: 404
response_strings:
- No resource provider with uuid d67370b5-4dc0-470d-a4fa-85e8e89abc6c found for delete
- name: post resource provider no uuid
POST: /resource_providers
request_headers: