Translator functions cleanup part 1

This part fixes ironic/common folder and tox.ini file.

Some modules use _ function for log translation, even when the
translated string is passed to e.g. LOG.warn function. This patch
fixes it, using translator functions appropriate for corresponding
log levels. Translator functions, imported from
ironic.openstack.common.gettextutils are now imported from
ironic.common.i18n. Translator functions are imported the same way
across all modules. All places that are changed conform to
http://docs.openstack.org/developer/oslo.i18n/guidelines.html

Partial-bug: #1364813

Change-Id: I195d0e256c5412d6d75d2e6c35b19b44f2a0b09f
This commit is contained in:
Vladyslav Drok 2014-09-03 12:46:51 +03:00
parent 9f651b69fd
commit f80e85ef6d
9 changed files with 34 additions and 35 deletions

View File

@ -19,6 +19,7 @@ from oslo.config import cfg
from ironic.common import exception
from ironic.common.i18n import _
from ironic.common.i18n import _LW
from ironic.common import utils
from ironic.openstack.common import log as logging
from ironic.openstack.common import loopingcall
@ -129,8 +130,8 @@ class DiskPartitioner(object):
pids_match = re.search(self._fuser_pids_re, out)
pids[0] = pids_match.group()
except processutils.ProcessExecutionError as exc:
LOG.warning(_('Failed to check the device %(device)s with fuser: '
' %(err)s') % {'device': self._device, 'err': exc})
LOG.warning(_LW('Failed to check the device %(device)s with fuser:'
' %(err)s'), {'device': self._device, 'err': exc})
def commit(self):
"""Write to the disk."""
@ -194,7 +195,7 @@ def list_partitions(device):
for line in lines:
match = _PARTED_PRINT_RE.match(line)
if match is None:
LOG.warn(_("Partition information from parted for device "
LOG.warn(_LW("Partition information from parted for device "
"%(device)s does not match "
"expected format: %(line)s"),
dict(device=device, line=line))

View File

@ -16,7 +16,7 @@
from oslo.config import cfg
from ironic.common import exception
from ironic.common.i18n import _
from ironic.common.i18n import _LI
from ironic.openstack.common import lockutils
from ironic.openstack.common import log
from stevedore import dispatch
@ -118,7 +118,7 @@ class DriverFactory(object):
_check_func,
invoke_on_load=True,
on_load_failure_callback=_catch_driver_not_found)
LOG.info(_("Loaded the following drivers: %s"),
LOG.info(_LI("Loaded the following drivers: %s"),
cls._extension_manager.names())
@property

View File

@ -26,6 +26,7 @@ from oslo.config import cfg
import six
from ironic.common.i18n import _
from ironic.common.i18n import _LE
from ironic.openstack.common import log as logging
@ -75,7 +76,7 @@ class IronicException(Exception):
except Exception as e:
# kwargs doesn't match a variable in the message
# log the issue and the kwargs
LOG.exception(_('Exception in string format operation'))
LOG.exception(_LE('Exception in string format operation'))
for name, value in kwargs.iteritems():
LOG.error("%s: %s" % (name, value))

View File

@ -28,7 +28,7 @@ import six.moves.urllib.parse as urlparse
from ironic.common import exception
from ironic.common.glance_service import service_utils
from ironic.common.i18n import _
from ironic.common.i18n import _LE
from oslo.config import cfg
@ -125,7 +125,7 @@ class BaseImageService(object):
host = self.glance_host
port = self.glance_port
extra = "retrying"
error_msg = _("Error contacting glance server "
error_msg = _LE("Error contacting glance server "
"'%(host)s:%(port)s' for '%(method)s', "
"%(extra)s.")
if attempt == num_attempts:

View File

@ -26,8 +26,8 @@ import jinja2
from oslo.config import cfg
from ironic.common import exception
from ironic.common import i18n
from ironic.common.i18n import _
from ironic.common.i18n import _LE
from ironic.common import image_service as service
from ironic.common import paths
from ironic.common import utils
@ -38,8 +38,6 @@ from ironic.openstack.common import processutils
LOG = logging.getLogger(__name__)
_LE = i18n._LE
image_opts = [
cfg.BoolOpt('force_raw_images',
default=True,

View File

@ -21,16 +21,13 @@ from oslo.config import cfg
from ironic.common import dhcp_factory
from ironic.common import exception
from ironic.common import i18n
from ironic.common.i18n import _
from ironic.common.i18n import _LW
from ironic.common import utils
from ironic.drivers import utils as driver_utils
from ironic.openstack.common import fileutils
from ironic.openstack.common import log as logging
_LW = i18n._LW
_LE = i18n._LE
CONF = cfg.CONF
LOG = logging.getLogger(__name__)

View File

@ -23,11 +23,11 @@ from oslo import messaging
from oslo.utils import importutils
from ironic.common import config
from ironic.common.i18n import _
from ironic.common.i18n import _LE
from ironic.common.i18n import _LI
from ironic.common import rpc
from ironic.objects import base as objects_base
from ironic.openstack.common import context
from ironic.openstack.common.gettextutils import _LI
from ironic.openstack.common import log
from ironic.openstack.common import service
@ -85,12 +85,12 @@ class RPCService(service.Service):
self.rpcserver.stop()
self.rpcserver.wait()
except Exception as e:
LOG.exception(_('Service error occurred when stopping the '
LOG.exception(_LE('Service error occurred when stopping the '
'RPC server. Error: %s'), e)
try:
self.manager.del_host()
except Exception as e:
LOG.exception(_('Service error occurred when cleaning up '
LOG.exception(_LE('Service error occurred when cleaning up '
'the RPC manager. Error: %s'), e)
LOG.info(_LI('Stopped RPC server for service %(service)s on host '
'%(host)s.'),

View File

@ -35,6 +35,8 @@ import six
from ironic.common import exception
from ironic.common.i18n import _
from ironic.common.i18n import _LE
from ironic.common.i18n import _LW
from ironic.openstack.common import log as logging
from ironic.openstack.common import processutils
@ -409,7 +411,7 @@ def tempdir(**kwargs):
try:
shutil.rmtree(tmpdir)
except OSError as e:
LOG.error(_('Could not remove tmpdir: %s'), str(e))
LOG.error(_LE('Could not remove tmpdir: %s'), e)
def mkfs(fs, path, label=None):
@ -444,7 +446,7 @@ def unlink_without_raise(path):
if e.errno == errno.ENOENT:
return
else:
LOG.warn(_("Failed to unlink %(path)s, error: %(e)s") %
LOG.warn(_LW("Failed to unlink %(path)s, error: %(e)s"),
{'path': path, 'e': e})
@ -453,7 +455,7 @@ def rmtree_without_raise(path):
if os.path.isdir(path):
shutil.rmtree(path)
except OSError as e:
LOG.warn(_("Failed to remove dir %(path)s, error: %(e)s") %
LOG.warn(_LW("Failed to remove dir %(path)s, error: %(e)s"),
{'path': path, 'e': e})
@ -469,8 +471,8 @@ def create_link_without_raise(source, link):
if e.errno == errno.EEXIST:
return
else:
LOG.warn(_("Failed to create symlink from %(source)s to %(link)s"
", error: %(e)s") %
LOG.warn(_LW("Failed to create symlink from %(source)s to %(link)s"
", error: %(e)s"),
{'source': source, 'link': link, 'e': e})
@ -483,8 +485,8 @@ def safe_rstrip(value, chars=None):
"""
if not isinstance(value, six.string_types):
LOG.warn(_("Failed to remove trailing character. Returning original "
"object. Supplied object is not a string: %s,") % value)
LOG.warn(_LW("Failed to remove trailing character. Returning original "
"object. Supplied object is not a string: %s,"), value)
return value
return value.rstrip(chars) or value

View File

@ -48,4 +48,4 @@ exclude = .venv,.git,.tox,dist,doc,*openstack/common*,*lib/python*,*egg,build,t
[hacking]
import_exceptions = ironic.openstack.common.gettextutils._, ironic.openstack.common.gettextutils._LI,
ironic.openstack.common.gettextutils._LW,ironic.openstack.common.gettextutils._LE,
ironic.openstack.common.gettextutils._LC, testtools.matchers, ironic.common.i18n._
ironic.openstack.common.gettextutils._LC, testtools.matchers, ironic.common.i18n