Revision 1c6d3839 test/py/ganeti.hypervisor.hv_kvm_unittest.py
b/test/py/ganeti.hypervisor.hv_kvm_unittest.py | ||
---|---|---|
27 | 27 |
import socket |
28 | 28 |
import os |
29 | 29 |
import struct |
30 |
import re |
|
30 | 31 |
|
31 | 32 |
from ganeti import serializer |
32 | 33 |
from ganeti import constants |
... | ... | |
366 | 367 |
self.assertFalse(hv_kvm._ProbeTapVnetHdr(fd, _features_fn=lambda _: None)) |
367 | 368 |
|
368 | 369 |
|
370 |
class TestGenerateDeviceKVMId(unittest.TestCase): |
|
371 |
def test(self): |
|
372 |
device = objects.NIC() |
|
373 |
target = constants.HOTPLUG_TARGET_NIC |
|
374 |
fn = hv_kvm._GenerateDeviceKVMId |
|
375 |
self.assertRaises(errors.HotplugError, fn, target, device) |
|
376 |
|
|
377 |
device.pci = 5 |
|
378 |
device.uuid = "003fc157-66a8-4e6d-8b7e-ec4f69751396" |
|
379 |
self.assertTrue(re.match("hotnic-003fc157-pci-5", fn(target, device))) |
|
380 |
|
|
381 |
|
|
382 |
class TestGetRuntimeInfo(unittest.TestCase): |
|
383 |
@classmethod |
|
384 |
def _GetRuntime(cls): |
|
385 |
data = testutils.ReadTestData("kvm_runtime.json") |
|
386 |
return hv_kvm._AnalyzeSerializedRuntime(data) |
|
387 |
|
|
388 |
def _fail(self, target, device, runtime): |
|
389 |
device.uuid = "aaaaaaaa-66a8-4e6d-8b7e-ec4f69751396" |
|
390 |
self.assertRaises(errors.HotplugError, |
|
391 |
hv_kvm._GetExistingDeviceInfo, |
|
392 |
target, device, runtime) |
|
393 |
|
|
394 |
def testNIC(self): |
|
395 |
device = objects.NIC() |
|
396 |
target = constants.HOTPLUG_TARGET_NIC |
|
397 |
runtime = self._GetRuntime() |
|
398 |
|
|
399 |
self._fail(target, device, runtime) |
|
400 |
|
|
401 |
device.uuid = "003fc157-66a8-4e6d-8b7e-ec4f69751396" |
|
402 |
devinfo = hv_kvm._GetExistingDeviceInfo(target, device, runtime) |
|
403 |
self.assertTrue(devinfo.pci==6) |
|
404 |
|
|
405 |
def testDisk(self): |
|
406 |
device = objects.Disk() |
|
407 |
target = constants.HOTPLUG_TARGET_DISK |
|
408 |
runtime = self._GetRuntime() |
|
409 |
|
|
410 |
self._fail(target, device, runtime) |
|
411 |
|
|
412 |
device.uuid = "9f5c5bd4-6f60-480b-acdc-9bb1a4b7df79" |
|
413 |
(devinfo, _) = hv_kvm._GetExistingDeviceInfo(target, device, runtime) |
|
414 |
self.assertTrue(devinfo.pci==5) |
|
415 |
|
|
416 |
|
|
369 | 417 |
if __name__ == "__main__": |
370 | 418 |
testutils.GanetiTestProgram() |
Also available in: Unified diff