[Trivial] Allow flushing named pipe log handles
The named pipe handler provided by os-win is used by Nova when
consuming instance serial ports. For convenience, it allows logging
the named pipe output to a file (useful for storing the serial
console output).
The issue is that the log file never gets flushed, thus Nova returns
incomplete results. This change adds a method that may be used for
flushing the log file.
Change-Id: I4b5eb7579ac0c92e9c3630539b0c4d76f5b98c6d
Closes-Bug: #1741494
(cherry picked from commit 1b99d30fa2
)
This commit is contained in:
parent
fec6f71345
commit
f1a917598b
|
@ -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')
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue