7290 ZFS test suite needs to control what utilities it can run
[unleashed.git] / usr / src / test / zfs-tests / tests / functional / cli_root / zpool_export / zpool_export_004_pos.ksh
blob7be92850c2633ecbf0cfc1cbae7430c320c476b5
1 #!/bin/ksh -p
3 # CDDL HEADER START
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.
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.
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]
20 # CDDL HEADER END
24 # Copyright 2009 Sun Microsystems, Inc. All rights reserved.
25 # Use is subject to license terms.
29 # Copyright (c) 2012, 2016 by Delphix. All rights reserved.
32 . $STF_SUITE/include/libtest.shlib
35 # DESCRIPTION:
36 # Verify zpool export succeed or fail with spare.
38 # STRATEGY:
39 # 1. Create two mirror pools with same spare.
40 # 2. Verify zpool export one pool succeed.
41 # 3. Import the pool.
42 # 4. Replace one device with the spare and detach it in one pool.
43 # 5. Verify zpool export the pool succeed.
44 # 6. Import the pool.
45 # 7. Replace one device with the spare in one pool.
46 # 8. Verify zpool export the pool fail.
47 # 9. Verify zpool export the pool with "-f" succeed.
48 # 10. Import the pool.
51 verify_runnable "global"
53 function cleanup
55 mntpnt=$(get_prop mountpoint $TESTPOOL)
56 datasetexists $TESTPOOL1 || log_must zpool import -d $mntpnt $TESTPOOL1
57 datasetexists $TESTPOOL1 && destroy_pool $TESTPOOL1
58 datasetexists $TESTPOOL2 && destroy_pool $TESTPOOL2
59 typeset -i i=0
60 while ((i < 5)); do
61 if [[ -e $mntpnt/vdev$i ]]; then
62 log_must rm -f $mntpnt/vdev$i
64 ((i += 1))
65 done
69 log_assert "Verify zpool export succeed or fail with spare."
70 log_onexit cleanup
72 mntpnt=$(get_prop mountpoint $TESTPOOL)
74 typeset -i i=0
75 while ((i < 5)); do
76 log_must mkfile $MINVDEVSIZE $mntpnt/vdev$i
77 eval vdev$i=$mntpnt/vdev$i
78 ((i += 1))
79 done
81 log_must zpool create $TESTPOOL1 mirror $vdev0 $vdev1 spare $vdev4
82 log_must zpool create $TESTPOOL2 mirror $vdev2 $vdev3 spare $vdev4
84 log_must zpool export $TESTPOOL1
85 log_must zpool import -d $mntpnt $TESTPOOL1
87 log_must zpool replace $TESTPOOL1 $vdev0 $vdev4
88 log_must zpool detach $TESTPOOL1 $vdev4
89 log_must zpool export $TESTPOOL1
90 log_must zpool import -d $mntpnt $TESTPOOL1
92 log_must zpool replace $TESTPOOL1 $vdev0 $vdev4
93 log_mustnot zpool export $TESTPOOL1
95 log_must zpool export -f $TESTPOOL1
96 log_must zpool import -d $mntpnt $TESTPOOL1
98 log_pass "Verify zpool export succeed or fail with spare."