Skip to contentSkip to conversation

Python patches

GIT PULL John Snow 4 participants 15 messages Oct 4, 2023 – Oct 5, 2023 Arm/Aspeed machine support

lore
Share & tools
lore

John Snow

author
#0 lore raw

The following changes since commit da1034094d375afe9e3d8ec8980550ea0f06f7e0:

Merge tag 'for-upstream' of https://gitlab.com/bonzini/qemu into staging (2023-10-03 07:43:44 -0400)

are available in the Git repository at:

https://gitlab.com/jsnow/qemu.git tags/python-pull-request

for you to fetch changes up to 4d7a663cbe8343e884b88e44bd88d37dd0a470e5:

Python: test Python 3.12 (2023-10-04 15:19:00 -0400)

----------------------------------------------------------------
Python pullreq

Buffering improvements for qemu machine, minor changes to support the newly released Python 3.12

----------------------------------------------------------------

John Snow (9):
Python/iotests: Add type hint for nbd module python/machine: move socket setup out of _base_args property python/machine: close sock_pair in cleanup path python/console_socket: accept existing FD in initializer python/machine: use socketpair() for console connections python/machine: use socketpair() for qtest connection python/machine: remove unused sock_dir argument python/qmp: remove Server.wait_closed() call for Python 3.12
Python: test Python 3.12

 python/qemu/machine/console_socket.py      | 29 ++++++++---
 python/qemu/machine/machine.py             | 58 +++++++++++++---------
 python/qemu/machine/qtest.py               | 54 +++++++++++++++-----
 python/qemu/qmp/protocol.py                |  1 -
 python/setup.cfg                           |  3 +-
 tests/avocado/acpi-bits.py                 |  5 +-
 tests/avocado/avocado_qemu/__init__.py     |  2 +-
 tests/avocado/machine_aspeed.py            |  5 +-
 tests/docker/dockerfiles/python.docker     |  6 ++-
 tests/qemu-iotests/iotests.py              |  2 +-
 tests/qemu-iotests/tests/copy-before-write |  3 +-
 tests/qemu-iotests/tests/nbd-multiconn     |  4 +-
 12 files changed, 114 insertions(+), 58 deletions(-)
Signature · 1 line
2.41.0
author
#1 lore raw

[PULL 3/9] python/machine: close sock_pair in cleanup path

If everything has gone smoothly, we'll already have closed the socket we gave to the child during post_launch. The other half of the pair that we gave to the QMP connection should, likewise, be definitively closed by now.

However, in the cleanup path, it's possible we've created the socketpair but flubbed the launch and need to clean up resources. These resources *would* be handled by the garbage collector, but that can happen at unpredictable times. Nicer to just clean them up synchronously on the exit path, here.

Message-id: [email protected]

---
 python/qemu/machine/machine.py | 5 +++++
 1 file changed, 5 insertions(+)
python/qemu/machine/machine.py +5 -0
index 345610d6e46..e26109e6f0e 100644
@@ -396,6 +396,11 @@ def _post_shutdown(self) -> None:
         finally:
             assert self._qmp_connection is None
 
+        if self._sock_pair:
+            self._sock_pair[0].close()
+            self._sock_pair[1].close()
+            self._sock_pair = None
+
         self._close_qemu_log_file()
 
         self._load_io_log()
Signature · 1 line
2.41.0
author
#2 lore raw

[PULL 2/9] python/machine: move socket setup out of _base_args property

In reply to John Snow

This property isn't meant to do much else besides return a list of strings, so move this setup back out into _pre_launch().

Message-id: [email protected]

---
 python/qemu/machine/machine.py | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
python/qemu/machine/machine.py +2 -3
index 35d5a672dbb..345610d6e46 100644
@@ -301,9 +301,7 @@ def _base_args(self) -> List[str]:
 
         if self._qmp_set:
             if self._sock_pair:
