[libvirt] [PATCH v2][TCK] add test case for block job lifecycle testing

Guannan Ren gren at redhat.com
Wed Jul 25 03:34:38 UTC 2012


On 07/24/2012 06:32 PM, Kyla Zhang wrote:
> From: Xiaoqiang Hu <xhu at redhat.com>
>
> v2: Add skip block for qemu only and 120s timeout for test
>
> v1: Add tests for block job lifecyle and the test flow is as follows:
> create 50M qed img with qed backing img->
> block pull->abort block job->resume block pull->set block job speed->
> wait to finish
> ---
>   scripts/qemu/300-blockjob-lifecycle.t |  142 +++++++++++++++++++++++++++++++++
>   1 files changed, 142 insertions(+), 0 deletions(-)
>   create mode 100644 scripts/qemu/300-blockjob-lifecycle.t
>
> diff --git a/scripts/qemu/300-blockjob-lifecycle.t b/scripts/qemu/300-blockjob-lifecycle.t
> new file mode 100644
> index 0000000..7840d43
> --- /dev/null
> +++ b/scripts/qemu/300-blockjob-lifecycle.t
> @@ -0,0 +1,142 @@
> +# -*- perl -*-
> +#
> +# Copyright (C) 2011-2012 Red Hat, Inc.
> +# Copyright (C) 2011 Xiaoqiang Hu <xhu redhat com>
> +#
> +# 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/300-blockjob-lifecycle.t - verify the lifecycle of block job:
> +block pull, set block job speed, get block job info and abort block job
> +
> +=head1 DESCRIPTION
> +
> +The test case validates that it is possible 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;
> +}
> +
> +SKIP:{
> +    skip "Only relevant to QEMU driver", 16 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 qed 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, $timeout);
> +    # 1MB/S
> +    $bandwidth = 1;
> +    $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"."MB/S");
> +
> +    $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"."MB/S");
> +
> +    # set block job bandwidth to 2MB/S
> +    $bandwidth = 2;
> +    $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"."MB/S");
> +
> +    # wait for the end of block pull and timeout is 120s
> +    $timeout = 120;
> +    while($jobinfo->{cur} < $jobinfo->{end} && $jobinfo->{type} == 1 && $timeout > 0) {
> +        sleep(1);
> +        $jobinfo = $dom->get_block_job_info($pathmain, $flags);
> +        $timeout--;
> +    }
> +
> +    diag "block pull is not finished in 120S" if $jobinfo->{type} == 1 && $timeout == 0;
> +    ok($jobinfo->{type} == 0, "block pull is finished");
> +}
> +# end

     It's better to check if underlying qemu support the 
"block_job_cancel" qmp command or not
     I encounter the error like the following on fedora 17
         libvirt error code: 67, message: unsupported configuration: 
block jobs not supported with this QEMU binary
     error on fedora 16
        libvirt error code: 1, message: internal error Process exited 
while reading console log output: Supported machines are:

        pc         Standard PC (alias of pc-0.14)
        pc-0.14    Standard PC (default)
        fedora-13  Standard PC
        pc-0.13    Standard PC
        pc-0.12    Standard PC
        pc-0.11    Standard PC, qemu 0.11
        pc-0.10    Standard PC, qemu 0.10
        isapc      ISA-only PC

     see if we can avoid these errors.

     Guannan Ren






More information about the libvir-list mailing list