Python 3 deprecated the logger.warn method in favor of 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.

Closes-Bug: 1508442
Change-Id: I245d24b30e783f1c6dcec1b425d78d271edff49b
This commit is contained in:
Wanlong Gao 2015-12-29 09:23:53 +08:00
parent a859b00596
commit 6ac4ce2eb1
6 changed files with 29 additions and 26 deletions

View File

@ -89,7 +89,7 @@ class CertManager(cert_manager.CertManager):
cert_ref = str(uuid.uuid4()) cert_ref = str(uuid.uuid4())
filename_base = os.path.join(CONF.certificates.storage_path, cert_ref) filename_base = os.path.join(CONF.certificates.storage_path, cert_ref)
LOG.warn(_LW( LOG.warning(_LW(
"Storing certificate data on the local filesystem. " "Storing certificate data on the local filesystem. "
"CertManager type 'local' should be used for testing purpose." "CertManager type 'local' should be used for testing purpose."
)) ))
@ -127,7 +127,7 @@ class CertManager(cert_manager.CertManager):
representation of the certificate data representation of the certificate data
:raises CertificateStorageException: if certificate retrieval fails :raises CertificateStorageException: if certificate retrieval fails
""" """
LOG.warn(_LW( LOG.warning(_LW(
"Loading certificate {0} from the local filesystem. " "Loading certificate {0} from the local filesystem. "
"CertManager type 'local' should be used for testing purpose." "CertManager type 'local' should be used for testing purpose."
).format(cert_ref)) ).format(cert_ref))
@ -188,7 +188,7 @@ class CertManager(cert_manager.CertManager):
:raises CertificateStorageException: if certificate deletion fails :raises CertificateStorageException: if certificate deletion fails
""" """
LOG.warn(_LW( LOG.warning(_LW(
"Deleting certificate {0} from the local filesystem. " "Deleting certificate {0} from the local filesystem. "
"CertManager type 'local' should be used for testing purpose." "CertManager type 'local' should be used for testing purpose."
).format(cert_ref)) ).format(cert_ref))

View File

@ -92,7 +92,7 @@ class KeystoneClientV3(object):
elif self.context.auth_token_info: elif self.context.auth_token_info:
kwargs['token'] = self.context.auth_token kwargs['token'] = self.context.auth_token
if self._is_v2_valid(self.context.auth_token_info): if self._is_v2_valid(self.context.auth_token_info):
LOG.warn('Keystone v2 is deprecated.') LOG.warning('Keystone v2 is deprecated.')
kwargs['auth_ref'] = self.context.auth_token_info['access'] kwargs['auth_ref'] = self.context.auth_token_info['access']
kwargs['auth_ref']['version'] = 'v2.0' kwargs['auth_ref']['version'] = 'v2.0'
elif self._is_v3_valid(self.context.auth_token_info): elif self._is_v3_valid(self.context.auth_token_info):

View File

@ -406,8 +406,8 @@ def unlink_without_raise(path):
if e.errno == errno.ENOENT: if e.errno == errno.ENOENT:
return return
else: else:
LOG.warn(_LW("Failed to unlink %(path)s, error: %(e)s"), LOG.warning(_LW("Failed to unlink %(path)s, error: %(e)s"),
{'path': path, 'e': e}) {'path': path, 'e': e})
def rmtree_without_raise(path): def rmtree_without_raise(path):
@ -415,8 +415,8 @@ def rmtree_without_raise(path):
if os.path.isdir(path): if os.path.isdir(path):
shutil.rmtree(path) shutil.rmtree(path)
except OSError as e: except OSError as e:
LOG.warn(_LW("Failed to remove dir %(path)s, error: %(e)s"), LOG.warning(_LW("Failed to remove dir %(path)s, error: %(e)s"),
{'path': path, 'e': e}) {'path': path, 'e': e})
def write_to_file(path, contents): def write_to_file(path, contents):
@ -431,9 +431,9 @@ def create_link_without_raise(source, link):
if e.errno == errno.EEXIST: if e.errno == errno.EEXIST:
return return
else: else:
LOG.warn(_LW("Failed to create symlink from %(source)s to %(link)s" LOG.warning(_LW("Failed to create symlink from %(source)s to "
", error: %(e)s"), "%(link)s, error: %(e)s"),
{'source': source, 'link': link, 'e': e}) {'source': source, 'link': link, 'e': e})
def safe_rstrip(value, chars=None): def safe_rstrip(value, chars=None):
@ -445,8 +445,10 @@ def safe_rstrip(value, chars=None):
""" """
if not isinstance(value, six.string_types): if not isinstance(value, six.string_types):
LOG.warn(_LW("Failed to remove trailing character. Returning original " LOG.warning(_LW(
"object. Supplied object is not a string: %s,"), value) "Failed to remove trailing character. Returning original object. "
"Supplied object is not a string: %s,"
), value)
return value return value
return value.rstrip(chars) or value return value.rstrip(chars) or value

