* [Qemu-devel] [PATCH 1/1] QMP test code - qmp.py
@ 2010-04-07 0:40 Costas Drogos
2010-04-07 13:36 ` [Qemu-devel] " Luiz Capitulino
0 siblings, 1 reply; 4+ messages in thread
From: Costas Drogos @ 2010-04-07 0:40 UTC (permalink / raw)
To: qemu-devel; +Cc: lcapitulino
Hello there,
a very small patch to address two small issues:
1) The json state in python2.5 and python2.6. json module is included
by default on python2.6, whereas you have to import simplejson in
python2.5. I have this problem on Debian testing, so feel free to test
if this is applicable in your distribution.
2) For qmp commands to work (e.g. query-kvm) we have to give first the
command 'qmp_capabilities' because monitor is in 'Capabilities
Negotiation mode' on startup. The patch takes care of issuing that
command immediately after connecting.
The patch is more of a hack to ease qmp testing and development.
Costas Drogos
--
diff --git a/QMP/qmp.py b/QMP/qmp.py
index d9da603..f8581c4 100644
--- a/QMP/qmp.py
+++ b/QMP/qmp.py
@@ -8,7 +8,15 @@
# This work is licensed under the terms of the GNU GPL, version 2. See
# the COPYING file in the top-level directory.
-import socket, json
+import socket
+
+from sys import version
+ver = version[:3]
+
+if ver == '2.6':
+ import json
+else:
+ import simplejson as json
class QMPError(Exception):
pass
@@ -24,6 +32,9 @@ class QEMUMonitorProtocol:
raise QMPConnectError
if not data.has_key('QMP'):
raise QMPConnectError
+ # initialize the qmp interface
+ cmd = {'execute':'qmp_capabilities' }
+ self.sock.send(str(cmd))
return data['QMP']['capabilities']
def close(self):
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [Qemu-devel] Re: [PATCH 1/1] QMP test code - qmp.py
2010-04-07 0:40 [Qemu-devel] [PATCH 1/1] QMP test code - qmp.py Costas Drogos
@ 2010-04-07 13:36 ` Luiz Capitulino
2010-04-07 13:51 ` Avi Kivity
0 siblings, 1 reply; 4+ messages in thread
From: Luiz Capitulino @ 2010-04-07 13:36 UTC (permalink / raw)
To: Costas Drogos; +Cc: qemu-devel
On Wed, 7 Apr 2010 03:40:32 +0300
Costas Drogos <costas.drogos@gmail.com> wrote:
> Hello there,
>
> a very small patch to address two small issues:
>
> 1) The json state in python2.5 and python2.6. json module is included
> by default on python2.6, whereas you have to import simplejson in
> python2.5. I have this problem on Debian testing, so feel free to test
> if this is applicable in your distribution.
>
> 2) For qmp commands to work (e.g. query-kvm) we have to give first the
> command 'qmp_capabilities' because monitor is in 'Capabilities
> Negotiation mode' on startup. The patch takes care of issuing that
> command immediately after connecting.
>
> The patch is more of a hack to ease qmp testing and development.
I already have a new version of that script in the master branch of:
git://repo.or.cz/qemu/qmp-unstable.git
It fixes current problems and has other improvements, I didn't submit
it yet because I didn't test it much.
So, I will add a fix for the json problem and would appreciate any testing.
> diff --git a/QMP/qmp.py b/QMP/qmp.py
> index d9da603..f8581c4 100644
> --- a/QMP/qmp.py
> +++ b/QMP/qmp.py
> @@ -8,7 +8,15 @@
> # This work is licensed under the terms of the GNU GPL, version 2. See
> # the COPYING file in the top-level directory.
>
> -import socket, json
> +import socket
> +
> +from sys import version
> +ver = version[:3]
> +
> +if ver == '2.6':
> + import json
> +else:
> + import simplejson as json
This won't do what we want for 2.7 and newer, so a better if would be:
if sys.version_info < (2, 6):
import simplejson as json
else:
import json
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Qemu-devel] Re: [PATCH 1/1] QMP test code - qmp.py
2010-04-07 13:36 ` [Qemu-devel] " Luiz Capitulino
@ 2010-04-07 13:51 ` Avi Kivity
2010-04-07 14:38 ` Costas Drogos
0 siblings, 1 reply; 4+ messages in thread
From: Avi Kivity @ 2010-04-07 13:51 UTC (permalink / raw)
To: Luiz Capitulino; +Cc: Costas Drogos, qemu-devel
On 04/07/2010 04:36 PM, Luiz Capitulino wrote:
>
>
>> diff --git a/QMP/qmp.py b/QMP/qmp.py
>> index d9da603..f8581c4 100644
>> --- a/QMP/qmp.py
>> +++ b/QMP/qmp.py
>> @@ -8,7 +8,15 @@
>> # This work is licensed under the terms of the GNU GPL, version 2. See
>> # the COPYING file in the top-level directory.
>>
>> -import socket, json
>> +import socket
>> +
>> +from sys import version
>> +ver = version[:3]
>> +
>> +if ver == '2.6':
>> + import json
>> +else:
>> + import simplejson as json
>>
> This won't do what we want for 2.7 and newer, so a better if would be:
>
> if sys.version_info< (2, 6):
> import simplejson as json
> else:
> import json
>
>
try:
import json
except:
import simplejson as json
--
I have a truly marvellous patch that fixes the bug which this
signature is too narrow to contain.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Qemu-devel] Re: [PATCH 1/1] QMP test code - qmp.py
2010-04-07 13:51 ` Avi Kivity
@ 2010-04-07 14:38 ` Costas Drogos
0 siblings, 0 replies; 4+ messages in thread
From: Costas Drogos @ 2010-04-07 14:38 UTC (permalink / raw)
To: qemu-devel; +Cc: Avi Kivity, Luiz Capitulino
On Wed, Apr 7, 2010 at 16:51, Avi Kivity <avi@redhat.com> wrote:
>> This won't do what we want for 2.7 and newer, so a better if would be:
Thats why i said it is just an ugly hack :) Anyway, I've just cloned
the qmp-unstable tree to run some tests and report back
>> if sys.version_info< (2, 6):
>> import simplejson as json
>> else:
>> import json
>>
>>
>
> try:
> import json
> except:
> import simplejson as json
I thought of that, but the thing is that, in Debian at least, there is
python-json for python 2.5 which does not work, but can be imported,
and also python-simplejson. On python2.6 json module is included and
there is a package python2.6-simplejson also. Anyway, we can't check
what every distribution does with modules, so I think Avi's solution
works most of the times. In the end it is just a test script :)
Thanks for the comments :)
--
Costas Drogos
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2010-04-07 14:38 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-04-07 0:40 [Qemu-devel] [PATCH 1/1] QMP test code - qmp.py Costas Drogos
2010-04-07 13:36 ` [Qemu-devel] " Luiz Capitulino
2010-04-07 13:51 ` Avi Kivity
2010-04-07 14:38 ` Costas Drogos
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).