diff --git a/HACKING.rst b/HACKING.rst index 212cd49ba..f0d1373ee 100644 --- a/HACKING.rst +++ b/HACKING.rst @@ -17,4 +17,5 @@ Vitrage Specific Commandments [V324] Use six.iteritems() or dict.items() instead of dict.iteritems() [V325] Use six.iterkeys() or dict.keys() instead of dict.iterkeys() [V326] Use six.itervalues() or dict.values instead of dict.itervalues() -[V327] Method's default argument shouldn't be mutable \ No newline at end of file +[V327] Method's default argument shouldn't be mutable +[V328] Disallow LOG.warn \ No newline at end of file diff --git a/vitrage/api_handler/apis/event.py b/vitrage/api_handler/apis/event.py index 3d2981cf5..b42816469 100644 --- a/vitrage/api_handler/apis/event.py +++ b/vitrage/api_handler/apis/event.py @@ -47,7 +47,8 @@ class EventApis(EntityGraphApisBase): event_type=event_type, payload=event) except Exception as e: - LOG.warn('Failed to post event %s. Exception: %s', event_type, e) + LOG.warning('Failed to post event %s. Exception: %s', + event_type, e) LOG.debug(e, exc_info=True) def _init_oslo_notifier(self): diff --git a/vitrage/api_handler/apis/resource.py b/vitrage/api_handler/apis/resource.py index 723a1e31f..cfdd0e225 100644 --- a/vitrage/api_handler/apis/resource.py +++ b/vitrage/api_handler/apis/resource.py @@ -71,9 +71,10 @@ class ResourceApis(EntityGraphApisBase): else: if project and project_id == project: return json.dumps(resource.properties) - LOG.warn('Have no authority to get resource with vitrage_id(%s)', - str(vitrage_id)) + LOG.warning( + 'Have no authority to get resource with vitrage_id(%s)', + str(vitrage_id)) else: - LOG.warn('Can not find the resource with vitrage_id(%s)', - str(vitrage_id)) + LOG.warning('Can not find the resource with vitrage_id(%s)', + str(vitrage_id)) return None diff --git a/vitrage/hacking/checks.py b/vitrage/hacking/checks.py index af830703c..ce0e7ae2b 100644 --- a/vitrage/hacking/checks.py +++ b/vitrage/hacking/checks.py @@ -135,6 +135,15 @@ def no_mutable_default_args(logical_line): yield (0, msg) +def no_log_warn(logical_line): + """Disallow 'LOG.warn(' + + V328 + """ + if logical_line.startswith('LOG.warn('): + yield(0, 'V328: Use LOG.warning() rather than LOG.warn()') + + def factory(register): register(assert_true_instance) register(assert_equal_type) @@ -148,3 +157,4 @@ def factory(register): register(check_python3_no_iteritems) register(check_python3_no_iterkeys) register(check_python3_no_itervalues) + register(no_log_warn) diff --git a/vitrage/tests/unit/hacking/test_hacking.py b/vitrage/tests/unit/hacking/test_hacking.py index 9d9a0642a..23b85c415 100644 --- a/vitrage/tests/unit/hacking/test_hacking.py +++ b/vitrage/tests/unit/hacking/test_hacking.py @@ -153,6 +153,10 @@ class HackingTestCase(base.BaseTest): self.assertEqual(0, len(list(checks.no_mutable_default_args( "defined, undefined = [], {}")))) + def test_no_log_warn(self): + self.assertEqual(0, len(list(checks.no_log_warn('LOG.warning("bl")')))) + self.assertEqual(1, len(list(checks.no_log_warn('LOG.warn("foo")')))) + def test_factory(self): class Register(object): def __init__(self):