[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH v5 07/11] iotests: add qmp recursive sorting fun
Re: [Qemu-devel] [PATCH v5 07/11] iotests: add qmp recursive sorting function
Wed, 19 Dec 2018 20:40:26 -0600
Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.3.1
On 12/19/18 8:29 PM, John Snow wrote:
Python before 3.6 does not sort dictionaries (including kwargs).
Therefore, printing QMP objects involves sorting the keys to have
a predictable ordering in the iotests output.
It may be worth also mentioning that sometimes this sorting results in
the log showing things in a different order than the source command
(with no ill effect, as long as the output order is deterministic).
However, if we want to pretty-print QMP objects being sent to the
QEMU process, we need to build the entire command before logging it.
Ordinarily, this would then involve "arguments" being sorted above
"execute", which would necessitate a rather ugly and harder-to-read
change to many iotests outputs.
To facilitate pretty-printing AND maintaining predictable output AND
having "arguments" sort before "execute", add a custom sort function
that takes a dictionary and recursively builds an OrderedDict that
maintains the specific key order we wish to see in iotests output.
namely, keys within subdicts are sorted by key name (even if that is not
the order they were input), but the top-level struct with "execute" and
"arguments" stays the way we want it.
Signed-off-by: John Snow <address@hidden>
tests/qemu-iotests/iotests.py | 24 ++++++++++++++++++++----
1 file changed, 20 insertions(+), 4 deletions(-)
Reviewed-by: Eric Blake <address@hidden>
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3266
Virtualization: qemu.org | libvirt.org
- Re: [Qemu-devel] [PATCH v5 03/11] blockdev: n-ary bitmap merge, (continued)
- [Qemu-devel] [PATCH v5 04/11] block: remove 'x' prefix from experimental bitmap APIs, John Snow, 2018/12/19
- [Qemu-devel] [PATCH v5 06/11] iotests: add filter_generated_node_ids, John Snow, 2018/12/19
- [Qemu-devel] [PATCH v5 05/11] iotests.py: don't abort if IMGKEYSECRET is undefined, John Snow, 2018/12/19
- [Qemu-devel] [PATCH v5 08/11] iotests: remove default filters from qmp_log, John Snow, 2018/12/19
- [Qemu-devel] [PATCH v5 07/11] iotests: add qmp recursive sorting function, John Snow, 2018/12/19
- [Qemu-devel] [PATCH v5 10/11] iotests: implement pretty-print for log and qmp_log, John Snow, 2018/12/19
- [Qemu-devel] [PATCH v5 09/11] iotests: change qmp_log filters to expect QMP objects only, John Snow, 2018/12/19
- [Qemu-devel] [PATCH v5 11/11] iotests: add iotest 236 for testing bitmap merge, John Snow, 2018/12/19