Revision fda3d987 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 |
... | ... | |
384 | 385 |
self.assertFalse(hv_kvm._ProbeTapVnetHdr(fd, _features_fn=lambda _: None)) |
385 | 386 |
|
386 | 387 |
|
388 |
class TestGenerateDeviceKVMId(unittest.TestCase): |
|
389 |
def test(self): |
|
390 |
device = objects.NIC() |
|
391 |
target = constants.HOTPLUG_TARGET_NIC |
|
392 |
fn = hv_kvm._GenerateDeviceKVMId |
|
393 |
self.assertRaises(errors.HotplugError, fn, target, device) |
|
394 |
|
|
395 |
device.pci = 5 |
|
396 |
device.uuid = "003fc157-66a8-4e6d-8b7e-ec4f69751396" |
|
397 |
self.assertTrue(re.match("hotnic-003fc157-pci-5", fn(target, device))) |
|
398 |
|
|
399 |
|
|
400 |
class TestGetRuntimeInfo(unittest.TestCase): |
|
401 |
@classmethod |
|
402 |
def _GetRuntime(cls): |
|
403 |
data = testutils.ReadTestData("kvm_runtime.json") |
|
404 |
return hv_kvm._AnalyzeSerializedRuntime(data) |
|
405 |
|
|
406 |
def _fail(self, target, device, runtime): |
|
407 |
device.uuid = "aaaaaaaa-66a8-4e6d-8b7e-ec4f69751396" |
|
408 |
self.assertRaises(errors.HotplugError, |
|
409 |
hv_kvm._GetExistingDeviceInfo, |
|
410 |
target, device, runtime) |
|
411 |
|
|
412 |
def testNIC(self): |
|
413 |
device = objects.NIC() |
|
414 |
target = constants.HOTPLUG_TARGET_NIC |
|
415 |
runtime = self._GetRuntime() |
|
416 |
|
|
417 |
self._fail(target, device, runtime) |
|
418 |
|
|
419 |
device.uuid = "003fc157-66a8-4e6d-8b7e-ec4f69751396" |
|
420 |
devinfo = hv_kvm._GetExistingDeviceInfo(target, device, runtime) |
|
421 |
self.assertTrue(devinfo.pci==6) |
|
422 |
|
|
423 |
def testDisk(self): |
|
424 |
device = objects.Disk() |
|
425 |
target = constants.HOTPLUG_TARGET_DISK |
|
426 |
runtime = self._GetRuntime() |
|
427 |
|
|
428 |
self._fail(target, device, runtime) |
|
429 |
|
|
430 |
device.uuid = "9f5c5bd4-6f60-480b-acdc-9bb1a4b7df79" |
|
431 |
(devinfo, _, __) = hv_kvm._GetExistingDeviceInfo(target, device, runtime) |
|
432 |
self.assertTrue(devinfo.pci==5) |
|
433 |
|
|
434 |
|
|
387 | 435 |
if __name__ == "__main__": |
388 | 436 |
testutils.GanetiTestProgram() |
Also available in: Unified diff