Add a hacking rule to enforce use of LOG.warning

LOG.warn is deprecated.
LOG.warning should be used instead of LOG.warn.
So add the following hacking rule.

- [M331] LOG.warn is deprecated. Enforce use of LOG.warning.

Change-Id: I1f99331e2a51f8295eac0734aa653b4ff04ccf65
Closes-Bug: #1508442
This commit is contained in:
Takashi NATSUME 2016-08-04 09:35:48 +09:00
parent cd3be63409
commit 8e601d1183
3 changed files with 28 additions and 0 deletions

View File

@ -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.

View File

@ -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)

View File

@ -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)