Remove log translations

Log messages are no longer being translated. This removes all use of
the _LE, _LI, _LW and _LC translation markers to simplify logging and to
avoid confusion with new contributions.

See:
http://lists.openstack.org/pipermail/openstack-i18n/2016-November/002574.html
http://lists.openstack.org/pipermail/openstack-dev/2017-March/113365.html

It will be a giant patch if all these _LE, _LI, _LW and _LC being deleted
within one patch, so this patch only delete _LEi and _LC has been handled in
previous patch; deletion of _LI and _LW will be in the following patches
related with this one.

Change-Id: I2aeb953b4b197f42a601edce67fbe5c745b9a9d8
This commit is contained in:
lcsong 2017-04-07 08:45:04 +08:00
parent 7fe65fc4ec
commit 8a51d42d03
19 changed files with 55 additions and 88 deletions

View File

@ -47,6 +47,5 @@ CLI tools packaged with sahara contain log translations.
* Debug: no translation
* Info: _LI
* Warning: _LW
* Error: _LE
.. _PEP 3101: https://www.python.org/dev/peps/pep-3101/

View File

@ -13,7 +13,6 @@
# limitations under the License.
from sahara import conductor # noqa
from sahara.i18n import _LE
from sahara.i18n import _LI
from sahara.plugins import base as plugins_base
from sahara.utils import remote
@ -21,9 +20,9 @@ from sahara.utils import remote
try:
import guestfs
except ImportError:
raise Exception(_LE("The image packing API depends on the system package "
"python-libguestfs (and libguestfs itself.) Please "
"install these packages to proceed."))
raise Exception("The image packing API depends on the system package "
"python-libguestfs (and libguestfs itself.) Please "
"install these packages to proceed.")
LOG = None

View File

@ -31,4 +31,3 @@ _ = _translators.primary
# the level.
_LI = _translators.log_info
_LW = _translators.log_warning
_LE = _translators.log_error

View File

@ -32,7 +32,6 @@ from six.moves import urllib
from sahara import context
from sahara.i18n import _
from sahara.i18n import _LE
from sahara.i18n import _LW
from sahara.plugins.cdh import exceptions as ex
@ -93,7 +92,7 @@ class Resource(object):
json_dict = json.loads(body)
return json_dict
except Exception:
LOG.error(_LE('JSON decode error: {body}').format(body=body))
LOG.error('JSON decode error: {body}'.format(body=body))
raise
else:
return body

View File

@ -19,7 +19,6 @@ from sahara import conductor as cond
from sahara import context
from sahara import exceptions as ex
from sahara.i18n import _
from sahara.i18n import _LE
from sahara.i18n import _LW
conductor = cond.API
@ -108,7 +107,7 @@ class LabelHandler(object):
try:
plugin = conductor.plugin_get(context.ctx(), plugin_name)
except Exception:
LOG.error(_LE("Unable to retrieve plugin data from database"))
LOG.error("Unable to retrieve plugin data from database")
plugin = None
if not plugin:
plugin = self.get_default_label_details(plugin_name)

View File

@ -20,7 +20,6 @@ import six
from sahara import conductor as c
from sahara import context
from sahara import exceptions as ex
from sahara.i18n import _LE
from sahara.plugins import base as plugin_base
from sahara.service import api
from sahara.service.edp.binary_retrievers import dispatch
@ -129,8 +128,8 @@ def execute_job(job_id, data):
try:
p.create_proxy_user_for_job_execution(job_execution)
except ex.SaharaException as e:
LOG.error(_LE("Can't run job execution. "
"(Reasons: {reason})").format(reason=e))
LOG.error("Can't run job execution. "
"(Reasons: {reason})".format(reason=e))
conductor.job_execution_destroy(context.ctx(), job_execution)
raise

View File

@ -18,7 +18,6 @@ from oslo_log import log as logging
from sahara import conductor as c
from sahara import context
from sahara import exceptions as ex
from sahara.i18n import _LE
from sahara.service import api
from sahara.service.edp import job_manager as manager
from sahara.utils import edp
@ -61,8 +60,8 @@ def execute_job(job_id, data):
try:
p.create_proxy_user_for_job_execution(job_execution)
except ex.SaharaException as e:
LOG.error(_LE("Can't run job execution. "
"(Reasons: {reason})").format(reason=e))
LOG.error("Can't run job execution. "
"(Reasons: {reason})".format(reason=e))
conductor.job_execution_destroy(context.ctx(), job_execution)
raise e

View File

