All of lore.kernel.org
 help / color / mirror / Atom feed
From: John Snow <jsnow@redhat.com>
To: qemu-devel <qemu-devel@nongnu.org>
Cc: Willian Rampazzo <wrampazz@redhat.com>,
	Eduardo Habkost <ehabkost@redhat.com>,
	Markus Armbruster <armbru@redhat.com>,
	Wainer dos Santos Moschetta <wainersm@redhat.com>,
	"Niteesh G . S ." <niteesh.gs@gmail.com>,
	Stefan Hajnoczi <stefanha@redhat.com>,
	Cleber Rosa <crosa@redhat.com>, Eric Blake <eblake@redhat.com>
Subject: Re: [PATCH v3 00/25] python: introduce Asynchronous QMP package
Date: Mon, 16 Aug 2021 17:44:49 -0400	[thread overview]
Message-ID: <CAFn=p-bmA_BgNbd6eAM+GUd6Ls85aj+GdM2d0h65-0HXTSCm6g@mail.gmail.com> (raw)
In-Reply-To: <20210803182941.504537-1-jsnow@redhat.com>

[-- Attachment #1: Type: text/plain, Size: 13111 bytes --]

On Tue, Aug 3, 2021 at 2:29 PM John Snow <jsnow@redhat.com> wrote:

> GitLab: https://gitlab.com/jsnow/qemu/-/commits/python-async-qmp-aqmp
> CI: https://gitlab.com/jsnow/qemu/-/pipelines/347375602
> Docs: https://people.redhat.com/~jsnow/sphinx/html/qemu.aqmp.html
>
> Hi!
>
> This patch series adds an Asynchronous QMP package to the Python
> library. It offers a few improvements over the previous library:
>
> - out-of-band support
> - true asynchronous event support
> - avoids undocumented interfaces abusing non-blocking sockets
> - unit tests!
> - documentation!
>
> This library serves as the basis for a new qmp-shell program that will
> offer improved reconnection support, true asynchronous display of
> events, VM and job status update notifiers, and so on.
>
> My intent is to eventually publish this library directly to PyPI as a
> standalone package. I would like to phase out our usage of the old QMP
> library over time; eventually replacing it entirely with this
> one. (Since v2 of this series, I have authored a compatibility shim not
> included in this series that can be used to run all of iotests on this
> new library successfully with very minimal churn.)
>
> This series looks big by line count, but it's *mostly*
> docstrings. Seriously!
>
> This package has *no* external dependencies whatsoever.
>
> Notes & Design
> ==============
>
> Here are some notes on the design of how the library works, to serve as
> a primer for review; however I also **highly recommend** browsing the
> generated Sphinx documentation for this series.
>
> Here's that link again:
> https://people.redhat.com/~jsnow/sphinx/html/qemu.aqmp.html
>
> The core machinery is split between the AsyncProtocol and QMPClient
> classes. AsyncProtocol provides the generic machinery, while QMPClient
> provides the QMP-specific details.
>
> The design uses two independent coroutines that act as the "bottom
> half", a writer task and a reader task. These tasks run for the duration
> of the connection and independently send and receive messages,
> respectively.
>
> A third task, disconnect, is scheduled asynchronously whenever an
> unrecoverable error occurs and facilitates coalescing of the other two
> tasks.
>
> This diagram for how execute() operates may be helpful for understanding
> how AsyncProtocol is laid out. The arrows indicate the direction of a
> QMP message; the long horizontal dash indicates the separation between
> the upper and lower halves of the event loop. The queue mechanisms
> between both dashes serve as the intermediaries between the upper and
> lower halves.
>
>                        +---------+
>                        | caller  |
>                        +---------+
>                            ^ |
>                            | v
>                        +---------+
>      +---------------> |execute()| -----------+
>      |                 +---------+            |
>      |                                        |
> [-----------------------------------------------------------]
>      |                                        |
>      |                                        v
> +----+------+    +----------------+    +------+-------+
> | ExecQueue |    | EventListeners |    |Outbound Queue|
> +----+------+    +----+-----------+    +------+-------+
>      ^                ^                       |
>      |                |                       |
> [-----------------------------------------------------------]
>      |                |                       |
>      |                |                       v
>   +--+----------------+---+       +-----------+-----------+
>   | Reader Task/Coroutine |       | Writer Task/Coroutine |
>   +-----------+-----------+       +-----------+-----------+
>               ^                               |
>               |                               v
>         +-----+------+                  +-----+------+
>         |StreamReader|                  |StreamWriter|
>         +------------+                  +------------+
>
> The caller will invoke execute(), which in turn will deposit a message
> in the outbound send queue. This will wake up the writer task, which
> well send the message over the wire.
>
> The execute() method will then yield to wait for a reply delivered to an
> execution queue created solely for that execute statement.
>
> When a message arrives, the Reader task will unblock and route the
> message either to the EventListener subsystem, or place it in the
> appropriate pending execution queue.
>
> Once a message is placed in the pending execution queue, execute() will
> unblock and the execution will conclude, returning the result of the RPC
> call to the caller.
>
> Patch Layout
> ============
>
> Patches 1-4   add tiny pre-requisites, utilities, etc.
> Patches 5-12  add a generic async message-based protocol class,
>               AsyncProtocol. They are split fairly small and should
>               be reasonably self-contained.
> Patches 13-15 check in more QMP-centric components.
> Patches 16-21 add qmp_client.py, with a new 'QMPClient()' class.
>               They're split into reasonably tiny pieces here.
> Patches 22-23 add a few finishing touches, they are small patches.
> Patches 24-25 adds unit tests. They're a little messy still, but
>               they've been quite helpful to me so far. Coverage of
>               protocol.py is at about ~86%.
>
> Future Work
> ===========
>
> These items are in progress:
>
> - A synchronous QMP wrapper that allows this library to be easily used
>   from non-async code; this will also allow me to prove it works well by
>   demoing its replacement throughout iotests.
>
>   This work is feature-complete, but needs polish. All of iotests is now
>   passing with Async QMP and this Sync wrapper. This will be its own
>   follow-up series.
>
> - A QMP server class; to facilitate writing of unit tests. An early
>   version is done, but possibly not feature complete. More polish and
>   tests are warranted. This will be its own follow-up series.
>
> - More unit tests for qmp_client.py, qmp_server.py and other modules.
>
> Changelog
> =========
>
> V3:
>
> - (02, 05) Typo fixes (Eric Blake)
> - (04) Rewrote the "wait_closed" compatibility function for Python 3.6;
>   the older version raised unwanted exceptions in error pathways.
>   (Niteesh)
> - (04, 05, 06, 08) Rewrote _bh_disconnect fairly substantially again;
>   the problem is that exceptions can surface during both flushing of the
>   stream and when waiting for the stream to close. These errors can be
>   new, primary causes of failure or secondary failures. Distinguishing
>   between them is tricky. The new disconnection method takes much
>   greater pains to ensure that even if Exceptions occur, disconnect
>   *will* complete. This adds robustness to cases exposed by iotests
>   where one or more endpoints might segfault or abort and cleanup can be
>   challenged.
> - (11) Fixed logging hook names (Niteesh)
> - (24, 25) Bumped avocado dependency to v90; It added support for async
>   test functions which made my prior workaround non-suitable. The
>   choices were to mandate <90 and keep the workarounds or mandate >=90
>   and drop the workarounds. I went with the latter.
>
> V2:
>
> Renamed classes/methods:
>
> - Renamed qmp_protocol.py to qmp_client.py
> - Renamed 'QMP' class to 'QMPClient'
> - Renamed _begin_new_session() to _establish_session()
> - Split _establish_connection() out from _new_session().
> - Removed _results() method
>
> Bugfixes:
>
> - Suppress duplicate Exceptions when attempting to drain the
>   StreamWriter
> - Delay initialization of asyncio.Queue and asyncio.Event variables to
>   _new_session or later -- they must not be created outside of the loop,
>   even if they are not async functions.
> - Rework runstate_changed events to guarantee visibility of events to
>   waiters
> - Improve connect()/accept() cleanup to work with
>   asyncio.CancelledError, asyncio.TimeoutError
> - No-argument form of Message() now succeeds properly.
> - flush utility will correctly yield when data is below the "high water
>   mark", giving the stream a chance to actually flush.
> - Increase read buffer size to accommodate query-qmp-schema (Thanks
>   Niteesh)
>
> Ugly bits from V1 removed:
>
> - Remove tertiary filtering from EventListener (for now), accompanying
>   documentation removed from events.py
> - Use asyncio.wait() instead of custom wait_task_done()
> - MultiException is removed in favor of just raising the first Exception
>   that occurs in the bottom half; other Exceptions if any are logged
>   instead.
>
> Improvements:
>
> - QMPClient now allows ID-less execution statements via the _raw()
>   interface.
> - Add tests that grant ~86% coverage of protocol.py to the avocado test
>   suite.
> - Removed 'force' parameter from _bh_disconnect; the disconnection
>   routine determines for itself if we are in the error pathway or not
>   instead now.  This removes any chance of duplicate calls to
>   _schedule_disconnect accidentally dropping the 'force' setting.
>
> Debugging/Testing changes:
>
> - Add debug: bool parameter to asyncio_run utility wrapper
> - Improve error messages for '@require' decorator
> - Add debugging message for state change events
> - Avoid flushing the StreamWriter if we don't have one (This
>   circumstance only arises in testing, but it's helpful.)
> - Improved __repr__ method for AsyncProtocol, and removed __str__
>   method.  enforcing eval(__repr__(x)) == x does not make sense for
>   AsyncProtocol.
> - Misc logging message changes
> - Add a suite of fancy Task debugging utilities.
> - Most tracebacks now log at the DEBUG level instead of
>   CRITICAL/ERROR/WARNING; In those error cases, a one-line summary is
>   logged instead.
>
> Misc. aesthetic changes:
>
> - Misc docstring fixes, whitespace, etc.
> - Reordered the definition of some methods to try and keep similar
>   methods near each other (Moved _cleanup near _bh_disconnect in
>   QMPClient.)
>
> John Snow (25):
>   python/aqmp: add asynchronous QMP (AQMP) subpackage
>   python/aqmp: add error classes
>   python/pylint: Add exception for TypeVar names ('T')
>   python/aqmp: add asyncio compatibility wrappers
>   python/aqmp: add generic async message-based protocol support
>   python/aqmp: add runstate state machine to AsyncProtocol
>   python/aqmp: Add logging utility helpers
>   python/aqmp: add logging to AsyncProtocol
>   python/aqmp: add AsyncProtocol.accept() method
>   python/aqmp: add configurable read buffer limit
>   python/aqmp: add _cb_inbound and _cb_outbound logging hooks
>   python/aqmp: add AsyncProtocol._readline() method
>   python/aqmp: add QMP Message format
>   python/aqmp: add well-known QMP object models
>   python/aqmp: add QMP event support
>   python/pylint: disable too-many-function-args
>   python/aqmp: add QMP protocol support
>   python/pylint: disable no-member check
>   python/aqmp: Add message routing to QMP protocol
>   python/aqmp: add execute() interfaces
>   python/aqmp: add _raw() execution interface
>   python/aqmp: add asyncio_run compatibility wrapper
>   python/aqmp: add scary message
>   python: bump avocado to v90.0
>   python/aqmp: add AsyncProtocol unit tests
>
>  python/Pipfile.lock            |   8 +-
>  python/qemu/aqmp/__init__.py   |  59 +++
>  python/qemu/aqmp/error.py      |  50 ++
>  python/qemu/aqmp/events.py     | 706 ++++++++++++++++++++++++++
>  python/qemu/aqmp/message.py    | 209 ++++++++
>  python/qemu/aqmp/models.py     | 133 +++++
>  python/qemu/aqmp/protocol.py   | 902 +++++++++++++++++++++++++++++++++
>  python/qemu/aqmp/py.typed      |   0
>  python/qemu/aqmp/qmp_client.py | 621 +++++++++++++++++++++++
>  python/qemu/aqmp/util.py       | 217 ++++++++
>  python/setup.cfg               |   7 +-
>  python/tests/null_proto.py     |  70 +++
>  python/tests/protocol.py       | 535 +++++++++++++++++++
>  13 files changed, 3511 insertions(+), 6 deletions(-)
>  create mode 100644 python/qemu/aqmp/__init__.py
>  create mode 100644 python/qemu/aqmp/error.py
>  create mode 100644 python/qemu/aqmp/events.py
>  create mode 100644 python/qemu/aqmp/message.py
>  create mode 100644 python/qemu/aqmp/models.py
>  create mode 100644 python/qemu/aqmp/protocol.py
>  create mode 100644 python/qemu/aqmp/py.typed
>  create mode 100644 python/qemu/aqmp/qmp_client.py
>  create mode 100644 python/qemu/aqmp/util.py
>  create mode 100644 python/tests/null_proto.py
>  create mode 100644 python/tests/protocol.py
>
> --
> 2.31.1
>
>
>
Any opposition to me checking this into the tree when it opens up again?
I'd like to get it into the tree early in the cycle and test having iotests
run on the new library.

I am thinking that (In a follow-up series, not this one) I will modify the
QEMUMachine class to use the new library by default, but expose an
environment variable that can be used to push it to use the older library.
My hope is that if I do this early on in the development window that any
remaining problems could be identified and fixed while still causing little
to no disruption.

Thoughts?

[-- Attachment #2: Type: text/html, Size: 15500 bytes --]

      parent reply	other threads:[~2021-08-16 21:46 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-03 18:29 [PATCH v3 00/25] python: introduce Asynchronous QMP package John Snow
2021-08-03 18:29 ` [PATCH v3 01/25] python/aqmp: add asynchronous QMP (AQMP) subpackage John Snow
2021-08-03 18:29 ` [PATCH v3 02/25] python/aqmp: add error classes John Snow
2021-08-03 18:29 ` [PATCH v3 03/25] python/pylint: Add exception for TypeVar names ('T') John Snow
2021-08-03 18:29 ` [PATCH v3 04/25] python/aqmp: add asyncio compatibility wrappers John Snow
2021-08-03 18:29 ` [PATCH v3 05/25] python/aqmp: add generic async message-based protocol support John Snow
2021-08-03 18:29 ` [PATCH v3 06/25] python/aqmp: add runstate state machine to AsyncProtocol John Snow
2021-08-05 21:02   ` Eric Blake
2021-08-05 21:30     ` John Snow
2021-08-03 18:29 ` [PATCH v3 07/25] python/aqmp: Add logging utility helpers John Snow
2021-08-17 19:14   ` Eric Blake
2021-08-03 18:29 ` [PATCH v3 08/25] python/aqmp: add logging to AsyncProtocol John Snow
2021-08-17 19:18   ` Eric Blake
2021-08-03 18:29 ` [PATCH v3 09/25] python/aqmp: add AsyncProtocol.accept() method John Snow
2021-08-17 19:29   ` Eric Blake
2021-08-18 14:24     ` John Snow
2021-08-19 14:50       ` Eric Blake
2021-08-19 15:48         ` John Snow
2021-08-19 16:43           ` Eduardo Habkost
2021-08-03 18:29 ` [PATCH v3 10/25] python/aqmp: add configurable read buffer limit John Snow
2021-08-17 19:30   ` Eric Blake
2021-08-03 18:29 ` [PATCH v3 11/25] python/aqmp: add _cb_inbound and _cb_outbound logging hooks John Snow
2021-08-17 19:32   ` Eric Blake
2021-08-03 18:29 ` [PATCH v3 12/25] python/aqmp: add AsyncProtocol._readline() method John Snow
2021-08-17 19:36   ` Eric Blake
2021-08-03 18:29 ` [PATCH v3 13/25] python/aqmp: add QMP Message format John Snow
2021-08-17 19:47   ` Eric Blake
2021-08-18 14:31     ` John Snow
2021-08-03 18:29 ` [PATCH v3 14/25] python/aqmp: add well-known QMP object models John Snow
2021-08-03 18:29 ` [PATCH v3 15/25] python/aqmp: add QMP event support John Snow
2021-08-03 18:29 ` [PATCH v3 16/25] python/pylint: disable too-many-function-args John Snow
2021-08-03 18:29 ` [PATCH v3 17/25] python/aqmp: add QMP protocol support John Snow
2021-08-03 18:29 ` [PATCH v3 18/25] python/pylint: disable no-member check John Snow
2021-08-03 18:29 ` [PATCH v3 19/25] python/aqmp: Add message routing to QMP protocol John Snow
2021-08-03 18:29 ` [PATCH v3 20/25] python/aqmp: add execute() interfaces John Snow
2021-08-03 18:29 ` [PATCH v3 21/25] python/aqmp: add _raw() execution interface John Snow
2021-08-03 18:29 ` [PATCH v3 22/25] python/aqmp: add asyncio_run compatibility wrapper John Snow
2021-08-03 18:29 ` [PATCH v3 23/25] python/aqmp: add scary message John Snow
2021-08-03 18:29 ` [PATCH v3 24/25] python: bump avocado to v90.0 John Snow
2021-08-03 18:29 ` [PATCH v3 25/25] python/aqmp: add AsyncProtocol unit tests John Snow
2021-08-04 18:41   ` John Snow
2021-08-16 21:44 ` John Snow [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAFn=p-bmA_BgNbd6eAM+GUd6Ls85aj+GdM2d0h65-0HXTSCm6g@mail.gmail.com' \
    --to=jsnow@redhat.com \
    --cc=armbru@redhat.com \
    --cc=crosa@redhat.com \
    --cc=eblake@redhat.com \
    --cc=ehabkost@redhat.com \
    --cc=niteesh.gs@gmail.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    --cc=wainersm@redhat.com \
    --cc=wrampazz@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.