diff --git a/cinder/brick/local_dev/lvm.py b/cinder/brick/local_dev/lvm.py index ab6611a94de..b5086ba849a 100644 --- a/cinder/brick/local_dev/lvm.py +++ b/cinder/brick/local_dev/lvm.py @@ -38,6 +38,7 @@ LOG = logging.getLogger(__name__) class LVM(executor.Executor): """LVM object to enable various LVM related operations.""" LVM_CMD_PREFIX = ['env', 'LC_ALL=C'] + _supports_pvs_ignoreskippedcluster = None def __init__(self, vg_name, root_helper, create_vg=False, physical_volumes=None, lvm_type='default', @@ -71,7 +72,6 @@ class LVM(executor.Executor): self.vg_thin_pool_free_space = 0.0 self._supports_snapshot_lv_activation = None self._supports_lvchange_ignoreskipactivation = None - self._supports_pvs_ignoreskippedcluster = None self.vg_provisioned_capacity = 0.0 # Ensure LVM_SYSTEM_DIR has been added to LVM.LVM_CMD_PREFIX @@ -258,21 +258,21 @@ class LVM(executor.Executor): return self._supports_lvchange_ignoreskipactivation - @property - def supports_pvs_ignoreskippedcluster(self): + @staticmethod + def supports_pvs_ignoreskippedcluster(root_helper): """Property indicating whether pvs supports --ignoreskippedcluster Check for LVM version >= 2.02.103. (LVM2 git: baf95bbff cmdline: Add --ignoreskippedcluster. """ - if self._supports_pvs_ignoreskippedcluster is not None: - return self._supports_pvs_ignoreskippedcluster + if LVM._supports_pvs_ignoreskippedcluster is not None: + return LVM._supports_pvs_ignoreskippedcluster - self._supports_pvs_ignoreskippedcluster = ( - self.get_lvm_version(self._root_helper) >= (2, 2, 103)) + LVM._supports_pvs_ignoreskippedcluster = ( + LVM.get_lvm_version(root_helper) >= (2, 2, 103)) - return self._supports_pvs_ignoreskippedcluster + return LVM._supports_pvs_ignoreskippedcluster @staticmethod def get_lv_info(root_helper, vg_name=None, lv_name=None): @@ -351,7 +351,7 @@ class LVM(executor.Executor): '-o', 'vg_name,name,size,free', '--separator', field_sep, '--nosuffix'] - if LVM.supports_pvs_ignoreskippedcluster: + if LVM.supports_pvs_ignoreskippedcluster(root_helper): cmd.append('--ignoreskippedcluster') (out, _err) = putils.execute(*cmd, diff --git a/cinder/tests/unit/brick/test_brick_lvm.py b/cinder/tests/unit/brick/test_brick_lvm.py index 27123085682..54aa1020dc2 100644 --- a/cinder/tests/unit/brick/test_brick_lvm.py +++ b/cinder/tests/unit/brick/test_brick_lvm.py @@ -67,7 +67,7 @@ class BrickLvmTestCase(test.TestCase): cmd_string): data = " fake-vg\n" elif _lvm_prefix + 'vgs, --version' in cmd_string: - data = " LVM version: 2.02.95(2) (2012-03-06)\n" + data = " LVM version: 2.02.103(2) (2012-03-06)\n" elif(_lvm_prefix + 'vgs, --noheadings, -o, uuid, fake-vg' in cmd_string): data = " kVxztV-dKpG-Rz7E-xtKY-jeju-QsYU-SLG6Z1\n" @@ -289,17 +289,19 @@ class BrickLvmTestCase(test.TestCase): def test_pvs_ignoreskippedcluster_support(self): """Tests if lvm support ignoreskippedcluster option.""" - self.vg._supports_pvs_ignoreskippedcluster = None + brick.LVM._supports_pvs_ignoreskippedcluster = None with mock.patch.object(processutils, 'execute', self.fake_pretend_lvm_version): - self.assertTrue(self.vg.supports_pvs_ignoreskippedcluster) + self.assertTrue(brick.LVM.supports_pvs_ignoreskippedcluster( + 'sudo')) - self.vg._supports_pvs_ignoreskippedcluster = None + brick.LVM._supports_pvs_ignoreskippedcluster = None with mock.patch.object(processutils, 'execute', self.fake_old_lvm_version): - self.assertFalse(self.vg.supports_pvs_ignoreskippedcluster) + self.assertFalse(brick.LVM.supports_pvs_ignoreskippedcluster( + 'sudo')) - self.vg._supports_pvs_ignoreskippedcluster = None + brick.LVM._supports_pvs_ignoreskippedcluster = None def test_thin_pool_creation(self):