Update oslo log messages with translation domains

Update the incubator code to use different domains for log
messages at different levels.

Update the import exceptions setting for hacking to allow
multiple functions to be imported from gettextutils on one
line.

bp log-messages-translation-domain

Change-Id: I6ce0f4a59438612ce74c46b3ee9398bef24c0c19
This commit is contained in:
Doug Hellmann
2014-01-08 19:35:05 +00:00
parent af9cad7939
commit 9e0402c223
2 changed files with 15 additions and 14 deletions

View File

@@ -28,7 +28,7 @@ import weakref
from oslo.config import cfg from oslo.config import cfg
from openstack.common import fileutils from openstack.common import fileutils
from openstack.common.gettextutils import _ from openstack.common.gettextutils import _, _LE, _LI
from openstack.common import log as logging from openstack.common import log as logging
@@ -79,7 +79,7 @@ class _InterProcessLock(object):
if not os.path.exists(basedir): if not os.path.exists(basedir):
fileutils.ensure_tree(basedir) fileutils.ensure_tree(basedir)
LOG.info(_('Created lock path: %s'), basedir) LOG.info(_LI('Created lock path: %s'), basedir)
self.lockfile = open(self.fname, 'w') self.lockfile = open(self.fname, 'w')
@@ -90,7 +90,7 @@ class _InterProcessLock(object):
# Also upon reading the MSDN docs for locking(), it seems # Also upon reading the MSDN docs for locking(), it seems
# to have a laughable 10 attempts "blocking" mechanism. # to have a laughable 10 attempts "blocking" mechanism.
self.trylock() self.trylock()
LOG.debug(_('Got file lock "%s"'), self.fname) LOG.debug('Got file lock "%s"', self.fname)
return True return True
except IOError as e: except IOError as e:
if e.errno in (errno.EACCES, errno.EAGAIN): if e.errno in (errno.EACCES, errno.EAGAIN):
@@ -114,9 +114,9 @@ class _InterProcessLock(object):
try: try:
self.unlock() self.unlock()
self.lockfile.close() self.lockfile.close()
LOG.debug(_('Released file lock "%s"'), self.fname) LOG.debug('Released file lock "%s"', self.fname)
except IOError: except IOError:
LOG.exception(_("Could not release the acquired lock `%s`"), LOG.exception(_LE("Could not release the acquired lock `%s`"),
self.fname) self.fname)
def __exit__(self, exc_type, exc_val, exc_tb): def __exit__(self, exc_type, exc_val, exc_tb):
@@ -158,7 +158,7 @@ _semaphores_lock = threading.Lock()
def external_lock(name, lock_file_prefix=None): def external_lock(name, lock_file_prefix=None):
with internal_lock(name): with internal_lock(name):
LOG.debug(_('Attempting to grab external lock "%(lock)s"'), LOG.debug('Attempting to grab external lock "%(lock)s"',
{'lock': name}) {'lock': name})
# NOTE(mikal): the lock name cannot contain directory # NOTE(mikal): the lock name cannot contain directory
@@ -184,7 +184,7 @@ def internal_lock(name):
sem = threading.Semaphore() sem = threading.Semaphore()
_semaphores[name] = sem _semaphores[name] = sem
LOG.debug(_('Got semaphore "%(lock)s"'), {'lock': name}) LOG.debug('Got semaphore "%(lock)s"', {'lock': name})
return sem return sem
@@ -241,11 +241,11 @@ def synchronized(name, lock_file_prefix=None, external=False):
def inner(*args, **kwargs): def inner(*args, **kwargs):
try: try:
with lock(name, lock_file_prefix, external): with lock(name, lock_file_prefix, external):
LOG.debug(_('Got semaphore / lock "%(function)s"'), LOG.debug('Got semaphore / lock "%(function)s"',
{'function': f.__name__}) {'function': f.__name__})
return f(*args, **kwargs) return f(*args, **kwargs)
finally: finally:
LOG.debug(_('Semaphore / lock released "%(function)s"'), LOG.debug('Semaphore / lock released "%(function)s"',
{'function': f.__name__}) {'function': f.__name__})
return inner return inner
return wrap return wrap

View File

@@ -151,7 +151,8 @@ def execute(*cmd, **kwargs):
while attempts > 0: while attempts > 0:
attempts -= 1 attempts -= 1
try: try:
LOG.log(loglevel, _('Running cmd (subprocess): %s'), ' '.join(cmd)) LOG.log(loglevel, 'Running cmd (subprocess): %s',
' '.join(cmd))
_PIPE = subprocess.PIPE # pylint: disable=E1101 _PIPE = subprocess.PIPE # pylint: disable=E1101
if os.name == 'nt': if os.name == 'nt':
@@ -184,7 +185,7 @@ def execute(*cmd, **kwargs):
break break
obj.stdin.close() # pylint: disable=E1101 obj.stdin.close() # pylint: disable=E1101
_returncode = obj.returncode # pylint: disable=E1101 _returncode = obj.returncode # pylint: disable=E1101
LOG.log(loglevel, _('Result was %s') % _returncode) LOG.log(loglevel, 'Result was %s' % _returncode)
if not ignore_exit_code and _returncode not in check_exit_code: if not ignore_exit_code and _returncode not in check_exit_code:
(stdout, stderr) = result (stdout, stderr) = result
raise ProcessExecutionError(exit_code=_returncode, raise ProcessExecutionError(exit_code=_returncode,
@@ -196,7 +197,7 @@ def execute(*cmd, **kwargs):
if not attempts: if not attempts:
raise raise
else: else:
LOG.log(loglevel, _('%r failed. Retrying.'), cmd) LOG.log(loglevel, '%r failed. Retrying.', cmd)
if delay_on_retry: if delay_on_retry:
greenthread.sleep(random.randint(20, 200) / 100.0) greenthread.sleep(random.randint(20, 200) / 100.0)
finally: finally:
@@ -235,7 +236,7 @@ def trycmd(*args, **kwargs):
def ssh_execute(ssh, cmd, process_input=None, def ssh_execute(ssh, cmd, process_input=None,
addl_env=None, check_exit_code=True): addl_env=None, check_exit_code=True):
LOG.debug(_('Running cmd (SSH): %s'), cmd) LOG.debug('Running cmd (SSH): %s', cmd)
if addl_env: if addl_env:
raise InvalidArgumentError(_('Environment not supported over SSH')) raise InvalidArgumentError(_('Environment not supported over SSH'))
@@ -256,7 +257,7 @@ def ssh_execute(ssh, cmd, process_input=None,
# exit_status == -1 if no exit code was returned # exit_status == -1 if no exit code was returned
if exit_status != -1: if exit_status != -1:
LOG.debug(_('Result was %s') % exit_status) LOG.debug('Result was %s' % exit_status)
if check_exit_code and exit_status != 0: if check_exit_code and exit_status != 0:
raise ProcessExecutionError(exit_code=exit_status, raise ProcessExecutionError(exit_code=exit_status,
stdout=stdout, stdout=stdout,