Generate a dummy 'Fedora' fedora.img in images directory for use by tests.

We were generating this dummy 'Fedora' image already in the
tools directory.  It contains just enough Fedora-like files
to fool our inspection code and thus to test the tools.

This is general enough that we can use it everywhere.
This commit is contained in:
Richard W.M. Jones
2010-11-11 16:20:25 +00:00
parent 4d59e27104
commit 4d900cdac8
10 changed files with 53 additions and 42 deletions

1
.gitignore vendored
View File

@@ -120,6 +120,7 @@ images/100kallzeroes
images/100krandom
images/10klines
images/abssymlink
images/fedora.img
images/hello.b64
images/initrd
images/initrd-x86_64.img

View File

@@ -1,5 +1,5 @@
# libguestfs test images
# Copyright (C) 2009 Red Hat Inc.
# Copyright (C) 2009-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
@@ -36,14 +36,19 @@ EXTRA_DIST = \
lib-win32.dll \
lib-win64.dll \
lib-x86_64.so \
test-grep.txt
test-grep.txt \
make-dummy-fedora-img.sh
noinst_DATA = test.iso
# This is 'check_DATA' because we don't need it until 'make check'
# time and we need the tools we have built in order to make it.
check_DATA = fedora.img
CLEANFILES = \
test.iso test.sqsh \
100kallzeroes 100kallnewlines 100kallspaces 100krandom 10klines \
initrd
initrd fedora.img
images_files_src = \
$(srcdir)/helloworld.tar \
@@ -150,3 +155,9 @@ $(builddir)/test-grep.txt.gz: test-grep.txt
rm -f $@ $@-t
gzip --best -c $< > $@-t
mv $@-t $@
# Make a (dummy) Fedora image.
fedora.img: make-dummy-fedora-img.sh
LIBGUESTFS_PATH=../appliance \
LD_LIBRARY_PATH=../src/.libs \
bash $<

View File

@@ -1,5 +1,5 @@
#!/bin/bash -
# libguestfs virt-* tools
# libguestfs
# Copyright (C) 2010 Red Hat Inc.
#
# This program is free software; you can redistribute it and/or modify
@@ -16,24 +16,24 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
# Make a standard test image which is used by all the tools/test-*.sh
# test scripts. This test image is supposed to look like a Fedora
# installation, or at least enough of one to fool virt-inspector's
# Make a standard test image which is used by all the tools test
# scripts. This test image is supposed to look like a Fedora
# installation, or at least enough of one to fool the inspection API
# heuristics.
export LANG=C
set -e
rm -f test.img
rm -f fedora.img
cat > fstab <<EOF
cat > fstab.tmp <<EOF
LABEL=BOOT /boot ext2 default 0 0
LABEL=ROOT / ext2 default 0 0
EOF
# Create a disk image.
../fish/guestfish <<'EOF'
sparse test.img- 512M
sparse fedora.img- 512M
run
# Format the disk.
@@ -63,7 +63,7 @@ mount-options "" /dev/sda1 /boot
mkdir /bin
mkdir /etc
mkdir /usr
upload fstab /etc/fstab
upload fstab.tmp /etc/fstab
mkdir /boot/grub
touch /boot/grub/grub.conf
@@ -85,5 +85,5 @@ mkfs-b ext2 1024 /dev/VG/LV2
mkfs-b ext2 2048 /dev/VG/LV3
EOF
rm fstab
mv test.img- test.img
rm fstab.tmp
mv fedora.img- fedora.img

View File

