def __call__(self, *args, **kw): # this heading displays the test name just as a PREREQUISITES entry needs. self._report.add_heading(repr_test(self.test_name, args, kw), 2) self.starttime = timelib.now() self.info("STARTTIME: %s" % (timelib.strftime("%a, %d %b %Y %H:%M:%S %Z", timelib.localtime(self.starttime)),)) rv = None # in case of exception rv = self._initialize(rv) if rv is not None: # an exception happened return rv # test elapsed time does not include initializer time. teststarttime = timelib.now() # run test_method try: rv = apply(self.test_method, args, kw) except KeyboardInterrupt: if self._debug: ex, val, tb = sys.exc_info() debugger.post_mortem(ex, val, tb) rv = self.abort("%s: aborted by user." % self.test_name) self._finalize(rv) raise except TestFailError, errval: rv = self.failed("Caught Fail exception: %s" % (errval,))
def run_module(self, mod): """run_module(module) Runs the module. The parameter should be a module object, but if it is a string then a module object with that name will be imported. """ cf = self._config ui = self._config.userinterface # user to choose one. user_name = commands.getoutput('whoami') output = commands.getoutput("groups %s" % user_name) user_group = output.split(':')[1].strip() cf.flags.USERGROUP = user_group if cf.flags.USERGROUP.startswith('opsusers'): ui.info("network is in '%s'" % cf.baseurl) if 'stratalight' in cf.baseurl: run_modes = ['MFG', 'NPI', 'RMA', 'GRR'] else: run_modes = ['MFG', 'RMA'] else: run_modes = ['MFG', 'NPI', 'RMA', 'DEV', 'DEBUG', 'ENG', 'GRR'] if cf.has_key('mode'): mode = cf.mode.upper() if mode not in run_modes: ui.error("Run mode specified is not predefined, please choose one of the follow") cf.run_mode = ui.choose(run_modes) else: cf.run_mode = mode else: # don't default to anything. List out the options to the user. ui.error("Run mode missing, please choose one of the following") cf.run_mode = ui.choose(run_modes) while cf.run_mode is None: cf.run_mode = ui.choose(run_modes) # XXX: hardcode it for now. if type(mod) is str: # get the .pyc module specified. mod = self.get_module(mod) # always true...assign properties module_ID and multiModule. if mod: try: version_full_name = file(os.path.join(os.environ["STRATATEST_HOME"], "etc", "VERSION")).read() # remove trailing space and Manufacturing_Test_ from the full # name cf.module_ID = version_full_name.strip() except AttributeError: cf.module_ID = "<unknown>" try: cf.multiModule = mod._MULTI except AttributeError: cf.multiModule = False try: cf.upgrade = mod._UPGRADE except AttributeError: cf.upgrade = False try: cf._IGNORE_SN_CHECK = mod._IGNORE_SN_CHECK except AttributeError: cf._IGNORE_SN_CHECK = False try: cf._FORCE_CHECK_PERMISSION = mod._FORCE_CHECK_PERMISSION except AttributeError: cf._FORCE_CHECK_PERMISSION = False cf.reportbasename = mod.__name__.replace(".", "_") cf.logbasename = "%s.log" % (cf.reportbasename,) # merge any test-module specific config files. modconf = os.path.join(os.path.dirname(mod.__file__) , "%s.conf" % (mod.__name__.split(".")[-1],)) cf.conf_dir = os.path.dirname(modconf) cf.mergefile(modconf) # the "resultsdir" is where you would place any resulting data files. starttime = timelib.now() cf.results_year_month_dir = os.path.join( cf.get("resultsdirbase", "/var/tmp"), "%s" % (timelib.strftime("%Y%m")), ) # first make the YYYYMM top directory try: os.mkdir(cf.results_year_month_dir) os.chmod(cf.results_year_month_dir, 0777) except OSError, errno: if errno[0] == EEXIST: pass else: raise if cf.multiModule: import random rand_num = random.randint(0, 5000) else: rand_num = cf.ser_no # now make the actual test directory cf.resultsdir = os.path.join( cf.results_year_month_dir, "%s-%s-%s" % (cf.reportbasename, rand_num, timelib.strftime("%Y%m%d%H%M%S", timelib.localtime(starttime))) ) try: os.mkdir(cf.resultsdir) except OSError, errno: if errno[0] == EEXIST: pass else: raise
except: self.info("Error: Can't open %s!" % version_file) # insert the _ID if it exists. try: rpt.add_message("File ID", mod._ID) except: rpt.add_message("File ID", 'Missing') note = self.get_note() if note: rpt.add_message("NOTE", note) self._config.comment = note else: self._config.comment = None self.lasturl = url = self._reporturl(rpt) rpt.add_message("MODULESTART", timelib.strftime("%a, %d %b %Y %H:%M:%S %Z", timelib.localtime(starttime))) suite = mod.get_suite(cf) self.test_name = self._config.test_name # if not specified in command line, then testbedname would be empty. if self._config.testbedname is None: tblist = suite.get_testbeds() if tblist: if len(tblist) == 1: # if only one found, just use it self._config.testbedname = tblist[0].name else: tbnames = map(lambda tb: tb.name, tblist) tbnames.sort() tbname = ui.choose(tbnames, prompt="Testbed name? ") self._config.testbedname = tbname
def logfilename(self, ext="log"): """Return a standardized log file name with a timestamp that should be unique enough to not clash with other tests, and also able to correlate it later to the test report via the time stamp.""" return "%s-%s.%s" % (self.test_name, timelib.strftime("%Y%m%d%H%M%S", timelib.localtime(self.starttime)), ext)
def run_module(self, mod): cf = self._config userinterface = storage.get_ui(cf) cf['userinterface'] = userinterface # ui = self._config.userinterface user_name = commands.getoutput('whoami') cf['user'] = user_name output = commands.getoutput("groups %s" % user_name) user_group = output.split(':')[0].strip() cf.USERGROUP = user_group if type(mod) is str: mod = self.get_module(mod) # find out what type of test this is. if UI, then we need to instantiate # a AutoWeb instance cf['mod_type'] = mod.__name__.split('.')[0] if cf.options.tag: # user wants to run a collection of test (a testsuite, instantiate # a TCMS object, which will be used to add_test() cf['tcms_obj'] = tcms_base.TCMS() if mod: cf.reportbasename = mod.__name__.replace(".", "_") cf.logbasename = "%s.log" % (cf.reportbasename,) cf['logfile'] = storage.get_logfile(cf) # merge any test-module specific configuration files modconf = os.path.join(os.path.dirname(mod.__file__), "%s.conf" % (mod.__name__.split(".")[-1],)) user_modconf = modconf + "." + cf.OPENSHIFT_user_email if os.path.exists(user_modconf): execfile(user_modconf, cf.__dict__) elif os.path.exists(modconf): execfile(modconf, cf.__dict__) try: print "tcms_testcaserun_id: %s" %(cf.tcms_testcaserun_id) if os.environ.has_key("OPENSHIFT_tcms_testcaserun_id"): cf.tcms_testcaserun_id = os.environ['OPENSHIFT_tcms_testcaserun_id'] except: #if rhtest is run manually from command line without launcher, which should put this into the .conf file cf.tcms_testcaserun_id = None #print "WARN: None tcms_testcaserun_id info!!!" if cf.tcms_testcaserun_id != None: import tcms cf['tcms_obj'] = tcms.TCMS() else: cf['tcms_obj'] = None starttime = timelib.now() cf.results_year_month_dir = os.path.join(cf.resultsdirbase, "%s" % (timelib.strftime("%Y%m/%d/"))) # first make the YYYYMM top directory try: os.system("sudo mkdir -p %s" % (cf.results_year_month_dir)) os.system("sudo find %s -type d -exec chmod 777 {} \;" % (cf.resultsdirbase)) except OSError, errno: if errno[0] == EEXIST: pass else: raise rand_num = random.randint(0, 5000) # now make the actual test directory, added rand_num to make it more unique cf.resultsdir = os.path.join( cf.results_year_month_dir, "%s-%s-%s" % (cf.reportbasename, rand_num, timelib.strftime("%Y%m%d%H%M%S", timelib.localtime(starttime))) ) try: os.system("sudo mkdir -p %s" % (cf.resultsdir)) os.system("sudo find %s -type d -exec chmod 777 {} \;" % (cf.resultsdirbase)) except OSError, errno: if errno[0] == EEXIST: pass else: raise
def encode(self): ts = timelib.strftime("%b %d %H:%M:%S", timelib.localtime(self.timestamp)) return "<%s>%s %s %s: %s" % ((self.facility<<3) + self.priority, ts, self.tag, self.message)
def run_module(self, mod): """run_module(module) Runs the module. The parameter should be a module object, but if it is a string then a module object with that name will be imported. """ cf = self._config if type(mod) is str: mod = self.get_module(mod) if mod: try: cf.module_ID = mod._ID except AttributeError: cf.module_ID = "<unknown>" cf.reportbasename = mod.__name__.replace(".", "_") cf.logbasename = "%s.log" % (cf.reportbasename,) # merge any test-module specific config files. testconf = os.path.join(os.path.dirname(mod.__file__) , "%s.conf" % (mod.__name__.split(".")[-1],)) cf.mergefile(testconf) # resultsdir is where you would place any resulting data files. starttime = timelib.now() cf.resultsdir = os.path.join( cf.get("resultsdirbase", os.environ["HOME"]), "%s-%s" % (cf.reportbasename, timelib.strftime("%Y%m%d%H%M", timelib.localtime(starttime))) ) # make collection dir try: os.mkdir(cf.resultsdir) except OSError, errno: if errno[0] == EEXIST: pass else: raise # firstly, run the module-level initialize function. if hasattr(mod, "initialize") and callable(mod.initialize): if cf.flags.DEBUG: try: mod.initialize(cf) except: ex, val, tb = sys.exc_info() import debugger debugger.post_mortem(ex, val, tb) else: mod.initialize(cf) rpt = cf.get_report() cf.reportfilenames = rpt.filenames # Report file's names. save for future use. rpt.initialize() rpt.logfile(cf.logfilename) rpt.add_title("Test Results for module %r." % (mod.__name__, )) rpt.add_message("ARGUMENTS", " ".join(cf.arguments)) note = self.get_note() if note: rpt.add_message("NOTE", note) self._config.comment = note else: self._config.comment = "<none>" self._reporturl(rpt) rpt.add_message("MODULESTART", timelib.strftime("%a, %d %b %Y %H:%M:%S %Z", timelib.localtime(starttime))) mod.run(cf) # run the test! rpt.add_message("MODULEEND", timelib.localtimestamp()) rpt.finalize() # force close of report and logfile between modules cf.logfile.flush() del cf.report ; del cf.logfile # lastly, run the module-level finalize function. if hasattr(mod, "finalize") and callable(mod.finalize): if cf.flags.DEBUG: try: mod.finalize(cf) except: ex, val, tb = sys.exc_info() import debugger debugger.post_mortem(ex, val, tb) else: mod.finalize(cf)
def timestamp(self, abstime): return timelib.strftime("%a, %d %b %Y %H:%M:%S %Z", timelib.localtime(abstime))