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# ident	"@(#)zpool_create_020_pos.ksh	1.3	09/05/19 SMI"
28#
29
30. $STF_SUITE/include/libtest.kshlib
31. $STF_SUITE/tests/cli_root/zpool_create/zpool_create.kshlib
32
33################################################################################
34#
35# __stc_assertion_start
36#
37# ID: zpool_create_020_pos
38#
39# DESCRIPTION:
40#
41# zpool create -R works as expected
42#
43# STRATEGY:
44# 1. Create a -R altroot pool
45# 2. Verify the pool is mounted at the correct location
46# 3. Verify that cachefile=none for the pool
47# 4. Verify that root=<mountpoint> for the pool
48# 5. Verify that no reference to the pool is found in /etc/zfs/zpool.cache
49
50#
51# TESTABILITY: explicit
52#
53# TEST_AUTOMATION_LEVEL: automated
54#
55# CODING_STATUS: COMPLETED (2007-07-27)
56#
57# __stc_assertion_end
58#
59################################################################################
60
61function cleanup
62{
63	poolexists $TESTPOOL && destroy_pool $TESTPOOL
64	[[ -d ${TESTPOOL}.root ]] && log_must $RM -rf /${TESTPOOL}.root
65}
66
67log_onexit cleanup
68
69log_assert "zpool create -R works as expected"
70
71if [[ -n $DISK ]]; then
72	disk=$DISK
73else
74	disk=$DISK0
75fi
76
77$RM -rf /${TESTPOOL}.root
78log_must $MKDIR /${TESTPOOL}.root
79log_must $ZPOOL create -R /${TESTPOOL}.root $TESTPOOL $disk
80if [ ! -d /${TESTPOOL}.root ]
81then
82	log_fail "Mountpoint was not create when using zpool with -R flag!"
83fi
84
85FS=$($ZFS list $TESTPOOL)
86if [ -z "$FS" ]
87then
88	log_fail "Mounted filesystem at /${TESTPOOL}.root isn't ZFS!"
89fi
90
91log_must $ZPOOL get all $TESTPOOL
92$ZPOOL get all $TESTPOOL > $TMPDIR/values.${TESTCASE_ID}
93
94# check for the cachefile property, verifying that it's set to 'none'
95$GREP "$TESTPOOL[ ]*cachefile[ ]*none" $TMPDIR/values.${TESTCASE_ID} > /dev/null 2>&1
96if [ $? -ne 0 ]
97then
98	log_fail "zpool property \'cachefile\' was not set to \'none\'."
99fi
100
101# check that the root = /mountpoint property is set correctly
102$GREP "$TESTPOOL[ ]*altroot[ ]*/${TESTPOOL}.root" $TMPDIR/values.${TESTCASE_ID} > /dev/null 2>&1
103if [ $? -ne 0 ]
104then
105	log_fail "zpool property root was not found in pool output."
106fi
107
108$RM $TMPDIR/values.${TESTCASE_ID}
109
110# finally, check that the pool has no reference in /etc/zfs/zpool.cache
111if [[ -f /etc/zfs/zpool.cache ]] ; then
112	REF=$($STRINGS /etc/zfs/zpool.cache | $GREP ${TESTPOOL})
113	if [ ! -z "$REF" ]
114	then
115		$STRINGS /etc/zfs/zpool.cache
116		log_fail "/etc/zfs/zpool.cache appears to have a reference to $TESTPOOL"
117	fi
118fi
119
120
121log_pass "zpool create -R works as expected"
122