qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: John Snow <jsnow@redhat.com>
To: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>,
	qemu-devel@nongnu.org, qemu-block@nongnu.org
Cc: fam@euphon.net, kwolf@redhat.com, den@openvz.org, mreitz@redhat.com
Subject: Re: [Qemu-devel] [PATCH v2 2/9] python/qemu: improve event_wait method of vm
Date: Fri, 31 May 2019 19:33:41 -0400	[thread overview]
Message-ID: <7d905bca-84d4-de2b-f23f-91c02e97cee3@redhat.com> (raw)
In-Reply-To: <20190531163202.162543-3-vsementsov@virtuozzo.com>



On 5/31/19 12:31 PM, Vladimir Sementsov-Ogievskiy wrote:
> Support several names to wait for, which useful, when we don't sure
> which event will we get. For example when mirror fails we get
> BLOCK_JOB_COMPLETE otherwise we get BLOCK_JOB_READY (and only then,
> after completing block-job we get BLOCK_JOB_COMPLETE).
> 
> Also, add filtered version for convenient use.
> 
> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
> ---
>  python/qemu/__init__.py       | 9 ++++++---
>  tests/qemu-iotests/iotests.py | 5 +++++
>  2 files changed, 11 insertions(+), 3 deletions(-)
> 
> diff --git a/python/qemu/__init__.py b/python/qemu/__init__.py
> index 81d9657ec0..5e517025b9 100644
> --- a/python/qemu/__init__.py
> +++ b/python/qemu/__init__.py
> @@ -402,7 +402,7 @@ class QEMUMachine(object):
>          self._qmp.clear_events()
>          return events
>  
> -    def event_wait(self, name, timeout=60.0, match=None):
> +    def event_wait(self, names, timeout=60.0, match=None):
>          """
>          Wait for specified timeout on named event in QMP; optionally filter
>          results by match.
> @@ -412,6 +412,9 @@ class QEMUMachine(object):
>             {"foo": {"bar": 1}} matches {"foo": None}
>             {"foo": {"bar": 1}} does not matches {"foo": {"baz": None}}
>          """
> +        if not isinstance(names, list):
> +            names = [names]
> +
>          def event_match(event, match=None):
>              if match is None:
>                  return True
> @@ -430,14 +433,14 @@ class QEMUMachine(object):
>  
>          # Search cached events
>          for event in self._events:
> -            if (event['event'] == name) and event_match(event, match):
> +            if (event['event'] in names) and event_match(event, match):
>                  self._events.remove(event)
>                  return event
>  
>          # Poll for new events
>          while True:
>              event = self._qmp.pull_event(wait=timeout)
> -            if (event['event'] == name) and event_match(event, match):
> +            if (event['event'] in names) and event_match(event, match):
>                  return event
>              self._events.append(event)
>  
> diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py
> index 7bde380d96..4218fc908b 100644
> --- a/tests/qemu-iotests/iotests.py
> +++ b/tests/qemu-iotests/iotests.py
> @@ -532,6 +532,11 @@ class VM(qtest.QEMUQtestMachine):
>          log(result, filters, indent=indent)
>          return result
>  
> +    def event_wait_log(self, names, **kwargs):
> +        event = self.event_wait(names, **kwargs)
> +        log(event, filters=[filter_qmp_event])
> +        return event
> +
>      # Returns None on success, and an error string on failure
>      def run_job(self, job, auto_finalize=True, auto_dismiss=False):
>          error = None
> 

There's something like this in the queue; see:
[Qemu-devel] [PATCH v3 3/5] QEMUMachine: add events_wait method.

Though yours is a lot shorter, actually, because I made separate
event_wait and events_wait calls instead of just throwing non-iterables
in a list.

--js



  reply	other threads:[~2019-05-31 23:34 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-31 16:31 [Qemu-devel] [PATCH v2 0/9] qcow2-bitmaps: rewrite reopening logic Vladimir Sementsov-Ogievskiy
2019-05-31 16:31 ` [Qemu-devel] [PATCH v2 1/9] block: add .bdrv_need_rw_file_child_during_reopen_rw handler Vladimir Sementsov-Ogievskiy
2019-05-31 16:31 ` [Qemu-devel] [PATCH v2 2/9] python/qemu: improve event_wait method of vm Vladimir Sementsov-Ogievskiy
2019-05-31 23:33   ` John Snow [this message]
2019-06-03 10:05     ` Vladimir Sementsov-Ogievskiy
2019-05-31 16:31 ` [Qemu-devel] [PATCH v2 3/9] iotests: add test 255 to check bitmap life after snapshot + commit Vladimir Sementsov-Ogievskiy
2019-05-31 23:42   ` John Snow
2019-06-03 10:03     ` Vladimir Sementsov-Ogievskiy
2019-05-31 16:31 ` [Qemu-devel] [PATCH v2 4/9] block/qcow2-bitmap: get rid of bdrv_has_changed_persistent_bitmaps Vladimir Sementsov-Ogievskiy
2019-05-31 16:31 ` [Qemu-devel] [PATCH v2 5/9] block/qcow2-bitmap: drop qcow2_reopen_bitmaps_rw_hint() Vladimir Sementsov-Ogievskiy
2019-05-31 23:54   ` John Snow
2019-05-31 16:31 ` [Qemu-devel] [PATCH v2 6/9] block/qcow2-bitmap: do not remove bitmaps on reopen-ro Vladimir Sementsov-Ogievskiy
2019-06-01  0:06   ` John Snow
2019-06-03 10:14     ` Vladimir Sementsov-Ogievskiy
2019-06-18 14:30       ` John Snow
2019-06-18 14:38         ` Vladimir Sementsov-Ogievskiy
2019-05-31 16:32 ` [Qemu-devel] [PATCH v2 7/9] block/qcow2-bitmap: fix and improve qcow2_reopen_bitmaps_rw Vladimir Sementsov-Ogievskiy
2019-05-31 16:32 ` [Qemu-devel] [PATCH v2 8/9] block/qcow2-bitmap: fix reopening bitmaps to RW Vladimir Sementsov-Ogievskiy
2019-05-31 16:32 ` [Qemu-devel] [PATCH v2 9/9] qcow2-bitmap: move bitmap reopen-rw code to qcow2_reopen_prepare Vladimir Sementsov-Ogievskiy

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=7d905bca-84d4-de2b-f23f-91c02e97cee3@redhat.com \
    --to=jsnow@redhat.com \
    --cc=den@openvz.org \
    --cc=fam@euphon.net \
    --cc=kwolf@redhat.com \
    --cc=mreitz@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=vsementsov@virtuozzo.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).