Merge "[Trivial] Allow flushing named pipe log handles"

This commit is contained in:
Zuul 2018-01-22 16:50:49 +00:00 committed by Gerrit Code Review
commit 12c46121f1
2 changed files with 17 additions and 0 deletions

View File

@ -324,6 +324,16 @@ class NamedPipeTestCase(base.BaseTestCase):
def test_write_to_log_size_exceeded(self):
self._test_write_to_log(size_exceeded=True)
def test_flush_log_file(self):
self._handler._log_file_handle = None
self._handler.flush_log_file()
self._handler._log_file_handle = mock.Mock()
self._handler.flush_log_file()
self._handler._log_file_handle.flush.side_effect = ValueError
self._handler.flush_log_file()
@mock.patch.object(namedpipe.NamedPipeHandler, '_retry_if_file_in_use')
@mock.patch.object(builtins, 'open')
@mock.patch.object(namedpipe, 'os')

View File

@ -221,6 +221,13 @@ class NamedPipeHandler(object):
except Exception:
self._stopped.set()
def flush_log_file(self):
try:
self._log_file_handle.flush()
except (AttributeError, ValueError):
# We'll ignore errors caused by closed handles.
pass
def _rotate_logs(self):
self._log_file_handle.flush()
self._log_file_handle.close()