]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Add keyword argument missing at some exc.HTTPError subclass
authorKIYOHIRO ADACHI <adachi@mxs.nes.nec.co.jp>
Fri, 27 Dec 2013 03:16:37 +0000 (12:16 +0900)
committerKIYOHIRO ADACHI <adachi@mxs.nes.nec.co.jp>
Mon, 16 Jun 2014 08:37:51 +0000 (17:37 +0900)
Some exc.HTTPError subclass needs keyword argument ``explanation``.
If there is no ``explanation=``, the message of the argument is
recognized as ``detail``.

Change-Id: Idfc07b2bd71da31e44212d3296921e18d2024a63
Closes-Bug: #1264424

cinder/api/contrib/admin_actions.py
cinder/api/contrib/services.py
cinder/api/contrib/volume_actions.py
cinder/api/middleware/auth.py

index 15ad489c042b8a0c29f01ef97cb8e88b89841fee..64e833d9ced761f47e22b9e7686a57d008dd626c 100644 (file)
@@ -61,9 +61,10 @@ class AdminController(wsgi.Controller):
         try:
             update['status'] = body['status'].lower()
         except (TypeError, KeyError):
-            raise exc.HTTPBadRequest("Must specify 'status'")
+            raise exc.HTTPBadRequest(explanation=_("Must specify 'status'"))
         if update['status'] not in self.valid_status:
-            raise exc.HTTPBadRequest("Must specify a valid status")
+            raise exc.HTTPBadRequest(
+                explanation=_("Must specify a valid status"))
         return update
 
     def authorize(self, context, action_name):
@@ -89,7 +90,7 @@ class AdminController(wsgi.Controller):
         try:
             self._update(context, id, update)
         except exception.NotFound as e:
-            raise exc.HTTPNotFound(e)
+            raise exc.HTTPNotFound(explanation=e.msg)
 
         notifier.info(context, self.collection + '.reset_status.end',
                       notifier_info)
@@ -152,20 +153,22 @@ class VolumeAdminController(AdminController):
             valid = True
             update['attach_status'] = attach_status.lower()
             if update['attach_status'] not in self.valid_attach_status:
-                raise exc.HTTPBadRequest("Must specify a valid attach status")
+                raise exc.HTTPBadRequest(
+                    explanation=_("Must specify a valid attach status"))
 
         if migration_status:
             valid = True
             update['migration_status'] = migration_status.lower()
             if update['migration_status'] not in self.valid_migration_status:
-                raise exc.HTTPBadRequest("Must specify a valid migration "
-                                         "status")
+                raise exc.HTTPBadRequest(
+                    explanation=_("Must specify a valid migration status"))
             if update['migration_status'] == 'none':
                 update['migration_status'] = None
 
         if not valid:
-            raise exc.HTTPBadRequest("Must specify 'status', 'attach_status' "
-                                     "or 'migration_status' for update.")
+            raise exc.HTTPBadRequest(
+                explanation=_("Must specify 'status', 'attach_status' "
+                              "or 'migration_status' for update."))
         return update
 
     @wsgi.action('os-force_detach')
@@ -195,16 +198,18 @@ class VolumeAdminController(AdminController):
         try:
             host = params['host']
         except KeyError:
-            raise exc.HTTPBadRequest("Must specify 'host'")
+            raise exc.HTTPBadRequest(explanation=_("Must specify 'host'"))
         force_host_copy = params.get('force_host_copy', False)
         if isinstance(force_host_copy, basestring):
             try:
                 force_host_copy = strutils.bool_from_string(force_host_copy,
                                                             strict=True)
             except ValueError:
-                raise exc.HTTPBadRequest("Bad value for 'force_host_copy'")
+                raise exc.HTTPBadRequest(
+                    explanation=_("Bad value for 'force_host_copy'"))
         elif not isinstance(force_host_copy, bool):
-            raise exc.HTTPBadRequest("'force_host_copy' not string or bool")
+            raise exc.HTTPBadRequest(
+                explanation=_("'force_host_copy' not string or bool"))
         self.volume_api.migrate_volume(context, volume, host, force_host_copy)
         return webob.Response(status_int=202)
 
@@ -221,7 +226,8 @@ class VolumeAdminController(AdminController):
         try:
             new_volume_id = params['new_volume']
         except KeyError:
-            raise exc.HTTPBadRequest("Must specify 'new_volume'")
+            raise exc.HTTPBadRequest(
+                explanation=_("Must specify 'new_volume'"))
         try:
             new_volume = self._get(context, new_volume_id)
         except exception.NotFound:
index 8fde5b874b27b4d3b1cef7f54c7ee8437b61efd3..574ccdfdcee53a3f3ecf9b1b06a0fb0a1fb57bd4 100644 (file)
@@ -147,7 +147,7 @@ class ServiceController(wsgi.Controller):
             disabled = True
             status = "disabled"
         else:
-            raise webob.exc.HTTPNotFound("Unknown action")
+            raise webob.exc.HTTPNotFound(explanation=_("Unknown action"))
 
         try:
             host = body['host']
@@ -174,11 +174,11 @@ class ServiceController(wsgi.Controller):
         try:
             svc = db.service_get_by_args(context, host, binary_key)
             if not svc:
-                raise webob.exc.HTTPNotFound('Unknown service')
+                raise webob.exc.HTTPNotFound(explanation=_('Unknown service'))
 
             db.service_update(context, svc['id'], ret_val)
         except exception.ServiceNotFound:
-            raise webob.exc.HTTPNotFound("service not found")
+            raise webob.exc.HTTPNotFound(explanation=_("service not found"))
 
         ret_val.update({'host': host, 'service': service,
                         'binary': binary, 'status': status})
index 0f8a8b8600ef8dd27dea7480dbc5f01f7bf618aa..f2859904addce4300ed1bc7d14b9ee4ab47d801b 100644 (file)
@@ -188,14 +188,15 @@ class VolumeActionsController(wsgi.Controller):
         try:
             connector = body['os-initialize_connection']['connector']
         except KeyError:
-            raise webob.exc.HTTPBadRequest("Must specify 'connector'")
+            raise webob.exc.HTTPBadRequest(
+                explanation=_("Must specify 'connector'"))
         try:
             info = self.volume_api.initialize_connection(context,
                                                          volume,
                                                          connector)
         except exception.VolumeBackendAPIException as error:
             msg = _("Unable to fetch connection information from backend.")
-            raise webob.exc.HTTPInternalServerError(msg)
+            raise webob.exc.HTTPInternalServerError(explanation=msg)
 
         return {'connection_info': info}
 
@@ -210,7 +211,8 @@ class VolumeActionsController(wsgi.Controller):
         try:
             connector = body['os-terminate_connection']['connector']
         except KeyError:
-            raise webob.exc.HTTPBadRequest("Must specify 'connector'")
+            raise webob.exc.HTTPBadRequest(
+                explanation=_("Must specify 'connector'"))
         try:
             self.volume_api.terminate_connection(context, volume, connector)
         except exception.VolumeBackendAPIException as error:
index 8572949cfe4125a29ab771a5747624efdba312a0..2c213b655d5e923faf0d9a385b6ff1c758b7063b 100644 (file)
@@ -109,7 +109,7 @@ class CinderKeystoneContext(base_wsgi.Middleware):
                 service_catalog = jsonutils.loads(catalog_header)
             except ValueError:
                 raise webob.exc.HTTPInternalServerError(
-                    _('Invalid service catalog json.'))
+                    explanation=_('Invalid service catalog json.'))
 
         if CONF.use_forwarded_for:
             remote_address = req.headers.get('X-Forwarded-For', remote_address)