diff --git a/WHATS_NEW b/WHATS_NEW index 26b482c15..65ae1a032 100644 --- a/WHATS_NEW +++ b/WHATS_NEW @@ -1,5 +1,6 @@ Version 2.02.29 - ================================== + Tests are run with LVM_SYSTEM_DIR pointing to private root and /dev dirs. Fix a bug in lvm_dump.sh checks for lvm/dmsetup binaries. Fix underquotations in lvm_dump.sh. Refactor lvcreate stripe and mirror parameter validation. diff --git a/test/Makefile.in b/test/Makefile.in index dbccfbb0e..c861e2651 100644 --- a/test/Makefile.in +++ b/test/Makefile.in @@ -21,6 +21,7 @@ srcdir = @srcdir@ top_srcdir = @top_srcdir@ top_builddir = @top_builddir@ abs_srcdir = @abs_srcdir@ +abs_builddir = @abs_builddir@ abs_top_builddir = @abs_top_builddir@ abs_top_srcdir = @abs_top_srcdir@ @@ -32,6 +33,7 @@ init.sh: Makefile.in .bin-dir-stamp echo 'abs_top_srcdir=$(abs_top_builddir)' >> $@-t echo 'PATH=$(abs_top_builddir)/test/bin:$$PATH' >> $@-t echo 'abs_srcdir=$(abs_srcdir)' >> $@-t + echo 'abs_builddir=$(abs_builddir)' >> $@-t echo 'export PATH' >> $@-t chmod a-w $@-t mv $@-t $@ diff --git a/test/lvm-utils.sh b/test/lvm-utils.sh index 7f63714fe..5c827fcd4 100644 --- a/test/lvm-utils.sh +++ b/test/lvm-utils.sh @@ -19,19 +19,14 @@ warn() { echo >&2 "$ME: $@"; } unsafe_losetup_() { f=$1 - # Prefer the race-free losetup from recent util-linux-ng. - dev=$(losetup --find --show "$f" 2>/dev/null) \ - && { echo "$dev"; return 0; } - # If that fails, try to use util-linux-ng's -f "find-device" option. - dev=$(losetup -f 2>/dev/null) \ - && losetup "$dev" "$f" \ - && { echo "$dev"; return 0; } + test -n "$G_dev_" \ + || error "Internal error: unsafe_losetup_ called before init_root_dir_" - # Last resort: iterate through /dev/loop{,/}{0,1,2,3,4,5,6,7,8,9} + # Iterate through $G_dev_/loop{,/}{0,1,2,3,4,5,6,7,8,9} for slash in '' /; do for i in 0 1 2 3 4 5 6 7 8 9; do - dev=/dev/loop$slash$i + dev=$G_dev_/loop$slash$i losetup $dev > /dev/null 2>&1 && continue; losetup "$dev" "$f" > /dev/null && { echo "$dev"; return 0; } break @@ -55,7 +50,6 @@ loop_setup_() return 0; } - check_pv_size_() { return $(test $(pvs --noheadings -o pv_free $1) == $2) @@ -65,3 +59,45 @@ check_lv_size_() { return $(test $(lvs --noheadings -o lv_size $1) == $2) } + +dmsetup_has_dm_devdir_support_() +{ + # Detect support for the envvar. If it's supported, the + # following command will fail with the expected diagnostic. + out=$(DM_DEV_DIR=j dmsetup version 2>&1) + test "$?:$out" = "1:Invalid DM_DEV_DIR envvar value." +} + +# set up private /dev and /etc +init_root_dir_() +{ + test -n "$test_dir_rand_" \ + || error "Internal error: called init_root_dir_ before" \ + " defining $test_dir_rand_" + + # Define these two globals. + G_root_=$test_dir_rand_/root + G_dev_=$G_root_/dev + + export LVM_SYSTEM_DIR=$G_root_/etc + export DM_DEV_DIR=$G_dev_ + + # Only the first caller does anything. + mkdir -p $G_root_/etc $G_dev_ $G_dev_/mapper + for i in 0 1 2 3 4 5 6 7; do + mknod $G_root_/dev/loop$i b 7 $i + done + cat > $G_root_/etc/lvm.conf <<-EOF + devices { + dir = "$G_dev_" + scan = "$G_dev_" + filter = [ "a/loop/", "a/mirror/", "a/mapper/", "r/.*/" ] + cache_dir = "$G_root_/etc" + sysfs_scan = 0 + } +EOF +} + +if test $(this_test_) != 000-basic; then + init_root_dir_ +fi diff --git a/test/t-lvcreate-pvtags.sh b/test/t-lvcreate-pvtags.sh index b230e795d..9c1982fa6 100755 --- a/test/t-lvcreate-pvtags.sh +++ b/test/t-lvcreate-pvtags.sh @@ -14,6 +14,13 @@ privileges_required_=1 . ./test-lib.sh +dmsetup_has_dm_devdir_support_ || +{ + say "Your version of dmsetup lacks support for changing DM_DEVDIR." + say "Skipping this test" + exit 0 +} + cleanup_() { test -n "$vg" && { @@ -48,7 +55,7 @@ for n in $(seq 1 $nr_pvs); do done for n in $(seq 1 $nr_pvs); do - pvs="$pvs /dev/mapper/pv$n" + pvs="$pvs $G_dev_/mapper/pv$n" done test_expect_success \ @@ -66,7 +73,7 @@ test_expect_success '3 stripes with 3 PVs (selected by tag, @fast) is fine' \ test_expect_failure 'too many stripes(4) for 3 PVs' \ 'lvcreate -l4 -i4 $vg @fast' test_expect_failure '2 stripes is too many with just one PV' \ - 'lvcreate -l2 -i2 $vg /dev/mapper/pv1' + 'lvcreate -l2 -i2 $vg $G_dev_/mapper/pv1' test_expect_success 'lvcreate mirror' \ 'lvcreate -l1 -m1 $vg @fast' @@ -77,6 +84,6 @@ test_expect_failure 'lvcreate mirror w/no free PVs' \ test_expect_failure 'lvcreate mirror (corelog, w/no free PVs)' \ 'lvcreate -l1 -m3 --corelog $vg @fast' test_expect_failure 'lvcreate mirror with a single PV arg' \ - 'lvcreate -l1 -m1 --corelog $vg /dev/mapper/pv1' + 'lvcreate -l1 -m1 --corelog $vg $G_dev_/mapper/pv1' test_done diff --git a/test/t-lvcreate-usage.sh b/test/t-lvcreate-usage.sh index cd488c51e..ff4e6d81b 100755 --- a/test/t-lvcreate-usage.sh +++ b/test/t-lvcreate-usage.sh @@ -30,15 +30,16 @@ test_expect_success \ 'set up temp files, loopback devices, PVs, and a VG' \ 'f1=$(pwd)/1 && d1=$(loop_setup_ "$f1") && f2=$(pwd)/2 && d2=$(loop_setup_ "$f2") && - pvcreate $d1 $d2 && - vg=$(this_test_)-test-vg-$$ && + pvcreate $d1 $d2 && + vg=$(this_test_)-test-vg-$$ && vgcreate $vg $d1 $d2' lv=lvcreate-usage-$$ test_expect_success \ 'lvcreate rejects a negative stripesize' \ - 'lvcreate -L 64M -n $lv -i2 --stripesize -4 $vg 2>err; test $? = 3 && + 'lvcreate -L 64M -n $lv -i2 --stripesize -4 $vg 2>err; + status=$?; echo status=$?; test $status = 3 && grep "^ Negative stripesize is invalid\$" err' test_expect_success \ diff --git a/test/test-lib.sh b/test/test-lib.sh index df52df2ee..010fa9431 100755 --- a/test/test-lib.sh +++ b/test/test-lib.sh @@ -37,7 +37,7 @@ say () { echo "* $*" } -this_test_() { expr "./$0" : '.*/\(t[0-9]*\)-[^/]*$'; } +this_test_() { expr "./$0" : '.*/t-\([^/]*\)\.sh$'; } test "${test_description}" != "" || error "Test script did not set test_description." @@ -193,8 +193,6 @@ test_done () { esac } -. lvm-utils.sh - this_test=$(this_test_) skip_=0 @@ -208,8 +206,6 @@ if test "$privileges_required_" != ''; then fi fi -# Test the binaries we have just built. -abs_top_srcdir=$(cd .. && pwd) pwd_=`pwd` test_dir_=${LVM_TEST_DIR-.} @@ -239,16 +235,20 @@ do esac done -t0=$($abs_srcdir/mkdtemp $test_dir_ lvm-$this_test.XXXXXXXXXX) \ +test_dir_rand_=$($abs_srcdir/mkdtemp $test_dir_ lvm-$this_test.XXXXXXXXXX) \ || error "failed to create temporary directory in $test_dir_" # Run each test from within a temporary sub-directory named after the # test itself, and arrange to remove it upon exception or normal exit. -trap 'st=$?; cleanup_; d='"$t0"'; +trap 'st=$?; cleanup_; d='"$test_dir_rand_"'; cd '"$test_dir_"' && chmod -R u+rwx "$d" && rm -rf "$d" && exit $st' 0 trap '(exit $?); exit $?' 1 2 13 15 -cd $t0 || error "failed to cd to $t0" +cd $test_dir_rand_ || error "failed to cd to $test_dir_rand_" + +if test $skip_ = 0; then + . $abs_srcdir/lvm-utils.sh || exit 1 +fi if ( diff --version < /dev/null 2>&1 | grep GNU ) 2>&1 > /dev/null; then compare='diff -u'