示例#1
0
    def Main(self):
        if GlobalOptions.testcases and self.Name(
        ) not in GlobalOptions.testcases:
            Logger.info("Skipping Testcase: %s due to cmdline filter." %
                        self.Name())
            self.__enable = False
            return types.status.SUCCESS

        if GlobalOptions.markers_present:
            if self.Name() == GlobalOptions.testcase_begin:
                Logger.debug("Match found for Testcase starting marker %s" %
                             self.Name())
                GlobalOptions.inb_markers = True

        if GlobalOptions.markers_present and not GlobalOptions.inb_markers:
            Logger.info(
                "Skipping Testcase: %s due to cmdline testcase begin/end markers."
                % self.Name())
            self.__enable = False
            return types.status.SUCCESS

        if self.__enable:
            Logger.SetTestcase(self.Name())
            Logger.info("Starting Testcase: %s" % self.Name())
            Logger.info("Testcase {0} timestamp: {1}".format(
                self.Name(), time.asctime()))
            self.__timer.Start()
            try:
                self.status = self.__execute()
            except OfflineTestbedException:
                utils.LogException(Logger)
                Logger.error(
                    "EXCEPTION: Aborting Testcase Execution. Reason: testbed failure"
                )
                raise
            except:
                utils.LogException(Logger)
                Logger.error("EXCEPTION: Aborting Testcase Execution.")
                self.status = types.status.ERROR
                if self.__ignored:
                    Logger.error(
                        "IGNORE: testcase in ignore mode, ignoring exception.")
                    self.status = types.status.SUCCESS
            self.__timer.Stop()
            Logger.info("Testcase %s FINAL RESULT = %d" %
                        (self.Name(), self.status))
        else:
            self.status = types.status.SUCCESS

        if GlobalOptions.markers_present:
            if self.Name() == GlobalOptions.testcase_end:
                Logger.debug("Match found for Testcase ending marker %s" %
                             self.Name())
                GlobalOptions.inb_markers = False

        return self.status
示例#2
0
    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