diff --git a/nova/api/openstack/placement/handlers/allocation.py b/nova/api/openstack/placement/handlers/allocation.py index 8fc154a6c03e..e67257aa98a4 100644 --- a/nova/api/openstack/placement/handlers/allocation.py +++ b/nova/api/openstack/placement/handlers/allocation.py @@ -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 diff --git a/nova/api/openstack/placement/handlers/resource_provider.py b/nova/api/openstack/placement/handlers/resource_provider.py index b24fb9a06341..271c8f57a333 100644 --- a/nova/api/openstack/placement/handlers/resource_provider.py +++ b/nova/api/openstack/placement/handlers/resource_provider.py @@ -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 diff --git a/nova/objects/resource_provider.py b/nova/objects/resource_provider.py index 7300c496192b..d069395a20b2 100644 --- a/nova/objects/resource_provider.py +++ b/nova/objects/resource_provider.py @@ -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 diff --git a/nova/tests/functional/api/openstack/placement/gabbits/allocations.yaml b/nova/tests/functional/api/openstack/placement/gabbits/allocations.yaml index cf769a683e13..b606ef680b47 100644 --- a/nova/tests/functional/api/openstack/placement/gabbits/allocations.yaml +++ b/nova/tests/functional/api/openstack/placement/gabbits/allocations.yaml @@ -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 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 3c3687401d51..50d9c40de516 100644 --- a/nova/tests/functional/api/openstack/placement/gabbits/resource-provider.yaml +++ b/nova/tests/functional/api/openstack/placement/gabbits/resource-provider.yaml @@ -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: