diff options
author | Richard W.M. Jones <rjones@redhat.com> | 2011-12-22 11:35:43 +0000 |
---|---|---|
committer | Richard W.M. Jones <rjones@redhat.com> | 2011-12-22 13:04:41 +0000 |
commit | 498758faee6be7e989869bf7feba5e1026a1bb65 (patch) | |
tree | 2c8c599870039286414c7e20d138c91889ca9b05 /tests/md | |
parent | 5d93d70b4d36b2337104b3dbca07722fa4d47ff5 (diff) | |
download | libguestfs-498758faee6be7e989869bf7feba5e1026a1bb65.tar.gz libguestfs-498758faee6be7e989869bf7feba5e1026a1bb65.tar.xz libguestfs-498758faee6be7e989869bf7feba5e1026a1bb65.zip |
tests: Split regressions -> various subdirectories of tests/
Diffstat (limited to 'tests/md')
-rw-r--r-- | tests/md/Makefile.am | 36 | ||||
-rwxr-xr-x | tests/md/test-inspect-fstab-md.sh | 74 | ||||
-rwxr-xr-x | tests/md/test-inspect-fstab.sh | 130 | ||||
-rwxr-xr-x | tests/md/test-list-filesystems.sh | 76 | ||||
-rwxr-xr-x | tests/md/test-list-md-devices.sh | 59 | ||||
-rwxr-xr-x | tests/md/test-mdadm.sh | 166 |
6 files changed, 541 insertions, 0 deletions
diff --git a/tests/md/Makefile.am b/tests/md/Makefile.am new file mode 100644 index 00000000..c778956f --- /dev/null +++ b/tests/md/Makefile.am @@ -0,0 +1,36 @@ +# libguestfs +# Copyright (C) 2009-2011 Red Hat Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +include $(top_srcdir)/subdir-rules.mk + +TESTS = \ + test-inspect-fstab.sh \ + test-inspect-fstab-md.sh \ + test-list-filesystems.sh \ + test-list-md-devices.sh \ + test-mdadm.sh + +random_val := $(shell awk 'BEGIN{srand(); print 1+int(255*rand())}' < /dev/null) + +TESTS_ENVIRONMENT = \ + MALLOC_PERTURB_=$(random_val) \ + LD_LIBRARY_PATH=$(top_builddir)/src/.libs \ + LIBGUESTFS_PATH=$(top_builddir)/appliance \ + TMPDIR=$(top_builddir) + +EXTRA_DIST = \ + $(TESTS)
\ No newline at end of file diff --git a/tests/md/test-inspect-fstab-md.sh b/tests/md/test-inspect-fstab-md.sh new file mode 100755 index 00000000..2a6cb6a9 --- /dev/null +++ b/tests/md/test-inspect-fstab-md.sh @@ -0,0 +1,74 @@ +#!/bin/bash - +# libguestfs +# Copyright (C) 2011 Red Hat Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +# Test the handling of MD devices specified in /etc/fstab + +set -e +export LANG=C + +# The first test requires a new Augeas lens for parsing mdadm.conf. +# If this is not present in the appliance or on the host, skip the +# test. +f=$(grep mdadm_conf.aug ../../appliance/supermin.d/hostfiles | head -1) +if [ -z "$f" -o ! -f "$f" ]; then + echo "$0: test skipped because Augeas mdadm.conf lens is not available." + exit 0 +fi + +guestfish=../../fish/guestfish + +rm -f test1.img test.fstab test.output + +# First, test the regular fedora image, which specifies /boot as /dev/md0 +cp ../../images/fedora-md1.img test1.img +cp ../../images/fedora-md2.img test2.img + +$guestfish -i test[12].img <<'EOF' | sort > test.output + exists /boot/grub/grub.conf +EOF + +if [ "$(cat test.output)" != "true" ]; then + echo "$0: /boot not correctly mounted (/dev/md0)" + exit 1 +fi + +# Test inspection when /boot is specfied as /dev/md/boot +cat <<'EOF' > test.fstab +/dev/VG/Root / ext2 default 0 0 +/dev/md/boot /boot ext2 default 0 0 +EOF + +$guestfish -a test1.img -a test2.img <<'EOF' + run + mount-options "" /dev/VG/Root / + upload test.fstab /etc/fstab +EOF + +$guestfish -i test[12].img <<'EOF' | sort > test.output + exists /boot/grub/grub.conf +EOF + +if [ "$(cat test.output)" != "true" ]; then + echo "$0: error: /boot not correctly mounted (/dev/md/boot)" + cat test.output + exit 1 +fi + +rm test.fstab +rm test[12].img +rm test.output diff --git a/tests/md/test-inspect-fstab.sh b/tests/md/test-inspect-fstab.sh new file mode 100755 index 00000000..72a11fad --- /dev/null +++ b/tests/md/test-inspect-fstab.sh @@ -0,0 +1,130 @@ +#!/bin/bash - +# libguestfs +# Copyright (C) 2011 Red Hat Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +# Test various aspects of core inspection of /etc/fstab. +# This also tests: https://bugzilla.redhat.com/668574 + +set -e +export LANG=C + +guestfish=../../fish/guestfish + +rm -f test1.img test.fstab test.output + +# Start with the regular (good) fedora image, modify /etc/fstab +# and then inspect it. +cp ../../images/fedora.img test1.img + +cat <<'EOF' > test.fstab +/dev/VG/Root / ext2 default 0 0 + +# Xen-style partition names. +/dev/xvda1 /boot ext2 default 0 0 + +# Non-existant device. +/dev/sdb3 /var ext2 default 0 0 + +# Non-existant mountpoint. +/dev/VG/LV1 /nosuchfile ext2 default 0 0 +EOF + +$guestfish -a test1.img <<'EOF' + run + mount-options "" /dev/VG/Root / + upload test.fstab /etc/fstab +EOF + +# This will give a warning, but should not fail. +$guestfish -a test1.img -i <<'EOF' | sort > test.output + inspect-get-mountpoints /dev/VG/Root +EOF + +if [ "$(cat test.output)" != "/: /dev/VG/Root +/boot: /dev/vda1 +/nosuchfile: /dev/VG/LV1 +/var: /dev/sdb3" ]; then + echo "$0: error: unexpected output from inspect-get-mountpoints command" + cat test.output + exit 1 +fi + +# Test device name hints + +cat <<'EOF' > test.fstab +/dev/VG/Root / ext2 default 0 0 + +# Device name which requires a hint +/dev/xvdg1 /boot ext2 default 0 0 +EOF + +$guestfish -a test1.img <<'EOF' + run + mount-options "" /dev/VG/Root / + upload test.fstab /etc/fstab +EOF + +$guestfish <<'EOF' > test.output + add-drive-opts test1.img readonly:true name:xvdg + run + inspect-os + inspect-get-mountpoints /dev/VG/Root +EOF + +if [ "$(cat test.output)" != "/dev/VG/Root +/: /dev/VG/Root +/boot: /dev/vda1" ]; then + echo "$0: error: unexpected output from inspect-get-mountpoints command" + cat test.output + exit 1 +fi + +cat <<'EOF' > test.fstab +/dev/VG/Root / ext2 default 0 0 + +# cciss device which requires a hint +/dev/cciss/c1d3p1 /boot ext2 default 0 0 + +# cciss device, whole disk +/dev/cciss/c1d3 /var ext2 default 0 0 +EOF + +$guestfish -a test1.img <<'EOF' + run + mount-options "" /dev/VG/Root / + upload test.fstab /etc/fstab +EOF + +$guestfish <<'EOF' > test.output + add-drive-opts test1.img readonly:true name:cciss/c1d3 + run + inspect-os + inspect-get-mountpoints /dev/VG/Root +EOF + +if [ "$(cat test.output)" != "/dev/VG/Root +/: /dev/VG/Root +/boot: /dev/vda1 +/var: /dev/vda" ]; then + echo "$0: error: unexpected output from inspect-get-mountpoints command" + cat test.output + exit 1 +fi + +rm test.fstab +rm test1.img +rm test.output diff --git a/tests/md/test-list-filesystems.sh b/tests/md/test-list-filesystems.sh new file mode 100755 index 00000000..9aea21a0 --- /dev/null +++ b/tests/md/test-list-filesystems.sh @@ -0,0 +1,76 @@ +#!/bin/bash - +# libguestfs +# Copyright (C) 2011 Red Hat Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +# Test guestfish list-mddevices command + +set -e + +# Create 2 disks partitioned as: +# sda1: 20M ext3 +# sda2: 20M MD (md127) +# +# sdb1: 20M PV (vg0) +# sdb2: 20M MD (md127) +# +# md127 : 20M ext4 +# vg0 : 16M LV (lv0) +# lv0 : 16M vfat +output=$( +../../fish/guestfish <<EOF +# Add 2 empty disks +sparse fs-test1.img 50M +sparse fs-test2.img 50M +run + +part-init /dev/sda mbr +part-add /dev/sda p 64 41023 +part-add /dev/sda p 41024 81983 +part-init /dev/sdb mbr +part-add /dev/sdb p 64 41023 +part-add /dev/sdb p 41024 81983 + +# Create vg0 and lv0 on /dev/sdb1 +pvcreate /dev/sdb1 +vgcreate vg0 /dev/sdb1 +lvcreate lv0 vg0 16 + +# Create an md device from sda2 and sdb2 +md-create test "/dev/sda2 /dev/sdb2" level:raid1 + +# Create filesystems +mkfs ext3 /dev/sda1 +mkfs ext4 /dev/md127 +mkfs vfat /dev/vg0/lv0 + +list-filesystems +EOF +) + +expected="/dev/vda1: ext3 +/dev/md127: ext4 +/dev/vg0/lv0: vfat" + +# Check the output of list-filesystems +if [ "$output" != "$expected" ]; then + echo "$0: error: output of list-filesystems did not match expected output" + printf "%s\n" "$output" + exit 1; +fi + + +rm -f fs-test1.img fs-test2.img diff --git a/tests/md/test-list-md-devices.sh b/tests/md/test-list-md-devices.sh new file mode 100755 index 00000000..99283be5 --- /dev/null +++ b/tests/md/test-list-md-devices.sh @@ -0,0 +1,59 @@ +#!/bin/bash - +# libguestfs +# Copyright (C) 2011 Red Hat Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +# Test guestfish list-md-devices command + +set -e + +output=$( +../../fish/guestfish <<EOF +# Add 2 empty disks +sparse md-test1.img 100M +sparse md-test2.img 100M +run + +# list-md-devices should return nothing +list-md-devices + +# Create a raid1 based on the 2 disks +md-create test "/dev/sda /dev/sdb" level:raid1 +EOF +) + +# Ensure list-md-devices above returned nothing +if [ ! -z "$output" ]; then + echo "$0: error: output of list-md-devices with no MD devices did not match expected output" + echo $output + exit 1; +fi + +# Ensure list-md-devices now returns the newly created md device +output=$( +../../fish/guestfish -a md-test1.img -a md-test2.img <<EOF +run +list-md-devices +EOF +) + +if [ "$output" != "/dev/md127" ]; then + echo "$0: error: output of list-md-devices did not match expected output" + echo "$output" + exit 1 +fi + +rm -f md-test1.img md-test2.img diff --git a/tests/md/test-mdadm.sh b/tests/md/test-mdadm.sh new file mode 100755 index 00000000..e7f5775a --- /dev/null +++ b/tests/md/test-mdadm.sh @@ -0,0 +1,166 @@ +#!/bin/bash - +# libguestfs +# Copyright (C) 2011 Red Hat Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +# Test guestfish md-create and md-detail commands. + +set -e + +rm -f md-test1.img md-test2.img md-test3.img md-test4.img + +../../fish/guestfish <<EOF +# Add four empty disks +sparse md-test1.img 100M +sparse md-test2.img 100M +sparse md-test3.img 100M +sparse md-test4.img 100M +run + +# Create lots of test partitions. +part-init /dev/sda mbr +part-add /dev/sda p 4096 8191 +part-add /dev/sda p 8192 12287 +part-add /dev/sda p 12288 16383 +part-add /dev/sda p 16384 20479 +part-init /dev/sdb mbr +part-add /dev/sdb p 4096 8191 +part-add /dev/sdb p 8192 12287 +part-add /dev/sdb p 12288 16383 +part-add /dev/sdb p 16384 20479 +part-init /dev/sdc mbr +part-add /dev/sdc p 4096 8191 +part-add /dev/sdc p 8192 12287 +part-add /dev/sdc p 12288 16383 +part-add /dev/sdc p 16384 20479 +part-init /dev/sdd mbr +part-add /dev/sdd p 4096 8191 +part-add /dev/sdd p 8192 12287 +part-add /dev/sdd p 12288 16383 +part-add /dev/sdd p 16384 20479 + +# RAID 1. +md-create r1t1 "/dev/sda1 /dev/sdb1" +md-create r1t2 "/dev/sdc1 /dev/sdd1" chunk:65536 + +# RAID 5. +md-create r5t1 "/dev/sda2 /dev/sdb2 /dev/sdc2 /dev/sdd2" \ + missingbitmap:0x10 nrdevices:4 spare:1 level:5 + +md-create r5t2 "/dev/sda3 /dev/sdb3" missingbitmap:0x1 level:5 + +md-create r5t3 "/dev/sdc3 /dev/sdd3" \ + missingbitmap:0x6 nrdevices:2 spare:2 level:5 + +# Make some filesystems and put some content on the +# new RAID devices to see if they work. +mkfs ext2 /dev/md/r1t1 +mkfs ext2 /dev/md/r1t2 +mkfs ext2 /dev/md/r5t1 +mkfs ext2 /dev/md/r5t2 +mkfs ext2 /dev/md/r5t3 + +mkmountpoint /r1t1 +mount /dev/md/r1t1 /r1t1 +mkmountpoint /r1t2 +mount /dev/md/r1t2 /r1t2 +mkmountpoint /r5t1 +mount /dev/md/r5t1 /r5t1 +mkmountpoint /r5t2 +mount /dev/md/r5t2 /r5t2 +mkmountpoint /r5t3 +mount /dev/md/r5t3 /r5t3 + +touch /r1t1/foo +mkdir /r1t2/bar +write /r5t1/foo "hello" +write /r5t2/bar "goodbye" +write /r5t3/baz "testing" + +EOF + +eval `../../fish/guestfish --listen` +../../fish/guestfish --remote add-ro md-test1.img +../../fish/guestfish --remote add-ro md-test2.img +../../fish/guestfish --remote add-ro md-test3.img +../../fish/guestfish --remote add-ro md-test4.img +../../fish/guestfish --remote run + +for md in `../../fish/guestfish --remote list-md-devices`; do + ../../fish/guestfish --remote md-detail "${md}" > md-detail.out + + sed 's/:\s*/=/' md-detail.out > md-detail.out.sh + . md-detail.out.sh + rm -f md-detail.out.sh + + error=0 + case "$name" in + *:r1t1) + [ "$level" == "raid1" ] || error=1 + [ "$devices" == "2" ] || error=1 + ;; + + *:r1t2) + [ "$level" == "raid1" ] || error=1 + [ "$devices" == "2" ] || error=1 + ;; + + *:r5t1) + [ "$level" == "raid5" ] || error=1 + [ "$devices" == "4" ] || error=1 + ;; + + *:r5t2) + [ "$level" == "raid5" ] || error=1 + [ "$devices" == "3" ] || error=1 + ;; + + *:r5t3) + [ "$level" == "raid5" ] || error=1 + [ "$devices" == "2" ] || error=1 + ;; + + *) + error=1 + esac + + [[ "$uuid" =~ ([0-9a-f]{8}:){3}[0-9a-f]{8} ]] || error=1 + [ ! -z "$metadata" ] || error=1 + + if [ "$error" == "1" ]; then + echo "$0: Unexpected output from md-detail for device $md" + cat md-detail.out + ../../fish/guestfish --remote exit + exit 1 + fi +done + +../../fish/guestfish --remote exit + +eval `../../fish/guestfish --listen` +../../fish/guestfish --remote add-ro md-test1.img +../../fish/guestfish --remote add-ro md-test2.img +../../fish/guestfish --remote add-ro md-test3.img +../../fish/guestfish --remote add-ro md-test4.img +../../fish/guestfish --remote run + +for md in `../../fish/guestfish --remote list-md-devices`; do + ../../fish/guestfish --remote md-stop "${md}" +done + +../../fish/guestfish --remote exit + +rm -f md-detail.out md-test1.img md-test2.img md-test3.img md-test4.img |