Skip to contentSkip to conversation

qmp: allow setting properties to empty string in qmp-shell

PATCH In review Daniel P. Berrange 4 participants 4 messages Mar 2, 2017 – Mar 6, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 qmp: allow setting properties to empty string in qmp-shell

The qmp-shell property parser currently rejects attempts to set string properties to the empty string eg

(QEMU) migrate-set-parameters tls-hostname=
Error while parsing command line: Expected a key=value pair, got 'tls-hostname='
command format: <command-name> [arg-name1=arg1] ... [arg-nameN=argN]

This is caused by checking the wrong condition after splitting the parameter on '='. The "partition" method will return "" for the separator field, if the seperator was not present, so that is the correct thing to check for malformed syntax.

---
 scripts/qmp/qmp-shell | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
scripts/qmp/qmp-shell +2 -2
index 0373b24..eccb88a 100755
@@ -166,8 +166,8 @@ class QMPShell(qmp.QEMUMonitorProtocol):
 
     def __cli_expr(self, tokens, parent):
         for arg in tokens:
-            (key, _, val) = arg.partition('=')
-            if not val:
+            (key, sep, val) = arg.partition('=')
+            if sep != '=':
                 raise QMPShellError("Expected a key=value pair, got '%s'" % arg)
 
             value = self.__parse_value(val)
Signature · 1 line
2.9.3
Reviewed-by on v1 1/1
#1 lore raw
Quoted 12 lines · Daniel P. Berrange

The qmp-shell property parser currently rejects attempts to set string properties to the empty string eg

(QEMU) migrate-set-parameters tls-hostname=
Error while parsing command line: Expected a key=value pair, got 'tls-hostname='
command format: <command-name> [arg-name1=arg1] ... [arg-nameN=argN]

This is caused by checking the wrong condition after splitting the parameter on '='. The "partition" method will return "" for the separator field, if the seperator was not present, so that is the correct thing to check for malformed syntax.

Quoted 4 lines
---
 scripts/qmp/qmp-shell | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Probably worth having in 2.9, since we are having the parallel discussion about permitting an empty string as a way to clear out TLS in migration parameters.

Quoted 17 lines
scripts/qmp/qmp-shell +2 -2
index 0373b24..eccb88a 100755
@@ -166,8 +166,8 @@ class QMPShell(qmp.QEMUMonitorProtocol):
 
     def __cli_expr(self, tokens, parent):
         for arg in tokens:
-            (key, _, val) = arg.partition('=')
-            if not val:
+            (key, sep, val) = arg.partition('=')
+            if sep != '=':
                 raise QMPShellError("Expected a key=value pair, got '%s'" % arg)
 
             value = self.__parse_value(val)
Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
Reviewed-by on v1 1/1
#2 lore raw
In reply to Daniel P. Berrange
Quoted 12 lines · Daniel P. Berrange

The qmp-shell property parser currently rejects attempts to set string properties to the empty string eg

(QEMU) migrate-set-parameters tls-hostname=
Error while parsing command line: Expected a key=value pair, got 'tls-hostname='
command format: <command-name> [arg-name1=arg1] ... [arg-nameN=argN]

This is caused by checking the wrong condition after splitting the parameter on '='. The "partition" method will return "" for the separator field, if the seperator was not present, so that is the correct thing to check for malformed syntax.

Ah, good point.

Quoted 1 line
Quoted 20 lines
---
 scripts/qmp/qmp-shell | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
scripts/qmp/qmp-shell +2 -2
index 0373b24..eccb88a 100755
@@ -166,8 +166,8 @@ class QMPShell(qmp.QEMUMonitorProtocol):
 
     def __cli_expr(self, tokens, parent):
         for arg in tokens:
-            (key, _, val) = arg.partition('=')
-            if not val:
+            (key, sep, val) = arg.partition('=')
+            if sep != '=':
                 raise QMPShellError("Expected a key=value pair, got '%s'" % arg)
 
             value = self.__parse_value(val)
#3 lore raw
In reply to Daniel P. Berrange
Quoted 7 lines · Daniel P. Berrange

The qmp-shell property parser currently rejects attempts to set string properties to the empty string eg

(QEMU) migrate-set-parameters tls-hostname=
Error while parsing command line: Expected a key=value pair, got 'tls-hostname='
command format: <command-name> [arg-name1=arg1] ... [arg-nameN=argN]

Quoted 6 lines

This is caused by checking the wrong condition after splitting the parameter on '='. The "partition" method will return "" for the separator field, if the seperator was not present, so that is the correct thing to check for malformed syntax.

I'll take this through my tree, unless qemu-trivial beats me to the punch. Thanks!