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. $STF_SUITE/include/libtest.kshlib
27. $STF_SUITE/tests/cli_root/zfs_upgrade/zfs_upgrade.kshlib
28
29################################################################################
30#
31# __stc_assertion_start
32#
33# ID: zfs_upgrade_003_pos
34#
35# DESCRIPTION:
36# 	Executing 'zfs upgrade [-V version] filesystem' command succeeds,
37#	it could upgrade a filesystem to specific version or current version.
38#
39# STRATEGY:
40# 1. Prepare a set of datasets which contain old-version and current version.
41# 2. Execute 'zfs upgrade [-V version] filesystem', verify return 0,
42# 3. Verify the filesystem be updated as expected.
43#
44# TESTABILITY: explicit
45#
46# TEST_AUTOMATION_LEVEL: automated
47#
48# CODING_STATUS: COMPLETED (2007-06-25)
49#
50# __stc_assertion_end
51#
52################################################################################
53
54verify_runnable "both"
55
56function cleanup
57{
58	if datasetexists $rootfs ; then
59		log_must $ZFS destroy -Rf $rootfs
60	fi
61	log_must $ZFS create $rootfs
62}
63
64function setup_datasets
65{
66	datasets=""
67	for version in $ZFS_ALL_VERSIONS ; do
68		typeset verfs
69		eval verfs=\$ZFS_VERSION_$version
70		typeset current_fs=$rootfs/$verfs
71		typeset current_snap=${current_fs}@snap
72		typeset current_clone=$rootfs/clone$verfs
73		log_must $ZFS create -o version=${version} ${current_fs}
74		log_must $ZFS snapshot ${current_snap}
75		log_must $ZFS clone ${current_snap} ${current_clone}
76		datasets="$datasets ${current_fs} ${current_clone}"
77	done
78}
79
80log_assert "Executing 'zfs upgrade [-V version] filesystem' command succeeds."
81log_onexit cleanup
82
83rootfs=$TESTPOOL/$TESTFS
84typeset datasets
85
86typeset newv
87for newv in "" "current" $ZFS_ALL_VERSIONS; do
88	setup_datasets
89	for fs in $datasets ; do
90		typeset -i oldv=$(get_prop version $fs)
91
92		if [[ -n $newv ]]; then
93			opt="-V $newv"
94			if [[ $newv == current ]]; then
95				newv=$ZFS_VERSION
96			fi
97		else
98			newv=$ZFS_VERSION
99		fi
100
101		if (( newv >= oldv )); then
102			log_must eval '$ZFS upgrade $opt $fs > /dev/null 2>&1'
103			log_must check_fs_version $fs $newv
104		else
105			log_mustnot eval '$ZFS upgrade $opt $fs > /dev/null 2>&1'
106			log_must check_fs_version $fs $oldv
107		fi
108	done
109	cleanup
110done
111
112log_pass "Executing 'zfs upgrade [-V version] filesystem' command succeeds."
113