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
This commit is contained in:
parent
cbc6e8ef5d
commit
193096a476
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue