Add hacking check for use of LOG.audit

Commit 4dc37abc removes the few instances of LOG.audit that
were in Cinder.  Given that the plan is to remove LOG.audit messages
from OpenStack, I am adding this hacking check to ensure that such
messages do not sneak their way back into Cinder.

Unit tests are included with this change.

Change-Id: Icc416a68f958f60260f1c55af0d8605c95913bf1
This commit is contained in:
Jay S. Bryant 2014-08-01 15:43:51 -05:00
parent 057d9feeb8
commit 097d3d7910
3 changed files with 23 additions and 0 deletions

View File

@ -10,6 +10,8 @@ Cinder Specific Commandments
- [N319] Validate that debug level logs are not translated
- [N323] Add check for explicit import of _() to ensure proper translation.
- [N324] Enforce no use of LOG.audit messages. LOG.info should be used instead.
General
-------
- Use 'raise' instead of 'raise e' to preserve original traceback or exception being reraised::

View File

@ -39,6 +39,7 @@ vi_header_re = re.compile(r"^#\s+vim?:.+")
underscore_import_check = re.compile(r"(.)*import _(.)*")
# We need this for cases where they have created their own _ function.
custom_underscore_check = re.compile(r"(.)*_\s*=\s*(.)*")
no_audit_log = re.compile(r"(.)*LOG\.audit(.)*")
def no_vi_headers(physical_line, line_number, lines):
@ -99,8 +100,22 @@ def check_explicit_underscore_import(logical_line, filename):
yield(0, "N323: Found use of _() without explicit import of _ !")
def check_no_log_audit(logical_line):
"""Ensure that we are not using LOG.audit messages
Plans are in place going forward as discussed in the following
spec (https://review.openstack.org/#/c/91446/) to take out
LOG.audit messages. Given that audit was a concept invented
for OpenStack we can enforce not using it.
"""
if no_audit_log.match(logical_line):
yield(0, "N324: Found LOG.audit. Use LOG.info instead.")
def factory(register):
register(no_vi_headers)
register(no_translate_debug_logs)
register(no_mutable_default_args)
register(check_explicit_underscore_import)
register(check_no_log_audit)

View File

@ -104,3 +104,9 @@ class HackingTestCase(test.TestCase):
self.assertEqual(len(list(checks.check_explicit_underscore_import(
"msg = _('My message')",
"cinder/tests/other_files3.py"))), 0)
def test_check_no_log_audit(self):
self.assertEqual(len(list(checks.check_no_log_audit(
"LOG.audit('My test audit log')"))), 1)
self.assertEqual(len(list(checks.check_no_log_audit(
"LOG.info('My info test log.')"))), 0)