Richard W.M. Jones
2022-Jun-08 16:48 UTC
[Libguestfs] [PATCH virt-v2v 0/3] tests: Add a phony Fedora image for testing
When we split virt-v2v from libguestfs many moons ago, I copied the test-data/ subdirectory over. I didn't modify it much, and it contains much test data that is irrelevant to virt-v2v. (This change does _not_ clean up any of that ...) However we did use the phony Windows image (test-data/phony-guests/windows.img) to do a semblance of testing Windows conversions, or as much as can be done without having the proprietary operating system itself around. We never used any of the Linux images, and in fact (before this change) they could not be used. They simply don't appear close enough to a real guest to work with virt-v2v. In particular they lack installed kernels, modules, bootloader config and the program needed to rebuild the initramfs. This change fixes the Fedora image(s) so they can be used for testing, and adds conversion of those to the testsuite. I already pushed the first commit in this series since it was a big binary blob update to the phony Fedora RPM database that was not reviewable: https://github.com/libguestfs/virt-v2v/commit/0d1b2ec1b733db1ca0bebf2e4a9e8d5fd7db7f93 Rich.
Richard W.M. Jones
2022-Jun-08 16:49 UTC
[Libguestfs] [PATCH virt-v2v 1/3] test-data/phony-guests: Increase size of root filesystem
Avoid this error in virt-v2v when trying to convert the phony Fedora guest image: [ 8.1] Checking for sufficient free disk space in the guest virt-v2v: error: not enough free space for conversion on filesystem ?/?. 21.6 MB free < 100 MB needed --- test-data/phony-guests/make-fedora-img.pl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test-data/phony-guests/make-fedora-img.pl b/test-data/phony-guests/make-fedora-img.pl index 90492b814e..f340f4d744 100755 --- a/test-data/phony-guests/make-fedora-img.pl +++ b/test-data/phony-guests/make-fedora-img.pl @@ -1,6 +1,6 @@ #!/usr/bin/env perl # libguestfs -# Copyright (C) 2010-2020 Red Hat Inc. +# Copyright (C) 2010-2022 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 @@ -210,7 +210,7 @@ sub init_lvm_root { $g->pvcreate ($rootdev); $g->vgcreate ('VG', [$rootdev]); - $g->lvcreate ('Root', 'VG', 32); + $g->lvcreate ('Root', 'VG', 256); $g->lvcreate ('LV1', 'VG', 32); $g->lvcreate ('LV2', 'VG', 32); $g->lvcreate ('LV3', 'VG', 64); -- 2.35.1
Richard W.M. Jones
2022-Jun-08 16:49 UTC
[Libguestfs] [PATCH virt-v2v 2/3] test-data/phony-guests: Allow virt-v2v to work against phony Fedora
We didn't use the phony Fedora guest before with virt-v2v (only the phony Windows image). This commit makes miscellaneous changes so that it can be used for testing: - Add dummy rpm and dracut commands. - Add dummy kernel, initramfs and modules directory. - Add dummy grub configuration pointing to the kernel. --- .gitignore | 1 + test-data/phony-guests/Makefile.am | 19 +++++-- test-data/phony-guests/fedora.c | 67 +++++++++++++++++++++++ test-data/phony-guests/make-fedora-img.pl | 26 ++++++++- 4 files changed, 108 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index ac7d6a3ce0..04ab847dcd 100644 --- a/.gitignore +++ b/.gitignore @@ -117,6 +117,7 @@ Makefile.in /test-data/phony-guests/fedora-luks.img /test-data/phony-guests/fedora-md1.img /test-data/phony-guests/fedora-md2.img +/test-data/phony-guests/fedora-static-bin /test-data/phony-guests/fedora.db /test-data/phony-guests/guests.xml /test-data/phony-guests/guests-all-good.xml diff --git a/test-data/phony-guests/Makefile.am b/test-data/phony-guests/Makefile.am index 60313548af..c45ddc1123 100644 --- a/test-data/phony-guests/Makefile.am +++ b/test-data/phony-guests/Makefile.am @@ -76,7 +76,8 @@ blank-%.img: # Make a (dummy) Fedora image. fedora.img: make-fedora-img.pl \ fedora-journal.tar.xz \ - fedora.db + fedora.db \ + fedora-static-bin SRCDIR=$(srcdir) LAYOUT=partitions $(top_builddir)/run --test ./$< # Make a (dummy) Fedora image using md devices @@ -84,7 +85,8 @@ fedora-md1.img fedora-md2.img: stamp-fedora-md.img stamp-fedora-md.img: make-fedora-img.pl \ fedora-journal.tar.xz \ - fedora.db + fedora.db \ + fedora-static-bin rm -f $@ SRCDIR=$(srcdir) LAYOUT=partitions-md $(top_builddir)/run --test ./$< touch $@ @@ -93,13 +95,15 @@ stamp-fedora-md.img: make-fedora-img.pl \ # for root and home. fedora-btrfs.img: make-fedora-img.pl \ fedora-journal.tar.xz \ - fedora.db + fedora.db \ + fedora-static-bin SRCDIR=$(srcdir) LAYOUT=btrfs $(top_builddir)/run --test ./$< # Make a (dummy) Fedora image with LVM encrypted with LUKS. fedora-luks.img: make-fedora-img.pl \ fedora-journal.tar.xz \ - fedora.db + fedora.db \ + fedora-static-bin SRCDIR=$(srcdir) LAYOUT=lvm-luks $(top_builddir)/run --test ./$< # Make a (dummy) Debian image. @@ -137,6 +141,13 @@ fedora.db: fedora-db.sql.xz xzcat $< | $(SQLITE3) $@-t mv $@-t $@ +# This is included in the phony Fedora image to act as a phony "rpm" +# and "dracut" command. For the use of -all-static here, see +# libguestfs/tests/Makefile.am +check_PROGRAMS = fedora-static-bin +fedora_static_bin_SOURCES = fedora.c +fedora_static_bin_LDFLAGS = -all-static + windows-software: windows-software.reg rm -f $@ $@-t cp $(srcdir)/minimal-hive $@-t diff --git a/test-data/phony-guests/fedora.c b/test-data/phony-guests/fedora.c new file mode 100644 index 0000000000..36eaa233fc --- /dev/null +++ b/test-data/phony-guests/fedora.c @@ -0,0 +1,67 @@ +/* libguestfs test images + * Copyright (C) 2009-2020 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. + */ + +/* This is "just enough" of a binary to look like RPM and dracut, as + * far as virt-v2v is concerned. + */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <assert.h> + +/* NB: This is also defined in make-fedora-img.pl */ +#define KVER "5.19.0-0.rc1.14.fc37.x86_64" + +static const char * +basename (const char *str) +{ + const char *ret = strrchr (str, '/'); + return ret == NULL ? str : ret + 1; +} + +int +main (int argc, char *argv[]) +{ + if (argc == 3 && + strcmp (basename (argv[0]), "rpm") == 0 && + strcmp (argv[1], "-ql") == 0 && + strncmp (argv[2], "kernel-", 7) == 0) { + /* XXX These files and directories actually exist. It would be + * better to list files in /boot and /lib/modules matching a + * pattern rather than hard-coding the list here, which duplicates + * information in make-fedora-img.pl. + */ + printf ("/boot/vmlinuz-" KVER "\n"); + printf ("/lib/modules/" KVER "\n"); + printf ("/lib/modules/" KVER "/kernel\n"); + printf ("/lib/modules/" KVER "/kernel/drivers\n"); + printf ("/lib/modules/" KVER "/kernel/drivers/block\n"); + printf ("/lib/modules/" KVER "/kernel/drivers/block/virtio_blk.ko\n"); + } + else if (argc >= 1 && + strcmp (basename (argv[0]), "dracut") == 0) { + // do nothing, pretend to rebuild the initramfs + } + else { + fprintf (stderr, "phony Fedora: unknown command\n"); + exit (1); + } + + exit (0); +} diff --git a/test-data/phony-guests/make-fedora-img.pl b/test-data/phony-guests/make-fedora-img.pl index f340f4d744..ad30960fa3 100755 --- a/test-data/phony-guests/make-fedora-img.pl +++ b/test-data/phony-guests/make-fedora-img.pl @@ -240,6 +240,7 @@ $g->mount ($bootdev, '/boot'); $g->mkdir ('/bin'); $g->mkdir ('/etc'); $g->mkdir ('/etc/sysconfig'); +$g->mkdir ('/sbin'); $g->mkdir ('/usr'); $g->mkdir ('/usr/share'); $g->mkdir ('/usr/share/zoneinfo'); @@ -276,8 +277,17 @@ $g->upload ($ENV{SRCDIR}.'/../binaries/bin-x86_64-dynamic', '/bin/ls'); $g->tar_in ($ENV{SRCDIR}.'/fedora-journal.tar.xz', '/var/log/journal', compress => "xz"); +# NB: This is also defined in fedora.c +my $kver = "5.19.0-0.rc1.14.fc37.x86_64"; $g->mkdir ('/boot/grub'); -$g->touch ('/boot/grub/grub.conf'); +$g->write ('/boot/grub/grub.conf', <<EOF); +title Fedora + root (hd0,0) + kernel /vmlinuz-$kver + initrd /initramfs-$kver.img +EOF + +$g->touch ('/etc/modprobe.conf'); # Test files. $g->write ('/etc/test1', 'abcdefg'); @@ -300,6 +310,20 @@ $g->ln_s ('/bin/test1', '/bin/test5'); $g->mkfifo (0777, '/bin/test6'); $g->mknod (0777, 10, 10, '/bin/test7'); +# Virt-v2v needs an RPM command, or at least something which acts +# similarly, and also a dracut command. +$g->upload ('fedora-static-bin', '/bin/rpm'); +$g->chmod (0777, '/bin/rpm'); +$g->upload ('fedora-static-bin', '/sbin/dracut'); +$g->chmod (0777, '/sbin/dracut'); + +# Virt-v2v also needs a kernel, initrd and modules path. +$g->touch ("/boot/vmlinuz-$kver"); +$g->touch ("/boot/initramfs-$kver.img"); +$g->mkdir_p ("/lib/modules/$kver/kernel/drivers/block"); +$g->upload ($ENV{SRCDIR}.'/../binaries/bin-x86_64-dynamic', + "/lib/modules/$kver/kernel/drivers/block/virtio_blk.ko"); + # Cleanup $g->shutdown (); $g->close (); -- 2.35.1
Richard W.M. Jones
2022-Jun-08 16:49 UTC
[Libguestfs] [PATCH virt-v2v 3/3] tests: Add test cases for converting the phony Fedora images
As well as testing a full Fedora conversion which was not really tested properly before, this also adds tests of conversions of Btrfs, RAID and LUKS guests. --- tests/Makefile.am | 8 ++++++ tests/test-v2v-fedora-btrfs-conversion.sh | 31 +++++++++++++++++++++ tests/test-v2v-fedora-conversion.sh | 31 +++++++++++++++++++++ tests/test-v2v-fedora-luks-conversion.sh | 32 ++++++++++++++++++++++ tests/test-v2v-fedora-md-conversion.sh | 33 +++++++++++++++++++++++ 5 files changed, 135 insertions(+) diff --git a/tests/Makefile.am b/tests/Makefile.am index 1244279836..63e654a3d1 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -96,6 +96,10 @@ TESTS = \ test-v2v-print-source.sh \ test-v2v-sound.sh \ test-v2v-virtio-win-iso.sh \ + test-v2v-fedora-conversion.sh \ + test-v2v-fedora-btrfs-conversion.sh \ + test-v2v-fedora-luks-conversion.sh \ + test-v2v-fedora-md-conversion.sh \ test-v2v-windows-conversion.sh \ rhbz1232192.sh \ $(SLOW_TESTS) \ @@ -171,6 +175,10 @@ EXTRA_DIST += \ test-v2v-bad-networks-and-bridges.sh \ test-v2v-cdrom.expected \ test-v2v-cdrom.sh \ + test-v2v-fedora-conversion.sh \ + test-v2v-fedora-btrfs-conversion.sh \ + test-v2v-fedora-luks-conversion.sh \ + test-v2v-fedora-md-conversion.sh \ test-v2v-floppy.expected \ test-v2v-floppy.sh \ test-v2v-i-disk.sh \ diff --git a/tests/test-v2v-fedora-btrfs-conversion.sh b/tests/test-v2v-fedora-btrfs-conversion.sh new file mode 100755 index 0000000000..c78f8ae246 --- /dev/null +++ b/tests/test-v2v-fedora-btrfs-conversion.sh @@ -0,0 +1,31 @@ +#!/bin/bash - +# libguestfs virt-v2v test script +# Copyright (C) 2014-2022 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 virt-v2v (Phony) Fedora conversion. + +set -e + +source ./functions.sh +set -e +set -x + +skip_if_skipped +f=../test-data/phony-guests/fedora-btrfs.img +requires test -f $f + +$VG virt-v2v --debug-gc -i disk $f -o null diff --git a/tests/test-v2v-fedora-conversion.sh b/tests/test-v2v-fedora-conversion.sh new file mode 100755 index 0000000000..92f4bbe8ea --- /dev/null +++ b/tests/test-v2v-fedora-conversion.sh @@ -0,0 +1,31 @@ +#!/bin/bash - +# libguestfs virt-v2v test script +# Copyright (C) 2014-2022 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 virt-v2v (Phony) Fedora conversion. + +set -e + +source ./functions.sh +set -e +set -x + +skip_if_skipped +f=../test-data/phony-guests/fedora.img +requires test -f $f + +$VG virt-v2v --debug-gc -i disk $f -o null diff --git a/tests/test-v2v-fedora-luks-conversion.sh b/tests/test-v2v-fedora-luks-conversion.sh new file mode 100755 index 0000000000..2922c31da1 --- /dev/null +++ b/tests/test-v2v-fedora-luks-conversion.sh @@ -0,0 +1,32 @@ +#!/bin/bash - +# libguestfs virt-v2v test script +# Copyright (C) 2014-2022 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 virt-v2v (Phony) Fedora conversion. + +set -e + +source ./functions.sh +set -e +set -x + +skip_if_skipped +f=../test-data/phony-guests/fedora-luks.img +requires test -f $f + +# The disk is encrypted with password "FEDORA". +$VG virt-v2v --debug-gc -i disk $f -o null --key /dev/sda2:key:FEDORA diff --git a/tests/test-v2v-fedora-md-conversion.sh b/tests/test-v2v-fedora-md-conversion.sh new file mode 100755 index 0000000000..669f2c01b5 --- /dev/null +++ b/tests/test-v2v-fedora-md-conversion.sh @@ -0,0 +1,33 @@ +#!/bin/bash - +# libguestfs virt-v2v test script +# Copyright (C) 2014-2022 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 virt-v2v (Phony) Fedora conversion. + +set -e + +source ./functions.sh +set -e +set -x + +skip_if_skipped +f1=../test-data/phony-guests/fedora-md1.img +requires test -f $f1 +f2=../test-data/phony-guests/fedora-md2.img +requires test -f $f2 + +$VG virt-v2v --debug-gc -i disk $f1 $f2 -o null -- 2.35.1
Laszlo Ersek
2022-Jun-09 08:02 UTC
[Libguestfs] [PATCH virt-v2v 0/3] tests: Add a phony Fedora image for testing
On 06/08/22 18:48, Richard W.M. Jones wrote:> When we split virt-v2v from libguestfs many moons ago, I copied the > test-data/ subdirectory over. I didn't modify it much, and it > contains much test data that is irrelevant to virt-v2v. (This change > does _not_ clean up any of that ...) However we did use the phony > Windows image (test-data/phony-guests/windows.img) to do a semblance > of testing Windows conversions, or as much as can be done without > having the proprietary operating system itself around. > > We never used any of the Linux images, and in fact (before this > change) they could not be used.Ah, indeed; for the LUKS-on-LV stuff, I synched "test-data/phony-guests/make-fedora-img.pl" from libguestfs and guestfs-tools (commits 8f2bbc3d50d8 and 27da4b0c4991), but didn't touch virt-v2v's copy. There was no need, and even prior differences existed. ... Indeed, libguestfs commit 0b223a287711 ("test-data: Replace deprecated luks_open with cryptsetup_open.", 2021-05-27) had not been ported to virt-v2v's copy.> They simply don't appear close enough > to a real guest to work with virt-v2v. In particular they lack > installed kernels, modules, bootloader config and the program needed > to rebuild the initramfs. > > This change fixes the Fedora image(s) so they can be used for testing, > and adds conversion of those to the testsuite. > > I already pushed the first commit in this series since it was a big > binary blob update to the phony Fedora RPM database that was not > reviewable: > > https://github.com/libguestfs/virt-v2v/commit/0d1b2ec1b733db1ca0bebf2e4a9e8d5fd7db7f93 > > Rich. > >Thanks Laszlo