From 1c2bfa9e4f57b75a85dd7ff0db426cf50c0d5583 Mon Sep 17 00:00:00 2001 From: Eric Harney Date: Fri, 30 Jun 2017 08:14:04 -0400 Subject: [PATCH] LVM: Don't initialize VG with lvm_type='auto' The 'auto' arg should be translated to 'thin' for the lvm.LVM() call. Otherwise the checks for lvm_type=='thin' in the LVM() code do not function as intended. Closes-Bug: #1701547 Change-Id: Ifad854e6f0ef23085ff7af608e290e62c2ad2554 (cherry picked from commit 7033774fbb2f488fb0cfc94cf1a1d059b08b6d98) --- cinder/brick/local_dev/lvm.py | 3 +++ cinder/tests/unit/volume/drivers/test_lvm_driver.py | 8 ++++++++ cinder/volume/drivers/lvm.py | 8 +++++++- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/cinder/brick/local_dev/lvm.py b/cinder/brick/local_dev/lvm.py index c60cf36ab52..4232b4abd5e 100644 --- a/cinder/brick/local_dev/lvm.py +++ b/cinder/brick/local_dev/lvm.py @@ -74,6 +74,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 f564098ff14..d5a9696a06f 100644 --- a/cinder/tests/unit/volume/drivers/test_lvm_driver.py +++ b/cinder/tests/unit/volume/drivers/test_lvm_driver.py @@ -362,6 +362,10 @@ class LVMVolumeDriverTestCase(test_volume.DriverTestCase): @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', @@ -378,6 +382,10 @@ class LVMVolumeDriverTestCase(test_volume.DriverTestCase): @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 1fdf76b1f03..41d64802e5a 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=(