mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-01 23:03:54 -06:00
python/machine.py: Fix monitor address typing
Prior to this, it's difficult for mypy to intuit what the concrete type of the monitor address is; it has difficulty inferring the type across two variables. Create _monitor_address as a property that always returns a valid address to simplify static type analysis. To preserve our ability to clean up, use a simple boolean to indicate whether or not we should try to clean up the sock file after execution. Signed-off-by: John Snow <jsnow@redhat.com> Reviewed-by: Kevin Wolf <kwolf@redhat.com> Message-id: 20201006235817.3280413-3-jsnow@redhat.com Signed-off-by: John Snow <jsnow@redhat.com>
This commit is contained in:
parent
932ca4bbde
commit
c4e6023f05
1 changed files with 25 additions and 15 deletions
|
@ -28,6 +28,7 @@ from types import TracebackType
|
||||||
from typing import Optional, Type
|
from typing import Optional, Type
|
||||||
|
|
||||||
from . import console_socket, qmp
|
from . import console_socket, qmp
|
||||||
|
from .qmp import SocketAddrT
|
||||||
|
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
@ -68,7 +69,8 @@ class QEMUMachine:
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, binary, args=None, wrapper=None, name=None,
|
def __init__(self, binary, args=None, wrapper=None, name=None,
|
||||||
test_dir="/var/tmp", monitor_address=None,
|
test_dir="/var/tmp",
|
||||||
|
monitor_address: Optional[SocketAddrT] = None,
|
||||||
socket_scm_helper=None, sock_dir=None,
|
socket_scm_helper=None, sock_dir=None,
|
||||||
drain_console=False, console_log=None):
|
drain_console=False, console_log=None):
|
||||||
'''
|
'''
|
||||||
|
@ -95,8 +97,14 @@ class QEMUMachine:
|
||||||
if sock_dir is None:
|
if sock_dir is None:
|
||||||
sock_dir = test_dir
|
sock_dir = test_dir
|
||||||
self._name = name
|
self._name = name
|
||||||
self._monitor_address = monitor_address
|
if monitor_address is not None:
|
||||||
self._vm_monitor = None
|
self._monitor_address = monitor_address
|
||||||
|
self._remove_monitor_sockfile = False
|
||||||
|
else:
|
||||||
|
self._monitor_address = os.path.join(
|
||||||
|
sock_dir, f"{name}-monitor.sock"
|
||||||
|
)
|
||||||
|
self._remove_monitor_sockfile = True
|
||||||
self._qemu_log_path = None
|
self._qemu_log_path = None
|
||||||
self._qemu_log_file = None
|
self._qemu_log_file = None
|
||||||
self._popen = None
|
self._popen = None
|
||||||
|
@ -241,15 +249,17 @@ class QEMUMachine:
|
||||||
|
|
||||||
def _base_args(self):
|
def _base_args(self):
|
||||||
args = ['-display', 'none', '-vga', 'none']
|
args = ['-display', 'none', '-vga', 'none']
|
||||||
|
|
||||||
if self._qmp_set:
|
if self._qmp_set:
|
||||||
if isinstance(self._monitor_address, tuple):
|
if isinstance(self._monitor_address, tuple):
|
||||||
moncdev = "socket,id=mon,host=%s,port=%s" % (
|
moncdev = "socket,id=mon,host={},port={}".format(
|
||||||
self._monitor_address[0],
|
*self._monitor_address
|
||||||
self._monitor_address[1])
|
)
|
||||||
else:
|
else:
|
||||||
moncdev = 'socket,id=mon,path=%s' % self._vm_monitor
|
moncdev = f"socket,id=mon,path={self._monitor_address}"
|
||||||
args.extend(['-chardev', moncdev, '-mon',
|
args.extend(['-chardev', moncdev, '-mon',
|
||||||
'chardev=mon,mode=control'])
|
'chardev=mon,mode=control'])
|
||||||
|
|
||||||
if self._machine is not None:
|
if self._machine is not None:
|
||||||
args.extend(['-machine', self._machine])
|
args.extend(['-machine', self._machine])
|
||||||
for _ in range(self._console_index):
|
for _ in range(self._console_index):
|
||||||
|
@ -274,14 +284,14 @@ class QEMUMachine:
|
||||||
self._qemu_log_file = open(self._qemu_log_path, 'wb')
|
self._qemu_log_file = open(self._qemu_log_path, 'wb')
|
||||||
|
|
||||||
if self._qmp_set:
|
if self._qmp_set:
|
||||||
if self._monitor_address is not None:
|
if self._remove_monitor_sockfile:
|
||||||
self._vm_monitor = self._monitor_address
|
assert isinstance(self._monitor_address, str)
|
||||||
else:
|
self._remove_files.append(self._monitor_address)
|
||||||
self._vm_monitor = os.path.join(self._sock_dir,
|
self._qmp = qmp.QEMUMonitorProtocol(
|
||||||
self._name + "-monitor.sock")
|
self._monitor_address,
|
||||||
self._remove_files.append(self._vm_monitor)
|
server=True,
|
||||||
self._qmp = qmp.QEMUMonitorProtocol(self._vm_monitor, server=True,
|
nickname=self._name
|
||||||
nickname=self._name)
|
)
|
||||||
|
|
||||||
def _post_launch(self):
|
def _post_launch(self):
|
||||||
if self._qmp:
|
if self._qmp:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue