]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
LVM: Make sparse_copy_volume private, use for capabilities
authorEric Harney <eharney@redhat.com>
Wed, 23 Sep 2015 20:26:20 +0000 (16:26 -0400)
committerEric Harney <eharney@redhat.com>
Wed, 30 Sep 2015 19:58:42 +0000 (15:58 -0400)
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

cinder/tests/unit/test_volume.py
cinder/volume/drivers/lvm.py

index e060d8d9f8d400478c512d0ba546d79b0f5112e9..e008c0b60b334d649847457982da62ff5e39a360 100644 (file)
@@ -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
index fa0c7ec861fa833442a5b7da92ef732a6bbdb2af..363ec3c3b9ba3ca9ef51184103276f75552035e2 100644 (file)
@@ -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 "