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