Use LOG.warning instead of deprecated LOG.warn
The LOG.warn method is deprecated[1] and the LOG.warning method should be used instead. [1] https://docs.python.org/3/library/logging.html#logging.warning Change-Id: I7e3dc5d1897cd10b94e0a5a5a06db667cba7d443
This commit is contained in:
@@ -9,3 +9,5 @@ masakari-monitors Specific Commandments
|
|||||||
- [M301] Ensure that the _() function is explicitly imported to ensure proper translations.
|
- [M301] Ensure that the _() function is explicitly imported to ensure proper translations.
|
||||||
- [M302] Validate that log messages are not translated.
|
- [M302] Validate that log messages are not translated.
|
||||||
- [M303] Yield must always be followed by a space when yielding a value.
|
- [M303] Yield must always be followed by a space when yielding a value.
|
||||||
|
- [M304] Check for usage of deprecated assertRaisesRegexp
|
||||||
|
- [M305] LOG.warn is deprecated. Enforce use of LOG.warning.
|
||||||
|
@@ -114,3 +114,18 @@ def assert_raisesRegexp(logical_line):
|
|||||||
if res:
|
if res:
|
||||||
yield (0, "M304: assertRaisesRegex must be used instead "
|
yield (0, "M304: assertRaisesRegex must be used instead "
|
||||||
"of assertRaisesRegexp")
|
"of assertRaisesRegexp")
|
||||||
|
|
||||||
|
|
||||||
|
@core.flake8ext
|
||||||
|
def no_log_warn(logical_line):
|
||||||
|
"""Disallow 'LOG.warn('
|
||||||
|
|
||||||
|
LOG.warn() is deprecated and LOG.warning should be used instead.
|
||||||
|
https://docs.python.org/3/library/logging.html#logging.warning
|
||||||
|
|
||||||
|
N352
|
||||||
|
"""
|
||||||
|
|
||||||
|
msg = ("M305: LOG.warn is deprecated, please use LOG.warning!")
|
||||||
|
if "LOG.warn(" in logical_line:
|
||||||
|
yield (0, msg)
|
||||||
|
@@ -271,7 +271,7 @@ class QemuGuestAgent(object):
|
|||||||
self._getJournalObject(domain_uuid).processEvent('report')
|
self._getJournalObject(domain_uuid).processEvent('report')
|
||||||
self._getJournalObject(domain_uuid).setSentNotification(True)
|
self._getJournalObject(domain_uuid).setSentNotification(True)
|
||||||
except Exception:
|
except Exception:
|
||||||
LOG.warn('Exception :' + domain_uuid +
|
LOG.warning('Exception :' + domain_uuid +
|
||||||
' @ ' + get_function_name())
|
' @ ' + get_function_name())
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@@ -405,10 +405,10 @@ class QemuGuestAgent(object):
|
|||||||
do_qemuAgentGuestPing(domain,
|
do_qemuAgentGuestPing(domain,
|
||||||
ICONF.guest_monitoring_timeout)
|
ICONF.guest_monitoring_timeout)
|
||||||
except libvirt.libvirtError as le:
|
except libvirt.libvirtError as le:
|
||||||
LOG.warn(le)
|
LOG.warning(le)
|
||||||
continue
|
continue
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
LOG.warn(e)
|
LOG.warning(e)
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
@@ -145,3 +145,15 @@ class HackingTestCase(testtools.TestCase):
|
|||||||
yieldx_func(a, b)
|
yieldx_func(a, b)
|
||||||
"""
|
"""
|
||||||
self._assert_has_no_errors(code, checks.yield_followed_by_space)
|
self._assert_has_no_errors(code, checks.yield_followed_by_space)
|
||||||
|
|
||||||
|
def test_no_log_warn(self):
|
||||||
|
code = """
|
||||||
|
LOG.warn("LOG.warn is deprecated")
|
||||||
|
"""
|
||||||
|
errors = [(1, 0, 'M305')]
|
||||||
|
self._assert_has_errors(code, checks.no_log_warn,
|
||||||
|
expected_errors=errors)
|
||||||
|
code = """
|
||||||
|
LOG.warning("LOG.warn is deprecated")
|
||||||
|
"""
|
||||||
|
self._assert_has_no_errors(code, checks.no_log_warn)
|
||||||
|
1
tox.ini
1
tox.ini
@@ -115,6 +115,7 @@ extension =
|
|||||||
M302 = checks:no_translate_logs
|
M302 = checks:no_translate_logs
|
||||||
M303 = checks:yield_followed_by_space
|
M303 = checks:yield_followed_by_space
|
||||||
M304 = checks:assert_raisesRegexp
|
M304 = checks:assert_raisesRegexp
|
||||||
|
M305 = checks:no_log_warn
|
||||||
paths = ./masakarimonitors/hacking
|
paths = ./masakarimonitors/hacking
|
||||||
|
|
||||||
[testenv:bindep]
|
[testenv:bindep]
|
||||||
|
Reference in New Issue
Block a user