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_004_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_004_pos
40#
41# DESCRIPTION:
42# 	Executing 'zfs upgrade -r [-V version] filesystem' command succeeds,
43#	it upgrade filesystem recursively to specific 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 -r [-V version] filesystem', verify return 0,
48# 3. Verify the filesystem be updated recursively 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
83		for subversion in $ZFS_ALL_VERSIONS ; do
84			typeset subverfs
85			eval subverfs=\$ZFS_VERSION_$subversion
86			log_must $ZFS create -o version=${subversion} \
87				${current_fs}/$subverfs
88		done
89		datasets="$datasets ${current_fs}"
90	done
91}
92
93log_assert "Executing 'zfs upgrade -r [-V version] filesystem' command succeeds."
94log_onexit cleanup
95
96rootfs=$TESTPOOL/$TESTFS
97
98typeset datasets
99
100typeset newv
101for newv in "" "current" $ZFS_VERSION; do
102	setup_datasets
103	for topfs in $datasets ; do
104		if [[ -n $newv ]]; then
105			opt="-V $newv"
106			if [[ $newv == current ]]; then
107				newv=$ZFS_VERSION
108			fi
109		else
110			newv=$ZFS_VERSION
111		fi
112
113		log_must eval '$ZFS upgrade -r $opt $topfs > /dev/null 2>&1'
114
115		for fs in $($ZFS list -rH -t filesystem -o name $topfs) ; do
116			log_must check_fs_version $fs $newv
117		done
118	done
119	cleanup
120done
121
122log_pass "Executing 'zfs upgrade -r [-V version] filesystem' command succeeds."
123