qapi: Unify type bypass and add tests
authorEric Blake <eblake@redhat.com>
Mon, 4 May 2015 15:05:19 +0000 (09:05 -0600)
committerMarkus Armbruster <armbru@redhat.com>
Tue, 5 May 2015 16:39:01 +0000 (18:39 +0200)
For a few QMP commands, we are forced to pass an arbitrary type
without tracking it properly in QAPI.  Among the existing clients,
this unnamed type was spelled 'dict', 'visitor', and '**'; this
patch standardizes on '**', matching the documentation changes
earlier in the series.

Meanwhile, for the 'gen' key, we have been ignoring the value,
although the schema consistently used "'no'" ('success-response'
was hard-coded to checking for 'no').  But now that we can support
a literal "false" in the schema, we might as well use that rather
than ignoring the value or special-casing a random string.  Note
that these are one-way switches (use of 'gen':true is not the same
as omitting 'gen'). Also, the use of '**' requires 'gen':false,
but the use of 'gen':false does not mandate the use of '**'.

There is no difference to the generated code.  Add some tests on
what we'd like to guarantee, although it will take later patches
to clean up test results and actually enforce the use of a bool
parameter.

Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
16 files changed:
qapi-schema.json
qga/qapi-schema.json
scripts/qapi-commands.py
tests/Makefile
tests/qapi-schema/type-bypass-bad-gen.err [new file with mode: 0644]
tests/qapi-schema/type-bypass-bad-gen.exit [new file with mode: 0644]
tests/qapi-schema/type-bypass-bad-gen.json [new file with mode: 0644]
tests/qapi-schema/type-bypass-bad-gen.out [new file with mode: 0644]
tests/qapi-schema/type-bypass-no-gen.err [new file with mode: 0644]
tests/qapi-schema/type-bypass-no-gen.exit [new file with mode: 0644]
tests/qapi-schema/type-bypass-no-gen.json [new file with mode: 0644]
tests/qapi-schema/type-bypass-no-gen.out [new file with mode: 0644]
tests/qapi-schema/type-bypass.err [new file with mode: 0644]
tests/qapi-schema/type-bypass.exit [new file with mode: 0644]
tests/qapi-schema/type-bypass.json [new file with mode: 0644]
tests/qapi-schema/type-bypass.out [new file with mode: 0644]

index ac9594d66dfe36c49f7bb9a300e8228de6eb9573..7f4cf86ee508dedfdb47a1e76069f164b1874c25 100644 (file)
 ##
 { 'command': 'qom-get',
   'data': { 'path': 'str', 'property': 'str' },
-  'returns': 'visitor',
-  'gen': 'no' }
+  'returns': '**',
+  'gen': false }
 
 ##
 # @qom-set:
 # Since: 1.2
 ##
 { 'command': 'qom-set',
-  'data': { 'path': 'str', 'property': 'str', 'value': 'visitor' },
-  'gen': 'no' }
+  'data': { 'path': 'str', 'property': 'str', 'value': '**' },
+  'gen': false }
 
 ##
 # @set_password:
 ##
 { 'command': 'netdev_add',
   'data': {'type': 'str', 'id': 'str', '*props': '**'},
-  'gen': 'no' }
+  'gen': false }
 
 ##
 # @netdev_del:
 # Since: 2.0
 ##
 { 'command': 'object-add',
-  'data': {'qom-type': 'str', 'id': 'str', '*props': 'dict'},
-  'gen': 'no' }
+  'data': {'qom-type': 'str', 'id': 'str', '*props': '**'},
+  'gen': false }
 
 ##
 # @object-del:
index 5c4cd40a92b971c3a7f76cb31ec7b0fd257235ef..fecc4427d59637a31be5f3980d2bc077a501bc1c 100644 (file)
 # Since: 0.15.0
 ##
 { 'command': 'guest-shutdown', 'data': { '*mode': 'str' },
-  'success-response': 'no' }
+  'success-response': false }
 
 ##
 # @guest-file-open:
 #
 # Since: 1.1
 ##
-{ 'command': 'guest-suspend-disk', 'success-response': 'no' }
+{ 'command': 'guest-suspend-disk', 'success-response': false }
 
 ##
 # @guest-suspend-ram
 #
 # Since: 1.1
 ##
-{ 'command': 'guest-suspend-ram', 'success-response': 'no' }
+{ 'command': 'guest-suspend-ram', 'success-response': false }
 
 ##
 # @guest-suspend-hybrid
 #
 # Since: 1.1
 ##
-{ 'command': 'guest-suspend-hybrid', 'success-response': 'no' }
+{ 'command': 'guest-suspend-hybrid', 'success-response': false }
 
 ##
 # @GuestIpAddressType:
index 053ba85b5f17af721f192dc73f86e78fdedfee3a..cb786825ee91d6aa23a174252a56e5b94ee165e6 100644 (file)
@@ -2,7 +2,7 @@
 # QAPI command marshaller generator
 #
 # Copyright IBM, Corp. 2011