-                fd = self._sock_pair[0].fileno()
-                os.set_inheritable(fd, True)
-                moncdev = f"socket,id=mon,fd={fd}"
+                moncdev = f"socket,id=mon,fd={self._sock_pair[0].fileno()}"
             elif isinstance(self._monitor_address, tuple):
                 moncdev = "socket,id=mon,host={},port={}".format(
                     *self._monitor_address
@@ -340,6 +338,7 @@ def _pre_launch(self) -> None:
         if self._qmp_set:
             if self._monitor_address is None:
                 self._sock_pair = socket.socketpair()
+                os.set_inheritable(self._sock_pair[0].fileno(), True)
                 sock = self._sock_pair[1]
             if isinstance(self._monitor_address, str):
                 self._remove_files.append(self._monitor_address)
Signature · 1 line
2.41.0
author
#3 lore raw

[PULL 5/9] python/machine: use socketpair() for console connections

In reply to John Snow

Create a socketpair for the console output. This should help eliminate race conditions around console text early in the boot process that might otherwise have been dropped on the floor before being able to connect to QEMU under "server,nowait".

Message-id: [email protected]

---
 python/qemu/machine/machine.py | 30 +++++++++++++++++++++++++++---
 1 file changed, 27 insertions(+), 3 deletions(-)
python/qemu/machine/machine.py +27 -3
index e26109e6f0e..4156b8cf7d4 100644
@@ -159,6 +159,8 @@ def __init__(self,
 
         self._name = name or f"{id(self):x}"
         self._sock_pair: Optional[Tuple[socket.socket, socket.socket]] = None
+        self._cons_sock_pair: Optional[
+            Tuple[socket.socket, socket.socket]] = None
         self._temp_dir: Optional[str] = None
         self._base_temp_dir = base_temp_dir
         self._sock_dir = sock_dir
@@ -316,8 +318,9 @@ def _base_args(self) -> List[str]:
         for _ in range(self._console_index):
             args.extend(['-serial', 'null'])
         if self._console_set:
-            chardev = ('socket,id=console,path=%s,server=on,wait=off' %
-                       self._console_address)
+            assert self._cons_sock_pair is not None
+            fd = self._cons_sock_pair[0].fileno()
+            chardev = f"socket,id=console,fd={fd}"
             args.extend(['-chardev', chardev])
             if self._console_device_type is None:
                 args.extend(['-serial', 'chardev:console'])
@@ -352,6 +355,10 @@ def _pre_launch(self) -> None:
                 nickname=self._name
             )
 
+        if self._console_set:
+            self._cons_sock_pair = socket.socketpair()
+            os.set_inheritable(self._cons_sock_pair[0].fileno(), True)
+
         # NOTE: Make sure any opened resources are *definitely* freed in
         # _post_shutdown()!
         # pylint: disable=consider-using-with
@@ -369,6 +376,9 @@ def _pre_launch(self) -> None:
     def _post_launch(self) -> None:
         if self._sock_pair:
             self._sock_pair[0].close()
+        if self._cons_sock_pair:
+            self._cons_sock_pair[0].close()
+
         if self._qmp_connection:
             if self._sock_pair:
                 self._qmp.connect()
@@ -524,6 +534,11 @@ def _early_cleanup(self) -> None:
             self._console_socket.close()
             self._console_socket = None
 
+        if self._cons_sock_pair:
+            self._cons_sock_pair[0].close()
+            self._cons_sock_pair[1].close()
+            self._cons_sock_pair = None
+
     def _hard_shutdown(self) -> None:
         """
         Perform early cleanup, kill the VM, and wait for it to terminate.
@@ -885,10 +900,19 @@ def console_socket(self) -> socket.socket:
         """
         if self._console_socket is None:
             LOG.debug("Opening console socket")
+            if not self._console_set:
+                raise QEMUMachineError(
+                    "Attempt to access console socket with no connection")
+            assert self._cons_sock_pair is not None
+            # os.dup() is used here for sock_fd because otherwise we'd
+            # have two rich python socket objects that would each try to
+            # close the same underlying fd when either one gets garbage
+            # collected.
             self._console_socket = console_socket.ConsoleSocket(
-                self._console_address,
+                sock_fd=os.dup(self._cons_sock_pair[1].fileno()),
                 file=self._console_log_path,
                 drain=self._drain_console)
+            self._cons_sock_pair[1].close()
         return self._console_socket
 
     @property
Signature · 1 line
2.41.0
author
#4 lore raw

[PULL 4/9] python/console_socket: accept existing FD in initializer

In reply to John Snow

Useful if we want to use ConsoleSocket() for a socket created by socketpair().

Message-id: [email protected]

---
 python/qemu/machine/console_socket.py | 29 +++++++++++++++++++--------
 1 file changed, 21 insertions(+), 8 deletions(-)
python/qemu/machine/console_socket.py +21 -8
index 4e28ba9bb23..0a4e09ffc73 100644
@@ -24,19 +24,32 @@ class ConsoleSocket(socket.socket):
     """
     ConsoleSocket represents a socket attached to a char device.
 
-    Optionally (if drain==True), drains the socket and places the bytes
-    into an in memory buffer for later processing.
-
-    Optionally a file path can be passed in and we will also
-    dump the characters to this file for debugging purposes.
+    :param address: An AF_UNIX path or address.
+    :param sock_fd: Optionally, an existing socket file descriptor.
+                    One of address or sock_fd must be specified.
+    :param file: Optionally, a filename to log to.
+    :param drain: Optionally, drains the socket and places the bytes
+                  into an in memory buffer for later processing.
     """
-    def __init__(self, address: str, file: Optional[str] = None,
+    def __init__(self,
+                 address: Optional[str] = None,
+                 sock_fd: Optional[int] = None,
+                 file: Optional[str] = None,
                  drain: bool = False):
+        if address is None and sock_fd is None:
+            raise ValueError("one of 'address' or 'sock_fd' must be specified")
+        if address is not None and sock_fd is not None:
+            raise ValueError("can't specify both 'address' and 'sock_fd'")
+
         self._recv_timeout_sec = 300.0
         self._sleep_time = 0.5
         self._buffer: Deque[int] = deque()
-        socket.socket.__init__(self, socket.AF_UNIX, socket.SOCK_STREAM)
-        self.connect(address)
+        if address is not None:
+            socket.socket.__init__(self, socket.AF_UNIX, socket.SOCK_STREAM)
+            self.connect(address)
+        else:
+            assert sock_fd is not None
+            socket.socket.__init__(self, fileno=sock_fd)
         self._logfile = None
         if file:
             # pylint: disable=consider-using-with
Signature · 1 line
2.41.0
author
#5 lore raw

[PULL 7/9] python/machine: remove unused sock_dir argument

In reply to John Snow

By using a socketpair for all of the sockets managed by the VM class and its extensions, we don't need the sock_dir argument anymore, so remove it.

We only added this argument so that we could specify a second, shorter temporary directory for cases where the temp/log dirs were "too long" as a socket name on macOS. We don't need it for this class now. In one case, avocado testing takes over responsibility for creating an appropriate sockdir.

Message-id: [email protected]

---
 python/qemu/machine/machine.py             | 18 ------------------
 python/qemu/machine/qtest.py               |  5 +----
 tests/avocado/acpi-bits.py                 |  5 +----
 tests/avocado/avocado_qemu/__init__.py     |  2 +-
 tests/avocado/machine_aspeed.py            |  5 ++++-
 tests/qemu-iotests/iotests.py              |  2 +-
 tests/qemu-iotests/tests/copy-before-write |  3 +--
 7 files changed, 9 insertions(+), 31 deletions(-)
python/qemu/machine/machine.py +0 -18
index 4156b8cf7d4..d539e91268a 100644
@@ -127,7 +127,6 @@ def __init__(self,
                  name: Optional[str] = None,
                  base_temp_dir: str = "/var/tmp",
                  monitor_address: Optional[SocketAddrT] = None,
-                 sock_dir: Optional[str] = None,
                  drain_console: bool = False,
                  console_log: Optional[str] = None,
                  log_dir: Optional[str] = None,
@@ -141,7 +140,6 @@ def __init__(self,
         @param name: prefix for socket and log file names (default: qemu-PID)
         @param base_temp_dir: default location where temp files are created
         @param monitor_address: address for QMP monitor
-        @param sock_dir: where to create socket (defaults to base_temp_dir)
         @param drain_console: (optional) True to drain console socket to buffer
         @param console_log: (optional) path to console log file
         @param log_dir: where to create and keep log files
@@ -163,7 +161,6 @@ def __init__(self,
             Tuple[socket.socket, socket.socket]] = None
         self._temp_dir: Optional[str] = None
         self._base_temp_dir = base_temp_dir
-        self._sock_dir = sock_dir
         self._log_dir = log_dir
 
         self._monitor_address = monitor_address
@@ -189,9 +186,6 @@ def __init__(self,
         self._console_index = 0
         self._console_set = False
         self._console_device_type: Optional[str] = None
-        self._console_address = os.path.join(
-            self.sock_dir, f"{self._name}.con"
-        )
         self._console_socket: Optional[socket.socket] = None
         self._console_file: Optional[socket.SocketIO] = None
         self._remove_files: List[str] = []
@@ -335,9 +329,6 @@ def args(self) -> List[str]:
         return self._args
 
     def _pre_launch(self) -> None:
-        if self._console_set:
-            self._remove_files.append(self._console_address)
-
         if self._qmp_set:
             if self._monitor_address is None:
                 self._sock_pair = socket.socketpair()
@@ -937,15 +928,6 @@ def temp_dir(self) -> str:
                                               dir=self._base_temp_dir)
         return self._temp_dir
 
-    @property
-    def sock_dir(self) -> str:
-        """
-        Returns the directory used for sockfiles by this machine.
-        """
-        if self._sock_dir:
-            return self._sock_dir
-        return self.temp_dir
-
     @property
     def log_dir(self) -> str:
         """
python/qemu/machine/qtest.py +1 -4
index 8180d3ab017..4f5ede85b23 100644
@@ -135,17 +135,14 @@ def __init__(self,
                  wrapper: Sequence[str] = (),
                  name: Optional[str] = None,
                  base_temp_dir: str = "/var/tmp",
-                 sock_dir: Optional[str] = None,
                  qmp_timer: Optional[float] = None):
         # pylint: disable=too-many-arguments
 
         if name is None:
             name = "qemu-%d" % os.getpid()
-        if sock_dir is None:
-            sock_dir = base_temp_dir
         super().__init__(binary, args, wrapper=wrapper, name=name,
                          base_temp_dir=base_temp_dir,
-                         sock_dir=sock_dir, qmp_timer=qmp_timer)
+                         qmp_timer=qmp_timer)
         self._qtest: Optional[QEMUQtestProtocol] = None
         self._qtest_sock_pair: Optional[
             Tuple[socket.socket, socket.socket]] = None
tests/avocado/acpi-bits.py +1 -4
index bb3f8186899..eca13dc5181 100644
@@ -92,17 +92,14 @@ def __init__(self,
                  base_temp_dir: str = "/var/tmp",
                  debugcon_log: str = "debugcon-log.txt",
                  debugcon_addr: str = "0x403",
-                 sock_dir: Optional[str] = None,
                  qmp_timer: Optional[float] = None):
         # pylint: disable=too-many-arguments
 
         if name is None:
             name = "qemu-bits-%d" % os.getpid()
-        if sock_dir is None:
-            sock_dir = base_temp_dir
         super().__init__(binary, args, wrapper=wrapper, name=name,
                          base_temp_dir=base_temp_dir,
-                         sock_dir=sock_dir, qmp_timer=qmp_timer)
+                         qmp_timer=qmp_timer)
         self.debugcon_log = debugcon_log
         self.debugcon_addr = debugcon_addr
         self.base_temp_dir = base_temp_dir
tests/avocado/avocado_qemu/__init__.py +1 -1
index 0172a359b71..0589534f28a 100644
@@ -322,7 +322,7 @@ def require_multiprocess(self):
     def _new_vm(self, name, *args):
         self._sd = tempfile.TemporaryDirectory(prefix="qemu_")
         vm = QEMUMachine(self.qemu_bin, base_temp_dir=self.workdir,
-                         sock_dir=self._sd.name, log_dir=self.logdir)
+                         log_dir=self.logdir)
         self.log.debug('QEMUMachine "%s" created', name)
         self.log.debug('QEMUMachine "%s" temp_dir: %s', name, vm.temp_dir)
         self.log.debug('QEMUMachine "%s" log_dir: %s', name, vm.log_dir)
tests/avocado/machine_aspeed.py +4 -1
index 90f1b7cb77a..f691ee3fb82 100644
@@ -247,7 +247,10 @@ def test_arm_ast2600_evb_buildroot_tpm(self):
         image_path = self.fetch_asset(image_url, asset_hash=image_hash,
                                       algorithm='sha256')
 
-        socket = os.path.join(self.vm.sock_dir, 'swtpm-socket')
+        # force creation of VM object, which also defines self._sd
+        vm = self.vm
+
+        socket = os.path.join(self._sd.name, 'swtpm-socket')
 
         subprocess.run(['swtpm', 'socket', '-d', '--tpm2',
                         '--tpmstate', f'dir={self.vm.temp_dir}',
tests/qemu-iotests/iotests.py +1 -1
index ef66fbd62b0..145c6827138 100644
@@ -823,7 +823,7 @@ def __init__(self, path_suffix=''):
         super().__init__(qemu_prog, qemu_opts, wrapper=wrapper,
                          name=name,
                          base_temp_dir=test_dir,
-                         sock_dir=sock_dir, qmp_timer=timer)
+                         qmp_timer=timer)
         self._num_drives = 0
 
     def _post_shutdown(self) -> None:
tests/qemu-iotests/tests/copy-before-write +1 -2
index 2ffe092b318..d3987db9421 100755
@@ -44,8 +44,7 @@ class TestCbwError(iotests.QMPTestCase):
 
         opts = ['-nodefaults', '-display', 'none', '-machine', 'none']
         self.vm = QEMUMachine(iotests.qemu_prog, opts,
-                              base_temp_dir=iotests.test_dir,
-                              sock_dir=iotests.sock_dir)
+                              base_temp_dir=iotests.test_dir)
         self.vm.launch()
 
     def do_cbw_error(self, on_cbw_error):
Signature · 1 line
2.41.0
author
#6 lore raw

[PULL 6/9] python/machine: use socketpair() for qtest connection

In reply to John Snow

Like the QMP and console sockets, begin using socketpairs for the qtest connection, too. After this patch, we'll be able to remove the vestigial sock_dir argument, but that cleanup is best done in its own patch.

Message-id: [email protected]

---
 python/qemu/machine/qtest.py | 49 +++++++++++++++++++++++++++++-------
 1 file changed, 40 insertions(+), 9 deletions(-)
python/qemu/machine/qtest.py +40 -9
index 1c46138bd0c..8180d3ab017 100644
@@ -24,6 +24,7 @@
     Optional,
     Sequence,
     TextIO,
+    Tuple,
 )
 
 from qemu.qmp import SocketAddrT
@@ -38,23 +39,41 @@ class QEMUQtestProtocol:
     :param address: QEMU address, can be either a unix socket path (string)
                     or a tuple in the form ( address, port ) for a TCP
                     connection
-    :param server: server mode, listens on the socket (bool)
+    :param sock: An existing socket can be provided as an alternative to
+                 an address. One of address or sock must be provided.
+    :param server: server mode, listens on the socket. Only meaningful
+                   in conjunction with an address and not an existing
+                   socket.
+
     :raise socket.error: on socket connection errors
 
     .. note::
        No connection is established by __init__(), this is done
        by the connect() or accept() methods.
     """
-    def __init__(self, address: SocketAddrT,
+    def __init__(self,
+                 address: Optional[SocketAddrT] = None,
+                 sock: Optional[socket.socket] = None,
                  server: bool = False):
+        if address is None and sock is None:
+            raise ValueError("Either 'address' or 'sock' must be specified")
+        if address is not None and sock is not None:
+            raise ValueError(
+                "Either 'address' or 'sock' must be specified, but not both")
+        if sock is not None and server:
+            raise ValueError("server=True is meaningless when passing socket")
+
         self._address = address
-        self._sock = self._get_sock()
+        self._sock = sock or self._get_sock()
         self._sockfile: Optional[TextIO] = None
+
         if server:
+            assert self._address is not None
             self._sock.bind(self._address)
             self._sock.listen(1)
 
     def _get_sock(self) -> socket.socket:
+        assert self._address is not None
         if isinstance(self._address, tuple):
             family = socket.AF_INET
         else:
@@ -67,7 +86,8 @@ def connect(self) -> None:
 
         @raise socket.error on socket connection errors
         """
-        self._sock.connect(self._address)
+        if self._address is not None:
+            self._sock.connect(self._address)
         self._sockfile = self._sock.makefile(mode='r')
 
     def accept(self) -> None:
@@ -127,29 +147,40 @@ def __init__(self,
                          base_temp_dir=base_temp_dir,
                          sock_dir=sock_dir, qmp_timer=qmp_timer)
         self._qtest: Optional[QEMUQtestProtocol] = None
-        self._qtest_path = os.path.join(sock_dir, name + "-qtest.sock")
+        self._qtest_sock_pair: Optional[
+            Tuple[socket.socket, socket.socket]] = None
 
     @property
     def _base_args(self) -> List[str]:
         args = super()._base_args
+        assert self._qtest_sock_pair is not None
+        fd = self._qtest_sock_pair[0].fileno()
         args.extend([
-            '-qtest', f"unix:path={self._qtest_path}",
+            '-chardev', f"socket,id=qtest,fd={fd}",
+            '-qtest', 'chardev:qtest',
             '-accel', 'qtest'
         ])
         return args
 
     def _pre_launch(self) -> None:
+        self._qtest_sock_pair = socket.socketpair()
+        os.set_inheritable(self._qtest_sock_pair[0].fileno(), True)
         super()._pre_launch()
-        self._qtest = QEMUQtestProtocol(self._qtest_path, server=True)
+        self._qtest = QEMUQtestProtocol(sock=self._qtest_sock_pair[1])
 
     def _post_launch(self) -> None:
         assert self._qtest is not None
         super()._post_launch()
-        self._qtest.accept()
+        if self._qtest_sock_pair:
+            self._qtest_sock_pair[0].close()
+        self._qtest.connect()
 
     def _post_shutdown(self) -> None:
+        if self._qtest_sock_pair:
+            self._qtest_sock_pair[0].close()
+            self._qtest_sock_pair[1].close()
+            self._qtest_sock_pair = None
         super()._post_shutdown()
-        self._remove_if_exists(self._qtest_path)
 
     def qtest(self, cmd: str) -> str:
         """
Signature · 1 line
2.41.0
author
#7 lore raw

[PULL 8/9] python/qmp: remove Server.wait_closed() call for Python 3.12

In reply to John Snow

This patch is a backport from
https://gitlab.com/qemu-project/python-qemu-qmp/-/commit/e03a3334b6a477beb09b293708632f2c06fe9f61

According to Guido in https://github.com/python/cpython/issues/104344 , this call was never meant to wait for the server to shut down - that is handled synchronously - but instead, this waits for all connections to close. Or, it would have, if it wasn't broken since it was introduced.

3.12 fixes the bug, which now causes a hang in our code. The fix is just to remove the wait.

---
 python/qemu/qmp/protocol.py | 1 -
 1 file changed, 1 deletion(-)
python/qemu/qmp/protocol.py +0 -1
index 753182131fd..a4ffdfad51b 100644
@@ -495,7 +495,6 @@ async def _stop_server(self) -> None:
         try:
             self.logger.debug("Stopping server.")
             self._server.close()
-            await self._server.wait_closed()
             self.logger.debug("Server stopped.")
         finally:
             self._server = None
Signature · 1 line
2.41.0
author
#8 lore raw

[PULL 9/9] Python: test Python 3.12

In reply to John Snow

Python 3.12 has released, so update the test infrastructure to test against this version.

---
 python/setup.cfg                       | 3 ++-
 tests/docker/dockerfiles/python.docker | 6 +++++-
 2 files changed, 7 insertions(+), 2 deletions(-)
python/setup.cfg +2 -1
index 8c67dce4579..48668609d3e 100644
@@ -18,6 +18,7 @@ classifiers =
     Programming Language :: Python :: 3.9
     Programming Language :: Python :: 3.10
     Programming Language :: Python :: 3.11
+    Programming Language :: Python :: 3.12
     Typing :: Typed
 
 [options]
@@ -182,7 +183,7 @@ multi_line_output=3
 # of python available on your system to run this test.
 
 [tox:tox]
-envlist = py38, py39, py310, py311
+envlist = py38, py39, py310, py311, py312
 skip_missing_interpreters = true
 
 [testenv]
tests/docker/dockerfiles/python.docker +5 -1
index 383ccbdc3a5..a3c1321190c 100644
@@ -11,7 +11,11 @@ ENV PACKAGES \
     python3-pip \
     python3-tox \
     python3-virtualenv \
-    python3.10
+    python3.10 \
+    python3.11 \
+    python3.12 \
+    python3.8 \
+    python3.9
 
 RUN dnf install -y $PACKAGES
 RUN rpm -q $PACKAGES | sort > /packages.txt
Signature · 1 line
2.41.0
author
#9 lore raw

[PULL 1/9] Python/iotests: Add type hint for nbd module

In reply to John Snow

The test bails gracefully if this module isn't installed, but linters need a little help understanding that. It's enough to just declare the type in this case.

(Fixes pylint complaining about use of an uninitialized variable because it isn't wise enough to understand the notrun call is noreturn.)

---
 tests/qemu-iotests/tests/nbd-multiconn | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
tests/qemu-iotests/tests/nbd-multiconn +3 -1
index 478a1eaba27..7e686a786ea 100755
@@ -20,6 +20,8 @@
 
 import os
 from contextlib import contextmanager
+from types import ModuleType
+
 import iotests
 from iotests import qemu_img_create, qemu_io
 
@@ -28,7 +30,7 @@ disk = os.path.join(iotests.test_dir, 'disk')
 size = '4M'
 nbd_sock = os.path.join(iotests.sock_dir, 'nbd_sock')
 nbd_uri = 'nbd+unix:///{}?socket=' + nbd_sock
-
+nbd: ModuleType
 
 @contextmanager
 def open_nbd(export_name):
Signature · 1 line
2.41.0
#12 lore raw
In reply to John Snow

Hi John,

Quoted 20 lines · John Snow

The following changes since commit da1034094d375afe9e3d8ec8980550ea0f06f7e0:

   Merge tag 'for-upstream' of https://gitlab.com/bonzini/qemu into staging (2023-10-03 07:43:44 -0400)

are available in the Git repository at:

https://gitlab.com/jsnow/qemu.git tags/python-pull-request

for you to fetch changes up to 4d7a663cbe8343e884b88e44bd88d37dd0a470e5:

   Python: test Python 3.12 (2023-10-04 15:19:00 -0400)

----------------------------------------------------------------
Python pullreq

Buffering improvements for qemu machine, minor changes to support the newly released Python 3.12

----------------------------------------------------------------

Quoted 10 lines

John Snow (9):
Python/iotests: Add type hint for nbd module python/machine: move socket setup out of _base_args property python/machine: close sock_pair in cleanup path python/console_socket: accept existing FD in initializer python/machine: use socketpair() for console connections python/machine: use socketpair() for qtest connection python/machine: remove unused sock_dir argument python/qmp: remove Server.wait_closed() call for Python 3.12
Python: test Python 3.12

Is that a pull request or a patch series to be reviewed?

#13 lore raw
Quoted 35 lines · Philippe Mathieu-Daudé

Hi John,

Quoted 20 lines · John Snow

The following changes since commit da1034094d375afe9e3d8ec8980550ea0f06f7e0:

   Merge tag 'for-upstream' of https://gitlab.com/bonzini/qemu into staging (2023-10-03 07:43:44 -0400)

are available in the Git repository at:

https://gitlab.com/jsnow/qemu.git tags/python-pull-request

for you to fetch changes up to 4d7a663cbe8343e884b88e44bd88d37dd0a470e5:

   Python: test Python 3.12 (2023-10-04 15:19:00 -0400)

----------------------------------------------------------------
Python pullreq

Buffering improvements for qemu machine, minor changes to support the newly released Python 3.12

----------------------------------------------------------------

Quoted 10 lines

John Snow (9):
Python/iotests: Add type hint for nbd module python/machine: move socket setup out of _base_args property python/machine: close sock_pair in cleanup path python/console_socket: accept existing FD in initializer python/machine: use socketpair() for console connections python/machine: use socketpair() for qtest connection python/machine: remove unused sock_dir argument python/qmp: remove Server.wait_closed() call for Python 3.12
Python: test Python 3.12

Quoted 1 line

Is that a pull request or a patch series to be reviewed?

Strange, some of the patches have Reviewed-by tags but others do not. I could not find a "Add type hint for nbd module" patch on the mailing list before this pull request, so I guess it hasn't been reviewed.

I'll hold off from merging this series for now.

John: Please make sure all patches have been on the mailing list for review before sending a pull request.

Stefan

Reviewed-by
#10 lore raw

Re: [PULL 1/9] Python/iotests: Add type hint for nbd module

In reply to John Snow
Quoted 11 lines · John Snow

The test bails gracefully if this module isn't installed, but linters need a little help understanding that. It's enough to just declare the type in this case.

(Fixes pylint complaining about use of an uninitialized variable because it isn't wise enough to understand the notrun call is noreturn.)

---
 tests/qemu-iotests/tests/nbd-multiconn | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Since there's questions about this pull request seeming to be the first time this patch has appeared on list, I'll go ahead and review it here on the assumption that a v2 pull request is warranted.

Quoted 15 lines
tests/qemu-iotests/tests/nbd-multiconn +2 -0
index 478a1eaba27..7e686a786ea 100755
@@ -20,6 +20,8 @@
 
 import os
 from contextlib import contextmanager
+from types import ModuleType
+
 import iotests
 from iotests import qemu_img_create, qemu_io
 

tests/qemu-iotests/tests/nbd-multiconn disk = os.path.join(iotests.test_dir, 'disk') · line 33

Quoted 5 lines
tests/qemu-iotests/tests/nbd-multiconn +1 -1
@@ -28,7 +30,7 @@ disk = os.path.join(iotests.test_dir, 'disk')
 size = '4M'
 nbd_sock = os.path.join(iotests.sock_dir, 'nbd_sock')
 nbd_uri = 'nbd+unix:///{}?socket=' + nbd_sock
-
+nbd: ModuleType

Is it possible to put this closer to the code actually using 'nbd', as in this region?

| if __name__ == '__main__':
|     try:
|         # Easier to use libnbd than to try and set up parallel
|         # 'qemu-nbd --list' or 'qemu-io' processes, but not all systems
|         # have libnbd installed.
|         import nbd  # type: ignore

but then again, open_nbd() right after your current location utilizes the variable, so I guess not. I trust your judgment on silencing the linters, so whether or not you move it (if moving is even possible),

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.
Virtualization:  qemu.org | libguestfs.org
author
#11 lore raw

Re: [PULL 1/9] Python/iotests: Add type hint for nbd module

Quoted 8 lines · Eric Blake
Quoted 7 lines · John Snow

The test bails gracefully if this module isn't installed, but linters need a little help understanding that. It's enough to just declare the type in this case.

(Fixes pylint complaining about use of an uninitialized variable because it isn't wise enough to understand the notrun call is noreturn.)

Quoted 9 lines
Quoted 4 lines
---
 tests/qemu-iotests/tests/nbd-multiconn | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Since there's questions about this pull request seeming to be the first time this patch has appeared on list, I'll go ahead and review it here on the assumption that a v2 pull request is warranted.

Sorry... Tried to "sneak" in some real trivial stuff, but didn't mean to try and pull a fast one. I figured it'd get reviewed and then we'd merge. I can see this sentiment is not a well expected one 😓

Quoted 32 lines

Review

Quoted 2 lines
(quoted diff) +0 -0

b/tests/qemu-iotests/tests/nbd-multiconn

Quoted 13 lines

index 478a1eaba27..7e686a786ea 100755

tests/qemu-iotests/tests/nbd-multiconn +2 -0
@@ -20,6 +20,8 @@
 
 import os
 from contextlib import contextmanager
+from types import ModuleType
+
 import iotests
 from iotests import qemu_img_create, qemu_io
 

tests/qemu-iotests/tests/nbd-multiconn disk = os.path.join(iotests.test_dir, 'disk') · line 33

Quoted 5 lines
tests/qemu-iotests/tests/nbd-multiconn +1 -1
@@ -28,7 +30,7 @@ disk = os.path.join(iotests.test_dir, 'disk')
 size = '4M'
 nbd_sock = os.path.join(iotests.sock_dir, 'nbd_sock')
 nbd_uri = 'nbd+unix:///{}?socket=' + nbd_sock
-
+nbd: ModuleType

Is it possible to put this closer to the code actually using 'nbd', as in this region?

| if __name__ == '__main__':
|     try:
|         # Easier to use libnbd than to try and set up parallel
|         # 'qemu-nbd --list' or 'qemu-io' processes, but not all systems
|         # have libnbd installed.
|         import nbd  # type: ignore
Quoted 4 lines

but then again, open_nbd() right after your current location utilizes the variable, so I guess not. I trust your judgment on silencing the linters, so whether or not you move it (if moving is even possible),

It might be possible to move things around to be more localized, but this was the smallest possible diffstat.

It's not really about the type, the declaration also helps pylint not complain the "potentially" illegal use. (type: ignore isn't sufficient.)

The alternative is, I think, using some try...except around the import up at the top, and using a HAVE_NBDLIB variable that we use to exit early instead. I think there's no real benefit to that much churn, and this gets the job done with less.

It might be possible to teach pylint that notrun is a NORETURN function, but I didn't explore that avenue.

Quoted 2 lines

Thanks, and apologies for the fastball.

Quoted 6 lines

--
Eric Blake, Principal Software Engineer
Red Hat, Inc.
Virtualization: qemu.org | libguestfs.org

author
#14 lore raw
In reply to Stefan Hajnoczi
Quoted 46 lines · Stefan Hajnoczi
Quoted 5 lines · Philippe Mathieu-Daudé

Hi John,

Quoted 1 line · John Snow

The following changes since commit

da1034094d375afe9e3d8ec8980550ea0f06f7e0:

Quoted 2 lines
Quoted 2 lines

Merge tag 'for-upstream' of https://gitlab.com/bonzini/qemu into

staging (2023-10-03 07:43:44 -0400)

Quoted 6 lines
Quoted 6 lines

are available in the Git repository at:

https://gitlab.com/jsnow/qemu.git tags/python-pull-request

for you to fetch changes up to

4d7a663cbe8343e884b88e44bd88d37dd0a470e5:

Quoted 22 lines
Quoted 11 lines
   Python: test Python 3.12 (2023-10-04 15:19:00 -0400)

----------------------------------------------------------------
Python pullreq

Buffering improvements for qemu machine, minor changes to support the newly released Python 3.12

----------------------------------------------------------------

Quoted 10 lines

John Snow (9):
Python/iotests: Add type hint for nbd module python/machine: move socket setup out of _base_args property python/machine: close sock_pair in cleanup path python/console_socket: accept existing FD in initializer python/machine: use socketpair() for console connections python/machine: use socketpair() for qtest connection python/machine: remove unused sock_dir argument python/qmp: remove Server.wait_closed() call for Python 3.12
Python: test Python 3.12

Quoted 1 line

Is that a pull request or a patch series to be reviewed?

Strange, some of the patches have Reviewed-by tags but others do not. I could not find a "Add type hint for nbd module" patch on the mailing list before this pull request, so I guess it hasn't been reviewed.

Quoted 7 lines

I'll hold off from merging this series for now.

John: Please make sure all patches have been on the mailing list for review before sending a pull request.

Stefan

Okey Dokey.

--js