]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
improves lvm version parsing for customised builds
authorGiulio Fidente <gfidente@redhat.com>
Thu, 10 Oct 2013 12:59:44 +0000 (14:59 +0200)
committerJohn Griffith <john.griffith@solidfire.com>
Thu, 10 Oct 2013 17:12:00 +0000 (11:12 -0600)
supports_thin_provisioning now uses a regexp to ensure parsing of
lvm version succeeds when the build is customised; also adds a test
for a customised string parsing

Closes-Bug: #1237994
Change-Id: I49049a58bbdb5315b9d2d7c259a9324ca15d78cb
(cherry picked from commit 51fd5edb106e26d65696ce37a70eef6a4f75b1e2)

cinder/brick/local_dev/lvm.py
cinder/tests/brick/test_brick_lvm.py

index 0049693f7d8f6d0b0d2eb7a3d0fe50728c349fd7..4b3066c6a990f6958673dc6099129c0ca8dd3dc7 100644 (file)
@@ -136,10 +136,12 @@ class LVM(executor.Executor):
         for line in lines:
             if 'LVM version' in line:
                 version_list = line.split()
+                # NOTE(gfidente): version is formatted as follows:
+                # major.minor.patchlevel(library API version)[-customisation]
                 version = version_list[2]
-                if '(2)' in version:
-                    version = version.replace('(2)', '')
-                version_tuple = tuple(map(int, version.split('.')))
+                version_filter = "(\d+)\.(\d+)\.(\d+).*"
+                r = re.search(version_filter, version)
+                version_tuple = tuple(map(int, r.group(1, 2, 3)))
                 if version_tuple >= (2, 2, 95):
                     return True
         return False
index 0b15c0a985c659e986c3873283e3fa219c849a5b..16df44b5b9fb0d5441b82c0e01e054d408948962 100644 (file)
@@ -58,6 +58,9 @@ class BrickLvmTestCase(test.TestCase):
     def fake_old_lvm_version(obj, *cmd, **kwargs):
         return ("  LVM version:     2.02.65(2) (2012-03-06)\n", "")
 
+    def fake_customised_lvm_version(obj, *cmd, **kwargs):
+        return ("  LVM version:     2.02.100(2)-RHEL6 (2013-09-12)\n", "")
+
     def fake_execute(obj, *cmd, **kwargs):
         cmd_string = ', '.join(cmd)
         data = "\n"
@@ -133,7 +136,7 @@ class BrickLvmTestCase(test.TestCase):
     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 proessutils.execute appropriately
+        # so we need to stub processutils.execute appropriately
 
         self.stubs.Set(processutils, 'execute', self.fake_execute)
         self.assertTrue(self.vg.supports_thin_provisioning('sudo'))
@@ -144,6 +147,11 @@ class BrickLvmTestCase(test.TestCase):
         self.stubs.Set(processutils, 'execute', self.fake_old_lvm_version)
         self.assertFalse(self.vg.supports_thin_provisioning('sudo'))
 
+        self.stubs.Set(processutils,
+                       'execute',
+                       self.fake_customised_lvm_version)
+        self.assertTrue(self.vg.supports_thin_provisioning('sudo'))
+
     def test_volume_create_after_thin_creation(self):
         """Test self.vg.vg_thin_pool is set to pool_name