Debian Codegraph @

t/500-storage-vols.t

raw
1 # -*- perl -*-
2
3 use strict;
4 use warnings;
5
6 use Test::More tests => 12;
7
8 BEGIN {
9 use_ok('Sys::Virt');
10 }
11
12
13 my $conn = Sys::Virt->new(uri => "test:///default");
14 isa_ok($conn, "Sys::Virt");
15
16 my $pool = $conn->get_storage_pool_by_name("default-pool");
17 isa_ok($pool, "Sys::Virt::StoragePool");
18
19
20 my $volxml = <<EOF;
21 <volume>
22 <name>demo-vol</name>
23 <capacity unit="G">5</capacity>
24 </volume>
25 EOF
26
27 my $newvol = $pool->create_volume($volxml);
28 isa_ok($newvol, "Sys::Virt::StorageVol");
29
30 my @vols = $pool->list_all_volumes();
31 is(int(@vols), 1, "1 storage vol");
32 is($vols[0]->get_name, "demo-vol", "storage vol name matches");
33
34
35 my $key = $newvol->get_key();
36
37
38 my $vol1 = $conn->get_storage_volume_by_path("/default-pool/demo-vol");
39 isa_ok($vol1, "Sys::Virt::StorageVol");
40 is($vol1->get_key(), $newvol->get_key(), "key matches");
41
42
43 my $vol2 = $conn->get_storage_volume_by_key($key);
44 isa_ok($vol2, "Sys::Virt::StorageVol");
45
46 is($vol2->get_path(), $newvol->get_path(), "path matches");
47
48 my $newpool = $conn->get_storage_pool_by_volume($vol2);
49
50 isa_ok($newpool, "Sys::Virt::StoragePool");
51
52 is($newpool->get_uuid(), $pool->get_uuid(), "Pool UUID matches");