[Qemu-devel] [PATCH 3/4] scripts/qemu.py: tiny enhancement for event_wiat

Vladimir Sementsov-Ogievskiy posted 4 patches 8 years, 2 months ago
There is a newer version of this series
[Qemu-devel] [PATCH 3/4] scripts/qemu.py: tiny enhancement for event_wiat
Posted by Vladimir Sementsov-Ogievskiy 8 years, 2 months ago
- add comment
- allow int timeout and disallow bool (which has special
  meaning for pull_event())
- remove unreachable 'return None'

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
---
 scripts/qemu.py | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/scripts/qemu.py b/scripts/qemu.py
index 9bfdf6d37d..8763335254 100644
--- a/scripts/qemu.py
+++ b/scripts/qemu.py
@@ -291,7 +291,13 @@ class QEMUMachine(object):
         branch processing on match's value None
            {"foo": {"bar": 1}} matches {"foo": None}
            {"foo": {"bar": 1}} does not matches {"foo": {"baz": None}}
+
+        @raise QMPTimeoutError: If timeout period elapses.
+        @raise QMPConnectError: If some other error occurred.
         '''
+
+        assert isinstance(timeout, float) or isinstance(timeout, int)
+
         def event_match(event, match=None):
             if match is None:
                 return True
@@ -316,13 +322,11 @@ class QEMUMachine(object):
 
         # Poll for new events
         while True:
-            event = self._qmp.pull_event(wait=timeout)
+            event = self._qmp.pull_event(wait=float(timeout))
             if (event['event'] == name) and event_match(event, match):
                 return event
             self._events.append(event)
 
-        return None
-
     def get_log(self):
         '''
         After self.shutdown or failed qemu execution, this returns the output
-- 
2.11.1


Re: [Qemu-devel] [Qemu-block] [PATCH 3/4] scripts/qemu.py: tiny enhancement for event_wiat
Posted by John Snow 8 years, 2 months ago

On 11/28/2017 02:14 AM, Vladimir Sementsov-Ogievskiy wrote:
> - add comment
> - allow int timeout and disallow bool (which has special
>   meaning for pull_event())
> - remove unreachable 'return None'
> 
> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
> ---
>  scripts/qemu.py | 10 +++++++---
>  1 file changed, 7 insertions(+), 3 deletions(-)
> 
> diff --git a/scripts/qemu.py b/scripts/qemu.py
> index 9bfdf6d37d..8763335254 100644
> --- a/scripts/qemu.py
> +++ b/scripts/qemu.py
> @@ -291,7 +291,13 @@ class QEMUMachine(object):
>          branch processing on match's value None
>             {"foo": {"bar": 1}} matches {"foo": None}
>             {"foo": {"bar": 1}} does not matches {"foo": {"baz": None}}
> +
> +        @raise QMPTimeoutError: If timeout period elapses.
> +        @raise QMPConnectError: If some other error occurred.
>          '''
> +
> +        assert isinstance(timeout, float) or isinstance(timeout, int)
> +
>          def event_match(event, match=None):
>              if match is None:
>                  return True
> @@ -316,13 +322,11 @@ class QEMUMachine(object):
>  
>          # Poll for new events
>          while True:
> -            event = self._qmp.pull_event(wait=timeout)
> +            event = self._qmp.pull_event(wait=float(timeout))

Before this patch you *could* ask for no timeout, and this would block
waiting for an event. After, you can't.

Are you making the argument that it is *never* correct to ask for no
timeout?

>              if (event['event'] == name) and event_match(event, match):
>                  return event
>              self._events.append(event)
>  
> -        return None
> -
>      def get_log(self):
>          '''
>          After self.shutdown or failed qemu execution, this returns the output
> 

