diff --git a/tests/runfiles/common.run b/tests/runfiles/common.run index ac2c541a9188..f85e5157b53c 100644 --- a/tests/runfiles/common.run +++ b/tests/runfiles/common.run @@ -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 = diff --git a/tests/zfs-tests/include/commands.cfg b/tests/zfs-tests/include/commands.cfg index daa794551682..19770138bf14 100644 --- a/tests/zfs-tests/include/commands.cfg +++ b/tests/zfs-tests/include/commands.cfg @@ -46,6 +46,7 @@ export SYSTEM_FILES_COMMON='awk hostname id iostat + jq kill ksh ldd diff --git a/tests/zfs-tests/tests/Makefile.am b/tests/zfs-tests/tests/Makefile.am index 00f306122daa..b9a489e9fdc1 100644 --- a/tests/zfs-tests/tests/Makefile.am +++ b/tests/zfs-tests/tests/Makefile.am @@ -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 \ diff --git a/tests/zfs-tests/tests/functional/cli_root/json/cleanup.ksh b/tests/zfs-tests/tests/functional/cli_root/json/cleanup.ksh new file mode 100755 index 000000000000..f82a90962292 --- /dev/null +++ b/tests/zfs-tests/tests/functional/cli_root/json/cleanup.ksh @@ -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 diff --git a/tests/zfs-tests/tests/functional/cli_root/json/json_sanity.ksh b/tests/zfs-tests/tests/functional/cli_root/json/json_sanity.ksh new file mode 100755 index 000000000000..e598dd57181e --- /dev/null +++ b/tests/zfs-tests/tests/functional/cli_root/json/json_sanity.ksh @@ -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" diff --git a/tests/zfs-tests/tests/functional/cli_root/json/setup.ksh b/tests/zfs-tests/tests/functional/cli_root/json/setup.ksh new file mode 100755 index 000000000000..f94dc5697423 --- /dev/null +++ b/tests/zfs-tests/tests/functional/cli_root/json/setup.ksh @@ -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}