@ -21,7 +21,6 @@ from oslo_log import log
from oslo_utils import uuidutils
from tooz import coordination
from sahara.i18n import _LE
from sahara.i18n import _LI
LOG = log.getLogger(__name__)
@ -54,7 +53,7 @@ class Coordinator(object):
self.coordinator.start()
LOG.info(_LI('Coordination backend loaded successfully.'))
except coordination.ToozError:
LOG.error(_LE('Error connecting to coordination backend.'))
LOG.error('Error connecting to coordination backend.')
raise
def is_started(self):
@ -88,8 +87,8 @@ class Coordinator(object):
except coordination.GroupNotCreated:
self.join_group(group_id)
except coordination.ToozError as e:
LOG.error(_LE("Couldn't get members of {group} group. "
"Reason: {ex}").format(
LOG.error("Couldn't get members of {group} group. "
"Reason: {ex}".format(
group=group_id, ex=str(e)))
return []

View File

@ -23,7 +23,6 @@ from sahara import conductor as c
from sahara import context
from sahara import exceptions as e
from sahara.i18n import _
from sahara.i18n import _LE
from sahara.i18n import _LI
from sahara.i18n import _LW
from sahara.service.edp import job_utils
@ -136,9 +135,8 @@ def run_job(job_execution_id):
try:
_run_job(job_execution_id)
except Exception as ex:
LOG.exception(
_LE("Can't run job execution (reason: {reason})").format(
reason=ex))
LOG.exception("Can't run job execution (reason: {reason})".format(
reason=ex))
job_execution = conductor.job_execution_get(
context.ctx(), job_execution_id)
@ -218,7 +216,7 @@ def update_job_status(job_execution_id):
try:
get_job_status(job_execution_id)
except Exception as e:
LOG.exception(_LE("Error during update job execution {job}: {error}")
LOG.exception("Error during update job execution {job}: {error}"
.format(job=job_execution_id, error=e))

View File

@ -25,7 +25,6 @@ from sahara import conductor
from sahara import context
from sahara import exceptions
from sahara.i18n import _
from sahara.i18n import _LE
from sahara.plugins import base as plugin_base
from sahara.service.health import common
from sahara.utils import cluster as cluster_utils
@ -141,7 +140,7 @@ class AllInstancesAccessible(BasicHealthCheck):
if inst_ips_or_names:
insts = ', '.join(inst_ips_or_names)
LOG.exception(
_LE("Instances (%s) are not available in the cluster") % insts)
"Instances (%s) are not available in the cluster" % insts)
raise RedHealthError(
_("Instances (%s) are not available in the cluster.") % insts)
return _("All instances are available")
@ -173,7 +172,7 @@ class ResolvConfIsUnchanged(BasicHealthCheck):
"Instances ({}) have incorrect '/etc/resolv.conf' "
"file, expected nameservers: {}.").format(insts, ns)
if bad_inst_msg or res_conf_msg:
LOG.exception(_LE("{} {}").format(res_conf_msg, bad_inst_msg))
LOG.exception("{} {}".format(res_conf_msg, bad_inst_msg))
raise RedHealthError(_("{} {}").format(res_conf_msg, bad_inst_msg))
return _("All instances have correct '/etc/resolv.conf' file")
@ -191,7 +190,7 @@ class AlertsProvider(object):
data = self._get_resolv_conf(r)
except Exception:
data = None
LOG.exception(_LE("Couldn't read '/etc/resolv.conf'"))
LOG.exception("Couldn't read '/etc/resolv.conf'")
with lock:
self._data[instance.get_ip_or_dns_name()] = data

View File

@ -25,7 +25,6 @@ from sahara import conductor as c
from sahara import context
from sahara import exceptions
from sahara.i18n import _
from sahara.i18n import _LE
from sahara.plugins import base as plugin_base
from sahara.service.edp import job_manager
from sahara.service.edp.utils import shares
@ -202,8 +201,8 @@ def ops_error_handler(description):
return
msg = six.text_type(ex)
LOG.exception(_LE("Error during operating on cluster (reason: "
"{reason})").format(reason=msg))
LOG.exception("Error during operating on cluster (reason: "
"{reason})".format(reason=msg))
try:
# trying to rollback
@ -225,8 +224,8 @@ def ops_error_handler(description):
return
LOG.exception(
_LE("Error during rollback of cluster (reason:"
" {reason})").format(reason=six.text_type(rex)))
"Error during rollback of cluster (reason:"
" {reason})".format(reason=six.text_type(rex)))
desc = "{0}, {1}".format(msg, six.text_type(rex))
c_u.change_cluster_status(
cluster, c_u.CLUSTER_STATUS_ERROR,
@ -393,8 +392,8 @@ def _delete_job_execution(job_execution_id):
# job_execution was deleted already, nothing to do
return
except exceptions.CancelingFailed:
LOG.error(_LE("Job execution can't be cancelled in time. "
"Deleting it anyway."))
LOG.error("Job execution can't be cancelled in time. "
"Deleting it anyway.")
conductor.job_execution_destroy(context.ctx(), job_execution_id)

View File

@ -19,7 +19,6 @@ from oslo_log import log as logging
from sahara import exceptions as ex
from sahara.i18n import _
from sahara.i18n import _LE
CONF = cfg.CONF
@ -90,9 +89,8 @@ class SessionCache(object):
if session_function:
return session_function()
else:
LOG.error(
_LE('Requesting an unknown session type (type: {type})').
format(type=session_type))
LOG.error('Requesting an unknown session type (type: {type})'.
format(type=session_type))
raise ex.SaharaException(
_('Session type {type} not recognized').
format(type=session_type))

View File

@ -22,7 +22,6 @@ from sahara import conductor as c
from sahara import context
from sahara import exceptions as ex
from sahara.i18n import _
from sahara.i18n import _LE
from sahara.utils.openstack import keystone
conductor = c.API
@ -70,8 +69,7 @@ def create_trust(trustor, trustee, role_names, impersonation=True,
trust_id=six.text_type(trust.id)))
return trust.id
except Exception as e:
LOG.error(_LE('Unable to create trust (reason: {reason})').format(
reason=e))
LOG.error('Unable to create trust (reason: {reason})'.format(reason=e))
raise ex.CreationFailed(_('Failed to create trust'))
@ -117,8 +115,7 @@ def delete_trust(trustee, trust_id):
LOG.debug('Deleted trust {trust_id}'.format(
trust_id=six.text_type(trust_id)))
except Exception as e:
LOG.error(_LE('Unable to delete trust (reason: {reason})').format(
reason=e))
LOG.error('Unable to delete trust (reason: {reason})'.format(reason=e))
raise ex.DeletionFailed(
_('Failed to delete trust {0}').format(trust_id))

