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/lvm | |
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/lvm')
-rw-r--r-- | tests/lvm/Makefile.am | 33 | ||||
-rwxr-xr-x | tests/lvm/test-lvm-filtering.sh | 92 | ||||
-rwxr-xr-x | tests/lvm/test-lvm-mapping.pl | 99 |
3 files changed, 224 insertions, 0 deletions
diff --git a/tests/lvm/Makefile.am b/tests/lvm/Makefile.am new file mode 100644 index 00000000..290f6b3d --- /dev/null +++ b/tests/lvm/Makefile.am @@ -0,0 +1,33 @@ +# 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-lvm-filtering.sh \ + test-lvm-mapping.pl + +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) diff --git a/tests/lvm/test-lvm-filtering.sh b/tests/lvm/test-lvm-filtering.sh new file mode 100755 index 00000000..d5ae8d50 --- /dev/null +++ b/tests/lvm/test-lvm-filtering.sh @@ -0,0 +1,92 @@ +#!/bin/bash - +# libguestfs +# Copyright (C) 2010 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 LVM device filtering. + +set -e + +rm -f test1.img test2.img + +actual=$(../../fish/guestfish <<'EOF' +sparse test1.img 1G +sparse test2.img 1G + +run + +part-disk /dev/sda mbr +part-disk /dev/sdb mbr + +pvcreate /dev/sda1 +pvcreate /dev/sdb1 + +vgcreate VG1 /dev/sda1 +vgcreate VG2 /dev/sdb1 + +# Should see VG1 and VG2 +vgs + +# Should see just VG1 +lvm-set-filter /dev/sda +vgs +lvm-set-filter /dev/sda1 +vgs + +# Should see just VG2 +lvm-set-filter /dev/sdb +vgs +lvm-set-filter /dev/sdb1 +vgs + +# Should see VG1 and VG2 +lvm-set-filter "/dev/sda /dev/sdb" +vgs +lvm-set-filter "/dev/sda1 /dev/sdb1" +vgs +lvm-set-filter "/dev/sda /dev/sdb1" +vgs +lvm-set-filter "/dev/sda1 /dev/sdb" +vgs +lvm-clear-filter +vgs +EOF +) + +expected="VG1 +VG2 +VG1 +VG1 +VG2 +VG2 +VG1 +VG2 +VG1 +VG2 +VG1 +VG2 +VG1 +VG2 +VG1 +VG2" + +rm -f test1.img test2.img + +if [ "$actual" != "$expected" ]; then + echo "LVM filter test failed. Actual output was:" + echo "$actual" + exit 1 +fi diff --git a/tests/lvm/test-lvm-mapping.pl b/tests/lvm/test-lvm-mapping.pl new file mode 100755 index 00000000..3e6faa5e --- /dev/null +++ b/tests/lvm/test-lvm-mapping.pl @@ -0,0 +1,99 @@ +#!/usr/bin/perl +# Copyright (C) 2010 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 discovery of relationships between LVM PVs, VGs and LVs. + +use strict; +use warnings; + +use Sys::Guestfs; + +my $testimg = "test.img"; + +unlink $testimg; +open FILE, ">$testimg" or die "$testimg: $!"; +truncate FILE, 256*1024*1024 or die "$testimg: truncate: $!"; +close FILE or die "$testimg: $!"; + +my $g = Sys::Guestfs->new (); + +#$g->set_verbose (1); +#$g->set_trace (1); + +$g->add_drive_opts ($testimg, format => "raw"); +$g->launch (); + +# Create an arrangement of PVs, VGs and LVs. +$g->sfdiskM ("/dev/sda", [",127", "128,"]); + +$g->pvcreate ("/dev/sda1"); +$g->pvcreate ("/dev/sda2"); +$g->vgcreate ("VG", ["/dev/sda1", "/dev/sda2"]); + +$g->lvcreate ("LV1", "VG", 32); +$g->lvcreate ("LV2", "VG", 32); +$g->lvcreate ("LV3", "VG", 32); + +# Now let's get the arrangement. +my @pvs = $g->pvs (); +my @lvs = $g->lvs (); + +my %pvuuids; +foreach my $pv (@pvs) { + my $uuid = $g->pvuuid ($pv); + $pvuuids{$uuid} = $pv; +} +my %lvuuids; +foreach my $lv (@lvs) { + my $uuid = $g->lvuuid ($lv); + $lvuuids{$uuid} = $lv; +} + +# In this case there is only one VG, called "VG", but in a real +# program you'd want to repeat these steps for each VG that you found. +my @pvuuids_in_VG = $g->vgpvuuids ("VG"); +my @lvuuids_in_VG = $g->vglvuuids ("VG"); + +my @pvs_in_VG; +foreach my $uuid (@pvuuids_in_VG) { + push @pvs_in_VG, $pvuuids{$uuid}; +} +@pvs_in_VG = sort @pvs_in_VG; + +my @lvs_in_VG; +foreach my $uuid (@lvuuids_in_VG) { + push @lvs_in_VG, $lvuuids{$uuid}; +} +@lvs_in_VG = sort @lvs_in_VG; + +unless (@pvs_in_VG == 2 && + $pvs_in_VG[0] eq "/dev/vda1" && $pvs_in_VG[1] eq "/dev/vda2") { + die "unexpected set of PVs for volume group VG: [", + join (", ", @pvs_in_VG), "]\n" +} + +unless (@lvs_in_VG == 3 && + $lvs_in_VG[0] eq "/dev/VG/LV1" && + $lvs_in_VG[1] eq "/dev/VG/LV2" && + $lvs_in_VG[2] eq "/dev/VG/LV3") { + die "unexpected set of LVs for volume group VG: [", + join (", ", @lvs_in_VG), "]\n" +} + +undef $g; + +unlink $testimg or die "$testimg: unlink: $!"; |