]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
LVM: Robustify skipactivation detection
authorDirk Mueller <dirk@dmllr.de>
Wed, 15 Jan 2014 14:45:01 +0000 (15:45 +0100)
committerDirk Mueller <dirk@dmllr.de>
Mon, 27 Jan 2014 18:09:17 +0000 (19:09 +0100)
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
cinder/tests/brick/test_brick_lvm.py

index d6148b05afbb11b77a07a361d0e18431059a6e39..28da6459a2490c731b82acc22bcb65f7e95ed37d 100644 (file)
@@ -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
 
index 5aef2f1695f47697bffe858265183bcbcb44b9e0..838a4332798eaa51d187b92bbd757c1c5cf5013b 100644 (file)
@@ -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