Convert ignoreskippedcluster check to be static

Using LVM.supports_XXX will check for the existence of the
property method, rather than attempting to retrieve the property.

As the caller is a static method, we can't actually use a property
here, so fix this to use static methods and cache on the class.
Fixes I89ffea86d0951fe4c80783a612b6cde76c8838b4.

Change-Id: I7294ccdf9c0c5858d949b01ad55763ad3129d8ec
Closes-bug: 1661144
This commit is contained in:
Bob Ball 2017-02-02 14:45:43 +00:00
parent fb97be7f10
commit c891ca9a7b
2 changed files with 17 additions and 15 deletions

View File

@ -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,

View File

@ -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):