summaryrefslogtreecommitdiffstats
path: root/libs/utils/atfutils.py
diff options
context:
space:
mode:
authorShwetha-H-Panduranga <shwetha@gluster.com>2012-02-03 15:52:29 +0530
committerShwetha-H-Panduranga <shwetha@gluster.com>2012-02-06 21:08:26 +0530
commit2e06fd3e78331c0352fb9992a7ca3f49f86a2f54 (patch)
treeb61b1b25dca1a35a5acd12906d6d116b0d73498d /libs/utils/atfutils.py
parent39329e86b7cc99a5d44e88f53ffc60ac46d2879b (diff)
Changing the return value of all the libraries. The libraries will return a dictionary with 'exitstatus', 'stdoutdata', 'stderrdata' as keys. The value of 'exitstatus' is the exit status of the command execution. The 'stdoutdata' contains data written to the stdout during command execution. The 'stderrdata' contains data written to stderr during command execution.
Change-Id: Ib04062ab34ddf6cf1d8bde07716c4a3be1800ec5 Signed-off-by: Shwetha-H-Panduranga <shwetha@gluster.com>
Diffstat (limited to 'libs/utils/atfutils.py')
-rw-r--r--libs/utils/atfutils.py116
1 files changed, 84 insertions, 32 deletions
diff --git a/libs/utils/atfutils.py b/libs/utils/atfutils.py
index d1c4e0a..1f0d499 100644
--- a/libs/utils/atfutils.py
+++ b/libs/utils/atfutils.py
@@ -6,32 +6,74 @@
*) print_stderr
*) set_active_volume
"""
-
import re
-import ssh
+import inspect
from atfglobals import GlobalObj
+commands = {
+ 'wc' : 'wc',
+ 'ls' : 'ls',
+ 'stat' : 'stat',
+ 'echo' : 'echo',
+ 'cat' : 'cat',
+ 'touch' : 'touch',
+ 'rename': 'mv',
+ 'unlink': 'rm',
+ 'dd' : 'dd',
+ 'chmod' : 'chmod',
+ 'chown' : 'chown',
+ 'mkdir' : 'mkdir -p',
+ 'mkfs' : 'mkfs',
+ 'mount' : 'mount',
+ 'umount' : 'umount',
+ 'hardlink' : 'ln',
+ 'symlink' : 'ln -s',
+ 'setattr' : 'setfattr',
+ 'getattr' : 'getfattr',
+ 'truncate' : 'truncate',
+ 'unlink_force' : 'rm -f',
+ 'unlink_dir_force' : 'rm -rf'
+ }
+
+def get_new_output_obj():
+ output = {}
+ for key in ('exitstatus', 'stdoutdata', 'stderrdata'):
+ output[key] = None
+ return output
+
def assert_success(exit_status):
"""
"""
- if exit_status is None:
+ if exit_status is not 0:
return 1
-
- if not exit_status:
- return 0
else:
- return 1
+ return 0
def assert_failure(exit_status):
"""
"""
- if exit_status is None:
+ if exit_status is 0:
return 1
-
- if exit_status:
- return 0
else:
+ return 0
+
+def assert_success_of_outputs(outputs):
+ """
+ """
+ caller = inspect.stack()[1][3]
+ logger = GlobalObj.getLoggerObj()
+ assert_success_flag = True
+ for key in outputs.keys():
+ output = outputs[key]
+ assert_success_status = assert_success(output["exitstatus"])
+ if assert_success_status is not 0:
+ assert_success_flag = False
+ logger.error("%s Failed to Execute %s") % (key, caller)
+
+ if assert_success_flag is False:
return 1
+ else:
+ return 0
def expect(actual_string, expected_string):
"""
@@ -42,14 +84,14 @@ def expect(actual_string, expected_string):
matched = False
if not expected_string:
matched = True
-
else:
if re.search(new_pattern, actual_string):
matched = True
return matched
-def validate_output(output, expected_exit_status, expected_output, stream="stdout"):
+def validate_output(output, expected_exit_status, expected_output,
+ stream="stdout"):
"""
Parameters:
output: This is dictionary which is return value of
@@ -66,21 +108,38 @@ def validate_output(output, expected_exit_status, expected_output, stream="stdou
False: if output doesn't match with expected_exit_status or
expected_output
"""
- output_status = False
- if expected_exit_status is not 0:
- exit_status = assert_failure(output['exitstatus'])
- else:
- exit_status = assert_success(output['exitstatus'])
+ logger = GlobalObj.getLoggerObj()
+ exit_status_match = False
+ output_data_match = False
- if stream is "stdout":
- output_status = expect(str(output['stdoutdata']),
- expected_output)
+ if None in (output["stdoutdata"], output["stderrdata"]):
+ logger.error("Error in Test Environment")
+ return 1
- elif stream is "stderr":
- output_status = expect(str(output['stderrdata']),
- expected_output)
+ if expected_exit_status is not 0:
+ assert_exit_status = assert_failure(output['exitstatus'])
+ else:
+ assert_exit_status = assert_success(output['exitstatus'])
+ if assert_exit_status is 0:
+ exit_status_match = True
- if output_status is True and (not exit_status):
+ if not expected_output:
+ output_data_match = True
+ else:
+ if stream is "stderr":
+ actual_output = str(output['stderrdata'])
+ else:
+ actual_output = str(output['stdoutdata'])
+ output_data_match = expect(actual_output, expected_output)
+
+ if exit_status_match is False:
+ logger.error("Expected exit status is '%s'.Actual exit status is '%s'" %
+ (expected_exit_status, exit_status))
+ if output_data_match is False:
+ logger.error("Expected ouput is '%s'.Actual output is '%s'" %
+ (expected_output, actual_output))
+
+ if (exit_status_match and output_data_match) is True:
return 0
else:
return 1
@@ -119,10 +178,3 @@ def get_active_volume():
if active_volume is None:
logger.error("Active Volume not set in the TestEnvironment")
return active_volume
-
-__all__ = ['assert_success',
- 'assert_failure',
- 'print-stdout',
- 'print_stderr',
- 'set_active_volume',
- 'get_active_volume']