diff options
| author | John Griffith <john.griffith@solidfire.com> | 2012-07-23 22:42:25 -0600 |
|---|---|---|
| committer | John Griffith <john.griffith@solidfire.com> | 2012-07-25 09:16:47 -0600 |
| commit | 76c1fd11b73fd8516bbde20cb46f627b658d4a6d (patch) | |
| tree | e9414028b2f4579deaa8029a988527f285e0eef1 /nova/tests | |
| parent | b8aedb281f8e6cc8b1583640c31f5d52ce5e4eac (diff) | |
Check for exception codes in openstack API results
* Inspect all exceptions for code, not just nova.exceptions
Originally the fault wrapper would only inspect an exception for
status, header and safe attributes if it was a nova.exception.
As a result, excecptions returned from Cinder were always being incorrectly
interpretted/categorized as ComputeFaults (500). This results in tempest
tests that expect exceptions such as 404 NotFound to fail.
Now that we're checking all Exceptions the same way, there's no need
for a specifying nova.exceptions or even doing the import.
Change-Id: If49e364063d5288c81ce1557bddc6dcec3ec457e
Diffstat (limited to 'nova/tests')
| -rw-r--r-- | nova/tests/api/openstack/compute/test_api.py | 30 |
1 files changed, 23 insertions, 7 deletions
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('/') |
