HACKING: fix edge case with log hints
A log message with _() was not raised as an error, for example: LOG.info(_('who let the dogs out!')). This should be: LOG.info(_LI('who who who who!')) Change-Id: I040f01b19ff5de00467b80be7399b998534d9a57 Closes-bug: #1522054
This commit is contained in:
parent
5b804251ac
commit
0ce4510b35
|
@ -30,6 +30,9 @@ import six
|
||||||
# neutron/tests/unit/hacking/test_checks.py
|
# neutron/tests/unit/hacking/test_checks.py
|
||||||
|
|
||||||
_all_log_levels = {
|
_all_log_levels = {
|
||||||
|
'reserved': '_', # this should never be used with a log unless
|
||||||
|
# it is a variable used for a log message and
|
||||||
|
# a exception
|
||||||
'error': '_LE',
|
'error': '_LE',
|
||||||
'info': '_LI',
|
'info': '_LI',
|
||||||
'warn': '_LW',
|
'warn': '_LW',
|
||||||
|
|
|
@ -18,6 +18,7 @@ from pecan import hooks
|
||||||
import webob.exc
|
import webob.exc
|
||||||
|
|
||||||
from neutron.api.v2 import base as v2base
|
from neutron.api.v2 import base as v2base
|
||||||
|
from neutron.i18n import _LE
|
||||||
|
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
@ -33,6 +34,6 @@ class ExceptionTranslationHook(hooks.PecanHook):
|
||||||
raise to_class(getattr(e, 'msg', e.message))
|
raise to_class(getattr(e, 'msg', e.message))
|
||||||
# leaked unexpected exception, convert to boring old 500 error and
|
# leaked unexpected exception, convert to boring old 500 error and
|
||||||
# hide message from user in case it contained sensitive details
|
# hide message from user in case it contained sensitive details
|
||||||
LOG.exception(_("An unexpected exception was caught: %s") % e)
|
LOG.exception(_LE("An unexpected exception was caught: %s"), e)
|
||||||
raise webob.exc.HTTPInternalServerError(
|
raise webob.exc.HTTPInternalServerError(
|
||||||
_("An unexpected internal error occurred."))
|
_("An unexpected internal error occurred."))
|
||||||
|
|
|
@ -39,6 +39,9 @@ class HackingTestCase(base.BaseTestCase):
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
0, len(list(checks.validate_log_translations(debug, debug, 'f'))))
|
0, len(list(checks.validate_log_translations(debug, debug, 'f'))))
|
||||||
for log in logs:
|
for log in logs:
|
||||||
|
bad = 'LOG.%s(_("Bad"))' % log
|
||||||
|
self.assertEqual(
|
||||||
|
1, len(list(checks.validate_log_translations(bad, bad, 'f'))))
|
||||||
bad = 'LOG.%s("Bad")' % log
|
bad = 'LOG.%s("Bad")' % log
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
1, len(list(checks.validate_log_translations(bad, bad, 'f'))))
|
1, len(list(checks.validate_log_translations(bad, bad, 'f'))))
|
||||||
|
|
Loading…
Reference in New Issue