xref: /illumos-gate/usr/src/test/zfs-tests/tests/functional/inheritance/inherit.kshlib (revision 069e6b7e31ba5dcbc5441b98af272714d9a5455c)
1#
2# CDDL HEADER START
3#
4# The contents of this file are subject to the terms of the
5# Common Development and Distribution License (the "License").
6# You may not use this file except in compliance with the License.
7#
8# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9# or http://www.opensolaris.org/os/licensing.
10# See the License for the specific language governing permissions
11# and limitations under the License.
12#
13# When distributing Covered Code, include this CDDL HEADER in each
14# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15# If applicable, add the following below this CDDL HEADER, with the
16# fields enclosed by brackets "[]" replaced with your own identifying
17# information: Portions Copyright [yyyy] [name of copyright owner]
18#
19# CDDL HEADER END
20#
21
22#
23# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
24# Use is subject to license terms.
25#
26
27#
28# Copyright (c) 2013, 2016 by Delphix. All rights reserved.
29#
30
31#
32# Simple function to get the source of the specified property.
33# If unable to get the property then exits.
34#
35function get_prop_src # property dataset
36{
37        typeset prop_val
38        typeset prop=$1
39        typeset dataset=$2
40
41	prop_val=`zfs get -H -o source $prop $dataset`
42
43        if [[ $? -ne 0 ]]; then
44                log_fail "Unable to determine the source of $prop " \
45                        "property for dataset $dataset"
46        else
47                echo $prop_val
48        fi
49}
50
51#
52# Function to check the 'source' of a property. The source can
53# either be "default", "local", or "inherited from <parent dataset>".
54#
55# The 'expected src' argument must be either "default", "local", or
56# a dataset name.
57#
58# Returns 0 on success, 1 on failure.
59#
60function verify_prop_src # child_dataset property expected_src
61{
62        typeset target=$1
63        typeset prop=$2
64        typeset expected=$3
65
66        prop_src=`get_prop_src $prop $target`
67
68	#
69	# Rather than just checking if $prop_src == $expected
70	# we first determine what value $expected should have.
71	# This allows us to catch the case where a property
72	# has a source of "local" but we expected it to be
73	# "default"
74	#
75	if [[ $expected == "default" ]]; then
76		if [[ $prop_src != $expected ]]; then
77			log_note "Property $prop of $target has source"\
78				" $prop_src rather than $expected"
79			return 1
80		fi
81	elif [[ $expected == "local" ]]; then
82		if [[ $prop_src != $expected ]]; then
83			log_note "Property $prop of $target has source"\
84				" $prop_src rather than $expected"
85			return 1
86		fi
87	elif [[ $prop_src != "inherited from $expected" ]]; then
88		log_note "Property $prop of $expected has source $prop_src"\
89			" rather than 'inherited from $expected'"
90                return 1
91	fi
92
93	return 0
94}
95
96#
97# Simple function to set a property to a
98# specified value and verify it has changed
99# correctly.
100#
101function set_n_verify_prop #property value dataset
102{
103	typeset prop=$1
104	typeset prop_val=$2
105	typeset dataset=$3
106
107	zfs set $prop=$prop_val $dataset
108	check_val=`get_prop $prop $dataset`
109
110	if [[ $check_val != $prop_val ]]; then
111		log_fail "Property $prop of $dataset has value $check_val"\
112			" rather than $prop_val"
113	fi
114}
115