execute=lvm_driver._execute,
sparse=True)
+ @mock.patch.object(cinder.volume.utils, 'get_all_volume_groups',
+ return_value=[{'name': 'cinder-volumes'}])
+ @mock.patch('cinder.brick.local_dev.lvm.LVM.update_volume_group_info')
+ @mock.patch('cinder.brick.local_dev.lvm.LVM.get_all_physical_volumes')
+ @mock.patch('cinder.brick.local_dev.lvm.LVM.supports_thin_provisioning',
+ return_value=True)
+ def test_lvm_type_auto_thin_pool_exists(self, *_unused_mocks):
+ configuration = conf.Configuration(fake_opt, 'fake_group')
+ configuration.lvm_type = 'auto'
+
+ vg_obj = fake_lvm.FakeBrickLVM('cinder-volumes',
+ False,
+ None,
+ 'default')
+
+ lvm_driver = lvm.LVMVolumeDriver(configuration=configuration,
+ vg_obj=vg_obj)
+
+ lvm_driver.check_for_setup_error()
+
+ self.assertEqual('thin', lvm_driver.configuration.lvm_type)
+
+ @mock.patch.object(cinder.volume.utils, 'get_all_volume_groups',
+ return_value=[{'name': 'cinder-volumes'}])
+ @mock.patch.object(cinder.brick.local_dev.lvm.LVM, 'get_volumes',
+ return_value=[])
+ @mock.patch('cinder.brick.local_dev.lvm.LVM.update_volume_group_info')
+ @mock.patch('cinder.brick.local_dev.lvm.LVM.get_all_physical_volumes')
+ @mock.patch('cinder.brick.local_dev.lvm.LVM.supports_thin_provisioning',
+ return_value=True)
+ def test_lvm_type_auto_no_lvs(self, *_unused_mocks):
+ configuration = conf.Configuration(fake_opt, 'fake_group')
+ configuration.lvm_type = 'auto'
+
+ vg_obj = fake_lvm.FakeBrickLVM('cinder-volumes',
+ False,
+ None,
+ 'default')
+
+ lvm_driver = lvm.LVMVolumeDriver(configuration=configuration,
+ vg_obj=vg_obj)
+
+ lvm_driver.check_for_setup_error()
+
+ self.assertEqual('thin', lvm_driver.configuration.lvm_type)
+
+ @mock.patch.object(cinder.volume.utils, 'get_all_volume_groups',
+ return_value=[{'name': 'cinder-volumes'}])
+ @mock.patch('cinder.brick.local_dev.lvm.LVM.update_volume_group_info')
+ @mock.patch('cinder.brick.local_dev.lvm.LVM.get_all_physical_volumes')
+ @mock.patch('cinder.brick.local_dev.lvm.LVM.supports_thin_provisioning',
+ return_value=False)
+ def test_lvm_type_auto_no_thin_support(self, *_unused_mocks):
+ configuration = conf.Configuration(fake_opt, 'fake_group')
+ configuration.lvm_type = 'auto'
+
+ lvm_driver = lvm.LVMVolumeDriver(configuration=configuration)
+
+ lvm_driver.check_for_setup_error()
+
+ self.assertEqual('default', lvm_driver.configuration.lvm_type)
+
+ @mock.patch.object(cinder.volume.utils, 'get_all_volume_groups',
+ return_value=[{'name': 'cinder-volumes'}])
+ @mock.patch('cinder.brick.local_dev.lvm.LVM.update_volume_group_info')
+ @mock.patch('cinder.brick.local_dev.lvm.LVM.get_all_physical_volumes')
+ @mock.patch('cinder.brick.local_dev.lvm.LVM.get_volume')
+ @mock.patch('cinder.brick.local_dev.lvm.LVM.supports_thin_provisioning',
+ return_value=False)
+ def test_lvm_type_auto_no_thin_pool(self, *_unused_mocks):
+ configuration = conf.Configuration(fake_opt, 'fake_group')
+ configuration.lvm_type = 'auto'
+
+ lvm_driver = lvm.LVMVolumeDriver(configuration=configuration)
+
+ lvm_driver.check_for_setup_error()
+
+ self.assertEqual('default', lvm_driver.configuration.lvm_type)
+
class ISCSITestCase(DriverTestCase):
"""Test Case for ISCSIDriver"""
'this requires lvm_mirrors + 2 PVs with available space'),
cfg.StrOpt('lvm_type',
default='default',
- choices=['default', 'thin'],
- help='Type of LVM volumes to deploy'),
+ choices=['default', 'thin', 'auto'],
+ help='Type of LVM volumes to deploy; (default, thin, or auto). '
+ 'Auto defaults to thin if thin is supported.'),
cfg.StrOpt('lvm_conf_file',
default='/etc/cinder/lvm.conf',
help='LVM conf file to use for the LVM driver in Cinder; '
self.configuration.volume_group)
raise exception.VolumeBackendAPIException(data=message)
+ pool_name = "%s-pool" % self.configuration.volume_group
+
+ if self.configuration.lvm_type == 'auto':
+ # Default to thin provisioning if it is supported and
+ # the volume group is empty, or contains a thin pool
+ # for us to use.
+ self.vg.update_volume_group_info()
+
+ self.configuration.lvm_type = 'default'
+
+ if volutils.supports_thin_provisioning():
+ if self.vg.get_volume(pool_name) is not None:
+ LOG.info(_LI('Enabling LVM thin provisioning by default '
+ 'because a thin pool exists.'))
+ self.configuration.lvm_type = 'thin'
+ elif len(self.vg.get_volumes()) == 0:
+ LOG.info(_LI('Enabling LVM thin provisioning by default '
+ 'because no LVs exist.'))
+ self.configuration.lvm_type = 'thin'
+
if self.configuration.lvm_type == 'thin':
# Specific checks for using Thin provisioned LV's
if not volutils.supports_thin_provisioning():
"on this version of LVM.")
raise exception.VolumeBackendAPIException(data=message)
- pool_name = "%s-pool" % self.configuration.volume_group
if self.vg.get_volume(pool_name) is None:
try:
self.vg.create_thin_pool(pool_name)