Skip to contentSkip to conversation

scripts/qmp/qom-set: Allow setting integer value

PATCH In review Jonatan Pålsson 3 participants 4 messages Oct 2, 2020 – Oct 4, 2020

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 scripts/qmp/qom-set: Allow setting integer value

If the value appears to be an integer, parse it as such.

This allows the following:

qmp/qom-set -s ~/qmp.sock sensor.temperature 20000

.. where sensor is a tmp105 device, and temperature is an integer property.

---
 scripts/qmp/qom-set | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
scripts/qmp/qom-set +4 -1
index 240a78187f..49eebe4924 100755
@@ -56,7 +56,10 @@ if len(args) > 1:
         path, prop = args[0].rsplit('.', 1)
     except:
         usage_error("invalid format for path/property/value")
-    value = args[1]
+    try:
+        value = int(args[1])
+    except ValueError:
+        value = args[1]
 else:
     usage_error("not enough arguments")
 
Signature · 1 line
2.26.1
#1 lore raw

Hi Jonatan,

Quoted 5 lines · Jonatan Pålsson

If the value appears to be an integer, parse it as such.

This allows the following:

qmp/qom-set -s ~/qmp.sock sensor.temperature 20000

Maybe instead:

Fix the following error:

  $ scripts/qmp/qom-set -s ~/qmp.sock sensor.temperature 20000
  Traceback (most recent call last):
    File "scripts/qmp/qom-set", line 66, in <module>
      print(srv.command('qom-set', path=path, property=prop, value=value))
    File "scripts/qmp/../../python/qemu/qmp.py", line 274, in command
      raise QMPResponseError(ret)
  qemu.qmp.QMPResponseError: Invalid parameter type for 'temperature',
expected: integer
Quoted 14 lines

.. where sensor is a tmp105 device, and temperature is an integer property.

---
 scripts/qmp/qom-set | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
scripts/qmp/qom-set +0 -0
index 240a78187f..49eebe4924 100755

scripts/qmp/qom-set if len(args) > 1: · line 60

Quoted 6 lines
scripts/qmp/qom-set +2 -1
@@ -56,7 +56,10 @@ if len(args) > 1:
         path, prop = args[0].rsplit('.', 1)
     except:
         usage_error("invalid format for path/property/value")
-    value = args[1]
+    try:
+        value = int(args[1])

Maybe 'long' is safer?

Quoted 6 lines
scripts/qmp/qom-set +2 -0
+    except ValueError:
+        value = args[1]
 else:
     usage_error("not enough arguments")
 
#2 lore raw
Quoted 13 lines · Philippe Mathieu-Daudé

Hi Jonatan,

Quoted 5 lines · Jonatan Pålsson

If the value appears to be an integer, parse it as such.

This allows the following:

qmp/qom-set -s ~/qmp.sock sensor.temperature 20000

Maybe instead:

Fix the following error:

Quoted 9 lines
   $ scripts/qmp/qom-set -s ~/qmp.sock sensor.temperature 20000
   Traceback (most recent call last):
     File "scripts/qmp/qom-set", line 66, in <module>
       print(srv.command('qom-set', path=path, property=prop, value=value))
     File "scripts/qmp/../../python/qemu/qmp.py", line 274, in command
       raise QMPResponseError(ret)
   qemu.qmp.QMPResponseError: Invalid parameter type for 'temperature',
expected: integer

No, this is just relaying the error that QMP returned. QMP is telling you it doesn't want string data for this parameter. His diagnosis of the problem is accurate.

Quoted 9 lines
Quoted 9 lines

.. where sensor is a tmp105 device, and temperature is an integer property.

---
  scripts/qmp/qom-set | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)
Quoted 14 lines

scripts/qmp/qom-set if len(args) > 1: · line 60

Quoted 11 lines
scripts/qmp/qom-set +2 -1
index 240a78187f..49eebe4924 100755
@@ -56,7 +56,10 @@ if len(args) > 1:
          path, prop = args[0].rsplit('.', 1)
      except:
          usage_error("invalid format for path/property/value")
-    value = args[1]
+    try:
+        value = int(args[1])

Maybe 'long' is safer?

This is a Python patch, what's a "long"?

Quoted 7 lines
Quoted 6 lines
scripts/qmp/qom-set +2 -0
+    except ValueError:
+        value = args[1]
  else:
      usage_error("not enough arguments")
 
#3 lore raw
Quoted 25 lines · John Snow
Quoted 13 lines · Philippe Mathieu-Daudé

Hi Jonatan,

Quoted 5 lines · Jonatan Pålsson

If the value appears to be an integer, parse it as such.

This allows the following:

     qmp/qom-set -s ~/qmp.sock sensor.temperature 20000

Maybe instead:

Fix the following error:

Quoted 10 lines
   $ scripts/qmp/qom-set -s ~/qmp.sock sensor.temperature 20000
   Traceback (most recent call last):
     File "scripts/qmp/qom-set", line 66, in <module>
       print(srv.command('qom-set', path=path, property=prop,
value=value))
     File "scripts/qmp/../../python/qemu/qmp.py", line 274, in command
       raise QMPResponseError(ret)
   qemu.qmp.QMPResponseError: Invalid parameter type for 'temperature',
expected: integer
Quoted 3 lines

No, this is just relaying the error that QMP returned. QMP is telling you it doesn't want string data for this parameter. His diagnosis of the problem is accurate.

OK.

Quoted 25 lines
Quoted 10 lines
Quoted 10 lines

.. where sensor is a tmp105 device, and temperature is an integer property.

---
  scripts/qmp/qom-set | 5 ++++-

  1 file changed, 4 insertions(+), 1 deletion(-)
Quoted 14 lines
Quoted 11 lines
scripts/qmp/qom-set +0 -0
index 240a78187f..49eebe4924 100755
@@ -56,7 +56,10 @@ if len(args) > 1:
           path, prop = args[0].rsplit('.', 1)

      except:
          usage_error("invalid format for path/property/value") -    value = args[1]
+    try:
+        value = int(args[1])

Maybe 'long' is safer?

Quoted 1 line

This is a Python patch, what's a "long"?

I haven't finished the mental 2 -> 3 switch yet :/

Quoted 8 lines
Quoted 7 lines
Quoted 6 lines

+    except ValueError:
+        value = args[1]
  else:
      usage_error("not enough arguments")