View File

@ -22,7 +22,6 @@ from oslo_log import log as logging
from sahara import conductor as c
from sahara import context
from sahara.i18n import _
from sahara.i18n import _LE
from sahara.i18n import _LW
from sahara.plugins import provisioning as plugin_base
from sahara.utils import cluster_progress_ops as cpo
@ -231,7 +230,7 @@ def _mount_volume(instance, device_path, mount_point, use_xfs):
'sudo sh -c "grep %s /etc/mtab >> /etc/fstab"' % device_path)
except Exception:
LOG.error(_LE("Error mounting volume to instance"))
LOG.error("Error mounting volume to instance")
raise
@ -257,7 +256,7 @@ def _detach_volume(instance, volume_id):
b.execute_with_retries(nova.client().volumes.delete_server_volume,
instance.instance_id, volume_id)
except Exception:
LOG.error(_LE("Can't detach volume {id}").format(id=volume.id))
LOG.error("Can't detach volume {id}".format(id=volume.id))
detach_timeout = CONF.timeouts.detach_volume_timeout
LOG.debug("Waiting {timeout} seconds to detach {id} volume".format(
@ -271,5 +270,4 @@ def _delete_volume(volume_id):
try:
b.execute_with_retries(volume.delete)
except Exception:
LOG.error(_LE("Can't delete volume {volume}").format(
volume=volume.id))
LOG.error("Can't delete volume {volume}".format(volume=volume.id))

View File

@ -37,7 +37,6 @@ from oslo_log import log as logging
import sahara.db.migration
from sahara.db.sqlalchemy import api as sa
from sahara.db.sqlalchemy import model_base
from sahara.i18n import _LE
LOG = logging.getLogger(__name__)
@ -152,8 +151,8 @@ class BaseWalkMigrationTestCase(object):
if check:
check(engine, data)
except Exception:
LOG.error(_LE("Failed to migrate to version {version} on engine "
"{engine}").format(version=version, engine=engine))
LOG.error("Failed to migrate to version {version} on engine "
"{engine}".format(version=version, engine=engine))
raise

View File

@ -23,7 +23,6 @@ from werkzeug import datastructures
from sahara import context
from sahara import exceptions as ex
from sahara.i18n import _
from sahara.i18n import _LE
from sahara.utils import types
from sahara.utils import wsgi
@ -259,9 +258,8 @@ def get_request_args():
def abort_and_log(status_code, descr, exc=None):
LOG.error(_LE("Request aborted with status code {code} and "
"message '{message}'").format(code=status_code,
message=descr))
LOG.error("Request aborted with status code {code} and "
"message '{message}'".format(code=status_code, message=descr))
if exc is not None:
LOG.error(traceback.format_exc())
@ -283,9 +281,8 @@ def render_error_message(error_code, error_message, error_name):
def internal_error(status_code, descr, exc=None):
LOG.error(_LE("Request aborted with status code {code} and "
"message '{message}'").format(code=status_code,
message=descr))
LOG.error("Request aborted with status code {code} and "
"message '{message}'".format(code=status_code, message=descr))
if exc is not None:
LOG.error(traceback.format_exc())
@ -300,11 +297,11 @@ def internal_error(status_code, descr, exc=None):
def bad_request(error):
error_code = 400
LOG.error(_LE("Validation Error occurred: "
"error_code={code}, error_message={message}, "
"error_name={name}").format(code=error_code,
message=error.message,
name=error.code))
LOG.error("Validation Error occurred: "
"error_code={code}, error_message={message}, "
"error_name={name}".format(code=error_code,
message=error.message,
name=error.code))
return render_error_message(error_code, error.message, error.code)
@ -312,11 +309,10 @@ def bad_request(error):
def access_denied(error):
error_code = 403
LOG.error(_LE("Access Denied: "
"error_code={code}, error_message={message}, "
"error_name={name}").format(code=error_code,
message=error.message,
name=error.code))
LOG.error("Access Denied: error_code={code}, error_message={message}, "
"error_name={name}".format(code=error_code,
message=error.message,
name=error.code))
return render_error_message(error_code, error.message, error.code)
@ -324,11 +320,11 @@ def access_denied(error):
def not_found(error):
error_code = 404
LOG.error(_LE("Not Found exception occurred: "
"error_code={code}, error_message={message}, "
"error_name={name}").format(code=error_code,
message=error.message,
name=error.code))
LOG.error("Not Found exception occurred: "
"error_code={code}, error_message={message}, "
"error_name={name}".format(code=error_code,
message=error.message,
name=error.code))
return render_error_message(error_code, error.message, error.code)

View File

@ -22,8 +22,6 @@ import re
log_translation_LI = re.compile(
r"(.)*LOG\.(info)\(\s*(_\(|'|\")")
log_translation_LE = re.compile(
r"(.)*LOG\.(exception)\(\s*(_\(|'|\")")
log_translation_LW = re.compile(
r"(.)*LOG\.(warning)\(\s*(_\(|'|\")")
accepted_log_level = re.compile(
@ -55,10 +53,6 @@ def validate_log_translations(logical_line, filename):
msg = "S369: LOG.info messages require translations `_LI()`!"
if log_translation_LI.search(logical_line):
yield (0, msg)
msg = ("S370: LOG.exception and LOG.error messages require "
"translations `_LE()`!")
if log_translation_LE.search(logical_line):
yield (0, msg)
msg = "S371: LOG.warning messages require translations `_LW()`!"
if log_translation_LW.search(logical_line):
yield (0, msg)

View File

@ -21,7 +21,6 @@ from oslo_messaging.rpc import dispatcher
from oslo_serialization import jsonutils
from sahara import context
from sahara.i18n import _LE
MESSAGING_TRANSPORT = None
@ -105,8 +104,8 @@ def setup_notifications():
NOTIFICATION_TRANSPORT = \
messaging.get_notification_transport(cfg.CONF)
except Exception:
LOG.error(_LE("Unable to setup notification transport. Reusing "
"service transport for that."))
LOG.error("Unable to setup notification transport. Reusing "
"service transport for that.")
setup_service_messaging()
NOTIFICATION_TRANSPORT = MESSAGING_TRANSPORT

View File

@ -53,7 +53,6 @@ import six
from sahara import context
from sahara import exceptions as ex
from sahara.i18n import _
from sahara.i18n import _LE
from sahara.service import trusts
from sahara.utils import crypto
from sahara.utils import network as net_utils
@ -345,8 +344,7 @@ def _read_file_from(remote_file, run_as_root=False):
try:
return _read_file(_ssh.open_sftp(), fl)
except IOError:
LOG.error(_LE("Can't read file {filename}").format(
filename=remote_file))
LOG.error("Can't read file {filename}".format(filename=remote_file))
raise
finally:
if run_as_root:
@ -672,7 +670,7 @@ class InstanceInteropHelper(remote.Remote):
try:
command = command.format(**keywords)
except KeyError as e:
LOG.error(_LE('Invalid keyword in proxy_command: {result}').format(
LOG.error('Invalid keyword in proxy_command: {result}'.format(
result=e))
# Do not give more details to the end-user
raise ex.SystemError('Misconfiguration')