1#!/usr/local/bin/ksh93 -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 2012 Spectra Logic.  All rights reserved.
25# Use is subject to license terms.
26. $STF_SUITE/tests/hotspare/hotspare.kshlib
27
28################################################################################
29#
30# __stc_assertion_start
31#
32# ID: zfsd_hotspare_005_pos
33#
34# DESCRIPTION:
35#	If a spare gets added to an already damaged pool, the spare will be
36#	activated
37#
38# STRATEGY:
39#	1. Create 1 storage pool without hot spares
40#	2. Fail one vdev by using zinject to degrade or fault it
41#	3. Verify that it gets degraded or faulted, respectively
42#	4. Add a hotspare
43#	5. Verify that the spare is in use.
44#
45# TESTABILITY: explicit
46#
47# TEST_AUTOMATION_LEVEL: automated
48#
49# CODING STATUS: COMPLETED (2012-08-10)
50#
51# __stc_assertion_end
52#
53###############################################################################
54
55verify_runnable "global"
56
57function cleanup
58{
59	if poolexists $TESTPOOL ; then
60		destroy_pool $TESTPOOL
61	fi
62
63	partition_cleanup
64}
65
66function verify_assertion # damage_type
67{
68	typeset damage=$1
69	typeset err_dev=${devarray[3]}
70	typeset mntp=$(get_prop mountpoint $TESTPOOL)
71
72	log_must $ZINJECT -d $err_dev -A $damage $TESTPOOL
73	log_must check_state $TESTPOOL $err_dev ${damage_status[$damage]}
74
75	# Add the spare, and check that it is in use
76	log_must $ZPOOL add $TESTPOOL spare $sdev
77	for ((timeout=0; $timeout<10; timeout=$timeout+1)); do
78		if check_state $TESTPOOL "$sdev" "INUSE"; then
79			break
80		fi
81		$SLEEP 6
82	done
83	log_must $ZPOOL status $TESTPOOL
84	log_must check_state $TESTPOOL "$sdev" "INUSE"
85}
86
87log_onexit cleanup
88
89log_assert "A spare that is added to a degraded pool will be activated"
90
91ensure_zfsd_running
92set_devs
93
94typeset  sdev="${sparedevs[0]}"
95typeset -A damage_status
96damage_status["degrade"]="DEGRADED"
97damage_status["fault"]="FAULTED"
98
99set -A my_keywords "mirror" "raidz1" "raidz2"
100
101for keyword in "${my_keywords[@]}"; do
102	for damage in "degrade" "fault"; do
103		log_must create_pool $TESTPOOL $keyword ${pooldevs[@]}
104		verify_assertion $damage
105		destroy_pool $TESTPOOL
106	done
107done
108