]>
git.proxmox.com Git - mirror_zfs.git/blob - tests/zfs-tests/tests/functional/cli_root/zfs_program/zfs_program_json.ksh
5 # This file and its contents are supplied under the terms of the
6 # Common Development and Distribution License ("CDDL"), version 1.0.
7 # You may only use this file in accordance with the terms of version
10 # A full copy of the text of the CDDL should have accompanied this
11 # source. A copy is of the CDDL is also available via the Internet
12 # at http://www.illumos.org/license/CDDL.
18 # Copyright (c) 2018 Datto Inc.
19 # Copyright (c) 2019 by Delphix. All rights reserved.
22 .
$STF_SUITE/include
/libtest.shlib
28 # 1. Compare JSON output formatting for a channel program to template
29 # 2. Using bad command line option (-Z) gives correct error output
32 verify_runnable
"both"
36 log_must zfs destroy
$TESTDS
41 log_assert
"Channel programs output valid JSON"
43 TESTDS
="$TESTPOOL/zcp-json"
44 log_must zfs create
$TESTDS
46 TESTZCP
="/$TESTDS/zfs_rlist.zcp"
47 cat > "$TESTZCP" << EOF
51 function list_recursive(root, prop)
52 for child in zfs.list.children(root) do
53 list_recursive(child, prop)
55 val, src = zfs.get_prop(root, prop)
67 list_recursive(argv[1], argv[2])
70 results["succeeded"] = succeeded
71 results["failed"] = failed
75 # 1. Compare JSON output formatting for a channel program to template
76 typeset
-a pos_cmds
=("recordsize" "type")
77 typeset
-a pos_cmds_out
=(
90 \"$TESTDS\": \"filesystem\"
96 for cmd
in ${pos_cmds[@]}; do
97 log_must zfs program
$TESTPOOL $TESTZCP $TESTDS $cmd 2>&1
98 log_must zfs program
$TESTPOOL -j $TESTZCP $TESTDS $cmd 2>&1
99 # json.tool is needed to guarantee consistent ordering of fields
100 # sed is needed to trim trailing space in CentOS 6's json.tool output
101 OUTPUT
=$
(zfs program
$TESTPOOL -j $TESTZCP $TESTDS $cmd 2>&1 | python
-m json.tool |
sed 's/[[:space:]]*$//')
102 if [ "$OUTPUT" != "${pos_cmds_out[$cnt]}" ]; then
103 log_note
"Got :$OUTPUT"
104 log_note
"Expected:${pos_cmds_out[$cnt]}"
105 log_fail
"Unexpected channel program output";
110 # 2. Using bad command line option (-Z) gives correct error output
111 typeset
-a neg_cmds
=("-Z")
112 typeset
-a neg_cmds_out
=(
115 program [-jn] [-t <instruction limit>] [-m <memory limit (b)>]
116 <pool> <program file> [lua args...]
118 For the property list, run: zfs set|get
120 For the delegated permission list, run: zfs allow|unallow")
122 for cmd
in ${neg_cmds[@]}; do
123 log_mustnot zfs program
$TESTPOOL $TESTZCP $TESTDS $cmd 2>&1
124 log_mustnot zfs program
$TESTPOOL -j $TESTZCP $TESTDS $cmd 2>&1
125 OUTPUT
=$
(zfs program
$TESTPOOL -j $TESTZCP $TESTDS $cmd 2>&1)
126 if [ "$OUTPUT" != "${neg_cmds_out[$cnt]}" ]; then
127 log_note
"Got :$OUTPUT"
128 log_note
"Expected:${neg_cmds_out[$cnt]}"
129 log_fail
"Unexpected channel program error output";
134 log_pass
"Channel programs output valid JSON"