[PATCH v2 12/25] python/machine: permanently switch to AQMP

John Snow posted 25 patches 4 years ago
Maintainers: Kevin Wolf <kwolf@redhat.com>, Eduardo Habkost <eduardo@habkost.net>, Hanna Reitz <hreitz@redhat.com>, Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>, Cleber Rosa <crosa@redhat.com>, John Snow <jsnow@redhat.com>, Markus Armbruster <armbru@redhat.com>
There is a newer version of this series
[PATCH v2 12/25] python/machine: permanently switch to AQMP
Posted by John Snow 4 years ago
Remove the QEMU_PYTHON_LEGACY_QMP environment variable, making the
switch permanent. Update Exceptions and import paths as necessary.

Signed-off-by: John Snow <jsnow@redhat.com>
---
 python/qemu/machine/machine.py | 18 +++++++-----------
 python/qemu/machine/qtest.py   |  2 +-
 2 files changed, 8 insertions(+), 12 deletions(-)

diff --git a/python/qemu/machine/machine.py b/python/qemu/machine/machine.py
index 67ab06ca2b..21fb4a4f30 100644
--- a/python/qemu/machine/machine.py
+++ b/python/qemu/machine/machine.py
@@ -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__)
 
 
@@ -710,8 +705,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.
         """
@@ -734,7 +730,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
diff --git a/python/qemu/machine/qtest.py b/python/qemu/machine/qtest.py
index f2f9aaa5e5..817c8a5425 100644
--- a/python/qemu/machine/qtest.py
+++ b/python/qemu/machine/qtest.py
@@ -26,7 +26,7 @@
     TextIO,
 )
 
-from qemu.qmp import SocketAddrT  # pylint: disable=import-error
+from qemu.aqmp.protocol import SocketAddrT
 
 from .machine import QEMUMachine
 
-- 
2.31.1


Re: [PATCH v2 12/25] python/machine: permanently switch to AQMP
Posted by Vladimir Sementsov-Ogievskiy 4 years ago
15.12.2021 22:39, John Snow wrote:
> Remove the QEMU_PYTHON_LEGACY_QMP environment variable, making the
> switch permanent. Update Exceptions and import paths as necessary.
> 
> Signed-off-by: John Snow <jsnow@redhat.com>
> ---
>   python/qemu/machine/machine.py | 18 +++++++-----------
>   python/qemu/machine/qtest.py   |  2 +-
>   2 files changed, 8 insertions(+), 12 deletions(-)
> 
> diff --git a/python/qemu/machine/machine.py b/python/qemu/machine/machine.py
> index 67ab06ca2b..21fb4a4f30 100644
> --- a/python/qemu/machine/machine.py
> +++ b/python/qemu/machine/machine.py
> @@ -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__)
>   
>   
> @@ -710,8 +705,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.
>           """
> @@ -734,7 +730,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
> diff --git a/python/qemu/machine/qtest.py b/python/qemu/machine/qtest.py
> index f2f9aaa5e5..817c8a5425 100644
> --- a/python/qemu/machine/qtest.py
> +++ b/python/qemu/machine/qtest.py
> @@ -26,7 +26,7 @@
>       TextIO,
>   )
>   
> -from qemu.qmp import SocketAddrT  # pylint: disable=import-error
> +from qemu.aqmp.protocol import SocketAddrT

You can also import it simply from qemu.aqmp

>   
>   from .machine import QEMUMachine
>   
> 

Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>

-- 
Best regards,
Vladimir

Re: [PATCH v2 12/25] python/machine: permanently switch to AQMP
Posted by John Snow 4 years ago
On Thu, Dec 16, 2021 at 5:52 AM Vladimir Sementsov-Ogievskiy <
vsementsov@virtuozzo.com> wrote:

> 15.12.2021 22:39, John Snow wrote:
> > Remove the QEMU_PYTHON_LEGACY_QMP environment variable, making the
> > switch permanent. Update Exceptions and import paths as necessary.
> >
> > Signed-off-by: John Snow <jsnow@redhat.com>
> > ---
> >   python/qemu/machine/machine.py | 18 +++++++-----------
> >   python/qemu/machine/qtest.py   |  2 +-
> >   2 files changed, 8 insertions(+), 12 deletions(-)
> >
> > diff --git a/python/qemu/machine/machine.py
> b/python/qemu/machine/machine.py
> > index 67ab06ca2b..21fb4a4f30 100644
> > --- a/python/qemu/machine/machine.py
> > +++ b/python/qemu/machine/machine.py
> > @@ -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__)
> >
> >
> > @@ -710,8 +705,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.
> >           """
> > @@ -734,7 +730,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
> > diff --git a/python/qemu/machine/qtest.py b/python/qemu/machine/qtest.py
> > index f2f9aaa5e5..817c8a5425 100644
> > --- a/python/qemu/machine/qtest.py
> > +++ b/python/qemu/machine/qtest.py
> > @@ -26,7 +26,7 @@
> >       TextIO,
> >   )
> >
> > -from qemu.qmp import SocketAddrT  # pylint: disable=import-error
> > +from qemu.aqmp.protocol import SocketAddrT
>
> You can also import it simply from qemu.aqmp
>
>
Guess what order those patches got written in :)

You're right, I'll update this.


> >
> >   from .machine import QEMUMachine
> >
> >
>
> Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
>
>
Thanks
Re: [PATCH v2 12/25] python/machine: permanently switch to AQMP
Posted by Beraldo Leal 4 years ago
On Wed, Dec 15, 2021 at 02:39:26PM -0500, John Snow wrote:
> Remove the QEMU_PYTHON_LEGACY_QMP environment variable, making the
> switch permanent. Update Exceptions and import paths as necessary.
> 
> Signed-off-by: John Snow <jsnow@redhat.com>
> ---
>  python/qemu/machine/machine.py | 18 +++++++-----------
>  python/qemu/machine/qtest.py   |  2 +-
>  2 files changed, 8 insertions(+), 12 deletions(-)
> 
> diff --git a/python/qemu/machine/machine.py b/python/qemu/machine/machine.py
> index 67ab06ca2b..21fb4a4f30 100644
> --- a/python/qemu/machine/machine.py
> +++ b/python/qemu/machine/machine.py
> @@ -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__)
>  
>  
> @@ -710,8 +705,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.
>          """
> @@ -734,7 +730,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
> diff --git a/python/qemu/machine/qtest.py b/python/qemu/machine/qtest.py
> index f2f9aaa5e5..817c8a5425 100644
> --- a/python/qemu/machine/qtest.py
> +++ b/python/qemu/machine/qtest.py
> @@ -26,7 +26,7 @@
>      TextIO,
>  )
>  
> -from qemu.qmp import SocketAddrT  # pylint: disable=import-error
> +from qemu.aqmp.protocol import SocketAddrT
>  
>  from .machine import QEMUMachine
>  

Reviewed-by: Beraldo Leal <bleal@redhat.com>

--
Beraldo