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
This commit is contained in:
parent
dbd53c13a7
commit
0cdbbf669d
@ -7,3 +7,4 @@ masakari-monitors Specific Commandments
|
|||||||
------------------------------
|
------------------------------
|
||||||
|
|
||||||
- [M301] Ensure that the _() function is explicitly imported to ensure proper translations.
|
- [M301] Ensure that the _() function is explicitly imported to ensure proper translations.
|
||||||
|
- [M302] Validate that log messages are not translated.
|
||||||
|
@ -61,11 +61,9 @@ def _import_modules(module_names):
|
|||||||
for modname in module_names:
|
for modname in module_names:
|
||||||
mod = importlib.import_module("masakarimonitors.conf." + modname)
|
mod = importlib.import_module("masakarimonitors.conf." + modname)
|
||||||
if not hasattr(mod, LIST_OPTS_FUNC_NAME):
|
if not hasattr(mod, LIST_OPTS_FUNC_NAME):
|
||||||
msg = (_("The module 'masakarimonitors.conf.%(modname)s'"
|
msg = "The module 'masakarimonitors.conf.%s' should have a" \
|
||||||
" should have a '%(function)s' function"
|
" '%s' function which returns the config options." % \
|
||||||
" which returns the config options.") % {
|
(modname, LIST_OPTS_FUNC_NAME)
|
||||||
'modname': modname,
|
|
||||||
'function': LIST_OPTS_FUNC_NAME})
|
|
||||||
raise Exception(msg)
|
raise Exception(msg)
|
||||||
else:
|
else:
|
||||||
imported_modules.append(mod)
|
imported_modules.append(mod)
|
||||||
|
@ -20,9 +20,6 @@ from oslo_log import log as oslo_logging
|
|||||||
|
|
||||||
from masakariclient.sdk.ha import ha_service
|
from masakariclient.sdk.ha import ha_service
|
||||||
import masakarimonitors.conf
|
import masakarimonitors.conf
|
||||||
from masakarimonitors.i18n import _LE
|
|
||||||
from masakarimonitors.i18n import _LI
|
|
||||||
from masakarimonitors.i18n import _LW
|
|
||||||
|
|
||||||
LOG = oslo_logging.getLogger(__name__)
|
LOG = oslo_logging.getLogger(__name__)
|
||||||
CONF = masakarimonitors.conf.CONF
|
CONF = masakarimonitors.conf.CONF
|
||||||
@ -69,7 +66,7 @@ class SendNotification(object):
|
|||||||
:param event: dictionary of event that included in notification.
|
: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.
|
# Get connection.
|
||||||
conn = self._get_connection(
|
conn = self._get_connection(
|
||||||
@ -93,7 +90,7 @@ class SendNotification(object):
|
|||||||
generated_time=event['notification']['generated_time'],
|
generated_time=event['notification']['generated_time'],
|
||||||
payload=event['notification']['payload'])
|
payload=event['notification']['payload'])
|
||||||
|
|
||||||
LOG.info(_LI("Response: %s"), response)
|
LOG.info("Response: %s", response)
|
||||||
break
|
break
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@ -102,13 +99,13 @@ class SendNotification(object):
|
|||||||
if e.http_status == 409:
|
if e.http_status == 409:
|
||||||
msg = ("Stop retrying to send a notification because "
|
msg = ("Stop retrying to send a notification because "
|
||||||
"same notification have been already sent.")
|
"same notification have been already sent.")
|
||||||
LOG.info(_LI("%s"), msg)
|
LOG.info("%s", msg)
|
||||||
break
|
break
|
||||||
|
|
||||||
if retry_count < api_retry_max:
|
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
|
retry_count = retry_count + 1
|
||||||
eventlet.greenthread.sleep(api_retry_interval)
|
eventlet.greenthread.sleep(api_retry_interval)
|
||||||
else:
|
else:
|
||||||
LOG.exception(_LE("Exception caught: %s"), e)
|
LOG.exception("Exception caught: %s", e)
|
||||||
break
|
break
|
||||||
|
@ -41,6 +41,12 @@ underscore_import_check = re.compile(r"(.)*import _(.)*")
|
|||||||
underscore_import_check_multi = re.compile(r"(.)*i18n\s+import(.)* _, (.)*")
|
underscore_import_check_multi = re.compile(r"(.)*i18n\s+import(.)* _, (.)*")
|
||||||
# We need this for cases where they have created their own _ function.
|
# We need this for cases where they have created their own _ function.
|
||||||
custom_underscore_check = re.compile(r"(.)*_\s*=\s*(.)*")
|
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):
|
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 _ !")
|
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):
|
def factory(register):
|
||||||
register(check_explicit_underscore_import)
|
register(check_explicit_underscore_import)
|
||||||
|
register(no_translate_logs)
|
||||||
|
@ -18,7 +18,6 @@ from stevedore import driver
|
|||||||
from oslo_log import log as oslo_logging
|
from oslo_log import log as oslo_logging
|
||||||
|
|
||||||
import masakarimonitors.conf
|
import masakarimonitors.conf
|
||||||
from masakarimonitors.i18n import _LE
|
|
||||||
from masakarimonitors import manager
|
from masakarimonitors import manager
|
||||||
|
|
||||||
LOG = oslo_logging.getLogger(__name__)
|
LOG = oslo_logging.getLogger(__name__)
|
||||||
@ -48,8 +47,7 @@ class HostmonitorManager(manager.Manager):
|
|||||||
)
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
LOG.exception(
|
LOG.exception(
|
||||||
_LE("Exception caught during initializing hostmonitor: %s"),
|
"Exception caught during initializing hostmonitor: %s", e)
|
||||||
e)
|
|
||||||
os._exit(1)
|
os._exit(1)
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
@ -63,6 +61,6 @@ class HostmonitorManager(manager.Manager):
|
|||||||
self.driver.driver.monitor_hosts()
|
self.driver.driver.monitor_hosts()
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
LOG.exception(_LE("Exception caught: %s"), e)
|
LOG.exception("Exception caught: %s", e)
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -23,9 +23,6 @@ from masakarimonitors.ha import masakari
|
|||||||
import masakarimonitors.hostmonitor.host_handler.driver as driver
|
import masakarimonitors.hostmonitor.host_handler.driver as driver
|
||||||
from masakarimonitors.hostmonitor.host_handler import hold_host_status
|
from masakarimonitors.hostmonitor.host_handler import hold_host_status
|
||||||
from masakarimonitors.hostmonitor.host_handler import parse_cib_xml
|
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.objects import event_constants as ec
|
||||||
from masakarimonitors import utils
|
from masakarimonitors import utils
|
||||||
|
|
||||||
@ -77,10 +74,10 @@ class HandleHost(driver.DriverBase):
|
|||||||
if corosync_status is False or pacemaker_status is False:
|
if corosync_status is False or pacemaker_status is False:
|
||||||
if pacemaker_remote_status is False:
|
if pacemaker_remote_status is False:
|
||||||
LOG.error(
|
LOG.error(
|
||||||
_LE("Neither pacemaker nor pacemaker-remote is running."))
|
"Neither pacemaker nor pacemaker-remote is running.")
|
||||||
return 2
|
return 2
|
||||||
else:
|
else:
|
||||||
LOG.info(_LI("Works on pacemaker-remote."))
|
LOG.info("Works on pacemaker-remote.")
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
# Check whether the neccesary parameters are set.
|
# Check whether the neccesary parameters are set.
|
||||||
@ -88,7 +85,7 @@ class HandleHost(driver.DriverBase):
|
|||||||
CONF.host.corosync_multicast_ports is None:
|
CONF.host.corosync_multicast_ports is None:
|
||||||
msg = ("corosync_multicast_interfaces or "
|
msg = ("corosync_multicast_interfaces or "
|
||||||
"corosync_multicast_ports is not set.")
|
"corosync_multicast_ports is not set.")
|
||||||
LOG.error(_LE("%s"), msg)
|
LOG.error("%s", msg)
|
||||||
return 2
|
return 2
|
||||||
|
|
||||||
# Check whether the corosync communication is normal.
|
# Check whether the corosync communication is normal.
|
||||||
@ -100,7 +97,7 @@ class HandleHost(driver.DriverBase):
|
|||||||
if len(corosync_multicast_interfaces) != len(corosync_multicast_ports):
|
if len(corosync_multicast_interfaces) != len(corosync_multicast_ports):
|
||||||
msg = ("Incorrect parameters corosync_multicast_interfaces or "
|
msg = ("Incorrect parameters corosync_multicast_interfaces or "
|
||||||
"corosync_multicast_ports.")
|
"corosync_multicast_ports.")
|
||||||
LOG.error(_LE("%s"), msg)
|
LOG.error("%s", msg)
|
||||||
return 2
|
return 2
|
||||||
|
|
||||||
is_nic_normal = False
|
is_nic_normal = False
|
||||||
@ -118,16 +115,16 @@ class HandleHost(driver.DriverBase):
|
|||||||
# If command doesn't raise exception, nic is normal.
|
# If command doesn't raise exception, nic is normal.
|
||||||
msg = ("Corosync communication using '%s' is normal.") \
|
msg = ("Corosync communication using '%s' is normal.") \
|
||||||
% corosync_multicast_interfaces[num]
|
% corosync_multicast_interfaces[num]
|
||||||
LOG.info(_LI("%s"), msg)
|
LOG.info("%s", msg)
|
||||||
is_nic_normal = True
|
is_nic_normal = True
|
||||||
break
|
break
|
||||||
except Exception:
|
except Exception:
|
||||||
msg = ("Corosync communication using '%s' is failed.") \
|
msg = ("Corosync communication using '%s' is failed.") \
|
||||||
% corosync_multicast_interfaces[num]
|
% corosync_multicast_interfaces[num]
|
||||||
LOG.warning(_LW("%s"), msg)
|
LOG.warning("%s", msg)
|
||||||
|
|
||||||
if is_nic_normal is False:
|
if is_nic_normal is False:
|
||||||
LOG.error(_LE("Corosync communication is failed."))
|
LOG.error("Corosync communication is failed.")
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
@ -151,8 +148,8 @@ class HandleHost(driver.DriverBase):
|
|||||||
"crmadmin command output unexpected host status.")
|
"crmadmin command output unexpected host status.")
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
LOG.warning(_LW("Exception caught: %s"), e)
|
LOG.warning("Exception caught: %s", e)
|
||||||
LOG.warning(_LW("'%s' is unstable state on cluster."),
|
LOG.warning("'%s' is unstable state on cluster.",
|
||||||
self.my_hostname)
|
self.my_hostname)
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
@ -166,7 +163,7 @@ class HandleHost(driver.DriverBase):
|
|||||||
raise Exception(msg)
|
raise Exception(msg)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
LOG.warning(_LW("Exception caught: %s"), e)
|
LOG.warning("Exception caught: %s", e)
|
||||||
return
|
return
|
||||||
|
|
||||||
return out
|
return out
|
||||||
@ -174,7 +171,7 @@ class HandleHost(driver.DriverBase):
|
|||||||
def _is_poweroff(self, hostname):
|
def _is_poweroff(self, hostname):
|
||||||
ipmi_values = self.xml_parser.get_stonith_ipmi_params(hostname)
|
ipmi_values = self.xml_parser.get_stonith_ipmi_params(hostname)
|
||||||
if ipmi_values is None:
|
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
|
return False
|
||||||
|
|
||||||
cmd_str = ("timeout %s ipmitool -U %s -P %s -I %s -H %s "
|
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
|
msg = ("ipmitool command output stdout: %s") % out
|
||||||
|
|
||||||
if 'Power is off' in out:
|
if 'Power is off' in out:
|
||||||
LOG.info(_LI("%s"), msg)
|
LOG.info("%s", msg)
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
raise Exception(msg)
|
raise Exception(msg)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if retry_count < CONF.host.ipmi_retry_max:
|
if retry_count < CONF.host.ipmi_retry_max:
|
||||||
LOG.warning(_LW("Retry executing ipmitool command. (%s)"),
|
LOG.warning("Retry executing ipmitool command. (%s)", e)
|
||||||
e)
|
|
||||||
retry_count = retry_count + 1
|
retry_count = retry_count + 1
|
||||||
eventlet.greenthread.sleep(CONF.host.ipmi_retry_interval)
|
eventlet.greenthread.sleep(CONF.host.ipmi_retry_interval)
|
||||||
else:
|
else:
|
||||||
LOG.error(_LE("Exception caught: %s"), e)
|
LOG.error("Exception caught: %s", e)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def _make_event(self, hostname, current_status):
|
def _make_event(self, hostname, current_status):
|
||||||
@ -271,14 +267,14 @@ class HandleHost(driver.DriverBase):
|
|||||||
msg = ("Recognized '%s' as a new member of cluster."
|
msg = ("Recognized '%s' as a new member of cluster."
|
||||||
" Host status is '%s'.") \
|
" Host status is '%s'.") \
|
||||||
% (node_state_tag.get('uname'), current_status)
|
% (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)
|
self.status_holder.set_host_status(node_state_tag)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# Output host status.
|
# Output host status.
|
||||||
msg = ("'%s' is '%s'.") % (node_state_tag.get('uname'),
|
msg = ("'%s' is '%s'.") % (node_state_tag.get('uname'),
|
||||||
current_status)
|
current_status)
|
||||||
LOG.info(_LI("%s"), msg)
|
LOG.info("%s", msg)
|
||||||
|
|
||||||
# If host status changed, send a notification.
|
# If host status changed, send a notification.
|
||||||
if current_status != old_status:
|
if current_status != old_status:
|
||||||
@ -288,7 +284,7 @@ class HandleHost(driver.DriverBase):
|
|||||||
msg = ("Since host status is '%s',"
|
msg = ("Since host status is '%s',"
|
||||||
" hostmonitor doesn't send a notification.") \
|
" hostmonitor doesn't send a notification.") \
|
||||||
% current_status
|
% current_status
|
||||||
LOG.info(_LI("%s"), msg)
|
LOG.info("%s", msg)
|
||||||
else:
|
else:
|
||||||
event = self._make_event(node_state_tag.get('uname'),
|
event = self._make_event(node_state_tag.get('uname'),
|
||||||
current_status)
|
current_status)
|
||||||
@ -315,7 +311,7 @@ class HandleHost(driver.DriverBase):
|
|||||||
# Check if pacemaker cluster have quorum.
|
# Check if pacemaker cluster have quorum.
|
||||||
if self.xml_parser.have_quorum() == 0:
|
if self.xml_parser.have_quorum() == 0:
|
||||||
msg = "Pacemaker cluster doesn't have quorum."
|
msg = "Pacemaker cluster doesn't have quorum."
|
||||||
LOG.warning(_LW("%s"), msg)
|
LOG.warning("%s", msg)
|
||||||
|
|
||||||
# Get node_state tag list.
|
# Get node_state tag list.
|
||||||
node_state_tag_list = self.xml_parser.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.
|
# brain condition, sleep for a certain time.
|
||||||
eventlet.greenthread.sleep(CONF.host.stonith_wait)
|
eventlet.greenthread.sleep(CONF.host.stonith_wait)
|
||||||
elif ret == 2:
|
elif ret == 2:
|
||||||
LOG.warning(_LW("hostmonitor skips monitoring hosts."))
|
LOG.warning("hostmonitor skips monitoring hosts.")
|
||||||
eventlet.greenthread.sleep(CONF.host.monitoring_interval)
|
eventlet.greenthread.sleep(CONF.host.monitoring_interval)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
@ -361,20 +357,20 @@ class HandleHost(driver.DriverBase):
|
|||||||
'pacemaker_remote')
|
'pacemaker_remote')
|
||||||
if pacemaker_remote_status is False:
|
if pacemaker_remote_status is False:
|
||||||
if self._check_host_status_by_crmadmin() != 0:
|
if self._check_host_status_by_crmadmin() != 0:
|
||||||
LOG.warning(_LW("hostmonitor skips monitoring hosts."))
|
LOG.warning("hostmonitor skips monitoring hosts.")
|
||||||
eventlet.greenthread.sleep(
|
eventlet.greenthread.sleep(
|
||||||
CONF.host.monitoring_interval)
|
CONF.host.monitoring_interval)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# Check the host status is online or offline by cibadmin.
|
# Check the host status is online or offline by cibadmin.
|
||||||
if self._check_host_status_by_cibadmin() != 0:
|
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)
|
eventlet.greenthread.sleep(CONF.host.monitoring_interval)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
eventlet.greenthread.sleep(CONF.host.monitoring_interval)
|
eventlet.greenthread.sleep(CONF.host.monitoring_interval)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
LOG.exception(_LE("Exception caught: %s"), e)
|
LOG.exception("Exception caught: %s", e)
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -16,8 +16,6 @@ from xml.etree import ElementTree
|
|||||||
|
|
||||||
from oslo_log import log as oslo_logging
|
from oslo_log import log as oslo_logging
|
||||||
|
|
||||||
from masakarimonitors.i18n import _LE
|
|
||||||
|
|
||||||
LOG = oslo_logging.getLogger(__name__)
|
LOG = oslo_logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
@ -77,13 +75,13 @@ class ParseCibXml(object):
|
|||||||
# Get status tag.
|
# Get status tag.
|
||||||
status_tag = self._get_status_tag()
|
status_tag = self._get_status_tag()
|
||||||
if status_tag is None:
|
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 []
|
return []
|
||||||
|
|
||||||
# Get node_state tag list.
|
# Get node_state tag list.
|
||||||
node_state_tag_list = self._get_node_states(status_tag)
|
node_state_tag_list = self._get_node_states(status_tag)
|
||||||
if len(node_state_tag_list) == 0:
|
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
|
return node_state_tag_list
|
||||||
|
|
||||||
@ -157,7 +155,7 @@ class ParseCibXml(object):
|
|||||||
configuration_tag = child
|
configuration_tag = child
|
||||||
break
|
break
|
||||||
if configuration_tag is None:
|
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
|
return None
|
||||||
|
|
||||||
# Get resources tag from configuration tag.
|
# Get resources tag from configuration tag.
|
||||||
@ -168,7 +166,7 @@ class ParseCibXml(object):
|
|||||||
resources_tag = child
|
resources_tag = child
|
||||||
break
|
break
|
||||||
if resources_tag is None:
|
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
|
return None
|
||||||
|
|
||||||
# They are set at nvpair tag which exists under the
|
# They are set at nvpair tag which exists under the
|
||||||
|
@ -20,16 +20,6 @@ _translators = oslo_i18n.TranslatorFactory(domain=DOMAIN)
|
|||||||
# 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 translate(value, user_locale):
|
def translate(value, user_locale):
|
||||||
return oslo_i18n.translate(value, user_locale)
|
return oslo_i18n.translate(value, user_locale)
|
||||||
|
@ -19,7 +19,6 @@ import eventlet
|
|||||||
import libvirt
|
import libvirt
|
||||||
from oslo_log import log as oslo_logging
|
from oslo_log import log as oslo_logging
|
||||||
|
|
||||||
from masakarimonitors.i18n import _LW
|
|
||||||
from masakarimonitors.instancemonitor.libvirt_handler import eventfilter
|
from masakarimonitors.instancemonitor.libvirt_handler import eventfilter
|
||||||
from masakarimonitors import manager
|
from masakarimonitors import manager
|
||||||
|
|
||||||
@ -95,7 +94,7 @@ class InstancemonitorManager(manager.Manager):
|
|||||||
-1, -1, dom.UUIDString())
|
-1, -1, dom.UUIDString())
|
||||||
|
|
||||||
def _err_handler(self, ctxt, err):
|
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):
|
def _virt_event(self, uri):
|
||||||
# Run a background thread with the event loop
|
# Run a background thread with the event loop
|
||||||
@ -139,7 +138,7 @@ class InstancemonitorManager(manager.Manager):
|
|||||||
|
|
||||||
# If connection between libvirtd was lost,
|
# If connection between libvirtd was lost,
|
||||||
# clear callback connection.
|
# clear callback connection.
|
||||||
LOG.warning(_LW("Libvirt Connection Closed Unexpectedly."))
|
LOG.warning("Libvirt Connection Closed Unexpectedly.")
|
||||||
for cid in callback_ids:
|
for cid in callback_ids:
|
||||||
try:
|
try:
|
||||||
vc.domainEventDeregisterAny(cid)
|
vc.domainEventDeregisterAny(cid)
|
||||||
|
@ -16,7 +16,6 @@ from oslo_log import log as oslo_logging
|
|||||||
|
|
||||||
import masakarimonitors.conf
|
import masakarimonitors.conf
|
||||||
from masakarimonitors.ha import masakari
|
from masakarimonitors.ha import masakari
|
||||||
from masakarimonitors.i18n import _LI
|
|
||||||
|
|
||||||
|
|
||||||
LOG = oslo_logging.getLogger(__name__)
|
LOG = oslo_logging.getLogger(__name__)
|
||||||
@ -47,16 +46,16 @@ class Callback(object):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
# Output to the syslog.
|
# Output to the syslog.
|
||||||
LOG.info(_LI("Libvirt Event: type=%(notice_type)s,"
|
LOG.info("Libvirt Event: type=%(notice_type)s,"
|
||||||
" hostname=%(hostname)s,"
|
" hostname=%(hostname)s,"
|
||||||
" uuid=%(uuid)s, time=%(current_time)s,"
|
" uuid=%(uuid)s, time=%(current_time)s,"
|
||||||
" event_id=%(event_id)s,"
|
" event_id=%(event_id)s,"
|
||||||
" detail=%(detail)s)") % {'notice_type': notice_type,
|
" detail=%(detail)s)" % {'notice_type': notice_type,
|
||||||
'hostname': hostname,
|
'hostname': hostname,
|
||||||
'uuid': domain_uuid,
|
'uuid': domain_uuid,
|
||||||
'current_time': current_time,
|
'current_time': current_time,
|
||||||
'event_id': event_id,
|
'event_id': event_id,
|
||||||
'detail': details})
|
'detail': details})
|
||||||
|
|
||||||
# Set the event to the dictionary.
|
# Set the event to the dictionary.
|
||||||
event = {
|
event = {
|
||||||
|
@ -18,7 +18,6 @@ import eventlet
|
|||||||
from oslo_log import log as oslo_logging
|
from oslo_log import log as oslo_logging
|
||||||
|
|
||||||
import masakarimonitors.conf
|
import masakarimonitors.conf
|
||||||
from masakarimonitors.i18n import _LE
|
|
||||||
from masakarimonitors import manager
|
from masakarimonitors import manager
|
||||||
from masakarimonitors.processmonitor.process_handler import handle_process
|
from masakarimonitors.processmonitor.process_handler import handle_process
|
||||||
|
|
||||||
@ -41,10 +40,10 @@ class ProcessmonitorManager(manager.Manager):
|
|||||||
|
|
||||||
return process_list
|
return process_list
|
||||||
except yaml.YAMLError as e:
|
except yaml.YAMLError as e:
|
||||||
LOG.exception(_LE("YAMLError caught: %s"), e)
|
LOG.exception("YAMLError caught: %s", e)
|
||||||
return
|
return
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
LOG.exception(_LE("Exception caught: %s"), e)
|
LOG.exception("Exception caught: %s", e)
|
||||||
return
|
return
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
@ -57,7 +56,7 @@ class ProcessmonitorManager(manager.Manager):
|
|||||||
# Load process list.
|
# Load process list.
|
||||||
process_list = self._load_process_list()
|
process_list = self._load_process_list()
|
||||||
if process_list is None:
|
if process_list is None:
|
||||||
LOG.error(_LE("Failed to load process list file."))
|
LOG.error("Failed to load process list file.")
|
||||||
return
|
return
|
||||||
|
|
||||||
# Set process_list object to the process handler.
|
# 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.
|
# Reload process list and set to the process handler.
|
||||||
process_list = self._load_process_list()
|
process_list = self._load_process_list()
|
||||||
if process_list is None:
|
if process_list is None:
|
||||||
LOG.error(_LE("Failed to reload process list file."))
|
LOG.error("Failed to reload process list file.")
|
||||||
break
|
break
|
||||||
self.process_handler.set_process_list(process_list)
|
self.process_handler.set_process_list(process_list)
|
||||||
|
|
||||||
eventlet.greenthread.sleep(CONF.process.check_interval)
|
eventlet.greenthread.sleep(CONF.process.check_interval)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
LOG.exception(_LE("Exception caught: %s"), e)
|
LOG.exception("Exception caught: %s", e)
|
||||||
return
|
return
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -20,9 +20,6 @@ from oslo_utils import timeutils
|
|||||||
|
|
||||||
import masakarimonitors.conf
|
import masakarimonitors.conf
|
||||||
from masakarimonitors.ha import masakari
|
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.objects import event_constants as ec
|
||||||
from masakarimonitors import utils
|
from masakarimonitors import utils
|
||||||
|
|
||||||
@ -58,16 +55,16 @@ class HandleProcess(object):
|
|||||||
|
|
||||||
if out:
|
if out:
|
||||||
msg = ("CMD '%s' output stdout: %s") % (cmd_str, out)
|
msg = ("CMD '%s' output stdout: %s") % (cmd_str, out)
|
||||||
LOG.info(_LI("%s"), msg)
|
LOG.info("%s", msg)
|
||||||
|
|
||||||
if err:
|
if err:
|
||||||
msg = ("CMD '%s' output stderr: %s") % (cmd_str, err)
|
msg = ("CMD '%s' output stderr: %s") % (cmd_str, err)
|
||||||
LOG.warning(_LW("%s"), msg)
|
LOG.warning("%s", msg)
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
msg = ("CMD '%s' raised exception: %s") % (cmd_str, e)
|
msg = ("CMD '%s' raised exception: %s") % (cmd_str, e)
|
||||||
LOG.error(_LE("%s"), e)
|
LOG.error("%s", e)
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
@ -90,8 +87,7 @@ class HandleProcess(object):
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
# Execute start command.
|
# Execute start command.
|
||||||
LOG.info(
|
LOG.info("Start of process with executing command: %s", cmd_str)
|
||||||
_LI("Start of process with executing command: %s"), cmd_str)
|
|
||||||
self._execute_cmd(cmd_str, process['run_as_root'])
|
self._execute_cmd(cmd_str, process['run_as_root'])
|
||||||
|
|
||||||
# Execute post start command.
|
# Execute post start command.
|
||||||
@ -118,10 +114,9 @@ class HandleProcess(object):
|
|||||||
else:
|
else:
|
||||||
# Append down_process_list.
|
# Append down_process_list.
|
||||||
down_process_list.append(process)
|
down_process_list.append(process)
|
||||||
LOG.warning(
|
LOG.warning("Process '%s' is not found.", process_name)
|
||||||
_LW("Process '%s' is not found."), process_name)
|
|
||||||
except Exception as e:
|
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
|
return down_process_list
|
||||||
|
|
||||||
@ -157,7 +152,7 @@ class HandleProcess(object):
|
|||||||
if down_process['process_name'] in self.restart_failure_list:
|
if down_process['process_name'] in self.restart_failure_list:
|
||||||
msg = "Process '%s' doesn't be restarted because it failed" \
|
msg = "Process '%s' doesn't be restarted because it failed" \
|
||||||
" to restart previously." % down_process['process_name']
|
" 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'])
|
tmp_restart_failure_list.append(down_process['process_name'])
|
||||||
continue
|
continue
|
||||||
|
|
||||||
@ -165,8 +160,7 @@ class HandleProcess(object):
|
|||||||
pre_cmd_str = down_process['pre_restart_command']
|
pre_cmd_str = down_process['pre_restart_command']
|
||||||
post_cmd_str = down_process['post_restart_command']
|
post_cmd_str = down_process['post_restart_command']
|
||||||
|
|
||||||
LOG.info(
|
LOG.info("Restart of process with executing command: %s", cmd_str)
|
||||||
_LI("Restart of process with executing command: %s"), cmd_str)
|
|
||||||
|
|
||||||
for retries in range(0, CONF.process.restart_retries + 1):
|
for retries in range(0, CONF.process.restart_retries + 1):
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ from oslo_service import service
|
|||||||
from oslo_utils import importutils
|
from oslo_utils import importutils
|
||||||
|
|
||||||
import masakarimonitors.conf
|
import masakarimonitors.conf
|
||||||
from masakarimonitors.i18n import _, _LE, _LI
|
from masakarimonitors.i18n import _
|
||||||
from masakarimonitors import utils
|
from masakarimonitors import utils
|
||||||
|
|
||||||
|
|
||||||
@ -56,7 +56,7 @@ class Service(service.Service):
|
|||||||
}
|
}
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
LOG.info(_LI('Starting %s'), self.binary)
|
LOG.info('Starting %s', self.binary)
|
||||||
self.basic_config_check()
|
self.basic_config_check()
|
||||||
self.manager.init_host()
|
self.manager.init_host()
|
||||||
self.manager.main()
|
self.manager.main()
|
||||||
@ -99,7 +99,7 @@ class Service(service.Service):
|
|||||||
self.stop()
|
self.stop()
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
LOG.info(_LI('Stopping %s'), self.binary)
|
LOG.info('Stopping %s', self.binary)
|
||||||
self.manager.stop()
|
self.manager.stop()
|
||||||
super(Service, self).stop()
|
super(Service, self).stop()
|
||||||
|
|
||||||
@ -110,7 +110,7 @@ class Service(service.Service):
|
|||||||
with utils.tempdir():
|
with utils.tempdir():
|
||||||
pass
|
pass
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
LOG.error(_LE('Temporary directory is invalid: %s'), e)
|
LOG.error('Temporary directory is invalid: %s', e)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
def reset(self):
|
def reset(self):
|
||||||
|
@ -66,7 +66,7 @@ class HackingTestCase(testtools.TestCase):
|
|||||||
"msg = _('My message')",
|
"msg = _('My message')",
|
||||||
"masakarimonitors/tests/other_files.py"))), 0)
|
"masakarimonitors/tests/other_files.py"))), 0)
|
||||||
self.assertEqual(len(list(checks.check_explicit_underscore_import(
|
self.assertEqual(len(list(checks.check_explicit_underscore_import(
|
||||||
"from masakarimonitors.i18n import _, _LW",
|
"from masakarimonitors.i18n import _",
|
||||||
"masakarimonitors/tests/other_files2.py"))), 0)
|
"masakarimonitors/tests/other_files2.py"))), 0)
|
||||||
self.assertEqual(len(list(checks.check_explicit_underscore_import(
|
self.assertEqual(len(list(checks.check_explicit_underscore_import(
|
||||||
"msg = _('My message')",
|
"msg = _('My message')",
|
||||||
@ -77,3 +77,19 @@ class HackingTestCase(testtools.TestCase):
|
|||||||
self.assertEqual(len(list(checks.check_explicit_underscore_import(
|
self.assertEqual(len(list(checks.check_explicit_underscore_import(
|
||||||
"msg = _('My message')",
|
"msg = _('My message')",
|
||||||
"masakarimonitors/tests/other_files3.py"))), 0)
|
"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'))"))))
|
||||||
|
@ -27,7 +27,7 @@ from oslo_utils import importutils
|
|||||||
import six
|
import six
|
||||||
|
|
||||||
import masakarimonitors.conf
|
import masakarimonitors.conf
|
||||||
from masakarimonitors.i18n import _, _LE
|
from masakarimonitors.i18n import _
|
||||||
from masakarimonitors import privsep
|
from masakarimonitors import privsep
|
||||||
|
|
||||||
|
|
||||||
@ -97,7 +97,7 @@ def tempdir(**kwargs):
|
|||||||
try:
|
try:
|
||||||
shutil.rmtree(tmpdir)
|
shutil.rmtree(tmpdir)
|
||||||
except OSError as e:
|
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
|
@privsep.monitors_priv.entrypoint
|
||||||
|
@ -14,8 +14,6 @@
|
|||||||
|
|
||||||
from pbr import version as pbr_version
|
from pbr import version as pbr_version
|
||||||
|
|
||||||
from masakarimonitors.i18n import _LE
|
|
||||||
|
|
||||||
MONITORS_VENDOR = "OpenStack Foundation"
|
MONITORS_VENDOR = "OpenStack Foundation"
|
||||||
MONITORS_PRODUCT = "OpenStack Masakari Monitors"
|
MONITORS_PRODUCT = "OpenStack Masakari Monitors"
|
||||||
MONITORS_PACKAGE = None # OS distro package version suffix
|
MONITORS_PACKAGE = None # OS distro package version suffix
|
||||||
@ -59,7 +57,7 @@ def _load_config():
|
|||||||
MONITORS_PACKAGE = cfg.get("Masakarimonitors", "package")
|
MONITORS_PACKAGE = cfg.get("Masakarimonitors", "package")
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
LOG = logging.getLogger(__name__)
|
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})
|
{'cfgfile': cfgfile, 'ex': ex})
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user