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