qom: add test tools (resend from "qom: dynamic properties")
v2 cover qom: add test tools (resend from "qom: dynamic properties")
CHANGES SINCE V2:
- this one actually works :) QMP_SOCKET env variable wasn't being handled properly in the last version.
AFAICT the qom tool got dropped from Anthony's "qom: dynamic properties and composition tree" series due to some hardcoded paths for the QMP socket.
I've since ended up adding support for user-specified paths to get them working in my environment so I figured I'd resend to the list since I've seen others express interest.
Only functional change for existing users would be the need to set your QMP_SOCKET env variable to the previous default (/tmp/server.sock):
mdroth@illuin:~$ qom-set -h
environment variables:
QMP_SOCKET=<path | addr:port>
usage:
/home/mdroth/bin/qom-set [-h] [-s <QMP socket path | addr:port>] <path>.<property> <value>mdroth@illuin:~$ qom-get -h
environment variables:
QMP_SOCKET=<path | addr:port>
usage:
/home/mdroth/bin/qom-get [-h] [-s <QMP socket path | addr:port>] <path>.<property>mdroth@illuin:~$ qom-list -h
environment variables:
QMP_SOCKET=<path | addr:port>
usage:
/home/mdroth/bin/qom-list [-h] [-s <QMP socket path | addr:port>] [<path>]mdroth@illuin:~$
PATCH v2 1/2 qmp: make qmp.py easier to use
From: Anthony Liguori <[email protected]>
--- QMP/qmp.py | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-)
QMP/qmp.py +6 -0
@@ -128,6 +128,12 @@ class QEMUMonitorProtocol: qmp_cmd['id'] = id return self.cmd_obj(qmp_cmd) + def command(self, cmd, **kwds): + ret = self.cmd(cmd, kwds) + if ret.has_key('error'): + raise Exception(ret['error']['desc']) + return ret['return'] + def get_events(self, wait=False): """ Get a list of available QMP events.
Signature · 1 line
1.7.4.1
PATCH v2 2/2 qom: add test tools
In reply to Michael RothFrom: Anthony Liguori <[email protected]>
--- QMP/qom-get | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ QMP/qom-list | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ QMP/qom-set | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 195 insertions(+), 0 deletions(-) create mode 100755 QMP/qom-get create mode 100755 QMP/qom-list create mode 100755 QMP/qom-set
QMP/qom-get new file +67 -0
@@ -0,0 +1,67 @@ +#!/usr/bin/python +## +# QEMU Object Model test tools +# +# Copyright IBM, Corp. 2011 +# +# Authors: +# Anthony Liguori <[email protected]> +# +# This work is licensed under the terms of the GNU GPL, version 2 or later. See +# the COPYING file in the top-level directory. +## + +import sys +import os +from qmp import QEMUMonitorProtocol + +cmd, args = sys.argv[0], sys.argv[1:] +socket_path = None +path = None +prop = None + +def usage(): + return '''environment variables: + QMP_SOCKET=<path | addr:port> +usage: + %s [-h] [-s <QMP socket path | addr:port>] <path>.<property> +''' % cmd + +def usage_error(error_msg = "unspecified error"): + sys.stderr.write('%s\nERROR: %s\n' % (usage(), error_msg)) + exit(1) + +if len(args) > 0: + if args[0] == "-h": + print usage() + exit(0); + elif args[0] == "-s": + try: + socket_path = args[1] + except: + usage_error("missing argument: QMP socket path or address"); + args = args[2:] + +if not socket_path: + if os.environ.has_key('QMP_SOCKET'): + socket_path = os.environ['QMP_SOCKET'] + else: + usage_error("no QMP socket path or address given"); + +if len(args) > 0: + try: + path, prop = args[0].rsplit('.', 1) + except: + usage_error("invalid format for path/property/value") +else: + usage_error("not enough arguments") + +srv = QEMUMonitorProtocol(socket_path) +srv.connect() + +rsp = srv.command('qom-get', path=path, property=prop) +if type(rsp) == dict: + for i in rsp.keys(): + print '%s: %s' % (i, rsp[i]) +else: + print rsp
QMP/qom-list new file +64 -0
64 lines not on this page · raw message
QMP/qom-set new file +64 -0
64 lines not on this page · raw message
Signature · 1 line
1.7.4.1
Re: [Qemu-devel] [PATCH 2/2] qom: add test tools
Am 20.02.2012 23:28, schrieb Michael Roth:
Quoted 4 lines
From: Anthony Liguori <[email protected]>
Signed-off-by Anthony Liguori <[email protected]>Signed-off-by Michael Roth <[email protected]>
Thanks, these are really handy! :-)
Since it's three independent scripts, it might make sense to split this into three commits?
Andreas
Quoted 8 lines
--- QMP/qom-get | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ QMP/qom-list | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ QMP/qom-set | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 195 insertions(+), 0 deletions(-) create mode 100755 QMP/qom-get create mode 100755 QMP/qom-list create mode 100755 QMP/qom-set
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
Anthony Liguori
AppliedQuoted 7 lines · Michael Roth
CHANGES SINCE V2:
- this one actually works :)QMP_SOCKETenv variable wasn't being handled properly in the last version.AFAICT the qom tool got dropped from Anthony's "qom: dynamic properties and composition tree" series due to some hardcoded paths for the QMP socket.
Quoted 6 lines
I've since ended up adding support for user-specified paths to get them working in my environment so I figured I'd resend to the list since I've seen others express interest.
Only functional change for existing users would be the need to set your
QMP_SOCKETenv variable to the previous default (/tmp/server.sock):
Applied. Thanks.
Regards,
Anthony Liguori
Quoted 23 lines
mdroth@illuin:~$ qom-set -h environment variables: QMP_SOCKET=<path | addr:port> usage: /home/mdroth/bin/qom-set [-h] [-s<QMP socket path | addr:port>]<path>.<property> <value>mdroth@illuin:~$ qom-get -h environment variables: QMP_SOCKET=<path | addr:port> usage: /home/mdroth/bin/qom-get [-h] [-s<QMP socket path | addr:port>]<path>.<property>mdroth@illuin:~$ qom-list -h environment variables: QMP_SOCKET=<path | addr:port> usage: /home/mdroth/bin/qom-list [-h] [-s<QMP socket path | addr:port>] [<path>]mdroth@illuin:~$