From: Emoly Liu Date: Thu, 27 Dec 2012 06:46:39 +0000 (+0800) Subject: LU-2420 tests: Have POSIX testing on b1_8 X-Git-Tag: v1_8_9_WC1_RC1~24 X-Git-Url: https://git.whamcloud.com/gitweb?a=commitdiff_plain;h=4ce80481d9c9a5ff2870c9df3e75c98807d001fc;p=fs%2Flustre-release.git LU-2420 tests: Have POSIX testing on b1_8 Have POSIX testing automated on b1_8 as it is on master. LU-2274 port is included to change the baseline filesystem to ext3 for POSIX testing on SLES distro. Also, this patch adds add_group() and add_user() functions into the test-framework.sh. They are used by setup_posix_users() in posix.sh. port of b2_1 patch f55a2af51af0bbb1d97e6987a45ca501adbc4ab6 port of b2_1 patch f9531ab0803cbafcb68003f3470307e4b826129f Test-Parameters: envdefinitions=SLOW=yes testlist=posix Signed-off-by: Liu Ying Change-Id: I8e3e8d5e87b13f4fd2d0b972d2161e9f1afbc4e9 Reviewed-on: http://review.whamcloud.com/4894 Tested-by: Hudson Tested-by: Maloo Reviewed-by: Jian Yu Reviewed-by: Minh Diep Reviewed-by: Johann Lombardi --- diff --git a/lustre/tests/Makefile.am b/lustre/tests/Makefile.am index 6b122ef..cd4bcfb 100644 --- a/lustre/tests/Makefile.am +++ b/lustre/tests/Makefile.am @@ -25,13 +25,14 @@ noinst_SCRIPTS += recovery-random-scale.sh parallel-scale.sh metadata-updates.sh noinst_SCRIPTS += ost-pools.sh rpc.sh lnet-selftest.sh obdfilter-survey.sh mmp.sh mmp_mark.sh noinst_SCRIPTS += sgpdd-survey.sh auster yaml.sh maloo_upload.sh setup-nfs.sh noinst_SCRIPTS += parallel-scale-nfs.sh parallel-scale-nfsv3.sh parallel-scale-nfsv4.sh -noinst_SCRIPTS += ha.sh +noinst_SCRIPTS += ha.sh posix.sh nobase_noinst_SCRIPTS = cfg/local.sh nobase_noinst_SCRIPTS += test-groups/regression test-groups/regression-mpi nobase_noinst_SCRIPTS += acl/make-tree acl/run cfg/ncli.sh nobase_noinst_SCRIPTS += racer/dir_create.sh racer/file_create.sh racer/file_list.sh nobase_noinst_SCRIPTS += racer/file_rm.sh racer/racer.sh racer/file_concat.sh nobase_noinst_SCRIPTS += racer/file_link.sh racer/file_rename.sh racer/file_symlink.sh +nobase_noinst_SCRIPTS += posix/posix.cfg nobase_noinst_DATA = acl/cp.test acl/getfacl-noacl.test acl/inheritance.test nobase_noinst_DATA += acl/misc.test acl/permissions.test acl/setfacl.test diff --git a/lustre/tests/posix.sh b/lustre/tests/posix.sh new file mode 100644 index 0000000..e2bb173 --- /dev/null +++ b/lustre/tests/posix.sh @@ -0,0 +1,122 @@ +#!/bin/bash +#set -vx +set -e + +LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)} +. $LUSTRE/tests/test-framework.sh +init_test_env $@ +. ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh} +init_logging + +build_test_filter +check_and_setup_lustre + +POSIX_DIR=${POSIX_DIR:-"$LUSTRE/tests/posix"} +POSIX_SRC=${POSIX_SRC:-"/usr/src/posix"} +BASELINE_FS=${BASELINE_FS:-"ext4"} + +# SLES does not support read-write access to an ext4 file system by default +[[ -e /etc/SuSE-release ]] && BASELINE_FS=ext3 + +cleanup_loop_dev() { + local mnt=$1 + local dev=$2 + local file=$3 + + # if we only have 1 arg, we will search for dev + if [[ $# = 1 ]]; then + dev=$(losetup -a | grep "$mnt" | cut -d: -f1) + [[ -n $dev ]] && losetup -d $dev + else # we need all args + [[ -z $mnt ]] || [[ -z $dev ]] || [[ -z $file ]] && + error "Can't cleanup loop device" + umount -f $mnt + losetup -d $dev && rm -rf $mnt + rm -f $file + fi +} + +setup_loop_dev() { + local mnt=$1 + local dev=$2 + local file=$3 + local rc=0 + + echo "Make a loop file system with $file on $dev" + dd if=/dev/zero of=$file bs=1024k count=500 > /dev/null + if ! losetup $dev $file; then + rc=$? + echo "can't set up $dev for $file" + return $rc + fi + if ! eval mkfs.$BASELINE_FS $dev; then + rc=$? + echo "mkfs.$BASELINE_FS on $dev failed" + return $rc + fi + mkdir -p $mnt + if ! mount -t $BASELINE_FS $dev $mnt; then + rc=$? + echo "mount $BASELINE_FS failed" + return $rc + fi + echo + return $rc +} + +test_1() { + local allnodes="$(comma_list $(nodes_list))" + local tfile="$TMP/$BASELINE_FS-file" + local mntpnt=$POSIX_SRC/$BASELINE_FS + local loopbase + local loopdev + local rc=0 + + # We start at loop1 because posix build uses loop0 + [ -b /dev/loop/1 ] && loopbase=/dev/loop/ + [ -b /dev/loop1 ] && loopbase=/dev/loop + [ -z "$loopbase" ] && error "/dev/loop/1 and /dev/loop1 gone?" + + for i in `seq 1 7`; do + losetup $loopbase$i > /dev/null 2>&1 && continue || true + loopdev=$loopbase$i + break + done + + [ -z "$loopdev" ] && error "Can not find loop device" + + if ! setup_loop_dev $mntpnt $loopdev $tfile; then + cleanup_loop_dev "$mntpnt" "$loopdev" "$tfile" + error "Setup loop device failed" + fi + + # copy the source over to ext mount point + if ! cp -af ${POSIX_SRC}/*.* $mntpnt; then + cleanup_loop_dev "$mntpnt" "$loopdev" "$tfile" + error "Copy POSIX test suite failed" + fi + export POSIX_SRC=$mntpnt + . $POSIX_DIR/posix.cfg + + setup_posix_users $allnodes + if ! setup_posix; then + delete_posix_users $allnodes + cleanup_loop_dev "$POSIX_SRC" + cleanup_loop_dev "$mntpnt" "$loopdev" "$tfile" + error "Setup POSIX test suite failed" + fi + + log "Run POSIX test against lustre filesystem" + run_posix $MOUNT compare || \ + error_noexit "Run POSIX testsuite on $MOUNT failed" + + [[ -d "$MOUNT/TESTROOT" ]] && rm -fr $MOUNT/TESTROOT + delete_posix_users $allnodes + cleanup_loop_dev "$POSIX_SRC" + cleanup_loop_dev "$mntpnt" "$loopdev" "$tfile" +} +run_test 1 "install, build, run posix on $BASELINE_FS and lustre, then compare" + +complete $(basename $0) $SECONDS +check_and_cleanup_lustre +exit_status diff --git a/lustre/tests/posix/posix.cfg b/lustre/tests/posix/posix.cfg new file mode 100644 index 0000000..1f1408c --- /dev/null +++ b/lustre/tests/posix/posix.cfg @@ -0,0 +1,190 @@ +#!/bin/bash +# +# This file contains the global variables and common functions +# used in the posix test scripts. +set -e + +LUSTRE=${LUSTRE:-$(cd $(dirname $0)/../..; echo $PWD)} +. $LUSTRE/tests/test-framework.sh + +#************************ Initialize Global Variables *************************# +export POSIX_SRC=${POSIX_SRC:-"/usr/src/posix"} +export POSIX_RUN=${POSIX_RUN:-"$POSIX_SRC/run_posix_suite.pl"} +export TEST_BIN="$POSIX_SRC/TESTROOT-gcc$(gcc -v 2>&1 | tail -1 | + cut -d' ' -f3)-$(uname -m).tgz" + +# Root directory of the POSIX test suite installation. +export INSTALL_DIR=${INSTALL_DIR:-"$POSIX_SRC/tet"} + +# Root directory from which the testsets will be executed. +export TESTEXEC_DIR=${TESTEXEC_DIR:-"$POSIX_SRC/TESTROOT"} + +# Test results directory. +export RESULT_DIR=${RESULT_DIR:-"$INSTALL_DIR/test_sets/results"} + +# Test groups for POSIX compliance test suite. +USER_GROUPS="vsxg0,vsxg1,vsxg2" + +for i in $(seq 31); do + SUPP_GROUPS="$SUPP_GROUPS,supp$i" +done +SUPP_GROUPS=${SUPP_GROUPS#,} + +export GROUP_ID=${GROUP_ID:-"2000000000"} +export USER_ID=${USER_ID:-"2000000000"} + +#***************************** Common Functions *******************************# +# Remove users and groups for running the POSIX test suite. +delete_posix_users() { + local node=${1:-$(hostname)} + + do_nodes $node " + for i in 0 1 2; do + userdel vsx\\\$i; + done; + for group in ${SUPP_GROUPS//,/ } ${USER_GROUPS//,/ }; do + groupdel \\\$group; + done" 2>&1 | dshbak -c + return ${PIPESTATUS[0]} +} + +# Setup users and groups for running the POSIX test suite. +setup_posix_users() { + local node=${1:-$HOSTNAME} + # consistent with install.sh in LSB Test Suite + local gid=$((GROUP_ID + 1)) + local uid=$USER_ID + local user group + local home + local opts + local i + + for group in ${USER_GROUPS//,/ } ${SUPP_GROUPS//,/ }; do + if ! do_rpc_nodes $node add_group $gid $group; then + delete_posix_users $node + return 1 + fi + gid=$((gid + 1)) + done + + for i in 0 1 2; do + user=vsx$i + group=vsxg$i + + if [[ "$user" = "vsx0" ]]; then + home=$INSTALL_DIR/test_sets + opts="-G $SUPP_GROUPS" + else + home=$INSTALL_DIR + opts="" + fi + + if ! do_rpc_nodes $node add_user $uid $user $group $home $opts + then + delete_posix_users $node + return 2 + fi + uid=$((uid + 1)) + done + + return 0 +} + +prep() { + if [[ ! -d $POSIX_SRC ]]; then + echo "Missing POSIX testsuite source" + return 1 + fi + [[ -f $TEST_BIN ]] && rm -f $TEST_BIN + [[ -d $INSTALL_DIR ]] && rm -rf $INSTALL_DIR + + if grep -q " 6." /etc/issue; then + [[ -d /usr/include/bits ]] || mkdir -p /usr/include/bits + [[ -d /usr/include/sys ]] || mkdir -p /usr/include/sys + [[ -s /usr/include/stropts.h ]] || \ + ln -s /usr/lib/x86_64-redhat-linux5E/include/stropts.h \ + /usr/include/stropts.h + [[ -s /usr/include/bits/stropts.h ]] || \ + ln -s /usr/lib/x86_64-redhat-linux5E/include/bits/stropts.h \ + /usr/include/bits/stropts.h + [[ -s /usr/include/bits/xtitypes.h ]] || \ + ln -s /usr/lib/x86_64-redhat-linux5E/include/bits/xtitypes.h \ + /usr/include/bits/xtitypes.h + [[ -s /usr/include/sys/stropts.h ]] || \ + ln -s /usr/lib/x86_64-redhat-linux5E/include/sys/stropts.h \ + /usr/include/sys/stropts.h + fi + + pushd $POSIX_SRC > /dev/null + + if [[ -f install.sh ]]; then + [[ ! -x install.sh ]] && chmod +x install.sh + else + popd > /dev/null + echo "install.sh does not exist in $POSIX_SRC." + return 1 + fi + + popd > /dev/null +} + +install() { + pushd $POSIX_SRC > /dev/null + + log "Installing POSIX test suite" + # Install the POSIX test suite source files + expect -f install-posix.exp $INSTALL_DIR $TESTEXEC_DIR + + popd > /dev/null +} + +build() { + pushd $POSIX_SRC > /dev/null + + log "Building POSIX test suite" + # Build testsets + expect -f build-posix.exp $INSTALL_DIR $TESTEXEC_DIR $POSIX_SRC + + popd > /dev/null +} + +cleanup() { + if [[ -f $TEST_BIN ]]; then + rm -fr $TESTEXEC_DIR + echo "Install and build POSIX test suite successfully!" + return 0 + else + echo "failed to build POSIX test suite." + return 1 + fi +} + +run_posix() { + local MNTPNT=$1 + local COMPARE=${2} + local compare="" + local rc=0 + local cmd + + [[ "x$COMPARE" != "x" ]] && compare="--compare-result" + # command to run posix test suite + cmd="TMP=/tmp/vsx0 TMPDIR=/tmp/vsx0 $POSIX_RUN --mountpt=$MNTPNT \ + --posix-src=$POSIX_SRC --install-dir=$INSTALL_DIR \ + --results-dir=$RESULT_DIR $compare 2>&1" + + # run posix test suite + echo $cmd + if ! eval $cmd; then + rc=${PIPESTATUS[0]} + fi + + return $rc +} + +setup_posix() { + log "Setting up POSIX test suite from $POSIX_SRC" + prep || return $? + install + build + cleanup +} diff --git a/lustre/tests/test-framework.sh b/lustre/tests/test-framework.sh index c5249e1..4980849 100644 --- a/lustre/tests/test-framework.sh +++ b/lustre/tests/test-framework.sh @@ -3380,6 +3380,63 @@ setstripe_nfsserver () { do_nodev $nfsserver lfs setstripe "$@" } +# Check and add a test group. +add_group() { + local group_id=$1 + local group_name=$2 + local rc=0 + + local gid=$(getent group $group_name | cut -d: -f3) + if [[ -n "$gid" ]]; then + [[ "$gid" -eq "$group_id" ]] || { + error_noexit "inconsistent group ID:" \ + "new: $group_id, old: $gid" + rc=1 + } + else + groupadd -g $group_id $group_name + rc=${PIPESTATUS[0]} + fi + + return $rc +} + +# Check and add a test user. +add_user() { + local user_id=$1 + shift + local user_name=$1 + shift + local group_name=$1 + shift + local home=$1 + shift + local opts="$@" + local rc=0 + + local uid=$(getent passwd $user_name | cut -d: -f3) + if [[ -n "$uid" ]]; then + if [[ "$uid" -eq "$user_id" ]]; then + local dir=$(getent passwd $user_name | cut -d: -f6) + if [[ "$dir" != "$home" ]]; then + mkdir -p $home + usermod -d $home $user_name + rc=${PIPESTATUS[0]} + fi + else + error_noexit "inconsistent user ID:" \ + "new: $user_id, old: $uid" + rc=1 + fi + else + mkdir -p $home + useradd -M -u $user_id -d $home -g $group_name $opts $user_name + rc=${PIPESTATUS[0]} + fi + + return $rc +} + check_runas_id_ret() { local myRC=0 local myRUNAS_UID=$1