Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ZTS: zfs_program_json #9774

Merged
merged 1 commit into from
Dec 27, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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]}"
Expand Down