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 2008 Sun Microsystems, Inc.  All rights reserved.
27# Use is subject to license terms.
28#
29# ident	"@(#)zpool_create_005_pos.ksh	1.3	08/02/27 SMI"
30#
31. $STF_SUITE/include/libtest.kshlib
32. $STF_SUITE/tests/cli_root/zpool_create/zpool_create.kshlib
33
34################################################################################
35#
36# __stc_assertion_start
37#
38# ID: zpool_create_005_pos
39#
40# DESCRIPTION:
41# 'zpool create [-R root][-m mountpoint] <pool> <vdev> ...' can create an
42#  alternate root pool or a new pool mounted at the specified mountpoint.
43#
44# STRATEGY:
45# 1. Create a pool with '-m' option
46# 2. Verify the pool is mounted at the specified mountpoint
47#
48# TESTABILITY: explicit
49#
50# TEST_AUTOMATION_LEVEL: automated
51#
52# CODING_STATUS: COMPLETED (2006-08-04)
53#
54# __stc_assertion_end
55#
56################################################################################
57
58verify_runnable "global"
59
60function cleanup
61{
62	poolexists $TESTPOOL && \
63		log_must $ZPOOL destroy -f $TESTPOOL
64
65	for dir in $TMPDIR/zpool_create_005_pos $TESTDIR1; do
66		[[ -d $dir ]] && $RM -rf $dir
67	done
68}
69
70log_assert "'zpool create [-R root][-m mountpoint] <pool> <vdev> ...' can create" \
71	"an alternate pool or a new pool mounted at the specified mountpoint."
72log_onexit cleanup
73
74set -A pooltype "" "mirror" "raidz" "raidz1" "raidz2"
75
76#prepare raw file for file disk
77TDIR=$TMPDIR/zpool_create_005_pos
78FBASE=$TDIR/file
79log_must $MKDIR $TDIR
80log_must create_vdevs $FBASE.0 $FBASE.1 $FBASE.2 $FBASE.3
81#Remove the directory with name as pool name if it exists
82[[ -d /$TESTPOOL ]] && $RM -rf /$TESTPOOL
83
84for opt in "-R $TESTDIR1" "-m $TESTDIR1" \
85	"-R $TESTDIR1 -m $TESTDIR1" "-m $TESTDIR1 -R $TESTDIR1"
86do
87	i=0
88	while (( i < ${#pooltype[*]} )); do
89		#Remove the testing pool and its mount directory
90		poolexists $TESTPOOL && \
91			log_must $ZPOOL destroy -f $TESTPOOL
92		[[ -d $TESTDIR1 ]] && $RM -rf $TESTDIR1
93		log_must $ZPOOL create $opt $TESTPOOL ${pooltype[i]} \
94			$FBASE.1 $FBASE.2 $FBASE.3
95		mpt=`$ZFS mount | $EGREP "^$TESTPOOL[^/]" | $AWK '{print $2}'`
96		(( ${#mpt} == 0 )) && \
97			log_fail "$TESTPOOL created with $opt is not mounted."
98		mpt_val=$(get_prop "mountpoint" $TESTPOOL)
99		[[ "$mpt" != "$mpt_val" ]] && \
100			log_fail "The value of mountpoint property is different\
101				from the output of zfs mount"
102		if [[ "$opt" == "-R $TESTDIR1" ]]; then
103			expected_mpt=${TESTDIR1}/${TESTPOOL}
104		elif [[ "$opt" == "-m $TESTDIR1" ]]; then
105			expected_mpt=${TESTDIR1}
106		else
107			expected_mpt=${TESTDIR1}${TESTDIR1}
108		fi
109		[[ ! -d $expected_mpt ]] && \
110			log_fail "$expected_mpt is not created auotmatically."
111		[[ "$mpt" != "$expected_mpt" ]] && \
112			log_fail "$expected_mpt is mounted on ${mpt} instead of $expected_mpt."
113
114		[[ -d /$TESTPOOL ]] && \
115			log_fail "The default mountpoint /$TESTPOOL is created" \
116				"while with $opt option."
117
118		(( i = i + 1 ))
119	done
120done
121
122log_pass "'zpool create [-R root][-m mountpoint] <pool> <vdev> ...' works as expected."
123