From 0cdbbf669dfffd546a527a28f8955b64b12631c9 Mon Sep 17 00:00:00 2001 From: Kengo Takahara Date: Mon, 19 Jun 2017 16:38:05 +0900 Subject: [PATCH] Remove log translations Log messages are no longer being translated. This removes all use of the _LC, _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: Ic415d098199afb300eb7bd9967bf4a9acb457aec --- HACKING.rst | 1 + masakarimonitors/conf/opts.py | 8 ++-- masakarimonitors/ha/masakari.py | 13 ++--- masakarimonitors/hacking/checks.py | 15 ++++++ masakarimonitors/hostmonitor/host.py | 6 +-- .../hostmonitor/host_handler/handle_host.py | 48 +++++++++---------- .../hostmonitor/host_handler/parse_cib_xml.py | 10 ++-- masakarimonitors/i18n.py | 10 ---- masakarimonitors/instancemonitor/instance.py | 5 +- .../libvirt_handler/callback.py | 21 ++++---- masakarimonitors/processmonitor/process.py | 11 ++--- .../process_handler/handle_process.py | 22 ++++----- masakarimonitors/service.py | 8 ++-- masakarimonitors/tests/unit/test_hacking.py | 18 ++++++- masakarimonitors/utils.py | 4 +- masakarimonitors/version.py | 4 +- tox.ini | 2 +- 17 files changed, 102 insertions(+), 104 deletions(-) diff --git a/HACKING.rst b/HACKING.rst index 0f1b933..78f2640 100644 --- a/HACKING.rst +++ b/HACKING.rst @@ -7,3 +7,4 @@ masakari-monitors Specific Commandments ------------------------------ - [M301] Ensure that the _() function is explicitly imported to ensure proper translations. +- [M302] Validate that log messages are not translated. diff --git a/masakarimonitors/conf/opts.py b/masakarimonitors/conf/opts.py index 032452e..976847c 100644 --- a/masakarimonitors/conf/opts.py +++ b/masakarimonitors/conf/opts.py @@ -61,11 +61,9 @@ def _import_modules(module_names): for modname in module_names: mod = importlib.import_module("masakarimonitors.conf." + modname) if not hasattr(mod, LIST_OPTS_FUNC_NAME): - msg = (_("The module 'masakarimonitors.conf.%(modname)s'" - " should have a '%(function)s' function" - " which returns the config options.") % { - 'modname': modname, - 'function': LIST_OPTS_FUNC_NAME}) + msg = "The module 'masakarimonitors.conf.%s' should have a" \ + " '%s' function which returns the config options." % \ + (modname, LIST_OPTS_FUNC_NAME) raise Exception(msg) else: imported_modules.append(mod) diff --git a/masakarimonitors/ha/masakari.py b/masakarimonitors/ha/masakari.py index d4bbf3b..7807e49 100644 --- a/masakarimonitors/ha/masakari.py +++ b/masakarimonitors/ha/masakari.py @@ -20,9 +20,6 @@ from oslo_log import log as oslo_logging from masakariclient.sdk.ha import ha_service import masakarimonitors.conf -from masakarimonitors.i18n import _LE -from masakarimonitors.i18n import _LI -from masakarimonitors.i18n import _LW LOG = oslo_logging.getLogger(__name__) CONF = masakarimonitors.conf.CONF @@ -69,7 +66,7 @@ class SendNotification(object): :param event: dictionary of event that included in notification. """ - LOG.info(_LI("Send a notification. %s"), event) + LOG.info("Send a notification. %s", event) # Get connection. conn = self._get_connection( @@ -93,7 +90,7 @@ class SendNotification(object): generated_time=event['notification']['generated_time'], payload=event['notification']['payload']) - LOG.info(_LI("Response: %s"), response) + LOG.info("Response: %s", response) break except Exception as e: @@ -102,13 +99,13 @@ class SendNotification(object): if e.http_status == 409: msg = ("Stop retrying to send a notification because " "same notification have been already sent.") - LOG.info(_LI("%s"), msg) + LOG.info("%s", msg) break if retry_count < api_retry_max: - LOG.warning(_LW("Retry sending a notification. (%s)"), e) + LOG.warning("Retry sending a notification. (%s)", e) retry_count = retry_count + 1 eventlet.greenthread.sleep(api_retry_interval) else: - LOG.exception(_LE("Exception caught: %s"), e) + LOG.exception("Exception caught: %s", e) break diff --git a/masakarimonitors/hacking/checks.py b/masakarimonitors/hacking/checks.py index ec03267..43cfd6b 100644 --- a/masakarimonitors/hacking/checks.py +++ b/masakarimonitors/hacking/checks.py @@ -41,6 +41,12 @@ underscore_import_check = re.compile(r"(.)*import _(.)*") underscore_import_check_multi = re.compile(r"(.)*i18n\s+import(.)* _, (.)*") # We need this for cases where they have created their own _ function. custom_underscore_check = re.compile(r"(.)*_\s*=\s*(.)*") +log_translation = re.compile( + r"(.)*LOG\." + r"(audit|debug|error|info|warn|warning|critical|exception)" + r"\(" + r"(_|_LC|_LE|_LI|_LW)" + r"\(") def check_explicit_underscore_import(logical_line, filename): @@ -66,5 +72,14 @@ def check_explicit_underscore_import(logical_line, filename): yield(0, "M301: Found use of _() without explicit import of _ !") +def no_translate_logs(logical_line): + """Check that logging doesn't translate messages + M302 + """ + if log_translation.match(logical_line): + yield(0, "M302 Don't translate log messages!") + + def factory(register): register(check_explicit_underscore_import) + register(no_translate_logs) diff --git a/masakarimonitors/hostmonitor/host.py b/masakarimonitors/hostmonitor/host.py index f78ac67..c006777 100644 --- a/masakarimonitors/hostmonitor/host.py +++ b/masakarimonitors/hostmonitor/host.py @@ -18,7 +18,6 @@ from stevedore import driver from oslo_log import log as oslo_logging import masakarimonitors.conf -from masakarimonitors.i18n import _LE from masakarimonitors import manager LOG = oslo_logging.getLogger(__name__) @@ -48,8 +47,7 @@ class HostmonitorManager(manager.Manager): ) except Exception as e: LOG.exception( - _LE("Exception caught during initializing hostmonitor: %s"), - e) + "Exception caught during initializing hostmonitor: %s", e) os._exit(1) def stop(self): @@ -63,6 +61,6 @@ class HostmonitorManager(manager.Manager): self.driver.driver.monitor_hosts() except Exception as e: - LOG.exception(_LE("Exception caught: %s"), e) + LOG.exception("Exception caught: %s", e) return diff --git a/masakarimonitors/hostmonitor/host_handler/handle_host.py b/masakarimonitors/hostmonitor/host_handler/handle_host.py index ac6e77f..974b6bd 100644 --- a/masakarimonitors/hostmonitor/host_handler/handle_host.py +++ b/masakarimonitors/hostmonitor/host_handler/handle_host.py @@ -23,9 +23,6 @@ from masakarimonitors.ha import masakari import masakarimonitors.hostmonitor.host_handler.driver as driver from masakarimonitors.hostmonitor.host_handler import hold_host_status from masakarimonitors.hostmonitor.host_handler import parse_cib_xml -from masakarimonitors.i18n import _LE -from masakarimonitors.i18n import _LI -from masakarimonitors.i18n import _LW from masakarimonitors.objects import event_constants as ec from masakarimonitors import utils @@ -77,10 +74,10 @@ class HandleHost(driver.DriverBase): if corosync_status is False or pacemaker_status is False: if pacemaker_remote_status is False: LOG.error( - _LE("Neither pacemaker nor pacemaker-remote is running.")) + "Neither pacemaker nor pacemaker-remote is running.") return 2 else: - LOG.info(_LI("Works on pacemaker-remote.")) + LOG.info("Works on pacemaker-remote.") return 0 # Check whether the neccesary parameters are set. @@ -88,7 +85,7 @@ class HandleHost(driver.DriverBase): CONF.host.corosync_multicast_ports is None: msg = ("corosync_multicast_interfaces or " "corosync_multicast_ports is not set.") - LOG.error(_LE("%s"), msg) + LOG.error("%s", msg) return 2 # Check whether the corosync communication is normal. @@ -100,7 +97,7 @@ class HandleHost(driver.DriverBase): if len(corosync_multicast_interfaces) != len(corosync_multicast_ports): msg = ("Incorrect parameters corosync_multicast_interfaces or " "corosync_multicast_ports.") - LOG.error(_LE("%s"), msg) + LOG.error("%s", msg) return 2 is_nic_normal = False @@ -118,16 +115,16 @@ class HandleHost(driver.DriverBase): # If command doesn't raise exception, nic is normal. msg = ("Corosync communication using '%s' is normal.") \ % corosync_multicast_interfaces[num] - LOG.info(_LI("%s"), msg) + LOG.info("%s", msg) is_nic_normal = True break except Exception: msg = ("Corosync communication using '%s' is failed.") \ % corosync_multicast_interfaces[num] - LOG.warning(_LW("%s"), msg) + LOG.warning("%s", msg) if is_nic_normal is False: - LOG.error(_LE("Corosync communication is failed.")) + LOG.error("Corosync communication is failed.") return 1 return 0 @@ -151,8 +148,8 @@ class HandleHost(driver.DriverBase): "crmadmin command output unexpected host status.") except Exception as e: - LOG.warning(_LW("Exception caught: %s"), e) - LOG.warning(_LW("'%s' is unstable state on cluster."), + LOG.warning("Exception caught: %s", e) + LOG.warning("'%s' is unstable state on cluster.", self.my_hostname) return 1 @@ -166,7 +163,7 @@ class HandleHost(driver.DriverBase): raise Exception(msg) except Exception as e: - LOG.warning(_LW("Exception caught: %s"), e) + LOG.warning("Exception caught: %s", e) return return out @@ -174,7 +171,7 @@ class HandleHost(driver.DriverBase): def _is_poweroff(self, hostname): ipmi_values = self.xml_parser.get_stonith_ipmi_params(hostname) if ipmi_values is None: - LOG.error(_LE("Failed to get params of ipmi RA.")) + LOG.error("Failed to get params of ipmi RA.") return False cmd_str = ("timeout %s ipmitool -U %s -P %s -I %s -H %s " @@ -197,19 +194,18 @@ class HandleHost(driver.DriverBase): msg = ("ipmitool command output stdout: %s") % out if 'Power is off' in out: - LOG.info(_LI("%s"), msg) + LOG.info("%s", msg) return True else: raise Exception(msg) except Exception as e: if retry_count < CONF.host.ipmi_retry_max: - LOG.warning(_LW("Retry executing ipmitool command. (%s)"), - e) + LOG.warning("Retry executing ipmitool command. (%s)", e) retry_count = retry_count + 1 eventlet.greenthread.sleep(CONF.host.ipmi_retry_interval) else: - LOG.error(_LE("Exception caught: %s"), e) + LOG.error("Exception caught: %s", e) return False def _make_event(self, hostname, current_status): @@ -271,14 +267,14 @@ class HandleHost(driver.DriverBase): msg = ("Recognized '%s' as a new member of cluster." " Host status is '%s'.") \ % (node_state_tag.get('uname'), current_status) - LOG.info(_LI("%s"), msg) + LOG.info("%s", msg) self.status_holder.set_host_status(node_state_tag) continue # Output host status. msg = ("'%s' is '%s'.") % (node_state_tag.get('uname'), current_status) - LOG.info(_LI("%s"), msg) + LOG.info("%s", msg) # If host status changed, send a notification. if current_status != old_status: @@ -288,7 +284,7 @@ class HandleHost(driver.DriverBase): msg = ("Since host status is '%s'," " hostmonitor doesn't send a notification.") \ % current_status - LOG.info(_LI("%s"), msg) + LOG.info("%s", msg) else: event = self._make_event(node_state_tag.get('uname'), current_status) @@ -315,7 +311,7 @@ class HandleHost(driver.DriverBase): # Check if pacemaker cluster have quorum. if self.xml_parser.have_quorum() == 0: msg = "Pacemaker cluster doesn't have quorum." - LOG.warning(_LW("%s"), msg) + LOG.warning("%s", msg) # Get node_state tag list. node_state_tag_list = self.xml_parser.get_node_state_tag_list() @@ -350,7 +346,7 @@ class HandleHost(driver.DriverBase): # brain condition, sleep for a certain time. eventlet.greenthread.sleep(CONF.host.stonith_wait) elif ret == 2: - LOG.warning(_LW("hostmonitor skips monitoring hosts.")) + LOG.warning("hostmonitor skips monitoring hosts.") eventlet.greenthread.sleep(CONF.host.monitoring_interval) continue @@ -361,20 +357,20 @@ class HandleHost(driver.DriverBase): 'pacemaker_remote') if pacemaker_remote_status is False: if self._check_host_status_by_crmadmin() != 0: - LOG.warning(_LW("hostmonitor skips monitoring hosts.")) + LOG.warning("hostmonitor skips monitoring hosts.") eventlet.greenthread.sleep( CONF.host.monitoring_interval) continue # Check the host status is online or offline by cibadmin. if self._check_host_status_by_cibadmin() != 0: - LOG.warning(_LW("hostmonitor skips monitoring hosts.")) + LOG.warning("hostmonitor skips monitoring hosts.") eventlet.greenthread.sleep(CONF.host.monitoring_interval) continue eventlet.greenthread.sleep(CONF.host.monitoring_interval) except Exception as e: - LOG.exception(_LE("Exception caught: %s"), e) + LOG.exception("Exception caught: %s", e) return diff --git a/masakarimonitors/hostmonitor/host_handler/parse_cib_xml.py b/masakarimonitors/hostmonitor/host_handler/parse_cib_xml.py index 6717aa5..83d9d43 100644 --- a/masakarimonitors/hostmonitor/host_handler/parse_cib_xml.py +++ b/masakarimonitors/hostmonitor/host_handler/parse_cib_xml.py @@ -16,8 +16,6 @@ from xml.etree import ElementTree from oslo_log import log as oslo_logging -from masakarimonitors.i18n import _LE - LOG = oslo_logging.getLogger(__name__) @@ -77,13 +75,13 @@ class ParseCibXml(object): # Get status tag. status_tag = self._get_status_tag() if status_tag is None: - LOG.error(_LE("Cib xml doesn't have status tag.")) + LOG.error("Cib xml doesn't have status tag.") return [] # Get node_state tag list. node_state_tag_list = self._get_node_states(status_tag) if len(node_state_tag_list) == 0: - LOG.error(_LE("Cib xml doesn't have node_state tag.")) + LOG.error("Cib xml doesn't have node_state tag.") return node_state_tag_list @@ -157,7 +155,7 @@ class ParseCibXml(object): configuration_tag = child break if configuration_tag is None: - LOG.error(_LE("Cib xml doesn't have configuration tag.")) + LOG.error("Cib xml doesn't have configuration tag.") return None # Get resources tag from configuration tag. @@ -168,7 +166,7 @@ class ParseCibXml(object): resources_tag = child break if resources_tag is None: - LOG.error(_LE("Cib xml doesn't have resources tag.")) + LOG.error("Cib xml doesn't have resources tag.") return None # They are set at nvpair tag which exists under the diff --git a/masakarimonitors/i18n.py b/masakarimonitors/i18n.py index 5dee692..16232b6 100644 --- a/masakarimonitors/i18n.py +++ b/masakarimonitors/i18n.py @@ -20,16 +20,6 @@ _translators = oslo_i18n.TranslatorFactory(domain=DOMAIN) # The primary translation function using the well-known name "_" _ = _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 translate(value, user_locale): return oslo_i18n.translate(value, user_locale) diff --git a/masakarimonitors/instancemonitor/instance.py b/masakarimonitors/instancemonitor/instance.py index a06429d..479ee87 100644 --- a/masakarimonitors/instancemonitor/instance.py +++ b/masakarimonitors/instancemonitor/instance.py @@ -19,7 +19,6 @@ import eventlet import libvirt from oslo_log import log as oslo_logging -from masakarimonitors.i18n import _LW from masakarimonitors.instancemonitor.libvirt_handler import eventfilter from masakarimonitors import manager @@ -95,7 +94,7 @@ class InstancemonitorManager(manager.Manager): -1, -1, dom.UUIDString()) def _err_handler(self, ctxt, err): - LOG.warning(_LW("Error from libvirt : %s"), err[2]) + LOG.warning("Error from libvirt : %s", err[2]) def _virt_event(self, uri): # Run a background thread with the event loop @@ -139,7 +138,7 @@ class InstancemonitorManager(manager.Manager): # If connection between libvirtd was lost, # clear callback connection. - LOG.warning(_LW("Libvirt Connection Closed Unexpectedly.")) + LOG.warning("Libvirt Connection Closed Unexpectedly.") for cid in callback_ids: try: vc.domainEventDeregisterAny(cid) diff --git a/masakarimonitors/instancemonitor/libvirt_handler/callback.py b/masakarimonitors/instancemonitor/libvirt_handler/callback.py index 25d7237..1d49171 100644 --- a/masakarimonitors/instancemonitor/libvirt_handler/callback.py +++ b/masakarimonitors/instancemonitor/libvirt_handler/callback.py @@ -16,7 +16,6 @@ from oslo_log import log as oslo_logging import masakarimonitors.conf from masakarimonitors.ha import masakari -from masakarimonitors.i18n import _LI LOG = oslo_logging.getLogger(__name__) @@ -47,16 +46,16 @@ class Callback(object): """ # Output to the syslog. - LOG.info(_LI("Libvirt Event: type=%(notice_type)s," - " hostname=%(hostname)s," - " uuid=%(uuid)s, time=%(current_time)s," - " event_id=%(event_id)s," - " detail=%(detail)s)") % {'notice_type': notice_type, - 'hostname': hostname, - 'uuid': domain_uuid, - 'current_time': current_time, - 'event_id': event_id, - 'detail': details}) + LOG.info("Libvirt Event: type=%(notice_type)s," + " hostname=%(hostname)s," + " uuid=%(uuid)s, time=%(current_time)s," + " event_id=%(event_id)s," + " detail=%(detail)s)" % {'notice_type': notice_type, + 'hostname': hostname, + 'uuid': domain_uuid, + 'current_time': current_time, + 'event_id': event_id, + 'detail': details}) # Set the event to the dictionary. event = { diff --git a/masakarimonitors/processmonitor/process.py b/masakarimonitors/processmonitor/process.py index 74652c9..66e03bb 100644 --- a/masakarimonitors/processmonitor/process.py +++ b/masakarimonitors/processmonitor/process.py @@ -18,7 +18,6 @@ import eventlet from oslo_log import log as oslo_logging import masakarimonitors.conf -from masakarimonitors.i18n import _LE from masakarimonitors import manager from masakarimonitors.processmonitor.process_handler import handle_process @@ -41,10 +40,10 @@ class ProcessmonitorManager(manager.Manager): return process_list except yaml.YAMLError as e: - LOG.exception(_LE("YAMLError caught: %s"), e) + LOG.exception("YAMLError caught: %s", e) return except Exception as e: - LOG.exception(_LE("Exception caught: %s"), e) + LOG.exception("Exception caught: %s", e) return def stop(self): @@ -57,7 +56,7 @@ class ProcessmonitorManager(manager.Manager): # Load process list. process_list = self._load_process_list() if process_list is None: - LOG.error(_LE("Failed to load process list file.")) + LOG.error("Failed to load process list file.") return # Set process_list object to the process handler. @@ -81,14 +80,14 @@ class ProcessmonitorManager(manager.Manager): # Reload process list and set to the process handler. process_list = self._load_process_list() if process_list is None: - LOG.error(_LE("Failed to reload process list file.")) + LOG.error("Failed to reload process list file.") break self.process_handler.set_process_list(process_list) eventlet.greenthread.sleep(CONF.process.check_interval) except Exception as e: - LOG.exception(_LE("Exception caught: %s"), e) + LOG.exception("Exception caught: %s", e) return return diff --git a/masakarimonitors/processmonitor/process_handler/handle_process.py b/masakarimonitors/processmonitor/process_handler/handle_process.py index 6243d6f..04217e0 100644 --- a/masakarimonitors/processmonitor/process_handler/handle_process.py +++ b/masakarimonitors/processmonitor/process_handler/handle_process.py @@ -20,9 +20,6 @@ from oslo_utils import timeutils import masakarimonitors.conf from masakarimonitors.ha import masakari -from masakarimonitors.i18n import _LE -from masakarimonitors.i18n import _LI -from masakarimonitors.i18n import _LW from masakarimonitors.objects import event_constants as ec from masakarimonitors import utils @@ -58,16 +55,16 @@ class HandleProcess(object): if out: msg = ("CMD '%s' output stdout: %s") % (cmd_str, out) - LOG.info(_LI("%s"), msg) + LOG.info("%s", msg) if err: msg = ("CMD '%s' output stderr: %s") % (cmd_str, err) - LOG.warning(_LW("%s"), msg) + LOG.warning("%s", msg) return 1 except Exception as e: msg = ("CMD '%s' raised exception: %s") % (cmd_str, e) - LOG.error(_LE("%s"), e) + LOG.error("%s", e) return 1 return 0 @@ -90,8 +87,7 @@ class HandleProcess(object): continue # Execute start command. - LOG.info( - _LI("Start of process with executing command: %s"), cmd_str) + LOG.info("Start of process with executing command: %s", cmd_str) self._execute_cmd(cmd_str, process['run_as_root']) # Execute post start command. @@ -118,10 +114,9 @@ class HandleProcess(object): else: # Append down_process_list. down_process_list.append(process) - LOG.warning( - _LW("Process '%s' is not found."), process_name) + LOG.warning("Process '%s' is not found.", process_name) except Exception as e: - LOG.error(_LW("Monitoring command raised exception: %s"), e) + LOG.error("Monitoring command raised exception: %s", e) return down_process_list @@ -157,7 +152,7 @@ class HandleProcess(object): if down_process['process_name'] in self.restart_failure_list: msg = "Process '%s' doesn't be restarted because it failed" \ " to restart previously." % down_process['process_name'] - LOG.warning(_LW("%s"), msg) + LOG.warning("%s", msg) tmp_restart_failure_list.append(down_process['process_name']) continue @@ -165,8 +160,7 @@ class HandleProcess(object): pre_cmd_str = down_process['pre_restart_command'] post_cmd_str = down_process['post_restart_command'] - LOG.info( - _LI("Restart of process with executing command: %s"), cmd_str) + LOG.info("Restart of process with executing command: %s", cmd_str) for retries in range(0, CONF.process.restart_retries + 1): diff --git a/masakarimonitors/service.py b/masakarimonitors/service.py index fd5f138..e6ef132 100644 --- a/masakarimonitors/service.py +++ b/masakarimonitors/service.py @@ -22,7 +22,7 @@ from oslo_service import service from oslo_utils import importutils import masakarimonitors.conf -from masakarimonitors.i18n import _, _LE, _LI +from masakarimonitors.i18n import _ from masakarimonitors import utils @@ -56,7 +56,7 @@ class Service(service.Service): } def start(self): - LOG.info(_LI('Starting %s'), self.binary) + LOG.info('Starting %s', self.binary) self.basic_config_check() self.manager.init_host() self.manager.main() @@ -99,7 +99,7 @@ class Service(service.Service): self.stop() def stop(self): - LOG.info(_LI('Stopping %s'), self.binary) + LOG.info('Stopping %s', self.binary) self.manager.stop() super(Service, self).stop() @@ -110,7 +110,7 @@ class Service(service.Service): with utils.tempdir(): pass except Exception as e: - LOG.error(_LE('Temporary directory is invalid: %s'), e) + LOG.error('Temporary directory is invalid: %s', e) sys.exit(1) def reset(self): diff --git a/masakarimonitors/tests/unit/test_hacking.py b/masakarimonitors/tests/unit/test_hacking.py index 5dee83d..bb69106 100644 --- a/masakarimonitors/tests/unit/test_hacking.py +++ b/masakarimonitors/tests/unit/test_hacking.py @@ -66,7 +66,7 @@ class HackingTestCase(testtools.TestCase): "msg = _('My message')", "masakarimonitors/tests/other_files.py"))), 0) self.assertEqual(len(list(checks.check_explicit_underscore_import( - "from masakarimonitors.i18n import _, _LW", + "from masakarimonitors.i18n import _", "masakarimonitors/tests/other_files2.py"))), 0) self.assertEqual(len(list(checks.check_explicit_underscore_import( "msg = _('My message')", @@ -77,3 +77,19 @@ class HackingTestCase(testtools.TestCase): self.assertEqual(len(list(checks.check_explicit_underscore_import( "msg = _('My message')", "masakarimonitors/tests/other_files3.py"))), 0) + + def test_no_translate_logs(self): + self.assertEqual(1, len(list(checks.no_translate_logs( + "LOG.error(_LE('foo'))")))) + + self.assertEqual(0, len(list(checks.no_translate_logs( + "LOG.debug('foo')")))) + + self.assertEqual(1, len(list(checks.no_translate_logs( + "LOG.info(_LI('foo'))")))) + + self.assertEqual(1, len(list(checks.no_translate_logs( + "LOG.warning(_LW('foo'))")))) + + self.assertEqual(1, len(list(checks.no_translate_logs( + "LOG.critical(_LC('foo'))")))) diff --git a/masakarimonitors/utils.py b/masakarimonitors/utils.py index e9a8bdf..c1dd725 100644 --- a/masakarimonitors/utils.py +++ b/masakarimonitors/utils.py @@ -27,7 +27,7 @@ from oslo_utils import importutils import six import masakarimonitors.conf -from masakarimonitors.i18n import _, _LE +from masakarimonitors.i18n import _ from masakarimonitors import privsep @@ -97,7 +97,7 @@ def tempdir(**kwargs): try: shutil.rmtree(tmpdir) except OSError as e: - LOG.error(_LE('Could not remove tmpdir: %s'), e) + LOG.error('Could not remove tmpdir: %s', e) @privsep.monitors_priv.entrypoint diff --git a/masakarimonitors/version.py b/masakarimonitors/version.py index e356604..bd74a26 100644 --- a/masakarimonitors/version.py +++ b/masakarimonitors/version.py @@ -14,8 +14,6 @@ from pbr import version as pbr_version -from masakarimonitors.i18n import _LE - MONITORS_VENDOR = "OpenStack Foundation" MONITORS_PRODUCT = "OpenStack Masakari Monitors" MONITORS_PACKAGE = None # OS distro package version suffix @@ -59,7 +57,7 @@ def _load_config(): MONITORS_PACKAGE = cfg.get("Masakarimonitors", "package") except Exception as ex: LOG = logging.getLogger(__name__) - LOG.error(_LE("Failed to load %(cfgfile)s: %(ex)s"), + LOG.error("Failed to load %(cfgfile)s: %(ex)s", {'cfgfile': cfgfile, 'ex': ex}) diff --git a/tox.ini b/tox.ini index a3bd124..f52d5c6 100644 --- a/tox.ini +++ b/tox.ini @@ -48,4 +48,4 @@ exclude=.venv,.git,.tox,dist,doc,*lib/python*,*egg,build [hacking] import_exceptions = masakarimonitors.i18n - +local-check-factory = masakarimonitors.hacking.checks.factory