Debian Codegraph @

t/200-domains.t

raw
1 # -*- perl -*-
2
3 use strict;
4 use warnings;
5
6 use Test::More tests => 59;
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_domains();
19 is($nid, 1, "1 active domain");
20
21 my @domids = $conn->list_domain_ids($nid);
22 is_deeply(\@domids, [1], "domain ids");
23
24 my @doms = $conn->list_all_domains();
25 isa_ok($doms[0], "Sys::Virt::Domain");
26 is(int(@doms), 1, "1 active domain");
27 is($doms[0]->get_id, "1", "domain id matches");
28
29 my $dom = $conn->get_domain_by_id($domids[0]);
30 isa_ok($dom, "Sys::Virt::Domain");
31
32 is($dom->get_name, "test", "name");
33 is($dom->get_id, "1", "id");
34 ok($dom->is_persistent(), "domain is persistent");
35 ok($dom->is_active(), "domain is active");
36 ok(!$dom->is_updated(), "domain is not updated");
37
38 # Lookup again via UUID to verify we get the same
39 my $uuid = $dom->get_uuid();
40
41 my $dom2 = $conn->get_domain_by_uuid($uuid);
42 isa_ok($dom2, "Sys::Virt::Domain");
43 is($dom2->get_name, "test", "name");
44 is($dom2->get_id, "1", "id");
45
46 my $uuidstr = $dom->get_uuid_string();
47
48 my $dom3 = $conn->get_domain_by_uuid($uuidstr);
49 isa_ok($dom3, "Sys::Virt::Domain");
50 is($dom3->get_name, "test", "name");
51 is($dom3->get_id, "1", "id");
52
53 @doms = $conn->list_domains();
54 is($#doms, 0, "one domain");
55 isa_ok($doms[0], "Sys::Virt::Domain");
56
57
58 my $nname = $conn->num_of_defined_domains();
59 is($nname, 0, "0 defined domain");
60
61 my $xml = "<domain type='test'>
62 <name>wibble</name>
63 <uuid>12341234-5678-5678-5678-123412341234</uuid>
64 <memory>10241024</memory>
65 <currentMemory>1024120</currentMemory>
66 <vcpu>4</vcpu>
67 <os>
68 <type>hvm</type>
69 </os>
70 </domain>";
71
72
73 $conn->define_domain($xml);
74
75 $nname = $conn->num_of_defined_domains();
76 is($nname, 1, "1 defined domain");
77
78 my @names = $conn->list_defined_domain_names($nname);
79 is_deeply(\@names, ["wibble"], "names");
80
81 @doms = $conn->list_defined_domains();
82 is($#doms, 0, "1 defined domain");
83 isa_ok($doms[0], "Sys::Virt::Domain");
84
85 $dom = $conn->get_domain_by_name("wibble");
86 isa_ok($dom, "Sys::Virt::Domain");
87
88 ok($dom->is_persistent(), "domain is persistent");
89 ok(!$dom->is_active(), "domain is not active");
90
91
92 $dom->create();
93
94 ok($dom->is_active(), "domain is active");
95
96 my $nids = $conn->num_of_domains();
97 is($nids, 2, "2 active domains");
98
99 my @ids = sort { $a <=> $b } $conn->list_domain_ids($nids);
100 is_deeply(\@ids, [1, 2], "domain ids");
101
102
103 my $info = $dom->get_info();
104 is($info->{memory}, "1024120", "memory");
105 is($info->{maxMem}, "10241024", "max mem");
106 is($info->{nrVirtCpu}, "4", "vcpu");
107 is($info->{state}, &Sys::Virt::Domain::STATE_RUNNING, "state");
108
109 my $params = $dom->get_scheduler_parameters();
110
111 ok(exists $params->{"weight"}, "weight param");
112 is($params->{"weight"}, 50, "weight param is 50");
113
114 $dom->set_scheduler_parameters({weight => 20 });
115
116 $params = $dom->get_scheduler_parameters();
117
118 ok(exists $params->{"weight"}, "weight param");
119 # Temp disabled because test driver is not persisting the set request
120 SKIP: {
121 skip "avoid bug in test driver sched params", 1;
122 is($params->{"weight"}, 20, "weight param is now 20");
123 }
124
125 $dom->destroy();
126
127 #my $free = $conn->get_node_free_memory();
128 #print STDERR $free;
129 my @mem = $conn->get_node_cells_free_memory(0, 8);
130 is($#mem, 1, "2 cells");
131 is($mem[0], 2097152, "mem in cell 1");
132 is($mem[1], 4194304, "mem in cell 2");
133
134
135 $nids = $conn->num_of_domains();
136 is($nids, 1, "1 active domains");
137
138 @ids = $conn->list_domain_ids($nids);
139 is_deeply(\@ids, [1], "domain ids");
140
141 $dom = $conn->get_domain_by_name("wibble");
142
143 $dom->undefine();
144
145
146 $nname = $conn->num_of_defined_domains();
147 is($nname, 0, "0 defined domain");
148
149 @names = $conn->list_defined_domain_names($nname);
150 is_deeply(\@names, [], "names");
151
152
153
154 $conn->create_domain($xml);
155
156 $nname = $conn->num_of_domains();
157 is($nname, 2, "1 domain");
158
159 @ids = sort { $a <=> $b} $conn->list_domain_ids($nname);
160 is_deeply(\@ids, [1, 3], "domain ids");
161
162 @doms = $conn->list_domains();
163 is($#doms, 1, "2 domains");
164 isa_ok($doms[0], "Sys::Virt::Domain");
165 isa_ok($doms[1], "Sys::Virt::Domain");
166
167 $dom = $conn->get_domain_by_name("wibble");
168 isa_ok($dom, "Sys::Virt::Domain");
169
170 ok(!$dom->is_persistent(), "domain is not persistent");
171 ok($dom->is_active(), "domain is active");
172
173 $dom->destroy();
174
175
176 $nname = $conn->num_of_domains();
177 is($nname, 1, "1 domains");
178
179 @ids = $conn->list_domain_ids($nname);
180 is_deeply(\@ids, [1], "ids");
181
182 $nname = $conn->num_of_defined_domains();
183 is($nname, 0, "0 defined domain");
184
185 @names = $conn->list_defined_domain_names($nname);
186 is_deeply(\@names, [], "names");
187