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#
24# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
25# Use is subject to license terms.
26#
27# ident	"@(#)zfs_get_001_pos.ksh	1.6	09/06/22 SMI"
28#
29
30. $STF_SUITE/tests/cli_root/zfs_get/zfs_get_common.kshlib
31. $STF_SUITE/tests/cli_root/zfs_get/zfs_get_list_d.kshlib
32. $STF_SUITE/tests/userquota/userquota_common.kshlib
33
34###############################################################################
35#
36# __stc_assertion_start
37#
38# ID: zfs_get_001_pos
39#
40# DESCRIPTION:
41# Setting the valid option and properties, 'zfs get' should return the
42# correct property value.
43#
44# STRATEGY:
45# 1. Create pool, filesystem, volume and snapshot.
46# 2. Setting valid parameter, 'zfs get' should succeed.
47# 3. Compare the output property name with the original input property.
48#
49# TESTABILITY: explicit
50#
51# TEST_AUTOMATION_LEVEL: automated
52#
53# CODING_STATUS: COMPLETED (2005-07-04)
54#
55# __stc_assertion_end
56#
57################################################################################
58
59verify_runnable "both"
60
61set -A options "" "-p" "-r" "-H"
62if zfs_get_list_d_supported ; then
63	typeset -i i=${#options[*]}
64	typeset -i j=0
65	while (( j<${#depth_options[*]} ));
66	do
67		options[$i]=-"${depth_options[$j]}"
68		(( j+=1 ))
69		(( i+=1 ))
70	done
71fi
72
73set -A zfs_props type used available creation volsize referenced \
74	compressratio mounted origin recordsize quota reservation mountpoint \
75	sharenfs checksum compression atime devices exec readonly setuid \
76	snapdir aclmode aclinherit canmount primarycache secondarycache \
77	usedbychildren usedbydataset usedbyrefreservation usedbysnapshots
78
79
80$ZFS upgrade -v > /dev/null 2>&1
81if [[ $? -eq 0 ]]; then
82	set -A zfs_props ${zfs_props[*]} version
83fi
84
85if is_userquota_supported; then
86	set -A  userquota_props userquota@root groupquota@root \
87		userused@root groupused@root
88fi
89
90set -A all_props --  "${zfs_props[@]}" "${userquota_props[@]}"
91
92set -A dataset $TESTPOOL/$TESTCTR $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL \
93	$TESTPOOL/$TESTFS@$TESTSNAP $TESTPOOL/$TESTVOL@$TESTSNAP
94
95#
96# According to dataset and option, checking if 'zfs get' return correct
97# property information.
98#
99# $1 dataset
100# $2 properties which are expected to output into $TESTDIR/$TESTFILE0
101# $3 option
102#
103function check_return_value
104{
105	typeset dst=$1
106	typeset props=$2
107	typeset opt=$3
108	typeset -i found=0
109	typeset p
110
111	for p in $props; do
112		found=0
113
114		while read line; do
115			typeset item
116			item=$($ECHO $line | $AWK '{print $2}' 2>&1)
117
118			if [[ $item == $p ]]; then
119				(( found += 1 ))
120				break
121			fi
122		done < $TESTDIR/$TESTFILE0
123
124		if (( found == 0 )); then
125			log_fail "'zfs get $opt $props $dst' return " \
126				"error message.'$p' haven't been found."
127		fi
128	done
129
130	log_note "SUCCESS: '$ZFS get $opt $prop $dst'."
131}
132
133log_assert "Setting the valid options and properties 'zfs get' should return " \
134	"the correct property value."
135log_onexit cleanup
136
137# Create filesystem and volume's snapshot
138create_snapshot $TESTPOOL/$TESTFS $TESTSNAP
139create_snapshot $TESTPOOL/$TESTVOL $TESTSNAP
140
141typeset -i i=0
142while (( i < ${#dataset[@]} )); do
143	for opt in "${options[@]}"; do
144		for prop in ${all_props[@]}; do
145			eval "$ZFS get $opt $prop ${dataset[i]} > \
146				$TESTDIR/$TESTFILE0"
147			ret=$?
148			if [[ $ret != 0 ]]; then
149				log_fail "$ZFS get returned: $ret"
150			fi
151			check_return_value ${dataset[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