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 2009 Sun Microsystems, Inc.  All rights reserved.
27# Use is subject to license terms.
28#
29# ident	"@(#)zfs_get_005_neg.ksh	1.5	09/06/22 SMI"
30#
31
32. $STF_SUITE/tests/cli_root/zfs_get/zfs_get_common.kshlib
33. $STF_SUITE/tests/userquota/userquota_common.kshlib
34
35###############################################################################
36#
37# __stc_assertion_start
38#
39# ID: zfs_get_005_neg
40#
41# DESCRIPTION:
42# Setting the invalid option and properties, 'zfs get' should failed.
43#
44# STRATEGY:
45# 1. Create pool, filesystem, volume and snapshot.
46# 2. Getting incorrect combination by invalid parameters
47# 3. Using the combination as the parameters of 'zfs get' to check the
48# command line return value.
49#
50# TESTABILITY: explicit
51#
52# TEST_AUTOMATION_LEVEL: automated
53#
54# CODING_STATUS: COMPLETED (2005-07-04)
55#
56# __stc_assertion_end
57#
58################################################################################
59
60verify_runnable "both"
61
62set -A val_opts p r H
63set -A v_props type used available creation volsize referenced compressratio mounted \
64	origin recordsize quota reservation mountpoint sharenfs checksum \
65	compression atime devices exec readonly setuid zoned snapdir aclmode \
66	aclinherit canmount primarycache secondarycache \
67	usedbychildren usedbydataset usedbyrefreservation usedbysnapshots
68
69$ZFS upgrade -v > /dev/null 2>&1
70if [[ $? -eq 0 ]]; then
71	set -A v_props ${v_props[*]} version
72fi
73
74if is_userquota_supported; then
75	set -A  userquota_props userquota@root groupquota@root \
76		userused@root groupused@root
77fi
78
79set -A val_pros -- "${v_props[@]}" "${userquota_props[@]}"
80
81set -f	# Force shell does not parse '?' and '*' as the wildcard
82set -A inval_opts P R h ? *
83set -A inval_props Type 0 ? * -on --on readonl time USED RATIO MOUNTED
84
85set -A dataset $TESTPOOL/$TESTFS $TESTPOOL/$TESTCTR $TESTPOOL/$TESTVOL \
86	$TESTPOOL/$TESTFS@$TESTSNAP $TESTPOOL/$TESTVOL@$TESTSNAP
87
88typeset -i opt_numb=6
89typeset -i prop_numb=12
90
91val_opts_str=$(gen_option_str "${val_opts[*]}" "-" "" $opt_numb)
92val_props_str=$(gen_option_str "${val_props[*]}" "" "," $prop_numb)
93val_props_str="$val_props_str -a -d"
94
95inval_opts_str=$(gen_option_str "${inval_opts[*]}" "-" "" $opt_numb)
96inval_props_str=$(gen_option_str "${inval_props[*]}" "" "," $prop_numb)
97
98#
99# Test different options and properties combination.
100#
101# $1 options
102# $2 properties
103#
104function test_options
105{
106	typeset opts=$1
107	typeset props=$2
108
109	for dst in ${dataset[@]}; do
110		for opt in $opts; do
111			for prop in $props; do
112				$ZFS get $opt $prop $dst > /dev/null 2>&1
113				ret=$?
114				if [[ $ret == 0 ]]; then
115					log_fail "$ZFS get \
116    $opt $prop $dst unexpectedly succeeded."
117				fi
118			done
119		done
120	done
121}
122
123log_assert "Setting the invalid option and properties, 'zfs get' should be \
124	failed."
125log_onexit cleanup
126
127# Create filesystem and volume's snapshot
128create_snapshot $TESTPOOL/$TESTFS $TESTSNAP
129create_snapshot $TESTPOOL/$TESTVOL $TESTSNAP
130
131log_note "Valid options + invalid properties, 'zfs get' should fail."
132test_options "$val_opts_str" "$inval_props_str"
133
134log_note "Invalid options + valid properties, 'zfs get' should fail."
135test_options "$inval_opts_str" "$val_props_str"
136
137log_note "Invalid options + invalid properties, 'zfs get' should fail."
138test_options "$inval_opts_str" "$inval_props_str"
139
140log_pass "Setting the invalid options to dataset, 'zfs get' pass."
141