diff --git a/cinder/brick/local_dev/lvm.py b/cinder/brick/local_dev/lvm.py index 78db70078ed..3c21c29d50e 100644 --- a/cinder/brick/local_dev/lvm.py +++ b/cinder/brick/local_dev/lvm.py @@ -73,6 +73,9 @@ class LVM(executor.Executor): self._supports_lvchange_ignoreskipactivation = None self.vg_provisioned_capacity = 0.0 + if lvm_type not in ['default', 'thin']: + raise exception.Invalid('lvm_type must be "default" or "thin"') + # Ensure LVM_SYSTEM_DIR has been added to LVM.LVM_CMD_PREFIX # before the first LVM command is executed, and use the directory # where the specified lvm_conf file is located as the value. diff --git a/cinder/tests/unit/volume/drivers/test_lvm_driver.py b/cinder/tests/unit/volume/drivers/test_lvm_driver.py index 2a944269fd6..8acf89f307c 100644 --- a/cinder/tests/unit/volume/drivers/test_lvm_driver.py +++ b/cinder/tests/unit/volume/drivers/test_lvm_driver.py @@ -284,6 +284,10 @@ class LVMVolumeDriverTestCase(test_driver.BaseDriverTestCase): @mock.patch.object(cinder.volume.utils, 'get_all_volume_groups', return_value=[{'name': 'cinder-volumes'}]) + @mock.patch('cinder.brick.local_dev.lvm.LVM.get_lv_info') + @mock.patch('cinder.brick.local_dev.lvm.LVM.activate_lv') + @mock.patch('cinder.brick.local_dev.lvm.LVM.' + 'supports_lvchange_ignoreskipactivation') @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', @@ -300,6 +304,10 @@ class LVMVolumeDriverTestCase(test_driver.BaseDriverTestCase): @mock.patch.object(cinder.volume.utils, 'get_all_volume_groups', return_value=[{'name': 'cinder-volumes'}]) + @mock.patch('cinder.brick.local_dev.lvm.LVM.get_lv_info') + @mock.patch('cinder.brick.local_dev.lvm.LVM.activate_lv') + @mock.patch('cinder.brick.local_dev.lvm.LVM.' + 'supports_lvchange_ignoreskipactivation') @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') diff --git a/cinder/volume/drivers/lvm.py b/cinder/volume/drivers/lvm.py index 18e5dc5bd03..74f6f8ed885 100644 --- a/cinder/volume/drivers/lvm.py +++ b/cinder/volume/drivers/lvm.py @@ -291,10 +291,16 @@ class LVMVolumeDriver(driver.VolumeDriver): lvm_conf_file = None try: + lvm_type = self.configuration.lvm_type + if lvm_type == 'auto': + if volutils.supports_thin_provisioning(): + lvm_type = 'thin' + else: + lvm_type = 'default' self.vg = lvm.LVM( self.configuration.volume_group, root_helper, - lvm_type=self.configuration.lvm_type, + lvm_type=lvm_type, executor=self._execute, lvm_conf=lvm_conf_file, suppress_fd_warn=(