Add hacking rules for deprecated LOG.warn

Because LOG.warn is deprecated,
we should replace LOG.warn with LOG.warning.

This patch add a hacking rule:
    [N313] - Validate that LOG.warning is used instead of deprecated LOG.warn.

and replace deprecated LOG.warn with LOG.warning in rally/api.py

Change-Id: I7d016b30368f13bde822ca27ef503ce09e3e875b
Closes-Bug: #1508442
This commit is contained in:
Kiseok Kim 2017-03-07 10:45:27 +00:00
parent 0a3e985ac4
commit 59ac7139d8
4 changed files with 17 additions and 2 deletions

View File

@ -1007,8 +1007,8 @@ class _DeprecatedAPIClass(object):
self._cls = cls
def __getattr__(self, attr, default=None):
LOG.warn(_LW("'%s' is deprecated since Rally 0.8.0 in favor of "
"'rally.api.API' class.") % self._cls.__name__[1:])
LOG.warning(_LW("'%s' is deprecated since Rally 0.8.0 in favor of "
"'rally.api.API' class.") % self._cls.__name__[1:])
return getattr(self._cls, attr, default)

View File

@ -15,6 +15,7 @@ Rally Specific Commandments
* [N310] - Ensure that ``rally.common.log`` is used as logging module
* [N311] - Validate that debug level logs are not translated
* [N312] - Validate correctness of debug on check.
* [N313] - Validate that LOG.warning is used instead of deprecated LOG.warn.
* [N32x] - Reserved for rules related to assert* methods
* [N320] - Ensure that ``assertTrue(isinstance(A, B))`` is not used
* [N321] - Ensure that ``assertEqual(type(A), B)`` is not used

View File

@ -68,6 +68,7 @@ re_db_import = re.compile(r"^from rally.common import db")
re_objects_import = re.compile(r"^from rally.common import objects")
re_old_type_class = re.compile(r"^\s*class \w+(\(\))?:")
re_datetime_alias = re.compile(r"^(from|import) datetime(?!\s+as\s+dt$)")
re_log_warn = re.compile(r"(.)*LOG\.(warn)\(\s*('|\"|_)")
def skip_ignored_lines(func):
@ -555,6 +556,12 @@ def check_objects_imports_in_cli(logical_line, physical_line, filename):
"`rally.common.objects``.")
@skip_ignored_lines
def check_log_warn(logical_line, physical_line, filename):
if re_log_warn.search(logical_line):
yield(0, "N313 LOG.warn is deprecated, please use LOG.warning")
def factory(register):
register(check_assert_methods_from_mock)
register(check_import_of_logging)
@ -577,3 +584,4 @@ def factory(register):
register(check_objects_imports_in_cli)
register(check_old_type_class)
register(check_no_six_iteritems)
register(check_log_warn)

View File

@ -401,3 +401,9 @@ class HackingTestCase(test.TestCase):
line = "import datetime as dt"
checkres = checks.check_datetime_alias(line, line, "fakefile")
def test_check_log_warn(self):
bad_samples = ["LOG.warn('foo')", "LOG.warn(_('bar'))"]
self._assert_bad_samples(checks.check_log_warn, bad_samples)
good_samples = ["LOG.warning('foo')", "LOG.warning(_('bar'))"]
self._assert_good_samples(checks.check_log_warn, good_samples)