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