summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorBrian Behlendorf <[email protected]>2019-12-27 12:12:41 -0800
committerGitHub <[email protected]>2019-12-27 12:12:41 -0800
commita6f6ef8bda9d012f3217acd2e94cf0dd445ae5c1 (patch)
tree45ffb9ef5eee9e805a9dc7a8b13c91565883fac6 /tests
parent590ff61a5520214c9ad7101c55d87adaa580e15e (diff)
ZTS: zfs_program_json
As of Python 3.5 the default behavior of json.tool was changed to preserve the input order rather than lexical order. The test case expects the output to be sorted so apply the --sort-keys option to the json.tool command when using Python 3.5 and the option is supported. https://docs.python.org/3/library/json.html#module-json.tool Reviewed-by: Kjeld Schouten <[email protected]> Signed-off-by: Brian Behlendorf <[email protected]> Closes #9774
Diffstat (limited to 'tests')
-rwxr-xr-xtests/zfs-tests/tests/functional/cli_root/zfs_program/zfs_program_json.ksh20
1 files changed, 17 insertions, 3 deletions
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_program/zfs_program_json.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_program/zfs_program_json.ksh
index 3d59f784a..3788543b0 100755
--- a/tests/zfs-tests/tests/functional/cli_root/zfs_program/zfs_program_json.ksh
+++ b/tests/zfs-tests/tests/functional/cli_root/zfs_program/zfs_program_json.ksh
@@ -91,14 +91,28 @@ typeset -a pos_cmds_out=(
}
}
}")
+
+#
+# N.B. json.tool is needed to guarantee consistent ordering of fields,
+# sed is needed to trim trailing space in CentOS 6's json.tool output
+#
+# As of Python 3.5 the behavior of json.tool changed to keep the order
+# the same as the input and the --sort-keys option was added. Detect when
+# --sort-keys is supported and apply the option to ensure the expected order.
+#
+if python -m json.tool --sort-keys <<< "{}"; then
+ JSON_TOOL_CMD="python -m json.tool --sort-keys"
+else
+ JSON_TOOL_CMD="python -m json.tool"
+fi
+
typeset -i cnt=0
typeset cmd
for cmd in ${pos_cmds[@]}; do
log_must zfs program $TESTPOOL $TESTZCP $TESTDS $cmd 2>&1
log_must zfs program -j $TESTPOOL $TESTZCP $TESTDS $cmd 2>&1
- # json.tool is needed to guarantee consistent ordering of fields
- # sed is needed to trim trailing space in CentOS 6's json.tool output
- OUTPUT=$(zfs program -j $TESTPOOL $TESTZCP $TESTDS $cmd 2>&1 | python -m json.tool | sed 's/[[:space:]]*$//')
+ OUTPUT=$(zfs program -j $TESTPOOL $TESTZCP $TESTDS $cmd 2>&1 |
+ $JSON_TOOL_CMD | sed 's/[[:space:]]*$//')
if [ "$OUTPUT" != "${pos_cmds_out[$cnt]}" ]; then
log_note "Got :$OUTPUT"
log_note "Expected:${pos_cmds_out[$cnt]}"