[libvirt] [PATCH TCK] Add a test for QCow2 files with a backing store

This test case verifies that it is possible to run QEMU guest from a qcow2 file with a backing store pointing to a physical disk. This verifies backing store handling with SELinux, UID/GID changing code and CGroups ACLs * scripts/qemu/150-disk-backingstore.t: New test case * lib/Sys/Virt/TCK/StorageVolBuilder.pm: Allow volume backing store to be set in XML --- lib/Sys/Virt/TCK/StorageVolBuilder.pm | 14 +++++ scripts/qemu/150-disk-backingstore.t | 97 +++++++++++++++++++++++++++++++++ 2 files changed, 111 insertions(+), 0 deletions(-) create mode 100644 scripts/qemu/150-disk-backingstore.t diff --git a/lib/Sys/Virt/TCK/StorageVolBuilder.pm b/lib/Sys/Virt/TCK/StorageVolBuilder.pm index 00680ed..2772d51 100644 --- a/lib/Sys/Virt/TCK/StorageVolBuilder.pm +++ b/lib/Sys/Virt/TCK/StorageVolBuilder.pm @@ -68,6 +68,14 @@ sub secret { return $self; } +sub backing_store { + my $self = shift; + + $self->{backingStore} = shift; + + return $self; +} + sub as_xml { my $self = shift; @@ -95,6 +103,12 @@ sub as_xml { $w->endTag("target"); } + if ($self->{backingStore}) { + $w->startTag("backingStore"); + $w->dataElement("path", $self->{backingStore}); + $w->endTag("backingStore"); + } + $w->endTag("volume"); return $data; diff --git a/scripts/qemu/150-disk-backingstore.t b/scripts/qemu/150-disk-backingstore.t new file mode 100644 index 0000000..62d8faf --- /dev/null +++ b/scripts/qemu/150-disk-backingstore.t @@ -0,0 +1,97 @@ +# -*- perl -*- +# +# Copyright (C) 2009-2010 Red Hat, Inc. +# +# This program is free software; You can redistribute it and/or modify +# it under the GNU General Public License as published by the Free +# Software Foundation; either version 2, or (at your option) any +# later version +# +# The file "LICENSE" distributed along with this file provides full +# details of the terms and conditions +# + +=pod + +=head1 NAME + +qemu/150-disk-backingstore.t - qcow2 image with a backing store on physical disk + +=head1 DESCRIPTION + +The test case validates that a guest can be booted from a +qcow2 file with a backing store pointing to a physical disk. +This verifies that SELinux labelling, uid/gid changes and +cgroups ACL setup is working correctly with backing stores + +=cut + +use strict; +use warnings; + +use Test::More tests => 8; + +use Sys::Virt::TCK; +use Test::Exception; +use File::Spec::Functions qw(catfile); + +my $tck = Sys::Virt::TCK->new(); +my $conn = eval { $tck->setup(); }; +BAIL_OUT "failed to setup test harness: $@" if $@; +END { $tck->cleanup if $tck; } + +my $dev = $tck->get_host_block_device(); + +SKIP: { + skip "no block device available", 8 unless $dev; + skip "Only relevant to QEMU driver", 8 unless $conn->get_type() eq "QEMU"; + + ok(-b $dev, "$dev is a block device"); + + my $dir = $tck->bucket_dir("150-disk-backingstore"); + my $disk = catfile($dir, "demo.qcow2"); + + my $poolXML = Sys::Virt::TCK::StoragePoolBuilder->new() + ->source_dir($dir)->target($dir)->as_xml(); + + my $pool; + + diag "Creating pool $poolXML"; + lives_ok(sub { $pool = $conn->create_storage_pool($poolXML) }, "pool created"); + + + my $volXML = Sys::Virt::TCK::StorageVolBuilder->new(name => "demo.qcow2") + ->capacity(1024*1024*1024) + ->format("qcow2") + ->backing_store($dev) + ->as_xml(); + + my $vol; + + diag "Creating volume $volXML"; + lives_ok(sub { $vol = $pool->create_volume($volXML) }, "volume created"); + + my $xml = $tck->generic_domain("tck") + ->disk(format => ["qemu", "qcow2"], + type => "file", + src => $disk, + dst => "hdb") + ->as_xml; + + diag "Creating a transient guest with config $xml"; + my $dom; + ok_domain(sub { $dom = $conn->create_domain($xml) }, "started transient domain config"); + + ok($dom->get_id() > 0, "running domain has an ID > 0"); + + diag "Trying another domain lookup by name"; + my $dom1; + ok_domain(sub { $dom1 = $conn->get_domain_by_name("tck") }, "the running domain object"); + ok($dom1->get_id() > 0, "running domain has an ID > 0"); + + + diag "Destroying the running domain"; + $dom->destroy(); + + ok_error(sub { $conn->get_domain_by_name("tck") }, "NO_DOMAIN error raised from missing domain", 42); +} -- 1.6.5.2

On 04/28/2010 09:31 AM, Daniel P. Berrange wrote:
diff --git a/scripts/qemu/150-disk-backingstore.t b/scripts/qemu/150-disk-backingstore.t new file mode 100644 index 0000000..62d8faf --- /dev/null +++ b/scripts/qemu/150-disk-backingstore.t @@ -0,0 +1,97 @@ +# -*- perl -*- +# +# Copyright (C) 2009-2010 Red Hat, Inc.
Just 2010 is sufficient.
+ +The test case validates that a guest can be booted from a +qcow2 file with a backing store pointing to a physical disk. +This verifies that SELinux labelling, uid/gid changes and
s/labelling/labeling/
+ diag "Creating pool $poolXML"; + lives_ok(sub { $pool = $conn->create_storage_pool($poolXML) }, "pool created"); + + + my $volXML = Sys::Virt::TCK::StorageVolBuilder->new(name => "demo.qcow2") + ->capacity(1024*1024*1024) + ->format("qcow2") + ->backing_store($dev) + ->as_xml();
That 1GB capacity at odds with the statement in conf/default.cfg that block devices need only be 512 MB. Can we get by with a smaller qcow image here, or does the config file minimum size limit need to be raised? Also, it would still be nice to follow through with the idea that host_block_devices in the config file list both device name and size, to avoid unintentionally trashing the wrong device. -- Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org

On Wed, Apr 28, 2010 at 09:42:49AM -0600, Eric Blake wrote:
On 04/28/2010 09:31 AM, Daniel P. Berrange wrote:
diff --git a/scripts/qemu/150-disk-backingstore.t b/scripts/qemu/150-disk-backingstore.t new file mode 100644 index 0000000..62d8faf --- /dev/null +++ b/scripts/qemu/150-disk-backingstore.t @@ -0,0 +1,97 @@ +# -*- perl -*- +# +# Copyright (C) 2009-2010 Red Hat, Inc.
Just 2010 is sufficient.
This was a 90% code derivative from another test case so I left the original copyright date.
+ +The test case validates that a guest can be booted from a +qcow2 file with a backing store pointing to a physical disk. +This verifies that SELinux labelling, uid/gid changes and
s/labelling/labeling/
+ diag "Creating pool $poolXML"; + lives_ok(sub { $pool = $conn->create_storage_pool($poolXML) }, "pool created"); + + + my $volXML = Sys::Virt::TCK::StorageVolBuilder->new(name => "demo.qcow2") + ->capacity(1024*1024*1024) + ->format("qcow2") + ->backing_store($dev) + ->as_xml();
That 1GB capacity at odds with the statement in conf/default.cfg that block devices need only be 512 MB. Can we get by with a smaller qcow image here, or does the config file minimum size limit need to be raised? Also, it would still be nice to follow through with the idea that host_block_devices in the config file list both device name and size, to avoid unintentionally trashing the wrong device.
The 512 MB in the config refers to actual disk usage. The 1 GB here is the logical qcow2 image size. The actual usage for this will be a few 10's of KB only, since qcow2 is a grow-on-demand format. Regards, Daniel -- |: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://deltacloud.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|
participants (2)
-
Daniel P. Berrange
-
Eric Blake