Commit 84e7c4af authored by Daniel P. Berrange's avatar Daniel P. Berrange

Allow test suite to auto-download/create all files it needs

 * bin/libvirt-tck: update help text
 * conf/default.cfg: Point to Fedora 11 repos for default kernel
   and initrd files needed by tests.
 * lib/Sys/Virt/TCK.pm: Auto download/copy all kernels/initrd
   needed for tests, and auto-create sparse disk files
parent 19ce09d3
......@@ -36,17 +36,16 @@ test suite for libvirt drivers.
There now follows a few words of warning
WARNING WARNING WARNING WARNING WARNING WARNING WARNING
The test suite needs to have a completely 'clean' initial
starting state and will do its best to make it so. Thus,
when this command runs, all existing (running and/or inactive)
guest domains, virtual networks, storage pools, or other libvirt
managed objects WILL BE DELETED.
To repeat: ALL YOUR EXISTING DOMAINS WILL BE DELETED
starting state. If your host already has virtual machines
defined and/or running this will cause problems. The test
suite will detect this and refuse to run, allowing you to
remove any preexisting guests. Alternatively you can pass
the --force option and libvirt will DELETE EVERYTHING it
finds.
WARNING WARNING WARNING WARNING WARNING WARNING WARNING
To repeat: ALL YOUR EXISTING DOMAINS, NETWORKS, STORAGE POOLS
WILL BE DELETED IF YOU USE THE --force OPTION.
The warning is now complete, continue reading
......@@ -222,7 +221,3 @@ then set the LIBVIRT_TCK_CONFIG environment variable to point to your
configuration file, and then run the C<prove> command passing in
the path to the test scripts to run.
C<libvirt-tck-prepare>. Before running C<libvirt-tck> this command can
be used to prepare a suitable kernel, initrd, bootable ISO, and dummy
chroot filesystem needed for various tests.
......@@ -5,14 +5,55 @@
#uri = "xen:///"
#uri = "qemu:///session"
# Override directory used for downloading/creating temporary files
#
# Where the kernel/initrd files needed by tests are found
# A minimum of 1 GB of free space is required on this
# directory.
#
# For most cases, can just grab the kernel/initrd from F10 to
# match your architecture: eg
# Defaults to /var/cache/libvirt-tck for root, or `pwd`/libvirt-tck for non-root
#scratch_dir = /var/cache/libvirt-tck
# To avoid filling the filessytem, the test suite will
# automatically set a usage limit of
#
# freespace(scratch_dir) - 500 MB
#
# http://download.fedora.redhat.com/pub/fedora/linux/releases/10/Fedora/x86_64/os/images/pxeboot/
kernel=/var/lib/libvirt-tck/vmlinuz
initrd=/var/lib/libvirt-tck/initrd.img
# The test suite will abort if it things it will exceed
# the limit.
#
# If you want to set a artificially lower usage limit...
#scratch_usage_limit = 10G
disk=/var/lib/libvirt-tck/disk-empty.img
\ No newline at end of file
#
# Where the kernel/initrd files needed by tests are to be
# found. These can be URLS or local file paths.
#
# The particular OS doesn't really matter - all the test
# suite currently needs is a kernel that doesn't crash
# upon boot. It doesn't actually need todo anything useful
#
# ...yet...
#
# So even if running on a Debian host, you'll not see any
# problem letting it grab the Fedora kernels
#
kernels = (
{
arch = x86_64
kernel=http://download.fedora.redhat.com/pub/fedora/linux/releases/11/Fedora/x86_64/os/images/pxeboot/vmlinuz
initrd=http://download.fedora.redhat.com/pub/fedora/linux/releases/11/Fedora/x86_64/os/images/pxeboot/initrd.img
ostype = (
hvm
xen
)
}
{
arch = i686
kernel=http://download.fedora.redhat.com/pub/fedora/linux/releases/11/Fedora/i386/os/images/pxeboot/vmlinuz
initrd=http://download.fedora.redhat.com/pub/fedora/linux/releases/11/Fedora/i386/os/images/pxeboot/initrd.img
ostype = (
hvm
xen
)
}
)
......@@ -7,6 +7,11 @@ use warnings;
use Sys::Virt;
use Sys::Virt::TCK::DomainBuilder;
use Config::Record;
use File::Copy qw(copy);
use File::Path qw(mkpath);
use File::Spec::Functions qw(catfile catdir rootdir);
use Cwd qw(cwd);
use LWP::UserAgent;
use Test::Builder;
use Sub::Uplevel qw(uplevel);
......@@ -103,12 +108,125 @@ sub conn {
}
sub scratch_dir {
my $self = shift;
my $scratch = $self->config("scratch_dir", $< > 0 ?
catdir(cwd(), "libvirt-tck") :
catdir(rootdir(), "var", "cache", "libvirt-tck"));
mkpath($scratch) unless -e $scratch;
return $scratch;
}
sub get_scratch {
my $self = shift;
my $source = shift;
my $bucket = shift;
my $name = shift;
my $scratch = $self->scratch_dir;
my $dir = catdir($scratch, $bucket);
mkpath($dir) unless -e $dir;
my $target = catfile($dir, $name);
return $target if -e $target;
if ($source =~ m,^/,) {
$self->copy_scratch($source, $target);
} else {
$self->download_scratch($source, $target);
}
return $target;
}
sub download_scratch {
my $self = shift;
my $source = shift;
my $target = shift;
my $ua = LWP::UserAgent->new;
$ua->timeout(10);
$ua->env_proxy;
my $response = $ua->get($source);
if ($response->is_success) {
open TGT, ">$target" or die "cannot create $target: $!";
print TGT $response->content or die "cannot write $target: $!";
#print TGT $response->decoded_content or die "cannot write $target: $!";
close TGT or die "cannot save $target: $!";
} else {
die "cannot download $source: " . $response->status_line;
}
}
sub copy_scratch {
my $self = shift;
my $source = shift;
my $target = shift;
copy ($source, $target) or die "cannot copy $source to $target: $!";
}
sub get_kernel {
my $self = shift;
my $arch = shift;
my $ostype = shift;
my $kernels = $self->config("kernels", []);
foreach my $entry (@$kernels) {
next unless $arch eq $entry->{arch};
next unless grep { $_ eq $ostype } @{$entry->{ostype}};
my $kernel = $entry->{kernel};
my $initrd = $entry->{initrd};
my $kfile = $self->get_scratch($kernel, "kernel", "$arch-$ostype-vmlinuz");
my $ifile = $self->get_scratch($initrd, "kernel", "$arch-$ostype-initrd");
return ($kfile, $ifile);
}
die "cannot find a kernel with arch '$arch' and ostype '$ostype'";
}
sub get_disk {
my $self = shift;
my $name = shift;
my $size = shift;
my $scratch = $self->scratch_dir;
my $bucket = catdir($scratch, "disks");
mkpath($bucket) unless -e $bucket;
my $target = catfile($bucket, $name);
open DISK, ">$target" or die "cannot create $target: $1";
truncate DISK, ($size * 1024 * 1024);
close DISK or die "cannot save $target: $!";
return $target;
}
sub generic_domain {
my $self = shift;
my $b = $self->bare_domain(@_);
my $disk = $self->config("disk");
my $disk = $self->get_disk("generic.img", 100);
$b->disk(src =>$disk, dst => "hda", type => "file");
return $b;
......@@ -123,8 +241,8 @@ sub bare_domain {
name => $name);
$b->memory(64 * 1024);
my $kernel = $self->config("kernel");
my $initrd = $self->config("initrd");
# XXX fix arch/type basedon capabilities
my ($kernel, $initrd) = $self->get_kernel("i686", "hvm");
$b->boot_kernel($kernel, $initrd);
return $b;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment