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:
Takashi Kajinami 2022-01-28 01:21:31 +09:00
parent 45adf21e01
commit 741cffdfe7
5 changed files with 34 additions and 4 deletions

View File

@ -9,3 +9,5 @@ masakari-monitors Specific Commandments
- [M301] Ensure that the _() function is explicitly imported to ensure proper translations.
- [M302] Validate that log messages are not translated.
- [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.

View File

@ -114,3 +114,18 @@ def assert_raisesRegexp(logical_line):
if res:
yield (0, "M304: assertRaisesRegex must be used instead "
"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)

View File

@ -271,8 +271,8 @@ class QemuGuestAgent(object):
self._getJournalObject(domain_uuid).processEvent('report')
self._getJournalObject(domain_uuid).setSentNotification(True)
except Exception:
LOG.warn('Exception :' + domain_uuid +
' @ ' + get_function_name())
LOG.warning('Exception :' + domain_uuid +
' @ ' + get_function_name())
pass
def _qemuAgentGuestPing(self, domain, timeout, flags=0):
@ -405,10 +405,10 @@ class QemuGuestAgent(object):
do_qemuAgentGuestPing(domain,
ICONF.guest_monitoring_timeout)
except libvirt.libvirtError as le:
LOG.warn(le)
LOG.warning(le)
continue
except Exception as e:
LOG.warn(e)
LOG.warning(e)
pass

View File

@ -145,3 +145,15 @@ class HackingTestCase(testtools.TestCase):
yieldx_func(a, b)
"""
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)

View File

@ -115,6 +115,7 @@ extension =
M302 = checks:no_translate_logs
M303 = checks:yield_followed_by_space
M304 = checks:assert_raisesRegexp
M305 = checks:no_log_warn
paths = ./masakarimonitors/hacking
[testenv:bindep]