]> err.no Git - util-linux/commitdiff
tests: add support for fstab modification
authorKarel Zak <kzak@redhat.com>
Tue, 22 May 2007 14:01:55 +0000 (16:01 +0200)
committerKarel Zak <kzak@redhat.com>
Tue, 22 May 2007 16:38:49 +0000 (18:38 +0200)
The patch adds ts_fstab_add and ts_fstab_clean routines.

Signed-off-by: Karel Zak <kzak@redhat.com>
tests/functions.sh
tests/ts-cramfs-mkfs
tests/ts-mount-devname
tests/ts-mount-label
tests/ts-mount-remount
tests/ts-mount-uuid

index 24308f696fa1c80b6dcf0703940d9b37259038ee..ba94ad4de61376c3bf50b99c8a18d0dda9ad596a 100644 (file)
@@ -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 "# <!-- util-linux-ng test entry" >> /etc/fstab
+}
+
+function ts_fstab_close {
+       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 "
+/# <!-- util-linux-ng/!b
+:a
+/# -->/!{
+  N
+  ba
+}
+s/# <!-- util-linux-ng.*-->//;
+/^$/d" /etc/fstab
+}
+
index cbe37292e8cd74cafc61df1f62f61c0d2227a2ae..c2d6c131a8f389100109dcd6acb47d8eb5966877 100755 (executable)
@@ -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"
index dd6e4a358ec967cc75b5dbbffe0bc31a9ecb21cd..a2ebb332e3797f5ad7a4423e0de75a0f40c4f23c 100755 (executable)
@@ -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
index 5a9b59aa80eb2bc8b05d2f315fbb4a7381aeb12d..c6a841eab61ae8ec7d49001c819eb83584e3c05a 100755 (executable)
@@ -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
index 295ca509704f0d90696937a610f49feb8a8ab420..b293572a4a59078a2eb51e86e8189ccb97245958 100755 (executable)
@@ -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
 
index 8e2bdf758ac9f6ade4924e9666cbcb415f3a4e96..4c9687173e6f62ef88f804e96311ae3a247e3e2c 100755 (executable)
@@ -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