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. $STF_SUITE/include/libtest.kshlib
27. $STF_SUITE/tests/cli_root/zfs_rename/zfs_rename.kshlib
28
29################################################################################
30#
31# __stc_assertion_start
32#
33# ID: zfs_rename_011_pos
34#
35# DESCRIPTION
36#       'zfs rename -p' should work as expected
37#
38# STRATEGY:
39#	1. Make sure the upper level of $newdataset does not exist
40#       2. Make sure without -p option, 'zfs rename' will fail
41#       3. With -p option, rename works
42#
43# TESTABILITY: explicit
44#
45# TEST_AUTOMATION_LEVEL: automated
46#
47# CODING_STATUS: COMPLETED (2007-06-05)
48#
49# __stc_assertion_end
50#
51###############################################################################
52
53if ! $(check_opt_support "create" "-p") ; then
54	log_unsupported "-p option is not supported yet."
55fi
56
57verify_runnable "both"
58
59function additional_cleanup
60{
61	if datasetexists $TESTPOOL/notexist ; then
62		log_must $ZFS destroy -Rf $TESTPOOL/notexist
63	fi
64
65	if datasetexists $TESTPOOL/$TESTFS ; then
66		log_must $ZFS destroy -Rf $TESTPOOL/$TESTFS
67	fi
68	log_must $ZFS create $TESTPOOL/$TESTFS
69
70	if is_global_zone ; then
71		if datasetexists $TESTPOOL/$TESTVOL ; then
72			log_must $ZFS destroy -Rf $TESTPOOL/$TESTVOL
73		fi
74		log_must $ZFS create -V $VOLSIZE $TESTPOOL/$TESTVOL
75	fi
76}
77
78log_onexit additional_cleanup
79
80log_assert "'zfs rename -p' should work as expected"
81
82log_must verify_opt_p_ops "rename" "fs" "$TESTPOOL/$TESTFS" \
83	"$TESTPOOL/notexist/new/$TESTFS1"
84
85if is_global_zone; then
86	log_must verify_opt_p_ops "rename" "vol" "$TESTPOOL/$TESTVOL" \
87		"$TESTPOOL/notexist/new/$TESTVOL1"
88fi
89
90log_pass "'zfs rename -p' should work as expected"
91