summaryrefslogtreecommitdiff
path: root/novaclient/tests/unit/v2/test_hypervisors.py
diff options
context:
space:
mode:
Diffstat (limited to 'novaclient/tests/unit/v2/test_hypervisors.py')
-rw-r--r--novaclient/tests/unit/v2/test_hypervisors.py178
1 files changed, 178 insertions, 0 deletions
diff --git a/novaclient/tests/unit/v2/test_hypervisors.py b/novaclient/tests/unit/v2/test_hypervisors.py
new file mode 100644
index 0000000..b297c12
--- /dev/null
+++ b/novaclient/tests/unit/v2/test_hypervisors.py
@@ -0,0 +1,178 @@
1# Copyright 2012 OpenStack Foundation
2# All Rights Reserved.
3#
4# Licensed under the Apache License, Version 2.0 (the "License"); you may
5# not use this file except in compliance with the License. You may obtain
6# a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13# License for the specific language governing permissions and limitations
14# under the License.
15
16from novaclient.tests.unit.fixture_data import client
17from novaclient.tests.unit.fixture_data import hypervisors as data
18from novaclient.tests.unit import utils
19
20
21class HypervisorsTest(utils.FixturedTestCase):
22
23 client_fixture_class = client.V1
24 data_fixture_class = data.V1
25
26 def compare_to_expected(self, expected, hyper):
27 for key, value in expected.items():
28 self.assertEqual(getattr(hyper, key), value)
29
30 def test_hypervisor_index(self):
31 expected = [
32 dict(id=1234, hypervisor_hostname='hyper1'),
33 dict(id=5678, hypervisor_hostname='hyper2')]
34
35 result = self.cs.hypervisors.list(False)
36 self.assert_called('GET', '/os-hypervisors')
37
38 for idx, hyper in enumerate(result):
39 self.compare_to_expected(expected[idx], hyper)
40
41 def test_hypervisor_detail(self):
42 expected = [
43 dict(id=1234,
44 service=dict(id=1, host='compute1'),
45 vcpus=4,
46 memory_mb=10 * 1024,
47 local_gb=250,
48 vcpus_used=2,
49 memory_mb_used=5 * 1024,
50 local_gb_used=125,
51 hypervisor_type="xen",
52 hypervisor_version=3,
53 hypervisor_hostname="hyper1",
54 free_ram_mb=5 * 1024,
55 free_disk_gb=125,
56 current_workload=2,
57 running_vms=2,
58 cpu_info='cpu_info',
59 disk_available_least=100),
60 dict(id=2,
61 service=dict(id=2, host="compute2"),
62 vcpus=4,
63 memory_mb=10 * 1024,
64 local_gb=250,
65 vcpus_used=2,
66 memory_mb_used=5 * 1024,
67 local_gb_used=125,
68 hypervisor_type="xen",
69 hypervisor_version=3,
70 hypervisor_hostname="hyper2",
71 free_ram_mb=5 * 1024,
72 free_disk_gb=125,
73 current_workload=2,
74 running_vms=2,
75 cpu_info='cpu_info',
76 disk_available_least=100)]
77
78 result = self.cs.hypervisors.list()
79 self.assert_called('GET', '/os-hypervisors/detail')
80
81 for idx, hyper in enumerate(result):
82 self.compare_to_expected(expected[idx], hyper)
83
84 def test_hypervisor_search(self):
85 expected = [
86 dict(id=1234, hypervisor_hostname='hyper1'),
87 dict(id=5678, hypervisor_hostname='hyper2')]
88
89 result = self.cs.hypervisors.search('hyper')
90 self.assert_called('GET', '/os-hypervisors/hyper/search')
91
92 for idx, hyper in enumerate(result):
93 self.compare_to_expected(expected[idx], hyper)
94
95 def test_hypervisor_servers(self):
96 expected = [
97 dict(id=1234,
98 hypervisor_hostname='hyper1',
99 servers=[
100 dict(name='inst1', uuid='uuid1'),
101 dict(name='inst2', uuid='uuid2')]),
102 dict(id=5678,
103 hypervisor_hostname='hyper2',
104 servers=[
105 dict(name='inst3', uuid='uuid3'),
106 dict(name='inst4', uuid='uuid4')]),
107 ]
108
109 result = self.cs.hypervisors.search('hyper', True)
110 self.assert_called('GET', '/os-hypervisors/hyper/servers')
111
112 for idx, hyper in enumerate(result):
113 self.compare_to_expected(expected[idx], hyper)
114
115 def test_hypervisor_get(self):
116 expected = dict(
117 id=1234,
118 service=dict(id=1, host='compute1'),
119 vcpus=4,
120 memory_mb=10 * 1024,
121 local_gb=250,
122 vcpus_used=2,
123 memory_mb_used=5 * 1024,
124 local_gb_used=125,
125 hypervisor_type="xen",
126 hypervisor_version=3,
127 hypervisor_hostname="hyper1",
128 free_ram_mb=5 * 1024,
129 free_disk_gb=125,
130 current_workload=2,
131 running_vms=2,
132 cpu_info='cpu_info',
133 disk_available_least=100)
134
135 result = self.cs.hypervisors.get(1234)
136 self.assert_called('GET', '/os-hypervisors/1234')
137
138 self.compare_to_expected(expected, result)
139
140 def test_hypervisor_uptime(self):
141 expected = dict(
142 id=1234,
143 hypervisor_hostname="hyper1",
144 uptime="fake uptime")
145
146 result = self.cs.hypervisors.uptime(1234)
147 self.assert_called('GET', '/os-hypervisors/1234/uptime')
148
149 self.compare_to_expected(expected, result)
150
151 def test_hypervisor_statistics(self):
152 expected = dict(
153 count=2,
154 vcpus=8,
155 memory_mb=20 * 1024,
156 local_gb=500,
157 vcpus_used=4,
158 memory_mb_used=10 * 1024,
159 local_gb_used=250,
160 free_ram_mb=10 * 1024,
161 free_disk_gb=250,
162 current_workload=4,
163 running_vms=4,
164 disk_available_least=200,
165 )
166
167 result = self.cs.hypervisors.statistics()
168 self.assert_called('GET', '/os-hypervisors/statistics')
169
170 self.compare_to_expected(expected, result)
171
172 def test_hypervisor_statistics_data_model(self):
173 result = self.cs.hypervisor_stats.statistics()
174 self.assert_called('GET', '/os-hypervisors/statistics')
175
176 # Test for Bug #1370415, the line below used to raise AttributeError
177 self.assertEqual("<HypervisorStats: 2 Hypervisors>",
178 result.__repr__())