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: I43e2269d4b1c425119c86919eb869941d621c6de
This commit is contained in:
Takashi Kajinami 2021-11-29 15:48:25 +09:00
parent daeae9c8a5
commit 2a5ef1b933
5 changed files with 22 additions and 1 deletions

View File

@ -26,6 +26,7 @@ Tempest Specific Commandments
- [T116] Unsupported 'message' Exception attribute in PY3
- [T117] Check negative tests have ``@decorators.attr(type=['negative'])``
applied.
- [T118] LOG.warn is deprecated. Enforce use of LOG.warning.
It is recommended to use ``tox -eautopep8`` before submitting a patch.

View File

@ -130,7 +130,7 @@ def verify_glance_api_versions(os, update):
msg = ('Glance is available in the catalog, but no known version, '
'(v1.x or v2.x) of Glance could be found, so Glance should '
'be configured as not available')
LOG.warn(msg)
LOG.warning(msg)
print_and_or_update('glance', 'service-available', False, update)
return

View File

@ -318,3 +318,16 @@ def negative_test_attribute_always_applied_to_negative_tests(physical_line,
" to all negative API tests"
)
_HAVE_NEGATIVE_DECORATOR = False
@core.flake8ext
def no_log_warn(logical_line):
"""Disallow 'LOG.warn('
Use LOG.warning() instead of Deprecated LOG.warn().
https://docs.python.org/3/library/logging.html#logging.warning
"""
msg = ("T118: LOG.warn is deprecated, please use LOG.warning!")
if "LOG.warn(" in logical_line:
yield (0, msg)

View File

@ -240,3 +240,9 @@ class HackingTestCase(base.TestCase):
with_other_decorators=True,
with_negative_decorator=False,
expected_success=False)
def test_no_log_warn(self):
self.assertFalse(list(checks.no_log_warn(
'LOG.warning("LOG.warn is deprecated")')))
self.assertTrue(list(checks.no_log_warn(
'LOG.warn("LOG.warn is deprecated")')))

View File

@ -370,6 +370,7 @@ extension =
T115 = checks:dont_put_admin_tests_on_nonadmin_path
T116 = checks:unsupported_exception_attribute_PY3
T117 = checks:negative_test_attribute_always_applied_to_negative_tests
T118 = checks:no_log_warn
paths =
./tempest/hacking