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 (c) 2017 by Lawrence Livermore National Security, LLC.
25#
26
27# DESCRIPTION:
28#	Verify zpool status command mode (-c) works with ZPOOL_SCRIPTS_PATH
29# defined.
30#
31# STRATEGY:
32#	1. Set ZPOOL_SCRIPTS_PATH to contain a couple of non-default dirs
33#	2. Make a simple script that echoes a key value pair in each dir
34#	3. Make sure scripts can be run with -c
35#	4. Remove the scripts we created
36
37. $STF_SUITE/include/libtest.shlib
38. $STF_SUITE/include/zpool_script.shlib
39
40verify_runnable "both"
41
42typeset SCRIPT_1="$TEST_BASE_DIR/scripts1/test1"
43typeset SCRIPT_2="$TEST_BASE_DIR/scripts2/test2"
44
45function cleanup
46{
47	log_must rm -rf $(dirname "$SCRIPT_1")
48	log_must rm -rf $(dirname "$SCRIPT_2")
49}
50
51log_assert "zpool status -c can run scripts from custom search path"
52
53if [ -e "$SCRIPT_1" ]; then
54	log_fail "$SCRIPT_1 already exists."
55fi
56
57if [ -e "$SCRIPT_2" ]; then
58	log_fail "$SCRIPT_2 already exists."
59fi
60
61log_onexit cleanup
62
63# change zpool status search path
64export ZPOOL_SCRIPTS_PATH="$(dirname $SCRIPT_1):$(dirname $SCRIPT_2)"
65
66# create simple script in each dir
67log_must mkdir -p $(dirname "$SCRIPT_1")
68cat > "$SCRIPT_1" << EOF
69#!/bin/sh
70echo "USRCOL1=USRVAL1"
71EOF
72log_must chmod +x "$SCRIPT_1"
73
74log_must mkdir -p $(dirname "$SCRIPT_2")
75cat > "$SCRIPT_2" << EOF
76#!/bin/sh
77echo "USRCOL2=USRVAL2"
78EOF
79log_must chmod +x "$SCRIPT_2"
80
81# test that we can run the scripts
82typeset CMD_1=$(basename "$SCRIPT_1")
83typeset CMD_2=$(basename "$SCRIPT_2")
84test_zpool_script "$CMD_1" "$TESTPOOL" "zpool status -P -c"
85test_zpool_script "$CMD_2" "$TESTPOOL" "zpool status -P -c"
86test_zpool_script "$CMD_2,$CMD_1" "$TESTPOOL" "zpool status -P -c"
87
88log_pass "zpool status -c can run scripts from custom search path passed"
89