diff options
| author | Jenkins <jenkins@review.openstack.org> | 2012-07-25 17:25:16 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2012-07-25 17:25:16 +0000 |
| commit | 6618878b71c48abbdfe766c01e6b2e7604b60002 (patch) | |
| tree | 8283a3183940b7715e5297752c5b172753a1ddfb | |
| parent | a4ce1e57a61a858506ccde4ae1dc10641067637e (diff) | |
| parent | 76c1fd11b73fd8516bbde20cb46f627b658d4a6d (diff) | |
| download | nova-6618878b71c48abbdfe766c01e6b2e7604b60002.tar.gz nova-6618878b71c48abbdfe766c01e6b2e7604b60002.tar.xz nova-6618878b71c48abbdfe766c01e6b2e7604b60002.zip | |
Merge "Check for exception codes in openstack API results"
| -rw-r--r-- | nova/api/openstack/__init__.py | 10 | ||||
| -rw-r--r-- | nova/tests/api/openstack/compute/test_api.py | 30 |
2 files changed, 29 insertions, 11 deletions
diff --git a/nova/api/openstack/__init__.py b/nova/api/openstack/__init__.py index c1ce7ee94..a2f73e852 100644 --- a/nova/api/openstack/__init__.py +++ b/nova/api/openstack/__init__.py @@ -25,7 +25,6 @@ import webob.dec import webob.exc from nova.api.openstack import wsgi -from nova import exception from nova.openstack.common import log as logging from nova import utils from nova import wsgi as base_wsgi @@ -47,8 +46,13 @@ class FaultWrapper(base_wsgi.Middleware): return FaultWrapper._status_to_type.get( status, webob.exc.HTTPInternalServerError)() - def _error(self, inner, req, headers=None, status=500, safe=False): + def _error(self, inner, req): LOG.exception(_("Caught error: %s"), unicode(inner)) + + safe = getattr(inner, 'safe', False) + headers = getattr(inner, 'headers', None) + status = getattr(inner, 'code', 500) + msg_dict = dict(url=req.url, status=status) LOG.info(_("%(url)s returned with HTTP %(status)d") % msg_dict) outer = self.status_to_type(status) @@ -70,8 +74,6 @@ class FaultWrapper(base_wsgi.Middleware): def __call__(self, req): try: return req.get_response(self.application) - except exception.NovaException as ex: - return self._error(ex, req, ex.headers, ex.code, ex.safe) except Exception as ex: return self._error(ex, req) diff --git a/nova/tests/api/openstack/compute/test_api.py b/nova/tests/api/openstack/compute/test_api.py index 3ef8f9690..5bbf1540b 100644 --- a/nova/tests/api/openstack/compute/test_api.py +++ b/nova/tests/api/openstack/compute/test_api.py @@ -144,21 +144,37 @@ class APITest(test.TestCase): def test_unsafe_exceptions_are_not_described_in_faults(self): self._do_test_exception_safety_reflected_in_faults(False) - def _do_test_exception_mapping(self, exception_type): + def _do_test_exception_mapping(self, exception_type, msg): @webob.dec.wsgify def fail(req): - raise exception_type('too many used') + raise exception_type(msg) api = self._wsgi_app(fail) resp = webob.Request.blank('/').get_response(api) - self.assertTrue('too many used' in resp.body, resp.body) + self.assertTrue(msg in resp.body, resp.body) self.assertEqual(resp.status_int, exception_type.code, resp.body) - for (key, value) in exception_type.headers.iteritems(): - self.assertTrue(key in resp.headers) - self.assertEquals(resp.headers[key], value) + + if hasattr(exception_type, 'headers'): + for (key, value) in exception_type.headers.iteritems(): + self.assertTrue(key in resp.headers) + self.assertEquals(resp.headers[key], value) def test_quota_error_mapping(self): - self._do_test_exception_mapping(exception.QuotaError) + self._do_test_exception_mapping(exception.QuotaError, 'too many used') + + def test_non_nova_notfound_exception_mapping(self): + class ExceptionWithCode(Exception): + code = 404 + + self._do_test_exception_mapping(ExceptionWithCode, + 'NotFound') + + def test_non_nova_exception_mapping(self): + class ExceptionWithCode(Exception): + code = 417 + + self._do_test_exception_mapping(ExceptionWithCode, + 'Expectation failed') def test_request_id_in_response(self): req = webob.Request.blank('/') |
