From 2d56ff3360042072de4bd67b0bf950d1f3404d67 Mon Sep 17 00:00:00 2001 From: Pranav Date: Mon, 1 Jun 2020 10:35:30 +0530 Subject: [Lib] Add find_specific_hashed method This method helps in cases of rename scenarios where the new filename has to be hashed to a specific subvol Change-Id: Ia36ea8e3d279ddf130f3a8a940dbe1fcb1910974 Signed-off-by: Pranav --- .../glustolibs/gluster/dht_test_utils.py | 34 ++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'glustolibs-gluster') diff --git a/glustolibs-gluster/glustolibs/gluster/dht_test_utils.py b/glustolibs-gluster/glustolibs/gluster/dht_test_utils.py index 55dcce5c7..eaf4fc99c 100644 --- a/glustolibs-gluster/glustolibs/gluster/dht_test_utils.py +++ b/glustolibs-gluster/glustolibs/gluster/dht_test_utils.py @@ -342,6 +342,40 @@ def find_new_hashed(subvols, parent_path, oldname): return None +def find_specific_hashed(subvols, parent_path, subvol): + """ 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 + + Returns: + (Class Object): For success returns an object of type NewHashed + holding information pertaining to new name. + None, otherwise + Note: The new hash will be searched under the same parent + """ + # pylint: disable=protected-access + brickobject = create_brickobjectlist(subvols, parent_path) + if brickobject is None: + g.log.error("could not form brickobject list") + return None + count = -1 + for item in range(1, 5000, 1): + newhash = calculate_hash(brickobject[0]._host, str(item)) + for brickdir in brickobject: + count += 1 + if subvol._fqpath == brickdir._fqpath: + ret = brickdir.hashrange_contains_hash(newhash) + if ret: + g.log.debug("oldhashed %s new %s count %s", + subvol, brickdir._host, str(count)) + return NewHashed(item, brickdir, count) + count = -1 + return None + + class NewHashed(object): ''' Helper Class to hold new hashed info -- cgit