Skip to content

Commit

Permalink
improves lvm version parsing for customised builds
Browse files Browse the repository at this point in the history
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
  • Loading branch information
gfidente committed Oct 10, 2013
1 parent 18218bd commit 51fd5ed
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
8 changes: 5 additions & 3 deletions cinder/brick/local_dev/lvm.py
Expand Up @@ -136,10 +136,12 @@ def supports_thin_provisioning(root_helper):
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
Expand Down
10 changes: 9 additions & 1 deletion cinder/tests/brick/test_brick_lvm.py
Expand Up @@ -58,6 +58,9 @@ def fake_pretend_lvm_version(obj, *cmd, **kwargs):
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"
Expand Down Expand Up @@ -133,7 +136,7 @@ def test_get_volume_groups(self):
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'))
Expand All @@ -144,6 +147,11 @@ def test_thin_support(self):
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
Expand Down

0 comments on commit 51fd5ed

Please sign in to comment.