zpool iostat/status -c improvements

Users can now provide their own scripts to be run
with 'zpool iostat/status -c'. User scripts should be
placed in ~/.zpool.d to be included in zpool's
default search path.

Provide a script which can be used with
'zpool iostat|status -c' that will return the type of
device (hdd, sdd, file).

Provide a script to get various values from smartctl
when using 'zpool iostat/status -c'.

Allow users to define the ZPOOL_SCRIPTS_PATH
environment variable which can be used to override
the default 'zpool iostat/status -c' search path.

Allow the ZPOOL_SCRIPTS_ENABLED environment
variable to enable or disable 'zpool status/iostat -c'
functionality.

Use the new smart script to provide the serial command.

Install /etc/sudoers.d/zfs file which contains the sudoer
rule for smartctl as a sample.

Allow 'zpool iostat/status -c' tests to run in tree.

Reviewed-by: Tony Hutter <hutter2@llnl.gov>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Giuseppe Di Natale <dinatale2@llnl.gov>
Closes #6121 
Closes #6153
This commit is contained in:
Giuseppe Di Natale
2017-06-05 13:52:15 -04:00
committed by Brian Behlendorf
parent 92aceb2a7e
commit 099700d9df
43 changed files with 812 additions and 61 deletions
@@ -4,4 +4,7 @@ dist_pkgdata_SCRIPTS = \
cleanup.ksh \
zpool_status_001_pos.ksh \
zpool_status_002_pos.ksh \
zpool_status_003_pos.ksh
zpool_status_003_pos.ksh \
zpool_status_-c_disable.ksh \
zpool_status_-c_homedir.ksh \
zpool_status_-c_searchpath.ksh
@@ -0,0 +1,54 @@
#!/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 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 (c) 2017 by Lawrence Livermore National Security, LLC.
#
# DESCRIPTION:
# Verify zpool status command mode (-c) respects ZPOOL_SCRIPTS_ENABLED.
#
# STRATEGY:
# 1. Set ZPOOL_SCRIPTS_ENABLED to 0, disabling zpool status -c
# 2. zpool status -c must not run successfully
# 3. Set ZPOOL_SCRIPTS_ENABLED to 1, enabling zpool status -c
# 4. zpool status -c must run successfully
# 5. Unset ZPOOL_SCRIPTS_ENABLED, enabling zpool status -c
# 6. zpool status -c must run successfully
. $STF_SUITE/include/libtest.shlib
. $STF_SUITE/include/zpool_script.shlib
verify_runnable "both"
log_assert "zpool status -c properly handles ZPOOL_SCRIPTS_ENABLED"
export ZPOOL_SCRIPTS_ENABLED=0
log_mustnot zpool status -c media
export ZPOOL_SCRIPTS_ENABLED=1
log_must zpool status -c media
unset ZPOOL_SCRIPTS_ENABLED
log_must zpool status -c media
log_pass "zpool status -c properly handles ZPOOL_SCRIPTS_ENABLED passed"
@@ -0,0 +1,76 @@
#!/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 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 (c) 2017 by Lawrence Livermore National Security, LLC.
#
# DESCRIPTION:
# Verify zpool status command mode (-c) works with scripts in user's
# home directory.
#
# STRATEGY:
# 1. Change HOME to /var/tmp
# 2. Make a simple script that echos a key value pair
# in /var/tmp/.zpool.d
# 3. Make sure it can be run with -c
# 4. Remove the script we created
. $STF_SUITE/include/libtest.shlib
. $STF_SUITE/include/zpool_script.shlib
verify_runnable "both"
# In tree testing sets this variable, we need to unset it
# to restore zpool's search path.
unset ZPOOL_SCRIPTS_PATH
# change HOME
export HOME="$TEST_BASE_DIR"
typeset USER_SCRIPT_FULL="$HOME/.zpool.d/userscript"
function cleanup
{
log_must rm -rf "$HOME/.zpool.d"
}
log_assert "zpool status -c can run scripts from ~/.zpool.d"
if [ -e "$USER_SCRIPT_FULL" ]; then
log_fail "$USER_SCRIPT_FULL already exists."
fi
log_onexit cleanup
# create simple script
log_must mkdir -p "$HOME/.zpool.d"
cat > "$USER_SCRIPT_FULL" << EOF
#!/bin/sh
echo "USRCOL=USRVAL"
EOF
log_must chmod +x "$USER_SCRIPT_FULL"
# test that we can run the script
typeset USER_SCRIPT=$(basename "$USER_SCRIPT_FULL")
test_zpool_script "$USER_SCRIPT" "$TESTPOOL" "zpool status -P -c"
log_pass "zpool status -c can run scripts from ~/.zpool.d passed"
@@ -0,0 +1,88 @@
#!/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 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 (c) 2017 by Lawrence Livermore National Security, LLC.
#
# DESCRIPTION:
# Verify zpool status command mode (-c) works with ZPOOL_SCRIPTS_PATH
# defined.
#
# STRATEGY:
# 1. Set ZPOOL_SCRIPTS_PATH to contain a couple of non-default dirs
# 2. Make a simple script that echos a key value pair in each dir
# 3. Make sure scripts can be run with -c
# 4. Remove the scripts we created
. $STF_SUITE/include/libtest.shlib
. $STF_SUITE/include/zpool_script.shlib
verify_runnable "both"
typeset SCRIPT_1="$TEST_BASE_DIR/scripts1/test1"
typeset SCRIPT_2="$TEST_BASE_DIR/scripts2/test2"
function cleanup
{
log_must rm -rf $(dirname "$SCRIPT_1")
log_must rm -rf $(dirname "$SCRIPT_2")
}
log_assert "zpool status -c can run scripts from custom search path"
if [ -e "$SCRIPT_1" ]; then
log_fail "$SCRIPT_1 already exists."
fi
if [ -e "$SCRIPT_2" ]; then
log_fail "$SCRIPT_2 already exists."
fi
log_onexit cleanup
# change zpool status search path
export ZPOOL_SCRIPTS_PATH="$(dirname $SCRIPT_1):$(dirname $SCRIPT_2)"
# create simple script in each dir
log_must mkdir -p $(dirname "$SCRIPT_1")
cat > "$SCRIPT_1" << EOF
#!/bin/sh
echo "USRCOL1=USRVAL1"
EOF
log_must chmod +x "$SCRIPT_1"
log_must mkdir -p $(dirname "$SCRIPT_2")
cat > "$SCRIPT_2" << EOF
#!/bin/sh
echo "USRCOL2=USRVAL2"
EOF
log_must chmod +x "$SCRIPT_2"
# test that we can run the scripts
typeset CMD_1=$(basename "$SCRIPT_1")
typeset CMD_2=$(basename "$SCRIPT_2")
test_zpool_script "$CMD_1" "$TESTPOOL" "zpool status -P -c"
test_zpool_script "$CMD_2" "$TESTPOOL" "zpool status -P -c"
test_zpool_script "$CMD_2,$CMD_1" "$TESTPOOL" "zpool status -P -c"
log_pass "zpool status -c can run scripts from custom search path passed"
@@ -6,4 +6,7 @@ dist_pkgdata_SCRIPTS = \
zpool_iostat_002_pos.ksh \
zpool_iostat_003_neg.ksh \
zpool_iostat_004_pos.ksh \
zpool_iostat_005_pos.ksh
zpool_iostat_005_pos.ksh \
zpool_iostat_-c_disable.ksh \
zpool_iostat_-c_searchpath.ksh \
zpool_iostat_-c_homedir.ksh
@@ -0,0 +1,54 @@
#!/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 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 (c) 2017 by Lawrence Livermore National Security, LLC.
#
# DESCRIPTION:
# Verify zpool iostat command mode (-c) respects ZPOOL_SCRIPTS_ENABLED.
#
# STRATEGY:
# 1. Set ZPOOL_SCRIPTS_ENABLED to 0, disabling zpool iostat -c
# 2. zpool iostat -c must not run successfully
# 3. Set ZPOOL_SCRIPTS_ENABLED to 1, enabling zpool iostat -c
# 4. zpool iostat -c must run successfully
# 5. Unset ZPOOL_SCRIPTS_ENABLED, enabling zpool iostat -c
# 6. zpool iostat -c must run successfully
. $STF_SUITE/include/libtest.shlib
. $STF_SUITE/include/zpool_script.shlib
verify_runnable "both"
log_assert "zpool iostat -c properly handles ZPOOL_SCRIPTS_ENABLED"
export ZPOOL_SCRIPTS_ENABLED=0
log_mustnot zpool iostat -c media
export ZPOOL_SCRIPTS_ENABLED=1
log_must zpool iostat -c media
unset ZPOOL_SCRIPTS_ENABLED
log_must zpool iostat -c media
log_pass "zpool iostat -c properly handles ZPOOL_SCRIPTS_ENABLED passed"
@@ -0,0 +1,76 @@
#!/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 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 (c) 2017 by Lawrence Livermore National Security, LLC.
#
# DESCRIPTION:
# Verify zpool iostat command mode (-c) works with scripts in user's
# home directory.
#
# STRATEGY:
# 1. Change HOME to /var/tmp
# 2. Make a simple script that echos a key value pair
# in /var/tmp/.zpool.d
# 3. Make sure it can be run with -c
# 4. Remove the script we created
. $STF_SUITE/include/libtest.shlib
. $STF_SUITE/include/zpool_script.shlib
verify_runnable "both"
# In tree testing sets this variable, we need to unset it
# to restore zpool's search path.
unset ZPOOL_SCRIPTS_PATH
# change HOME
export HOME="$TEST_BASE_DIR"
typeset USER_SCRIPT_FULL="$HOME/.zpool.d/userscript"
function cleanup
{
log_must rm -rf "$HOME/.zpool.d"
}
log_assert "zpool iostat -c can run scripts from ~/.zpool.d"
if [ -e "$USER_SCRIPT_FULL" ]; then
log_fail "$USER_SCRIPT_FULL already exists."
fi
log_onexit cleanup
# create simple script
log_must mkdir -p "$HOME/.zpool.d"
cat > "$USER_SCRIPT_FULL" << EOF
#!/bin/sh
echo "USRCOL=USRVAL"
EOF
log_must chmod +x "$USER_SCRIPT_FULL"
# test that we can run the script
typeset USER_SCRIPT=$(basename "$USER_SCRIPT_FULL")
test_zpool_script "$USER_SCRIPT" "$TESTPOOL" "zpool iostat -P -c"
log_pass "zpool iostat -c can run scripts from ~/.zpool.d passed"
@@ -0,0 +1,88 @@
#!/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 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 (c) 2017 by Lawrence Livermore National Security, LLC.
#
# DESCRIPTION:
# Verify zpool iostat command mode (-c) works with ZPOOL_SCRIPTS_PATH
# defined.
#
# STRATEGY:
# 1. Set ZPOOL_SCRIPTS_PATH to contain a couple of non-default dirs
# 2. Make a simple script that echos a key value pair in each dir
# 3. Make sure scripts can be run with -c
# 4. Remove the scripts we created
. $STF_SUITE/include/libtest.shlib
. $STF_SUITE/include/zpool_script.shlib
verify_runnable "both"
typeset SCRIPT_1="$TEST_BASE_DIR/scripts1/test1"
typeset SCRIPT_2="$TEST_BASE_DIR/scripts2/test2"
function cleanup
{
log_must rm -rf $(dirname "$SCRIPT_1")
log_must rm -rf $(dirname "$SCRIPT_2")
}
log_assert "zpool iostat -c can run scripts from custom search path"
if [ -e "$SCRIPT_1" ]; then
log_fail "$SCRIPT_1 already exists."
fi
if [ -e "$SCRIPT_2" ]; then
log_fail "$SCRIPT_2 already exists."
fi
log_onexit cleanup
# change zpool iostat search path
export ZPOOL_SCRIPTS_PATH="$(dirname $SCRIPT_1):$(dirname $SCRIPT_2)"
# create simple script in each dir
log_must mkdir -p $(dirname "$SCRIPT_1")
cat > "$SCRIPT_1" << EOF
#!/bin/sh
echo "USRCOL1=USRVAL1"
EOF
log_must chmod +x "$SCRIPT_1"
log_must mkdir -p $(dirname "$SCRIPT_2")
cat > "$SCRIPT_2" << EOF
#!/bin/sh
echo "USRCOL2=USRVAL2"
EOF
log_must chmod +x "$SCRIPT_2"
# test that we can run the scripts
typeset CMD_1=$(basename "$SCRIPT_1")
typeset CMD_2=$(basename "$SCRIPT_2")
test_zpool_script "$CMD_1" "$TESTPOOL" "zpool iostat -P -c"
test_zpool_script "$CMD_2" "$TESTPOOL" "zpool iostat -P -c"
test_zpool_script "$CMD_2,$CMD_1" "$TESTPOOL" "zpool iostat -P -c"
log_pass "zpool iostat -c can run scripts from custom search path passed"