From 51815402f01fddb6956a4908a3042fe6a5fb9b49 Mon Sep 17 00:00:00 2001 From: Dmitry Kudyukin Date: Thu, 10 Nov 2016 17:36:09 +0300 Subject: [PATCH] Cluster volume group fix in lvm After adding lvm cluster volume group on host with cinder-volume service, this service failed to start. Add --ignoreskippedcluster option to pvs and unit test for pvs command in case cluster volume group exist. Closes-Bug: 1640536 Change-Id: I89ffea86d0951fe4c80783a612b6cde76c8838b4 --- cinder/brick/local_dev/lvm.py | 20 ++++++++++++++++++++ cinder/tests/unit/brick/test_brick_lvm.py | 21 +++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/cinder/brick/local_dev/lvm.py b/cinder/brick/local_dev/lvm.py index 664883b6a10..ab6611a94de 100644 --- a/cinder/brick/local_dev/lvm.py +++ b/cinder/brick/local_dev/lvm.py @@ -71,6 +71,7 @@ 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 @@ -257,6 +258,22 @@ class LVM(executor.Executor): return self._supports_lvchange_ignoreskipactivation + @property + def supports_pvs_ignoreskippedcluster(self): + """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 + + self._supports_pvs_ignoreskippedcluster = ( + self.get_lvm_version(self._root_helper) >= (2, 2, 103)) + + return self._supports_pvs_ignoreskippedcluster + @staticmethod def get_lv_info(root_helper, vg_name=None, lv_name=None): """Retrieve info about LVs (all, in a VG, or a single LV). @@ -334,6 +351,9 @@ class LVM(executor.Executor): '-o', 'vg_name,name,size,free', '--separator', field_sep, '--nosuffix'] + if LVM.supports_pvs_ignoreskippedcluster: + cmd.append('--ignoreskippedcluster') + (out, _err) = putils.execute(*cmd, root_helper=root_helper, run_as_root=True) diff --git a/cinder/tests/unit/brick/test_brick_lvm.py b/cinder/tests/unit/brick/test_brick_lvm.py index 71ae1c3de95..27123085682 100644 --- a/cinder/tests/unit/brick/test_brick_lvm.py +++ b/cinder/tests/unit/brick/test_brick_lvm.py @@ -140,6 +140,12 @@ class BrickLvmTestCase(test.TestCase): data += " fake-vg|/dev/sdb|10.00|1.00\n" data += " fake-vg|/dev/sdc|10.00|8.99\n" data += " fake-vg-2|/dev/sdd|10.00|9.99\n" + if '--ignoreskippedcluster' not in cmd_string: + raise processutils.ProcessExecutionError( + stderr="Skipping clustered volume group", + stdout=data, + exit_code=5 + ) elif _lvm_prefix + 'lvs, --noheadings, --unit=g' \ ', -o, size,data_percent, --separator, :' in cmd_string: if 'test-prov-cap-pool' in cmd_string: @@ -280,6 +286,21 @@ class BrickLvmTestCase(test.TestCase): self.vg._supports_lvchange_ignoreskipactivation = None + def test_pvs_ignoreskippedcluster_support(self): + """Tests if lvm support ignoreskippedcluster option.""" + + self.vg._supports_pvs_ignoreskippedcluster = None + with mock.patch.object(processutils, 'execute', + self.fake_pretend_lvm_version): + self.assertTrue(self.vg.supports_pvs_ignoreskippedcluster) + + self.vg._supports_pvs_ignoreskippedcluster = None + with mock.patch.object(processutils, 'execute', + self.fake_old_lvm_version): + self.assertFalse(self.vg.supports_pvs_ignoreskippedcluster) + + self.vg._supports_pvs_ignoreskippedcluster = None + def test_thin_pool_creation(self): # The size of fake-vg volume group is 10g, so the calculated thin