Skip to content

Commit

Permalink
ZTS: test clearing pool and vdev userprops
Browse files Browse the repository at this point in the history
Confirming that clearing pool and vdev userprops produce the same
result: an empty value, with default source.

Sponsored-by: Klara, Inc.
Sponsored-by: Wasabi Technology, Inc.
Reviewed-by: Brian Behlendorf <[email protected]>
Reviewed-by: Alexander Motin <[email protected]>
Signed-off-by: Rob Norris <[email protected]>
Closes #16887
  • Loading branch information
robn authored and behlendorf committed Dec 29, 2024
1 parent 03b7cfd commit c4e5fa5
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 3 deletions.
3 changes: 2 additions & 1 deletion tests/runfiles/common.run
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,8 @@ tags = ['functional', 'cli_root', 'zpool_scrub']
[tests/functional/cli_root/zpool_set]
tests = ['zpool_set_001_pos', 'zpool_set_002_neg', 'zpool_set_003_neg',
'zpool_set_ashift', 'zpool_set_features', 'vdev_set_001_pos',
'user_property_001_pos', 'user_property_002_neg']
'user_property_001_pos', 'user_property_002_neg',
'zpool_set_clear_userprop']
tags = ['functional', 'cli_root', 'zpool_set']

[tests/functional/cli_root/zpool_split]
Expand Down
1 change: 1 addition & 0 deletions tests/zfs-tests/tests/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -1243,6 +1243,7 @@ nobase_dist_datadir_zfs_tests_tests_SCRIPTS += \
functional/cli_root/zpool_set/user_property_001_pos.ksh \
functional/cli_root/zpool_set/user_property_002_neg.ksh \
functional/cli_root/zpool_set/zpool_set_features.ksh \
functional/cli_root/zpool_set/zpool_set_clear_userprop.ksh \
functional/cli_root/zpool_split/cleanup.ksh \
functional/cli_root/zpool_split/setup.ksh \
functional/cli_root/zpool_split/zpool_split_cliargs.ksh \
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/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, Klara, Inc.
#

. $STF_SUITE/tests/functional/cli_root/zpool_set/zpool_set_common.kshlib

verify_runnable "both"

log_assert "Setting a user-defined property to the empty string removes it."
log_onexit cleanup_user_prop $TESTPOOL

log_must zpool set cool:pool=hello $TESTPOOL
log_must check_user_prop $TESTPOOL cool:pool hello local
log_must zpool set cool:pool= $TESTPOOL
log_must check_user_prop $TESTPOOL cool:pool '-' default

log_must zpool set cool:vdev=goodbye $TESTPOOL root
log_must check_vdev_user_prop $TESTPOOL root cool:vdev goodbye local
log_must zpool set cool:vdev= $TESTPOOL root
log_must check_vdev_user_prop $TESTPOOL root cool:vdev '-' default

log_pass "Setting a user-defined property to the empty string removes it."
Original file line number Diff line number Diff line change
Expand Up @@ -160,19 +160,55 @@ function user_property_value
random_string ALL_CHAR $len
}

function _check_user_prop
{
typeset pool="$1"
typeset vdev="$2"
typeset user_prop="$3"
typeset expect_value="$4"
typeset expect_source="$5"

typeset -a \
v=($(zpool get -p -H -o value,source "$user_prop" $pool $vdev 2>&1))

[[ "$expect_value" == "${v[0]}" && \
-z "$expect_source" || "$expect_source" == "${v[1]}" ]]
}

#
# Check if the user-defined property is identical to the expected value.
#
# $1 pool
# $2 user property
# $3 expected value
# $4 expected source (optional)
#
function check_user_prop
{
typeset pool=$1
typeset user_prop="$2"
typeset expect_value="$3"
typeset value=$(zpool get -p -H -o value "$user_prop" $pool 2>&1)
typeset expect_source="${4:-}"

_check_user_prop $pool '' $user_prop $expect_value $expect_source
}

#
# Check if the user-defined property is identical to the expected value.
#
# $1 pool
# $2 vdev
# $3 user property
# $4 expected value
# $5 expected source (optional)
#
function check_vdev_user_prop
{
typeset pool="$1"
typeset vdev="$2"
typeset user_prop="$3"
typeset expect_value="$4"
typeset expect_source="${5:-}"

[ "$expect_value" = "$value" ]
_check_user_prop $pool $vdev $user_prop $expect_value $expect_source
}

0 comments on commit c4e5fa5

Please sign in to comment.