-# Copyright (C) 2014 Red Hat, Inc.
+# Copyright (C) 2014-2015 Red Hat, Inc.
 #
 # Authors:
 #  Anthony Liguori <aliguori@us.ibm.com>
@@ -293,17 +293,12 @@ out:
 
     return ret
 
-def option_value_matches(opt, val, cmd):
-    if opt in cmd and cmd[opt] == val:
-        return True
-    return False
-
 def gen_registry(commands):
     registry=""
     push_indent()
     for cmd in commands:
         options = 'QCO_NO_OPTIONS'
-        if option_value_matches('success-response', 'no', cmd):
+        if not cmd.get('success-response', True):
             options = 'QCO_NO_SUCCESS_RESP'
 
         registry += mcgen('''
index c27940c41792cb3060f0153034ab7deb884418f8..64e678502c200155ea8ff39b08c856ba5eb07311 100644 (file)
@@ -216,6 +216,7 @@ check-qapi-schema-y := $(addprefix tests/qapi-schema/, \
        bad-type-dict.json double-data.json unknown-expr-key.json \
        redefined-type.json redefined-command.json redefined-builtin.json \
        redefined-event.json command-int.json event-max.json \
+       type-bypass.json type-bypass-no-gen.json type-bypass-bad-gen.json \
        missing-colon.json missing-comma-list.json \
        missing-comma-object.json non-objects.json \
        qapi-schema-test.json quoted-structural-chars.json \
diff --git a/tests/qapi-schema/type-bypass-bad-gen.err b/tests/qapi-schema/type-bypass-bad-gen.err
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/tests/qapi-schema/type-bypass-bad-gen.exit b/tests/qapi-schema/type-bypass-bad-gen.exit
new file mode 100644 (file)
index 0000000..573541a
--- /dev/null
@@ -0,0 +1 @@
+0
diff --git a/tests/qapi-schema/type-bypass-bad-gen.json b/tests/qapi-schema/type-bypass-bad-gen.json
new file mode 100644 (file)
index 0000000..bb70bee
--- /dev/null
@@ -0,0 +1,2 @@
+# FIXME: 'gen' should only appear with value false
+{ 'command': 'foo', 'gen': 'whatever' }
diff --git a/tests/qapi-schema/type-bypass-bad-gen.out b/tests/qapi-schema/type-bypass-bad-gen.out
new file mode 100644 (file)
index 0000000..e678f2c
--- /dev/null
@@ -0,0 +1,3 @@
+[OrderedDict([('command', 'foo'), ('gen', 'whatever')])]
+[]
+[]
diff --git a/tests/qapi-schema/type-bypass-no-gen.err b/tests/qapi-schema/type-bypass-no-gen.err
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/tests/qapi-schema/type-bypass-no-gen.exit b/tests/qapi-schema/type-bypass-no-gen.exit
new file mode 100644 (file)
index 0000000..573541a
--- /dev/null
@@ -0,0 +1 @@
+0
diff --git a/tests/qapi-schema/type-bypass-no-gen.json b/tests/qapi-schema/type-bypass-no-gen.json
new file mode 100644 (file)
index 0000000..af87c19
--- /dev/null
@@ -0,0 +1,2 @@
+# FIXME: type bypass should only work with 'gen':false
+{ 'command': 'unsafe', 'data': { 'arg': '**' }, 'returns': '**' }
diff --git a/tests/qapi-schema/type-bypass-no-gen.out b/tests/qapi-schema/type-bypass-no-gen.out
new file mode 100644 (file)
index 0000000..8b2a9ac
--- /dev/null
@@ -0,0 +1,3 @@
+[OrderedDict([('command', 'unsafe'), ('data', OrderedDict([('arg', '**')])), ('returns', '**')])]
+[]
+[]
diff --git a/tests/qapi-schema/type-bypass.err b/tests/qapi-schema/type-bypass.err
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/tests/qapi-schema/type-bypass.exit b/tests/qapi-schema/type-bypass.exit
new file mode 100644 (file)
index 0000000..573541a
--- /dev/null
@@ -0,0 +1 @@
+0
diff --git a/tests/qapi-schema/type-bypass.json b/tests/qapi-schema/type-bypass.json
new file mode 100644 (file)
index 0000000..48b2137
--- /dev/null
@@ -0,0 +1,2 @@
+# Use of 'gen':false allows bypassing type system
+{ 'command': 'unsafe', 'data': { 'arg': '**' }, 'returns': '**', 'gen': false }
diff --git a/tests/qapi-schema/type-bypass.out b/tests/qapi-schema/type-bypass.out
new file mode 100644 (file)
index 0000000..eaf20f8
--- /dev/null
@@ -0,0 +1,3 @@
+[OrderedDict([('command', 'unsafe'), ('data', OrderedDict([('arg', '**')])), ('returns', '**'), ('gen', False)])]
+[]
+[]