aboutsummaryrefslogtreecommitdiff
path: root/tests/zfs-tests/tests/functional/cli_user/zpool_iostat/zpool_iostat_-c_searchpath.ksh
blob: 1197ea2d1176456287a44f3b959c20c1e9f517fc (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
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"