]> xenbits.xensource.com Git - osstest/openstack-nova.git/commitdiff
Placement api: Add informative message to 404 response.
authorPushkar Umaranikar <pushkar.umaranikar@intel.com>
Tue, 1 Nov 2016 21:49:19 +0000 (21:49 +0000)
committerMatt Riedemann <mriedem@us.ibm.com>
Wed, 23 Nov 2016 22:51:07 +0000 (22:51 +0000)
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

nova/api/openstack/placement/handlers/inventory.py
nova/api/openstack/placement/handlers/usage.py
nova/tests/functional/api/openstack/placement/gabbits/inventory.yaml
nova/tests/functional/api/openstack/placement/gabbits/usage.yaml

index 2a445cc05b2c71bb9aa657553726f3e3e6904531..86d61a6f5a2cc8ced9ea8508e7302ac2809a54c5 100644 (file)
@@ -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)
 
index aaa59e6b40b2773a71de0a9291ae0d90c64c731b..236e974e883a74ad985d19952c078d01b7f6aea3 100644 (file)
@@ -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)
 
index 358474dc3ed4f1971c9ba76112a8f0a02f657efc..6bdfe5f41859b729f0e512831c51e1d6a6e6763e 100644 (file)
@@ -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
index ef1952e1d4f451558d2dc6b96f7a0eac6c783f4f..9027ec0bb71f95b67de8b5d199dae3099edec0e5 100644 (file)
@@ -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