Remove log translations

Log messages are no longer being translated. This removes all use of
the _LE, _LI, and _LW 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

Change-Id: Iaef58c19695821426f97b18e96475869265d61d9
This commit is contained in:
shihanzhang 2017-03-21 13:24:40 +08:00
parent b8201a1801
commit 0b972304f0
9 changed files with 17 additions and 74 deletions

View File

@ -19,16 +19,6 @@ _translators = oslo_i18n.TranslatorFactory(domain='tacker')
# The primary translation function using the well-known name "_" # The primary translation function using the well-known name "_"
_ = _translators.primary _ = _translators.primary
# Translators for log levels.
#
# The abbreviated names are meant to reflect the usual use of a short
# name like '_'. The "L" is for "log" and the other letter comes from
# the level.
_LI = _translators.log_info
_LW = _translators.log_warning
_LE = _translators.log_error
_LC = _translators.log_critical
def enable_lazy(enable=True): def enable_lazy(enable=True):
return oslo_i18n.enable_lazy(enable) return oslo_i18n.enable_lazy(enable)

View File

@ -36,7 +36,7 @@ from oslo_utils import importutils
from six import iteritems from six import iteritems
from stevedore import driver from stevedore import driver
from tacker._i18n import _LE from tacker._i18n import _
from tacker.common import constants as q_const from tacker.common import constants as q_const
@ -183,7 +183,7 @@ def load_class_by_alias_or_classname(namespace, name):
""" """
if not name: if not name:
LOG.error(_LE("Alias or class name is not set")) LOG.error("Alias or class name is not set")
raise ImportError(_("Class not found.")) raise ImportError(_("Class not found."))
try: try:
# Try to resolve class by alias # Try to resolve class by alias
@ -195,9 +195,9 @@ def load_class_by_alias_or_classname(namespace, name):
try: try:
class_to_load = importutils.import_class(name) class_to_load = importutils.import_class(name)
except (ImportError, ValueError): except (ImportError, ValueError):
LOG.error(_LE("Error loading class by alias"), LOG.error("Error loading class by alias",
exc_info=e1_info) exc_info=e1_info)
LOG.error(_LE("Error loading class by class name"), LOG.error("Error loading class by class name",
exc_info=True) exc_info=True)
raise ImportError(_("Class not found.")) raise ImportError(_("Class not found."))
return class_to_load return class_to_load

View File

