From 27b820afb57381e9c61e258f470f2a1c5227581e Mon Sep 17 00:00:00 2001 From: Shwetha-H-Panduranga Date: Tue, 20 Dec 2011 22:03:08 +0530 Subject: Automating Bug2645, Bug2771, Bug2725 --- TestUnits/cli/volume/top/testunit.py | 114 +++++++++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 TestUnits/cli/volume/top/testunit.py (limited to 'TestUnits/cli/volume/top/testunit.py') diff --git a/TestUnits/cli/volume/top/testunit.py b/TestUnits/cli/volume/top/testunit.py new file mode 100644 index 0000000..f0f6b5d --- /dev/null +++ b/TestUnits/cli/volume/top/testunit.py @@ -0,0 +1,114 @@ +"""testunit.py is the main module for the testunit. + +This module "main" function is called from atfexecute to execute the testunit. +""" +from atfglobals import GlobalObj +import os +import parser +import atfutils +import managerutils +import testcases + +reload(testcases) +filename = os.path.abspath(__file__) +dir_path = os.path.dirname(filename) + +def initialize(): + """ + """ + logger = GlobalObj.getLoggerObj() + return_status = 1 + testenv_file = GlobalObj.testenv_file + testenv_abspath = os.path.join(dir_path, testenv_file) + + if not (os.path.isfile(testenv_abspath)): + logger.error("%s not found in %s" % (testenv_file, dir_path)) + + if parser.parse_testenv_configfile(testenv_abspath): + return return_status + if managerutils.ssh_connect_allhosts(): + return return_status + + return 0 + +def setup(): + """ + """ + return_status = 1 + if atfutils.set_active_volume("volume1"): + return return_status + return 0 + +def execute(): + """ + """ + logger = GlobalObj.getLoggerObj() + return_status = 1 + testcaseslist_file = GlobalObj.testcaseslist_file + testcaseslist_abspath = os.path.join(dir_path, testcaseslist_file) + + if not (os.path.isfile(testcaseslist_abspath)): + logger.error("%s not found in %s" % (testcaseslist_file, dir_path)) + return return_status + + else: + testcaseslist = [] + testcaseslist = parser.parse_testcaseslist_file(testcaseslist_abspath) + if not testcaseslist: + logger.error("Skipping TestUnit %s. No testcases to execute" + % dir_path) + return 0 + else: + passedtestcases = 0 + failedtestcases = 0 + selectedtestcases = len(testcaseslist) + + logger.info("Starting TestUnit: '%s' test execution" % dir_path) + testcases.reset_testenv() + testcases.setup_testenv() + for testcase in testcaseslist: + function_obj = getattr(testcases, testcase) + if function_obj: + logger.debug("Starting Test: ' %s '" % testcase) + return_status = function_obj() + if return_status: + logger.debug("TestCase '%s' Failed" % testcase) + failedtestcases +=1 + else: + logger.debug("TestCase '%s' Passed" % testcase) + passedtestcases +=1 + logger.debug("Ending Test: '%s'" % testcase) + else: + logger.info("TestCase %s not defined in 'testcases' module" + % testcase) + continue + + + logger.info("Selected %d : Passed %d, Failed %d" + % (selectedtestcases, + passedtestcases, + failedtestcases)) + + logger.info("Ending TestUnit: '%s' test execution" % dir_path) + + return 0 + +def cleanup(): + """ + """ + pass + +def main(): + """ + """ + return_status = 1 + if initialize(): + return return_status + if setup(): + return return_status + if execute(): + return return_status + if cleanup(): + return return_status + + return 0 -- cgit