]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - tests/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_005_neg.ksh
Vendor import of openzfs master @ 184df27eef0abdc7ab2105b21257f753834b936b
[FreeBSD/FreeBSD.git] / tests / zfs-tests / tests / functional / cli_root / zfs_rename / zfs_rename_005_neg.ksh
1 #!/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/zfs_rename/zfs_rename.kshlib
34
35 #
36 # DESCRIPTION:
37 #       'zfs rename' should fail when the dataset are not within the same pool
38 #
39 # STRATEGY:
40 #       1. Given a file system, snapshot and volume.
41 #       2. Rename each dataset object to a different pool.
42 #       3. Verify the operation fails, and only the original name
43 #          is displayed by zfs list.
44 #
45
46 verify_runnable "global"
47
48 function my_cleanup
49 {
50         poolexists $TESTPOOL1 && \
51                 destroy_pool $TESTPOOL1
52         [[ -e $TESTDIR/$TESTFILE1 ]] && \
53                 log_must rm -f $TESTDIR/$TESTFILE1
54         cleanup
55 }
56
57 set -A src_dataset \
58     "$TESTPOOL/$TESTFS1" "$TESTPOOL/$TESTCTR1" \
59     "$TESTPOOL/$TESTCTR/$TESTFS1" "$TESTPOOL/$TESTVOL" \
60     "$TESTPOOL/$TESTFS@snapshot" "$TESTPOOL/$TESTFS-clone"
61
62 #
63 # cleanup defined in zfs_rename.kshlib
64 #
65 log_onexit my_cleanup
66
67 log_assert "'zfs rename' should fail while datasets are within different pool."
68
69 additional_setup
70
71 log_must mkfile $MINVDEVSIZE $TESTDIR/$TESTFILE1
72 create_pool $TESTPOOL1 $TESTDIR/$TESTFILE1
73
74 for src in ${src_dataset[@]} ; do
75         dest=${src#$TESTPOOL/}
76         if [[ $dest == *"@"* ]]; then
77                 dest=${dest#*@}
78                 dest=${TESTPOOL1}@$dest
79         else
80                 dest=${TESTPOOL1}/$dest
81         fi
82         log_mustnot zfs rename $src $dest
83         log_mustnot zfs rename -p $src $dest
84
85         #
86         # Verify original dataset name still in use
87         #
88         log_must datasetexists $src
89 done
90
91 log_pass "'zfs rename' fail while datasets are within different pool."