Merge "Flush console log file before retrieving content"
This commit is contained in:
commit
b7a5775ab6
|
@ -49,6 +49,7 @@ class SerialConsoleHandler(object):
|
|||
|
||||
self._serial_proxy = None
|
||||
self._workers = []
|
||||
self._log_handler = None
|
||||
|
||||
def start(self):
|
||||
self._setup_handlers()
|
||||
|
@ -117,6 +118,9 @@ class SerialConsoleHandler(object):
|
|||
enable_logging=enable_logging)
|
||||
self._workers.append(handler)
|
||||
|
||||
if enable_logging:
|
||||
self._log_handler = handler
|
||||
|
||||
def _get_named_pipe_handler(self, pipe_path, pipe_type,
|
||||
enable_logging):
|
||||
kwargs = {}
|
||||
|
@ -161,3 +165,9 @@ class SerialConsoleHandler(object):
|
|||
raise exception.ConsoleTypeUnavailable(console_type='serial')
|
||||
return ctype.ConsoleSerial(host=self._listen_host,
|
||||
port=self._listen_port)
|
||||
|
||||
def flush_console_log(self):
|
||||
if self._log_handler:
|
||||
LOG.debug("Flushing instance %s console log.",
|
||||
self._instance_name)
|
||||
self._log_handler.flush_log_file()
|
||||
|
|
|
@ -111,6 +111,10 @@ class SerialConsoleOps(object):
|
|||
console_log_paths = self._pathutils.get_vm_console_log_paths(
|
||||
instance_name)
|
||||
|
||||
handler = _console_handlers.get(instance_name)
|
||||
if handler:
|
||||
handler.flush_console_log()
|
||||
|
||||
try:
|
||||
log = b''
|
||||
# Start with the oldest console log file.
|
||||
|
|
|
@ -135,7 +135,7 @@ class SerialConsoleHandlerTestCase(test_base.HyperVBaseTestCase):
|
|||
|
||||
return mock_get_pipe_handler
|
||||
|
||||
def test_setup_ro_pipe_handler(self):
|
||||
def test_setup_rw_pipe_handler(self):
|
||||
serial_port_mapping = {
|
||||
constants.SERIAL_PORT_TYPE_RW: mock.sentinel.pipe_path
|
||||
}
|
||||
|
@ -147,6 +147,8 @@ class SerialConsoleHandlerTestCase(test_base.HyperVBaseTestCase):
|
|||
mock.sentinel.pipe_path,
|
||||
pipe_type=constants.SERIAL_PORT_TYPE_RW,
|
||||
enable_logging=True)
|
||||
self.assertEqual(mock_get_handler.return_value,
|
||||
self._consolehandler._log_handler)
|
||||
|
||||
def test_setup_pipe_handlers(self):
|
||||
serial_port_mapping = {
|
||||
|
@ -251,3 +253,12 @@ class SerialConsoleHandlerTestCase(test_base.HyperVBaseTestCase):
|
|||
self.flags(enabled=False, group='serial_console')
|
||||
self.assertRaises(exception.ConsoleTypeUnavailable,
|
||||
self._consolehandler.get_serial_console)
|
||||
|
||||
def test_flush_console_log(self):
|
||||
self._consolehandler._log_handler = None
|
||||
self._consolehandler.flush_console_log()
|
||||
|
||||
mock_handler = mock.Mock()
|
||||
self._consolehandler._log_handler = mock_handler
|
||||
self._consolehandler.flush_console_log()
|
||||
mock_handler.flush_log_file.assert_called_once_with()
|
||||
|
|
|
@ -109,6 +109,8 @@ class SerialConsoleOpsTestCase(test_base.HyperVBaseTestCase):
|
|||
@mock.patch.object(builtins, 'open')
|
||||
@mock.patch("os.path.exists")
|
||||
def test_get_console_output_exception(self, fake_path_exists, fake_open):
|
||||
mock_handler = self._setup_console_handler_mock()
|
||||
|
||||
self._serialops._vmutils.is_secure_vm.return_value = False
|
||||
self._serialops._pathutils.get_vm_console_log_paths.return_value = [
|
||||
mock.sentinel.log_path_1, mock.sentinel.log_path_2]
|
||||
|
@ -118,6 +120,7 @@ class SerialConsoleOpsTestCase(test_base.HyperVBaseTestCase):
|
|||
self.assertRaises(exception.ConsoleLogOutputException,
|
||||
self._serialops.get_console_output,
|
||||
mock.sentinel.instance_name)
|
||||
mock_handler.flush_console_log.assert_called_once_with()
|
||||
fake_open.assert_called_once_with(mock.sentinel.log_path_2, 'rb')
|
||||
|
||||
def test_get_console_output_secure_vm(self):
|
||||
|
|
Loading…
Reference in New Issue