Revision 20529708 test/py/ganeti.masterd.iallocator_unittest.py
b/test/py/ganeti.masterd.iallocator_unittest.py | ||
---|---|---|
22 | 22 |
"""Script for testing ganeti.masterd.iallocator""" |
23 | 23 |
|
24 | 24 |
import unittest |
25 |
import mock |
|
25 | 26 |
|
26 | 27 |
from ganeti import compat |
27 | 28 |
from ganeti import constants |
28 | 29 |
from ganeti import errors |
29 | 30 |
from ganeti import objects |
30 | 31 |
from ganeti import ht |
32 |
from ganeti import rpc |
|
31 | 33 |
from ganeti.masterd import iallocator |
32 | 34 |
|
33 | 35 |
import testutils |
... | ... | |
177 | 179 |
else: |
178 | 180 |
self.assertTrue(result["node1"]["offline"]) |
179 | 181 |
|
182 |
class TestProcessStorageInfo(unittest.TestCase): |
|
183 |
|
|
184 |
def setUp(self): |
|
185 |
self.free_storage_file = 23 |
|
186 |
self.total_storage_file = 42 |
|
187 |
self.free_storage_lvm = 69 |
|
188 |
self.total_storage_lvm = 666 |
|
189 |
self.space_info = [{"name": "mynode", |
|
190 |
"type": constants.ST_FILE, |
|
191 |
"storage_free": self.free_storage_file, |
|
192 |
"storage_size": self.total_storage_file}, |
|
193 |
{"name": "mynode", |
|
194 |
"type": constants.ST_LVM_VG, |
|
195 |
"storage_free": self.free_storage_lvm, |
|
196 |
"storage_size": self.total_storage_lvm}, |
|
197 |
{"name": "mynode", |
|
198 |
"type": constants.ST_LVM_PV, |
|
199 |
"storage_free": 33, |
|
200 |
"storage_size": 44}] |
|
201 |
self.node_info = ("123", self.space_info, ({},)) |
|
202 |
|
|
203 |
def testComputeStorageDataLvm(self): |
|
204 |
has_lvm = True |
|
205 |
node_name = "mynode" |
|
206 |
remote_info = rpc.MakeLegacyNodeInfo(self.node_info, |
|
207 |
require_vg_info=has_lvm) |
|
208 |
(total_disk, free_disk, total_spindles, free_spindles) = \ |
|
209 |
iallocator.IAllocator._ComputeStorageData(remote_info, node_name, has_lvm) |
|
210 |
self.assertEqual(self.free_storage_lvm, free_disk) |
|
211 |
self.assertEqual(self.total_storage_lvm, total_disk) |
|
212 |
|
|
213 |
def testComputeStorageDataDefault(self): |
|
214 |
has_lvm = False |
|
215 |
node_name = "mynode" |
|
216 |
remote_info = rpc.MakeLegacyNodeInfo(self.node_info, |
|
217 |
require_vg_info=has_lvm) |
|
218 |
(total_disk, free_disk, total_spindles, free_spindles) = \ |
|
219 |
iallocator.IAllocator._ComputeStorageData(remote_info, node_name, has_lvm) |
|
220 |
# FIXME: right now, iallocator ignores anything else than LVM, adjust |
|
221 |
# this test once that arbitrary storage is supported |
|
222 |
self.assertEqual(0, free_disk) |
|
223 |
self.assertEqual(0, total_disk) |
|
224 |
|
|
180 | 225 |
|
181 | 226 |
if __name__ == "__main__": |
182 | 227 |
testutils.GanetiTestProgram() |
Also available in: Unified diff