Change LOG.warn to LOG.warning

Python 3 deprecated the logger.warn method, see:
https://docs.python.org/3/library/logging.html#logging.warning
so we prefer to use warning to avoid DeprecationWarning.

Change-Id: I7d20b2f8003ee89069d7cfd896729c6c78d5beb9
Closes-Bug: #1530742
This commit is contained in:
zhangguoqing 2016-01-04 04:56:07 +00:00 committed by David Stanek
parent dd21f2f2d7
commit 624675f694
10 changed files with 43 additions and 42 deletions

View File

@ -274,8 +274,8 @@ class PKISetup(BaseCertificateSetup):
@classmethod
def main(cls):
LOG.warn(_LW('keystone-manage pki_setup is not recommended for '
'production use.'))
LOG.warning(_LW('keystone-manage pki_setup is not recommended for '
'production use.'))
keystone_user_id, keystone_group_id = cls.get_user_group()
conf_pki = openssl.ConfigurePKI(keystone_user_id, keystone_group_id,
rebuild=CONF.command.rebuild)
@ -293,8 +293,8 @@ class SSLSetup(BaseCertificateSetup):
@classmethod
def main(cls):
LOG.warn(_LW('keystone-manage ssl_setup is not recommended for '
'production use.'))
LOG.warning(_LW('keystone-manage ssl_setup is not recommended for '
'production use.'))
keystone_user_id, keystone_group_id = cls.get_user_group()
conf_ssl = openssl.ConfigureSSL(keystone_user_id, keystone_group_id,
rebuild=CONF.command.rebuild)
@ -598,8 +598,8 @@ class DomainConfigUploadFiles(object):
fname[len(DOMAIN_CONF_FHEAD):
-len(DOMAIN_CONF_FTAIL)])
else:
LOG.warn(_LW('Ignoring file (%s) while scanning '
'domain config directory'), fname)
LOG.warning(_LW('Ignoring file (%s) while scanning '
'domain config directory'), fname)
def run(self):
# First off, let's just check we can talk to the domain database

View File