@@ -29,17 +29,21 @@ test -d /dev/fd || {
set -e
rm -f test1.img
rm -rf copy
rm -rf original copy
mkdir original
cp $srcdir/../images/known* original
cp -P $srcdir/../images/abssymlink* original
output=$(
../fish/guestfish -N fs -m /dev/sda1 <<EOF
mkdir /data
# This creates a directory /data/images/
copy-in ../images /data
is-file /data/images/known-1
is-file /data/images/known-3
is-file /data/images/known-5
is-symlink /data/images/abssymlink
copy-in original /data
is-file /data/original/known-1
is-file /data/original/known-3
is-file /data/original/known-5
is-symlink /data/original/abssymlink
is-file /data/known-1
is-file /known-1
EOF
@@ -60,13 +64,13 @@ fi
mkdir copy
../fish/guestfish --ro -a test1.img -m /dev/sda1 <<EOF
copy-out /data/images copy
copy-out /data/original copy
EOF
if test ! -f copy/images/known-1 || \
test ! -f copy/images/known-3 || \
test ! -f copy/images/known-5 || \
test ! -L copy/images/abssymlink || \
if test ! -f copy/original/known-1 || \
test ! -f copy/original/known-3 || \
test ! -f copy/original/known-5 || \
test ! -L copy/original/abssymlink || \
test -f copy/known-1 || \
test -f known-1
then
@@ -75,4 +79,4 @@ then
fi
rm -f test1.img
rm -rf copy
rm -rf original copy

View File

@@ -33,7 +33,6 @@ tools = \
EXTRA_DIST = \
run-locally \
$(tools:%=virt-%) \
make-test-img.sh \
test-virt-*.sh
CLEANFILES = test.img
@@ -76,11 +75,6 @@ TESTS_ENVIRONMENT = \
LIBGUESTFS_PATH=$(top_builddir)/appliance \
PERL5LIB=$(top_builddir)/perl/blib/lib:$(top_builddir)/perl/blib/arch
# Build a standard test image to be used by all these tests.
check_DATA = test.img
test.img: make-test-img.sh
$(TESTS_ENVIRONMENT) $(srcdir)/make-test-img.sh
TESTS = test-virt-cat.sh \
test-virt-df.sh \
test-virt-list-filesystems.sh \

View File

@@ -4,11 +4,11 @@ export LANG=C
set -e
# Read out the test files from the image using virt-cat.
if [ "$(./virt-cat test.img /etc/test1)" != "abcdefg" ]; then
if [ "$(./virt-cat ../images/fedora.img /etc/test1)" != "abcdefg" ]; then
echo "$0: error: mismatch in file test1"
exit 1
fi
if [ "$(./virt-cat test.img /etc/test2)" != "" ]; then
if [ "$(./virt-cat ../images/fedora.img /etc/test2)" != "" ]; then
echo "$0: error: mismatch in file test2"
exit 1
fi

View File

@@ -4,7 +4,7 @@ export LANG=C
set -e
# Run virt-df.
output=$(./virt-df test.img)
output=$(./virt-df ../images/fedora.img)
# Check title is the first line.
if [[ ! $output =~ ^Filesystem.* ]]; then
@@ -19,25 +19,25 @@ if [ $(echo "$output" | wc -l) -ne 6 ]; then
fi
# Check /dev/VG/LV[1-3] and /dev/VG/Root were found.
if [[ ! $output =~ test.img:/dev/VG/LV1 ]]; then
if [[ ! $output =~ fedora.img:/dev/VG/LV1 ]]; then
echo "$0: error: filesystem /dev/VG/LV1 was not found"
exit 1
fi
if [[ ! $output =~ test.img:/dev/VG/LV2 ]]; then
if [[ ! $output =~ fedora.img:/dev/VG/LV2 ]]; then
echo "$0: error: filesystem /dev/VG/LV2 was not found"
exit 1
fi
if [[ ! $output =~ test.img:/dev/VG/LV3 ]]; then
if [[ ! $output =~ fedora.img:/dev/VG/LV3 ]]; then
echo "$0: error: filesystem /dev/VG/LV3 was not found"
exit 1
fi
if [[ ! $output =~ test.img:/dev/VG/Root ]]; then
if [[ ! $output =~ fedora.img:/dev/VG/Root ]]; then
echo "$0: error: filesystem /dev/VG/Root was not found"
exit 1
fi
# Check /dev/sda1 was found. Might be called /dev/vda1.
if [[ ! $output =~ test.img:/dev/[hsv]da1 ]]; then
if [[ ! $output =~ fedora.img:/dev/[hsv]da1 ]]; then
echo "$0: error: filesystem /dev/VG/sda1 was not found"
exit 1
fi

View File

@@ -5,7 +5,8 @@ set -e
# Run virt-list-filesystems.
# Only columns 1 & 2 are guaranteed, we may add more in future.
if [ "$(./virt-list-filesystems -l test.img | sort | awk '{print $1 $2}')" \
if [ "$(./virt-list-filesystems -l ../images/fedora.img |
sort | awk '{print $1 $2}')" \
!= \
"/dev/VG/LV1ext2
/dev/VG/LV2ext2

View File

@@ -7,7 +7,7 @@ set -e
uuid=868b1447-0ec5-41bf-a2e5-6a77a4c9b66f
# Read out the test directory using virt-ls.
if [ "$(./virt-ls test.img /bin)" != "test1
if [ "$(./virt-ls ../images/fedora.img /bin)" != "test1
test2
test3
test4

View File

@@ -4,7 +4,7 @@ export LANG=C
set -e
# Read out the test directory using virt-tar.
./virt-tar -x test.img /bin test.tar
./virt-tar -x ../images/fedora.img /bin test.tar
if [ "$(tar tf test.tar)" != "./
./test1