File: 400-storage-pools.t

package info (click to toggle)
libsys-virt-perl 11.6.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,088 kB
  • sloc: perl: 2,187; sh: 12; makefile: 3
file content (113 lines) | stat: -rw-r--r-- 2,909 bytes parent folder | download | duplicates (5)
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
# -*- perl -*-

use strict;
use warnings;

use Test::More tests => 32;

BEGIN {
        use_ok('Sys::Virt');
}


my $conn = Sys::Virt->new(uri => "test:///default");

isa_ok($conn, "Sys::Virt");


my $nid = $conn->num_of_storage_pools();
is($nid, 1, "1 active storage_pool");

my @poolnames = $conn->list_storage_pool_names($nid);
is_deeply(\@poolnames, ["default-pool"], "storage_pool names");

my @pools = $conn->list_all_storage_pools();
isa_ok($pools[0], "Sys::Virt::StoragePool");
is(int(@pools), 1, "1 active pool");
is($pools[0]->get_name, "default-pool", "pool name matches");

my $pool = $conn->get_storage_pool_by_name($poolnames[0]);
isa_ok($pool, "Sys::Virt::StoragePool");

is($pool->get_name, "default-pool", "name");
ok($pool->is_persistent(), "pool is persistent");
ok($pool->is_active(), "pool is active");


# Lookup again via UUID to verify we get the same
my $uuid = $pool->get_uuid();

my $pool2 = $conn->get_storage_pool_by_uuid($uuid);
isa_ok($pool2, "Sys::Virt::StoragePool");
is($pool2->get_name, "default-pool", "name");

my $uuidstr = $pool->get_uuid_string();

my $pool3 = $conn->get_storage_pool_by_uuid($uuidstr);
isa_ok($pool3, "Sys::Virt::StoragePool");
is($pool3->get_name, "default-pool", "name");


@pools = $conn->list_storage_pools();
is($#pools, 0, "one storage_pool");
isa_ok($pools[0], "Sys::Virt::StoragePool");


my $nname = $conn->num_of_defined_storage_pools();
is($nname, 0, "0 defined storage_pool");

my $xml = "<pool type='dir'>
  <name>wibble</name>
  <uuid>12341234-5678-5678-5678-123412341234</uuid>
  <target>
    <path>/wibble</path>
  </target>
</pool>";

$pool = $conn->define_storage_pool($xml);

$nname = $conn->num_of_defined_storage_pools();
is($nname, 1, "1 defined storage_pool");
ok($pool->is_persistent(), "pool is persistent");
ok(!$pool->is_active(), "pool is not active");

my @names = $conn->list_defined_storage_pool_names($nname);
is_deeply(\@names, ["wibble"], "names");

@pools = $conn->list_defined_storage_pools();
is($#pools, 0, "1 defined storage_pool");
isa_ok($pools[0], "Sys::Virt::StoragePool");

$pool = $conn->get_storage_pool_by_name("wibble");
isa_ok($pool, "Sys::Virt::StoragePool");


$pool->create();
ok($pool->is_active(), "pool is active");

my $nids = $conn->num_of_storage_pools();
is($nids, 2, "2 active storage_pools");

my @ids = sort { $a cmp $b } $conn->list_storage_pool_names($nids);
is_deeply(\@ids, ["default-pool", "wibble"], "storage_pool names");

$pool->destroy();


$nids = $conn->num_of_storage_pools();
is($nids, 1, "1 active storage_pools");

@ids = $conn->list_storage_pool_names($nids);
is_deeply(\@ids, ["default-pool"], "storage_pool names");

$pool = $conn->get_storage_pool_by_name("wibble");

$pool->undefine();


$nname = $conn->num_of_defined_storage_pools();
is($nname, 0, "0 defined storage_pool");

@names = $conn->list_defined_storage_pool_names($nname);
is_deeply(\@names, [], "names");