Merge "Libvirt: preallocate_images CONFIG can be arbitrary characters"
This commit is contained in:
commit
d2b62042d1
|
@ -1362,9 +1362,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)
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue