Handle CannotDeleteParentResourceProvider to 409 Conflict

Error handling to raise the exception 409 while deleting
the parent if it has children.

Closes-Bug: #1770636
Change-Id: I87df68992e4e635f009974f5205ca4919a4f2576
This commit is contained in:
deepak.mourya 2018-06-25 10:05:38 +05:30 committed by Deepak Mourya
parent 9113dc0c06
commit 1ea3d5ec74
3 changed files with 14 additions and 0 deletions

View File

@ -141,6 +141,10 @@ def delete_resource_provider(req):
except exception.NotFound as exc:
raise webob.exc.HTTPNotFound(
_("No resource provider with uuid %s found for delete") % uuid)
except exception.CannotDeleteParentResourceProvider as exc:
raise webob.exc.HTTPConflict(
_("Unable to delete parent resource provider %(rp_uuid)s: "
"It has child resource providers.") % {'rp_uuid': uuid})
req.response.status = 204
req.response.content_type = None
return req.response

View File

@ -388,6 +388,13 @@ tests:
response_strings:
- 'un-parenting a provider is not currently allowed'
- name: 409 conflict while trying to delete parent with existing child
DELETE: /resource_providers/$ENVIRON['PARENT_PROVIDER_UUID']
status: 409
response_strings:
- "Unable to delete parent resource provider
$ENVIRON['PARENT_PROVIDER_UUID']: It has child resource providers."
- name: list all resource providers in a tree that does not exist
GET: /resource_providers?in_tree=$ENVIRON['ALT_PARENT_PROVIDER_UUID']
response_json_paths:

View File

@ -106,6 +106,9 @@ A `409 Conflict` response code will be returned if there exist
allocations records for any of the inventories that would be deleted
as a result of removing the resource provider.
This error code will be also returned if there are existing child resource
providers under the parent resource provider being deleted.
Request
-------