Libvirt: preallocate_images CONFIG can be arbitrary characters

We can now set preallocate_images as any characters as long as it is
not equal to 'none' to enable preallocate images function, this is
too bad.

This patch changes the condition to equal to 'space'/'Space'/'SPACE'

Closes-Bug: 1427092
Change-Id: Ie8f4861fb77d2c3c3a8976fb7768ced12e7d8d5b
This commit is contained in:
Eli Qiao 2015-02-28 17:13:00 +08:00 committed by Dan Smith
parent a07bf6dc8f
commit 41bc820e14
2 changed files with 29 additions and 2 deletions

View File

@ -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)

View File

@ -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()