Re: [PATCH][TCK] add test case for block job lifecycle testing

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Dec 27, 2011 at 05:08:09PM +0800, xhu wrote:
> diff --git a/scripts/domain/400-blockjob-lifecycle.t b/scripts/domain/400-blockjob-lifecycle.t
> new file mode 100644
> index 0000000..f4d0c39
> --- /dev/null
> +++ b/scripts/domain/400-blockjob-lifecycle.t
> @@ -0,0 +1,136 @@
> +# -*- perl -*-
> +#
> +# Copyright (C) 2011-2012 Red Hat, Inc.
> +# Copyright (C) 2011 Xiaoqiang Hu <xhu@xxxxxxxxxx>
> +#
> +# 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
> +
> +domain/400-block-pull-abort-info.t - verify the lifecycle of block job:
> +block pull, set block job speed, get block job info and abort block job

The block job pull functionality is very QEMU specific, so it
would be preferable to have this as

   scripts/qemu/400-block-pull-abort-inbfo.t


> +
> +=head1 DESCRIPTION
> +
> +The test case validates that it is fine to block pull, set block job speed
> +, get block job info and abort block job for domain using qed img with
> +qed backing img
> +
> +=cut
> +
> +use strict;
> +use warnings;
> +
> +use Test::More tests => 16;
> +
> +use Sys::Virt::TCK;
> +use Test::Exception;
> +use File::Spec::Functions qw(catfile);
> +use File::stat;
> +
> +my $tck = Sys::Virt::TCK->new();
> +my $conn = eval { $tck->setup(); };
> +BAIL_OUT "failed to setup test harness: $@" if $@;
> +END {
> +    $tck->cleanup if $tck;
> +}

Since this script is only expected to work on QEMU, we need
to add a giant SKIP block around everything following this
line.eg

SKIP: {
    skip "Only relevant to QEMU driver", 8 unless $conn->get_type() eq "QEMU";



> +
> +my $xml = $tck->generic_pool("dir")
> +    ->mode("0755")->as_xml;
> +
> +diag "Defining transient storage pool $xml";
> +my $pool;
> +
> +ok_pool(sub { $pool = $conn->define_storage_pool($xml) }, "define transient storage pool");
> +lives_ok(sub { $pool->build(0) }, "built storage pool");
> +lives_ok(sub { $pool->create }, "started storage pool");
> +
> +my $volbackxml = $tck->generic_volume("tck-back", "qed", 1024*1024*50)->allocation(0)->as_xml;
> +
> +my ($volback, $pathback);
> +diag "back $volbackxml";
> +ok_volume(sub { $volback = $pool->create_volume($volbackxml) }, "create raw backing file volume");
> +
> +my $st;
> +$pathback = xpath($volback, "string(/volume/target/path)");
> +$st = stat($pathback);
> +
> +ok($st, "path $pathback exists");
> +
> +ok($st->size < 1024*1024, "size is < 1M");
> +
> +my $volmainxml = $tck->generic_volume("tck-main", "qed", 1024*1024*50)
> +    ->backing_file($pathback)
> +    ->backing_format("qed")
> +    ->allocation(0)->as_xml;
> +
> +my ($volmain, $pathmain);
> +diag "main $volmainxml";
> +ok_volume(sub { $volmain = $pool->create_volume($volmainxml) }, "create qed backing file volume");
> +
> +$pathmain = xpath($volmain, "string(/volume/target/path)");
> +$st = stat($pathmain);
> +
> +ok($st, "path $pathmain exists");
> +
> +ok($st->size < 1024*1024, "size is < 1M");
> +
> +# define the guest at a qed image
> +# and the backing store in this qed image.
> +$xml = $tck->generic_domain("tck")
> +    ->disk(format => { name => "qemu", type => "qed" },
> +           type => "file",
> +           src => $pathmain,
> +           dst => "vdb")
> +    ->as_xml;
> +
> +diag "Defining an inactive domain config $xml";
> +my $dom;
> +ok_domain(sub { $dom = $conn->define_domain($xml) }, "defined persistent domain config");
> +
> +diag "Starting inactive domain config";
> +$dom->create;
> +ok($dom->get_id() > 0, "running domain has an ID > 0");
> +
> +# start to block pull and bandwidth is 1MB/S
> +my ($bandwidth, $flags, $jobinfo);
> +# 1024 KB/S - 1MB/S
> +$bandwidth = 1*1024;
> +$flags=0;
> +$dom->block_pull($pathmain, $bandwidth, $flags);
> +# $jobinfo is a hash reference summarising the execution state of the block job.
> +# and it has four keys:cur, end, bandwidth, type
> +$jobinfo = $dom->get_block_job_info($pathmain, $flags);
> +ok($jobinfo->{bandwidth} == $bandwidth, "start to block pull and block job bandwidth is $bandwidth");
> +
> +$dom->abort_block_job($pathmain, $flags);
> +$jobinfo = $dom->get_block_job_info($pathmain, $flags);
> +ok($jobinfo->{type} == 0, "abort block job");
> +
> +$dom->block_pull($pathmain, $bandwidth, $flags);
> +$jobinfo = $dom->get_block_job_info($pathmain, $flags);
> +ok($jobinfo->{bandwidth} == $bandwidth, "continue to block pull and block job bandwidth is $bandwidth");
> +
> +# set block job bandwidth to 2MB/S
> +$bandwidth = 2*1024;
> +$dom->set_block_job_speed($pathmain, $bandwidth, $flags);
> +$jobinfo = $dom->get_block_job_info($pathmain, $flags);
> +ok($jobinfo->{bandwidth} == $bandwidth, "block job bandwidth is set to $bandwidth");
> +
> +# wait for the end of block pull
> +while($jobinfo->{cur} < $jobinfo->{end} && $jobinfo->{type} == 1) {
> +    $jobinfo = $dom->get_block_job_info($pathmain, $flags);
> +    sleep 1
> +}

To avoid an infinite loop if something goes wrong in QEMU, it is
probably worth adding a finite timeout here. eg, if we have done
more than 120 iterations (2 minutes), then abort the test.

> +
> +ok($jobinfo->{type} == 0, "block pull is finished");
> +# end


}   # End of SKIP:



Overall this looks good.

Regards,
Daniel
-- 
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]