From 097d3d791071148b53c076aef66eefa77b2b10db Mon Sep 17 00:00:00 2001 From: "Jay S. Bryant" Date: Fri, 1 Aug 2014 15:43:51 -0500 Subject: [PATCH] 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 --- HACKING.rst | 2 ++ cinder/hacking/checks.py | 15 +++++++++++++++ cinder/tests/test_hacking.py | 6 ++++++ 3 files changed, 23 insertions(+) diff --git a/HACKING.rst b/HACKING.rst index 2c22b63ac..1f831845a 100644 --- a/HACKING.rst +++ b/HACKING.rst @@ -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:: diff --git a/cinder/hacking/checks.py b/cinder/hacking/checks.py index 8078d3070..3f6e675ee 100644 --- a/cinder/hacking/checks.py +++ b/cinder/hacking/checks.py @@ -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) diff --git a/cinder/tests/test_hacking.py b/cinder/tests/test_hacking.py index dc13d4366..7a6bf424e 100644 --- a/cinder/tests/test_hacking.py +++ b/cinder/tests/test_hacking.py @@ -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) -- 2.45.2