mirror_zfs/tests/zfs-tests/tests/functional/inheritance/inherit.kshlib
John Wren Kennedy c1d9abf905 OpenZFS 7290 - ZFS test suite needs to control what utilities it can run
Authored by: John Wren Kennedy <john.kennedy@delphix.com>
Reviewed by: Dan Kimmel <dan.kimmel@delphix.com>
Reviewed by: Matthew Ahrens <mahrens@delphix.com>
Reviewed by: Dan McDonald <danmcd@omniti.com>
Approved by: Gordon Ross <gordon.w.ross@gmail.com>
Ported-by: Brian Behlendorf <behlendorf1@llnl.gov>
Ported-by: George Melikov <mail@gmelikov.ru>

Porting Notes:
- Utilities which aren't available under Linux have been removed.
- Because of sudo's default secure path behavior PATH must be
  explicitly reset at the top of libtest.shlib.  This avoids the
  need for all users to customize secure path on their system.
- Updated ZoL infrastructure to manage constrained path
- Updated all test cases
- Check permissions for usergroup tests
- When testing in-tree create links under bin/
- Update fault cleanup such that missing files during
  cleanup aren't fatal.
- Configure su environment with constrained path

OpenZFS-issue: https://www.illumos.org/issues/7290
OpenZFS-commit: https://github.com/openzfs/openzfs/commit/1d32ba6
Closes #5903
2017-04-06 09:25:36 -07:00

115 lines
3.1 KiB
Plaintext

#
# 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 http://www.opensolaris.org/os/licensing.
# 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 2009 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
#
# Copyright (c) 2013, 2016 by Delphix. All rights reserved.
#
#
# Simple function to get the source of the specified property.
# If unable to get the property then exits.
#
function get_prop_src # property dataset
{
typeset prop_val
typeset prop=$1
typeset dataset=$2
prop_val=`zfs get -H -o source $prop $dataset`
if [[ $? -ne 0 ]]; then
log_fail "Unable to determine the source of $prop " \
"property for dataset $dataset"
else
echo $prop_val
fi
}
#
# Function to check the 'source' of a property. The source can
# either be "default", "local", or "inherited from <parent dataset>".
#
# The 'expected src' argument must be either "default", "local", or
# a dataset name.
#
# Returns 0 on success, 1 on failure.
#
function verify_prop_src # child_dataset property expected_src
{
typeset target=$1
typeset prop=$2
typeset expected=$3
prop_src=`get_prop_src $prop $target`
#
# Rather than just checking if $prop_src == $expected
# we first determine what value $expected should have.
# This allows us to catch the case where a property
# has a source of "local" but we expected it to be
# "default"
#
if [[ $expected == "default" ]]; then
if [[ $prop_src != $expected ]]; then
log_note "Property $prop of $target has source"\
" $prop_src rather than $expected"
return 1
fi
elif [[ $expected == "local" ]]; then
if [[ $prop_src != $expected ]]; then
log_note "Property $prop of $target has source"\
" $prop_src rather than $expected"
return 1
fi
elif [[ $prop_src != "inherited from $expected" ]]; then
log_note "Property $prop of $expected has source $prop_src"\
" rather than 'inherited from $expected'"
return 1
fi
return 0
}
#
# Simple function to set a property to a
# specified value and verify it has changed
# correctly.
#
function set_n_verify_prop #property value dataset
{
typeset prop=$1
typeset prop_val=$2
typeset dataset=$3
zfs set $prop=$prop_val $dataset
check_val=`get_prop $prop $dataset`
if [[ $check_val != $prop_val ]]; then
log_fail "Property $prop of $dataset has value $check_val"\
" rather than $prop_val"
fi
}