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