Skip to contentSkip to conversation

QAPI schema: turn example commands/returns into proper JSON

PATCH In review Cleber Rosa 3 participants 5 messages Aug 8, 2017 – Aug 14, 2017

lore
Share & tools
lore
#0 lore raw

cover QAPI schema: turn example commands/returns into proper JSON

The QAPI schema documentation sections contain examples of QMP input and output. These are supposed to follow the "JSON-based" wire protocol, but in practice, there are a few data structure problems and also documentation.

This turns all inputs and outputs into parseable JSON-like data. Besides allowing humans to copy and paste the examples without surprises, this also paves the way towards automatic execution of examples as tests.

Cleber Rosa(1):
QAPI schema: turn example commands/returns into proper JSON

 qapi-schema.json     |  9 ++++-----
 qapi/block-core.json | 32 ++++++++++++++++----------------
 qapi/rocker.json     |  5 +----
 3 files changed, 21 insertions(+), 25 deletions(-)
#1 lore raw

PATCH 1/1 QAPI schema: turn example commands/returns into proper JSON

Most QMP commands and returns in the QAPI schema documentation are valid "JSON-based wire format". A few examples are either malformed, or contain comments.

This fixes all the examples command and return data, making them proper JSON, as they would be received and generated by QEMU's QMP monitor.

---
 qapi-schema.json     |  9 ++++-----
 qapi/block-core.json | 32 ++++++++++++++++----------------
 qapi/rocker.json     |  5 +----
 3 files changed, 21 insertions(+), 25 deletions(-)
qapi-schema.json +4 -5
index 802ea53d00..78c1e8cbde 100644
@@ -2000,8 +2000,7 @@
 #                "host": "127.0.0.1",
 #                "channel-id": 0,
 #                "tls": false
-#             },
-#             [ ... more channels follow ... ]
+#             }
 #          ]
 #       }
 #    }
@@ -2039,7 +2038,7 @@
 #
 # -> { "execute": "query-balloon" }
 # <- { "return": {
-#          "actual": 1073741824,
+#          "actual": 1073741824
 #       }
 #    }
 #
@@ -3536,7 +3535,7 @@
 #
 # -> { "execute": "query-dump-guest-memory-capability" }
 # <- { "return": { "formats":
