]> granicus.if.org Git - zfs/blob - tests/zfs-tests/tests/functional/cli_root/zfs_set/user_property_002_pos.ksh
310d1540a0966027136bbd31367c97739cd1c208
[zfs] / tests / zfs-tests / tests / functional / cli_root / zfs_set / user_property_002_pos.ksh
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 http://www.opensolaris.org/os/licensing.
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 2007 Sun Microsystems, Inc.  All rights reserved.
25 # Use is subject to license terms.
26 #
27
28 #
29 # Copyright (c) 2016 by Delphix. All rights reserved.
30 #
31
32 . $STF_SUITE/tests/functional/cli_root/zfs_set/zfs_set_common.kshlib
33
34 #
35 # DESCRIPTION:
36 #       User defined property are always inherited from its parent dataset
37 #       directly.
38 #
39 # STRATEGY:
40 #       1. Create pool, fs, volume, fsclone & volclone.
41 #       2. Get random user property name and set to the pool
42 #       3. Verify all dataset user property inherit from pool.
43 #       4. Set intermediate dataset and verify its children will inherit user
44 #          property from it directly.
45 #
46
47 verify_runnable "both"
48
49 function cleanup
50 {
51         datasetexists $new_vol && log_must zfs rename $new_vol $vol
52
53         typeset dtst
54         for dtst in $new_fsclone $new_volclone $fsclone $volclone \
55             $fssnap $volsnap; do
56                 if datasetexists $dtst; then
57                         log_must zfs destroy -f $dtst
58                 fi
59         done
60
61         cleanup_user_prop $pool
62 }
63
64 #
65 # Verify options datasets (3-n) inherit from the inherited dataset $2.
66 #
67 # $1 user property
68 # $2 inherited dataset
69 # $3-n datasets
70 #
71 function inherit_check
72 {
73         typeset prop=$1
74         typeset inherited_dtst=$2
75         shift 2
76         [[ -z $@ ]] && return 1
77
78         typeset inherited_value=$(get_prop $prop $inherited_dtst)
79         for dtst in $@; do
80                 typeset value=$(get_prop $prop $dtst)
81                 typeset source=$(get_source $prop $dtst)
82                 if [[ "$value" != "$inherited_value" || \
83                       "$source" != "inherited from $inherited_dtst" ]]
84                 then
85                         return 1
86                 fi
87
88                 shift
89         done
90
91         return 0
92 }
93
94 log_assert "User defined property inherited from its parent."
95 log_onexit cleanup
96
97 pool=$TESTPOOL; fs=$pool/$TESTFS; vol=$pool/$TESTVOL
98 fssnap=$fs@snap; volsnap=$vol@snap;
99 log_must zfs snapshot $fssnap
100 log_must zfs snapshot $volsnap
101 fsclone=$pool/fsclone; volclone=$pool/volclone
102 log_must zfs clone $fssnap $fsclone
103 log_must zfs clone $volsnap $volclone
104
105 prop_name=$(valid_user_property 10)
106 value=$(user_property_value 16)
107 log_must eval "zfs set $prop_name='$value' $pool"
108 log_must eval "check_user_prop $pool $prop_name '$value'"
109 log_must inherit_check $prop_name $pool $fs $vol $fsclone $volclone
110
111 new_fsclone=$fs/fsclone; new_volclone=$fs/volclone
112 log_must zfs rename $fsclone $new_fsclone
113 log_must zfs rename $volclone $new_volclone
114 log_must inherit_check $prop_name $pool $fs $new_fsclone $new_volclone
115
116 log_note "Set intermediate dataset will change the inherited relationship."
117 new_value=$(user_property_value 16)
118 log_must eval "zfs set $prop_name='$new_value' $fs"
119 log_must eval "check_user_prop $fs $prop_name '$new_value'"
120 log_must inherit_check $prop_name $fs $new_fsclone $new_volclone
121
122 log_pass "User defined property inherited from its parent passed."