diff --git a/HACKING.rst b/HACKING.rst index 9a88b7900d..59a53d68d9 100644 --- a/HACKING.rst +++ b/HACKING.rst @@ -23,3 +23,4 @@ Magnum Specific Commandments with a sequence of key-value pairs. - [M338] Use assertIn/NotIn(A, B) rather than assertEqual(A in B, True/False). - [M339] Don't use xrange() +- [M352] LOG.warn is deprecated. Enforce use of LOG.warning. diff --git a/magnum/hacking/checks.py b/magnum/hacking/checks.py index 8238a6e797..43ca3fcc50 100644 --- a/magnum/hacking/checks.py +++ b/magnum/hacking/checks.py @@ -144,6 +144,20 @@ def dict_constructor_with_list_copy(logical_line): yield (0, msg) +def no_log_warn(logical_line): + """Disallow 'LOG.warn(' + + Deprecated LOG.warn(), instead use LOG.warning + https://bugs.launchpad.net/magnum/+bug/1508442 + + M352 + """ + + msg = ("M352: LOG.warn is deprecated, please use LOG.warning!") + if "LOG.warn(" in logical_line: + yield (0, msg) + + def factory(register): register(no_mutable_default_args) register(assert_equal_none) @@ -154,3 +168,4 @@ def factory(register): register(use_timeutils_utcnow) register(dict_constructor_with_list_copy) register(no_xrange) + register(no_log_warn) diff --git a/magnum/tests/unit/test_hacking.py b/magnum/tests/unit/test_hacking.py index 6842628afc..6f4846aa74 100644 --- a/magnum/tests/unit/test_hacking.py +++ b/magnum/tests/unit/test_hacking.py @@ -189,6 +189,19 @@ class HackingTestCase(base.TestCase): code = "range(45)" self._assert_has_no_errors(code, check) + def test_no_log_warn(self): + errors = [(1, 0, "M352")] + check = checks.no_log_warn + code = """ + LOG.warn("LOG.warn is deprecated") + """ + self._assert_has_errors(code, check, errors) + + code = """ + LOG.warning("LOG.warn is deprecated") + """ + self._assert_has_no_errors(code, check) + def test_use_timeunitls_utcow(self): errors = [(1, 0, "M310")] check = checks.use_timeutils_utcnow