diff --git a/nova/tests/unit/virt/libvirt/test_imagebackend.py b/nova/tests/unit/virt/libvirt/test_imagebackend.py index 4739a59322cc..cfb6a7db3c6f 100644 --- a/nova/tests/unit/virt/libvirt/test_imagebackend.py +++ b/nova/tests/unit/virt/libvirt/test_imagebackend.py @@ -1363,9 +1363,33 @@ class BackendTestCase(test.NoDBTestCase): def test_image_raw(self): self._test_image('raw', imagebackend.Raw, imagebackend.Raw) + def test_image_raw_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') + self.assertTrue(raw.preallocate) + + def test_image_raw_preallocate_images_bad_conf(self): + self.flags(preallocate_images='space1') + raw = imagebackend.Raw(self.INSTANCE, 'fake_disk', '/tmp/xyz') + self.assertFalse(raw.preallocate) + def test_image_qcow2(self): self._test_image('qcow2', imagebackend.Qcow2, imagebackend.Qcow2) + def test_image_qcow2_preallocate_images(self): + flags = ('space', 'Space', 'SPACE') + for f in flags: + self.flags(preallocate_images=f) + qcow = imagebackend.Qcow2(self.INSTANCE, 'fake_disk', '/tmp/xyz') + self.assertTrue(qcow.preallocate) + + def test_image_qcow2_preallocate_images_bad_conf(self): + self.flags(preallocate_images='space1') + qcow = imagebackend.Qcow2(self.INSTANCE, 'fake_disk', '/tmp/xyz') + self.assertFalse(qcow.preallocate) + def test_image_lvm(self): self.flags(images_volume_group='FakeVG', group='libvirt') self._test_image('lvm', imagebackend.Lvm, imagebackend.Lvm) diff --git a/nova/virt/libvirt/imagebackend.py b/nova/virt/libvirt/imagebackend.py index b85b1e8c7418..266f677b6a6f 100644 --- a/nova/virt/libvirt/imagebackend.py +++ b/nova/virt/libvirt/imagebackend.py @@ -23,6 +23,7 @@ from oslo_config import cfg from oslo_log import log as logging from oslo_serialization import jsonutils from oslo_utils import excutils +from oslo_utils import strutils from oslo_utils import units import six @@ -383,7 +384,8 @@ class Raw(Image): self.path = (path or os.path.join(libvirt_utils.get_instance_path(instance), disk_name)) - self.preallocate = CONF.preallocate_images != 'none' + self.preallocate = ( + strutils.to_slug(CONF.preallocate_images) == 'space') self.disk_info_path = os.path.join(os.path.dirname(self.path), 'disk.info') self.correct_format() @@ -455,7 +457,8 @@ class Qcow2(Image): self.path = (path or os.path.join(libvirt_utils.get_instance_path(instance), disk_name)) - self.preallocate = CONF.preallocate_images != 'none' + self.preallocate = ( + strutils.to_slug(CONF.preallocate_images) == 'space') self.disk_info_path = os.path.join(os.path.dirname(self.path), 'disk.info') self.resolve_driver_format()