summaryrefslogtreecommitdiffstats
path: root/libs/utils/serverutils.py
diff options
context:
space:
mode:
Diffstat (limited to 'libs/utils/serverutils.py')
-rw-r--r--libs/utils/serverutils.py112
1 files changed, 102 insertions, 10 deletions
diff --git a/libs/utils/serverutils.py b/libs/utils/serverutils.py
index 068dd17..10fe830 100644
--- a/libs/utils/serverutils.py
+++ b/libs/utils/serverutils.py
@@ -3,6 +3,98 @@
import re
import hostutils
from atfglobals import GlobalObj
+import atfutils
+
+def md5sum_of_brick(brickkey):
+ """
+ Parameter: brick (tye: string)
+ Returns: output of arequal-checksum command execution(type:dict)
+ Key : Value of the Output
+ exitstatus: exit status of the arequal-checksum command on brick
+ stdoutdata: stdout data of arequal-checksum command execution
+ stderrdata: stderr data of arequal-checksum command execution
+ """
+ output = {}
+ output["exitstatus"] = None
+ output["stdoutdata"] = None
+ output["stderrdata"] = None
+ logger = GlobalObj.getLoggerObj()
+ env = GlobalObj.getTestenvObj()
+
+ raw_brick_obj = env.getRawBrick(brickkey)
+ if not raw_brick_obj:
+ logger.error("InValid Brick. %s not defined in TestEnvironment" %
+ brickkey)
+ output["exitstatus"] = 1
+ return output
+
+ else:
+ serverkey = re.split("\.", raw_brick_obj.hostname, maxsplit=1)[0]
+
+ brick_obj = env.getBrick(brickkey)
+ if not brick_obj:
+ logger.error("InValid Brick. %s not defined in TestEnvironment"
+ % brickkey)
+ output["exitstatus"] = 1
+ return output
+ else:
+ brick_path = brick_obj.path
+
+ output = hostutils.md5sum(serverkey, brick_path)
+ return output
+
+def md5sum_of_bricks(bricks):
+ """
+ Description:
+ Calculate md5sum of bricks using arequal-checksum
+
+ Parameters: bricks (type: List)
+
+ Returns: md5sums of all the bricks (type: dict)
+ Keys: bricks
+ Value: ouput (type:dict)
+ exitstatus: exit status of the arequal-checksum command on brick
+ stdoutdata: stdout data of arequal-checksum command execution
+ stderrdata: stderr data of arequal-checksum command execution
+ """
+ md5sums = {}
+ for brickkey in bricks:
+ output = md5sum_of_brick(brickkey)
+ md5sums[brickkey] = output
+
+ return md5sums
+
+def get_gfid_on_brick(brickkey, filename="."):
+ """
+ """
+ output = {}
+ output["exitstatus"] = None
+ output["stdoutdata"] = None
+ output["stderrdata"] = None
+ base_command = "getfattr -n 'trusted.gfid' -e hex"
+ command = ' '.join([base_command, filename])
+ output = execute_on_brick(brickkey, command)
+ if atfutils.assert_success(output['exitstatus']):
+ atfutils.print_stdout(output['stdoutdata'])
+ atfutils.print_stderr(output['stderrdata'])
+
+ elif output['stdoutdata'] is None or (not output['stdoutdata']):
+ output['stdoutdata'] = ""
+
+ else:
+ output['stdoutdata'] = str(output['stdoutdata'])
+
+ return output
+
+def get_gfid_on_bricks(bricks, filename="."):
+ """
+ """
+ gfid_on_bricks = {}
+ for brickkey in bricks:
+ output = get_gfid_on_brick(brickkey, filename)
+ gfid_on_bricks[brickkey] = output
+
+ return gfid_on_bricks
def execute_on_brick(brickkey, command, commandInput=None):
"""
@@ -11,7 +103,7 @@ def execute_on_brick(brickkey, command, commandInput=None):
output["exitstatus"] = None
output["stdoutdata"] = None
output["stderrdata"] = None
-
+
logger = GlobalObj.getLoggerObj()
env = GlobalObj.getTestenvObj()
@@ -19,23 +111,23 @@ def execute_on_brick(brickkey, command, commandInput=None):
if not raw_brick_obj:
logger.error("InValid Brick. %s not defined in TestEnvironment"
% brickkey)
+ output["exitstatus"] = 1
return output
- serverkey = re.split("\.", raw_brick_obj.hostname, maxsplit=1)[0]
-
+ else:
+ serverkey = re.split("\.", raw_brick_obj.hostname, maxsplit=1)[0]
+
brick_obj = env.getBrick(brickkey)
if not brick_obj:
logger.error("InValid Brick. %s not defined in TestEnvironment"
% brickkey)
+ output["exitstatus"] = 1
return output
- exportdirpath = brick_obj.path
+ else:
+ exportdirpath = brick_obj.path
command = "cd " + exportdirpath + ";" + command
output = hostutils.execute_command(serverkey, command, commandInput)
return output
-__all__ = ['execute_on_brick']
-
-
-
-
-
+__all__ = ['execute_on_brick',
+ 'md5sum_of_bricks']