xref: /freebsd/sys/contrib/openzfs/tests/zfs-tests/tests/functional/fault/auto_online_002_pos.ksh (revision 61145dc2b94f12f6a47344fb9aac702321880e43)
1#!/bin/ksh -p
2# SPDX-License-Identifier: CDDL-1.0
3#
4# CDDL HEADER START
5#
6# The contents of this file are subject to the terms of the
7# Common Development and Distribution License (the "License").
8# You may not use this file except in compliance with the License.
9#
10# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
11# or https://opensource.org/licenses/CDDL-1.0.
12# See the License for the specific language governing permissions
13# and limitations under the License.
14#
15# When distributing Covered Code, include this CDDL HEADER in each
16# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
17# If applicable, add the following below this CDDL HEADER, with the
18# fields enclosed by brackets "[]" replaced with your own identifying
19# information: Portions Copyright [yyyy] [name of copyright owner]
20#
21# CDDL HEADER END
22#
23# Copyright (c) 2016, 2017 by Intel Corporation. All rights reserved.
24# Copyright (c) 2019 by Delphix. All rights reserved.
25# Portions Copyright 2021 iXsystems, Inc.
26#
27
28. $STF_SUITE/include/libtest.shlib
29. $STF_SUITE/tests/functional/fault/fault.cfg
30
31#
32# DESCRIPTION:
33# Testing Fault Management Agent ZED Logic - Automated Auto-Online Test.
34# Now with partitioned vdevs.
35#
36# STRATEGY:
37# 1. Partition a scsi_debug device for simulating removal
38# 2. Create a pool
39# 3. Offline disk
40# 4. ZED polls for an event change for online disk to be automatically
41#    added back to the pool.
42#
43verify_runnable "both"
44
45function cleanup
46{
47	poolexists ${TESTPOOL} && destroy_pool ${TESTPOOL}
48	unload_scsi_debug
49}
50
51log_assert "Testing automated auto-online FMA test with partitioned vdev"
52
53log_onexit cleanup
54
55load_scsi_debug ${SDSIZE} ${SDHOSTS} ${SDTGTS} ${SDLUNS} '512b'
56SDDEVICE=$(get_debug_device)
57zpool labelclear -f ${SDDEVICE}
58partition_disk ${SDSIZE} ${SDDEVICE} 1
59part=${SDDEVICE}1
60host=$(get_scsi_host ${SDDEVICE})
61
62block_device_wait /dev/${part}
63log_must zpool create -f ${TESTPOOL} raidz1 ${part} ${DISKS}
64
65# Add some data to the pool
66log_must mkfile ${FSIZE} /${TESTPOOL}/data
67
68remove_disk ${SDDEVICE}
69check_state ${TESTPOOL} "" "degraded" || \
70    log_fail "${TESTPOOL} is not degraded"
71
72# Clear zpool events
73log_must zpool events -c
74
75# Online disk
76insert_disk ${SDDEVICE} ${host}
77
78log_note "Delay for ZED auto-online"
79typeset -i timeout=0
80until is_pool_resilvered ${TESTPOOL}; do
81	if ((timeout++ == MAXTIMEOUT)); then
82		log_fail "Timeout occurred"
83	fi
84	sleep 1
85done
86log_note "Auto-online of ${SDDEVICE} is complete"
87
88# Validate auto-online was successful
89sleep 1
90check_state ${TESTPOOL} "" "online" || \
91    log_fail "${TESTPOOL} is not back online"
92
93log_must zpool destroy ${TESTPOOL}
94
95log_pass "Auto-online with partitioned vdev test successful"
96