diff --git a/nova/tests/test_libvirt.py b/nova/tests/test_libvirt.py index d388a1d4..11aadc89 100644 --- a/nova/tests/test_libvirt.py +++ b/nova/tests/test_libvirt.py @@ -15,6 +15,7 @@ # under the License. import copy +import errno import eventlet import mox import os @@ -800,6 +801,19 @@ class LibvirtConnTestCase(test.TestCase): (check(tree), expected_result, i)) def _check_xml_and_disk_driver(self, image_meta): + os_open = os.open + directio_supported = True + + def os_open_stub(path, flags, *args, **kwargs): + if flags & os.O_DIRECT: + if not directio_supported: + raise OSError(errno.EINVAL, + '%s: %s' % (os.strerror(errno.EINVAL), path)) + flags &= ~os.O_DIRECT + return os_open(path, flags, *args, **kwargs) + + self.stubs.Set(os, 'open', os_open_stub) + user_context = context.RequestContext(self.user_id, self.project_id) instance_ref = db.instance_create(user_context, self.test_instance) network_info = _fake_network_info(self.stubs, 1) @@ -812,6 +826,18 @@ class LibvirtConnTestCase(test.TestCase): for disk in disks: self.assertEqual(disk.get("cache"), "none") + directio_supported = False + + # The O_DIRECT availability is cached on first use in + # LibvirtConnection, hence we re-create it here + xml = connection.LibvirtConnection(True).to_xml(instance_ref, + network_info, + image_meta) + tree = ElementTree.fromstring(xml) + disks = tree.findall('./devices/disk/driver') + for disk in disks: + self.assertEqual(disk.get("cache"), "writethrough") + def _check_xml_and_disk_bus(self, image_meta, device_type, bus): user_context = context.RequestContext(self.user_id, self.project_id) instance_ref = db.instance_create(user_context, self.test_instance) diff --git a/nova/tests/test_virt_drivers.py b/nova/tests/test_virt_drivers.py index 8018008a..59292659 100644 --- a/nova/tests/test_virt_drivers.py +++ b/nova/tests/test_virt_drivers.py @@ -451,6 +451,11 @@ class LibvirtConnTestCase(_VirtDriverTestCase): nova.virt.libvirt.connection.libvirt_utils = fake_libvirt_utils nova.virt.libvirt.firewall.libvirt = fakelibvirt + # So that the _supports_direct_io does the test based + # on the current working directory, instead of the + # default instances_path which doesn't exist + FLAGS.instances_path = '' + # Point _VirtDriverTestCase at the right module self.driver_module = nova.virt.libvirt.connection super(LibvirtConnTestCase, self).setUp()