Browse Source

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
tags/0.9.0
Kiseok Kim 2 years ago
parent
commit
59ac7139d8
4 changed files with 17 additions and 2 deletions
  1. 2
    2
      rally/api.py
  2. 1
    0
      tests/hacking/README.rst
  3. 8
    0
      tests/hacking/checks.py
  4. 6
    0
      tests/unit/test_hacking.py

+ 2
- 2
rally/api.py View File

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

+ 1
- 0
tests/hacking/README.rst View File

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

+ 8
- 0
tests/hacking/checks.py View File

@@ -68,6 +68,7 @@ re_db_import = re.compile(r"^from rally.common import db")
68 68
 re_objects_import = re.compile(r"^from rally.common import objects")
69 69
 re_old_type_class = re.compile(r"^\s*class \w+(\(\))?:")
70 70
 re_datetime_alias = re.compile(r"^(from|import) datetime(?!\s+as\s+dt$)")
71
+re_log_warn = re.compile(r"(.)*LOG\.(warn)\(\s*('|\"|_)")
71 72
 
72 73
 
73 74
 def skip_ignored_lines(func):
@@ -555,6 +556,12 @@ def check_objects_imports_in_cli(logical_line, physical_line, filename):
555 556
                   "`rally.common.objects``.")
556 557
 
557 558
 
559
+@skip_ignored_lines
560
+def check_log_warn(logical_line, physical_line, filename):
561
+    if re_log_warn.search(logical_line):
562
+        yield(0, "N313 LOG.warn is deprecated, please use LOG.warning")
563
+
564
+
558 565
 def factory(register):
559 566
     register(check_assert_methods_from_mock)
560 567
     register(check_import_of_logging)
@@ -577,3 +584,4 @@ def factory(register):
577 584
     register(check_objects_imports_in_cli)
578 585
     register(check_old_type_class)
579 586
     register(check_no_six_iteritems)
587
+    register(check_log_warn)

+ 6
- 0
tests/unit/test_hacking.py View File

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

Loading…
Cancel
Save