diff options
Diffstat (limited to 'libs/utils/clientutils.py')
-rw-r--r-- | libs/utils/clientutils.py | 203 |
1 files changed, 75 insertions, 128 deletions
diff --git a/libs/utils/clientutils.py b/libs/utils/clientutils.py index 4de2998..347e159 100644 --- a/libs/utils/clientutils.py +++ b/libs/utils/clientutils.py @@ -12,7 +12,6 @@ Supported Wrappers :- import atfutils import hostutils from atfglobals import GlobalObj -import pdb def umount(mountkey): """unmounts a mountpoint @@ -20,22 +19,22 @@ def umount(mountkey): Parameters: mountkey : name given to a mount as specified in testenv.cfg file. Ex:-"mount1" - + Returns: Success : 0 - Failure : 1` + Failure : 1` """ logger = GlobalObj.getLoggerObj() base_command = "umount" env = GlobalObj.getTestenvObj() cm = GlobalObj.getConnectionsManagerObj() - + mount_obj = env.getMount(mountkey) if not mount_obj: logger.error("InValid Mount. '%s' not defined in TestEnvironment" % mountkey) return 1 - + clientkey = mount_obj.client client_connection = cm.getConnection(clientkey) if not client_connection: @@ -56,7 +55,7 @@ def umount(mountkey): else: logger.error("Unable to umount %s" % mountkey) - + return return_status def umountall(): @@ -65,10 +64,10 @@ def umountall(): Parameters: None - + Returns: Success : 0 - Failure : 1` + Failure : 1` """ env = GlobalObj.getTestenvObj() failure_flag = False @@ -90,10 +89,10 @@ def mount(mountkey): Parameters: mountkey : name given to a mount as specified in testenv.cfg file. Ex:-"mount1" - + Returns: Success : 0 - Failure : 1` + Failure : 1` """ logger = GlobalObj.getLoggerObj() base_command = "mount" @@ -101,13 +100,13 @@ def mount(mountkey): cm = GlobalObj.getConnectionsManagerObj() command = [base_command] options = [] - + mount_obj = env.getMount(mountkey) if not mount_obj: logger.error("InValid Mount. %s not defined in TestEnvironment" % mountkey) return 1 - + clientkey = mount_obj.client client_connection = cm.getConnection(clientkey) if not client_connection: @@ -128,10 +127,10 @@ def mount(mountkey): if mount_obj.options: options.extend([mount_obj.option]) options.extend([device, mount_obj.dir]) - + command.extend(options) command = ' '.join(command) - + logger.debug('%s: Executing Command: %s' % (clientkey, command)) output = client_connection.executecommand(command) return_status = atfutils.assert_success(output['exitstatus']) @@ -140,14 +139,14 @@ def mount(mountkey): return return_status def mountall(): - """mounts a filesystem for all mounts specified in testenv.cfg file. + """mounts a filesystem for all mounts specified in testenv.cfg file. Parameters: None - + Returns: Success : 0 - Failure : 1` + Failure : 1` """ env = GlobalObj.getTestenvObj() @@ -159,134 +158,82 @@ def mountall(): return 0 +def md5sum_of_mount(mountkey): + """ + Parameter: mount (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 mount + 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() + mount_obj = env.getMount(mountkey) + if not mount_obj: + logger.error("InValid Mount. %s not defined in TestEnvironment" + % mountkey) + output["exitstatus"] = 1 + return output + + clientkey = mount_obj.client + path = mount_obj.dir + output = hostutils.md5sum(clientkey, path) + return output + +def md5sum_of_mounts(mounts): + """ + Description: + Calculate md5sum of mounts using arequal-checksum + + Parameters: mounts (type: List) + + Returns: md5sums of all the mounts (type: dict) + Keys: mounts + Value: ouput (type:dict) + exitstatus: exit status of the arequal-checksum command on mount + stdoutdata: stdout data of arequal-checksum command execution + stderrdata: stderr data of arequal-checksum command execution + """ + md5sums = {} + for mountkey in mounts: + output = md5sum_of_mount(mountkey) + md5sums[mountkey] = output + + return md5sums def execute_on_mount(mountkey, command, commandInput=None): """ """ + output = {} + output["exitstatus"] = None + output["stdoutdata"] = None + output["stderrdata"] = None + logger = GlobalObj.getLoggerObj() env = GlobalObj.getTestenvObj() mount_obj = env.getMount(mountkey) if not mount_obj: logger.error("InValid Mount. %s not defined in TestEnvironment" % mountkey) - return 1 - - + output["exitstatus"] = 1 + return output + + clientkey = mount_obj.client mountdir = mount_obj.dir command = "cd " + mountdir + " ;" + command output = hostutils.execute_command(clientkey, command, commandInput) return output - + __all__ = ['execute_on_mount', + 'md5sum_of_mounts', 'umount', 'umountall', 'mount', 'mountall'] - -##def umountall(clientkey): -## """ -## """ -## base_command = "umount " -## env = GlobalObj.get_testenv_obj() -## cm = GlobalObj.get_connectionsmanager_obj() -## client_obj = env.getclient(clientkey) -## mountdir = client_obj.mountdir -## volume = client_obj.device -## client = cm.getconnection(clientkey) -## -## mountpoints = [] -## success_flag = False -## failure_flag = False -## command = "mount | grep " + mountdir -## output = client.executecommand(command) -## if not output["exitstatus"]: -## for data in output["stdoutdata"]: -## mountpoints.append(data.split(" ")[2]) -## -## for mountpoint in mountpoints: -## command = base_command + mountpoint -## output = client.executecommand(command) -## return_code = utils.assert_success(output['exitstatus']) -## if return_code: -## failure_flag = True -## else: -## success_flag = True -## continue -## -## if failure_flag: -## return 1 -## -## mountpoints = [] -## success_flag = False -## failure_flag = False -## command = "mount | grep " + volume -## output = client.executecommand(command) -## if not output["exitstatus"]: -## for data in output["stdoutdata"]: -## mountpoints.append(data.split(" ")[2]) -## -## for mountpoint in mountpoints: -## command = base_command + mountpoint -## output = client.executecommand(command) -## return_code = utils.assert_success(output['exitstatus']) -## if return_code: -## failure_flag = True -## else: -## success_flag = True -## continue -## -## if failure_flag: -## return 1 -## -## return 0 - -##def cd_mount(mountkey): -## """ -## """ -## env = GlobalObj.getTestenvObj() -## mount_obj = env.getMount(mountkey) -## if not mount_obj: -## print "InValid Mount. %s not defined in TestEnvironment" % mountkey -## return 1 -## -## clientkey = mount_obj.client -## dirpath = mount_obj.dir -## return_status = hostutils.cd(clientkey, dirpath) -## return return_status -## -##def cd_allmounts(): -## """ -## """ -## env = GlobalObj.getTestenvObj() -## mounts_keys = env.getMountsKeys() -## for mountkey in mounts_keys: -## return_status = cd_mount(mountkey) -## if return_status: -## return return_status -## -## return 0 - - - - - - - - - - - - - - - - - - - - - - - - |