Merge "Proper log translation"

This commit is contained in:
Zuul 2021-01-23 01:12:02 +00:00 committed by Gerrit Code Review
commit a1e74ac37c
6 changed files with 25 additions and 35 deletions

View File

@ -94,8 +94,8 @@ class DhcpAgent(manager.Manager):
# If 'resync_throttle' is configured more than 'resync_interval' by
# mistake, raise exception and log with message.
if self.conf.resync_throttle > self.conf.resync_interval:
msg = _("DHCP agent must have resync_throttle <= resync_interval")
LOG.exception(msg)
LOG.exception("DHCP agent must have resync_throttle <= "
"resync_interval")
raise exceptions.InvalidConfigurationOption(
opt_name='resync_throttle',
opt_value=self.conf.resync_throttle)

View File

@ -35,7 +35,6 @@ from oslo_utils import fileutils
from oslo_utils import netutils
from oslo_utils import uuidutils
from neutron._i18n import _
from neutron.agent.common import utils as agent_common_utils
from neutron.agent.linux import external_process
from neutron.agent.linux import ip_lib
@ -304,17 +303,13 @@ class DhcpLocalProcess(DhcpBase, metaclass=abc.ABCMeta):
def _get_value_from_conf_file(self, kind, converter=None):
"""A helper function to read a value from one of the state files."""
file_name = self.get_conf_file_name(kind)
msg = _('Error while reading %s')
try:
with open(file_name, 'r') as f:
try:
return converter(f.read()) if converter else f.read()
except ValueError:
msg = _('Unable to convert value in %s')
return converter(f.read()) if converter else f.read()
except ValueError:
msg = "Unable to convert value in %s"
except IOError:
msg = _('Unable to access %s')
msg = "Unable to access %s"
LOG.debug(msg, file_name)
return None

View File

@ -1024,8 +1024,8 @@ def _arping(ns_name, iface_name, address, count, log_exception):
[address],
mac=None,
namespace=ns_name)
msg = _("Failed sending gratuitous ARP to %(addr)s on "
"%(iface)s in namespace %(ns)s: %(err)s")
msg = ("Failed sending gratuitous ARP to %(addr)s on "
"%(iface)s in namespace %(ns)s: %(err)s")
logger_method = LOG.exception
if not (log_exception and (first or exists)):
logger_method = LOG.info

View File

@ -128,23 +128,22 @@ def execute(cmd, process_input=None, addl_env=None,
extra_ok_codes = extra_ok_codes or []
if returncode and returncode not in extra_ok_codes:
msg = _("Exit code: %(returncode)d; "
"Cmd: %(cmd)s; "
"Stdin: %(stdin)s; "
"Stdout: %(stdout)s; "
"Stderr: %(stderr)s") % {
msg = ("Exit code: %(returncode)d; "
"Cmd: %(cmd)s; "
"Stdin: %(stdin)s; "
"Stdout: %(stdout)s; "
"Stderr: %(stderr)s" % {
'returncode': returncode,
'cmd': cmd,
'stdin': process_input or '',
'stdout': _stdout,
'stderr': _stderr}
'stderr': _stderr})
if log_fail_as_error:
LOG.error(msg)
if check_exit_code:
raise exceptions.ProcessExecutionError(msg,
raise exceptions.ProcessExecutionError(_(msg),
returncode=returncode)
finally:
# NOTE(termie): this appears to be necessary to let the subprocess
# call clean something up in between calls, without

View File

@ -114,13 +114,13 @@ def execute(cmd, process_input=None, addl_env=None,
_stdout = helpers.safe_decode_utf8(_stdout)
_stderr = helpers.safe_decode_utf8(_stderr)
m = _("\nCommand: %(cmd)s\nExit code: %(code)s\nStdin: %(stdin)s\n"
"Stdout: %(stdout)s\nStderr: %(stderr)s") % \
{'cmd': cmd,
'code': obj.returncode,
'stdin': process_input or '',
'stdout': _stdout,
'stderr': _stderr}
m = ("\nCommand: %(cmd)s\nExit code: %(code)s\nStdin: %(stdin)s\n"
"Stdout: %(stdout)s\nStderr: %(stderr)s" %
{'cmd': cmd,
'code': obj.returncode,
'stdin': process_input or '',
'stdout': _stdout,
'stderr': _stderr})
extra_ok_codes = extra_ok_codes or []
if obj.returncode and obj.returncode in extra_ok_codes:
@ -133,8 +133,7 @@ def execute(cmd, process_input=None, addl_env=None,
LOG.debug(log_msg)
if obj.returncode and check_exit_code:
raise exceptions.ProcessExecutionError(m, returncode=obj.returncode)
raise exceptions.ProcessExecutionError(_(m), returncode=obj.returncode)
return (_stdout, _stderr) if return_stderr else _stdout

View File

@ -43,7 +43,6 @@ from neutron_lib import constants
from neutron_lib import exceptions
from oslo_log import log as logging
from neutron._i18n import _
from neutron import privileged
from neutron.privileged.agent.linux import netlink_constants as nl_constants
@ -192,8 +191,7 @@ class ConntrackManager(object):
self._set_attributes(conntrack, entry)
self._query(nl_constants.NFCT_Q_DESTROY, conntrack)
except Exception as e:
msg = _("Failed to delete conntrack entries %s") % e
LOG.critical(msg)
LOG.critical("Failed to delete conntrack entries %s", e)
raise exceptions.CTZoneExhaustedError()
finally:
nfct.nfct_destroy(conntrack)
@ -234,8 +232,7 @@ class ConntrackManager(object):
nl_constants.NFNL_SUBSYS_CTNETLINK,
nl_constants.CONNTRACK)
if not self.conntrack_handler:
msg = _("Failed to open new conntrack handler")
LOG.critical(msg)
LOG.critical("Failed to open new conntrack handler")
raise exceptions.CTZoneExhaustedError()
return self