diff --git a/ceilometer/api/hooks.py b/ceilometer/api/hooks.py index bcd4cd1c8..f4538caff 100644 --- a/ceilometer/api/hooks.py +++ b/ceilometer/api/hooks.py @@ -74,6 +74,9 @@ class TranslationHook(hooks.PecanHook): self.local_error = threading.local() self.local_error.translatable_error = None + def before(self, state): + self.local_error.translatable_error = None + def after(self, state): if hasattr(state.response, 'translatable_error'): self.local_error.translatable_error = ( diff --git a/ceilometer/tests/api/v2/test_app.py b/ceilometer/tests/api/v2/test_app.py index d2867957e..30232fa07 100644 --- a/ceilometer/tests/api/v2/test_app.py +++ b/ceilometer/tests/api/v2/test_app.py @@ -18,9 +18,11 @@ # under the License. """Test basic ceilometer-api app """ +import json import os import mock +import wsme from ceilometer.api import acl from ceilometer.api import app @@ -207,3 +209,19 @@ class TestApiMiddleware(FunctionalTest): fault = response.xml.findall('./error/faultstring') for fault_string in fault: self.assertEqual(fault_string.text, self.en_US_translated_error) + + def test_translated_then_untranslated_error(self): + resp = self.get_json('/alarms/alarm-id-3', expect_errors=True) + self.assertEqual(resp.status_code, 404) + self.assertEqual(json.loads(resp.body)['error_message'] + ['faultstring'], "Alarm alarm-id-3 Not Found") + + with mock.patch('ceilometer.api.controllers.v2.EntityNotFound') \ + as CustomErrorClass: + CustomErrorClass.return_value = wsme.exc.ClientSideError( + "untranslated_error", status_code=404) + resp = self.get_json('/alarms/alarm-id-5', expect_errors=True) + + self.assertEqual(resp.status_code, 404) + self.assertEqual(json.loads(resp.body)['error_message'] + ['faultstring'], "untranslated_error")