1#!/usr/local/bin/ksh93 -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 2009 Sun Microsystems, Inc.  All rights reserved.
25# Use is subject to license terms.
26. $STF_SUITE/include/libtest.kshlib
27. $STF_SUITE/tests/cli_root/zpool_add/zpool_add.kshlib
28
29################################################################################
30#
31# __stc_assertion_start
32#
33# ID: zpool_add_005_pos
34#
35# DESCRIPTION:
36#       'zpool add' should return fail if
37#	1. vdev is part of an active pool
38# 	2. vdev is currently mounted
39# 	3. vdev is in /etc/vfstab
40#	3. vdev is specified as the dedicated dump device
41#
42# STRATEGY:
43#	1. Create case scenarios
44#	2. For each scenario, try to add the device to the pool
45#	3. Verify the add operation get failed
46#
47# TESTABILITY: explicit
48#
49# TEST_AUTOMATION_LEVEL: automated
50#
51# CODING_STATUS: COMPLETED (2005-09-29)
52#
53# __stc_assertion_end
54#
55###############################################################################
56
57verify_runnable "global"
58
59set_disks
60
61function cleanup
62{
63	poolexists "$TESTPOOL" && \
64		destroy_pool "$TESTPOOL"
65	poolexists "$TESTPOOL1" && \
66		destroy_pool "$TESTPOOL1"
67
68	log_onfail $UMOUNT $TMPDIR/mounted_dir
69	log_onfail $SWAPOFF $swap_dev
70	log_onfail $DUMPON -r $dump_dev
71}
72
73log_assert "'zpool add' should fail with inapplicable scenarios."
74
75log_onexit cleanup
76
77create_pool "$TESTPOOL" "${DISK0}"
78log_must poolexists "$TESTPOOL"
79
80create_pool "$TESTPOOL1" "${DISK1}"
81log_must poolexists "$TESTPOOL1"
82
83mounted_dev=${DISK2}
84log_must $MKDIR $TMPDIR/mounted_dir
85log_must $NEWFS $mounted_dev
86log_must $MOUNT $mounted_dev $TMPDIR/mounted_dir
87
88swap_dev=${DISK3}
89log_must $SWAPON $swap_dev
90
91dump_dev=${DISK4}
92log_must $DUMPON $dump_dev
93
94log_mustnot $ZPOOL add -f "$TESTPOOL" ${DISK1}
95
96log_mustnot $ZPOOL add -f "$TESTPOOL" $mounted_dev
97
98log_mustnot $ZPOOL add -f "$TESTPOOL" $swap_dev
99
100# https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=241070
101# When that bug is fixed, change this to log_mustnot.
102log_must $ZPOOL add -f "$TESTPOOL" $dump_dev
103
104log_pass "'zpool add' should fail with inapplicable scenarios."
105