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:
parent
45adf21e01
commit
741cffdfe7
@ -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.
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
||||
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user