From 1ea3d5ec743838ddb754739a9919a2ecf4c54f9f Mon Sep 17 00:00:00 2001 From: "deepak.mourya" Date: Mon, 25 Jun 2018 10:05:38 +0530 Subject: [PATCH] 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 --- nova/api/openstack/placement/handlers/resource_provider.py | 4 ++++ .../api/openstack/placement/gabbits/resource-provider.yaml | 7 +++++++ placement-api-ref/source/resource_provider.inc | 3 +++ 3 files changed, 14 insertions(+) diff --git a/nova/api/openstack/placement/handlers/resource_provider.py b/nova/api/openstack/placement/handlers/resource_provider.py index 86a83812e6ce..12096c326381 100644 --- a/nova/api/openstack/placement/handlers/resource_provider.py +++ b/nova/api/openstack/placement/handlers/resource_provider.py @@ -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 diff --git a/nova/tests/functional/api/openstack/placement/gabbits/resource-provider.yaml b/nova/tests/functional/api/openstack/placement/gabbits/resource-provider.yaml index e86ba80059fd..d87ceeb4a1e6 100644 --- a/nova/tests/functional/api/openstack/placement/gabbits/resource-provider.yaml +++ b/nova/tests/functional/api/openstack/placement/gabbits/resource-provider.yaml @@ -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: diff --git a/placement-api-ref/source/resource_provider.inc b/placement-api-ref/source/resource_provider.inc index 66b9fd11d1b2..4c1782ddc63e 100644 --- a/placement-api-ref/source/resource_provider.inc +++ b/placement-api-ref/source/resource_provider.inc @@ -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 -------