def __execute_testcases(self): result = types.status.SUCCESS for _i in range(GlobalOptions.bundle_stress): selected_list = [None] if self.__sel_module: selected_list = loader.RunCallback(self.__sel_module, 'Main', False, self.__sel_module_args) if self.__max_select: selected_list = selected_list[:int(self.__max_select)] if not selected_list: tcResId = "tb_{0}_tc_{1}_non_selected_count_{2}".format( self.Name(), tc.Name(), _i) tcResult = TestCaseResult(tcResId, tc.Name(), "unknown") tcResult.closeResult( types.status.SKIPPED, time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime()), 0, "{}") self.addTcResult(tcResult) for selected in selected_list: if self.__sel_entry: selected_list = loader.RunCallback(self.__sel_entry, 'Main', False, selected) for tc in self.__testcases: owner = tc._Testcase__get_owner() if tc.Name() in self.__ignoreList: tc._Testcase__ignored = True api.CurrentTestcase = tc tcResId = "TB:{0}_TC:{1}_SELECTED:{2}_COUNT:{3}".format( self.Name(), tc.Name(), selected, _i) tcResult = TestCaseResult(tcId=tcResId, name=tc.Name(), desc="", owner=owner, area="na", subArea="", feature="") self.addTcResult(tcResult) tc.SetSelected(selected) tc.SetBundleStore(self.GetStore()) startTime = time.time() ret = tc.Main() tcResult.closeResult( ret, time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime()), time.time() - startTime, tc.iterRes.toJson()) if ret != types.status.SUCCESS: result = ret if result == types.status.CRITICAL and GlobalOptions.stop_on_critical: return ret if GlobalOptions.no_keep_going: return ret if self.__aborted: return types.status.FAILURE return result
def __setup_config(self): for s in self.__spec.setup.config: # Reset the running directory before every step Logger.info("Starting Config Step: ", s.step) api.ChangeDirectory(None) status = loader.RunCallback(s.step, 'Main', True, getattr(s, "args", None)) if status != types.status.SUCCESS: Logger.error("ERROR: Failed to run config step", s.step) return status return types.status.SUCCESS
def __invoke_teardown(self): teardown_spec = getattr(self.__spec, 'teardown', []) if teardown_spec is None: return types.status.SUCCESS for s in teardown_spec: Logger.info("Starting Teardown Step: ", s.step) status = loader.RunCallback(s.step, 'Main', True, getattr(s, "args", None)) if status != types.status.SUCCESS: Logger.error("ERROR: Failed to run teardown step", s.step) return status return types.status.SUCCESS
def __execute(self, iter_data): if self.__background: Logger.debug("Running common teardown module in background: %s" % self.__spec.step) bt_inst = TestcaseBackgroundTrigger('Main', self.__trigger, self.__run, self.__sleep_interval, self.__terminate) return bt_inst.StartTask(self.__mod, iter_data) else: Logger.debug("Running common teardown module in foreground: %s" % self.__spec.step) return loader.RunCallback(self.__mod, 'Main', True, iter_data)
def __execute(self): Logger.debug("Running testcase setup module: %s" % self.__spec.step) return loader.RunCallback(self.__mod, 'Main', True, None)
def __execute(self): final_result = types.status.SUCCESS for iter_data in self.__iters: self.__iterid += 1 Logger.debug("Create new iter TestcaseData. ID:%d" % self.__iterid) iter_data.StartTime() api.ChangeDirectory("") instance_id = self.__get_instance_id(self.__iterid) iter_data.SetInstanceId(instance_id) iter_data.SetSelected(self.selected) iter_data.SetBundleStore(self.bundle_store) Logger.SetTestcase(instance_id) Logger.debug("Testcase Iteration directory = %s" % instance_id) ret = self.__mk_testcase_directory(instance_id) if ret != types.status.SUCCESS: iter_data.SetStatus(ret) iter_data.StopTime() return ret api.ChangeDirectory(instance_id) result = types.status.SUCCESS setup_result = self.__run_common_setups(iter_data) setup_result = loader.RunCallback(self.__tc, 'Setup', False, iter_data) if setup_result != types.status.SUCCESS: Logger.error( "Setup callback failed, Cannot continue, switching to Teardown" ) loader.RunCallback(self.__tc, 'Teardown', False, iter_data) result = setup_result else: for task_name, bt in self.__background_tasks.items(): if bt.IsAutoTriggerEnabled(): Logger.debug( "Triggering BackgroundTask %s - auto trigger" % task_name) bt_trigger_result = bt.StartTask(self.__tc, iter_data) if bt_trigger_result != types.status.SUCCESS: result = bt_trigger_result else: Logger.debug( "Skipping BackgroundTask %s - manual trigger" % task_name) trigger_result = self.__run_common_triggers(iter_data) trigger_result = loader.RunCallback(self.__tc, 'Trigger', True, iter_data) if trigger_result != types.status.SUCCESS: result = trigger_result for task_name, bt in self.__background_tasks.items(): bt_stop_result = bt.StopTask('after_trigger') verify_result = loader.RunCallback(self.__tc, 'Verify', True, iter_data) if verify_result != types.status.SUCCESS: result = verify_result for task_name, bt in self.__background_tasks.items(): bt_stop_result = bt.StopTask('verify') verify_result = self.__run_common_verifs(iter_data) if verify_result != types.status.SUCCESS: Logger.error("Common verifs failed.") result = verify_result self.iterRes.addResults(iter_data.GetInstanceId(), result) iter_data.SetStatus(result) for task_name, bt in self.__background_tasks.items(): bt_stop_result = bt.StopTask('teardown') bt.CollectTask() teardown_result = self.__run_common_teardowns(iter_data) teardown_result = loader.RunCallback(self.__tc, 'Teardown', False, iter_data) if teardown_result != types.status.SUCCESS: Logger.error("Teardown callback failed.") result = teardown_result # If the tests have failed (at any stage), lets run debug actions. if result != types.status.SUCCESS: debug_result = self.__run_common_debugs(iter_data) if debug_result != types.status.SUCCESS: Logger.error( f"Common debugs failed, ret {debug_result}") result = debug_result iter_data.StopTime() if self.__aborted: Logger.info("Iteration Instance: %s FINAL RESULT = %d" % (instance_id, types.status.ABORTED)) iter_data.SetStatus(types.status.ABORTED) return types.status.FAILURE if result != types.status.SUCCESS and GlobalOptions.no_keep_going: Logger.info("Iteration Instance: %s FINAL RESULT = %d" % (instance_id, result)) Logger.error("Error: STOPPING ON FIRST FAILURE.") iter_data.SetStatus(result) raise OfflineTestbedException #return types.status.FAILURE if result == types.status.CRITICAL and GlobalOptions.stop_on_critical: Logger.info("Iteration Instance: %s FINAL RESULT = %d" % (instance_id, result)) Logger.error("Error: STOPPING ON CRITICAL FAILURE.") iter_data.SetStatus(result) return types.status.CRITICAL if result == types.status.OFFLINE_TESTBED: Logger.info("Iteration Instance: %s FINAL RESULT = %d" % (instance_id, result)) Logger.error("Error: STOPPING ON OFFLINE TESTBED REQUEST.") iter_data.SetStatus(result) raise OfflineTestbedException iter_data.SetStatus(result) Logger.info("Iteration Instance: %s FINAL RESULT = %d" % (instance_id, result)) if result != types.status.SUCCESS or GlobalOptions.dryrun: if self.__ignored or result == types.status.IGNORED: Logger.info("Test failed, marking as ignored") Logger.info("Iteration Instance: %s FINAL RESULT = %d" % (instance_id, result)) iter_data.SetStatus(types.status.IGNORED) final_result = types.status.SUCCESS else: final_result = result api.ChangeDirectory("") return final_result
def __execute(self, iter_data): Logger.debug("Running testcase debug module: %s" % self.__spec.step) return loader.RunCallback(self.__mod, 'Main', True, iter_data)