def execute_step(self, current_step_number, go_to_step_number):
        """
        This function executes the determined step - step_num (integer index) from the step_list.
        This function is called either from the while loop (normal execution) in function
        execute_steps() or from a for loop (invoked execution)
        """
        self.current_step = self.step_list[current_step_number]
        #store loop iter number in data repository
        loop_iter_number = self.current_step.get("loop_iter_number", None)
        Utils.data_Utils.update_datarepository(
            {"loop_iter_number": loop_iter_number})
        # Incrementing current_step_number for printing purposes.
        self.current_step_number = current_step_number + 1

        self.go_to_step_number = go_to_step_number
        # execute steps
        # Decide whether or not to execute keyword
        # First decide if this step should be executed in this iteration
        if not self.go_to_step_number or self.go_to_step_number == str(
                self.current_step_number):
            # get Exectype information
            self.run_current_step, self.current_triggered_action = \
                exec_type_driver.main(self.current_step, skip_invoked=self.skip_invoked)
            if not self.run_current_step:
                return self._report_step_as_not_run()

        if not self.go_to_step_number or self.go_to_step_number == str(
                self.current_step_number):
            self.step_status = self._execute_current_step()
        else:
            # Skip because of goto
            return self._skip_because_of_goto()
        runmode, value, runmode_timer = \
            common_execution_utils.get_runmode_from_xmlfile(self.current_step)
        retry_type, retry_cond, retry_cond_value, retry_value, retry_interval = \
            common_execution_utils.get_retry_from_xmlfile(self.current_step)
        if runmode is not None:
            return self._execute_runmode_step(runmode_timer, runmode,
                                              self.step_status, value)

        elif retry_type is not None:
            return self._execute_retry_type_step(retry_type, retry_cond,
                                                 retry_cond_value,
                                                 retry_interval, retry_value)
        else:
            return self._execute_step_otherwise(self.step_status)
