]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Disallow log hints in LOG.debug
authorCedric Brandily <zzelle@gmail.com>
Mon, 8 Dec 2014 15:23:47 +0000 (15:23 +0000)
committerCedric Brandily <zzelle@gmail.com>
Mon, 8 Dec 2014 18:50:25 +0000 (19:50 +0100)
Currently LOG.debug(_(...)) is disallowed but not LOG.debug(_Lx(...)).
This change disallows all log hints in LOG.debug calls.

Change-Id: I9758ad4ca9f7e8534abf38f5064b01b0c353e904
Partial-bug: #1320867

neutron/hacking/checks.py
neutron/tests/unit/test_hacking.py

index 998f345a9139183c3d987eae7b84cd1e1cc41eb0..f6c6a64d40903177e008f7c7c4ada9a861a35f7c 100644 (file)
@@ -147,7 +147,7 @@ def no_author_tags(physical_line):
 
 
 def no_translate_debug_logs(logical_line, filename):
-    """Check for 'LOG.debug(_('
+    """Check for 'LOG.debug(_(' and 'LOG.debug(_Lx('
 
     As per our translation policy,
     https://wiki.openstack.org/wiki/LoggingStandards#Log_Translation
@@ -157,8 +157,9 @@ def no_translate_debug_logs(logical_line, filename):
     N319
     """
     if _directory_to_check_translation(filename):
-        if logical_line.startswith("LOG.debug(_("):
-            yield(0, "N319 Don't translate debug level logs")
+        for hint in _all_hints:
+            if logical_line.startswith("LOG.debug(%s(" % hint):
+                yield(0, "N319 Don't translate debug level logs")
 
 
 def check_assert_called_once_with(logical_line, filename):
index ec0f9ccd5a8d42e1449ac07615de5fd277823c22..64f8990ce062e535f95a23d872f37a06ceec078c 100644 (file)
@@ -59,6 +59,13 @@ class HackingTestCase(base.BaseTestCase):
                                                               stmt,
                                                               filename))))
 
+    def test_no_translate_debug_logs(self):
+        filename = 'neutron/agent/f'
+        for hint in checks._all_hints:
+            bad = "LOG.debug(%s('bad'))" % hint
+            self.assertEqual(
+                1, len(list(checks.no_translate_debug_logs(bad, filename))))
+
     def test_use_jsonutils(self):
         def __get_msg(fun):
             msg = ("N321: jsonutils.%(fun)s must be used instead of "