summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Prince <dprince@redhat.com>2012-08-09 22:16:33 -0400
committerDan Prince <dprince@redhat.com>2012-08-09 22:25:26 -0400
commit7219577ba48df211713cab655cdd296a07f35773 (patch)
treecc278304fd159f8e24be834f0d7b183ac442125d
parent043e3f5981d89d35aa8bb8f1c42561c38451dfc4 (diff)
Make FaultWrapper handle exception code = None.
Updates the FaultWrapper middleware so that it properly handles exceptions which contain a code variable set to None. Previously you'd get TypeError exception like this in the api.log file: TypeError: %d format: a number is required, not NoneType This was due to the fact that we tried to format a string with an integer value which was set to None. I hit this today when using Qpid which does in fact throw exceptions which contain 'code' variables set to None. Fixes LP Bug #1035159. Change-Id: I7193031b1f5f9bf84cdb476f8f1268efc50eadf0
-rw-r--r--nova/api/openstack/__init__.py2
-rw-r--r--nova/tests/api/openstack/compute/test_api.py14
2 files changed, 16 insertions, 0 deletions
diff --git a/nova/api/openstack/__init__.py b/nova/api/openstack/__init__.py
index 6baa6be91..12dd8ae83 100644
--- a/nova/api/openstack/__init__.py
+++ b/nova/api/openstack/__init__.py
@@ -52,6 +52,8 @@ class FaultWrapper(base_wsgi.Middleware):
safe = getattr(inner, 'safe', False)
headers = getattr(inner, 'headers', None)
status = getattr(inner, 'code', 500)
+ if status is None:
+ status = 500
msg_dict = dict(url=req.url, status=status)
LOG.info(_("%(url)s returned with HTTP %(status)d") % msg_dict)
diff --git a/nova/tests/api/openstack/compute/test_api.py b/nova/tests/api/openstack/compute/test_api.py
index 5bbf1540b..782f1a344 100644
--- a/nova/tests/api/openstack/compute/test_api.py
+++ b/nova/tests/api/openstack/compute/test_api.py
@@ -176,6 +176,20 @@ class APITest(test.TestCase):
self._do_test_exception_mapping(ExceptionWithCode,
'Expectation failed')
+ def test_exception_with_none_code_throws_500(self):
+ class ExceptionWithNoneCode(Exception):
+ code = None
+
+ msg = 'Internal Server Error'
+
+ @webob.dec.wsgify
+ def fail(req):
+ raise ExceptionWithNoneCode()
+
+ api = self._wsgi_app(fail)
+ resp = webob.Request.blank('/').get_response(api)
+ self.assertEqual(500, resp.status_int)
+
def test_request_id_in_response(self):
req = webob.Request.blank('/')
req.method = 'GET'