summaryrefslogtreecommitdiffstats
path: root/libs/utils/clientutils.py
diff options
context:
space:
mode:
Diffstat (limited to 'libs/utils/clientutils.py')
-rw-r--r--libs/utils/clientutils.py150
1 files changed, 68 insertions, 82 deletions
diff --git a/libs/utils/clientutils.py b/libs/utils/clientutils.py
index 347e159..57810d5 100644
--- a/libs/utils/clientutils.py
+++ b/libs/utils/clientutils.py
@@ -11,6 +11,7 @@ Supported Wrappers :-
import atfutils
import hostutils
+from atfutils import commands
from atfglobals import GlobalObj
def umount(mountkey):
@@ -25,38 +26,28 @@ def umount(mountkey):
Failure : 1`
"""
logger = GlobalObj.getLoggerObj()
- base_command = "umount"
- env = GlobalObj.getTestenvObj()
- cm = GlobalObj.getConnectionsManagerObj()
+ output = atfutils.get_new_output_obj()
+ 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
- client_connection = cm.getConnection(clientkey)
- if not client_connection:
- logger.error("SSH connection to host '%s' has not been established"
- % clientkey)
- return 1
-
- command = ' '.join([base_command, mount_obj.dir])
- logger.debug('%s: Executing Command: %s' % (clientkey, command))
- output = client_connection.executecommand(command)
- return_status = atfutils.assert_success(output['exitstatus'])
- atfutils.print_stdout(output['stdoutdata'])
- atfutils.print_stderr(output['stderrdata'])
- if return_status:
+ command = ' '.join([commands['umount'], mount_obj.dir])
+ output = hostutils.execute_command(clientkey, command)
+ assert_success_status = atfutils.assert_success(output['exitstatus'])
+ if assert_success_status is not 0:
stdoutdata = str(output["stdoutdata"])
if ((stdoutdata.rfind("not found")) or (stdoutdata.rfind("not mount"))):
- return_status = 0
-
+ output["exitstatus"] = 0
else:
logger.error("Unable to umount %s" % mountkey)
- return return_status
+ return output
def umountall():
"""unmounts all mount specified in testenv.cfg file.
@@ -69,19 +60,19 @@ def umountall():
Success : 0
Failure : 1`
"""
- env = GlobalObj.getTestenvObj()
- failure_flag = False
+ umountall_output = atfutils.get_new_output_obj()
+ env = GlobalObj.getTestenvObj()
mounts_keys = env.getMountsKeys()
for mountkey in mounts_keys:
- return_status = umount(mountkey)
- if return_status:
- failure_flag = True
+ output = umount(mountkey)
+ assert_success_status = atfutils.assert_success(output['exitstatus'])
+ if assert_success_status is not 0:
+ return output
- if failure_flag:
- return 1
- else:
- return 0
+ umountall_output["exitstatus"] = 0
+ umountall_output["stdoutdata"] = "Successful in unmounting all mounts"
+ return umountall_output
def mount(mountkey):
"""mounts a filesystem
@@ -95,48 +86,42 @@ def mount(mountkey):
Failure : 1`
"""
logger = GlobalObj.getLoggerObj()
- base_command = "mount"
- env = GlobalObj.getTestenvObj()
- cm = GlobalObj.getConnectionsManagerObj()
- command = [base_command]
- options = []
+ output = atfutils.get_new_output_obj()
+ 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
- client_connection = cm.getConnection(clientkey)
- if not client_connection:
- logger.error("SSH connection to host '%s' has not been established"
- % clientkey)
- return 1
+ #mount command
+ command = [commands['mount']]
- return_status = hostutils.mkdir(clientkey, mount_obj.dir)
- if return_status:
- return return_status
+ #mount type
+ command.extend(["-t", mount_obj.type])
- mountdevice_obj = mount_obj.device
- device = mountdevice_obj.hostname + ":/" + mountdevice_obj.volumename
- options.extend(["-t", mount_obj.type])
- if mount_obj.logfile:
- options.extend(["-o", ("log-file="+mount_obj.logfile),
- "log-level=INFO"])
+ #mount options if specified
if mount_obj.options:
- options.extend([mount_obj.option])
- options.extend([device, mount_obj.dir])
+ command.extend(["-o", mount_obj.options])
- command.extend(options)
+ #mount device
+ mountdevice_obj = mount_obj.device
+ device = mountdevice_obj.hostname + ":/" + mountdevice_obj.volumename
+ command.extend([device, mount_obj.dir])
command = ' '.join(command)
- logger.debug('%s: Executing Command: %s' % (clientkey, command))
- output = client_connection.executecommand(command)
- return_status = atfutils.assert_success(output['exitstatus'])
- atfutils.print_stdout(output['stdoutdata'])
- atfutils.print_stderr(output['stderrdata'])
- return return_status
+ clientkey = mount_obj.client
+ #create mount directory
+ output = hostutils.mkdir(clientkey, mount_obj.dir)
+ assert_success_status = atfutils.assert_success(output["exitstatus"])
+ if assert_success_status is not 0:
+ return output
+
+ #execute mount command
+ output = hostutils.execute_command(clientkey, command)
+ return output
def mountall():
"""mounts a filesystem for all mounts specified in testenv.cfg file.
@@ -148,15 +133,19 @@ def mountall():
Success : 0
Failure : 1`
"""
- env = GlobalObj.getTestenvObj()
+ mountall_output = atfutils.get_new_output_obj()
+ env = GlobalObj.getTestenvObj()
mounts_keys = env.getMountsKeys()
for mountkey in mounts_keys:
- return_status = mount(mountkey)
- if return_status:
- return return_status
+ output = mount(mountkey)
+ assert_success_status = atfutils.assert_success(output['exitstatus'])
+ if assert_success_status is not 0:
+ return output
- return 0
+ mountall_output["exitstatus"] = 0
+ mountall_output["stdoutdata"] = "Successful in mounting all mounts"
+ return mountall_output
def md5sum_of_mount(mountkey):
"""
@@ -167,12 +156,9 @@ def md5sum_of_mount(mountkey):
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()
+ output = atfutils.get_new_output_obj()
+
env = GlobalObj.getTestenvObj()
mount_obj = env.getMount(mountkey)
if not mount_obj:
@@ -210,12 +196,9 @@ def md5sum_of_mounts(mounts):
def execute_on_mount(mountkey, command, commandInput=None):
"""
"""
- output = {}
- output["exitstatus"] = None
- output["stdoutdata"] = None
- output["stderrdata"] = None
-
logger = GlobalObj.getLoggerObj()
+ output = atfutils.get_new_output_obj()
+
env = GlobalObj.getTestenvObj()
mount_obj = env.getMount(mountkey)
if not mount_obj:
@@ -224,16 +207,19 @@ def execute_on_mount(mountkey, command, commandInput=None):
output["exitstatus"] = 1
return output
-
clientkey = mount_obj.client
mountdir = mount_obj.dir
- command = "cd " + mountdir + " ;" + command
+ command = "cd %s ; %s" % (mountdir , command)
output = hostutils.execute_command(clientkey, command, commandInput)
return output
-__all__ = ['execute_on_mount',
- 'md5sum_of_mounts',
- 'umount',
- 'umountall',
- 'mount',
- 'mountall']
+def execute_on_mounts(mounts, command, commandInput=None):
+ """
+ """
+ all_outputs = {}
+
+ for mountkey in mounts:
+ output = execute_on_mount(mountkey, command, commandInput)
+ all_outputs[mountkey] = output
+
+ return all_outputs