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 <js...@redhat.com>
---
  tests/qemu-iotests/iotests.py | 24 ++++++++++++++++++++----
  1 file changed, 20 insertions(+), 4 deletions(-)

Reviewed-by: Eric Blake <ebl...@redhat.com>

--
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org

Reply via email to