xref: /illumos-gate/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_upgrade/zfs_upgrade_005_pos.ksh (revision d583b39bfb4e2571d3e41097c5c357ffe353ad45)
1#!/usr/bin/ksh -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#
28. $STF_SUITE/include/libtest.shlib
29. $STF_SUITE/tests/functional/cli_root/zfs_upgrade/zfs_upgrade.kshlib
30
31#
32# DESCRIPTION:
33#	Executing 'zfs upgrade [-V version] -a' command succeeds,
34#	it upgrade all filesystems to specific or current version.
35#
36# STRATEGY:
37# 1. Prepare a set of datasets which contain old-version and current version.
38# 2. Execute 'zfs upgrade [-V version] -a', verify return 0,
39# 3. Verify all the filesystems be updated as expected.
40#
41
42verify_runnable "both"
43
44function cleanup
45{
46	if datasetexists $rootfs ; then
47		log_must $ZFS destroy -Rf $rootfs
48	fi
49	log_must $ZFS create $rootfs
50}
51
52function setup_datasets
53{
54	datasets=""
55	for version in $ZFS_ALL_VERSIONS ; do
56		typeset verfs
57		eval verfs=\$ZFS_VERSION_$version
58		typeset current_fs=$rootfs/$verfs
59		typeset current_snap=${current_fs}@snap
60		typeset current_clone=$rootfs/clone$verfs
61		log_must $ZFS create -o version=${version} ${current_fs}
62		log_must $ZFS snapshot ${current_snap}
63		log_must $ZFS clone ${current_snap} ${current_clone}
64
65		for subversion in $ZFS_ALL_VERSIONS ; do
66			typeset subverfs
67			eval subverfs=\$ZFS_VERSION_$subversion
68			log_must $ZFS create -o version=${subversion} \
69				${current_fs}/$subverfs
70		done
71		datasets="$datasets ${current_fs}"
72	done
73}
74
75log_assert "Executing 'zfs upgrade [-V version] -a' command succeeds."
76log_onexit cleanup
77
78rootfs=$TESTPOOL/$TESTFS
79
80typeset datasets
81
82typeset newv
83for newv in "" "current" $ZFS_VERSION; do
84	setup_datasets
85	if [[ -n $newv ]]; then
86		opt="-V $newv"
87		if [[ $newv == current ]]; then
88			newv=$ZFS_VERSION
89		fi
90	else
91		newv=$ZFS_VERSION
92	fi
93
94	export __ZFS_POOL_RESTRICT="$TESTPOOL"
95	log_must $ZFS upgrade $opt -a
96	unset __ZFS_POOL_RESTRICT
97
98	for fs in $($ZFS list -rH -t filesystem -o name $rootfs) ; do
99		log_must check_fs_version $fs $newv
100	done
101	cleanup
102done
103
104log_pass "Executing 'zfs upgrade [-V version] -a' command succeeds."
105