20.12.2018 5:29, 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. > > 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.
I'm unsure about what it means 'build the entire command before logging'. [upd, after a second] aha, it's about '{"execute":...' -> {'execute': ...} may be, build the entire command object to be passed to json.dumps, or like this would be better, if you want. > > 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. > > Signed-off-by: John Snow<js...@redhat.com> Reviewed-by: Vladimir Sementsov-Ogievskiy <vsement...@virtuozzo.com> -- Best regards, Vladimir