xref: /illumos-gate/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_020_pos.ksh (revision 48bbca816818409505a6e214d0911fda44e622e3)
1#!/usr/bin/ksh -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
28#
29# Copyright (c) 2012, 2016 by Delphix. All rights reserved.
30#
31
32. $STF_SUITE/include/libtest.shlib
33. $STF_SUITE/tests/functional/cli_root/zpool_create/zpool_create.cfg
34
35#
36# DESCRIPTION:
37#
38# zpool create -R works as expected
39#
40# STRATEGY:
41# 1. Create a -R altroot pool
42# 2. Verify the pool is mounted at the correct location
43# 3. Verify that cachefile=none for the pool
44# 4. Verify that root=<mountpoint> for the pool
45# 5. Verify that no reference to the pool is found in /etc/zfs/zpool.cache
46
47function cleanup
48{
49	if poolexists $TESTPOOL ; then
50                destroy_pool $TESTPOOL
51        fi
52	if [ -d ${TESTPOOL}.root ]
53	then
54		log_must rmdir ${TESTPOOL}.root
55	fi
56}
57
58log_onexit cleanup
59
60log_assert "zpool create -R works as expected"
61
62if [[ -n $DISK ]]; then
63	disk=$DISK
64else
65	disk=$DISK0
66fi
67
68log_must mkdir /${TESTPOOL}.root
69log_must zpool create -R /${TESTPOOL}.root $TESTPOOL $disk
70if [ ! -d /${TESTPOOL}.root ]
71then
72	log_fail "Mountpoint was not create when using zpool with -R flag!"
73fi
74
75FS=$(zfs list $TESTPOOL)
76if [ -z "$FS" ]
77then
78	log_fail "Mounted filesystem at /${TESTPOOL}.root isn't ZFS!"
79fi
80
81log_must zpool get all $TESTPOOL
82zpool get all $TESTPOOL > /tmp/values.$$
83
84# check for the cachefile property, verifying that it's set to 'none'
85grep "$TESTPOOL[ ]*cachefile[ ]*none" /tmp/values.$$ > /dev/null 2>&1
86if [ $? -ne 0 ]
87then
88	log_fail "zpool property \'cachefile\' was not set to \'none\'."
89fi
90
91# check that the root = /mountpoint property is set correctly
92grep "$TESTPOOL[ ]*altroot[ ]*/${TESTPOOL}.root" /tmp/values.$$ > /dev/null 2>&1
93if [ $? -ne 0 ]
94then
95	log_fail "zpool property root was not found in pool output."
96fi
97
98rm /tmp/values.$$
99
100# finally, check that the pool has no reference in /etc/zfs/zpool.cache
101if [[ -f /etc/zfs/zpool.cache ]] ; then
102	REF=$(strings /etc/zfs/zpool.cache | grep ${TESTPOOL})
103	if [ ! -z "$REF" ]
104	then
105		strings /etc/zfs/zpool.cache
106		log_fail "/etc/zfs/zpool.cache appears to have a reference to $TESTPOOL"
107	fi
108fi
109
110
111log_pass "zpool create -R works as expected"
112