summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Gundlach <michael.gundlach@rackspace.com>2010-09-29 15:09:39 -0400
committerMichael Gundlach <michael.gundlach@rackspace.com>2010-09-29 15:09:39 -0400
commit2136f12d29cef9acc7dc6ee0a5901fa3878160f8 (patch)
tree55253b207cd3cc69fbe25d04f07523209693a07e
parent4c1aa3d96f0c44d3e01864ca3128e9b052d1d7fd (diff)
downloadnova-2136f12d29cef9acc7dc6ee0a5901fa3878160f8.tar.gz
nova-2136f12d29cef9acc7dc6ee0a5901fa3878160f8.tar.xz
nova-2136f12d29cef9acc7dc6ee0a5901fa3878160f8.zip
Make Fault raiseable by inheriting from webob.exc.HTTPException.
Change from using self.exception which is reserved by HTTPException to self.wrapped_exc.
-rw-r--r--nova/api/rackspace/faults.py17
-rw-r--r--nova/tests/api/rackspace/testfaults.py10
2 files changed, 19 insertions, 8 deletions
diff --git a/nova/api/rackspace/faults.py b/nova/api/rackspace/faults.py
index fd6bc3623..32e5c866f 100644
--- a/nova/api/rackspace/faults.py
+++ b/nova/api/rackspace/faults.py
@@ -17,11 +17,12 @@
import webob.dec
+import webob.exc
from nova import wsgi
-class Fault(wsgi.Application):
+class Fault(webob.exc.HTTPException):
"""An RS API fault response."""
@@ -39,23 +40,23 @@ class Fault(wsgi.Application):
def __init__(self, exception):
"""Create a Fault for the given webob.exc.exception."""
- self.exception = exception
+ self.wrapped_exc = exception
@webob.dec.wsgify
def __call__(self, req):
- """Generate a WSGI response based on self.exception."""
+ """Generate a WSGI response based on the exception passed to ctor."""
# Replace the body with fault details.
- code = self.exception.status_int
+ code = self.wrapped_exc.status_int
fault_name = self._fault_names.get(code, "cloudServersFault")
fault_data = {
fault_name: {
'code': code,
- 'message': self.exception.explanation}}
+ 'message': self.wrapped_exc.explanation}}
if code == 413:
- retry = self.exception.headers['Retry-After']
+ retry = self.wrapped_exc.headers['Retry-After']
fault_data[fault_name]['retryAfter'] = retry
# 'code' is an attribute on the fault tag itself
metadata = {'application/xml': {'attributes': {fault_name: 'code'}}}
serializer = wsgi.Serializer(req.environ, metadata)
- self.exception.body = serializer.to_content_type(fault_data)
- return self.exception
+ self.wrapped_exc.body = serializer.to_content_type(fault_data)
+ return self.wrapped_exc
diff --git a/nova/tests/api/rackspace/testfaults.py b/nova/tests/api/rackspace/testfaults.py
index 74caffd30..b2931bc98 100644
--- a/nova/tests/api/rackspace/testfaults.py
+++ b/nova/tests/api/rackspace/testfaults.py
@@ -1,5 +1,6 @@
import unittest
import webob
+import webob.dec
import webob.exc
from nova.api.rackspace import faults
@@ -28,3 +29,12 @@ class TestFaults(unittest.TestCase):
self.assertTrue('<message>sorry</message>' in body_sans_spaces)
self.assertTrue('<retryAfter>4</retryAfter>' in body_sans_spaces)
self.assertEqual(resp.headers['Retry-After'], 4)
+
+ def test_raise(self):
+ @webob.dec.wsgify
+ def raiser(req):
+ raise faults.Fault(webob.exc.HTTPNotFound(explanation='whut?'))
+ req = webob.Request.blank('/.xml')
+ resp = req.get_response(raiser)
+ self.assertEqual(resp.status_int, 404)
+ self.assertTrue('whut?' in resp.body)