qemu-block
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-block] [PATCH v5 07/11] iotests: add qmp recursive sorting fun


From: Eric Blake
Subject: Re: [Qemu-block] [PATCH v5 07/11] iotests: add qmp recursive sorting function
Date: Wed, 19 Dec 2018 20:40:26 -0600
User-agent: 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

s/before/after/

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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]