Skip to content

Commit dab8100

Browse files
tonyhutterbehlendorf
authored andcommitted
ZTS: Add zfs/zpool JSON sanity tests
Run basic JSON validation tests on the new `zfs|zpool -j` output. Reviewed-by: Ameer Hamza <[email protected]> Reviewed-by: Umer Saleem <[email protected]> Signed-off-by: Tony Hutter <[email protected]> Closes #16217
1 parent 959e963 commit dab8100

File tree

6 files changed

+146
-0
lines changed

6 files changed

+146
-0
lines changed

tests/runfiles/common.run

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,10 @@ tests = [ 'clean_mirror_001_pos', 'clean_mirror_002_pos',
153153
'clean_mirror_003_pos', 'clean_mirror_004_pos']
154154
tags = ['functional', 'clean_mirror']
155155

156+
[tests/functional/cli_root/json]
157+
tests = ['json_sanity']
158+
tags = ['functional', 'cli_root', 'json']
159+
156160
[tests/functional/cli_root/zinject]
157161
tests = ['zinject_args']
158162
pre =

tests/zfs-tests/include/commands.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export SYSTEM_FILES_COMMON='awk
4646
hostname
4747
id
4848
iostat
49+
jq
4950
kill
5051
ksh
5152
ldd

tests/zfs-tests/tests/Makefile.am

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,9 @@ nobase_dist_datadir_zfs_tests_tests_SCRIPTS += \
606606
functional/clean_mirror/clean_mirror_004_pos.ksh \
607607
functional/clean_mirror/cleanup.ksh \
608608
functional/clean_mirror/setup.ksh \
609+
functional/cli_root/json/cleanup.ksh \
610+
functional/cli_root/json/setup.ksh \
611+
functional/cli_root/json/json_sanity.ksh \
609612
functional/cli_root/zinject/zinject_args.ksh \
610613
functional/cli_root/zdb/zdb_002_pos.ksh \
611614
functional/cli_root/zdb/zdb_003_pos.ksh \
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/ksh -p
2+
#
3+
# CDDL HEADER START
4+
#
5+
# The contents of this file are subject to the terms of the
6+
# Common Development and Distribution License (the "License").
7+
# You may not use this file except in compliance with the License.
8+
#
9+
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10+
# or https://opensource.org/licenses/CDDL-1.0.
11+
# See the License for the specific language governing permissions
12+
# and limitations under the License.
13+
#
14+
# When distributing Covered Code, include this CDDL HEADER in each
15+
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16+
# If applicable, add the following below this CDDL HEADER, with the
17+
# fields enclosed by brackets "[]" replaced with your own identifying
18+
# information: Portions Copyright [yyyy] [name of copyright owner]
19+
#
20+
# CDDL HEADER END
21+
#
22+
23+
# Copyright (c) 2024 by Lawrence Livermore National Security, LLC.
24+
25+
. $STF_SUITE/include/libtest.shlib
26+
27+
zpool destroy testpool1
28+
zpool destroy testpool2
29+
30+
rm $TESTDIR/file{1..28}
31+
rmdir $TESTDIR
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/bin/ksh -p
2+
#
3+
# CDDL HEADER START
4+
#
5+
# The contents of this file are subject to the terms of the
6+
# Common Development and Distribution License (the "License").
7+
# You may not use this file except in compliance with the License.
8+
#
9+
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10+
# or https://opensource.org/licenses/CDDL-1.0.
11+
# See the License for the specific language governing permissions
12+
# and limitations under the License.
13+
#
14+
# When distributing Covered Code, include this CDDL HEADER in each
15+
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16+
# If applicable, add the following below this CDDL HEADER, with the
17+
# fields enclosed by brackets "[]" replaced with your own identifying
18+
# information: Portions Copyright [yyyy] [name of copyright owner]
19+
#
20+
# CDDL HEADER END
21+
22+
# Copyright (c) 2024 by Lawrence Livermore National Security, LLC.
23+
24+
. $STF_SUITE/include/libtest.shlib
25+
26+
#
27+
# DESCRIPTION:
28+
# Basic sanity check for valid JSON from zfs & zpool commands.
29+
#
30+
# STRATEGY:
31+
# 1. Run different zfs/zpool -j commands and check for valid JSON
32+
33+
list=(
34+
"zpool status -j -g --json-int --json-flat-vdevs --json-pool-key-guid"
35+
"zpool status -p -j -g --json-int --json-flat-vdevs --json-pool-key-guid"
36+
"zpool status -j -c upath"
37+
"zpool status -j"
38+
"zpool status -j testpool1"
39+
"zpool list -j"
40+
"zpool list -j -g"
41+
"zpool list -j -o fragmentation"
42+
"zpool get -j size"
43+
"zpool get -j all"
44+
"zpool version -j"
45+
"zfs list -j"
46+
"zfs list -j testpool1"
47+
"zfs get -j all"
48+
"zfs get -j available"
49+
"zfs mount -j"
50+
"zfs version -j"
51+
)
52+
53+
for cmd in "${list[@]}" ; do
54+
log_must eval "$cmd | jq > /dev/null"
55+
done
56+
57+
log_pass "zpool and zfs commands outputted valid JSON"
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/bin/ksh -p
2+
#
3+
# CDDL HEADER START
4+
#
5+
# The contents of this file are subject to the terms of the
6+
# Common Development and Distribution License (the "License").
7+
# You may not use this file except in compliance with the License.
8+
#
9+
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10+
# or https://opensource.org/licenses/CDDL-1.0.
11+
# See the License for the specific language governing permissions
12+
# and limitations under the License.
13+
#
14+
# When distributing Covered Code, include this CDDL HEADER in each
15+
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16+
# If applicable, add the following below this CDDL HEADER, with the
17+
# fields enclosed by brackets "[]" replaced with your own identifying
18+
# information: Portions Copyright [yyyy] [name of copyright owner]
19+
#
20+
# CDDL HEADER END
21+
#
22+
23+
# Copyright (c) 2024 by Lawrence Livermore National Security, LLC.
24+
25+
. $STF_SUITE/include/libtest.shlib
26+
27+
# Sanity check that 'testpool1' or 'testpool2' don't exist
28+
log_mustnot zpool status -j | \
29+
jq -e '.pools | has("testpool1") or has("testpool2")' &> /dev/null
30+
31+
mkdir -p $TESTDIR
32+
truncate -s 80M $TESTDIR/file{1..28}
33+
34+
DISK=${DISKS%% *}
35+
36+
# Create complex pool configs to exercise JSON
37+
zpool create -f testpool1 draid $TESTDIR/file{1..10} \
38+
special $DISK \
39+
dedup $TESTDIR/file11 \
40+
special $TESTDIR/file12 \
41+
cache $TESTDIR/file13 \
42+
log $TESTDIR/file14
43+
44+
zpool create -f testpool2 mirror $TESTDIR/file{15,16} \
45+
raidz1 $TESTDIR/file{17,18,19} \
46+
cache $TESTDIR/file20 \
47+
log $TESTDIR/file21 \
48+
special mirror $TESTDIR/file{22,23} \
49+
dedup mirror $TESTDIR/file{24,25} \
50+
spare $TESTDIR/file{26,27,28}

0 commit comments

Comments
 (0)