]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - tests/zfs-tests/tests/functional/fault/auto_online_001_pos.ksh
Allow 'zpool events' filtering by pool name
[FreeBSD/FreeBSD.git] / tests / zfs-tests / tests / functional / fault / auto_online_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 # Copyright (c) 2016, 2017 by Intel Corporation. All rights reserved.
24 #
25
26 . $STF_SUITE/include/libtest.shlib
27 . $STF_SUITE/tests/functional/fault/fault.cfg
28
29 #
30 # DESCRIPTION:
31 # Testing Fault Management Agent ZED Logic - Automated Auto-Online Test.
32 #
33 # STRATEGY:
34 # 1. Create a pool
35 # 2. Export a pool
36 # 3. Offline disk
37 # 4. Import pool with missing disk
38 # 5. Online disk
39 # 6. ZED polls for an event change for online disk to be automatically
40 #    added back to the pool.
41 #
42 # Creates a raidz1 zpool using persistent disk path names
43 # (ie not /dev/sdc).
44 #
45 # If loop devices are used, then a scsi_debug device is added to the pool.
46 # otherwise just an sd device is used as the auto-online device.
47 # Auto-online matches by devid.
48 #
49 verify_runnable "both"
50
51 if ! is_physical_device $DISKS; then
52         log_unsupported "Unsupported disks for this test."
53 fi
54
55 function cleanup
56 {
57         #online last disk before fail
58         insert_disk $offline_disk $host
59         poolexists $TESTPOOL && destroy_pool $TESTPOOL
60 }
61
62 log_assert "Testing automated auto-online FMA test"
63
64 log_onexit cleanup
65
66 # If using the default loop devices, need a scsi_debug device for auto-online
67 if is_loop_device $DISK1; then
68         SD=$(lsscsi | nawk '/scsi_debug/ {print $6; exit}')
69         SDDEVICE=$(echo $SD | nawk -F / '{print $3}')
70         SDDEVICE_ID=$(get_persistent_disk_name $SDDEVICE)
71         autoonline_disks="$SDDEVICE"
72 else
73         autoonline_disks="$DISK1 $DISK2 $DISK3"
74 fi
75
76 # Clear disk labels
77 for i in {0..2}
78 do
79         zpool labelclear -f /dev/disk/by-id/"${devs_id[i]}"
80 done
81
82 if is_loop_device $DISK1; then
83         # create a pool with one scsi_debug device and 3 loop devices
84         log_must zpool create -f $TESTPOOL raidz1 $SDDEVICE_ID $DISK1 \
85             $DISK2 $DISK3
86 elif ( is_real_device $DISK1 || is_mpath_device $DISK1 ); then
87         # else use the persistent names for sd devices
88         log_must zpool create -f $TESTPOOL raidz1 ${devs_id[0]} \
89             ${devs_id[1]} ${devs_id[2]}
90 else
91         log_fail "Disks are not supported for this test"
92 fi
93
94 # Add some data to the pool
95 log_must mkfile $FSIZE /$TESTPOOL/data
96
97 for offline_disk in $autoonline_disks
98 do
99         log_must zpool export -F $TESTPOOL
100
101         host=$(get_scsi_host $offline_disk)
102
103         # Offline disk
104         remove_disk $offline_disk
105
106         # Reimport pool with drive missing
107         log_must zpool import $TESTPOOL
108         check_state $TESTPOOL "" "degraded"
109         if (($? != 0)); then
110                 log_fail "$TESTPOOL is not degraded"
111         fi
112
113         # Clear zpool events
114         log_must zpool events -c
115
116         # Online disk
117         insert_disk $offline_disk $host
118
119         log_note "Delay for ZED auto-online"
120         typeset -i timeout=0
121         while true; do
122                 if ((timeout == $MAXTIMEOUT)); then
123                         log_fail "Timeout occured"
124                 fi
125                 ((timeout++))
126
127                 sleep 1
128                 zpool events $TESTPOOL \
129                     | egrep sysevent.fs.zfs.resilver_finish > /dev/null
130                 if (($? == 0)); then
131                         log_note "Auto-online of $offline_disk is complete"
132                         sleep 1
133                         break
134                 fi
135         done
136
137         # Validate auto-online was successful
138         check_state $TESTPOOL "" "online"
139         if (($? != 0)); then
140                 log_fail "$TESTPOOL is not back online"
141         fi
142         sleep 2
143 done
144 log_must zpool destroy $TESTPOOL
145
146 log_pass "Auto-online test successful"