From 63b0accd89f2894a199e4a60428bb2c5cd20facd Mon Sep 17 00:00:00 2001 From: Rick Harris Date: Tue, 8 Apr 2014 12:01:35 -0500 Subject: [PATCH] libvirt: Stub O_DIRECT in test if not supported `os.O_DIRECT` is only defined on platforms that support direct I/O. On Macs, which don't support direct I/O in this way, `os.O_DIRECT` will raise an `AttributeError`. We can still test the code-path, however, by just stubbing out the value on platforms where it's not supported. Closes-Bug: 1286958 Change-Id: I8f10d6dfc4a63b6a961006b029b828e703870e46 --- nova/tests/virt/libvirt/test_libvirt.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/nova/tests/virt/libvirt/test_libvirt.py b/nova/tests/virt/libvirt/test_libvirt.py index aa9d87727040..82f876ec3bbc 100644 --- a/nova/tests/virt/libvirt/test_libvirt.py +++ b/nova/tests/virt/libvirt/test_libvirt.py @@ -3308,6 +3308,16 @@ class LibvirtConnTestCase(test.TestCase): os.unlink(3) def test_supports_direct_io(self): + # O_DIRECT is not supported on all Python runtimes, so on platforms + # where it's not supported (e.g. Mac), we can still test the code-path + # by stubbing out the value. + if not hasattr(os, 'O_DIRECT'): + # `mock` seems to have trouble stubbing an attr that doesn't + # originally exist, so falling back to stubbing out the attribute + # directly. + os.O_DIRECT = 16384 + self.addCleanup(delattr, os, 'O_DIRECT') + einval = OSError() einval.errno = errno.EINVAL self.mox.StubOutWithMock(os, 'open')