From cff4d78a4a7ddbb18cb875c66b3c56f04a6caea3 Mon Sep 17 00:00:00 2001 From: Matthew Booth Date: Thu, 7 Apr 2016 13:40:58 +0100 Subject: [PATCH] Rename Raw backend to Flat As mentioned in a comment (which this patch deletes), calling this class 'Raw' was confusing, because it is not always raw. It is also a source of bugs, because some code assumes that the format is always raw, which it is not. This patch does not fix those bugs. We rename it to 'Flat', which describes it accurately. We also add doctext describing what it does. DocImpact The config option libvirt.images_type gets an additional value: 'flat'. The effect of this is identical to setting the value 'raw'. Change-Id: I93f0a2cc568b60c2b3f7509449167f03c3f30fb5 --- nova/conf/libvirt.py | 3 +- .../unit/virt/libvirt/test_imagebackend.py | 28 ++++++++++--------- nova/virt/libvirt/driver.py | 2 +- nova/virt/libvirt/imagebackend.py | 21 ++++++++------ tests-py3.txt | 2 +- 5 files changed, 32 insertions(+), 24 deletions(-) diff --git a/nova/conf/libvirt.py b/nova/conf/libvirt.py index f910c54aec54..9bc8eab24a46 100644 --- a/nova/conf/libvirt.py +++ b/nova/conf/libvirt.py @@ -220,7 +220,8 @@ libvirt_general_opts = [ libvirt_imagebackend_opts = [ cfg.StrOpt('images_type', default='default', - choices=('raw', 'qcow2', 'lvm', 'rbd', 'ploop', 'default'), + choices=('raw', 'flat', 'qcow2', 'lvm', 'rbd', 'ploop', + 'default'), help='VM Images format. If default is specified, then' ' use_cow_images flag is used instead of this one.'), cfg.StrOpt('images_volume_group', diff --git a/nova/tests/unit/virt/libvirt/test_imagebackend.py b/nova/tests/unit/virt/libvirt/test_imagebackend.py index 92b1bad58a3f..f0b20a063ef2 100644 --- a/nova/tests/unit/virt/libvirt/test_imagebackend.py +++ b/nova/tests/unit/virt/libvirt/test_imagebackend.py @@ -194,14 +194,15 @@ class _ImageTestCase(object): get_disk_size.assert_called_once_with(image.path) -class RawTestCase(_ImageTestCase, test.NoDBTestCase): +class FlatTestCase(_ImageTestCase, test.NoDBTestCase): SIZE = 1024 def setUp(self): - self.image_class = imagebackend.Raw - super(RawTestCase, self).setUp() - self.stubs.Set(imagebackend.Raw, 'correct_format', lambda _: None) + self.image_class = imagebackend.Flat + super(FlatTestCase, self).setUp() + self.stubs.Set(imagebackend.Flat, 'correct_format', + lambda _: None) def prepare_mocks(self): fn = self.mox.CreateMockAnything() @@ -1670,24 +1671,25 @@ class BackendTestCase(test.NoDBTestCase): assertIsInstance(image1, image_not_cow) assertIsInstance(image2, image_cow) - def test_image_raw(self): - self._test_image('raw', imagebackend.Raw, imagebackend.Raw) + def test_image_flat(self): + self._test_image('raw', imagebackend.Flat, imagebackend.Flat) - def test_image_raw_preallocate_images(self): + def test_image_flat_preallocate_images(self): flags = ('space', 'Space', 'SPACE') for f in flags: self.flags(preallocate_images=f) - raw = imagebackend.Raw(self.INSTANCE, 'fake_disk', '/tmp/xyz') + raw = imagebackend.Flat(self.INSTANCE, 'fake_disk', + '/tmp/xyz') self.assertTrue(raw.preallocate) - def test_image_raw_preallocate_images_bad_conf(self): + def test_image_flat_preallocate_images_bad_conf(self): self.flags(preallocate_images='space1') - raw = imagebackend.Raw(self.INSTANCE, 'fake_disk', '/tmp/xyz') + raw = imagebackend.Flat(self.INSTANCE, 'fake_disk', '/tmp/xyz') self.assertFalse(raw.preallocate) - def test_image_raw_native_io(self): + def test_image_flat_native_io(self): self.flags(preallocate_images="space") - raw = imagebackend.Raw(self.INSTANCE, 'fake_disk', '/tmp/xyz') + raw = imagebackend.Flat(self.INSTANCE, 'fake_disk', '/tmp/xyz') self.assertEqual(raw.driver_io, "native") def test_image_qcow2(self): @@ -1733,4 +1735,4 @@ class BackendTestCase(test.NoDBTestCase): self._test_image('rbd', imagebackend.Rbd, imagebackend.Rbd) def test_image_default(self): - self._test_image('default', imagebackend.Raw, imagebackend.Qcow2) + self._test_image('default', imagebackend.Flat, imagebackend.Qcow2) diff --git a/nova/virt/libvirt/driver.py b/nova/virt/libvirt/driver.py index 6583ca6b3b2e..8ff80de8d92e 100644 --- a/nova/virt/libvirt/driver.py +++ b/nova/virt/libvirt/driver.py @@ -5410,7 +5410,7 @@ class LibvirtDriver(driver.ComputeDriver): if (dest_check_data.is_shared_instance_path and self.image_backend.backend().is_file_in_instance_path()): - # NOTE(angdraug): file based image backends (Raw, Qcow2) + # NOTE(angdraug): file based image backends (Flat, Qcow2) # place block device files under the instance path return True diff --git a/nova/virt/libvirt/imagebackend.py b/nova/virt/libvirt/imagebackend.py index 01c02d06d58b..42c94581c51c 100644 --- a/nova/virt/libvirt/imagebackend.py +++ b/nova/virt/libvirt/imagebackend.py @@ -430,10 +430,15 @@ class Image(object): pass -class Raw(Image): +class Flat(Image): + """The Flat backend uses either raw or qcow2 storage. It never uses + a backing store, so when using qcow2 it copies an image rather than + creating an overlay. By default it creates raw files, but will use qcow2 + when creating a disk from a qcow2 if force_raw_images is not set in config. + """ def __init__(self, instance=None, disk_name=None, path=None): self.disk_name = disk_name - super(Raw, self).__init__("file", "raw", is_block_dev=False) + super(Flat, self).__init__("file", "raw", is_block_dev=False) self.path = (path or os.path.join(libvirt_utils.get_instance_path(instance), @@ -459,11 +464,11 @@ class Raw(Image): def _supports_encryption(self): # NOTE(dgenin): Kernel, ramdisk and disk.config are fetched using - # the Raw backend regardless of which backend is configured for - # ephemeral storage. Encryption for the Raw backend is not yet + # the Flat backend regardless of which backend is configured for + # ephemeral storage. Encryption for the Flat backend is not yet # implemented so this loophole is necessary to allow other # backends already supporting encryption to function. This can - # be removed once encryption for Raw is implemented. + # be removed once encryption for Flat is implemented. if self.disk_name not in ['kernel', 'ramdisk', 'disk.config']: return False else: @@ -480,7 +485,6 @@ class Raw(Image): def copy_raw_image(base, target, size): libvirt_utils.copy_image(base, target) if size: - # class Raw is misnamed, format may not be 'raw' in all cases image = imgmodel.LocalFileImage(target, self.driver_format) disk.extend(image, size) @@ -1069,12 +1073,13 @@ class Ploop(Image): class Backend(object): def __init__(self, use_cow): self.BACKEND = { - 'raw': Raw, + 'raw': Flat, + 'flat': Flat, 'qcow2': Qcow2, 'lvm': Lvm, 'rbd': Rbd, 'ploop': Ploop, - 'default': Qcow2 if use_cow else Raw + 'default': Qcow2 if use_cow else Flat } def backend(self, image_type=None): diff --git a/tests-py3.txt b/tests-py3.txt index 94fc07291be9..6a6d49347290 100644 --- a/tests-py3.txt +++ b/tests-py3.txt @@ -158,7 +158,7 @@ nova.tests.unit.virt.libvirt.test_fakelibvirt.FakeLibvirtTests.test_numa_topolog nova.tests.unit.virt.libvirt.test_firewall.IptablesFirewallTestCase nova.tests.unit.virt.libvirt.test_imagebackend.EncryptedLvmTestCase nova.tests.unit.virt.libvirt.test_imagebackend.LvmTestCase -nova.tests.unit.virt.libvirt.test_imagebackend.RawTestCase +nova.tests.unit.virt.libvirt.test_imagebackend.FlatTestCase nova.tests.unit.virt.libvirt.test_imagebackend.RbdTestCase nova.tests.unit.virt.libvirt.test_imagecache.ImageCacheManagerTestCase nova.tests.unit.virt.libvirt.test_imagecache.VerifyChecksumTestCase