Stop trying to log stdout when fetching logs during inspection
Logging the whole journalctl output is not the best idea. Fortunately, it does not work right now and fails with a traceback :) This change adds a new log_stdout argument to utils.execute() and uses it in the "logs" inspection collector. Also do not log the logs while logging the collected data. Change-Id: Ibc726ac2c4f5eb06c73ac4765bb400077b84a6cc
This commit is contained in:
parent
d25d94b316
commit
58f86d0353
|
@ -37,6 +37,7 @@ LOG = logging.getLogger(__name__)
|
||||||
CONF = cfg.CONF
|
CONF = cfg.CONF
|
||||||
DEFAULT_COLLECTOR = 'default'
|
DEFAULT_COLLECTOR = 'default'
|
||||||
_COLLECTOR_NS = 'ironic_python_agent.inspector.collectors'
|
_COLLECTOR_NS = 'ironic_python_agent.inspector.collectors'
|
||||||
|
_NO_LOGGING_FIELDS = ('logs',)
|
||||||
|
|
||||||
|
|
||||||
def extension_manager(names):
|
def extension_manager(names):
|
||||||
|
@ -108,7 +109,8 @@ def call_inspector(data, failures):
|
||||||
data['error'] = failures.get_error()
|
data['error'] = failures.get_error()
|
||||||
|
|
||||||
LOG.info('posting collected data to %s', CONF.inspection_callback_url)
|
LOG.info('posting collected data to %s', CONF.inspection_callback_url)
|
||||||
LOG.debug('collected data: %s', data)
|
LOG.debug('collected data: %s',
|
||||||
|
{k: v for k, v in data.items() if k not in _NO_LOGGING_FIELDS})
|
||||||
|
|
||||||
encoder = encoding.RESTJSONEncoder()
|
encoder = encoding.RESTJSONEncoder()
|
||||||
data = encoder.encode(data)
|
data = encoder.encode(data)
|
||||||
|
@ -274,7 +276,8 @@ def collect_logs(data, failures):
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
out, _e = utils.execute('journalctl', '--full', '--no-pager', '-b',
|
out, _e = utils.execute('journalctl', '--full', '--no-pager', '-b',
|
||||||
'-n', '10000', binary=True)
|
'-n', '10000', binary=True,
|
||||||
|
log_stdout=False)
|
||||||
except (processutils.ProcessExecutionError, OSError):
|
except (processutils.ProcessExecutionError, OSError):
|
||||||
LOG.warning('failed to get system journal')
|
LOG.warning('failed to get system journal')
|
||||||
return
|
return
|
||||||
|
|
|
@ -394,7 +394,8 @@ class TestCollectLogs(unittest.TestCase):
|
||||||
|
|
||||||
mock_execute.assert_called_once_with('journalctl', '--full',
|
mock_execute.assert_called_once_with('journalctl', '--full',
|
||||||
'--no-pager', '-b',
|
'--no-pager', '-b',
|
||||||
'-n', '10000', binary=True)
|
'-n', '10000', binary=True,
|
||||||
|
log_stdout=False)
|
||||||
|
|
||||||
def test_no_journal(self, mock_execute):
|
def test_no_journal(self, mock_execute):
|
||||||
mock_execute.side_effect = OSError()
|
mock_execute.side_effect = OSError()
|
||||||
|
|
|
@ -53,15 +53,18 @@ def execute(*cmd, **kwargs):
|
||||||
oslo_concurrency.processutils.execute for usage.
|
oslo_concurrency.processutils.execute for usage.
|
||||||
|
|
||||||
:param *cmd: positional arguments to pass to processutils.execute()
|
:param *cmd: positional arguments to pass to processutils.execute()
|
||||||
|
:param log_stdout: keyword-only argument: whether to log the output
|
||||||
:param **kwargs: keyword arguments to pass to processutils.execute()
|
:param **kwargs: keyword arguments to pass to processutils.execute()
|
||||||
:raises: UnknownArgumentError on receiving unknown arguments
|
:raises: UnknownArgumentError on receiving unknown arguments
|
||||||
:raises: ProcessExecutionError
|
:raises: ProcessExecutionError
|
||||||
:raises: OSError
|
:raises: OSError
|
||||||
:returns: tuple of (stdout, stderr)
|
:returns: tuple of (stdout, stderr)
|
||||||
"""
|
"""
|
||||||
|
log_stdout = kwargs.pop('log_stdout', True)
|
||||||
result = processutils.execute(*cmd, **kwargs)
|
result = processutils.execute(*cmd, **kwargs)
|
||||||
LOG.debug('Execution completed, command line is "%s"', ' '.join(cmd))
|
LOG.debug('Execution completed, command line is "%s"', ' '.join(cmd))
|
||||||
LOG.debug('Command stdout is: "%s"', result[0])
|
if log_stdout:
|
||||||
|
LOG.debug('Command stdout is: "%s"', result[0])
|
||||||
LOG.debug('Command stderr is: "%s"', result[1])
|
LOG.debug('Command stderr is: "%s"', result[1])
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
@ -76,6 +79,7 @@ def try_execute(*cmd, **kwargs):
|
||||||
returns None in case of failure.
|
returns None in case of failure.
|
||||||
|
|
||||||
:param *cmd: positional arguments to pass to processutils.execute()
|
:param *cmd: positional arguments to pass to processutils.execute()
|
||||||
|
:param log_stdout: keyword-only argument: whether to log the output
|
||||||
:param **kwargs: keyword arguments to pass to processutils.execute()
|
:param **kwargs: keyword arguments to pass to processutils.execute()
|
||||||
:raises: UnknownArgumentError on receiving unknown arguments
|
:raises: UnknownArgumentError on receiving unknown arguments
|
||||||
:returns: tuple of (stdout, stderr) or None in some error cases
|
:returns: tuple of (stdout, stderr) or None in some error cases
|
||||||
|
|
Loading…
Reference in New Issue