]> git.proxmox.com Git - mirror_zfs.git/blob - tests/zfs-tests/tests/functional/cli_root/zpool_offline/zpool_offline_001_pos.ksh
Add the ZFS Test Suite
[mirror_zfs.git] / tests / zfs-tests / tests / functional / cli_root / zpool_offline / zpool_offline_001_pos.ksh
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 2009 Sun Microsystems, Inc. All rights reserved.
25 # Use is subject to license terms.
26 #
27 . $STF_SUITE/include/libtest.shlib
28
29 #
30 # DESCRIPTION:
31 # Executing 'zpool offline' with valid parameters succeeds.
32 #
33 # STRATEGY:
34 # 1. Create an array of correctly formed 'zpool offline' options
35 # 2. Execute each element of the array.
36 # 3. Verify use of each option is successful.
37 #
38
39 verify_runnable "global"
40
41 DISKLIST=$(get_disklist $TESTPOOL)
42 set -A disks $DISKLIST
43 typeset -i num=${#disks[*]}
44
45 set -A args "" "-t"
46
47 function cleanup
48 {
49 #
50 # Ensure we don't leave disks in the offline state
51 #
52 for disk in $DISKLIST; do
53 log_must $ZPOOL online $TESTPOOL $disk
54 check_state $TESTPOOL $disk "online"
55 if [[ $? != 0 ]]; then
56 log_fail "Unable to online $disk"
57 fi
58
59 done
60 }
61
62 log_assert "Executing 'zpool offline' with correct options succeeds"
63
64 log_onexit cleanup
65
66 if [[ -z $DISKLIST ]]; then
67 log_fail "DISKLIST is empty."
68 fi
69
70 typeset -i i=0
71 typeset -i j=1
72
73 for disk in $DISKLIST; do
74 i=0
75 while [[ $i -lt ${#args[*]} ]]; do
76 if (( j < num )) ; then
77 log_must $ZPOOL offline ${args[$i]} $TESTPOOL $disk
78 check_state $TESTPOOL $disk "offline"
79 if [[ $? != 0 ]]; then
80 log_fail "$disk of $TESTPOOL did not match offline state"
81 fi
82 else
83 log_mustnot $ZPOOL offline ${args[$i]} $TESTPOOL $disk
84 check_state $TESTPOOL $disk "online"
85 if [[ $? != 0 ]]; then
86 log_fail "$disk of $TESTPOOL did not match online state"
87 fi
88 fi
89
90 (( i = i + 1 ))
91 done
92 (( j = j + 1 ))
93 done
94
95 log_note "Issuing repeated 'zpool offline' commands succeeds."
96
97 typeset -i iters=20
98 typeset -i index=0
99
100 for disk in $DISKLIST; do
101 i=0
102 while [[ $i -lt $iters ]]; do
103 index=`expr $RANDOM % ${#args[*]}`
104 log_must $ZPOOL offline ${args[$index]} $TESTPOOL $disk
105 check_state $TESTPOOL $disk "offline"
106 if [[ $? != 0 ]]; then
107 log_fail "$disk of $TESTPOOL is not offline."
108 fi
109
110 (( i = i + 1 ))
111 done
112
113 log_must $ZPOOL online $TESTPOOL $disk
114 check_state $TESTPOOL $disk "online"
115 if [[ $? != 0 ]]; then
116 log_fail "$disk of $TESTPOOL did not match online state"
117 fi
118 done
119
120 log_pass "'zpool offline' with correct options succeeded"