View File

@ -150,4 +150,4 @@ def delete_certificates_from_bay(bay):
cert_manager.get_backend().CertManager.delete_cert( cert_manager.get_backend().CertManager.delete_cert(
cert_ref, resource_ref=bay.uuid) cert_ref, resource_ref=bay.uuid)
except Exception: except Exception:
LOG.warn(_LW("Deleting cert is failed: %s") % cert_ref) LOG.warning(_LW("Deleting cert is failed: %s") % cert_ref)

View File

@ -51,10 +51,10 @@ class SwarmMonitor(MonitorBase):
try: try:
container = docker.inspect_container(container['Id']) container = docker.inspect_container(container['Id'])
except Exception as e: except Exception as e:
LOG.warn(_LW("Ignore error [%(e)s] when inspecting " LOG.warning(_LW("Ignore error [%(e)s] when inspecting "
"container %(container_id)s."), "container %(container_id)s."),
{'e': e, 'container_id': container['Id']}, {'e': e, 'container_id': container['Id']},
exc_info=True) exc_info=True)
containers.append(container) containers.append(container)
self.data['containers'] = containers self.data['containers'] = containers

View File

@ -98,8 +98,9 @@ class MagnumPeriodicTasks(periodic_task.PeriodicTasks):
self._sync_missing_heat_stack(bay) self._sync_missing_heat_stack(bay)
except Exception as e: except Exception as e:
LOG.warn(_LW("Ignore error [%s] when syncing up bay status."), e, LOG.warning(_LW(
exc_info=True) "Ignore error [%s] when syncing up bay status."
), e, exc_info=True)
def _sync_existing_bay(self, bay, stack): def _sync_existing_bay(self, bay, stack):
if bay.status != stack.stack_status: if bay.status != stack.stack_status:
@ -158,9 +159,9 @@ class MagnumPeriodicTasks(periodic_task.PeriodicTasks):
try: try:
monitor.pull_data() monitor.pull_data()
except Exception as e: except Exception as e:
LOG.warn(_LW("Skip pulling data from bay %(bay)s due to " LOG.warning(_LW("Skip pulling data from bay %(bay)s due to "
"error: %(e)s"), "error: %(e)s"),
{'e': e, 'bay': bay.uuid}, exc_info=True) {'e': e, 'bay': bay.uuid}, exc_info=True)
continue continue
metrics = list() metrics = list()
@ -173,9 +174,9 @@ class MagnumPeriodicTasks(periodic_task.PeriodicTasks):
} }
metrics.append(metric) metrics.append(metric)
except Exception as e: except Exception as e:
LOG.warn(_LW("Skip adding metric %(name)s due to " LOG.warning(_LW("Skip adding metric %(name)s due to "
"error: %(e)s"), "error: %(e)s"),
{'e': e, 'name': name}, exc_info=True) {'e': e, 'name': name}, exc_info=True)
message = dict(metrics=metrics, message = dict(metrics=metrics,
user_id=bay.user_id, user_id=bay.user_id,