def addSuccess(self, test, capt=None): id = test.id() self.stats['pass'] += 1 (modulename, classname, testname) = id.split('.') autopsy_logger.info("===========================================") autopsy_logger.info("| Test Passed : " + classname + "." + testname) autopsy_logger.info("===========================================") timetaken = self._timeTaken() self.total_run_time += timetaken if autopsy_globals.test_fail_reason.find("\n") != -1: autopsy_globals.test_fail_reason = autopsy_globals.test_fail_reason[0:autopsy_globals.test_fail_reason.find("\n")]\ .strip() self.report_string += "\n|{:<40}|{:^10}|{:^20}|{:<86}|"\ .format(" " + classname + ("" if testname.strip() == "test" else "." + testname), "PASS", self.nice_to_see_time(timetaken), " " + autopsy_globals.test_fail_reason.strip()) self.pass_report_string += '\n' + "#" * 50 + '\n' self.pass_report_string += '\nTest Case : ' + classname + "." + testname self.pass_report_string += '\nDescription : \n' + self.reindent( self.currTestDescription, 5) self.pass_report_string += '\nSteps : \n' + self.reindent( self.dumpTestSteps(), 5) if "test" == testname: testcase = self.getTestByName(classname) testcase.result = "Passed" autopsy_globals.dumpTestCaseJsonFile() else: testcase = self.getTestByName(classname + "." + testname) testcase.result = "Passed" autopsy_globals.dumpTestCaseJsonFile()
def startTest(self, test): id = test.id() (modulename, classname, testname) = id.split('.') self.stats['total'] += 1 if testname != "test": testcase = self.getTestByName(classname + "." + testname) else: testcase = self.getTestByName(classname) testcase.description = self.currTestDescription.replace('\n', '\\n') testcase.result = "InProgress" autopsy_globals.dumpTestCaseJsonFile() TestCore.startTest(testcase) # self.log_file.write("Test started: "+id_split(id)[0] + "\n") autopsy_logger.info("===========================================") autopsy_logger.info("| Test Started : " + classname + "." + testname) autopsy_logger.info("===========================================") if TestCore.TestHookHandler.ON_START_TEST in autopsy_globals.autopsy_test_hooks.keys( ): for testHook in autopsy_globals.autopsy_test_hooks[ TestCore.TestHookHandler.ON_START_TEST]: testHook.exec_hook() if is_pause_test_run(): autopsy_logger.info("Pausing the test run as pause file found") pdb.set_trace()
def configure(self, options, config): """Configures the xunit plugin. :param config: :param options: """ Plugin.configure(self, options, config) if self.enabled: self.stats = {'total': 0, 'pass': 0, 'fail': 0, 'error': 0} self.pass_report_string = '' self.fail_report_string = '' self.err_report_string = '' self.report_string = '\n ' + '-' * 159 self.report_string += "\n|{:^40}|{:^10}|{:^20}|{:^86}|".format( 'Test', 'Result', 'RunTime(sec)', 'Reason') self.report_string += '\n ' + '-' * 159 self.config = config if self.enabled: self.archive_loc = os.path.realpath(options.autopsy_summary_file) self.log_file_name = self.archive_loc + "/summary.txt" self.mailto = options.mailto # self.sortTestCasesByName() autopsy_globals.dumpTestCaseJsonFile()
def prepareTestCase(self, test): """Replace actual test with dummy that always passes. :param test: """ # Return something that always passes autopsy_logger.debug("Preparing test case {0}".format(test)) id = test.id() (modulename, classname, testname) = id.split('.') autopsy_logger.debug(testname) if "test" == testname: autopsy_globals.test_list.append( TestCase(classname, "NotStarted", "Yet to get")) else: autopsy_globals.test_list.append( TestCase(classname + '.' + testname, "NotStarted", "Yet to get")) # self.sortTestCasesByName() autopsy_globals.dumpTestCaseJsonFile() if not isinstance(test, Test): return def run(result): # We need to make these plugin calls because there won't be # a result proxy, due to using a stripped-down test suite # self.conf.plugins.startTest(test) # result.startTest(test) # self.conf.plugins.addSuccess(test) # result.addSuccess(test) # self.conf.plugins.stopTest(test) # result.stopTest(test) pass return run
def exit(status, archive=False): if autopsy_globals.autopsy_being_exited: # autopsy_logger.critical("Force stopping as per user request") if autopsy_globals.autopsy_testbed: autopsy_globals.autopsy_testbed.close_connections(True) unlockTestbed(autopsy_globals.autopsy_testbed.tbFileName) sys.exit(1) autopsy_globals.autopsy_being_exited = True for testcase in autopsy_globals.test_list: if testcase.result == 'InProgress': testcase.result = 'Stopped' autopsy_globals.dumpTestCaseJsonFile() for jobHandler in allJobsRunning: while jobHandler.isAlive(): jobHandler.join(timeout=2) if archive: if autopsy_globals.autopsy_testbed: autopsy_globals.autopsy_testbed.close_connections(quick=args.quick) archive_file_dir(archive_location) if autopsy_globals.autopsy_testbed: unlockTestbed(autopsy_globals.autopsy_testbed.tbFileName) sys.exit(status)
def startContext(self, context): if inspect.isclass(context): if context.__doc__ is not None: _currTestDescription = str.strip(str(context.__doc__)) lines = context.__doc__.split('\n') testcase = autopsy_globals.getTestByName(context.__name__) testcase.description = _currTestDescription.replace( '\n', '\\n') autopsy_globals.dumpTestCaseJsonFile()
def addFailure(self, test, err, capt=None, tb_info=None): id = test.id() tb = format_exception(err, self.encoding) self.stats['fail'] += 1 try: (modulename, classname, testname) = id.split('.') except Exception as e: autopsy_logger.error("ID: " + str(id)) autopsy_logger.error(e.message) return # autopsy_logger.error("REASON: " + format_exception(err, self.encoding)) autopsy_logger.error("===========================================") autopsy_logger.error("| Test Failed : " + classname + "." + testname) autopsy_logger.error("===========================================") timetaken = self._timeTaken() # autopsy_logger.info(timetaken) self.total_run_time += timetaken if autopsy_globals.test_fail_reason.find("\n") != -1: autopsy_globals.test_fail_reason = autopsy_globals.test_fail_reason[0:autopsy_globals.test_fail_reason.find("\n")]\ .strip() self.report_string += "\n|{:<40}|{:^10}|{:^20}|{:<86}|"\ .format(" " + classname + ("" if testname.strip() == "test" else "." + testname), "FAIL", self.nice_to_see_time(timetaken), " " + autopsy_globals.test_fail_reason.strip()) self.fail_report_string += '\n' + "#" * 50 + '\n' self.fail_report_string += '\nTest Case : ' + classname + "." + testname self.fail_report_string += '\nDescription : \n' + self.reindent( self.currTestDescription, 5) self.fail_report_string += '\nSteps : \n' + self.reindent( self.dumpTestSteps(), 5) self.fail_report_string += '\nFail Reason : \n' + self.reindent( format_exception(err, self.encoding), 5) if "test" == testname: testcase = self.getTestByName(classname) testcase.result = "Failed" autopsy_globals.dumpTestCaseJsonFile() else: testcase = self.getTestByName(classname + "." + testname) testcase.result = "Failed" autopsy_globals.dumpTestCaseJsonFile() if is_pause_on_fail(): autopsy_logger.info( "Pausing the test run as pause on fail file found") pdb.set_trace()
def stopTest(self, test): id = test.id() (modulename, classname, testname) = id.split('.') if testname != "test": testcase = self.getTestByName(classname + "." + testname) else: testcase = self.getTestByName(classname) if TestCore.TestHookHandler.ON_END_TEST in autopsy_globals.autopsy_test_hooks.keys( ): for testHook in autopsy_globals.autopsy_test_hooks[ TestCore.TestHookHandler.ON_END_TEST]: testHook.exec_hook() testcase.description += "\\n" + self.dumpTestSteps().replace( '\n', '\\n') autopsy_globals.dumpTestCaseJsonFile()
def addError(self, test, err, capt=None): id = test.id() self.stats['error'] += 1 try: (modulename, classname, testname) = id.split('.') except Exception as e: autopsy_logger.error("ID: " + str(id)) autopsy_logger.error(e.message) return autopsy_logger.error("REASON: " + format_exception(err, self.encoding)) autopsy_logger.error("===========================================") autopsy_logger.error("| Test Errored : " + classname + "." + testname) autopsy_logger.error("===========================================") timetaken = self._timeTaken() self.total_run_time += timetaken if autopsy_globals.test_fail_reason.find("\n") != -1: autopsy_globals.test_fail_reason = autopsy_globals.test_fail_reason[0:autopsy_globals.test_fail_reason.find("\n")]\ .strip() self.report_string += "\n|{:<40}|{:^10}|{:^20}|{:<86}|"\ .format(" " + classname + ("" if testname.strip() == "test" else "." + testname), "ERROR", self.nice_to_see_time(timetaken), " " + autopsy_globals.test_fail_reason.strip()) self.err_report_string += '\n' + "#" * 50 + '\n' self.err_report_string += '\nTest Case : ' + classname + "." + testname self.err_report_string += '\nDescription : \n' + self.reindent( self.currTestDescription, 5) self.err_report_string += '\nSteps : \n' + self.reindent( self.dumpTestSteps(), 5) self.err_report_string += '\nErr Reason : \n' + self.reindent( format_exception(err, self.encoding), 5) if "test" == testname: testcase = self.getTestByName(classname) testcase.result = "Errored" autopsy_globals.dumpTestCaseJsonFile() else: testcase = self.getTestByName(classname + "." + testname) testcase.result = "Errored" autopsy_globals.dumpTestCaseJsonFile()
testbedInitTestCase = TestCase( "TestbedInit", "NotStarted", "Initializing/Cleaning the nodes in testbed") autopsy_globals.test_list.append(testbedInitTestCase) nose.run(addplugins=[AutopsyCollectOnlyPlugin()], argv=list2) if args.debug: pdb.set_trace() signal.signal(signal.SIGUSR1, signalHandler) if args.reboot: autopsy_logger.info("*** REBOOTING all DP Nodes ***") rebootTestCase.result = "InProgress" autopsy_globals.dumpTestCaseJsonFile() autopsy_globals.autopsy_testbed.reboot_dp_nodes() # Waiting for all the processes to start and get settled with CP communication visual_sleep(120, "Waiting for all the processes to be up and settled") rebootTestCase.result = "Passed" autopsy_globals.dumpTestCaseJsonFile() if not args.quick: testbedInitTestCase.result = "InProgress" autopsy_globals.dumpTestCaseJsonFile() if not autopsy_globals.autopsy_testbed.openConnections(): autopsy_logger.critical( "Error connecting/logging-in to all necessary nodes..Exiting"