Fix the following failure by interpreting 'value' argument as 'int'.
Thanks for the patch. Do you use the qom tools often? I wasn't sure anybody did ...
$ scripts/qmp/qom-set -s /tmp/qmp-socket /machine/unattached/device[6].temperature 0
QMPResponseError: Invalid parameter type for 'temperature', expected: integer
Fixes: c750c02891a8 ("python/qmp: Add qom script rewrites")
Signed-off-by: Wang Bing-hua <louiswpf@gmail.com>
---
python/qemu/qmp/qom.py | 1 +
1 file changed, 1 insertion(+)
diff --git a/python/qemu/qmp/qom.py b/python/qemu/qmp/qom.py
index 8ff28a8343..0b77dc6aa3 100644
--- a/python/qemu/qmp/qom.py
+++ b/python/qemu/qmp/qom.py
@@ -72,6 +72,7 @@ def configure_parser(cls, parser: argparse.ArgumentParser) -> None:
cls.add_path_prop_arg(parser)
parser.add_argument(
'value',
+ type=int,
metavar='<value>',
action="">
help='new QOM property value'
--
2.34.1
Is this always going to be correct, though? QOM property values aren't *always* integers. Won't this break other cases?
The old qom-set script did this [1]:
> print(srv.command('qom-set', path=path, property=prop, value=value))
which looks an awful lot like the old qom-set just passed a string along, too.
Two ideas:
(1) try qom-get on the same property and just take note of what type it is that you get back from the server. e.g.
rsp = self.qmp.command('qom-get', path=self.path, property=self.prop)
if isinstance(rsp, int):
# Property we are setting must be an int
else:
# It's something else.
(2) use a query to just determine the type. qom-list with path=/tmp/qmp-socket /machine/unattached/device[6] will return a list of dicts; filter out for the one where "name" is "temperature", then use the "type" value to know what type we should expect from the user.