From 193096a476ca3da2ef7f36f89fdbd897c5bcc320 Mon Sep 17 00:00:00 2001 From: Dirk Mueller Date: Wed, 15 Jan 2014 15:45:01 +0100 Subject: [PATCH] LVM: Robustify skipactivation detection Running lvchange might fail due to not being in $PATH for non-root user, and the corresponding OSError was not caught. Simply check for lvm2 being 2.02.99 or newer. Closes-Bug: #1269445 Change-Id: I308bd97cb729e83677f18a693274265a182d794c --- cinder/brick/local_dev/lvm.py | 17 ++++-------- cinder/tests/brick/test_brick_lvm.py | 41 ++-------------------------- 2 files changed, 8 insertions(+), 50 deletions(-) diff --git a/cinder/brick/local_dev/lvm.py b/cinder/brick/local_dev/lvm.py index d6148b05a..28da6459a 100644 --- a/cinder/brick/local_dev/lvm.py +++ b/cinder/brick/local_dev/lvm.py @@ -202,7 +202,7 @@ class LVM(executor.Executor): def supports_snapshot_lv_activation(self): """Property indicating whether snap activation changes are supported. - Check for LVM version > 2.02.91. + Check for LVM version >= 2.02.91. (LVM2 git: e8a40f6 Allow to activate snapshot) :returns: True/False indicating support @@ -220,22 +220,15 @@ class LVM(executor.Executor): def supports_lvchange_ignoreskipactivation(self): """Property indicating whether lvchange can ignore skip activation. - Tests whether lvchange -K/--ignoreactivationskip exists. + 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 - cmd = ['lvchange', '--help'] - (out, err) = self._execute(*cmd) - - self._supports_lvchange_ignoreskipactivation = False - - lines = out.split('\n') - for line in lines: - if '-K' in line and '--ignoreactivationskip' in line: - self._supports_lvchange_ignoreskipactivation = True - break + self._supports_lvchange_ignoreskipactivation = ( + self.get_lvm_version(self._root_helper) >= (2, 2, 99)) return self._supports_lvchange_ignoreskipactivation diff --git a/cinder/tests/brick/test_brick_lvm.py b/cinder/tests/brick/test_brick_lvm.py index 5aef2f169..838a43327 100644 --- a/cinder/tests/brick/test_brick_lvm.py +++ b/cinder/tests/brick/test_brick_lvm.py @@ -181,49 +181,14 @@ class BrickLvmTestCase(test.TestCase): self.vg._supports_snapshot_lv_activation = None def test_lvchange_ignskipact_support_yes(self): - """Tests the ability to test support for lvchange -K - - Stubs provide output for "lvchange --help". - """ - - def lvchange_ign_yes(obj, *args, **kwargs): - return (""" - WARNING: Running as a non-root user. Functionality may be - unavailable. - lvchange: Change the attributes of logical volume(s) - - lvchange - [-A|--autobackup y|n] - [-k|--setactivationskip {y|n}] - [-K|--ignoreactivationskip] - [-y|--yes] - [-Z|--zero {y|n}] - LogicalVolume[Path] [LogicalVolume[Path]...] - """, "") + """Tests if lvchange -K is available via a lvm2 version check.""" self.vg._supports_lvchange_ignoreskipactivation = None - self.stubs.Set(self.vg, '_execute', lvchange_ign_yes) + self.stubs.Set(processutils, 'execute', self.fake_pretend_lvm_version) self.assertTrue(self.vg.supports_lvchange_ignoreskipactivation) self.vg._supports_lvchange_ignoreskipactivation = None - - def test_lvchange_ignskipact_support_no(self): - def lvchange_ign_no(obj, *args, **kwargs): - return (""" - WARNING: Running as a non-root user. Functionality may be - unavailable. - lvchange: Change the attributes of logical volume(s) - - lvchange - [-A|--autobackup y|n] - [-k|--setactivationskip {y|n}] - [-y|--yes] - [-Z|--zero {y|n}] - LogicalVolume[Path] [LogicalVolume[Path]...] - """, "") - - self.vg._supports_lvchange_ignoreskipactivation = None - self.stubs.Set(self.vg, '_execute', lvchange_ign_no) + self.stubs.Set(processutils, 'execute', self.fake_old_lvm_version) self.assertFalse(self.vg.supports_lvchange_ignoreskipactivation) self.vg._supports_lvchange_ignoreskipactivation = None -- 2.45.2