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# $FreeBSD$
24
25#
26# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
27# Use is subject to license terms.
28#
29# ident	"@(#)cachefile_004_pos.ksh	1.2	09/06/22 SMI"
30#
31
32. $STF_SUITE/include/libtest.kshlib
33. $STF_SUITE/tests/cachefile/cachefile.kshlib
34
35#################################################################################
36#
37# __stc_assertion_start
38#
39# ID: cachefile_004_pos
40#
41# DESCRIPTION:
42#	Verify set, export and destroy when cachefile is set on pool.
43#
44# STRATEGY:
45#	1. Create two pools with one same cahcefile1.
46#	2. Set cachefile of the two pools to another same cachefile2.
47#	3. Verify cachefile1 not exist.
48#	4. Export the two pools.
49#	5. Verify cachefile2 not exist.
50#	6. Import the two pools and set cachefile to cachefile2.
51#	7. Destroy the two pools.
52#	8. Verify cachefile2 not exist.
53#
54# TESTABILITY: explicit
55#
56# TEST_AUTOMATION_LEVEL: automated
57#
58# CODING_STATUS: COMPLETED (2009-04-24)
59#
60# __stc_assertion_end
61#
62################################################################################
63
64verify_runnable "global"
65
66function cleanup
67{
68	destroy_pool $TESTPOOL1
69	destroy_pool $TESTPOOL2
70
71	mntpnt=$(get_prop mountpoint $TESTPOOL)
72	typeset -i i=0
73	while ((i < 2)); do
74		if [[ -e $mntpnt/vdev$i ]]; then
75			log_must $RM -f $mntpnt/vdev$i
76		fi
77		((i += 1))
78	done
79
80	destroy_pool $TESTPOOL
81
82	for file in $CPATH1 $CPATH2 ; do
83		if [[ -f $file ]] ; then
84			log_must $RM $file
85		fi
86	done
87}
88
89
90log_assert "Verify set, export and destroy when cachefile is set on pool."
91log_onexit cleanup
92
93log_must $ZPOOL create $TESTPOOL $DISKS
94
95mntpnt=$(get_prop mountpoint $TESTPOOL)
96typeset -i i=0
97while ((i < 2)); do
98	log_must create_vdevs $mntpnt/vdev$i
99	eval vdev$i=$mntpnt/vdev$i
100	((i += 1))
101done
102
103log_must $ZPOOL create -o cachefile=$CPATH1 $TESTPOOL1 $vdev0
104log_must pool_in_cache $TESTPOOL1 $CPATH1
105log_must $ZPOOL create -o cachefile=$CPATH1 $TESTPOOL2 $vdev1
106log_must pool_in_cache $TESTPOOL2 $CPATH1
107
108log_must $ZPOOL set cachefile=$CPATH2 $TESTPOOL1
109log_must pool_in_cache $TESTPOOL1 $CPATH2
110log_must $ZPOOL set cachefile=$CPATH2 $TESTPOOL2
111log_must pool_in_cache $TESTPOOL2 $CPATH2
112if [[ -f $CPATH1 ]]; then
113	log_fail "Verify set when cachefile is set on pool."
114fi
115
116log_must $ZPOOL export $TESTPOOL1
117log_must $ZPOOL export $TESTPOOL2
118if [[ -f $CPATH2 ]]; then
119	log_fail "Verify export when cachefile is set on pool."
120fi
121
122log_must $ZPOOL import -d $mntpnt $TESTPOOL1
123log_must $ZPOOL set cachefile=$CPATH2 $TESTPOOL1
124log_must pool_in_cache $TESTPOOL1 $CPATH2
125log_must $ZPOOL import -d $mntpnt $TESTPOOL2
126log_must $ZPOOL set cachefile=$CPATH2 $TESTPOOL2
127log_must pool_in_cache $TESTPOOL2 $CPATH2
128
129log_must $ZPOOL destroy $TESTPOOL1
130log_must $ZPOOL destroy $TESTPOOL2
131if [[ -f $CPATH2 ]]; then
132	log_fail "Verify destroy when cachefile is set on pool."
133fi
134
135log_pass "Verify set, export and destroy when cachefile is set on pool."
136
137