xref: /illumos-gate/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_upgrade/zfs_upgrade_001_pos.ksh (revision b6805bf78d2bbbeeaea8909a05623587b42d58b3)
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 2008 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' command succeeds, it should report
34#	the current system version and list all old-version filesystems.
35#	If no old-version filesystems be founded, it prints out
36#	"All filesystems are formatted with the current version."
37#
38# STRATEGY:
39# 1. Prepare a set of datasets which contain old-version and current version.
40# 2. Execute 'zfs upgrade', verify return 0, and it prints out
41#	the current system version and list all old-version filesystems.
42# 3. Remove all old-version filesystems, then execute 'zfs upgrade' again,
43#	verify return 0, and get the expected message.
44#
45
46verify_runnable "both"
47
48function cleanup
49{
50	if datasetexists $rootfs ; then
51		log_must $ZFS destroy -Rf $rootfs
52	fi
53	log_must $ZFS create $rootfs
54
55	for file in $output $oldoutput ; do
56		if [[ -f $file ]]; then
57			log_must $RM -f $file
58		fi
59	done
60}
61
62log_assert "Executing 'zfs upgrade' command succeeds."
63log_onexit cleanup
64
65rootfs=$TESTPOOL/$TESTFS
66typeset output=/tmp/zfs-versions.$$
67typeset oldoutput=/tmp/zfs-versions-old.$$
68typeset expect_str1="This system is currently running ZFS filesystem version"
69typeset expect_str2="All filesystems are formatted with the current version"
70typeset expect_str3="The following filesystems are out of date, and can be upgraded"
71typeset -i COUNT OLDCOUNT
72
73$ZFS upgrade | $NAWK '$1 ~ "^[0-9]+$" {print $2}'> $oldoutput
74OLDCOUNT=$( $WC -l $oldoutput | $AWK '{print $1}' )
75
76old_datasets=""
77for version in $ZFS_ALL_VERSIONS ; do
78	typeset verfs
79	eval verfs=\$ZFS_VERSION_$version
80	typeset current_fs=$rootfs/$verfs
81	typeset current_snap=${current_fs}@snap
82	typeset current_clone=$rootfs/clone$verfs
83	log_must $ZFS create -o version=${version} ${current_fs}
84	log_must $ZFS snapshot ${current_snap}
85	log_must $ZFS clone ${current_snap} ${current_clone}
86
87	if (( version != $ZFS_VERSION )); then
88		old_datasets="$old_datasets ${current_fs} ${current_clone}"
89	fi
90done
91
92if is_global_zone; then
93	log_must $ZFS create -V 100m $rootfs/$TESTVOL
94fi
95
96log_must eval '$ZFS upgrade > $output 2>&1'
97
98# we also check that the usage message contains at least a description
99# of the current ZFS version.
100log_must eval '$GREP "${expect_str1} $ZFS_VERSION" $output > /dev/null 2>&1'
101$ZFS upgrade | $NAWK '$1 ~ "^[0-9]+$" {print $2}'> $output
102COUNT=$( $WC -l $output | $AWK '{print $1}' )
103
104typeset -i i=0
105for fs in ${old_datasets}; do
106	log_must $GREP "^$fs$" $output
107	(( i = i + 1 ))
108done
109
110if (( i != COUNT - OLDCOUNT )); then
111	$CAT $output
112	log_fail "More old-version filesystems print out than expect."
113fi
114
115for fs in $old_datasets ; do
116	if datasetexists $fs ; then
117		log_must $ZFS destroy -Rf $fs
118	fi
119done
120
121log_must eval '$ZFS upgrade > $output 2>&1'
122log_must eval '$GREP "${expect_str1} $ZFS_VERSION" $output > /dev/null 2>&1'
123if (( OLDCOUNT == 0 )); then
124	log_must eval '$GREP "${expect_str2}" $output > /dev/null 2>&1'
125else
126	log_must eval '$GREP "${expect_str3}" $output > /dev/null 2>&1'
127fi
128$ZFS upgrade | $NAWK '$1 ~ "^[0-9]+$" {print $2}'> $output
129COUNT=$( $WC -l $output | $AWK '{print $1}' )
130
131if (( COUNT != OLDCOUNT )); then
132	$CAT $output
133	log_fail "Unexpect old-version filesystems print out."
134fi
135
136log_pass "Executing 'zfs upgrade' command succeeds."
137