From f8b99117c1abfd8c6a9b95195c397ef484a05c23 Mon Sep 17 00:00:00 2001 From: David McNally Date: Thu, 13 Dec 2012 15:03:13 +0000 Subject: [PATCH] Adding ability to specify the libvirt cache mode for disk devices MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In past versions of Nova it was possible to explicitly configure the cache mode of disks via the libvirt XML template. The current approach makes this a derived setting of either “none” or “writethrough” based on the support of O_DIRECT. Whilst this provides a good set of default settings it removes the ability of the cloud provider to use other modes such as “writeback” and “unsafe” which are valuable in certain configurations. This change allows the cache mode to be specified on a per-disk type basis. If a disk type does not have a cache mode specified then the default behaviour remains unchanged. DocImpact bug 1086386 Change-Id: I3d296fe0b4b9b976db02db90ad69fd299cd2096a --- nova/tests/test_libvirt.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/nova/tests/test_libvirt.py b/nova/tests/test_libvirt.py index 6882bb08..333922ee 100644 --- a/nova/tests/test_libvirt.py +++ b/nova/tests/test_libvirt.py @@ -269,6 +269,17 @@ class FakeVolumeDriver(object): return "" +class FakeConfigGuestDisk(object): + def __init__(self, *args, **kwargs): + self.source_type = None + self.driver_cache = None + + +class FakeConfigGuest(object): + def __init__(self, *args, **kwargs): + self.driver_cache = None + + class LibvirtConnTestCase(test.TestCase): def setUp(self): @@ -3431,6 +3442,33 @@ class LibvirtConnTestCase(test.TestCase): self.assertEqual(got_events[0].transition, virtevent.EVENT_LIFECYCLE_STOPPED) + def test_set_cache_mode(self): + self.flags(disk_cachemodes=['file=directsync']) + conn = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), True) + fake_conf = FakeConfigGuestDisk() + + fake_conf.source_type = 'file' + conn.set_cache_mode(fake_conf) + self.assertEqual(fake_conf.driver_cache, 'directsync') + + def test_set_cache_mode_invalid_mode(self): + self.flags(disk_cachemodes=['file=FAKE']) + conn = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), True) + fake_conf = FakeConfigGuestDisk() + + fake_conf.source_type = 'file' + conn.set_cache_mode(fake_conf) + self.assertEqual(fake_conf.driver_cache, None) + + def test_set_cache_mode_invalid_object(self): + self.flags(disk_cachemodes=['file=directsync']) + conn = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), True) + fake_conf = FakeConfigGuest() + + fake_conf.driver_cache = 'fake' + conn.set_cache_mode(fake_conf) + self.assertEqual(fake_conf.driver_cache, 'fake') + class HostStateTestCase(test.TestCase):