Beispiel #2
0
def execute_sequential_testsuites(testsuite_list, project_repository,
                                  data_repository, auto_defects):
    """ Executes suites in a project sequentially """

    suite_cntr = 0
    goto_testsuite = False
    ts_status_list = []
    ts_impact_list = []
    impact_dict = {"IMPACT": "Impact", "NOIMPACT": "No Impact"}

    project_error_action = project_repository['def_on_error_action']
    project_filepath = project_repository['project_filepath']
    project_dir = os.path.dirname(project_filepath)
    wp_results_execdir = project_repository['wp_results_execdir']
    wp_logs_execdir = project_repository['wp_logs_execdir']
    project_error_value = project_repository['def_on_error_value']

    jiraproj = data_repository['jiraproj']
    pj_junit_object = data_repository['wt_junit_object']

    while suite_cntr < len(testsuite_list):
        testsuite = testsuite_list[suite_cntr]
        suite_cntr += 1

        testsuite_rel_path = testsuite_utils.get_path_from_xmlfile(testsuite)
        if testsuite_rel_path is not None:
            testsuite_path = Utils.file_Utils.getAbsPath(
                testsuite_rel_path, project_dir)
        else:
            testsuite_path = str(testsuite_rel_path)
        print_info("\n")
        print_debug("<<<< Starting execution of Test suite: {0}>>>>".format(
            testsuite_path))
        action, testsuite_status = exec_type_driver.main(testsuite)
        testsuite_impact = Utils.testcase_Utils.get_impact_from_xmlfile(
            testsuite)
        testsuite_name = Utils.file_Utils.getFileName(testsuite_path)
        testsuite_nameonly = Utils.file_Utils.getNameOnly(testsuite_name)
        ts_onError_action = Utils.xml_Utils.get_attributevalue_from_directchildnode(
            testsuite, 'onError', 'action')
        ts_onError_action = ts_onError_action if ts_onError_action else project_error_action
        if Utils.file_Utils.fileExists(testsuite_path):
            if not goto_testsuite and action is True:

                testsuite_result = testsuite_driver.main(
                    testsuite_path,
                    data_repository=data_repository,
                    from_project=True,
                    auto_defects=auto_defects,
                    jiraproj=jiraproj,
                    res_startdir=wp_results_execdir,
                    logs_startdir=wp_logs_execdir,
                    ts_onError_action=ts_onError_action)
                testsuite_status = testsuite_result[0]

            elif goto_testsuite and goto_testsuite == str(suite_cntr)\
                    and action is True:
                testsuite_result = testsuite_driver.main(
                    testsuite_path,
                    data_repository=data_repository,
                    from_project=True,
                    auto_defects=auto_defects,
                    jiraproj=jiraproj,
                    res_startdir=wp_results_execdir,
                    logs_startdir=wp_logs_execdir,
                    ts_onError_action=ts_onError_action)
                goto_testsuite = False
                testsuite_status = testsuite_result[0]

            else:
                msg = print_info(
                    'skipped testsuite: {0} '.format(testsuite_path))
                tmp_timestamp = str(
                    Utils.datetime_utils.get_current_timestamp())
                time.sleep(2)
                pj_junit_object.create_testsuite(
                    location=os.path.dirname(testsuite_path),
                    name=testsuite_nameonly,
                    timestamp=tmp_timestamp,
                    **pj_junit_object.init_arg())
                pj_junit_object.update_attr("status", "SKIPPED", "ts",
                                            tmp_timestamp)
                pj_junit_object.update_attr("skipped", "1", "pj",
                                            tmp_timestamp)
                pj_junit_object.update_count("suites", "1", "pj",
                                             tmp_timestamp)
                data_repository['testsuite_{}_result'.format(
                    suite_cntr)] = "SKIP"
                pj_junit_object.update_attr(
                    "impact", impact_dict.get(testsuite_impact.upper()), "ts",
                    tmp_timestamp)
                pj_junit_object.update_attr("onerror", "N/A", "ts",
                                            tmp_timestamp)
                pj_junit_object.output_junit(wp_results_execdir,
                                             print_summary=False)
                continue

        else:

            msg = print_error("Test suite does not exist in "
                              "provided path: {0}".format(testsuite_path))
            testsuite_status = 'ERROR'
            if goto_testsuite and goto_testsuite == str(suite_cntr):
                goto_testsuite = False
            elif goto_testsuite and goto_testsuite != str(suite_cntr):
                data_repository['testsuite_{}_result'.format(
                    suite_cntr)] = "ERROR"
                continue

        goto_testsuite_num = onerror_driver.main(testsuite,
                                                 project_error_action,
                                                 project_error_value)
        if goto_testsuite_num is False:
            onerror = "Next"
        elif goto_testsuite_num == "ABORT":
            onerror = "Abort"
        else:
            onerror = "Goto:" + str(goto_testsuite_num)
        pj_junit_object.update_attr("impact",
                                    impact_dict.get(testsuite_impact.upper()),
                                    "ts", data_repository['wt_ts_timestamp'])
        pj_junit_object.update_attr("onerror", onerror, "ts",
                                    data_repository['wt_ts_timestamp'])

        string_status = {
            "TRUE": "PASS",
            "FALSE": "FAIL",
            "ERROR": "ERROR",
            "SKIP": "SKIP",
            "RAN": "RAN"
        }

        if str(testsuite_status).upper() in string_status.keys():
            data_repository['testsuite_{}_result'.format(suite_cntr)] = \
             string_status[str(testsuite_status).upper()]
        else:
            print_error("unexpected testsuite status, default to exception")
            data_repository['testsuite_%d_result' % suite_cntr] = "ERROR"

        ts_status_list.append(testsuite_status)
        ts_impact_list.append(testsuite_impact)
        if testsuite_impact.upper() == 'IMPACT':
            msg = "Status of the executed test suite impacts Project result"
        elif testsuite_impact.upper() == 'NOIMPACT':
            msg = "Status of the executed test suite does not impact project result"
        print_debug(msg)

        runmode, value, _ = common_execution_utils.get_runmode_from_xmlfile(
            testsuite)
        retry_type, retry_cond, retry_cond_value, retry_value,\
            retry_interval = common_execution_utils.get_retry_from_xmlfile(testsuite)
        if runmode is not None:
            if testsuite.find("runmode") is not None and\
              testsuite.find("runmode").get("attempt") is not None:
                print_info("runmode attempt: {0}".format(
                    testsuite.find("runmode").get("attempt")))
            # if runmode is 'ruf' & step_status is False, skip the repeated
            # execution of same TC step and move to next actual step
            if not project_error_value and runmode == "RUF" and\
                    testsuite_status is False:
                goto_testsuite = str(value)
            # if runmode is 'rup' & step_status is True, skip the repeated
            # execution of same TC step and move to next actual step
            elif runmode == "RUP" and testsuite_status is True:
                goto_testsuite = str(value)
        elif retry_type is not None:
            if testsuite.find("retry") is not None and\
              testsuite.find("retry").get("attempt") is not None:
                print_info("retry attempt: {0}".format(
                    testsuite.find("retry").get("attempt")))
            if retry_type.upper() == 'IF':
                try:
                    if data_repository[retry_cond] == retry_cond_value:
                        condition_met = True
                        pNote("Wait for {0}sec before retrying".format(
                            retry_interval))
                        pNote("The given condition '{0}' matches the expected"
                              "value '{1}'".format(data_repository[retry_cond],
                                                   retry_cond_value))
                        time.sleep(int(retry_interval))
                    else:
                        condition_met = False
                        print_warning(
                            "The condition value '{0}' does not match with the expected "
                            "value '{1}'".format(data_repository[retry_cond],
                                                 retry_cond_value))
                except KeyError:
                    print_warning(
                        "The given condition '{0}' do not exists in "
                        "the data repository".format(retry_cond_value))

                    condition_met = False
                if condition_met is False:
                    goto_testsuite = str(retry_value)
            else:
                if retry_type.upper() == 'IF NOT':
                    try:
                        if data_repository[retry_cond] != retry_cond_value:
                            condition_met = True
                            pNote("Wait for {0}sec before "
                                  "retrying".format(retry_interval))
                            pNote("The condition value '{0}' does not match "
                                  "with the expected value '{1}'".format(
                                      data_repository[retry_cond],
                                      retry_cond_value))
                            time.sleep(int(retry_interval))
                        else:
                            condition_met = False
                    except KeyError:
                        condition_met = False
                        print_warning(
                            "The given condition '{0}' is not there "
                            "in the data repository".format(retry_cond_value))
                    if condition_met is False:
                        pNote("The given condition '{0}' matched with the "
                              "value '{1}'".format(data_repository[retry_cond],
                                                   retry_cond_value))
                        goto_testsuite = str(retry_value)
        else:
            if testsuite_status is False or testsuite_status == "ERROR" or\
                    testsuite_status == "EXCEPTION":
                goto_testsuite = onerror_driver.main(testsuite,
                                                     project_error_action,
                                                     project_error_value)
            if goto_testsuite in ['ABORT', 'ABORT_AS_ERROR']:
                break
            # when 'onError:goto' value is less than the current ts num,
            # change the next iteration point to goto value
            elif goto_testsuite and int(goto_testsuite) < suite_cntr:
                suite_cntr = int(goto_testsuite) - 1
                goto_testsuite = False

    project_status = Utils.testcase_Utils.compute_status_using_impact(
        ts_status_list, ts_impact_list)

    return project_status
    def _execute_step_list(self):
        """
        """

        goto_stepnum = False
        step_num = 0
        while step_num < len(self.step_list):

            index = step_num
            step = self.step_list[step_num]
            step_num += 1

            self.system_executed = self._get_system_executed(index)
            if self.stop_after_current_step:
                break

            # Decide whether or not to execute keyword
            # First decide if this step should be executed in this iteration
            if not goto_stepnum or goto_stepnum == str(step_num):
                # get Exectype information
                run_current_step, trigger_action = exec_type_driver.main(step)
                if not run_current_step:

                    if trigger_action.upper() in ['ABORT', 'ABORT_AS_ERROR']:
                        if any([
                                self.iter_type_list[index] == "once_per_tc",
                                self.iter_type_list[index] == "end_of_tc"
                        ]):
                            pNote("step exectype check failed, fail action is set to {0} and"
                                  "step iter_type={1} hence aborting execution compeletely".\
                                  format(trigger_action.upper(), self.iter_type_list[index]), "debug")
                            self.stop_after_current_iteration = True
                            self.stop_after_current_step = True
                        else:
                            pNote("step exectype check failed, fail action is set to {0} and"
                                  "step iter_type={1} hence aborting execution for this system".\
                                  format(trigger_action.upper(), self.iter_type_list[index]), "debug")
                        goto_stepnum = False
                        break
                    elif trigger_action.upper() in ['SKIP', 'NEXT']:
                        result = self._update_skip_results(
                            step, self.system_executed, step_num)
                        self.kw_resultfile_list.append(result[1])
                        continue
                    # when 'onError:goto' value is less than the current step num,
                    # change the next iteration point to goto value
                    elif trigger_action and int(trigger_action) < step_num:
                        result = self._update_skip_results(
                            step, self.system_executed, step_num)
                        self.kw_resultfile_list.append(result[1])
                        step_num = int(trigger_action) - 1
                        trigger_action = False

                    continue

            # when there is no goto
            if not goto_stepnum:
                result = self._execute_step(self.system_executed, step_num,
                                            index, goto_stepnum)

            # when goto is triggered and matches the current step number
            elif (goto_stepnum and goto_stepnum == str(step_num)):
                result = self._execute_step(self.system_executed, step_num,
                                            index, goto_stepnum)
                goto_stepnum = False

            # when goto is triggered and does not match current step... skip
            elif goto_stepnum and goto_stepnum != str(step_num):
                result = self._update_skip_results(step, self.system_executed,
                                                   step_num)
                self.kw_resultfile_list.append(result[1])
                continue

            step_status = result[0]
            kw_resultfile = result[1]
            step_impact = result[2]

            self._update_status_items(step_status, kw_resultfile, step_impact)
            goto_stepnum, step_num = self._compute_runmode_goto_operations(
                step, step_status, goto_stepnum, step_num)
            if (goto_stepnum == 'ABORT'):
                if any([
                        self.iter_type_list[index] == "once_per_tc",
                        self.iter_type_list[index] == "end_of_tc"
                ]):
                    pNote(
                        "step iter_type={0}, and onerror action=ABORT hence aborting execution"
                        "compeletely".format(self.iter_type_list[index]),
                        "debug")
                    self.stop_after_current_iteration = True
                    self.stop_after_current_step = True
                goto_stepnum = False
                break

        return
