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 2007 Sun Microsystems, Inc.  All rights reserved.
27# Use is subject to license terms.
28#
29# ident	"@(#)zpool_import_009_neg.ksh	1.2	07/01/09 SMI"
30#
31. $STF_SUITE/include/libtest.kshlib
32. $STF_SUITE/tests/cli_root/zfs_mount/zfs_mount.kshlib
33
34#################################################################################
35# __stc_assertion_start
36#
37# ID: zpool_import_009_neg
38#
39# DESCRIPTION:
40#	Try each 'zpool import' with inapplicable scenarios to make sure
41#	it returns an error. include:
42#		* A non-existent pool name is given
43#		* '-d', but no device directory specified
44#		* '-R', but no alter root directory specified
45#		* '-a', but a pool name specified either
46#		* more than 2 pool names is given
47#		* The new pool name specified already exists
48#		* Contain invalid characters not allowed in the ZFS namespace
49#
50# STRATEGY:
51#	1. Create an array of parameters
52#	2. For each parameter in the array, execute the sub-command
53#	3. Verify an error is returned.
54#
55# TESTABILITY: explicit
56#
57# TEST_AUTOMATION_LEVEL: automated
58#
59# CODING_STATUS: COMPLETED (2005-07-07)
60#
61# __stc_assertion_end
62#
63################################################################################
64
65verify_runnable "global"
66
67set -A args "blah" "-d" "-R" "-a $TESTPOOL" \
68	"$TESTPOOL ${TESTPOOL}-new ${TESTPOOL}-new" \
69	"$TESTPOOL $TESTPOOL1" \
70	"$TESTPOOL ${TESTPOOL1}*" "$TESTPOOL ${TESTPOOL1}?"
71
72set -A pools "$TESTPOOL" "$TESTPOOL1"
73set -A devs "" "-d $DEVICE_DIR"
74
75function cleanup
76{
77	typeset -i i=0
78	typeset -i j=0
79
80	while (( i < ${#pools[*]} )); do
81
82		poolexists ${pools[i]} && \
83			log_must $ZPOOL export ${pools[i]}
84
85		datasetexists "${pools[i]}/$TESTFS" || \
86			log_must $ZPOOL import ${devs[i]} ${pools[i]}
87
88		ismounted "${pools[i]}/$TESTFS" || \
89			log_must $ZFS mount ${pools[i]}/$TESTFS
90
91		((i = i + 1))
92	done
93
94	cleanup_filesystem $TESTPOOL1 $TESTFS
95
96        destroy_pool $TESTPOOL1
97}
98
99log_onexit cleanup
100
101log_assert "Badly-formed 'zpool import' with inapplicable scenarios " \
102	"should return an error."
103
104setup_filesystem "$DEVICE_FILES" $TESTPOOL1 $TESTFS $TESTDIR1
105
106log_must $ZPOOL export $TESTPOOL
107
108typeset -i i=0
109while (( i < ${#args[*]} )); do
110	log_mustnot $ZPOOL import ${args[i]}
111	((i = i + 1))
112done
113
114log_pass "Badly formed 'zpool import' with inapplicable scenarios " \
115	"fail as expected."
116