[parted-devel] [PATCH 2/2] tests: test for partitions on mdraid
Jim Meyering
jim at meyering.net
Sun Nov 27 08:55:26 UTC 2011
Petr Uzel wrote:
> tests/t6100-mdraid-partitions.sh: New file.
> tests/Makefile.am: Run this test.
Thanks a lot for this test.
I'm glad you found a way to test it with just one device.
> tests/Makefile.am | 1 +
> tests/t6100-mdraid-partitions.sh | 59 ++++++++++++++++++++++++++++++++++++++
> 2 files changed, 60 insertions(+), 0 deletions(-)
> create mode 100755 tests/t6100-mdraid-partitions.sh
>
> diff --git a/tests/Makefile.am b/tests/Makefile.am
> index 5bc513d..616684e 100644
> --- a/tests/Makefile.am
> +++ b/tests/Makefile.am
> @@ -49,6 +49,7 @@ TESTS = \
> t4300-nilfs2-tiny.sh \
> t5000-tags.sh \
> t6000-dm.sh \
> + t6100-mdraid-partitions.sh \
> t7000-scripting.sh \
> t8000-loop.sh \
> t8001-loop-blkpg.sh \
> diff --git a/tests/t6100-mdraid-partitions.sh b/tests/t6100-mdraid-partitions.sh
...
> +# create memory-backed device
> +scsi_debug_setup_ dev_size_mb=10 > dev-name ||
> + skip_ 'failed to create scsi_debug device'
> +scsi_dev=$(cat dev-name)
> +
> +# Arbitrary number, not likely to be used already
> +md_name="md99"
I'll drop the quotes. Not needed.
> +test -b /dev/${md_name} && skip_ "/dev/${md_name} already exists"
> +
> +# create gpt and two partitions on the device
> +parted -s "$scsi_dev" mklabel gpt mkpart p1 ext2 1M 4M mkpart p2 ext2 5M 8M > out 2>&1 || fail=1
Longer than 80.
> +compare out /dev/null || fail=1
> +
> +# create mdraid on top of both partitions
> +mdadm -C /dev/${md_name} --force -R -l1 -n2 "${scsi_dev}1" "${scsi_dev}2"
> +
> +# create gpt and two partitions on the raid device
> +parted -s /dev/${md_name} mklabel gpt mkpart r1 ext2 1M 2M mkpart r2 ext2 2M 3M > out 2>&1 || fail=1
> +compare out /dev/null || fail=1
> +
> +# verify that kernel has been informed about the second device
> +grep -s "${md_name}p2" /proc/partitions || { fail=1; cat /proc/partitions; }
> +
> +# remove partitions from the raid device
> +parted -s /dev/${md_name} rm 2 rm 1 > out 2>&1 || fail=1
> +compare out /dev/null || fail=1
> +
> +# verify that kernel has been informed about removing thos partitions
> +grep -s "${md_name}p[12]" /proc/partitions && { fail=1; cat /proc/partitions; }
> +
> +# stop mdraid array
> +mdadm -S /dev/${md_name} || { echo "Failed to stop MD array"; fail=1; }
> +
> +Exit $fail
I've made some stylistic changes (factoring, split lines longer than 80,
prefer $var notation: use ${var} unless needed), and have added the
cleanup_fn_ function so that the MD array is stopped also
upon interrupt or other catchable signal. Also, grep -s is not
portable, so I removed the -s. Finally, I reversed the compare
arguments so /dev/null is first. That makes it so when something
unexpected appears, the diffs show that output being "added", not
removed.
diff --git a/tests/t6100-mdraid-partitions.sh b/tests/t6100-mdraid-partitions.sh
index a3a2d0b..3836ca1 100755
--- a/tests/t6100-mdraid-partitions.sh
+++ b/tests/t6100-mdraid-partitions.sh
@@ -28,32 +28,39 @@ scsi_debug_setup_ dev_size_mb=10 > dev-name ||
scsi_dev=$(cat dev-name)
# Arbitrary number, not likely to be used already
-md_name="md99"
+md_name=md99
+md_dev=/dev/$md_name
-test -b /dev/${md_name} && skip_ "/dev/${md_name} already exists"
+test -b $md_dev && skip_ "$md_dev already exists"
# create gpt and two partitions on the device
-parted -s "$scsi_dev" mklabel gpt mkpart p1 ext2 1M 4M mkpart p2 ext2 5M 8M > out 2>&1 || fail=1
-compare out /dev/null || fail=1
+parted -s "$scsi_dev" mklabel gpt \
+ mkpart p1 ext2 1M 4M \
+ mkpart p2 ext2 5M 8M > out 2>&1 || fail=1
+compare /dev/null out || fail=1
+
+cleanup_fn_() {
+ # stop mdraid array
+ mdadm -S $md_dev || warn_ "Failed to stop MD array, $md_dev"
+}
# create mdraid on top of both partitions
-mdadm -C /dev/${md_name} --force -R -l1 -n2 "${scsi_dev}1" "${scsi_dev}2"
+mdadm -C $md_dev --force -R -l1 -n2 "${scsi_dev}1" "${scsi_dev}2"
# create gpt and two partitions on the raid device
-parted -s /dev/${md_name} mklabel gpt mkpart r1 ext2 1M 2M mkpart r2 ext2 2M 3M > out 2>&1 || fail=1
-compare out /dev/null || fail=1
-
-# verify that kernel has been informed about the second device
-grep -s "${md_name}p2" /proc/partitions || { fail=1; cat /proc/partitions; }
+parted -s $md_dev mklabel gpt \
+ mkpart r1 ext2 1M 2M \
+ mkpart r2 ext2 2M 3M > out 2>&1 || fail=1
+compare /dev/null out || fail=1
-# remove partitions from the raid device
-parted -s /dev/${md_name} rm 2 rm 1 > out 2>&1 || fail=1
-compare out /dev/null || fail=1
+# Verify that kernel has been informed about the second device.
+grep "${md_name}p2" /proc/partitions || { fail=1; cat /proc/partitions; }
-# verify that kernel has been informed about removing thos partitions
-grep -s "${md_name}p[12]" /proc/partitions && { fail=1; cat /proc/partitions; }
+# Remove partitions from the raid device.
+parted -s $md_dev rm 2 rm 1 > out 2>&1 || fail=1
+compare /dev/null out || fail=1
-# stop mdraid array
-mdadm -S /dev/${md_name} || { echo "Failed to stop MD array"; fail=1; }
+# Verify that kernel has been informed about those removals.
+grep "${md_name}p[12]" /proc/partitions && { fail=1; cat /proc/partitions; }
Exit $fail
More information about the parted-devel
mailing list