summaryrefslogtreecommitdiffstats
path: root/atf.py
diff options
context:
space:
mode:
Diffstat (limited to 'atf.py')
-rwxr-xr-xatf.py319
1 files changed, 319 insertions, 0 deletions
diff --git a/atf.py b/atf.py
new file mode 100755
index 0000000..e60bbb9
--- /dev/null
+++ b/atf.py
@@ -0,0 +1,319 @@
+#!/usr/bin/env python
+
+import sys
+import argparse
+import ConfigParser
+import ATFInit
+import ATFSetup
+import ATFExecute
+import ATFCleanup
+import ATFUtils
+
+##########################################################################
+## commandline : command executed to start the TestRun.
+##########################################################################
+commandline = ''
+
+##########################################################################
+## Configuration File Parser Object
+##########################################################################
+Config = ConfigParser.SafeConfigParser()
+
+def ConfigSectionMap(section):
+ """
+ Description:
+ Get the key=value pair for the Section 'section' in the Config File
+
+ Parameters:
+ section: Section Name in the Config File
+
+ Returns:
+ Success: Dictionary: List of key=value pairs from section 'section'
+ Failure: 1
+ """
+
+ dict1 = {}
+
+ try:
+ options = Config.options(section)
+
+ except ConfigParser.NoSectionError:
+ return 1
+
+ else:
+ for option in options:
+ dict1[option] = Config.get(section, option)
+
+ return dict1
+
+def parse_configfile(filename):
+ """
+ Description:
+ Function to Parse the Configuration file
+
+ Parameters:
+ filename: Name of the configuration file
+
+ Returns:
+ Success: 0
+ Failure: 1
+ """
+
+ keyword = ''
+ workunit = ''
+
+ status = Config.read(filename)
+
+ if status == []:
+ print "Configuration File: " + filename + "Not Found"
+ return 1
+ else:
+ ### Parse Section: [Keywords] ###
+ Map = ConfigSectionMap('Keywords')
+
+ if Map == 1:
+ print "Section: [Keywords] Not Found"
+ return 1
+ else:
+ keyword = Map['keystring']
+ ATFUtils.TestsObj.add_keywords(keyword)
+
+ ### Parse Section: [WorkUnits] ###
+ Map = ConfigSectionMap('WorkUnits')
+
+ if Map == 1:
+ print "Section: [WorkUnits] Not Found"
+ return 1
+ else:
+ for key in Map.keys():
+ workunit = Map[key]
+ ATFUtils.TestsObj.add_testunits(workunit)
+ ATFUtils.TestsObj.sort_testunits()
+
+ ### Parse Section: [ATFRoot] ###
+ Map = ConfigSectionMap('ATFRoot')
+
+ if Map == 1:
+ print "Section: [ATFRoot] Not Found"
+ return 1
+ else:
+ atfroot = Map['rootdir']
+
+ if atfroot == None:
+ print "ATF_ROOT Not defined. "
+ return 1
+ else:
+ if ATFUtils.set_environ(ATF_ROOT = atfroot):
+ return 1
+
+ ### Parse Section: [SummaryLog] ###
+ Map = ConfigSectionMap('SummaryLog')
+
+ if Map == 1:
+ print "Section: [SummaryLog] Not Found"
+ return 1
+ else:
+ summarylog_filename = Map['filename']
+ summarylog_level = Map['loglevel']
+
+ if summarylog_filename == None:
+ summarylog_filename = 'SummaryLog.out'
+
+ if summarylog_level == None:
+ summarylog_level = 'INFO'
+
+ ATFUtils.LogObj.set_summarylog(filename=summarylog_filename,
+ loglevel=summarylog_level)
+ abspath = atfroot + "/" + summarylog_filename
+
+ if ATFUtils.set_environ(ATF_SUMMARYLOG = abspath):
+ return 1
+
+ ### Parse Detail Log Section ###
+ Map = ConfigSectionMap('DetailLog')
+
+ if Map == 1:
+ print "Section: [DetailLog] Not Found"
+ return 1
+ else:
+ detaillog_filename = Map['filename']
+ detaillog_level = Map['loglevel']
+
+ if detaillog_filename == None:
+ detaillog_filename = 'DetailLog.out'
+
+ if detaillog_level == None:
+ detaillog_level = 'DEBUG'
+
+ ATFUtils.LogObj.set_detaillog(filename=detaillog_filename,
+ loglevel=detaillog_level)
+
+ ### Parse Stdout Log Section ###
+ Map = ConfigSectionMap('StdoutLog')
+
+ if Map == 1:
+ print "Section: [StdoutLog] Not Found"
+ else:
+ stdoutlog_log = Map['do_log']
+ stdoutlog_level = Map['loglevel']
+
+ if stdoutlog_log == 'true':
+ if stdoutlog_level == None:
+ stdoutlog_level = 'INFO'
+ ATFUtils.LogObj.set_stdoutlog(loglevel=stdoutlog_level)
+
+ ### Parse GlobalParam Section ###
+ Map = ConfigSectionMap('GlobalParam')
+
+ if Map == 1:
+ print "Section: [GlobalParam] Not Found"
+ return 1
+ else:
+ globalparamfile = Map['filename']
+
+ if globalparamfile == None:
+ print "Global Param File Not defined."
+ return 1
+ else :
+ ATFUtils.TestEnvObj.set_globalparamfile(globalparamfile)
+
+ #### Log the contents of Config File to SummaryLog and Stdout ####
+ abspath = atfroot + "/" + summarylog_filename
+
+ try:
+ fhr = open(filename, "r")
+
+ except IOError:
+ print "IOError: Cannot Open Config FIle for Reading" + abspath
+ return 1
+
+ else:
+ try:
+ fhw = open(abspath, "w")
+
+ except IOError:
+ print "IOError: Cannot Open Summary Log FIle " + abspath
+ fhr.close()
+ return 1
+
+ else:
+ lines = fhr.readlines()
+ fhw.write("Starting the Glusterfs Regression Tests")
+ fhw.write("\n\nCommandLine: " + commandline + "\n\n")
+ fhw.write(("-" * 50) + "\nConfiguration File Contents: \n" +
+ ("-" * 50) + "\n")
+ fhw.writelines(lines)
+
+ fhw.close()
+ fhr.close()
+
+ return 0
+
+def main(args):
+ """
+ Description:
+ 1) Parse the Configuration File
+ 2) Initialize the Loggers, TestEnvironment
+ 3) Set-up TestBed for TestRun Execution
+ 4) Execute the Tests for the WorkUnits Specified
+ 5) Cleanup the TestEnvironment after the Test Execution is complete
+
+ Parameters:
+ args: Command Line Arguments passed to 'atf'
+
+ Returns:
+ Success: 0
+ Failure: 1
+ """
+
+ configfilename = args.file[0]
+ if parse_configfile(configfilename):
+ exit(1)
+
+ if ATFInit.initialize():
+ exit(1)
+
+ if ATFSetup.setup():
+ exit(1)
+
+ if ATFExecute.execute():
+ exit(1)
+
+ if ATFCleanup.cleanup():
+ exit(1)
+
+ else:
+ exit(0)
+
+if __name__ == "__main__":
+
+ for arg in sys.argv:
+ commandline = commandline + arg + " "
+
+ parser = argparse.ArgumentParser(
+ description="Runs GlusterFS Regression Test Suite",
+ epilog="Report Bugs to dl-qa@gluster.com")
+
+ parser.add_argument('-f', '--file', nargs=1, required=True, type=str,
+ help="Configuration FIleName")
+
+ args = parser.parse_args()
+
+ main(args)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+