From: Pushkar Umaranikar Date: Tue, 1 Nov 2016 21:49:19 +0000 (+0000) Subject: Placement api: Add informative message to 404 response. X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=6a422d23e7330ae51a37f899adc9c73596f0dca0;p=osstest%2Fopenstack-nova.git Placement api: Add informative message to 404 response. Add informative messages to the 404 error response from inventory.py and usage.py This change also includes adding/altering existing Gabbi tests for 404 response and add resonse_strings validation checks for that. Change-Id: Ica46a5479dec06b035f8b43d6738e9d124f6ae37 Related-Bug: #1634115 --- diff --git a/nova/api/openstack/placement/handlers/inventory.py b/nova/api/openstack/placement/handlers/inventory.py index 2a445cc05b..86d61a6f5a 100644 --- a/nova/api/openstack/placement/handlers/inventory.py +++ b/nova/api/openstack/placement/handlers/inventory.py @@ -253,6 +253,11 @@ def delete_inventory(req): _('Unable to delete inventory of class %(class)s: %(error)s') % {'class': resource_class, 'error': exc}, json_formatter=util.json_error_formatter) + except exception.NotFound as exc: + raise webob.exc.HTTPNotFound( + _('No inventory of class %(class)s found for delete: %(error)s') % + {'class': resource_class, 'error': exc}, + json_formatter=util.json_error_formatter) response = req.response response.status = 204 @@ -270,8 +275,15 @@ def get_inventories(req): """ context = req.environ['placement.context'] uuid = util.wsgi_path_item(req.environ, 'uuid') - resource_provider = objects.ResourceProvider.get_by_uuid( - context, uuid) + try: + resource_provider = objects.ResourceProvider.get_by_uuid( + context, uuid) + except exception.NotFound as exc: + raise webob.exc.HTTPNotFound( + _("No resource provider with uuid %(uuid)s found : %(error)s") % + {'uuid': uuid, 'error': exc}, + json_formatter=util.json_error_formatter) + inventories = objects.InventoryList.get_all_by_resource_provider_uuid( context, resource_provider.uuid) diff --git a/nova/api/openstack/placement/handlers/usage.py b/nova/api/openstack/placement/handlers/usage.py index aaa59e6b40..236e974e88 100644 --- a/nova/api/openstack/placement/handlers/usage.py +++ b/nova/api/openstack/placement/handlers/usage.py @@ -15,6 +15,8 @@ from oslo_serialization import jsonutils import webob from nova.api.openstack.placement import util +from nova import exception +from nova.i18n import _ from nova import objects @@ -43,8 +45,15 @@ def list_usages(req): # get_all_by_resource_provider_uuid can return an empty list. # It is also needed for the generation, used in the outgoing # representation. - resource_provider = objects.ResourceProvider.get_by_uuid( - context, uuid) + try: + resource_provider = objects.ResourceProvider.get_by_uuid( + context, uuid) + except exception.NotFound as exc: + raise webob.exc.HTTPNotFound( + _("No resource provider with uuid %(uuid)s found: %(error)s") % + {'uuid': uuid, 'error': exc}, + json_formatter=util.json_error_formatter) + usage = objects.UsageList.get_all_by_resource_provider_uuid( context, uuid) diff --git a/nova/tests/functional/api/openstack/placement/gabbits/inventory.yaml b/nova/tests/functional/api/openstack/placement/gabbits/inventory.yaml index 358474dc3e..6bdfe5f418 100644 --- a/nova/tests/functional/api/openstack/placement/gabbits/inventory.yaml +++ b/nova/tests/functional/api/openstack/placement/gabbits/inventory.yaml @@ -9,6 +9,8 @@ tests: - name: inventories for missing provider GET: /resource_providers/7260669a-e3d4-4867-aaa7-683e2ab6958c/inventories status: 404 + response_strings: + - No resource provider with uuid 7260669a-e3d4-4867-aaa7-683e2ab6958c found - name: post new resource provider POST: /resource_providers @@ -241,14 +243,20 @@ tests: - name: delete inventory again DELETE: /resource_providers/$ENVIRON['RP_UUID']/inventories/IPV4_ADDRESS status: 404 + response_strings: + - No inventory of class IPV4_ADDRESS found for delete - name: get missing inventory class GET: /resource_providers/$ENVIRON['RP_UUID']/inventories/IPV4_ADDRESS status: 404 + response_strings: + - No inventory of class IPV4_ADDRESS for $ENVIRON['RP_UUID'] - name: get invalid inventory class GET: /resource_providers/$ENVIRON['RP_UUID']/inventories/HOUSE status: 404 + response_strings: + - No inventory of class HOUSE for $ENVIRON['RP_UUID'] - name: create another resource provider POST: /resource_providers diff --git a/nova/tests/functional/api/openstack/placement/gabbits/usage.yaml b/nova/tests/functional/api/openstack/placement/gabbits/usage.yaml index ef1952e1d4..9027ec0bb7 100644 --- a/nova/tests/functional/api/openstack/placement/gabbits/usage.yaml +++ b/nova/tests/functional/api/openstack/placement/gabbits/usage.yaml @@ -12,6 +12,8 @@ tests: - name: fail to get usages for missing provider GET: /resource_providers/fae14fa3-4b43-498c-a33c-4a1d00edb577/usages status: 404 + response_strings: + - No resource provider with uuid fae14fa3-4b43-498c-a33c-4a1d00edb577 found - name: create provider POST: /resource_providers