diff --git a/HACKING.rst b/HACKING.rst index b790f341..e7277952 100644 --- a/HACKING.rst +++ b/HACKING.rst @@ -49,3 +49,4 @@ Masakari Specific Commandments - [M328] Python 3: do not use dict.itervalues. - [M329] Deprecated library function os.popen() - [M330] String interpolation should be delayed at logging calls. +- [M331] LOG.warn is deprecated. Enforce use of LOG.warning. diff --git a/masakari/hacking/checks.py b/masakari/hacking/checks.py index 88b4eb58..fa413a4d 100644 --- a/masakari/hacking/checks.py +++ b/masakari/hacking/checks.py @@ -442,6 +442,20 @@ def check_delayed_string_interpolation(logical_line, filename, noqa): yield(logical_line.index('%'), msg) +def no_log_warn(logical_line): + """Disallow 'LOG.warn(' + + Deprecated LOG.warn(), instead use LOG.warning + https://bugs.launchpad.net/senlin/+bug/1508442 + + M331 + """ + + msg = ("M331: LOG.warn is deprecated, please use LOG.warning!") + if "LOG.warn(" in logical_line: + yield (0, msg) + + def factory(register): register(no_db_session_in_public_api) register(use_timeutils_utcnow) @@ -470,3 +484,4 @@ def factory(register): register(check_python3_no_itervalues) register(no_os_popen) register(check_delayed_string_interpolation) + register(no_log_warn) diff --git a/masakari/tests/unit/test_hacking.py b/masakari/tests/unit/test_hacking.py index d693f320..2354ccd8 100644 --- a/masakari/tests/unit/test_hacking.py +++ b/masakari/tests/unit/test_hacking.py @@ -533,3 +533,15 @@ class HackingTestCase(test.NoDBTestCase): for name, value in test.items()])}) """ self._assert_has_no_errors(code, checker) + + def test_no_log_warn(self): + code = """ + LOG.warn("LOG.warn is deprecated") + """ + errors = [(1, 0, 'M331')] + self._assert_has_errors(code, checks.no_log_warn, + expected_errors=errors) + code = """ + LOG.warning("LOG.warn is deprecated") + """ + self._assert_has_no_errors(code, checks.no_log_warn)