Skip to contentSkip to conversation

iotests: finalize switch to async QMP

PATCH Superseded John Snow 3 participants 9 messages Feb 3, 2022 – Mar 18, 2022

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

John Snow

author
#0 lore raw

cover iotests: finalize switch to async QMP

Based-on: <[email protected]>
[PULL 0/4] Python patches
GitLab: https://gitlab.com/jsnow/qemu/-/commits/python-qmp-legacy-switch-pt1b

This tiny series is a spiritual v4 to:
"[PATCH v3 00/31] Python: delete synchronous qemu.qmp package".

I've isolated just the bits that touch iotests, and that's these four patches. If this series is approved, I'll send the series that renames "qemu.aqmp" to "qemu.qmp" separately. That series has a lot of churn, but it doesn't meaningfully alter anything -- so I'll avoid cluttering up qemu-block list with those.

(Just be aware that I plan to finalize the switch soon!)

John Snow (4):
python/machine: permanently switch to AQMP
scripts/bench-block-job: switch to AQMP
iotests/mirror-top-perms: switch to AQMP
iotests: switch to AQMP

 python/qemu/machine/machine.py            | 18 +++++++-----------
 python/qemu/machine/qtest.py              |  2 +-
 scripts/simplebench/bench_block_job.py    |  3 +--
 tests/qemu-iotests/iotests.py             |  2 +-
 tests/qemu-iotests/tests/mirror-top-perms |  9 +++------
 5 files changed, 13 insertions(+), 21 deletions(-)
Signature · 1 line
2.31.1
author
#1 lore raw

PATCH 1/4 python/machine: permanently switch to AQMP

Remove the QEMU_PYTHON_LEGACY_QMP environment variable, making the switch permanent. Update Exceptions and import paths as necessary.

---
 python/qemu/machine/machine.py | 18 +++++++-----------
 python/qemu/machine/qtest.py   |  2 +-
 2 files changed, 8 insertions(+), 12 deletions(-)
python/qemu/machine/machine.py +7 -11
index a5972fab4d..41be025ac7 100644
@@ -40,21 +40,16 @@
     TypeVar,
 )
 