def execute_steps(step_list, data_repository, system_name, parallel, queue):
    """
        Take in a list of steps
        iterate through each of them and decide if each should run (pre-run check)
        get status and report to term and log
    """
    default_error_action = data_repository['wt_def_on_error_action']
    default_error_value = data_repository['wt_def_on_error_value']

    goto_stepnum = False
    kw_resultfile_list = []
    step_status_list = []
    step_impact_list = []
    step_num = 0

    if parallel is True:
        system_console_log = get_system_console_log(
            data_repository['wt_filename'], data_repository['wt_logsdir'],
            '{0}_consoleLogs'.format(system_name))
    while step_num < len(step_list):
        step = step_list[step_num]
        # execute steps
        step_num += 1

        run_current_step = False
        # Decide whether or not to execute keyword
        # First decide if this step should be executed in this iteration
        if not goto_stepnum or goto_stepnum == str(step_num):
            # get Exectype information
            run_current_step, trigger_action = exec_type_driver.main(step)
            if not run_current_step:
                keyword = step.get('Keyword')
                kw_resultfile = step_driver.get_keyword_resultfile(
                    data_repository, system_name, step_num, keyword)
                Utils.config_Utils.set_resultfile(kw_resultfile)
                Utils.testcase_Utils.pKeyword(keyword, step.get('Driver'))
                Utils.testcase_Utils.reportStatus('Skip')
                kw_resultfile_list.append(kw_resultfile)
                data_repository['wt_junit_object'].update_count(
                    "skipped", "1", "tc", data_repository['wt_tc_timestamp'])
                data_repository['wt_junit_object'].update_count(
                    "keywords", "1", "tc", data_repository['wt_tc_timestamp'])
                kw_start_time = Utils.datetime_utils.get_current_timestamp()
                step_impact = Utils.testcase_Utils.get_impact_from_xmlfile(
                    step)
                impact_dict = {"IMPACT": "Impact", "NOIMPACT": "No Impact"}
                data_repository['wt_junit_object'].add_keyword_result(
                    data_repository['wt_tc_timestamp'], step_num, keyword,
                    "SKIPPED", kw_start_time, "0", "skipped",
                    impact_dict.get(step_impact.upper()), "N/A")
                data_repository['step_{}_result'.format(step_num)] = "SKIPPED"

                if trigger_action.upper() in ['ABORT', 'ABORT_AS_ERROR']:
                    break
                elif trigger_action.upper() in ['SKIP', 'NEXT']:
                    continue
                # when 'onError:goto' value is less than the current step num,
                # change the next iteration point to goto value
                elif trigger_action and int(trigger_action) < step_num:
                    step_num = int(trigger_action) - 1
                    trigger_action = False

                continue

        if not goto_stepnum:
            try:
                result = step_driver.main(step, step_num, data_repository,
                                          system_name)
                step_status = result[0]
                kw_resultfile = result[1]
                step_impact = result[2]

            except Exception, e:
                print_error('unexpected error %s' % str(e))
                step_status = False
                kw_resultfile = None
                step_impact = Utils.testcase_Utils.get_impact_from_xmlfile(
                    step)
                print_error('unexpected error {0}'.format(
                    traceback.format_exc()))

        elif goto_stepnum and goto_stepnum == str(step_num):
            try:
                result = step_driver.main(step, step_num, data_repository,
                                          system_name)
                step_status = result[0]
                kw_resultfile = result[1]
                step_impact = result[2]

            except Exception, e:
                print_error('unexpected error %s' % str(e))
                step_status = False
                kw_resultfile = None
                step_impact = Utils.testcase_Utils.get_impact_from_xmlfile(
                    step)
                print_error('unexpected error {0}'.format(
                    traceback.format_exc()))