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