aboutsummaryrefslogtreecommitdiff
path: root/tests/zfs-tests/tests/functional/fault/auto_online_001_pos.ksh
blob: 03fc15a8a7cbe8dbf14ad4ace8bc000069edf7f1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#!/bin/ksh -p
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# or http://www.opensolaris.org/os/licensing.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
#
# Copyright (c) 2016, 2017 by Intel Corporation. All rights reserved.
# Copyright (c) 2019 by Delphix. All rights reserved.
#

. $STF_SUITE/include/libtest.shlib
. $STF_SUITE/tests/functional/fault/fault.cfg

#
# DESCRIPTION:
# Testing Fault Management Agent ZED Logic - Automated Auto-Online Test.
#
# STRATEGY:
# 1. Create a pool
# 2. Export a pool
# 3. Offline disk
# 4. Import pool with missing disk
# 5. Online disk
# 6. ZED polls for an event change for online disk to be automatically
#    added back to the pool.
#
# Creates a raidz1 zpool using persistent disk path names
# (ie not /dev/sdc).
#
# If loop devices are used, then a scsi_debug device is added to the pool.
# otherwise just an sd device is used as the auto-online device.
# Auto-online matches by devid.
#
verify_runnable "both"

if ! is_physical_device $DISKS; then
	log_unsupported "Unsupported disks for this test."
fi

function cleanup
{
	typeset disk

	# Replace any disk that may have been removed at failure time.
	for disk in $DISK1 $DISK2 $DISK3; do
		# Skip loop devices and devices that currently exist.
		is_loop_device $disk && continue
		is_real_device $disk && continue
		insert_disk $disk $(get_scsi_host $disk)
	done
	destroy_pool $TESTPOOL
	unload_scsi_debug
}

log_assert "Testing automated auto-online FMA test"

log_onexit cleanup

# If using the default loop devices, need a scsi_debug device for auto-online
if is_loop_device $DISK1; then
	load_scsi_debug $SDSIZE $SDHOSTS $SDTGTS $SDLUNS '512b'
	SDDEVICE=$(get_debug_device)
	SDDEVICE_ID=$(get_persistent_disk_name $SDDEVICE)
	autoonline_disks="$SDDEVICE"
else
	autoonline_disks="$DISK1 $DISK2 $DISK3"
fi

# Clear disk labels
for i in {0..2}
do
	zpool labelclear -f /dev/disk/by-id/"${devs_id[i]}"
done

if is_loop_device $DISK1; then
	# create a pool with one scsi_debug device and 3 loop devices
	log_must zpool create -f $TESTPOOL raidz1 $SDDEVICE_ID $DISK1 \
	    $DISK2 $DISK3
elif ( is_real_device $DISK1 || is_mpath_device $DISK1 ); then
	# else use the persistent names for sd devices
	log_must zpool create -f $TESTPOOL raidz1 ${devs_id[0]} \
	    ${devs_id[1]} ${devs_id[2]}
else
	log_fail "Disks are not supported for this test"
fi

# Add some data to the pool
log_must mkfile $FSIZE /$TESTPOOL/data

for offline_disk in $autoonline_disks
do
	log_must zpool export -F $TESTPOOL

	host=$(get_scsi_host $offline_disk)

	# Offline disk
	remove_disk $offline_disk

	# Reimport pool with drive missing
	log_must zpool import $TESTPOOL
	check_state $TESTPOOL "" "degraded"
	if (($? != 0)); then
		log_fail "$TESTPOOL is not degraded"
	fi

	# Clear zpool events
	log_must zpool events -c

	# Online disk
	insert_disk $offline_disk $host

	log_note "Delay for ZED auto-online"
	typeset -i timeout=0
	while true; do
		if ((timeout == $MAXTIMEOUT)); then
			log_fail "Timeout occurred"
		fi
		((timeout++))

		sleep 1
		zpool events $TESTPOOL \
		    | egrep sysevent.fs.zfs.resilver_finish > /dev/null
		if (($? == 0)); then
			log_note "Auto-online of $offline_disk is complete"
			sleep 1
			break
		fi
	done

	# Validate auto-online was successful
	check_state $TESTPOOL "" "online"
	if (($? != 0)); then
		log_fail "$TESTPOOL is not back online"
	fi
	sleep 2
done
log_must zpool destroy $TESTPOOL

log_pass "Auto-online test successful"