From 4a0b5f9d0e0266c8c67b5faa76599fc78a247437 Mon Sep 17 00:00:00 2001 From: shwetha Date: Tue, 6 Mar 2012 16:14:34 +0530 Subject: Adding libraries to suffix timestamps to the summarylog and detaillog files Change-Id: I853981b0de99372509649360a67e8c4cca24b415 Signed-off-by: shwetha --- atf.py | 36 +++++++++++++++--------------------- atfexecute.py | 9 ++++++--- atfinit.py | 11 ++++++----- atfsetup.py | 11 +++++++---- libs/globals/atfglobals.py | 33 +++++++++------------------------ libs/utils/atfutils.py | 8 ++++++++ 6 files changed, 51 insertions(+), 57 deletions(-) diff --git a/atf.py b/atf.py index 7ee9d13..3202701 100755 --- a/atf.py +++ b/atf.py @@ -9,15 +9,15 @@ import atfexecute import pdb if __name__ == "__main__": - + argparser = argparse.ArgumentParser( prog='atf', - description="Runs GlusterFS Functional/Regression Test Suite", + description="Runs GlusterFS Functional/Regression Test Suite", epilog="Report Bugs to dl-qa@gluster.com") argparser.add_argument('--atfdir', required=True, type=str, help="Absolute path of directory where automation framework is installed") - + argparser.add_argument('--testruninfo-file', required=True, type=str, help="TestRunInfo FileName") @@ -26,25 +26,29 @@ if __name__ == "__main__": help="SummaryLog Filename") argparser.add_argument('--summarylog-level', type=str, - default='INFO', + default='INFO', help="SummaryLog LogLevel") - + argparser.add_argument('--detaillog-file', type=str, default="detaillog.out", help="DetailLog Filename") - + argparser.add_argument('--detaillog-level', type=str, - default='DEBUG', + default='DEBUG', help="DetailLog LogLevel") - + + argparser.add_argument('--timestamp', type=str, + default='yes', + help="Attach timestamp to Summary/DetailLog Files: yes|no") + argparser.add_argument('--stdout-dolog', type=str, - default='yes', + default='yes', help="Log to Stdout yes|no") argparser.add_argument('--stdoutlog-level', type=str, default='INFO', help="StdoutLog LogLevel") - + args = argparser.parse_args() if atfinit.initialize(args): @@ -52,20 +56,10 @@ if __name__ == "__main__": if atfsetup.setup(): exit(1) - + if atfexecute.execute(): exit(1) else: exit(0) - - - - - - - - - - diff --git a/atfexecute.py b/atfexecute.py index c793cbb..bf5a9db 100644 --- a/atfexecute.py +++ b/atfexecute.py @@ -5,6 +5,7 @@ import sys import imp from atfglobals import GlobalObj import pdb +import atfutils def _execute_testunit(testunitname): """ @@ -20,8 +21,8 @@ def _execute_testunit(testunitname): testunits_maindir = GlobalObj.testunits_maindir testunit_mainmodule = GlobalObj.testunit_mainmodule testunit_abspath = os.path.join(atfdir, testunits_maindir, testunitname) - - + + _file, path, description = imp.find_module(testunit_mainmodule, [testunit_abspath]) @@ -38,9 +39,11 @@ def _execute_testunit(testunitname): (testunit_mainmodule, testunitname)) logger.error("%s execution Failed" % testunitname) return_status = 0 - + else: detaillog_abspath = os.path.join(testunit_abspath, detaillog_file) + if GlobalObj.attach_timestamp is 'yes': + detaillog_abspath = atfutils.attach_timestamp(detaillog_abspath) if logger.addDetaillogHandler(detaillog_abspath, detaillog_level): logger.error("Unbale to add Detaillog Handler for testunit: %s" % testunitname) diff --git a/atfinit.py b/atfinit.py index 39b27fd..5280809 100644 --- a/atfinit.py +++ b/atfinit.py @@ -1,6 +1,6 @@ """atfinit module """ -import os.path +import os from atfglobals import GlobalObj def initialize(args): @@ -11,7 +11,7 @@ def initialize(args): if not (os.path.exists(atfdir) and os.path.isdir(atfdir)): print "ATFDIR '%s' doesn't exist" % atfdir return 1 - + testruninfo_abspath = os.path.abspath(args.testruninfo_file) if not (os.path.exists(testruninfo_abspath) and os.path.isfile(testruninfo_abspath)): @@ -20,8 +20,9 @@ def initialize(args): os.patn.isfile(testruninfo_abspath)): print "TestrunInfoFile '%s' doesn't exist" % args.testruninfo_file return 1 - - GlobalObj.atfdir = atfdir + + GlobalObj.testrunid = os.getpid() + GlobalObj.atfdir = atfdir GlobalObj.testruninfo_file = testruninfo_abspath GlobalObj.detaillog_file = args.detaillog_file GlobalObj.detaillog_level = args.detaillog_level @@ -29,7 +30,7 @@ def initialize(args): GlobalObj.stdoutlog_level = args.stdoutlog_level GlobalObj.summarylog_file = args.summarylog_file GlobalObj.summarylog_level = args.summarylog_level - + GlobalObj.attach_timestamp = args.timestamp return 0 __all__ = ['initialize'] diff --git a/atfsetup.py b/atfsetup.py index f8eb99a..2e7a8eb 100644 --- a/atfsetup.py +++ b/atfsetup.py @@ -4,6 +4,7 @@ import re import os.path from atfglobals import GlobalObj import parser +import atfutils def _setup_loggers(): """ @@ -12,6 +13,8 @@ def _setup_loggers(): GlobalObj.initLoggerObj() atfdir = GlobalObj.atfdir summarylog_file = GlobalObj.summarylog_file + if GlobalObj.attach_timestamp is 'yes': + summarylog_file = atfutils.attach_timestamp(GlobalObj.summarylog_file) summarylog_level = GlobalObj.summarylog_level stdout_dolog = GlobalObj.stdout_dolog stdoutlog_level = GlobalObj.stdoutlog_level @@ -23,7 +26,7 @@ def _setup_loggers(): return return_status if re.match("yes", stdout_dolog, re.IGNORECASE): logger.addStdoutlogHandler(stdoutlog_level) - + return 0 def _setup_testrun_info(): @@ -32,7 +35,7 @@ def _setup_testrun_info(): testrun_info_file = GlobalObj.testruninfo_file return_status = parser.parse_testrun_info_file(testrun_info_file) return return_status - + def setup(): """ # Setup Summary/Detail/Stdout LogHandlers @@ -42,11 +45,11 @@ def setup(): return_status = _setup_loggers() if return_status: return return_status - + return_status = _setup_testrun_info() if return_status: return return_status - + return 0 __all__ = ['setup'] diff --git a/libs/globals/atfglobals.py b/libs/globals/atfglobals.py index f1e6946..3e7ca38 100644 --- a/libs/globals/atfglobals.py +++ b/libs/globals/atfglobals.py @@ -7,7 +7,7 @@ AtfGlobals class wrapps all global objects used in the framework *) ConnectionsManager GlobalObj is 'The Instance' of AtfGlobals which will be referred throughout -the framework utilities. +the framework utilities. """ import testruninfo @@ -21,6 +21,7 @@ class AtfGlobals: self._logger = None self._env = None self._connectionsmanager = None + self.testrunid = None self.logname = "ATFLOG" self.atfdir = None self.testruninfo_file = None @@ -28,6 +29,7 @@ class AtfGlobals: self.summarylog_level = 'INFO' self.detaillog_file = "detaillog.out" self.detaillog_level = 'DEBUG' + self.attach_timestamp = 'yes' self.stdoutlog_dolog = 'yes' self.stdoutlog_level = 'INFO' self.testunits_maindir = "TestUnits" @@ -37,22 +39,22 @@ class AtfGlobals: self.glusterd_dir = "/etc/glusterd/*" self.glusterd_log_paths = ["/var/log/glusterfs/*.log", "/var/log/glusterfs/bricks/*"] - - + + def initLoggerObj(self): """Instantiation of Logger Object """ self._logger = logger.Log(self.logname) - + def getLoggerObj(self): """Returns Logger Object """ return self._logger - + def initConnectionsManagerObj(self): """Instantiation of ConnectionsManager Object """ - self._connectionsmanager = manager.ConnectionsManager() + self._connectionsmanager = manager.ConnectionsManager() def getConnectionsManagerObj(self): """Returns ConnectionsManager Object @@ -68,7 +70,7 @@ class AtfGlobals: """Returns TestrunInfo Object """ return self._testruninfo - + def initTestenvObj(self): """Instantiation of Testenv Object """ @@ -81,20 +83,3 @@ class AtfGlobals: GlobalObj = AtfGlobals() __all__ = ['GlobalObj'] - - - - - - - - - - - - - - - - - diff --git a/libs/utils/atfutils.py b/libs/utils/atfutils.py index b6f5174..b5fa16d 100644 --- a/libs/utils/atfutils.py +++ b/libs/utils/atfutils.py @@ -7,6 +7,7 @@ *) set_active_volume """ import re +import time import inspect from atfglobals import GlobalObj @@ -178,3 +179,10 @@ def get_active_volume(): if active_volume is None: logger.error("Active Volume not set in the TestEnvironment") return active_volume + +def attach_timestamp(filename): + """ + """ + timestamp = time.strftime("%Y_%m_%d_%H_%M_%S") + new_filename = '.'.join([filename, timestamp]) + return new_filename -- cgit