-from qemu.qmp import (  # pylint: disable=import-error
+from qemu.aqmp import SocketAddrT
+from qemu.aqmp.legacy import (
+    QEMUMonitorProtocol,
     QMPMessage,
     QMPReturnValue,
-    SocketAddrT,
 )
 
 from . import console_socket
 
 
-if os.environ.get('QEMU_PYTHON_LEGACY_QMP'):
-    from qemu.qmp import QEMUMonitorProtocol
-else:
-    from qemu.aqmp.legacy import QEMUMonitorProtocol
-
-
 LOG = logging.getLogger(__name__)
 
 
@@ -743,8 +738,9 @@ def events_wait(self,
         :param timeout: Optional timeout, in seconds.
                         See QEMUMonitorProtocol.pull_event.
 
-        :raise QMPTimeoutError: If timeout was non-zero and no matching events
-                                were found.
+        :raise asyncio.TimeoutError:
+            If timeout was non-zero and no matching events were found.
+
         :return: A QMP event matching the filter criteria.
                  If timeout was 0 and no event matched, None.
         """
@@ -767,7 +763,7 @@ def _match(event: QMPMessage) -> bool:
             event = self._qmp.pull_event(wait=timeout)
             if event is None:
                 # NB: None is only returned when timeout is false-ish.
-                # Timeouts raise QMPTimeoutError instead!
+                # Timeouts raise asyncio.TimeoutError instead!
                 break
             if _match(event):
                 return event
python/qemu/machine/qtest.py +1 -1
index f2f9aaa5e5..13e0aaff84 100644
@@ -26,7 +26,7 @@
     TextIO,
 )
 
-from qemu.qmp import SocketAddrT  # pylint: disable=import-error
+from qemu.aqmp import SocketAddrT
 
 from .machine import QEMUMachine
 
Signature · 1 line
2.31.1
author
#2 lore raw

PATCH 2/4 scripts/bench-block-job: switch to AQMP

In reply to John Snow

For this commit, we only need to remove accommodations for the synchronous QMP library.

---
 scripts/simplebench/bench_block_job.py | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
scripts/simplebench/bench_block_job.py +1 -2
index a403c35b08..af9d1646a4 100755
@@ -27,7 +27,6 @@
 
 sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'python'))
 from qemu.machine import QEMUMachine
-from qemu.qmp import QMPConnectError
 from qemu.aqmp import ConnectError
 
 
@@ -50,7 +49,7 @@ def bench_block_job(cmd, cmd_args, qemu_args):
         vm.launch()
     except OSError as e:
         return {'error': 'popen failed: ' + str(e)}
-    except (QMPConnectError, ConnectError, socket.timeout):
+    except (ConnectError, socket.timeout):
         return {'error': 'qemu failed: ' + str(vm.get_log())}
 
     try:
Signature · 1 line
2.31.1
author
#3 lore raw

PATCH 3/4 iotests/mirror-top-perms: switch to AQMP

In reply to John Snow

We don't have to maintain compatibility with both QMP libraries anymore, so we can just remove the old exception. While we're here, take advantage of the extra fields present in the VMLaunchFailure exception that machine.py now raises.

(Note: I'm leaving the logging suppression here unchanged. I had suggested previously we use filters to scrub the PID out of the logging information so it could just be diffed as part of the iotest output, but that meant *always* scrubbing PID from logger output, which defeated the point of even offering that information in the output to begin with.

Ultimately, I decided it's fine to just suppress the logger temporarily.)

---
 tests/qemu-iotests/tests/mirror-top-perms | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
tests/qemu-iotests/tests/mirror-top-perms +3 -6
index b5849978c4..223f3c1620 100755
@@ -22,7 +22,6 @@
 import os
 
 from qemu.machine import machine
-from qemu.qmp import QMPConnectError
 
 import iotests
 from iotests import change_log_level, qemu_img
@@ -99,15 +98,13 @@ class TestMirrorTopPerms(iotests.QMPTestCase):
         self.vm_b.add_blockdev(f'file,node-name=drive0,filename={source}')
         self.vm_b.add_device('virtio-blk,drive=drive0,share-rw=on')
         try:
-            # Silence AQMP errors temporarily.
-            # TODO: Remove this and just allow the errors to be logged when
-            # AQMP fully replaces QMP.
+            # Silence AQMP logging errors temporarily.
             with change_log_level('qemu.aqmp'):
                 self.vm_b.launch()
                 print('ERROR: VM B launched successfully, '
                       'this should not have happened')
-        except (QMPConnectError, machine.VMLaunchFailure):
-            assert 'Is another process using the image' in self.vm_b.get_log()
+        except machine.VMLaunchFailure as exc:
+            assert 'Is another process using the image' in exc.output
 
         result = self.vm.qmp('block-job-cancel',
                              device='mirror')
Signature · 1 line
2.31.1
Reviewed-by on v1 3/4
#4 lore raw

Re: [PATCH 3/4] iotests/mirror-top-perms: switch to AQMP

Quoted 11 lines · John Snow

We don't have to maintain compatibility with both QMP libraries anymore, so we can just remove the old exception. While we're here, take advantage of the extra fields present in the VMLaunchFailure exception that machine.py now raises.

(Note: I'm leaving the logging suppression here unchanged. I had suggested previously we use filters to scrub the PID out of the logging information so it could just be diffed as part of the iotest output, but that meant*always* scrubbing PID from logger output, which defeated the point of even offering that information in the output to begin with.

Quoted 3 lines

Ultimately, I decided it's fine to just suppress the logger temporarily.)

Signature · 2 lines
Best regards,
Vladimir
author
#5 lore raw

PATCH 4/4 iotests: switch to AQMP

In reply to John Snow

All that's left is to import type definitions from the new library instead.

---
 tests/qemu-iotests/iotests.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tests/qemu-iotests/iotests.py +1 -1
index 8cdb381f2a..46e51ff07d 100644
@@ -38,7 +38,7 @@
 from contextlib import contextmanager
 
 from qemu.machine import qtest
-from qemu.qmp import QMPMessage
+from qemu.aqmp.legacy import QMPMessage
 
 # Use this logger for logging messages directly from the iotests module
 logger = logging.getLogger('qemu.iotests')
Signature · 1 line
2.31.1
author
#6 lore raw
In reply to John Snow

Squeak Squeak...

...Any objections to me staging this?

(This patchset removes the accommodations in iotests for allowing either library to run and always forces the new one. Point of no return for iotests.)

--js

Quoted 31 lines · John Snow

Based-on: <[email protected]>
[PULL 0/4] Python patches
GitLab: https://gitlab.com/jsnow/qemu/-/commits/python-qmp-legacy-switch-pt1b

This tiny series is a spiritual v4 to:
"[PATCH v3 00/31] Python: delete synchronous qemu.qmp package".

I've isolated just the bits that touch iotests, and that's these four patches. If this series is approved, I'll send the series that renames "qemu.aqmp" to "qemu.qmp" separately. That series has a lot of churn, but it doesn't meaningfully alter anything -- so I'll avoid cluttering up qemu-block list with those.

(Just be aware that I plan to finalize the switch soon!)

John Snow (4):
python/machine: permanently switch to AQMP
scripts/bench-block-job: switch to AQMP
iotests/mirror-top-perms: switch to AQMP
iotests: switch to AQMP

 python/qemu/machine/machine.py            | 18 +++++++-----------
 python/qemu/machine/qtest.py              |  2 +-
 scripts/simplebench/bench_block_job.py    |  3 +--
 tests/qemu-iotests/iotests.py             |  2 +-
 tests/qemu-iotests/tests/mirror-top-perms |  9 +++------
 5 files changed, 13 insertions(+), 21 deletions(-)

--
2.31.1

Acked-by
#7 lore raw
Quoted 7 lines · John Snow

Squeak Squeak...

...Any objections to me staging this?

(This patchset removes the accommodations in iotests for allowing either library to run and always forces the new one. Point of no return for iotests.)

I took this as “if I don’t reply, that’ll be reply enough” :)

Looks to me like the rebase is minimal (just shuffling the imports in patch 4 a bit), so I guess this’ll help even before you resend:

author
#8 lore raw
Quoted 10 lines · Hanna Reitz
Quoted 7 lines · John Snow

Squeak Squeak...

...Any objections to me staging this?

(This patchset removes the accommodations in iotests for allowing either library to run and always forces the new one. Point of no return for iotests.)

Quoted 7 lines

I took this as “if I don’t reply, that’ll be reply enough” :)

Looks to me like the rebase is minimal (just shuffling the imports in patch 4 a bit), so I guess this’ll help even before you resend:

Great, thanks! I just didn't want to pull the rug out from under anyone on this and really wanted an explicit "yes, sure".

You're the best!

--js