Revision ea2bcb82 test/py/ganeti.hypervisor.hv_kvm_unittest.py
b/test/py/ganeti.hypervisor.hv_kvm_unittest.py | ||
---|---|---|
26 | 26 |
import unittest |
27 | 27 |
import socket |
28 | 28 |
import os |
29 |
import struct |
|
29 | 30 |
|
30 | 31 |
from ganeti import serializer |
31 | 32 |
from ganeti import constants |
... | ... | |
315 | 316 |
self.assertFalse(boot_re.search(help_01590)) |
316 | 317 |
|
317 | 318 |
|
319 |
class TestGetTunFeatures(unittest.TestCase): |
|
320 |
def testWrongIoctl(self): |
|
321 |
tmpfile = tempfile.NamedTemporaryFile() |
|
322 |
# A file does not have the right ioctls, so this must always fail |
|
323 |
result = hv_kvm._GetTunFeatures(tmpfile.fileno()) |
|
324 |
self.assertTrue(result is None) |
|
325 |
|
|
326 |
def _FakeIoctl(self, features, fd, request, buf): |
|
327 |
self.assertEqual(request, hv_kvm.TUNGETFEATURES) |
|
328 |
|
|
329 |
(reqno, ) = struct.unpack("I", buf) |
|
330 |
self.assertEqual(reqno, 0) |
|
331 |
|
|
332 |
return struct.pack("I", features) |
|
333 |
|
|
334 |
def test(self): |
|
335 |
tmpfile = tempfile.NamedTemporaryFile() |
|
336 |
fd = tmpfile.fileno() |
|
337 |
|
|
338 |
for features in [0, hv_kvm.IFF_VNET_HDR]: |
|
339 |
fn = compat.partial(self._FakeIoctl, features) |
|
340 |
result = hv_kvm._GetTunFeatures(fd, _ioctl=fn) |
|
341 |
self.assertEqual(result, features) |
|
342 |
|
|
343 |
|
|
344 |
class TestProbeTapVnetHdr(unittest.TestCase): |
|
345 |
def _FakeTunFeatures(self, expected_fd, flags, fd): |
|
346 |
self.assertEqual(fd, expected_fd) |
|
347 |
return flags |
|
348 |
|
|
349 |
def test(self): |
|
350 |
tmpfile = tempfile.NamedTemporaryFile() |
|
351 |
fd = tmpfile.fileno() |
|
352 |
|
|
353 |
for flags in [0, hv_kvm.IFF_VNET_HDR]: |
|
354 |
fn = compat.partial(self._FakeTunFeatures, fd, flags) |
|
355 |
|
|
356 |
result = hv_kvm._ProbeTapVnetHdr(fd, _features_fn=fn) |
|
357 |
if flags == 0: |
|
358 |
self.assertFalse(result) |
|
359 |
else: |
|
360 |
self.assertTrue(result) |
|
361 |
|
|
362 |
def testUnsupported(self): |
|
363 |
tmpfile = tempfile.NamedTemporaryFile() |
|
364 |
fd = tmpfile.fileno() |
|
365 |
|
|
366 |
self.assertFalse(hv_kvm._ProbeTapVnetHdr(fd, _features_fn=lambda _: None)) |
|
367 |
|
|
368 |
|
|
318 | 369 |
if __name__ == "__main__": |
319 | 370 |
testutils.GanetiTestProgram() |
Also available in: Unified diff