Revision d0bb3f24 test/py/ganeti.hypervisor.hv_xen_unittest.py
b/test/py/ganeti.hypervisor.hv_xen_unittest.py | ||
---|---|---|
21 | 21 |
|
22 | 22 |
"""Script for testing ganeti.hypervisor.hv_lxc""" |
23 | 23 |
|
24 |
import string # pylint: disable=W0402 |
|
24 | 25 |
import unittest |
25 | 26 |
|
26 | 27 |
from ganeti import constants |
... | ... | |
213 | 214 |
}) |
214 | 215 |
|
215 | 216 |
|
217 |
class TestGetConfigFileDiskData(unittest.TestCase): |
|
218 |
def testLetterCount(self): |
|
219 |
self.assertEqual(len(hv_xen._DISK_LETTERS), 26) |
|
220 |
|
|
221 |
def testNoDisks(self): |
|
222 |
self.assertEqual(hv_xen._GetConfigFileDiskData([], "hd"), []) |
|
223 |
|
|
224 |
def testManyDisks(self): |
|
225 |
for offset in [0, 1, 10]: |
|
226 |
disks = [(objects.Disk(dev_type=constants.LD_LV), "/tmp/disk/%s" % idx) |
|
227 |
for idx in range(len(hv_xen._DISK_LETTERS) + offset)] |
|
228 |
|
|
229 |
if offset == 0: |
|
230 |
result = hv_xen._GetConfigFileDiskData(disks, "hd") |
|
231 |
self.assertEqual(result, [ |
|
232 |
"'phy:/tmp/disk/%s,hd%s,r'" % (idx, string.ascii_lowercase[idx]) |
|
233 |
for idx in range(len(hv_xen._DISK_LETTERS) + offset) |
|
234 |
]) |
|
235 |
else: |
|
236 |
try: |
|
237 |
hv_xen._GetConfigFileDiskData(disks, "hd") |
|
238 |
except errors.HypervisorError, err: |
|
239 |
self.assertEqual(str(err), "Too many disks") |
|
240 |
else: |
|
241 |
self.fail("Exception was not raised") |
|
242 |
|
|
243 |
def testTwoLvDisksWithMode(self): |
|
244 |
disks = [ |
|
245 |
(objects.Disk(dev_type=constants.LD_LV, mode=constants.DISK_RDWR), |
|
246 |
"/tmp/diskFirst"), |
|
247 |
(objects.Disk(dev_type=constants.LD_LV, mode=constants.DISK_RDONLY), |
|
248 |
"/tmp/diskLast"), |
|
249 |
] |
|
250 |
|
|
251 |
result = hv_xen._GetConfigFileDiskData(disks, "hd") |
|
252 |
self.assertEqual(result, [ |
|
253 |
"'phy:/tmp/diskFirst,hda,w'", |
|
254 |
"'phy:/tmp/diskLast,hdb,r'", |
|
255 |
]) |
|
256 |
|
|
257 |
def testFileDisks(self): |
|
258 |
disks = [ |
|
259 |
(objects.Disk(dev_type=constants.LD_FILE, mode=constants.DISK_RDWR, |
|
260 |
physical_id=[constants.FD_LOOP]), |
|
261 |
"/tmp/diskFirst"), |
|
262 |
(objects.Disk(dev_type=constants.LD_FILE, mode=constants.DISK_RDONLY, |
|
263 |
physical_id=[constants.FD_BLKTAP]), |
|
264 |
"/tmp/diskTwo"), |
|
265 |
(objects.Disk(dev_type=constants.LD_FILE, mode=constants.DISK_RDWR, |
|
266 |
physical_id=[constants.FD_LOOP]), |
|
267 |
"/tmp/diskThree"), |
|
268 |
(objects.Disk(dev_type=constants.LD_FILE, mode=constants.DISK_RDWR, |
|
269 |
physical_id=[constants.FD_BLKTAP]), |
|
270 |
"/tmp/diskLast"), |
|
271 |
] |
|
272 |
|
|
273 |
result = hv_xen._GetConfigFileDiskData(disks, "sd") |
|
274 |
self.assertEqual(result, [ |
|
275 |
"'file:/tmp/diskFirst,sda,w'", |
|
276 |
"'tap:aio:/tmp/diskTwo,sdb,r'", |
|
277 |
"'file:/tmp/diskThree,sdc,w'", |
|
278 |
"'tap:aio:/tmp/diskLast,sdd,w'", |
|
279 |
]) |
|
280 |
|
|
281 |
def testInvalidFileDisk(self): |
|
282 |
disks = [ |
|
283 |
(objects.Disk(dev_type=constants.LD_FILE, mode=constants.DISK_RDWR, |
|
284 |
physical_id=["#unknown#"]), |
|
285 |
"/tmp/diskinvalid"), |
|
286 |
] |
|
287 |
|
|
288 |
self.assertRaises(KeyError, hv_xen._GetConfigFileDiskData, disks, "sd") |
|
289 |
|
|
290 |
|
|
216 | 291 |
if __name__ == "__main__": |
217 | 292 |
testutils.GanetiTestProgram() |
Also available in: Unified diff