qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] python/qom: Fix qom-set failure


From: John Snow
Subject: Re: [PATCH] python/qom: Fix qom-set failure
Date: Mon, 10 Jan 2022 15:16:39 -0500



On Mon, Dec 20, 2021 at 12:46 PM Wang Bing-hua <louiswpf@gmail.com> wrote:
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.

--js

[1] https://gitlab.com/jsnow/qemu/-/blob/553032db17440f8de011390e5a1cfddd13751b0b/scripts/qmp/qom-set#L66


reply via email to

[Prev in Thread] Current Thread [Next in Thread]