]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - tests/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_009_neg.ksh
Vendor import of openzfs master @ 184df27eef0abdc7ab2105b21257f753834b936b
[FreeBSD/FreeBSD.git] / tests / zfs-tests / tests / functional / cli_root / zpool_import / zpool_import_009_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 2007 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_mount/zfs_mount.kshlib
34 . $STF_SUITE/tests/functional/cli_root/zpool_import/zpool_import.cfg
35
36 # DESCRIPTION:
37 #       Try each 'zpool import' with inapplicable scenarios to make sure
38 #       it returns an error. include:
39 #               * A non-existent pool name is given
40 #               * '-d', but no device directory specified
41 #               * '-R', but no alter root directory specified
42 #               * '-a', but a pool name specified either
43 #               * more than 2 pool names is given
44 #               * The new pool name specified already exists
45 #               * Contain invalid characters not allowed in the ZFS namespace
46 #
47 # STRATEGY:
48 #       1. Create an array of parameters
49 #       2. For each parameter in the array, execute the sub-command
50 #       3. Verify an error is returned.
51 #
52
53 verify_runnable "global"
54
55 set -A args "blah" "-d" "-R" "-a $TESTPOOL" \
56         "$TESTPOOL ${TESTPOOL}-new ${TESTPOOL}-new" \
57         "$TESTPOOL $TESTPOOL1" \
58         "$TESTPOOL ${TESTPOOL1}*" "$TESTPOOL ${TESTPOOL1}?"
59
60 set -A pools "$TESTPOOL" "$TESTPOOL1"
61 set -A devs "" "-d $DEVICE_DIR"
62
63 function cleanup
64 {
65         typeset -i i=0
66         typeset -i j=0
67
68         while (( i < ${#pools[*]} )); do
69
70                 poolexists ${pools[i]} && \
71                         log_must zpool export ${pools[i]}
72
73                 datasetexists "${pools[i]}/$TESTFS" || \
74                         log_must zpool import ${devs[i]} ${pools[i]}
75
76                 ismounted "${pools[i]}/$TESTFS" || \
77                         log_must zfs mount ${pools[i]}/$TESTFS
78
79                 ((i = i + 1))
80         done
81
82         cleanup_filesystem $TESTPOOL1 $TESTFS
83
84         destroy_pool $TESTPOOL1
85 }
86
87 log_onexit cleanup
88
89 log_assert "Badly-formed 'zpool import' with inapplicable scenarios " \
90         "should return an error."
91
92 setup_filesystem "$DEVICE_FILES" $TESTPOOL1 $TESTFS $TESTDIR1
93
94 log_must zpool export $TESTPOOL
95
96 typeset -i i=0
97 while (( i < ${#args[*]} )); do
98         log_mustnot zpool import ${args[i]}
99         ((i = i + 1))
100 done
101
102 log_pass "Badly formed 'zpool import' with inapplicable scenarios " \
103         "fail as expected."