From: Eric Harney Date: Wed, 23 Sep 2015 20:26:20 +0000 (-0400) Subject: LVM: Make sparse_copy_volume private, use for capabilities X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=7ce3c7130a4b10d4ca56bec3df665a8271da4a39;p=openstack-build%2Fcinder-build.git LVM: Make sparse_copy_volume private, use for capabilities This should be a private variable after the refactoring done for 0982ad1 Efficient volume copy for generic volume migration Additionally, just use the variable determined by the config at init time when reporting capabilities rather than having a separate calculation there. Change-Id: I433e22f71b24afd10a879447d79ce1fda0a7bfa6 --- diff --git a/cinder/tests/unit/test_volume.py b/cinder/tests/unit/test_volume.py index e060d8d9f..e008c0b60 100644 --- a/cinder/tests/unit/test_volume.py +++ b/cinder/tests/unit/test_volume.py @@ -6631,7 +6631,7 @@ class LVMISCSIVolumeDriverTestCase(DriverTestCase): False, None, 'default') - lvm_driver.sparse_copy_volume = True + lvm_driver._sparse_copy_volume = True moved, model_update = \ lvm_driver.migrate_volume(self.context, vol, host) self.assertTrue(moved) @@ -7075,7 +7075,7 @@ class LVMVolumeDriverTestCase(DriverTestCase): mock.patch.object(volutils, 'copy_volume') as mock_copy: # Test case for thin LVM - lvm_driver.sparse_copy_volume = True + lvm_driver._sparse_copy_volume = True src_volume = tests_utils.create_volume(self.context) snapshot_ref = tests_utils.create_snapshot(self.context, src_volume['id']) @@ -7264,12 +7264,15 @@ class ISCSITestCase(DriverTestCase): self.assertEqual(["iqn:iqn", "iqn:iqn"], result["target_iqns"]) self.assertEqual([0, 0], result["target_luns"]) - def test_get_volume_stats(self): + @mock.patch('cinder.brick.local_dev.lvm.LVM.get_lvm_version', + return_value=(2, 2, 100)) + def test_get_volume_stats(self, _mock_get_version): def _fake_get_all_physical_volumes(obj, root_helper, vg_name): return [{}] - def _fake_get_all_volume_groups(obj, vg_name=None, no_suffix=True): + @staticmethod + def _fake_get_all_volume_groups(root_helper, vg_name=None): return [{'name': 'cinder-volumes', 'size': '5.52', 'available': '0.52', @@ -7308,10 +7311,17 @@ class ISCSITestCase(DriverTestCase): self.assertFalse(stats['sparse_copy_volume']) # Check value of sparse_copy_volume for thin enabled case. + # This value is set in check_for_setup_error. self.configuration = conf.Configuration(None) self.configuration.lvm_type = 'thin' + vg_obj = fake_lvm.FakeBrickLVM('cinder-volumes', + False, + None, + 'default') lvm_driver = lvm.LVMVolumeDriver(configuration=self.configuration, - db=db) + db=db, + vg_obj=vg_obj) + lvm_driver.check_for_setup_error() lvm_driver.vg = brick_lvm.LVM('cinder-volumes', 'sudo') lvm_driver._update_volume_stats() stats = lvm_driver._stats diff --git a/cinder/volume/drivers/lvm.py b/cinder/volume/drivers/lvm.py index fa0c7ec86..363ec3c3b 100644 --- a/cinder/volume/drivers/lvm.py +++ b/cinder/volume/drivers/lvm.py @@ -98,7 +98,7 @@ class LVMVolumeDriver(driver.VolumeDriver): db=self.db, executor=self._execute) self.protocol = self.target_driver.protocol - self.sparse_copy_volume = False + self._sparse_copy_volume = False def _sizestr(self, size_in_g): return '%sg' % size_in_g @@ -248,7 +248,7 @@ class LVMVolumeDriver(driver.VolumeDriver): data["pools"].append(single_pool) # Check availability of sparse volume copy. - data['sparse_copy_volume'] = self.configuration.lvm_type == 'thin' + data['sparse_copy_volume'] = self._sparse_copy_volume self._stats = data @@ -320,7 +320,7 @@ class LVMVolumeDriver(driver.VolumeDriver): data=exception_message) # Enable sparse copy since lvm_type is 'thin' - self.sparse_copy_volume = True + self._sparse_copy_volume = True def create_volume(self, volume): """Creates a logical volume.""" @@ -386,7 +386,7 @@ class LVMVolumeDriver(driver.VolumeDriver): snapshot['volume_size'] * units.Ki, self.configuration.volume_dd_blocksize, execute=self._execute, - sparse=self.sparse_copy_volume) + sparse=self._sparse_copy_volume) def delete_volume(self, volume): """Deletes a logical volume.""" @@ -493,7 +493,7 @@ class LVMVolumeDriver(driver.VolumeDriver): src_vref['size'] * units.Ki, self.configuration.volume_dd_blocksize, execute=self._execute, - sparse=self.sparse_copy_volume) + sparse=self._sparse_copy_volume) finally: self.delete_snapshot(temp_snapshot) @@ -682,7 +682,7 @@ class LVMVolumeDriver(driver.VolumeDriver): size_in_mb, self.configuration.volume_dd_blocksize, execute=self._execute, - sparse=self.sparse_copy_volume) + sparse=self._sparse_copy_volume) except Exception as e: with excutils.save_and_reraise_exception(): LOG.error(_LE("Volume migration failed due to "