xref: /illumos-gate/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_001_pos.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. $STF_SUITE/tests/functional/cli_root/zfs_get/zfs_get_list_d.kshlib
34
35#
36# DESCRIPTION:
37# Setting the valid option and properties, 'zfs get' should return the
38# correct property value.
39#
40# STRATEGY:
41# 1. Create pool, filesystem, volume, snapshot, and bookmark.
42# 2. Setting valid parameter, 'zfs get' should succeed.
43# 3. Compare the output property name with the original input property.
44#
45
46verify_runnable "both"
47
48typeset options=("" "-p" "-r" "-H")
49
50typeset -i i=${#options[*]}
51typeset -i j=0
52while ((j<${#depth_options[*]}));
53do
54	options[$i]=-"${depth_options[$j]}"
55	((j+=1))
56	((i+=1))
57done
58
59typeset zfs_props=("type" used available creation volsize referenced \
60    compressratio mounted origin recordsize quota reservation mountpoint \
61    sharenfs checksum compression atime devices exec readonly setuid zoned \
62    snapdir aclmode aclinherit canmount primarycache secondarycache \
63    usedbychildren usedbydataset usedbyrefreservation usedbysnapshots \
64    version)
65
66typeset userquota_props=(userquota@root groupquota@root userused@root \
67    groupused@root)
68typeset all_props=("${zfs_props[@]}" "${userquota_props[@]}")
69typeset dataset=($TESTPOOL/$TESTCTR $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL \
70	$TESTPOOL/$TESTFS@$TESTSNAP $TESTPOOL/$TESTVOL@$TESTSNAP)
71
72typeset bookmark_props=(creation)
73typeset bookmark=($TESTPOOL/$TESTFS#$TESTBKMARK $TESTPOOL/$TESTVOL#$TESTBKMARK)
74
75#
76# According to dataset and option, checking if 'zfs get' return correct
77# property information.
78#
79# $1 dataset
80# $2 properties which are expected to output into $TESTDIR/$TESTFILE0
81# $3 option
82#
83function check_return_value
84{
85	typeset dst=$1
86	typeset props=$2
87	typeset opt=$3
88	typeset -i found=0
89	typeset p
90
91	for p in $props; do
92		found=0
93
94		while read line; do
95			typeset item
96			item=$(echo $line | awk '{print $2}' 2>&1)
97
98			if [[ $item == $p ]]; then
99				((found += 1))
100				break
101			fi
102		done < $TESTDIR/$TESTFILE0
103
104		if ((found == 0)); then
105			log_fail "'zfs get $opt $props $dst' return " \
106			    "error message.'$p' haven't been found."
107		fi
108	done
109
110	log_note "SUCCESS: 'zfs get $opt $prop $dst'."
111}
112
113log_assert "Setting the valid options and properties 'zfs get' should return " \
114    "the correct property value."
115log_onexit cleanup
116
117# Create filesystem and volume's snapshot
118create_snapshot $TESTPOOL/$TESTFS $TESTSNAP
119create_snapshot $TESTPOOL/$TESTVOL $TESTSNAP
120
121# Create filesystem and volume's bookmark
122create_bookmark $TESTPOOL/$TESTFS $TESTSNAP $TESTBKMARK
123create_bookmark $TESTPOOL/$TESTVOL $TESTSNAP $TESTBKMARK
124
125typeset -i i=0
126while ((i < ${#dataset[@]})); do
127	for opt in "${options[@]}"; do
128		for prop in ${all_props[@]}; do
129			eval "zfs get $opt $prop ${dataset[i]} > \
130			    $TESTDIR/$TESTFILE0"
131			ret=$?
132			if [[ $ret != 0 ]]; then
133				log_fail "zfs get returned: $ret"
134			fi
135			check_return_value ${dataset[i]} "$prop" "$opt"
136		done
137	done
138	((i += 1))
139done
140
141i=0
142while ((i < ${#bookmark[@]})); do
143	for opt in "${options[@]}"; do
144		for prop in ${bookmark_props[@]}; do
145			eval "zfs get $opt $prop ${bookmark[i]} > \
146			    $TESTDIR/$TESTFILE0"
147			ret=$?
148			if [[ $ret != 0 ]]; then
149				log_fail "zfs get returned: $ret"
150			fi
151			check_return_value ${bookmark[i]} "$prop" "$opt"
152		done
153	done
154	((i += 1))
155done
156
157log_pass "Setting the valid options to dataset, it should succeed and return " \
158    "valid value. 'zfs get' pass."
159