From 368bb38b81606b117af581681648f1386a823e2a Mon Sep 17 00:00:00 2001 From: Eric Harney Date: Thu, 17 Aug 2023 09:23:38 -0400 Subject: [PATCH] LVM: Assume version >= 2.02.99 Stop testing for presence of - lv activation support (added in 2.02.91) - thin provisioning (added in 2.02.95) - --ignoreactivationskip (added in 2.02.99) 2.02.99 was released in 2013. Change-Id: I98bbe898bb1e75aa519dddfd44546fe9d477392f --- os_brick/local_dev/lvm.py | 70 ++-------------------- os_brick/tests/local_dev/test_brick_lvm.py | 49 --------------- 2 files changed, 5 insertions(+), 114 deletions(-) diff --git a/os_brick/local_dev/lvm.py b/os_brick/local_dev/lvm.py index 5432530c6..83d93a73d 100644 --- a/os_brick/local_dev/lvm.py +++ b/os_brick/local_dev/lvm.py @@ -71,8 +71,6 @@ class LVM(executor.Executor): self.vg_thin_pool = None self.vg_thin_pool_size = 0.0 self.vg_thin_pool_free_space = 0.0 - self._supports_snapshot_lv_activation: Optional[bool] = None - self._supports_lvchange_ignoreskipactivation: Optional[bool] = None self.vg_provisioned_capacity = 0.0 # Ensure LVM_SYSTEM_DIR has been added to LVM.LVM_CMD_PREFIX @@ -247,51 +245,6 @@ class LVM(executor.Executor): return version_tuple raise exception.BrickException(message='Cannot parse LVM version') - @staticmethod - def supports_thin_provisioning(root_helper: str) -> bool: - """Static method to check for thin LVM support on a system. - - :param root_helper: root_helper to use for execute - :returns: True if supported, False otherwise - - """ - - return LVM.get_lvm_version(root_helper) >= (2, 2, 95) - - @property - def supports_snapshot_lv_activation(self) -> bool: - """Property indicating whether snap activation changes are supported. - - Check for LVM version >= 2.02.91. - (LVM2 git: e8a40f6 Allow to activate snapshot) - - :returns: True/False indicating support - """ - - if self._supports_snapshot_lv_activation is not None: - return self._supports_snapshot_lv_activation - - self._supports_snapshot_lv_activation = ( - self.get_lvm_version(self._root_helper) >= (2, 2, 91)) - - return self._supports_snapshot_lv_activation - - @property - def supports_lvchange_ignoreskipactivation(self) -> bool: - """Property indicating whether lvchange can ignore skip activation. - - Check for LVM version >= 2.02.99. - (LVM2 git: ab789c1bc add --ignoreactivationskip to lvchange) - """ - - if self._supports_lvchange_ignoreskipactivation is not None: - return self._supports_lvchange_ignoreskipactivation - - self._supports_lvchange_ignoreskipactivation = ( - self.get_lvm_version(self._root_helper) >= (2, 2, 99)) - - return self._supports_lvchange_ignoreskipactivation - @property def supports_full_pool_create(self) -> bool: """Property indicating whether 100% pool creation is supported. @@ -546,12 +499,6 @@ class LVM(executor.Executor): """ - if not LVM.supports_thin_provisioning(self._root_helper): - LOG.error('Requested to setup thin provisioning, ' - 'however current LVM version does not ' - 'support it.') - return None - if name is None: name = '%s-pool' % self.vg_name @@ -709,12 +656,6 @@ class LVM(executor.Executor): :raises: putils.ProcessExecutionError """ - # This is a no-op if requested for a snapshot on a version - # of LVM that doesn't support snapshot activation. - # (Assume snapshot LV is always active.) - if is_snapshot and not self.supports_snapshot_lv_activation: - return - lv_path = self.vg_name + '/' + self._mangle_lv_name(name) # Must pass --yes to activate both the snap LV and its origin LV. @@ -722,12 +663,11 @@ class LVM(executor.Executor): # and fails. cmd = ['lvchange', '-a', 'y', '--yes'] - if self.supports_lvchange_ignoreskipactivation: - cmd.append('-K') - # If permanent=True is specified, drop the skipactivation flag in - # order to make this LV automatically activated after next reboot. - if permanent: - cmd += ['-k', 'n'] + cmd.append('-K') + # If permanent=True is specified, drop the skipactivation flag in + # order to make this LV automatically activated after next reboot. + if permanent: + cmd += ['-k', 'n'] cmd.append(lv_path) diff --git a/os_brick/tests/local_dev/test_brick_lvm.py b/os_brick/tests/local_dev/test_brick_lvm.py index 4a1d1978a..044f0f5ef 100644 --- a/os_brick/tests/local_dev/test_brick_lvm.py +++ b/os_brick/tests/local_dev/test_brick_lvm.py @@ -279,55 +279,6 @@ class BrickLvmTestCase(base.TestCase): self.assertEqual(1, len(self.vg.get_all_volume_groups('sudo', 'fake-vg'))) - def test_thin_support(self): - # lvm.supports_thin() is a static method and doesn't - # use the self._executor fake we pass in on init - # so we need to stub processutils.execute appropriately - - with mock.patch.object(priv_rootwrap, 'execute', - side_effect=self.fake_execute): - self.assertTrue(self.vg.supports_thin_provisioning('sudo')) - - with mock.patch.object(priv_rootwrap, 'execute', - side_effect=self.fake_pretend_lvm_version): - self.assertTrue(self.vg.supports_thin_provisioning('sudo')) - - with mock.patch.object(priv_rootwrap, 'execute', - side_effect=self.fake_old_lvm_version): - self.assertFalse(self.vg.supports_thin_provisioning('sudo')) - - with mock.patch.object(priv_rootwrap, 'execute', - side_effect=self.fake_customised_lvm_version): - self.assertTrue(self.vg.supports_thin_provisioning('sudo')) - - def test_snapshot_lv_activate_support(self): - self.vg._supports_snapshot_lv_activation = None - with mock.patch.object(priv_rootwrap, 'execute', - side_effect=self.fake_execute): - self.assertTrue(self.vg.supports_snapshot_lv_activation) - - self.vg._supports_snapshot_lv_activation = None - with mock.patch.object(priv_rootwrap, 'execute', - side_effect=self.fake_old_lvm_version): - self.assertFalse(self.vg.supports_snapshot_lv_activation) - - self.vg._supports_snapshot_lv_activation = None - - def test_lvchange_ignskipact_support_yes(self): - """Tests if lvchange -K is available via a lvm2 version check.""" - - self.vg._supports_lvchange_ignoreskipactivation = None - with mock.patch.object(priv_rootwrap, 'execute', - side_effect=self.fake_pretend_lvm_version): - self.assertTrue(self.vg.supports_lvchange_ignoreskipactivation) - - self.vg._supports_lvchange_ignoreskipactivation = None - with mock.patch.object(priv_rootwrap, 'execute', - side_effect=self.fake_old_lvm_version): - self.assertFalse(self.vg.supports_lvchange_ignoreskipactivation) - - self.vg._supports_lvchange_ignoreskipactivation = None - def test_thin_pool_creation_manual(self): # The size of fake-vg volume group is 10g, so the calculated thin # pool size should be 9.5g (95% of 10g).