Browse Source

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
tags/2.0.0
Takashi NATSUME 3 years ago
parent
commit
8e601d1183
3 changed files with 28 additions and 0 deletions
  1. 1
    0
      HACKING.rst
  2. 15
    0
      masakari/hacking/checks.py
  3. 12
    0
      masakari/tests/unit/test_hacking.py

+ 1
- 0
HACKING.rst View File

@@ -49,3 +49,4 @@ Masakari Specific Commandments
49 49
 - [M328] Python 3: do not use dict.itervalues.
50 50
 - [M329] Deprecated library function os.popen()
51 51
 - [M330] String interpolation should be delayed at logging calls.
52
+- [M331] LOG.warn is deprecated. Enforce use of LOG.warning.

+ 15
- 0
masakari/hacking/checks.py View File

@@ -442,6 +442,20 @@ def check_delayed_string_interpolation(logical_line, filename, noqa):
442 442
         yield(logical_line.index('%'), msg)
443 443
 
444 444
 
445
+def no_log_warn(logical_line):
446
+    """Disallow 'LOG.warn('
447
+
448
+    Deprecated LOG.warn(), instead use LOG.warning
449
+    https://bugs.launchpad.net/senlin/+bug/1508442
450
+
451
+    M331
452
+    """
453
+
454
+    msg = ("M331: LOG.warn is deprecated, please use LOG.warning!")
455
+    if "LOG.warn(" in logical_line:
456
+        yield (0, msg)
457
+
458
+
445 459
 def factory(register):
446 460
     register(no_db_session_in_public_api)
447 461
     register(use_timeutils_utcnow)
@@ -470,3 +484,4 @@ def factory(register):
470 484
     register(check_python3_no_itervalues)
471 485
     register(no_os_popen)
472 486
     register(check_delayed_string_interpolation)
487
+    register(no_log_warn)

+ 12
- 0
masakari/tests/unit/test_hacking.py View File

@@ -533,3 +533,15 @@ class HackingTestCase(test.NoDBTestCase):
533 533
                               for name, value in test.items()])})
534 534
                """
535 535
         self._assert_has_no_errors(code, checker)
536
+
537
+    def test_no_log_warn(self):
538
+        code = """
539
+                  LOG.warn("LOG.warn is deprecated")
540
+               """
541
+        errors = [(1, 0, 'M331')]
542
+        self._assert_has_errors(code, checks.no_log_warn,
543
+                                expected_errors=errors)
544
+        code = """
545
+                  LOG.warning("LOG.warn is deprecated")
546
+               """
547
+        self._assert_has_no_errors(code, checks.no_log_warn)

Loading…
Cancel
Save