glusterfs.common: move the numreduct function to toplevel

This function is not specific to GlusterFS interaction.

Partially implements bp gluster-code-cleanup

Change-Id: I96ef68f13287d6654b65744df67880ab9deccb3f
This commit is contained in:
Csaba Henk 2016-02-18 21:43:07 +01:00
parent 1fda615f6f
commit 6bbd199b85
3 changed files with 19 additions and 21 deletions

View File

@ -328,7 +328,7 @@ class GlusterManager(object):
(given as tuple of integers, example: (3, 6))
"""
vers = self.get_gluster_version()
if self.numreduct(vers) < minvers:
if numreduct(vers) < minvers:
raise exception.GlusterfsException(_(
"Unsupported GlusterFS version %(version)s on server "
"%(server)s, minimum requirement: %(minvers)s") % {
@ -336,20 +336,20 @@ class GlusterManager(object):
'version': '.'.join(vers),
'minvers': '.'.join(six.text_type(c) for c in minvers)})
@staticmethod
def numreduct(vers):
"""The numeric reduct of a tuple of strings.
That is, applying an integer conversion map on the longest
initial segment of vers which consists of numerals.
"""
numvers = []
for c in vers:
try:
numvers.append(int(c))
except ValueError:
break
return tuple(numvers)
def numreduct(vers):
"""The numeric reduct of a tuple of strings.
That is, applying an integer conversion map on the longest
initial segment of vers which consists of numerals.
"""
numvers = []
for c in vers:
try:
numvers.append(int(c))
except ValueError:
break
return tuple(numvers)
def _mount_gluster_vol(execute, gluster_export, mount_path, ensure=False):

View File

@ -140,8 +140,7 @@ class GlusterfsVolumeMappedLayout(layout.GlusterfsShareLayoutBase):
','.join(exceptions.keys())))
notsupp_servers = []
for srvaddr, vers in glusterfs_versions.items():
if common.GlusterManager.numreduct(
vers) < self.driver.GLUSTERFS_VERSION_MIN:
if common.numreduct(vers) < self.driver.GLUSTERFS_VERSION_MIN:
notsupp_servers.append(srvaddr)
if notsupp_servers:
gluster_version_min_str = '.'.join(
@ -356,8 +355,7 @@ class GlusterfsVolumeMappedLayout(layout.GlusterfsShareLayoutBase):
# delete the paths of the two directories, but delete their contents
# along with the rest of the contents of the volume.
srvaddr = gluster_mgr.host_access
if common.GlusterManager.numreduct(self.glusterfs_versions[srvaddr]
) < (3, 7):
if common.numreduct(self.glusterfs_versions[srvaddr]) < (3, 7):
cmd = ['find', tmpdir, '-mindepth', '1', '-delete']
else:
ignored_dirs = map(lambda x: os.path.join(tmpdir, *x),
@ -465,7 +463,7 @@ class GlusterfsVolumeMappedLayout(layout.GlusterfsShareLayoutBase):
# a version check.
vers = self.glusterfs_versions[old_gmgr.host_access]
minvers = (3, 7)
if common.GlusterManager.numreduct(vers) < minvers:
if common.numreduct(vers) < minvers:
minvers_str = '.'.join(six.text_type(c) for c in minvers)
vers_str = '.'.join(vers)
msg = (_("GlusterFS version %(version)s on server %(server)s does "
@ -537,7 +535,7 @@ class GlusterfsVolumeMappedLayout(layout.GlusterfsShareLayoutBase):
if opret == -1:
vers = self.glusterfs_versions[gluster_mgr.host_access]
if common.GlusterManager.numreduct(vers) > (3, 6):
if common.numreduct(vers) > (3, 6):
# This logic has not yet been implemented in GlusterFS 3.6
if operrno == 0:
self.gluster_nosnap_vols_dict[

View File

@ -612,7 +612,7 @@ class GlusterManagerTestCase(test.TestCase):
('3', '6', '2beta'),
('3', '6', '2beta', '4'))
def test_numreduct(self, vers):
ret = common.GlusterManager.numreduct(vers)
ret = common.numreduct(vers)
self.assertEqual((3, 6), ret)