summaryrefslogtreecommitdiffstats
path: root/glustolibs-gluster/glustolibs/gluster/dht_test_utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'glustolibs-gluster/glustolibs/gluster/dht_test_utils.py')
-rw-r--r--glustolibs-gluster/glustolibs/gluster/dht_test_utils.py138
1 files changed, 108 insertions, 30 deletions
diff --git a/glustolibs-gluster/glustolibs/gluster/dht_test_utils.py b/glustolibs-gluster/glustolibs/gluster/dht_test_utils.py
index 692f09baf..11f2eda62 100644
--- a/glustolibs-gluster/glustolibs/gluster/dht_test_utils.py
+++ b/glustolibs-gluster/glustolibs/gluster/dht_test_utils.py
@@ -1,5 +1,5 @@
#!/usr/bin/env python
-# Copyright (C) 2018 Red Hat, Inc. <http://www.redhat.com>
+# Copyright (C) 2018-2020 Red Hat, Inc. <http://www.redhat.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -21,32 +21,43 @@ import os
from glusto.core import Glusto as g
-from glustolibs.gluster.glusterfile import GlusterFile, calculate_hash
+from glustolibs.gluster.glusterfile import (GlusterFile, calculate_hash,
+ get_pathinfo, file_exists)
from glustolibs.gluster.glusterdir import GlusterDir
from glustolibs.gluster.layout import Layout
import glustolibs.gluster.constants as k
import glustolibs.gluster.exceptions as gex
from glustolibs.gluster.brickdir import BrickDir
-from glustolibs.gluster.volume_libs import get_subvols
+from glustolibs.gluster.volume_libs import get_subvols, get_volume_type
+from glustolibs.misc.misc_libs import upload_scripts
-def run_layout_tests(fqpath, layout, test_type):
+def run_layout_tests(mnode, fqpath, layout, test_type):
"""run the is_complete and/or is_balanced tests"""
- if test_type & k.TEST_LAYOUT_IS_COMPLETE:
- g.log.info("Testing layout complete for %s" % fqpath)
- if not layout.is_complete:
- msg = ("Layout for %s IS NOT COMPLETE" % fqpath)
- g.log.error(msg)
- raise gex.LayoutIsNotCompleteError(msg)
- if test_type & k.TEST_LAYOUT_IS_BALANCED:
- g.log.info("Testing layout balance for %s" % fqpath)
- if not layout.is_balanced:
- msg = ("Layout for %s IS NOT BALANCED" % fqpath)
- g.log.error(msg)
- raise gex.LayoutIsNotBalancedError(msg)
-
- # returning True until logic requires non-exception error check(s)
- return True
+ ret = get_pathinfo(mnode, fqpath)
+ brick_path_list = ret.get('brickdir_paths')
+ for brickdir_path in brick_path_list:
+ (server_ip, _) = brickdir_path.split(':')
+ if get_volume_type(brickdir_path) in ('Replicate', 'Disperse',
+ 'Arbiter'):
+ g.log.info("Cannot check for layout completeness as"
+ " volume under test is Replicate/Disperse/Arbiter")
+ else:
+ if test_type & k.TEST_LAYOUT_IS_COMPLETE:
+ g.log.info("Testing layout complete for %s" % fqpath)
+ if not layout.is_complete:
+ msg = ("Layout for %s IS NOT COMPLETE" % fqpath)
+ g.log.error(msg)
+ raise gex.LayoutIsNotCompleteError(msg)
+ if test_type & k.TEST_LAYOUT_IS_BALANCED:
+ g.log.info("Testing layout balance for %s" % fqpath)
+ if not layout.is_balanced:
+ msg = ("Layout for %s IS NOT BALANCED" % fqpath)
+ g.log.error(msg)
+ raise gex.LayoutIsNotBalancedError(msg)
+
+ # returning True until logic requires non-exception error check(s)
+ return True
def run_hashed_bricks_test(gfile):
@@ -62,13 +73,13 @@ def run_hashed_bricks_test(gfile):
return True
-def validate_files_in_dir(host, rootdir,
+def validate_files_in_dir(mnode, rootdir,
file_type=k.FILETYPE_ALL,
test_type=k.TEST_ALL):
"""walk a directory tree and check if layout is_complete.
Args:
- host (str): The host of the directory being traversed.
+ mnode (str): The host of the directory being traversed.
rootdir (str): The fully qualified path of the dir being traversed.
file_type (int): An or'd set of constants defining the file types
to test.
@@ -108,16 +119,32 @@ def validate_files_in_dir(host, rootdir,
"""
layout_cache = {}
- conn = g.rpyc_get_connection(host)
-
- for walkies in conn.modules.os.walk(rootdir):
+ script_path = ("/usr/share/glustolibs/scripts/walk_dir.py")
+ if not file_exists(mnode, script_path):
+ if upload_scripts(mnode, script_path,
+ "/usr/share/glustolibs/scripts/"):
+ g.log.info("Successfully uploaded script "
+ "walk_dir.py!")
+ else:
+ g.log.error("Faild to upload walk_dir.py!")
+ return False
+ else:
+ g.log.info("compute_hash.py already present!")
+
+ cmd = ("/usr/bin/env python {0} {1}".format(script_path, rootdir))
+ ret, out, _ = g.run(mnode, cmd)
+ if ret:
+ g.log.error('Unable to run the script on node {0}'
+ .format(mnode))
+ return False
+ for walkies in eval(out):
g.log.info("TESTING DIRECTORY %s..." % walkies[0])
# check directories
if file_type & k.FILETYPE_DIR:
for testdir in walkies[1]:
fqpath = os.path.join(walkies[0], testdir)
- gdir = GlusterDir(host, fqpath)
+ gdir = GlusterDir(mnode, fqpath)
if gdir.parent_dir in layout_cache:
layout = layout_cache[gdir.parent_dir]
@@ -125,7 +152,7 @@ def validate_files_in_dir(host, rootdir,
layout = Layout(gdir.parent_dir_pathinfo)
layout_cache[gdir.parent_dir] = layout
- run_layout_tests(gdir.parent_dir, layout, test_type)
+ run_layout_tests(mnode, gdir.parent_dir, layout, test_type)
if test_type & k.TEST_FILE_EXISTS_ON_HASHED_BRICKS:
run_hashed_bricks_test(gdir)
@@ -134,7 +161,7 @@ def validate_files_in_dir(host, rootdir,
if file_type & k.FILETYPE_FILE:
for file in walkies[2]:
fqpath = os.path.join(walkies[0], file)
- gfile = GlusterFile(host, fqpath)
+ gfile = GlusterFile(mnode, fqpath)
if gfile.parent_dir in layout_cache:
layout = layout_cache[gfile.parent_dir]
@@ -142,11 +169,11 @@ def validate_files_in_dir(host, rootdir,
layout = Layout(gfile.parent_dir_pathinfo)
layout_cache[gfile.parent_dir] = layout
- run_layout_tests(gfile.parent_dir, layout, test_type)
+ run_layout_tests(mnode, gfile.parent_dir, layout,
+ test_type)
if test_type & k.TEST_FILE_EXISTS_ON_HASHED_BRICKS:
run_hashed_bricks_test(gfile)
-
return True
@@ -281,11 +308,22 @@ def find_new_hashed(subvols, parent_path, oldname):
g.log.error("could not form brickobject list")
return None
+ for bro in brickobject:
+ bro._get_hashrange()
+ low = bro._hashrange_low
+ high = bro._hashrange_high
+ g.log.debug("low hashrange %s high hashrange %s", str(low), str(high))
+ g.log.debug("absoulte path %s", bro._fqpath)
+
+ hash_num = calculate_hash(brickobject[0]._host, oldname)
oldhashed, _ = find_hashed_subvol(subvols, parent_path, oldname)
if oldhashed is None:
g.log.error("could not find old hashed subvol")
return None
+ g.log.debug("oldhashed: %s oldname: %s oldhash %s", oldhashed._host,
+ oldname, hash_num)
+
count = -1
for item in range(1, 5000, 1):
newhash = calculate_hash(brickobject[0]._host, str(item))
@@ -293,7 +331,7 @@ def find_new_hashed(subvols, parent_path, oldname):
count += 1
ret = brickdir.hashrange_contains_hash(newhash)
if ret == 1:
- if oldhashed._host != brickdir._host:
+ if oldhashed._fqpath != brickdir._fqpath:
g.log.debug("oldhashed %s new %s count %s",
oldhashed, brickdir._host, str(count))
return NewHashed(item, brickdir, count)
@@ -302,6 +340,44 @@ def find_new_hashed(subvols, parent_path, oldname):
return None
+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
+ holding information pertaining to new name.
+ None, otherwise
+ 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")
+ 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 and
+ item not in existing_names):
+ 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
@@ -380,3 +456,5 @@ def is_layout_complete(mnode, volname, dirpath):
return False
elif hash_difference < 1:
g.log.error("Layout has overlaps")
+
+ return True