summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2012-07-19 17:44:21 +0000
committerGerrit Code Review <review@openstack.org>2012-07-19 17:44:21 +0000
commitf8b83b7220955252453a71046ef29f07e082ebca (patch)
tree6636aef865931ebd045c9968a3d1a22bae4d346e
parent900879104e0a1a5e394f21a86346df05f7467165 (diff)
parent7d8936cc802ce28a476e30a6b94ab23881580b48 (diff)
downloadnova-f8b83b7220955252453a71046ef29f07e082ebca.tar.gz
nova-f8b83b7220955252453a71046ef29f07e082ebca.tar.xz
nova-f8b83b7220955252453a71046ef29f07e082ebca.zip
Merge "Static FaultWrapper status_to_type map."
-rw-r--r--nova/api/openstack/__init__.py17
1 files changed, 10 insertions, 7 deletions
diff --git a/nova/api/openstack/__init__.py b/nova/api/openstack/__init__.py
index f49c721ff..c1ce7ee94 100644
--- a/nova/api/openstack/__init__.py
+++ b/nova/api/openstack/__init__.py
@@ -37,18 +37,21 @@ LOG = logging.getLogger(__name__)
class FaultWrapper(base_wsgi.Middleware):
"""Calls down the middleware stack, making exceptions into faults."""
- def __init__(self, application):
- self.status_to_type = {}
- for clazz in utils.walk_class_hierarchy(webob.exc.HTTPError):
- self.status_to_type[clazz.code] = clazz
- super(FaultWrapper, self).__init__(application)
+ _status_to_type = {}
+
+ @staticmethod
+ def status_to_type(status):
+ if not FaultWrapper._status_to_type:
+ for clazz in utils.walk_class_hierarchy(webob.exc.HTTPError):
+ FaultWrapper._status_to_type[clazz.code] = clazz
+ return FaultWrapper._status_to_type.get(
+ status, webob.exc.HTTPInternalServerError)()
def _error(self, inner, req, headers=None, status=500, safe=False):
LOG.exception(_("Caught error: %s"), unicode(inner))
msg_dict = dict(url=req.url, status=status)
LOG.info(_("%(url)s returned with HTTP %(status)d") % msg_dict)
- outer = self.status_to_type.get(status,
- webob.exc.HTTPInternalServerError)()
+ outer = self.status_to_type(status)
if headers:
outer.headers = headers
# NOTE(johannes): We leave the explanation empty here on