xref: /illumos-gate/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_remove/zpool_remove_001_neg.ksh (revision be4e997e05c92f444c81d2d197b79e67ebee2786)
1#!/usr/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 2008 Sun Microsystems, Inc.  All rights reserved.
25# Use is subject to license terms.
26#
27
28#
29# Copyright (c) 2012, 2016 by Delphix. All rights reserved.
30#
31
32. $STF_SUITE/include/libtest.shlib
33. $STF_SUITE/tests/functional/cli_root/zpool_remove/zpool_remove.cfg
34
35#
36# DESCRIPTION:
37# Verify that 'zpool can not remove device except inactive hot spares from pool'
38#
39# STRATEGY:
40# 1. Create all kinds of pool (strip, mirror, raidz, hotspare)
41# 2. Try to remove device from the pool
42# 3. Verify that the remove failed.
43#
44
45typeset disk=${DISK}
46typeset vdev_devs="${disk}s${SLICE0}"
47typeset mirror_devs="${disk}s${SLICE0} ${disk}s${SLICE1}"
48typeset raidz_devs=${mirror_devs}
49typeset raidz1_devs=${mirror_devs}
50typeset raidz2_devs="${mirror_devs} ${disk}s${SLICE3}"
51typeset spare_devs1="${disk}s${SLICE0}"
52typeset spare_devs2="${disk}s${SLICE1}"
53
54function check_remove
55{
56        typeset pool=$1
57        typeset devs="$2"
58        typeset dev
59
60        for dev in $devs; do
61                log_mustnot zpool remove $dev
62        done
63
64        destroy_pool $pool
65
66}
67
68function cleanup
69{
70        if poolexists $TESTPOOL; then
71                destroy_pool $TESTPOOL
72        fi
73}
74
75set -A create_args "$vdev_devs" "mirror $mirror_devs"  \
76		"raidz $raidz_devs" "raidz $raidz1_devs" \
77		"raidz2 $raidz2_devs" \
78		"$spare_devs1 spare $spare_devs2"
79
80set -A verify_disks "$vdev_devs" "$mirror_devs" "$raidz_devs" \
81		"$raidz1_devs" "$raidz2_devs" "$spare_devs1"
82
83
84log_assert "Check zpool remove <pool> <device> can not remove " \
85	"active device from pool"
86
87log_onexit cleanup
88
89typeset -i i=0
90while [[ $i -lt ${#create_args[*]} ]]; do
91	log_must zpool create $TESTPOOL ${create_args[i]}
92	check_remove $TESTPOOL "${verify_disks[i]}"
93	(( i = i + 1))
94done
95
96log_pass "'zpool remove <pool> <device> fail as expected .'"
97