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 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
|
# -*- 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/100-create-vol-fs.t - Create volume with a filesystem pool
=head1 DESCRIPTION
The test case validates that it is possible to create volumes
with a filesystem pool.
=cut
use strict;
use warnings;
use Test::More tests => 33;
use Sys::Virt::TCK;
use Test::Exception;
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;
}
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");
my $volsparsexml = $tck->generic_volume("tck1", "raw", 1024*1024*50)->allocation(0)->as_xml;
my $volallocxml = $tck->generic_volume("tck2", "raw", 1024*1024*50)->allocation(1024*1024*50)->as_xml;
my $volcowxml = $tck->generic_volume("tck3", "cow", 1024*1024*50)->as_xml;
my $volqcow1xml = $tck->generic_volume("tck4", "qcow", 1024*1024*50)->as_xml;
my $volqcow2xml = $tck->generic_volume("tck5", "qcow2", 1024*1024*50)->as_xml;
my $volvmdkxml = $tck->generic_volume("tck6", "vmdk", 1024*1024*50)->as_xml;
my $volvpcxml = $tck->generic_volume("tck7", "vpc", 1024*1024*50)->as_xml;
my ($vol, $path, $st);
ok_volume(sub { $vol = $pool->create_volume($volsparsexml) }, "create sparse raw volume");
$path = xpath($vol, "string(/volume/target/path)");
$st = stat($path);
ok($st, "path $path exists");
is($st->size, 1024*1024*50, "size is 50M");
# In theory 0 blocks are allocated, but most FS have a couple of blocks
# overhead for a sparse file
ok($st->blocks < 10, "not many blocks allocated");
lives_ok(sub { $vol->delete(0) }, "deleted volume");
ok_volume { $vol = $pool->create_volume($volallocxml) } "create fully allocated raw volume";
$path = xpath($vol, "string(/volume/target/path)");
$st = stat($path);
ok($st, "path $path exists");
is($st->size, 1024*1024*50, "size is 50M");
# In theory exact number blocks are allocated, but most FS have a couple of blocks
# overhead for a file
ok($st->blocks >= (1024*1024*50/512), "alot of blocks allocated");
lives_ok(sub { $vol->delete(0) }, "deleted volume");
ok_volume { $vol = $pool->create_volume($volcowxml) } "create cow volume";
$path = xpath($vol, "string(/volume/target/path)");
$st = stat($path);
ok($st, "path $path exists");
# Don't know exactly how large a cow empty file is, but it
# should be quite small :-)
ok($st->size < 1024*1024, "basic cow header is allocated");
lives_ok(sub { $vol->delete(0) }, "deleted volume");
ok_volume(sub { $vol = $pool->create_volume($volqcow1xml) }, "create qcow volume");
$path = xpath($vol, "string(/volume/target/path)");
$st = stat($path);
ok($st, "path $path exists");
# Don't know exactly how large a qcow1 empty file is, but it
# should be quite small :-)
ok($st->size < 1024*1024, "basic qcow1 header is allocated");
lives_ok(sub { $vol->delete(0) }, "deleted volume");
ok_volume(sub { $vol = $pool->create_volume($volqcow2xml) }, "create qcow volume");
$path = xpath($vol, "string(/volume/target/path)");
$st = stat($path);
ok($st, "path $path exists");
# Don't know exactly how large a qcow2 empty file is, but it
# should be quite small :-)
ok($st->size < 1024*1024, "basic qcow2 header is allocated");
lives_ok(sub { $vol->delete(0) }, "deleted volume");
ok_volume(sub { $vol = $pool->create_volume($volvmdkxml) }, "create qcow volume");
$path = xpath($vol, "string(/volume/target/path)");
$st = stat($path);
ok($st, "path $path exists");
# Don't know exactly how large a vmdk empty file is, but it
# should be quite small :-)
ok($st->size < 1024*1024, "basic vmdk header is allocated");
lives_ok(sub { $vol->delete(0) }, "deleted volume");
ok_volume(sub { $vol = $pool->create_volume($volvpcxml) }, "create qcow volume");
$path = xpath($vol, "string(/volume/target/path)");
$st = stat($path);
ok($st, "path $path exists");
# Don't know exactly how large a vpc empty file is, but it
# should be quite small :-)
ok($st->size < 1024*1024, "basic vpc header is allocated");
lives_ok(sub { $vol->delete(0) }, "deleted volume");
|