diff --git a/HACKING.rst b/HACKING.rst index b1f1e5e2c..525586b47 100644 --- a/HACKING.rst +++ b/HACKING.rst @@ -21,3 +21,4 @@ Zun Specific Commandments with a sequence of key-value pairs. - [Z338] Use assertIn/NotIn(A, B) rather than assertEqual(A in B, True/False). - [Z339] Don't use xrange() +- [Z352] LOG.warn is deprecated. Enforce use of LOG.warning. diff --git a/zun/hacking/checks.py b/zun/hacking/checks.py index c60047d2e..cbc2410e2 100644 --- a/zun/hacking/checks.py +++ b/zun/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://review.openstack.org/#/c/412768/ + + Z352 + """ + + msg = ("Z352: 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/zun/tests/unit/test_hacking.py b/zun/tests/unit/test_hacking.py index 18e333062..a6e00d87b 100644 --- a/zun/tests/unit/test_hacking.py +++ b/zun/tests/unit/test_hacking.py @@ -232,3 +232,16 @@ class HackingTestCase(base.BaseTestCase): self.assertEqual(0, len(list(checks.dict_constructor_with_list_copy( " self._render_dict(xml, data_el, data.__dict__)")))) + + def test_no_log_warn(self): + errors = [(1, 0, "Z352")] + 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)