From: Karel Zak Date: Tue, 22 May 2007 14:01:55 +0000 (+0200) Subject: tests: add support for fstab modification X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c98825acab98e9154881025fdd35e6445b85f27e;p=util-linux tests: add support for fstab modification The patch adds ts_fstab_add and ts_fstab_clean routines. Signed-off-by: Karel Zak --- diff --git a/tests/functions.sh b/tests/functions.sh index 24308f69..ba94ad4d 100644 --- a/tests/functions.sh +++ b/tests/functions.sh @@ -56,6 +56,7 @@ function ts_init { TS_DIFF="$TS_DIFFDIR/$TS_NAME" TS_EXPECTED="$TS_EXPECTEDDIR/$TS_NAME" TS_INPUT="$TS_INPUTDIR/$TS_NAME" + TS_MOUNTPOINT="$(pwd)/$TS_OUTDIR/${TS_NAME}_mnt" rm -f $TS_OUTPUT touch $TS_OUTPUT @@ -90,6 +91,7 @@ function ts_die { ts_log "$1" if [ -n "$2" ] && [ -b "$2" ]; then ts_device_deinit "$2" + ts_fstab_clean # for sure... fi ts_finalize } @@ -203,3 +205,39 @@ function ts_swapoff { rm -f $TS_CMD_SWAPOFF fi } + +function ts_fstab_open { + echo "# " >> /etc/fstab +} + +function ts_fstab_addline { + local SPEC="$1" + local MNT=${2:-"$TS_MOUNTPOINT"} + local FS=${3:-"auto"} + local OPT=${4:-"default"} + + echo "$SPEC $MNT $FS defaults 0 0" >> /etc/fstab +} + +function ts_fstab_add { + ts_fstab_open + ts_fstab_addline "$*" + ts_fstab_close +} + +function ts_fstab_clean { + sed --in-place " +/# /!{ + N + ba +} +s/# //; +/^$/d" /etc/fstab +} + diff --git a/tests/ts-cramfs-mkfs b/tests/ts-cramfs-mkfs index cbe37292..c2d6c131 100755 --- a/tests/ts-cramfs-mkfs +++ b/tests/ts-cramfs-mkfs @@ -32,10 +32,11 @@ IMAGE="$TS_OUTDIR/cramfs-loop.img" IMAGE_DATA="$TS_OUTDIR/cramfs-data" IMAGE_RE=$( echo $IMAGE | sed 's:/:\\/:g' ) LABEL="testCramfs" -MOUNTPOINT="$TS_OUTDIR/cramfs-mnt" +TS_MOUNTPOINT="$TS_OUTDIR/cramfs-mnt" ts_log "create mountpoint dir" -[ -d "$MOUNTPOINT" ] || mkdir -p $MOUNTPOINT + +[ -d "$TS_MOUNTPOINT" ] || mkdir -p $TS_MOUNTPOINT ts_log "generate data" if [ ! -d "$IMAGE_DATA" ]; then @@ -74,18 +75,18 @@ ts_udev_dev_support "by-label" $LABEL [ "$?" == "0" ] || ts_skip "udev ignores /dev/loop*" $DEVICE ts_log "mount the image" -$TS_CMD_MOUNT -L $LABEL $MOUNTPOINT 2>&1 >> $TS_OUTPUT +$TS_CMD_MOUNT -L $LABEL $TS_MOUNTPOINT 2>&1 >> $TS_OUTPUT # check it grep -q $DEVICE /proc/mounts [ "$?" == "0" ] || ts_die "Cannot found $DEVICE in /proc/mounts" $DEVICE ts_log "list the image" -ls -laR $MOUNTPOINT >> $TS_OUTPUT +ls -laR $TS_MOUNTPOINT >> $TS_OUTPUT echo >> $TS_OUTPUT ts_log "list checksums from new data" -find $MOUNTPOINT -type f -exec md5sum {} \; >> $TS_OUTPUT +find $TS_MOUNTPOINT -type f -exec md5sum {} \; >> $TS_OUTPUT echo >> $TS_OUTPUT ts_log "umount the image" diff --git a/tests/ts-mount-devname b/tests/ts-mount-devname index dd6e4a35..a2ebb332 100755 --- a/tests/ts-mount-devname +++ b/tests/ts-mount-devname @@ -26,7 +26,6 @@ ts_skip_nonroot set -o pipefail -MOUNTPOINT="$TS_OUTDIR/${TS_NAME}_mnt" DEVICE=$(ts_device_init) [ "$?" == 0 ] || ts_die "Cannot init device" @@ -36,9 +35,9 @@ mkfs.ext3 $DEVICE &> /dev/null ts_device_has "TYPE" "ext3" $DEVICE [ "$?" == "0" ] || ts_die "Cannot found ext3 on $DEVICE" $DEVICE -[ -d "$MOUNTPOINT" ] || mkdir -p $MOUNTPOINT +[ -d "$TS_MOUNTPOINT" ] || mkdir -p $TS_MOUNTPOINT -$TS_CMD_MOUNT $DEVICE $MOUNTPOINT 2>&1 >> $TS_OUTPUT +$TS_CMD_MOUNT $DEVICE $TS_MOUNTPOINT 2>&1 >> $TS_OUTPUT grep -q $DEVICE /proc/mounts [ "$?" == "0" ] || ts_die "Cannot found $DEVICE in /proc/mounts" $DEVICE diff --git a/tests/ts-mount-label b/tests/ts-mount-label index 5a9b59aa..c6a841ea 100755 --- a/tests/ts-mount-label +++ b/tests/ts-mount-label @@ -28,11 +28,9 @@ ts_skip_nonroot set -o pipefail -MOUNTPOINT="$TS_OUTDIR/${TS_NAME}_mnt" DEVICE=$(ts_device_init) [ "$?" == 0 ] || ts_die "Cannot init device" - mkfs.ext3 -L $LABEL $DEVICE &> /dev/null [ "$?" == "0" ] || ts_die "Cannot make ext3 on $DEVICE" $DEVICE @@ -42,9 +40,9 @@ ts_device_has "LABEL" $LABEL $DEVICE ts_udev_dev_support "by-label" $LABEL [ "$?" == "0" ] || ts_skip "udev ignores /dev/loop*" $DEVICE -[ -d "$MOUNTPOINT" ] || mkdir -p $MOUNTPOINT +[ -d "$TS_MOUNTPOINT" ] || mkdir -p $TS_MOUNTPOINT -$TS_CMD_MOUNT -L $LABEL $MOUNTPOINT 2>&1 >> $TS_OUTPUT +$TS_CMD_MOUNT -L $LABEL $TS_MOUNTPOINT 2>&1 >> $TS_OUTPUT grep -q $DEVICE /proc/mounts [ "$?" == "0" ] || ts_die "Cannot found $DEVICE in /proc/mounts" $DEVICE diff --git a/tests/ts-mount-remount b/tests/ts-mount-remount index 295ca509..b293572a 100755 --- a/tests/ts-mount-remount +++ b/tests/ts-mount-remount @@ -13,8 +13,7 @@ ts_init "$1" ts_skip_nonroot # mountpoint -MOUNTPOINT="$(pwd)/$TS_OUTDIR/mnt-remount" -mkdir -p $MOUNTPOINT +[ -d $TS_MOUNTPOINT ] || mkdir -p $TS_MOUNTPOINT DEVICE=$(ts_device_init) [ "$?" == 0 ] || ts_die "Cannot init device" @@ -23,20 +22,20 @@ mkfs.ext2 $DEVICE &> /dev/null [ "$?" == "0" ] || ts_die "Cannot make ext2 on $DEVICE" $DEVICE # mount read-write -$TS_CMD_MOUNT $DEVICE $MOUNTPOINT -[ "$?" == "0" ] || ts_die "Cannot mount $MOUNTPOINT" $DEVICE +$TS_CMD_MOUNT $DEVICE $TS_MOUNTPOINT +[ "$?" == "0" ] || ts_die "Cannot mount $TS_MOUNTPOINT" $DEVICE # check the mount -egrep -q "^$DEVICE $MOUNTPOINT" /etc/mtab -[ "$?" == "0" ] || ts_die "Cannot found $MOUNTPOINT in /etc/mtab" $DEVICE +egrep -q "^$DEVICE $TS_MOUNTPOINT" /etc/mtab +[ "$?" == "0" ] || ts_die "Cannot found $TS_MOUNTPOINT in /etc/mtab" $DEVICE # remount -$TS_CMD_MOUNT -o remount,ro $MOUNTPOINT -[ "$?" == "0" ] || ts_die "Cannot remount $MOUNTPOINT" $DEVICE +$TS_CMD_MOUNT -o remount,ro $TS_MOUNTPOINT +[ "$?" == "0" ] || ts_die "Cannot remount $TS_MOUNTPOINT" $DEVICE # check the remount -egrep -q "^$DEVICE $MOUNTPOINT ext2 ro 0 0" /etc/mtab -[ "$?" == "0" ] || ts_die "Cannot found remounted $MOUNTPOINT in /etc/mtab" $DEVICE +egrep -q "^$DEVICE $TS_MOUNTPOINT ext2 ro 0 0" /etc/mtab +[ "$?" == "0" ] || ts_die "Cannot found remounted $TS_MOUNTPOINT in /etc/mtab" $DEVICE ts_device_deinit $DEVICE diff --git a/tests/ts-mount-uuid b/tests/ts-mount-uuid index 8e2bdf75..4c968717 100755 --- a/tests/ts-mount-uuid +++ b/tests/ts-mount-uuid @@ -26,7 +26,6 @@ ts_skip_nonroot set -o pipefail -MOUNTPOINT="$TS_OUTDIR/${TS_NAME}_mnt" DEVICE=$(ts_device_init) [ "$?" == 0 ] || ts_die "Cannot init device" @@ -41,9 +40,9 @@ UUID=$(ts_uuid_by_devname $DEVICE) ts_udev_dev_support "by-uuid" $UUID [ "$?" == "0" ] || ts_skip "udev ignores /dev/loop*" $DEVICE -[ -d "$MOUNTPOINT" ] || mkdir -p $MOUNTPOINT +[ -d "$TS_MOUNTPOINT" ] || mkdir -p $TS_MOUNTPOINT -$TS_CMD_MOUNT -U $UUID $MOUNTPOINT 2>&1 >> $TS_OUTPUT +$TS_CMD_MOUNT -U $UUID $TS_MOUNTPOINT 2>&1 >> $TS_OUTPUT grep -q $DEVICE /proc/mounts [ "$?" == "0" ] || ts_die "Cannot found $DEVICE in /proc/mounts" $DEVICE