Home | History | Annotate | Download | only in zfs
      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 # ident	"@(#)configure.ksh	1.11	09/05/19 SMI"
     28 #
     29 
     30 # max and min pool version
     31 typeset -i MAX_POOL_VERSION=$($ZPOOL upgrade|$HEAD -1|$AWK '{print $NF}'|$SED -e   's/\.//g')
     32 typeset -i MIN_POOL_VERSION=10
     33 
     34 # max and min file system version
     35 typeset -i MAX_FS_VERSION=$($ZFS upgrade|$HEAD -1|$AWK '{print $NF}'|$SED -e   's/\.//g')
     36 typeset -i MIN_FS_VERSION=2
     37 
     38 . ${STF_SUITE}/include/libtest.kshlib
     39 
     40 typeset PKGNAME=$(get_package_name)
     41 
     42 function usage
     43 {
     44         log_fail "Usage: $0 -c \"DISKS=<disks>\" \n" \
     45 			"[-c \"RUNTIME={short|medium|long}" \
     46                         "[-c \"KEEP=<pools>\"] \n"\
     47                         "[-c \"zone={new|existing}\"] \n"\
     48                         "[-c \"zone_name=<zone_name>\"] \n" \
     49                         "[-c \"zone_root=<zone_root\"] \n" \
     50                         "[-c \"zone_ip=<zone_ip>\"] \n" \
     51                         "[-c \"RHOSTS=<remote hosts>\"] \n"\
     52                         "[-c \"ZPOOL_TEST_VERSION=<zpool test version>\"] \n"\
     53                         "[-c \"ZFS_TEST_VERSION=<zfs test version>\"] \n"\
     54                         "[-c \"RDISKS=<disks for each host in RHOSTS>\"]" \
     55                         "\n\nwhere:\n"\
     56                         "the order to assign disks should be the same as \n"\
     57                         "that in RHOSTS. You can assign a 'detect' to seek\n" \
     58                         " any available disks in a remote host. If you \n" \
     59                         " assign more than one disk from command line \n"\
     60                         " for a host, you\n"\
     61                         " need to use '' to quote all the disks as a unit.\n" \
     62                         "[-c \"RTEST_ROOT=<directory in remote host>\"]" \
     63                         "[-c \"WRAPPER=<wrapper name list>\"]"
     64 }
     65 
     66 configfile=$1
     67 shift
     68 
     69 if [[ -n $RUNTIME ]]; then
     70 	RUNTIME=`echo $RUNTIME | tr "[:upper:]" "[:lower:]"`
     71 	case $RUNTIME in
     72 		long) RUNTIME=$RT_LONG
     73 			;;
     74 		medium) RUNTIME=$RT_MEDIUM
     75 			;;
     76 		short) RUNTIME=$RT_SHORT
     77 			;;
     78 		*) log_fail "'$RUNTIME' must be {long, medium, short}"
     79 			;;
     80 	esac
     81 else
     82 	# We default to 'long' mode for backward compatibilty.
     83 	RUNTIME=$RT_LONG
     84 fi
     85 
     86 log_note "--- Begin Test Suite Parameters:"
     87 log_note "      DISKS=\"$DISKS\""
     88 log_note "      KEEP=\"$KEEP\""
     89 log_note "      RUNTIME=\"$RUNTIME\""
     90 log_note "      zone=\"$zone\""
     91 log_note "      zone_name=\"$zone_name\""
     92 log_note "      zone_root=\"$zone_root\""
     93 log_note "      zone_ip=\"$zone_ip\""
     94 log_note "      RHOSTS=\"$RHOSTS\""
     95 log_note "      RDISKS=\"$RDISKS\""
     96 log_note "      RTEST_ROOT=\"$RTEST_ROOT\""
     97 log_note "      ZPOOL_TEST_VERSION=\"$ZPOOL_TEST_VERSION\""
     98 log_note "      ZFS_TEST_VERSION=\"$ZFS_TEST_VERSION\""
     99 log_note "      iscsi=\"$iscsi\""
    100 log_note "      WRAPPER=\"$WRAPPER\""
    101 log_note "--- End Test Suite Parameters"
    102 
    103 if (( ZPOOL_TEST_VERSION != 0 )); then
    104 	if (( ZPOOL_TEST_VERSION > MAX_POOL_VERSION )) ||
    105 		(( ZPOOL_TEST_VERSION < MIN_POOL_VERSION )) ; then
    106 		log_fail "Invalid pool version: $ZPOOL_TEST_VERSION. [$MIN_POOL_VERSION - $MAX_POOL_VERSION]"
    107 	fi
    108 fi
    109 
    110 if (( ZFS_TEST_VERSION != 0 )); then
    111 	$ZPOOL create 2>&1|$GREP "\-O" >/dev/null 2>&1
    112 	if [[ $? != 0 ]]; then
    113 		log_fail "zpool create -O can't be supported, so can't set ZFS_TEST_VERSION."
    114 	fi
    115 	if (( ZFS_TEST_VERSION > MAX_FS_VERSION )) ||
    116 		(( ZFS_TEST_VERSION < MIN_FS_VERSION )) ; then
    117 		log_fail "Invalid fs version: $ZFS_TEST_VERSION. [$MIN_FS_VERSION - $MAX_FS_VERSION]"
    118 	fi
    119 fi
    120 
    121 #
    122 # Verify the wrapper is exist and runnable.
    123 #
    124 typeset ZPOOL_WRAPPER
    125 typeset ZFS_WRAPPER
    126 for wrapper in $WRAPPER ; do
    127 	if [[ -x ${STF_SUITE}/bin/zpool_$wrapper ]]; then
    128 		ZPOOL_WRAPPER="${ZPOOL_WRAPPER} $wrapper"
    129 	fi
    130 	if [[ -x ${STF_SUITE}/bin/zfs_$wrapper ]]; then
    131 		ZFS_WRAPPER="${ZFS_WRAPPER} $wrapper"
    132 	fi
    133 done
    134 
    135 if [[ "$ZPOOL_TEST_VERSION" != "0" ]] ||
    136 	[[ "$ZFS_TEST_VERSION" != "0" ]]; then
    137         if [[ -x ${STF_SUITE}/bin/zpool_version ]]; then
    138                 ZPOOL_WRAPPER="${ZPOOL_WRAPPER} version"
    139         fi
    140 fi
    141 
    142 if [[ "$ZFS_TEST_VERSION" != "0" ]]; then
    143         if [[ -x ${STF_SUITE}/bin/zfs_version ]]; then
    144                 ZFS_WRAPPER="${ZFS_WRAPPER} version"
    145         fi
    146 fi
    147 
    148 if [[ -n ${ZPOOL_WRAPPER} ]]; then
    149 	export ZPOOL=zpool
    150 	export ZPOOL_WRAPPER
    151 fi
    152 
    153 if [[ -n ${ZFS_WRAPPER} ]]; then
    154 	export ZFS=zfs
    155 	export ZFS_WRAPPER
    156 fi
    157 
    158 
    159 # Make sure that all commands are executable.
    160 
    161 for cmd in $CMDS ; do
    162         [[ -x $cmd ]] || log_fail "$cmd must exist and be executable"
    163 done
    164 if ! is_global_zone; then
    165 	#
    166 	# Remove any existing ZFS data sets, so system is in known state
    167 	# before starting tests.
    168 	#
    169 	default_cleanup_noexit
    170 
    171 	cat >> $configfile <<-EOF
    172 	export RUNTIME="$RUNTIME"
    173 	export ZPOOL_WRAPPER="${ZPOOL_WRAPPER}"
    174 	export ZFS_WRAPPER="${ZFS_WRAPPER}"
    175 	export ZPOOL="${ZPOOL}"
    176 	export ZFS="${ZFS}"
    177 	export ZPOOL_TEST_VERSION="${ZPOOL_TEST_VERSION}"
    178 	export ZFS_TEST_VERSION="${ZFS_TEST_VERSION}"
    179 	EOF
    180 
    181 	log_pass
    182 fi
    183 
    184 #
    185 # Verify ZFS is installed on this machine
    186 # The test suite cannot execute without ZFS being installed.
    187 #
    188 if [[ $(isainfo -b) -eq 32 && -x /kernel/drv/zfs ]] || 
    189 	[[ -x /kernel/drv/$(isainfo -k)/zfs ]]; then
    190 	log_note "ZFS is installed on this machine."
    191 else
    192 	log_fail "ZFS is not installed on this machine. Aborting."
    193 fi
    194 
    195 # Set the ROOTPOOL and ROOTFS environment variables
    196 $DF -n / | $GREP zfs > /dev/null
    197 if [ $? -eq 0 ]
    198 then
    199 	ROOTPOOL=$($DF -h / | $TAIL -1 | $AWK -F/ '{print $1}')
    200 	ROOTFS=$($DF -h / | $TAIL -1 | $AWK '{print $1}')
    201 fi
    202 export ROOTPOOL="$ROOTPOOL"
    203 export ROOTFS="$ROOTFS"
    204 
    205 DUMP_DEV=$($DUMPADM | $GREP "Dump device" | $AWK '{print $3}')
    206 if [[ $DUMP_DEV == "none" ]]; then
    207 	log_fail "Dump device is 'none', please set it."
    208 fi
    209 
    210 #
    211 # We must always preserve $ROOTPOOL
    212 #
    213 KEEP="^$ROOTPOOL $KEEP"
    214 
    215 #
    216 # Verify the list of disks is valid
    217 #
    218 for each_item in $DISKS $KEEP
    219 do
    220         $ECHO "$each_item" | $EGREP "[,;]" > /dev/null
    221         RET=$?
    222         if (( $RET == 0 )); then
    223                 log_fail "List parameters must be space separated."
    224         fi
    225 done
    226 
    227 #
    228 # Verify DISKS are not disk slices
    229 #
    230 for each_item in $DISKS
    231 do
    232         $ECHO "$each_item" | $EGREP "[ps][0-9]$" > /dev/null
    233         RET=$?
    234         if (( $RET == 0 )); then
    235                 log_fail "Disk slices should be not passed in as parameters."
    236         fi
    237 done
    238 
    239 COUNT=`$ECHO $DISKS | $WC -w`
    240 if (( $COUNT < 1 )) ; then
    241         log_fail "A minimum of one disks is required to run."
    242 fi
    243 
    244 if [[ -n $KEEP ]]; then
    245 
    246 	#
    247 	# Replace "word" with "^word$|" which will create a
    248 	# regular expression for 'egrep'.
    249 	#
    250 	# e.g. we need to avoid 'pool' also excluding 'testpool'
    251 	# given that 'pool' is a substring of 'testpool'.
    252 	#	
    253 	KEEP=`$ECHO $KEEP | $SED "s/ /$|^/g"`
    254 	KEEP="${KEEP}$" # Append an end-of-line delimiter.
    255 else
    256 	KEEP="^${ROOTPOOL}$" # Append an end-of-line delimiter.
    257 fi
    258 
    259 remote_ready="off" #flag to see RHOSTS and RDISKS are set correctly
    260 if (( ${#RHOSTS} != 0 )) && (( ${#RDISKS} != 0 )); then
    261         eval set -A rhosts $RHOSTS
    262         eval set -A rdisks $RDISKS
    263         if (( ${#rhosts[*]} != ${#rdisks[*]} )); then
    264                 log_fail "Some remote hosts may not be assigned disks, please check."
    265         fi
    266 
    267         typeset -i i=0
    268         while (( i < ${#rhosts[*]} )); do
    269                 ! verify_rsh_connect ${rhosts[i]} && \
    270                         log_fail "rsh connection to $rhost verification failed."
    271                 (( i = i + 1 ))
    272         done
    273 
    274 	#Get the ZFS test suites package version info in local machine
    275 	pkgver=`$PKGINFO -l $PKGNAME | $GREP "VERSION:" | \
    276 		$AWK '{print $2}' | $CUT -d, -f1,2`
    277 	
    278         i=0
    279         while (( i < ${#rhosts[*]} )); do
    280 		cp_files="${STF_SUITE}/chk_pkg \
    281 			${STF_SUITE}/include/libremote.kshlib \
    282 			${STF_SUITE}/iscsi_tsetup \
    283 			${STF_CONFIG}/stf_config.vars"
    284                 rsh_status ""  ${rhosts[i]} "$RM -rf $RTEST_ROOT;\
    285 			$MKDIR -p -m 0777 $RTEST_ROOT"
    286 		(( $? != 0 )) && \
    287 			log_fail "Create directory in remote host failed."
    288 		for file in $cp_files; do
    289 			$RCP $file ${rhosts[i]}:$RTEST_ROOT > /dev/null 2>&1
    290 			(( $? !=0 )) && \
    291 				log_fail "Copying files to ${rhosts[i]} failed."
    292 		done
    293 
    294 		rsh_status "" ${rhosts[i]} "$CHMOD a+x $RTEST_ROOT/chk_pkg; \
    295 			$RTEST_ROOT/chk_pkg $pkgver"	
    296 		(( $? != 0 )) && log_fail "zfs test version on local and \
    297 			remote do not match."
    298 
    299 		(( i = i + 1 ))
    300         done
    301 	# Mark RHOSTS and RDISKS are assigned in correct format
    302 	remote_ready="on"
    303 elif (( ${#RHOSTS} != 0 )) && (( ${#RDISKS} == 0 )); then
    304         log_fail "There are no assigned disks for remote hosts, please try again."
    305 elif (( ${#RHOSTS} == 0 )) && (( ${#RDISKS} != 0 )); then
    306 	log_fail "Remote host assigning error, please try again."
    307 fi
    308 
    309 #
    310 # setup iSCSI if iscsi option is enabled
    311 #
    312 if [[ -n $iscsi ]] && [[ $remote_ready == "on" ]] ; then
    313 	iscsi=`$ECHO $iscsi | $TR "[:upper:]" "[:lower:]"`
    314 	case $iscsi in
    315 		remote)	
    316 			# exclude local disks as testing targets
    317 			DEVICES_IGNORE=$(find_disks)
    318 			ZFS_HOST_DEVICES_IGNORE="${ZFS_HOST_DEVICES_IGNORE} \
    319 				${DEVICES_IGNORE}"
    320 			export ZFS_HOST_DEVICES_IGNORE
    321 			# setup iscsi target at remote
    322 			rsh_status "" ${rhosts[0]} \
    323 				"$CHMOD a+x $RTEST_ROOT/iscsi_tsetup; \
    324 				$RTEST_ROOT/iscsi_tsetup ${rdisks[0]}"
    325 			if (( $? != 0 )) ; then
    326 		       		log_fail "target setup failed"
    327 			fi
    328 
    329 			# setup iscsi initiator at local
    330 			iscsi_isetup ${rhosts[0]}
    331 			;;
    332 		*)	 
    333 			log_fail "parameter iscsi must be remote"
    334 			;;
    335 	esac
    336 elif [[ -n $iscsi ]] ; then
    337 	log_fail "RHOSTS and RDISKS are not assigned."
    338 fi
    339 
    340 
    341 default_cleanup_noexit
    342 
    343 #
    344 # Sweep available and not-in-use disks in the test system;
    345 # And make sure all $DISKS are ready for zfs test
    346 #
    347 gooddisks=""
    348 AVAIL_DISKS=$(find_disks)
    349 (( ${#AVAIL_DISKS} == 0 )) && log_fail "No available disks for test."
    350 
    351 # merge $DISK into $AVAIL_DISKS 
    352 # because $AVAIL_DISKS has a default number limit of MAX_FINDDISKSNUM
    353 # note: no need to do the merge when iscsi is set
    354 if [[ $iscsi == "remote" ]]; then
    355 	DISKS=$AVAIL_DISKS
    356 else
    357 	for disk in $DISKS; do
    358 		$ECHO ${AVAIL_DISKS} | $GREP $disk > /dev/null 2>&1
    359 		(( $? != 0 )) && AVAIL_DISKS="$disk ${AVAIL_DISKS}"
    360 	done
    361 fi
    362 
    363 for disk in ${AVAIL_DISKS}; do
    364         $ZPOOL create -f foo_pool$$ $disk > /dev/null 2>&1
    365         # if disk is found not usable to create a pool, exclude it from
    366         # $DISKS paramter
    367         if (( $? == 0 )); then
    368                 $ECHO $DISKS | $GREP $disk > /dev/null 2>&1
    369                 (( $? == 0 )) && gooddisks="$disk $gooddisks"
    370                 $ZPOOL destroy -f foo_pool$$
    371         fi
    372 done
    373 (( ${#gooddisks} == 0 )) && log_fail "No good disks for test."
    374 DISKS="$gooddisks"
    375 
    376 cat >> $configfile <<-EOF
    377 export DISKS="$DISKS"
    378 export KEEP="$KEEP"
    379 export RUNTIME="$RUNTIME"
    380 export iscsi=$iscsi
    381 export ROOTPOOL="$ROOTPOOL"
    382 export ROOTFS="$ROOTFS"
    383 export ZPOOL_WRAPPER="${ZPOOL_WRAPPER}"
    384 export ZFS_WRAPPER="${ZFS_WRAPPER}"
    385 export ZPOOL="${ZPOOL}"
    386 export ZFS="${ZFS}"
    387 export ZPOOL_TEST_VERSION="${ZPOOL_TEST_VERSION}"
    388 export ZFS_TEST_VERSION="${ZFS_TEST_VERSION}"
    389 EOF
    390 
    391 (( $? != 0 )) && log_fail Could not write to configure file, $configfile
    392 
    393 # Create local zone and zone testing environment
    394 #
    395 if (( ${#zone_name} != 0 && ${#zone} != 0 )); then
    396 	# The specified zone existed
    397 	if $ZONEADM -z $zone_name list > /dev/null 2>&1; then
    398 		if [[ $zone == existing ]]; then
    399 			log_note "### WARNING: '$zone_name' already exists."
    400 
    401 			# Recover pool and 5 container within it
    402 			typeset -i i=0
    403 			log_must $ZPOOL create -f $ZONE_POOL $DISKS
    404 			while (( i < 5 )); do
    405 				log_must $ZFS create $ZONE_POOL/$ZONE_CTR$i
    406 				# Turn on 'zoned'
    407 				log_must $ZFS set zoned=on $ZONE_POOL/$ZONE_CTR$i
    408 				(( i += 1 ))
    409 			done
    410 			
    411 			log_pass	
    412 		elif [[ $zone == new ]]; then
    413 			# Get current zone status
    414 			status=$($ZONEADM -z $zone_name list -v | \
    415 				$GREP "\<$zone_name\>" | $AWK '{print $3}')
    416 			(( $? != 0 )) && \
    417 				log_fail "Getting $zone_name status failed."
    418 
    419 			# Remove this existed zone
    420 			case $status in
    421 			running)
    422 				log_must $ZONEADM -z $zone_name halt
    423 				log_must $ZONEADM -z $zone_name uninstall -F
    424 				log_must $ZONECFG -z $zone_name delete -F
    425 				;;
    426 			installed)
    427 				log_must $ZONEADM -z $zone_name uninstall -F
    428 				log_must $ZONECFG -z $zone_name delete -F
    429 				;;
    430 			configured)
    431 				log_must $ZONECFG -z $zone_name delete -F
    432 				;;
    433 			esac
    434 		else
    435 			log_fail "Invalid syntax for zone=new|existing"
    436 		fi
    437 	fi
    438 
    439 	# Create pool and container, then create zone 
    440 	zfs_zones_setup $zone_name $zone_root $zone_ip
    441 
    442 	# check ${zone_root}/${zone_name}/root/export before creating user zone
    443 	if [[ ! -d ${zone_root}/${zone_name}/root/export ]]; then
    444 		log_must $ZLOGIN $zone_name $MKDIR /export
    445 	fi
    446 
    447 	# Create an non-super user 'zone' to run the test cases
    448 	log_must $ZLOGIN $zone_name useradd -d /export/zone -m -s /bin/bash zone
    449 fi
    450 
    451 log_pass
    452