@ -1220,7 +1220,7 @@ class BaseLdap(object):
try:
ldap_attr, attr_map = item.split(':')
except Exception:
LOG.warn(_LW(
LOG.warning(_LW(
'Invalid additional attribute mapping: "%s". '
'Format must be <ldap_attribute>:<keystone_attribute>'),
item)
@ -1336,7 +1336,7 @@ class BaseLdap(object):
'as an ID. Will get the ID from DN instead') % (
{'id_attr': self.id_attr,
'dn': res[0]})
LOG.warn(message)
LOG.warning(message)
id_val = self._dn_to_id(res[0])
else:
id_val = id_attrs[0]
@ -1668,11 +1668,12 @@ class BaseLdap(object):
not_deleted_nodes.append(node_dn)
if not_deleted_nodes:
LOG.warn(_LW("When deleting entries for %(search_base)s, could not"
" delete nonexistent entries %(entries)s%(dots)s"),
{'search_base': search_base,
'entries': not_deleted_nodes[:3],
'dots': '...' if len(not_deleted_nodes) > 3 else ''})
LOG.warning(_LW("When deleting entries for %(search_base)s, "
"could not delete nonexistent entries "
"%(entries)s%(dots)s"),
{'search_base': search_base,
'entries': not_deleted_nodes[:3],
'dots': '...' if len(not_deleted_nodes) > 3 else ''})
def filter_query(self, hints, query=None):
"""Applies filtering to a query.

View File

@ -70,8 +70,8 @@ class BaseCertificateConfigure(object):
if "OpenSSL 0." in openssl_ver:
self.ssl_dictionary['default_md'] = 'sha1'
except environment.subprocess.CalledProcessError:
LOG.warn(_LW('Failed to invoke ``openssl version``, '
'assuming is v1.0 or newer'))
LOG.warning(_LW('Failed to invoke ``openssl version``, '
'assuming is v1.0 or newer'))
self.ssl_dictionary.update(kwargs)
def exec_command(self, command):

View File

@ -1375,7 +1375,7 @@ class DomainConfigManager(manager.Manager):
'value: %(value)s.')
if warning_msg:
LOG.warn(warning_msg % {
LOG.warning(warning_msg % {
'domain': domain_id,
'group': each_whitelisted['group'],
'option': each_whitelisted['option'],

View File

@ -39,7 +39,7 @@ def configure(version=None, config_files=None,
config.setup_logging()
if CONF.insecure_debug:
LOG.warn(_LW(
LOG.warning(_LW(
'insecure_debug is enabled so responses may include sensitive '
'information.'))

View File

@ -359,7 +359,7 @@ class CheckForLoggingIssues(BaseASTChecker):
# because:
# 1. We have code like this that we'll fix when dealing with the %:
# msg = _('....') % {}
# LOG.warn(msg)
# LOG.warning(msg)
# 2. We also do LOG.exception(e) in several places. I'm not sure
# exactly what we should be doing about that.
if msg.id not in self.assignments:

View File

@ -493,7 +493,7 @@ class DomainConfigTests(object):
with mock.patch('keystone.resource.core.LOG', mock_log):
res = self.domain_config_api.get_config_with_sensitive_info(
self.domain['id'])
mock_log.warn.assert_any_call(mock.ANY)
mock_log.warning.assert_any_call(mock.ANY)
self.assertEqual(
invalid_option_config['ldap']['url'], res['ldap']['url'])

View File

@ -219,12 +219,12 @@ class HackingLogging(fixtures.Fixture):
LOG.info(_('text'))
class C:
def __init__(self):
LOG.warn(oslo_i18n('text', {}))
LOG.warn(_LW('text', {}))
LOG.warning(oslo_i18n('text', {}))
LOG.warning(_LW('text', {}))
""",
'expected_errors': [
(3, 9, 'K006'),
(6, 17, 'K006'),
(6, 20, 'K006'),
],
},
{
@ -287,13 +287,13 @@ class HackingLogging(fixtures.Fixture):
LOG = logging.getLogger()
# ensure the correct helper is being used
LOG.warn(_LI('this should cause an error'))
LOG.warning(_LI('this should cause an error'))
# debug should not allow any helpers either
LOG.debug(_LI('this should cause an error'))
""",
'expected_errors': [
(4, 9, 'K006'),
(4, 12, 'K006'),
(7, 10, 'K005'),
],
},
@ -302,7 +302,7 @@ class HackingLogging(fixtures.Fixture):
# this should not be an error
L = log.getLogger(__name__)
msg = _('text')
L.warn(msg)
L.warning(msg)
raise Exception(msg)
""",
'expected_errors': [],
@ -312,7 +312,7 @@ class HackingLogging(fixtures.Fixture):
L = log.getLogger(__name__)
def f():
msg = _('text')
L2.warn(msg)
L2.warning(msg)
something = True # add an extra statement here
raise Exception(msg)
""",
@ -323,11 +323,11 @@ class HackingLogging(fixtures.Fixture):
LOG = log.getLogger(__name__)
def func():
msg = _('text')
LOG.warn(msg)
LOG.warning(msg)
raise Exception('some other message')
""",
'expected_errors': [
(4, 13, 'K006'),
(4, 16, 'K006'),
],
},
{
@ -337,7 +337,7 @@ class HackingLogging(fixtures.Fixture):
msg = _('text')
else:
msg = _('text')
LOG.warn(msg)
LOG.warning(msg)
raise Exception(msg)
""",
'expected_errors': [
@ -350,28 +350,28 @@ class HackingLogging(fixtures.Fixture):
msg = _('text')
else:
msg = _('text')
LOG.warn(msg)
LOG.warning(msg)
""",
'expected_errors': [
(6, 9, 'K006'),
(6, 12, 'K006'),
],
},
{
'code': """
LOG = log.getLogger(__name__)
msg = _LW('text')
LOG.warn(msg)
LOG.warning(msg)
raise Exception(msg)
""",
'expected_errors': [
(3, 9, 'K007'),
(3, 12, 'K007'),
],
},
{
'code': """
LOG = log.getLogger(__name__)
msg = _LW('text')
LOG.warn(msg)
LOG.warning(msg)
msg = _('something else')
raise Exception(msg)
""",
@ -381,18 +381,18 @@ class HackingLogging(fixtures.Fixture):
'code': """
LOG = log.getLogger(__name__)
msg = _LW('hello %s') % 'world'
LOG.warn(msg)
LOG.warning(msg)
raise Exception(msg)
""",
'expected_errors': [
(3, 9, 'K007'),
(3, 12, 'K007'),
],
},
{
'code': """
LOG = log.getLogger(__name__)
msg = _LW('hello %s') % 'world'
LOG.warn(msg)
LOG.warning(msg)
""",
'expected_errors': [],
},

View File

@ -39,7 +39,7 @@ class TestTestCase(unit.TestCase):
# If the arguments are invalid for the string in a log it raises an
# exception during testing.
self.assertThat(
lambda: LOG.warn('String %(p1)s %(p2)s', {'p1': 'something'}),
lambda: LOG.warning('String %(p1)s %(p2)s', {'p1': 'something'}),
matchers.raises(KeyError))
def test_sa_warning(self):

View File

@ -55,10 +55,10 @@ class Token(token.persistence.TokenDriverV8):
if self.__class__ == Token:
# NOTE(morganfainberg): Only warn if the base KVS implementation
# is instantiated.
LOG.warn(_LW('It is recommended to only use the base '
'key-value-store implementation for the token driver '
"for testing purposes. Please use 'memcache' or "
"'sql' instead."))
LOG.warning(_LW('It is recommended to only use the base '
'key-value-store implementation for the token '
'driver for testing purposes. Please use '
"'memcache' or 'sql' instead."))
def _prefix_token_id(self, token_id):
return 'token-%s' % token_id.encode('utf-8')