Re: [Qemu-devel] [Qemu-block] [PATCH 3/4] scripts/qemu.py: tiny enhancement for event_wiat
Posted by Vladimir Sementsov-Ogievskiy 8 years, 2 months ago
06.12.2017 01:59, John Snow wrote:
>
> On 11/28/2017 02:14 AM, Vladimir Sementsov-Ogievskiy wrote:
>> - add comment
>> - allow int timeout and disallow bool (which has special
>>    meaning for pull_event())
>> - remove unreachable 'return None'
>>
>> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
>> ---
>>   scripts/qemu.py | 10 +++++++---
>>   1 file changed, 7 insertions(+), 3 deletions(-)
>>
>> diff --git a/scripts/qemu.py b/scripts/qemu.py
>> index 9bfdf6d37d..8763335254 100644
>> --- a/scripts/qemu.py
>> +++ b/scripts/qemu.py
>> @@ -291,7 +291,13 @@ class QEMUMachine(object):
>>           branch processing on match's value None
>>              {"foo": {"bar": 1}} matches {"foo": None}
>>              {"foo": {"bar": 1}} does not matches {"foo": {"baz": None}}
>> +
>> +        @raise QMPTimeoutError: If timeout period elapses.
>> +        @raise QMPConnectError: If some other error occurred.
>>           '''
>> +
>> +        assert isinstance(timeout, float) or isinstance(timeout, int)
>> +
>>           def event_match(event, match=None):
>>               if match is None:
>>                   return True
>> @@ -316,13 +322,11 @@ class QEMUMachine(object):
>>   
>>           # Poll for new events
>>           while True:
>> -            event = self._qmp.pull_event(wait=timeout)
>> +            event = self._qmp.pull_event(wait=float(timeout))
> Before this patch you *could* ask for no timeout, and this would block
> waiting for an event. After, you can't.
>
> Are you making the argument that it is *never* correct to ask for no
> timeout?

hm, you are right, I'll fix.

>
>>               if (event['event'] == name) and event_match(event, match):
>>                   return event
>>               self._events.append(event)
>>   
>> -        return None
>> -
>>       def get_log(self):
>>           '''
>>           After self.shutdown or failed qemu execution, this returns the output
>>


-- 
Best regards,
Vladimir


Re: [Qemu-devel] [PATCH 3/4] scripts/qemu.py: tiny enhancement for event_wiat
Posted by Vladimir Sementsov-Ogievskiy 8 years, 2 months ago
let's just drop this patch.

28.11.2017 10:14, Vladimir Sementsov-Ogievskiy wrote:
> - add comment
> - allow int timeout and disallow bool (which has special
>    meaning for pull_event())
> - remove unreachable 'return None'
>
> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
> ---
>   scripts/qemu.py | 10 +++++++---
>   1 file changed, 7 insertions(+), 3 deletions(-)
>
> diff --git a/scripts/qemu.py b/scripts/qemu.py
> index 9bfdf6d37d..8763335254 100644
> --- a/scripts/qemu.py
> +++ b/scripts/qemu.py
> @@ -291,7 +291,13 @@ class QEMUMachine(object):
>           branch processing on match's value None
>              {"foo": {"bar": 1}} matches {"foo": None}
>              {"foo": {"bar": 1}} does not matches {"foo": {"baz": None}}
> +
> +        @raise QMPTimeoutError: If timeout period elapses.
> +        @raise QMPConnectError: If some other error occurred.
>           '''
> +
> +        assert isinstance(timeout, float) or isinstance(timeout, int)
> +
>           def event_match(event, match=None):
>               if match is None:
>                   return True
> @@ -316,13 +322,11 @@ class QEMUMachine(object):
>   
>           # Poll for new events
>           while True:
> -            event = self._qmp.pull_event(wait=timeout)
> +            event = self._qmp.pull_event(wait=float(timeout))
>               if (event['event'] == name) and event_match(event, match):
>                   return event
>               self._events.append(event)
>   
> -        return None
> -
>       def get_log(self):
>           '''
>           After self.shutdown or failed qemu execution, this returns the output


-- 
Best regards,
Vladimir