Debian Codegraph @

t/400-storage-pools.t

raw
1 # -*- perl -*-
2
3 use strict;
4 use warnings;
5
6 use Test::More tests => 32;
7
8 BEGIN {
9 use_ok('Sys::Virt');
10 }
11
12
13 my $conn = Sys::Virt->new(uri => "test:///default");
14
15 isa_ok($conn, "Sys::Virt");
16
17
18 my $nid = $conn->num_of_storage_pools();
19 is($nid, 1, "1 active storage_pool");
20
21 my @poolnames = $conn->list_storage_pool_names($nid);
22 is_deeply(\@poolnames, ["default-pool"], "storage_pool names");
23
24 my @pools = $conn->list_all_storage_pools();
25 isa_ok($pools[0], "Sys::Virt::StoragePool");
26 is(int(@pools), 1, "1 active pool");
27 is($pools[0]->get_name, "default-pool", "pool name matches");
28
29 my $pool = $conn->get_storage_pool_by_name($poolnames[0]);
30 isa_ok($pool, "Sys::Virt::StoragePool");
31
32 is($pool->get_name, "default-pool", "name");
33 ok($pool->is_persistent(), "pool is persistent");
34 ok($pool->is_active(), "pool is active");
35
36
37 # Lookup again via UUID to verify we get the same
38 my $uuid = $pool->get_uuid();
39
40 my $pool2 = $conn->get_storage_pool_by_uuid($uuid);
41 isa_ok($pool2, "Sys::Virt::StoragePool");
42 is($pool2->get_name, "default-pool", "name");
43
44 my $uuidstr = $pool->get_uuid_string();
45
46 my $pool3 = $conn->get_storage_pool_by_uuid($uuidstr);
47 isa_ok($pool3, "Sys::Virt::StoragePool");
48 is($pool3->get_name, "default-pool", "name");
49
50
51 @pools = $conn->list_storage_pools();
52 is($#pools, 0, "one storage_pool");
53 isa_ok($pools[0], "Sys::Virt::StoragePool");
54
55
56 my $nname = $conn->num_of_defined_storage_pools();
57 is($nname, 0, "0 defined storage_pool");
58
59 my $xml = "<pool type='dir'>
60 <name>wibble</name>
61 <uuid>12341234-5678-5678-5678-123412341234</uuid>
62 <target>
63 <path>/wibble</path>
64 </target>
65 </pool>";
66
67 $pool = $conn->define_storage_pool($xml);
68
69 $nname = $conn->num_of_defined_storage_pools();
70 is($nname, 1, "1 defined storage_pool");
71 ok($pool->is_persistent(), "pool is persistent");
72 ok(!$pool->is_active(), "pool is not active");
73
74 my @names = $conn->list_defined_storage_pool_names($nname);
75 is_deeply(\@names, ["wibble"], "names");
76
77 @pools = $conn->list_defined_storage_pools();
78 is($#pools, 0, "1 defined storage_pool");
79 isa_ok($pools[0], "Sys::Virt::StoragePool");
80
81 $pool = $conn->get_storage_pool_by_name("wibble");
82 isa_ok($pool, "Sys::Virt::StoragePool");
83
84
85 $pool->create();
86 ok($pool->is_active(), "pool is active");
87
88 my $nids = $conn->num_of_storage_pools();
89 is($nids, 2, "2 active storage_pools");
90
91 my @ids = sort { $a cmp $b } $conn->list_storage_pool_names($nids);
92 is_deeply(\@ids, ["default-pool", "wibble"], "storage_pool names");
93
94 $pool->destroy();
95
96
97 $nids = $conn->num_of_storage_pools();
98 is($nids, 1, "1 active storage_pools");
99
100 @ids = $conn->list_storage_pool_names($nids);
101 is_deeply(\@ids, ["default-pool"], "storage_pool names");
102
103 $pool = $conn->get_storage_pool_by_name("wibble");
104
105 $pool->undefine();
106
107
108 $nname = $conn->num_of_defined_storage_pools();
109 is($nname, 0, "0 defined storage_pool");
110
111 @names = $conn->list_defined_storage_pool_names($nname);
112 is_deeply(\@names, [], "names");
113