summaryrefslogtreecommitdiffstats
path: root/glustolibs-gluster
diff options
context:
space:
mode:
authorPranav <prprakas@redhat.com>2020-06-09 12:04:58 +0530
committerArthy Loganathan <aloganat@redhat.com>2020-06-10 04:24:17 +0000
commitf60a12bda34d206c1dca509a3a44d26a85f87239 (patch)
tree9bbdd8f52f87d5dea7ac85325ecc7febc0517052 /glustolibs-gluster
parent4d4559b77e83397f320a37164c9c2277a36db36a (diff)
[Libfix] Fix find_specific_hashed method
Problem: There are scenarios where multiple files are to be renamed to hash to a particular subvol. The existing method returns the same name as the loop always starts from 1. Fix: Adding an optional argument, existing_names which contains names already hashed to the subvol. An additional check is added to ensure the name found is not already used Change-Id: I453ee290c8462322194cebb42c40e8fbc7c373ed Signed-off-by: Pranav <prprakas@redhat.com>
Diffstat (limited to 'glustolibs-gluster')
-rw-r--r--glustolibs-gluster/glustolibs/gluster/dht_test_utils.py8
1 files changed, 6 insertions, 2 deletions
diff --git a/glustolibs-gluster/glustolibs/gluster/dht_test_utils.py b/glustolibs-gluster/glustolibs/gluster/dht_test_utils.py
index eaf4fc9..b01f7c5 100644
--- a/glustolibs-gluster/glustolibs/gluster/dht_test_utils.py
+++ b/glustolibs-gluster/glustolibs/gluster/dht_test_utils.py
@@ -342,13 +342,14 @@ def find_new_hashed(subvols, parent_path, oldname):
return None
-def find_specific_hashed(subvols, parent_path, subvol):
+def find_specific_hashed(subvols, parent_path, subvol, existing_names=None):
""" Finds filename that hashes to a specific subvol.
Args:
subvols(list): list of subvols
parent_path(str): parent path (relative to mount) of "oldname"
subvol(str): The subvol to which the new name has to be hashed
+ existing_names(int|list): The name(s) already hashed to subvol
Returns:
(Class Object): For success returns an object of type NewHashed
@@ -357,6 +358,8 @@ def find_specific_hashed(subvols, parent_path, subvol):
Note: The new hash will be searched under the same parent
"""
# pylint: disable=protected-access
+ if not isinstance(existing_names, list):
+ existing_names = [existing_names]
brickobject = create_brickobjectlist(subvols, parent_path)
if brickobject is None:
g.log.error("could not form brickobject list")
@@ -366,7 +369,8 @@ def find_specific_hashed(subvols, parent_path, subvol):
newhash = calculate_hash(brickobject[0]._host, str(item))
for brickdir in brickobject:
count += 1
- if subvol._fqpath == brickdir._fqpath:
+ if (subvol._fqpath == brickdir._fqpath and
+ item not in existing_names):
ret = brickdir.hashrange_contains_hash(newhash)
if ret:
g.log.debug("oldhashed %s new %s count %s",