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