diff options
Diffstat (limited to 'python/qemu/machine.py')
| -rw-r--r-- | python/qemu/machine.py | 44 |
1 files changed, 20 insertions, 24 deletions
diff --git a/python/qemu/machine.py b/python/qemu/machine.py index 80c4d4a8b6..82f3731fc3 100644 --- a/python/qemu/machine.py +++ b/python/qemu/machine.py @@ -23,11 +23,10 @@ import os import subprocess import shutil import signal -import socket import tempfile from typing import Optional, Type from types import TracebackType -from qemu.console_socket import ConsoleSocket +from . import console_socket from . import qmp @@ -394,15 +393,15 @@ class QEMUMachine: self._popen.kill() self._popen.wait(timeout=60) - def _soft_shutdown(self, has_quit: bool = False, - timeout: Optional[int] = 3) -> None: + def _soft_shutdown(self, timeout: Optional[int], + has_quit: bool = False) -> None: """ Perform early cleanup, attempt to gracefully shut down the VM, and wait for it to terminate. + :param timeout: Timeout in seconds for graceful shutdown. + A value of None is an infinite wait. :param has_quit: When True, don't attempt to issue 'quit' QMP command - :param timeout: Optional timeout in seconds for graceful shutdown. - Default 3 seconds, A value of None is an infinite wait. :raise ConnectionReset: On QMP communication errors :raise subprocess.TimeoutExpired: When timeout is exceeded waiting for @@ -418,14 +417,14 @@ class QEMUMachine: # May raise subprocess.TimeoutExpired self._popen.wait(timeout=timeout) - def _do_shutdown(self, has_quit: bool = False, - timeout: Optional[int] = 3) -> None: + def _do_shutdown(self, timeout: Optional[int], + has_quit: bool = False) -> None: """ Attempt to shutdown the VM gracefully; fallback to a hard shutdown. + :param timeout: Timeout in seconds for graceful shutdown. + A value of None is an infinite wait. :param has_quit: When True, don't attempt to issue 'quit' QMP command - :param timeout: Optional timeout in seconds for graceful shutdown. - Default 3 seconds, A value of None is an infinite wait. :raise AbnormalShutdown: When the VM could not be shut down gracefully. The inner exception will likely be ConnectionReset or @@ -433,7 +432,7 @@ class QEMUMachine: may result in its own exceptions, likely subprocess.TimeoutExpired. """ try: - self._soft_shutdown(has_quit, timeout) + self._soft_shutdown(timeout, has_quit) except Exception as exc: self._hard_shutdown() raise AbnormalShutdown("Could not perform graceful shutdown") \ @@ -441,7 +440,7 @@ class QEMUMachine: def shutdown(self, has_quit: bool = False, hard: bool = False, - timeout: Optional[int] = 3) -> None: + timeout: Optional[int] = 30) -> None: """ Terminate the VM (gracefully if possible) and perform cleanup. Cleanup will always be performed. @@ -453,7 +452,7 @@ class QEMUMachine: :param hard: When true, do not attempt graceful shutdown, and suppress the SIGKILL warning log message. :param timeout: Optional timeout in seconds for graceful shutdown. - Default 3 seconds, A value of None is an infinite wait. + Default 30 seconds, A `None` value is an infinite wait. """ if not self._launched: return @@ -463,7 +462,7 @@ class QEMUMachine: self._user_killed = True self._hard_shutdown() else: - self._do_shutdown(has_quit, timeout=timeout) + self._do_shutdown(timeout, has_quit) finally: self._post_shutdown() @@ -473,12 +472,12 @@ class QEMUMachine: """ self.shutdown(hard=True) - def wait(self, timeout: Optional[int] = 3) -> None: + def wait(self, timeout: Optional[int] = 30) -> None: """ Wait for the VM to power off and perform post-shutdown cleanup. - :param timeout: Optional timeout in seconds. - Default 3 seconds, A value of None is an infinite wait. + :param timeout: Optional timeout in seconds. Default 30 seconds. + A value of `None` is an infinite wait. """ self.shutdown(has_quit=True, timeout=timeout) @@ -673,11 +672,8 @@ class QEMUMachine: Returns a socket connected to the console """ if self._console_socket is None: - if self._drain_console: - self._console_socket = ConsoleSocket(self._console_address, - file=self._console_log_path) - else: - self._console_socket = socket.socket(socket.AF_UNIX, - socket.SOCK_STREAM) - self._console_socket.connect(self._console_address) + self._console_socket = console_socket.ConsoleSocket( + self._console_address, + file=self._console_log_path, + drain=self._drain_console) return self._console_socket |