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. $STF_SUITE/tests/cli_root/zfs_set/zfs_set_common.kshlib
28
29#################################################################################
30#
31# __stc_assertion_start
32#
33# ID: zfs_snapshot_006_pos
34#
35# DESCRIPTION:
36#	User property could be set via creation time by 'zfs snapshot -o'
37#
38# STRATEGY:
39#	1. Create snapshot and give '-o property=value'
40#	2. Verify the snapshot be created and user property have been set.
41#
42# TESTABILITY: explicit
43#
44# TEST_AUTOMATION_LEVEL: automated
45#
46# CODING_STATUS: COMPLETED (2009-04-27)
47#
48# __stc_assertion_end
49#
50################################################################################
51
52verify_runnable "both"
53
54function cleanup
55{
56	for fs in $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL $TESTPOOL ; do
57		typeset fssnap=$fs@snap
58		if datasetexists $fssnap ; then
59			log_must $ZFS destroy -rf $fssnap
60		fi
61	done
62	cleanup_user_prop $TESTPOOL
63}
64
65function nonexist_user_prop
66{
67	typeset user_prop=$1
68	typeset dtst=$2
69
70	typeset source=$(get_source $user_prop $dtst)
71	typeset value=$(get_prop $user_prop $dtst)
72	if [[ $source == '-' && $value == '-' ]]; then
73		return 0
74	else
75		return 1
76	fi
77}
78
79log_assert "User property could be set upon snapshot via 'zfs snapshot -o'."
80log_onexit cleanup
81
82typeset snap_property=
83
84$ZPOOL upgrade -v | $GREP "Snapshot properties" > /dev/null 2>&1
85if (( $? != 0 )) ; then
86	log_unsupported "Snapshot properties not supported on current system."
87fi
88
89for fs in $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL $TESTPOOL ; do
90	typeset fssnap=$fs@snap
91	prop_name=$(valid_user_property 10)
92	value=$(user_property_value 16)
93
94	log_must eval "$ZFS snapshot -o $prop_name='$value' $fssnap"
95	log_must snapexists $fssnap
96	log_mustnot nonexist_user_prop $prop_name $fssnap
97
98	log_must $ZFS destroy -f $fssnap
99
100	prop_name2=$(valid_user_property 10)
101	value2=$(user_property_value 16)
102
103	log_must eval "$ZFS snapshot -o $prop_name='$value' -o $prop_name2='$value2' $fssnap"
104	log_must snapexists $fssnap
105	log_mustnot nonexist_user_prop $prop_name $fssnap
106	log_mustnot nonexist_user_prop $prop_name2 $fssnap
107done
108
109cleanup
110
111prop_name=$(valid_user_property 10)
112value=$(user_property_value 16)
113
114log_must eval "$ZFS snapshot -r -o $prop_name='$value' $TESTPOOL@snap"
115for fs in $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL $TESTPOOL ; do
116	typeset fssnap=$fs@snap
117	log_must snapexists $fssnap
118	log_mustnot nonexist_user_prop $prop_name $fssnap
119
120	log_must $ZFS destroy -rf $fssnap
121done
122
123cleanup
124
125prop_name2=$(valid_user_property 10)
126value2=$(user_property_value 16)
127
128log_must eval "$ZFS snapshot -r -o $prop_name='$value' -o $prop_name2='$value2' $TESTPOOL@snap"
129for fs in $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL $TESTPOOL ; do
130	typeset fssnap=$fs@snap
131	log_must snapexists $fssnap
132	log_mustnot nonexist_user_prop $prop_name $fssnap
133	log_mustnot nonexist_user_prop $prop_name2 $fssnap
134
135	log_must $ZFS destroy -rf $fssnap
136done
137
138log_pass "User property could be set upon snapshot via 'zfs snapshot -o'."
139