add disable log.warn to hacking

logging.warn is deprecated in python 3

Change-Id: Ib2f25afc99169057179ae036273c526afc24e55e
This commit is contained in:
Eyal 2017-11-20 11:24:26 +02:00
parent e23373c913
commit 1c3ed3ba78
5 changed files with 23 additions and 6 deletions

View File

@ -17,4 +17,5 @@ Vitrage Specific Commandments
[V324] Use six.iteritems() or dict.items() instead of dict.iteritems() [V324] Use six.iteritems() or dict.items() instead of dict.iteritems()
[V325] Use six.iterkeys() or dict.keys() instead of dict.iterkeys() [V325] Use six.iterkeys() or dict.keys() instead of dict.iterkeys()
[V326] Use six.itervalues() or dict.values instead of dict.itervalues() [V326] Use six.itervalues() or dict.values instead of dict.itervalues()
[V327] Method's default argument shouldn't be mutable [V327] Method's default argument shouldn't be mutable
[V328] Disallow LOG.warn

View File

@ -47,7 +47,8 @@ class EventApis(EntityGraphApisBase):
event_type=event_type, event_type=event_type,
payload=event) payload=event)
except Exception as e: 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) LOG.debug(e, exc_info=True)
def _init_oslo_notifier(self): def _init_oslo_notifier(self):

View File

@ -71,9 +71,10 @@ class ResourceApis(EntityGraphApisBase):
else: else:
if project and project_id == project: if project and project_id == project:
return json.dumps(resource.properties) return json.dumps(resource.properties)
LOG.warn('Have no authority to get resource with vitrage_id(%s)', LOG.warning(
str(vitrage_id)) 'Have no authority to get resource with vitrage_id(%s)',
str(vitrage_id))
else: else:
LOG.warn('Can not find the resource with vitrage_id(%s)', LOG.warning('Can not find the resource with vitrage_id(%s)',
str(vitrage_id)) str(vitrage_id))
return None return None

View File

@ -135,6 +135,15 @@ def no_mutable_default_args(logical_line):
yield (0, msg) 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): def factory(register):
register(assert_true_instance) register(assert_true_instance)
register(assert_equal_type) register(assert_equal_type)
@ -148,3 +157,4 @@ def factory(register):
register(check_python3_no_iteritems) register(check_python3_no_iteritems)
register(check_python3_no_iterkeys) register(check_python3_no_iterkeys)
register(check_python3_no_itervalues) register(check_python3_no_itervalues)
register(no_log_warn)

View File

@ -153,6 +153,10 @@ class HackingTestCase(base.BaseTest):
self.assertEqual(0, len(list(checks.no_mutable_default_args( self.assertEqual(0, len(list(checks.no_mutable_default_args(
"defined, undefined = [], {}")))) "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): def test_factory(self):
class Register(object): class Register(object):
def __init__(self): def __init__(self):