Skip to content

Commit c4e5fa5

Browse files
robnbehlendorf
authored andcommitted
ZTS: test clearing pool and vdev userprops
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
1 parent 03b7cfd commit c4e5fa5

File tree

4 files changed

+85
-3
lines changed

4 files changed

+85
-3
lines changed

tests/runfiles/common.run

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,8 @@ tags = ['functional', 'cli_root', 'zpool_scrub']
544544
[tests/functional/cli_root/zpool_set]
545545
tests = ['zpool_set_001_pos', 'zpool_set_002_neg', 'zpool_set_003_neg',
546546
'zpool_set_ashift', 'zpool_set_features', 'vdev_set_001_pos',
547-
'user_property_001_pos', 'user_property_002_neg']
547+
'user_property_001_pos', 'user_property_002_neg',
548+
'zpool_set_clear_userprop']
548549
tags = ['functional', 'cli_root', 'zpool_set']
549550

550551
[tests/functional/cli_root/zpool_split]

tests/zfs-tests/tests/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1243,6 +1243,7 @@ nobase_dist_datadir_zfs_tests_tests_SCRIPTS += \
12431243
functional/cli_root/zpool_set/user_property_001_pos.ksh \
12441244
functional/cli_root/zpool_set/user_property_002_neg.ksh \
12451245
functional/cli_root/zpool_set/zpool_set_features.ksh \
1246+
functional/cli_root/zpool_set/zpool_set_clear_userprop.ksh \
12461247
functional/cli_root/zpool_split/cleanup.ksh \
12471248
functional/cli_root/zpool_split/setup.ksh \
12481249
functional/cli_root/zpool_split/zpool_split_cliargs.ksh \
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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+
#
24+
# Copyright (c) 2024, Klara, Inc.
25+
#
26+
27+
. $STF_SUITE/tests/functional/cli_root/zpool_set/zpool_set_common.kshlib
28+
29+
verify_runnable "both"
30+
31+
log_assert "Setting a user-defined property to the empty string removes it."
32+
log_onexit cleanup_user_prop $TESTPOOL
33+
34+
log_must zpool set cool:pool=hello $TESTPOOL
35+
log_must check_user_prop $TESTPOOL cool:pool hello local
36+
log_must zpool set cool:pool= $TESTPOOL
37+
log_must check_user_prop $TESTPOOL cool:pool '-' default
38+
39+
log_must zpool set cool:vdev=goodbye $TESTPOOL root
40+
log_must check_vdev_user_prop $TESTPOOL root cool:vdev goodbye local
41+
log_must zpool set cool:vdev= $TESTPOOL root
42+
log_must check_vdev_user_prop $TESTPOOL root cool:vdev '-' default
43+
44+
log_pass "Setting a user-defined property to the empty string removes it."

tests/zfs-tests/tests/functional/cli_root/zpool_set/zpool_set_common.kshlib

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,19 +160,55 @@ function user_property_value
160160
random_string ALL_CHAR $len
161161
}
162162

163+
function _check_user_prop
164+
{
165+
typeset pool="$1"
166+
typeset vdev="$2"
167+
typeset user_prop="$3"
168+
typeset expect_value="$4"
169+
typeset expect_source="$5"
170+
171+
typeset -a \
172+
v=($(zpool get -p -H -o value,source "$user_prop" $pool $vdev 2>&1))
173+
174+
[[ "$expect_value" == "${v[0]}" && \
175+
-z "$expect_source" || "$expect_source" == "${v[1]}" ]]
176+
}
177+
163178
#
164179
# Check if the user-defined property is identical to the expected value.
165180
#
166181
# $1 pool
167182
# $2 user property
168183
# $3 expected value
184+
# $4 expected source (optional)
169185
#
170186
function check_user_prop
171187
{
172188
typeset pool=$1
173189
typeset user_prop="$2"
174190
typeset expect_value="$3"
175-
typeset value=$(zpool get -p -H -o value "$user_prop" $pool 2>&1)
191+
typeset expect_source="${4:-}"
192+
193+
_check_user_prop $pool '' $user_prop $expect_value $expect_source
194+
}
195+
196+
#
197+
# Check if the user-defined property is identical to the expected value.
198+
#
199+
# $1 pool
200+
# $2 vdev
201+
# $3 user property
202+
# $4 expected value
203+
# $5 expected source (optional)
204+
#
205+
function check_vdev_user_prop
206+
{
207+
typeset pool="$1"
208+
typeset vdev="$2"
209+
typeset user_prop="$3"
210+
typeset expect_value="$4"
211+
typeset expect_source="${5:-}"
176212

177-
[ "$expect_value" = "$value" ]
213+
_check_user_prop $pool $vdev $user_prop $expect_value $expect_source
178214
}

0 commit comments

Comments
 (0)