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