119304Speter#!/usr/local/bin/ksh93 -p
219304Speter#
319304Speter# CDDL HEADER START
419304Speter#
519304Speter# The contents of this file are subject to the terms of the
619304Speter# Common Development and Distribution License (the "License").
719304Speter# You may not use this file except in compliance with the License.
819304Speter#
919304Speter# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
1019304Speter# or http://www.opensolaris.org/os/licensing.
1119304Speter# See the License for the specific language governing permissions
1219304Speter# and limitations under the License.
1319304Speter#
1419304Speter# When distributing Covered Code, include this CDDL HEADER in each
1519304Speter# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
1619304Speter# If applicable, add the following below this CDDL HEADER, with the
1719304Speter# fields enclosed by brackets "[]" replaced with your own identifying
1819304Speter# information: Portions Copyright [yyyy] [name of copyright owner]
1919304Speter#
2019304Speter# CDDL HEADER END
2119304Speter#
2219304Speter
2319304Speter#
2419304Speter# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
2519304Speter# Use is subject to license terms.
2619304Speter. $STF_SUITE/tests/hotspare/hotspare.kshlib
2719304Speter
2819304Speter################################################################################
2919304Speter#
3019304Speter# __stc_assertion_start
3119304Speter#
3219304Speter# ID: hotspare_onoffline_003_neg
3319304Speter#
3419304Speter# DESCRIPTION:
3519304Speter#	Regardless a hot spare is only in the available hot spare list,
3619304Speter#	or have been activated,
3719304Speter#	invoke "zpool offline" & "zpool online" with this hot spare
3819304Speter#	will fail with a return code of 1 and issue an error message.
3919304Speter#
4019304Speter# STRATEGY:
4119304Speter#	1. Create a storage pool with hot spares
4219304Speter#	2. Try 'zpool offline' & 'zpool online' with each hot spare 
4319304Speter#		of following condition
4419304Speter#		- only in the list of available hot spares (fail)
4519304Speter#		- have been activated (fail)
4619304Speter#	3. Verify offline/online results as expected.
4719304Speter#
4819304Speter# TESTABILITY: explicit
4919304Speter#
5019304Speter# TEST_AUTOMATION_LEVEL: automated
5119304Speter#
5219304Speter# CODING STATUS: COMPLETED (2006-06-07)
5319304Speter#
5419304Speter# __stc_assertion_end
5519304Speter#
5619304Speter###############################################################################
5719304Speter
5819304Speterverify_runnable "global"
5919304Speter
6019304Speterfunction cleanup
6119304Speter{
6219304Speter	poolexists $TESTPOOL && \
6319304Speter		destroy_pool $TESTPOOL
6419304Speter
6519304Speter	partition_cleanup
6619304Speter}
6719304Speter
6819304Speterfunction verify_assertion # dev
6919304Speter{
7019304Speter	typeset dev=$1
7119304Speter	typeset odev=${pooldevs[0]}
7219304Speter
7319304Speter	log_mustnot $ZPOOL offline $TESTPOOL $dev
7419304Speter	log_must check_hotspare_state $TESTPOOL $dev "AVAIL"
7519304Speter
7619304Speter	log_mustnot $ZPOOL online $TESTPOOL $dev
7719304Speter	log_must check_hotspare_state $TESTPOOL $dev "AVAIL"
7819304Speter}
7919304Speter
8019304Speterlog_assert "'zpool offline/online <pool> <vdev>' should fail on inactive spares"
8119304Speter
8219304Speterlog_onexit cleanup
8319304Speter
8419304Speterset_devs
8519304Speter
8619304Speterfor keyword in "${keywords[@]}" ; do
8719304Speter	setup_hotspares "$keyword"
8819304Speter
8919304Speter	iterate_over_hotspares verify_assertion
9019304Speter
9119304Speter	destroy_pool "$TESTPOOL"
9219304Speterdone
9319304Speter
9419304Speterlog_pass "'zpool offline/online <pool> <vdev>' against a hot spare works as expected."
9519304Speter