-#                  ["elf", "kdump-zlib", "kdump-lzo", "kdump-snappy"] }
+#                  ["elf", "kdump-zlib", "kdump-lzo", "kdump-snappy"] } }
 #
 ##
 { 'command': 'query-dump-guest-memory-capability',
@@ -6500,7 +6499,7 @@
 #        "vcpus-count": 1 },
 #      { "props": { "core": 0 }, "type": "POWER8-spapr-cpu-core",
 #        "vcpus-count": 1, "qom-path": "/machine/unattached/device[0]"}
-#    ]}'
+#    ]}
 #
 # For pc machine type started with -smp 1,maxcpus=2:
 #
qapi/block-core.json +16 -16
index 833c602150..ab273a4729 100644
@@ -801,10 +801,10 @@
 #                   "wr_bytes":9786368,
 #                   "wr_operations":751,
 #                   "rd_bytes":122567168,
-#                   "rd_operations":36772
-#                   "wr_total_times_ns":313253456
-#                   "rd_total_times_ns":3465673657
-#                   "flush_total_times_ns":49653
+#                   "rd_operations":36772,
+#                   "wr_total_times_ns":313253456,
+#                   "rd_total_times_ns":3465673657,
+#                   "flush_total_times_ns":49653,
 #                   "flush_operations":61,
 #                   "rd_merged":0,
 #                   "wr_merged":0,
@@ -818,10 +818,10 @@
 #                "wr_bytes":9786368,
 #                "wr_operations":692,
 #                "rd_bytes":122739200,
-#                "rd_operations":36604
+#                "rd_operations":36604,
 #                "flush_operations":51,
-#                "wr_total_times_ns":313253456
-#                "rd_total_times_ns":3465673657
+#                "wr_total_times_ns":313253456,
+#                "rd_total_times_ns":3465673657,
 #                "flush_total_times_ns":49653,
 #                "rd_merged":0,
 #                "wr_merged":0,
@@ -837,10 +837,10 @@
 #                "wr_bytes":0,
 #                "wr_operations":0,
 #                "rd_bytes":0,
-#                "rd_operations":0
+#                "rd_operations":0,
 #                "flush_operations":0,
-#                "wr_total_times_ns":0
-#                "rd_total_times_ns":0
+#                "wr_total_times_ns":0,
+#                "rd_total_times_ns":0,
 #                "flush_total_times_ns":0,
 #                "rd_merged":0,
 #                "wr_merged":0,
@@ -855,10 +855,10 @@
 #                "wr_bytes":0,
 #                "wr_operations":0,
 #                "rd_bytes":0,
-#                "rd_operations":0
+#                "rd_operations":0,
 #                "flush_operations":0,
-#                "wr_total_times_ns":0
-#                "rd_total_times_ns":0
+#                "wr_total_times_ns":0,
+#                "rd_total_times_ns":0,
 #                "flush_total_times_ns":0,
 #                "rd_merged":0,
 #                "wr_merged":0,
@@ -873,10 +873,10 @@
 #                "wr_bytes":0,
 #                "wr_operations":0,
 #                "rd_bytes":0,
-#                "rd_operations":0
+#                "rd_operations":0,
 #                "flush_operations":0,
-#                "wr_total_times_ns":0
-#                "rd_total_times_ns":0
+#                "wr_total_times_ns":0,
+#                "rd_total_times_ns":0,
 #                "flush_total_times_ns":0,
 #                "rd_merged":0,
 #                "wr_merged":0,
qapi/rocker.json +1 -4
index 3587661161..345863b600 100644
@@ -249,10 +249,7 @@
 #                   "hits": 138,
 #                   "cookie": 0,
 #                   "action": {"goto-tbl": 10},
-#                   "mask": {"in-pport": 4294901760}
-#                  },
-#                  {...more...},
-#    ]}
+#                   "mask": {"in-pport": 4294901760} } ] }
 #
 ##
 { 'command': 'query-rocker-of-dpa-flows',
Signature · 1 line
2.13.4
Reviewed-by on v1 1/1
#2 lore raw
Quoted 18 lines · Cleber Rosa

Most QMP commands and returns in the QAPI schema documentation are valid "JSON-based wire format". A few examples are either malformed, or contain comments.

This fixes all the examples command and return data, making them proper JSON, as they would be received and generated by QEMU's QMP monitor.

---
 qapi-schema.json     |  9 ++++-----
 qapi/block-core.json | 32 ++++++++++++++++----------------
 qapi/rocker.json     |  5 +----
 3 files changed, 21 insertions(+), 25 deletions(-)

+++ b/qapi-schema.json

qapi-schema.json line 2003

Quoted 6 lines
qapi-schema.json +1 -2
@@ -2000,8 +2000,7 @@
 #                "host": "127.0.0.1",
 #                "channel-id": 0,
 #                "tls": false
-#             },
-#             [ ... more channels follow ... ]
+#             }

I still wonder if we want SOME sort of markup to make it obvious where we are compressing the example for the sake of brevity, where whatever we use to automate tests based on the docs would know how to recognize that the actual values given in reply to the test can be longer than the documented example. But I guess we can cross that when we have an automated test where it matters.

qapi-schema.json line 2042

Quoted 7 lines
qapi-schema.json +1 -1
@@ -2039,7 +2038,7 @@
 #
 # -> { "execute": "query-balloon" }
 # <- { "return": {
-#          "actual": 1073741824,
+#          "actual": 1073741824
 #       }

I also suspect that test automation will have to do a lot of filtering, even for commands that don't need to be abbreviated, since some of the examples have pretty arbitrary numbers that will be difficult to reliably reproduce any particular number.

This is a documentation fix, so it could still go in 2.10 - but since we are past -rc2, it's probably just as easy to save it for 2.11. Either way,

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org
#3 lore raw
Quoted 17 lines · Eric Blake
Quoted 14 lines · Cleber Rosa

Most QMP commands and returns in the QAPI schema documentation are valid "JSON-based wire format". A few examples are either malformed, or contain comments.

This fixes all the examples command and return data, making them proper JSON, as they would be received and generated by QEMU's QMP monitor.

---
 qapi-schema.json     |  9 ++++-----
 qapi/block-core.json | 32 ++++++++++++++++----------------
 qapi/rocker.json     |  5 +----
 3 files changed, 21 insertions(+), 25 deletions(-)
Quoted 16 lines

qapi-schema.json line 2003

Quoted 8 lines

+++ b/qapi-schema.json

qapi-schema.json +1 -2
@@ -2000,8 +2000,7 @@
 #                "host": "127.0.0.1",
 #                "channel-id": 0,
 #                "tls": false
-#             },
-#             [ ... more channels follow ... ]
+#             }

I still wonder if we want SOME sort of markup to make it obvious where we are compressing the example for the sake of brevity, where whatever we use to automate tests based on the docs would know how to recognize that the actual values given in reply to the test can be longer than the documented example. But I guess we can cross that when we have an automated test where it matters.

I wonder the same. Also, we seem to agree that it's a separate and more complex problem, to be tackled later.

Quoted 4 lines
Quoted 4 lines
qapi-schema.json +0 -0
@@ -2039,7 +2038,7 @@
 #
 # -> { "execute": "query-balloon" }
 # <- { "return": {
Quoted 9 lines

qapi-schema.json line 2042

Quoted 3 lines
qapi-schema.json +1 -1
-#          "actual": 1073741824,
+#          "actual": 1073741824
 #       }

I also suspect that test automation will have to do a lot of filtering, even for commands that don't need to be abbreviated, since some of the examples have pretty arbitrary numbers that will be difficult to reliably reproduce any particular number.

Yes. I'm already aware of a couple of use cases that will require different types of comparison, including pretty relaxed ones. Expect more about that in a later thread.

Quoted 5 lines

This is a documentation fix, so it could still go in 2.10 - but since we are past -rc2, it's probably just as easy to save it for 2.11. Either way,

Thanks for the prompt review!

Signature · 4 lines
Cleber Rosa
[ Sr Software Engineer - Virtualization Team - Red Hat ]
[ Avocado Test Framework - avocado-framework.github.io ]
[  7ABB 96EB 8B46 B94D 5E0F  E9BB 657E 8D33 A5F2 09F3  ]
#4 lore raw
Quoted 35 lines · Cleber Rosa
Quoted 17 lines · Eric Blake
Quoted 14 lines · Cleber Rosa

Most QMP commands and returns in the QAPI schema documentation are valid "JSON-based wire format". A few examples are either malformed, or contain comments.

This fixes all the examples command and return data, making them proper JSON, as they would be received and generated by QEMU's QMP monitor.

---
 qapi-schema.json     |  9 ++++-----
 qapi/block-core.json | 32 ++++++++++++++++----------------
 qapi/rocker.json     |  5 +----
 3 files changed, 21 insertions(+), 25 deletions(-)
Quoted 16 lines

qapi-schema.json line 2003

Quoted 8 lines

+++ b/qapi-schema.json

qapi-schema.json +1 -2
@@ -2000,8 +2000,7 @@
 #                "host": "127.0.0.1",
 #                "channel-id": 0,
 #                "tls": false
-#             },
-#             [ ... more channels follow ... ]
+#             }

I still wonder if we want SOME sort of markup to make it obvious where we are compressing the example for the sake of brevity, where whatever we use to automate tests based on the docs would know how to recognize that the actual values given in reply to the test can be longer than the documented example. But I guess we can cross that when we have an automated test where it matters.

Quoted 2 lines

I wonder the same. Also, we seem to agree that it's a separate and more complex problem, to be tackled later.

We can cross that bridge when we get to it.

Any particular reason not to keep the [ ... more channels follow ... ] until then?

Quoted 7 lines
Quoted 7 lines

qapi-schema.json line 2042

Quoted 7 lines
qapi-schema.json +1 -1
@@ -2039,7 +2038,7 @@
 #
 # -> { "execute": "query-balloon" }
 # <- { "return": {
-#          "actual": 1073741824,
+#          "actual": 1073741824
 #       }

This is a straighforward doc fix.

Quoted 17 lines
Quoted 5 lines

I also suspect that test automation will have to do a lot of filtering, even for commands that don't need to be abbreviated, since some of the examples have pretty arbitrary numbers that will be difficult to reliably reproduce any particular number.

Yes. I'm already aware of a couple of use cases that will require different types of comparison, including pretty relaxed ones. Expect more about that in a later thread.

Quoted 5 lines

This is a documentation fix, so it could still go in 2.10 - but since we are past -rc2, it's probably just as easy to save it for 2.11. Either way,

Thanks for the prompt review!