From: Giulio Fidente Date: Thu, 10 Oct 2013 12:59:44 +0000 (+0200) Subject: improves lvm version parsing for customised builds X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=de031813b90d4a29fc6011a53fefa6c19001022e;p=openstack-build%2Fcinder-build.git improves lvm version parsing for customised builds 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) --- diff --git a/cinder/brick/local_dev/lvm.py b/cinder/brick/local_dev/lvm.py index 0049693f7..4b3066c6a 100644 --- a/cinder/brick/local_dev/lvm.py +++ b/cinder/brick/local_dev/lvm.py @@ -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 diff --git a/cinder/tests/brick/test_brick_lvm.py b/cinder/tests/brick/test_brick_lvm.py index 0b15c0a98..16df44b5b 100644 --- a/cinder/tests/brick/test_brick_lvm.py +++ b/cinder/tests/brick/test_brick_lvm.py @@ -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