Skip to content

Commit

Permalink
ZTS: Add zfs/zpool JSON sanity tests
Browse files Browse the repository at this point in the history
Run basic JSON validation tests on the new `zfs|zpool -j` output.

Signed-off-by: Tony Hutter <[email protected]>
  • Loading branch information
tonyhutter authored and usaleem-ix committed Jul 26, 2024
1 parent 32edec5 commit 01bd647
Show file tree
Hide file tree
Showing 6 changed files with 146 additions and 0 deletions.
4 changes: 4 additions & 0 deletions tests/runfiles/common.run
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ tests = [ 'clean_mirror_001_pos', 'clean_mirror_002_pos',
'clean_mirror_003_pos', 'clean_mirror_004_pos']
tags = ['functional', 'clean_mirror']

[tests/functional/cli_root/json]
tests = ['json_sanity']
tags = ['functional', 'cli_root', 'json']

[tests/functional/cli_root/zinject]
tests = ['zinject_args']
pre =
Expand Down
1 change: 1 addition & 0 deletions tests/zfs-tests/include/commands.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export SYSTEM_FILES_COMMON='awk
hostname
id
iostat
jq
kill
ksh
ldd
Expand Down
3 changes: 3 additions & 0 deletions tests/zfs-tests/tests/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,9 @@ nobase_dist_datadir_zfs_tests_tests_SCRIPTS += \
functional/clean_mirror/clean_mirror_004_pos.ksh \
functional/clean_mirror/cleanup.ksh \
functional/clean_mirror/setup.ksh \
functional/cli_root/json/cleanup.ksh \
functional/cli_root/json/setup.ksh \
functional/cli_root/json/json_sanity.ksh \
functional/cli_root/zinject/zinject_args.ksh \
functional/cli_root/zdb/zdb_002_pos.ksh \
functional/cli_root/zdb/zdb_003_pos.ksh \
Expand Down
31 changes: 31 additions & 0 deletions tests/zfs-tests/tests/functional/cli_root/json/cleanup.ksh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/ksh -p
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# or https://opensource.org/licenses/CDDL-1.0.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#

# Copyright (c) 2024 by Lawrence Livermore National Security, LLC.

. $STF_SUITE/include/libtest.shlib

zpool destroy testpool1
zpool destroy testpool2

rm $TESTDIR/file{1..28}
rmdir $TESTDIR
57 changes: 57 additions & 0 deletions tests/zfs-tests/tests/functional/cli_root/json/json_sanity.ksh
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/bin/ksh -p
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# or https://opensource.org/licenses/CDDL-1.0.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END

# Copyright (c) 2024 by Lawrence Livermore National Security, LLC.

. $STF_SUITE/include/libtest.shlib

#
# DESCRIPTION:
# Basic sanity check for valid JSON from zfs & zpool commands.
#
# STRATEGY:
# 1. Run different zfs/zpool -j commands and check for valid JSON

list=(
"zpool status -j -g --json-int --json-flat-vdevs --json-pool-key-guid"
"zpool status -p -j -g --json-int --json-flat-vdevs --json-pool-key-guid"
"zpool status -j -c upath"
"zpool status -j"
"zpool status -j testpool1"
"zpool list -j"
"zpool list -j -g"
"zpool list -j -o fragmentation"
"zpool get -j size"
"zpool get -j all"
"zpool version -j"
"zfs list -j"
"zfs list -j testpool1"
"zfs get -j all"
"zfs get -j available"
"zfs mount -j"
"zfs version -j"
)

for cmd in "${list[@]}" ; do
log_must eval "$cmd | jq > /dev/null"
done

log_pass "zpool and zfs commands outputted valid JSON"
50 changes: 50 additions & 0 deletions tests/zfs-tests/tests/functional/cli_root/json/setup.ksh
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/bin/ksh -p
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# or https://opensource.org/licenses/CDDL-1.0.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#

# Copyright (c) 2024 by Lawrence Livermore National Security, LLC.

. $STF_SUITE/include/libtest.shlib

# Sanity check that 'testpool1' or 'testpool2' don't exist
log_mustnot zpool status -j | \
jq -e '.pools | has("testpool1") or has("testpool2")' &> /dev/null

mkdir -p $TESTDIR
truncate -s 80M $TESTDIR/file{1..28}

DISK=${DISKS%% *}

# Create complex pool configs to exercise JSON
zpool create -f testpool1 draid $TESTDIR/file{1..10} \
special $DISK \
dedup $TESTDIR/file11 \
special $TESTDIR/file12 \
cache $TESTDIR/file13 \
log $TESTDIR/file14

zpool create -f testpool2 mirror $TESTDIR/file{15,16} \
raidz1 $TESTDIR/file{17,18,19} \
cache $TESTDIR/file20 \
log $TESTDIR/file21 \
special mirror $TESTDIR/file{22,23} \
dedup mirror $TESTDIR/file{24,25} \
spare $TESTDIR/file{26,27,28}

0 comments on commit 01bd647

Please sign in to comment.