1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
|
# -*- perl -*-
#
# Copyright (C) 2009 Red Hat, Inc.
# Copyright (C) 2009 Daniel P. Berrange
#
# 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
storage/200-clone-vol-fs.t - Clone a volume with a directory pool
=head1 DESCRIPTION
The test case validates that it is possible to clone volumes
within a directory pool. It starts by creating a raw volume
with a magic pattern. It then clones this to another format,
and then clones back to raw. The source and destinations are
checksummed and validated
=cut
use strict;
use warnings;
use Test::More tests => 61;
use Sys::Virt::TCK;
use Test::Exception;
use File::stat;
use Digest;
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 $xml = $tck->generic_pool("dir")->as_xml;
diag "Defining transient storage pool";
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");
diag "Preparing initial source volume with some special data";
my $volsrcxml = $tck->generic_volume("tcksrc", "raw", 1024*1024*50)->as_xml;
my ($vol, $path, $st);
ok_volume(sub { $vol = $pool->create_volume($volsrcxml) }, "create source raw volume");
$path = xpath($vol, "string(/volume/target/path)");
open FILE, ">$path"
or die "cannot create $path: $!";
for (my $i = 0 ; $i < 50 ; $i++) {
for (my $j = 0 ; $j < 1024 ; $j++) {
# 64 bytes
my $str = join('', ('a'..'z', 'A'..'Z', '0'..'9', '.',"\n"));
# 1 kb
my $data = join('', $str, $str, $str, $str,
$str, $str, $str, $str,
$str, $str, $str, $str,
$str, $str, $str, $str);
print FILE $data;
# Hack for VPC, add an extra 4k of data to round
# out 50 MB size upto a size that is mappable to
# VPC's CHS geometry without needing rounding
if ($i == 0 && $j == 0) {
print FILE $data;
print FILE $data;
print FILE $data;
print FILE $data;
}
}
}
close FILE or die "cannot save $path: $!";
$st = stat($path);
ok($st, "path $path exists");
is($st->size, ((1024*1024*50)+4096), "size is 50M");
my $srcdigest = &digest($path);
diag "Now testing cloning of various formats";
my @formats = qw(raw cow qcow qcow2 vmdk vpc);
foreach my $format (@formats) {
diag "Cloning source volume to $format format";
my $volclonexml = $tck->generic_volume("tck$format", $format, ((1024*1024*50)+4096))->as_xml;
my $clone;
ok_volume(sub { $clone = $pool->clone_volume($volclonexml, $vol) }, "clone to $format volume");
$path = xpath($clone, "string(/volume/target/path)");
$st = stat($path);
ok($st, "path $path exists");
ok($st->size >= ((1024*1024*50)+4096), "size is at least 50M");
diag "Cloning cloned volume back to raw format";
my $voldstxml = $tck->generic_volume("tckdst", "raw", ((1024*1024*50)+4096))->as_xml;
my $result;
ok_volume(sub { $result = $pool->clone_volume($voldstxml, $clone) }, "clone back to raw volume");
$path = xpath($result, "string(/volume/target/path)");
$st = stat($path);
ok($st, "path $path exists");
is($st->size, ((1024*1024*50)+4096), "size is 50M");
diag "Comparing data between source & result volume";
my $dstdigest = &digest($path);
is($srcdigest, $dstdigest, "digests match");
lives_ok(sub { $clone->delete(0) }, "deleted clone volume");
lives_ok(sub { $result->delete(0) }, "deleted result volume");
}
lives_ok(sub { $vol->delete(0) }, "deleted source vol");
sub digest {
my $file = shift;
open FILE, "<$file" or die "cannot open $file: $!";
my $digest = Digest->new("MD5");
$digest->addfile(\*FILE);
close FILE;
return $digest->hexdigest;
}
|