@ -29,7 +29,7 @@ from neutronclient.v2_0 import client as neutron_client
from oslo_config import cfg from oslo_config import cfg
from oslo_log import log as logging from oslo_log import log as logging
from tacker._i18n import _LW, _ from tacker._i18n import _
from tacker.agent.linux import utils as linux_utils from tacker.agent.linux import utils as linux_utils
from tacker.common import log from tacker.common import log
from tacker.extensions import nfvo from tacker.extensions import nfvo
@ -254,7 +254,7 @@ class OpenStack_Driver(abstract_vim_driver.VimAbstractDriver,
linux_utils.execute(ping_cmd, check_exit_code=True) linux_utils.execute(ping_cmd, check_exit_code=True)
return True return True
except RuntimeError: except RuntimeError:
LOG.warning(_LW("Cannot ping ip address: %s"), vim_ip) LOG.warning("Cannot ping ip address: %s", vim_ip)
return False return False
@log.log @log.log

View File

@ -25,7 +25,7 @@ from oslo_utils import excutils
from oslo_utils import importutils from oslo_utils import importutils
import six import six
from tacker._i18n import _, _LE, _LW from tacker._i18n import _
from tacker.api.v1 import attributes from tacker.api.v1 import attributes
from tacker.common import exceptions from tacker.common import exceptions
@ -113,8 +113,7 @@ def _build_subattr_match_rule(attr_name, attr, action, target):
validate = attr['validate'] validate = attr['validate']
key = list(filter(lambda k: k.startswith('type:dict'), validate.keys())) key = list(filter(lambda k: k.startswith('type:dict'), validate.keys()))
if not key: if not key:
LOG.warning(_LW("Unable to find data type descriptor " LOG.warning("Unable to find data type descriptor for attribute %s",
"for attribute %s"),
attr_name) attr_name)
return return
data = validate[key[0]] data = validate[key[0]]
@ -230,7 +229,7 @@ class OwnerCheck(policy.Check):
self.target_field) self.target_field)
else: else:
# If we are here split failed with both separators # If we are here split failed with both separators
err_reason = (_("Unable to find resource name in %s") % err_reason = ("Unable to find resource name in %s" %
self.target_field) self.target_field)
LOG.error(err_reason) LOG.error(err_reason)
raise exceptions.PolicyCheckError( raise exceptions.PolicyCheckError(
@ -239,8 +238,8 @@ class OwnerCheck(policy.Check):
parent_foreign_key = attributes.RESOURCE_FOREIGN_KEYS.get( parent_foreign_key = attributes.RESOURCE_FOREIGN_KEYS.get(
"%ss" % parent_res, None) "%ss" % parent_res, None)
if not parent_foreign_key: if not parent_foreign_key:
err_reason = (_("Unable to verify match:%(match)s as the " err_reason = ("Unable to verify match:%(match)s as the "
"parent resource: %(res)s was not found") % "parent resource: %(res)s was not found" %
{'match': self.match, 'res': parent_res}) {'match': self.match, 'res': parent_res})
LOG.error(err_reason) LOG.error(err_reason)
raise exceptions.PolicyCheckError( raise exceptions.PolicyCheckError(
@ -272,8 +271,7 @@ class OwnerCheck(policy.Check):
raise db_exc.RetryRequest(e) raise db_exc.RetryRequest(e)
except Exception: except Exception:
with excutils.save_and_reraise_exception(): with excutils.save_and_reraise_exception():
LOG.exception(_LE('Policy check error while calling %s!'), LOG.exception('Policy check error while calling %s!', f)
f)
match = self.match % target match = self.match % target
if self.kind in creds: if self.kind in creds:
return match == six.text_type(creds[self.kind]) return match == six.text_type(creds[self.kind])

View File

@ -1,43 +0,0 @@
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from tacker.hacking import checks
from tacker.tests import base
class HackingTestCase(base.BaseTestCase):
def test_log_translations(self):
logs = ['audit', 'error', 'info', 'warn', 'warning', 'critical',
'exception']
levels = ['_LI', '_LW', '_LE', '_LC']
debug = "LOG.debug('OK')"
self.assertEqual(
0, len(list(checks.validate_log_translations(debug, debug, 'f'))))
for log in logs:
bad = 'LOG.%s("Bad")' % log
self.assertEqual(
1, len(list(checks.validate_log_translations(bad, bad, 'f'))))
ok = "LOG.%s(_('OK'))" % log
self.assertEqual(
0, len(list(checks.validate_log_translations(ok, ok, 'f'))))
ok = "LOG.%s('OK') # noqa" % log
self.assertEqual(
0, len(list(checks.validate_log_translations(ok, ok, 'f'))))
ok = "LOG.%s(variable)" % log
self.assertEqual(
0, len(list(checks.validate_log_translations(ok, ok, 'f'))))
for level in levels:
ok = "LOG.%s(%s('OK'))" % (log, level)
self.assertEqual(
0, len(list(checks.validate_log_translations(ok,
ok, 'f'))))

View File

@ -17,7 +17,6 @@ from oslo_log import log as logging
import six.moves.urllib.error as urlerr import six.moves.urllib.error as urlerr
import six.moves.urllib.request as urlreq import six.moves.urllib.request as urlreq
from tacker._i18n import _LW
from tacker.common import log from tacker.common import log
from tacker.vnfm.monitor_drivers import abstract_driver from tacker.vnfm.monitor_drivers import abstract_driver
@ -70,7 +69,7 @@ class VNFMonitorHTTPPing(abstract_driver.VNFMonitorAbstractDriver):
urlreq.urlopen(url, timeout=timeout) urlreq.urlopen(url, timeout=timeout)
return True return True
except urlerr.URLError: except urlerr.URLError:
LOG.warning(_LW('Unable to reach to the url %s'), url) LOG.warning('Unable to reach to the url %s', url)
return 'failure' return 'failure'
@log.log @log.log

View File

@ -15,7 +15,6 @@
from oslo_config import cfg from oslo_config import cfg
from oslo_log import log as logging from oslo_log import log as logging
from tacker._i18n import _LW
from tacker.agent.linux import utils as linux_utils from tacker.agent.linux import utils as linux_utils
from tacker.common import log from tacker.common import log
from tacker.vnfm.monitor_drivers import abstract_driver from tacker.vnfm.monitor_drivers import abstract_driver
@ -71,7 +70,7 @@ class VNFMonitorPing(abstract_driver.VNFMonitorAbstractDriver):
linux_utils.execute(ping_cmd, check_exit_code=True) linux_utils.execute(ping_cmd, check_exit_code=True)
return True return True
except RuntimeError: except RuntimeError:
LOG.warning(_LW("Cannot ping ip address: %s"), mgmt_ip) LOG.warning("Cannot ping ip address: %s", mgmt_ip)
return 'failure' return 'failure'
@log.log @log.log

View File

@ -24,7 +24,6 @@ from oslo_log import log as logging
from oslo_utils import excutils from oslo_utils import excutils
from toscaparser.tosca_template import ToscaTemplate from toscaparser.tosca_template import ToscaTemplate
from tacker._i18n import _LE
from tacker.api.v1 import attributes from tacker.api.v1 import attributes
from tacker.common import driver_manager from tacker.common import driver_manager
from tacker.common import exceptions from tacker.common import exceptions
@ -263,7 +262,7 @@ class VNFMPlugin(vnfm_db.VNFMPluginDb, VNFMMgmtMixin):
vnf_dict=vnf_dict, vnf_id=instance_id, vnf_dict=vnf_dict, vnf_id=instance_id,
auth_attr=auth_attr) auth_attr=auth_attr)
except vnfm.VNFCreateWaitFailed as e: except vnfm.VNFCreateWaitFailed as e:
LOG.error(_LE("VNF Create failed for vnf_id %s"), vnf_id) LOG.error("VNF Create failed for vnf_id %s", vnf_id)
create_failed = True create_failed = True
vnf_dict['status'] = constants.ERROR vnf_dict['status'] = constants.ERROR
self.set_vnf_error_status_reason(context, vnf_id, self.set_vnf_error_status_reason(context, vnf_id,

View File

@ -86,7 +86,8 @@ commands = {posargs}
[flake8] [flake8]
# E128 continuation line under-indented for visual indent # E128 continuation line under-indented for visual indent
ignore = E128 # N320 log messages does not translate
ignore = E128,N320
show-source = true show-source = true
builtins = _ builtins = _
exclude = .venv,.git,.tox,dist,doc,*lib/python*,*egg,build,tools,.ropeproject exclude = .venv,.git,.tox,dist,doc,*lib/python*,*egg,build,tools,.ropeproject