Exemple #1
0
def run_suite(run_type, suite, env_mode, env_params, timeout=None):
    try:
        start_status = False
        # Initialize the class of the reported metric
        metric = api.Metric()
        global_params.metric = metric
        deploy_mode = env_params["deploy_mode"]
        deploy_opology = env_params[
            "deploy_opology"] if "deploy_opology" in env_params else None
        env = get_env(env_mode, deploy_mode)
        metric.set_run_id()
        metric.set_mode(env_mode)
        metric.env = Env()
        metric.server = Server(version=config.SERVER_VERSION,
                               mode=deploy_mode,
                               deploy_opology=deploy_opology)
        logger.info(env_params)
        if env_mode == "local":
            metric.hardware = Hardware("")
            if "server_tag" in env_params and env_params["server_tag"]:
                metric.hardware = Hardware("server_tag")
            start_status = env.start_up(env_params["host"], env_params["port"])
        elif env_mode == "helm":
            helm_params = env_params["helm_params"]
            helm_path = env_params["helm_path"]
            server_name = helm_params[
                "server_name"] if "server_name" in helm_params else None
            server_tag = helm_params[
                "server_tag"] if "server_tag" in helm_params else None
            if not server_name and not server_tag:
                metric.hardware = Hardware("")
            else:
                metric.hardware = Hardware(
                    server_name) if server_name else Hardware(server_tag)
            start_status = env.start_up(helm_path, helm_params)
        if start_status:
            metric.update_status(status="DEPLOYE_SUCC")
            logger.debug("Get runner")
            runner = get_runner(run_type, env, metric)
            cases, case_metrics = runner.extract_cases(suite)
            # TODO: only run when the as_group is equal to True
            logger.info("Prepare to run cases")
            runner.prepare(**cases[0])
            logger.info("Start run case")
            suite_status = True
            for index, case in enumerate(cases):
                case_metric = case_metrics[index]
                result = None
                err_message = ""
                try:
                    result = runner.run_case(case_metric, **case)
                except Exception as e:
                    err_message = str(e) + "\n" + traceback.format_exc()
                    logger.error(traceback.format_exc())
                logger.info(result)
                if result:
                    # Save the result of this test as true, and save the related test value results
                    case_metric.update_status(status="RUN_SUCC")
                    case_metric.update_result(result)
                else:
                    # The test run fails, save the related errors of the run method
                    case_metric.update_status(status="RUN_FAILED")
                    case_metric.update_message(err_message)
                    suite_status = False
                logger.debug(case_metric.metrics)
                if deploy_mode:
                    api.save(case_metric)
            if suite_status:
                metric.update_status(status="RUN_SUCC")
            else:
                metric.update_status(status="RUN_FAILED")
        else:
            logger.info("Deploy failed on server")
            metric.update_status(status="DEPLOYE_FAILED")
    except Exception as e:
        logger.error(str(e))
        logger.error(traceback.format_exc())
        metric.update_status(status="RUN_FAILED")
    finally:
        if deploy_mode:
            # Save all reported data to the database
            api.save(metric)
        env.tear_down()
        if metric.status != "RUN_SUCC":
            return False
        else:
            return True
Exemple #2
0
def run_suite(run_type, suite, env_mode, env_params):
    try:
        start_status = False
        metric = api.Metric()
        deploy_mode = env_params[
            "deploy_mode"] if "deploy_mode" in env_params else config.DEFAULT_DEPLOY_MODE
        env = get_env(env_mode, deploy_mode)
        metric.set_run_id()
        metric.set_mode(env_mode)
        metric.env = Env()
        metric.server = Server(version=config.SERVER_VERSION, mode=deploy_mode)
        logger.info(env_params)
        if env_mode == "local":
            metric.hardware = Hardware("")
            start_status = env.start_up(env_params["host"], env_params["port"])
        elif env_mode == "helm":
            helm_params = env_params["helm_params"]
            helm_path = env_params["helm_path"]
            server_name = helm_params[
                "server_name"] if "server_name" in helm_params else None
            server_tag = helm_params[
                "server_tag"] if "server_tag" in helm_params else None
            if not server_name and not server_tag:
                metric.hardware = Hardware("")
            else:
                metric.hardware = Hardware(
                    server_name) if server_name else Hardware(server_tag)
            start_status = env.start_up(helm_path, helm_params)
        if start_status:
            metric.update_status(status="DEPLOYE_SUCC")
            logger.debug("Get runner")
            runner = get_runner(run_type, env, metric)
            cases, case_metrics = runner.extract_cases(suite)
            # TODO: only run when the as_group is equal to True
            logger.info("Prepare to run cases")
            runner.prepare(**cases[0])
            logger.info("Start run case")
            suite_status = True
            for index, case in enumerate(cases):
                case_metric = case_metrics[index]
                result = None
                err_message = ""
                try:
                    result = runner.run_case(case_metric, **case)
                except Exception as e:
                    err_message = str(e) + "\n" + traceback.format_exc()
                    logger.error(traceback.format_exc())
                logger.info(result)
                if result:
                    case_metric.update_status(status="RUN_SUCC")
                    case_metric.update_result(result)
                else:
                    case_metric.update_status(status="RUN_FAILED")
                    case_metric.update_message(err_message)
                    suite_status = False
                logger.debug(case_metric.metrics)
                # if env_mode == "helm":
                api.save(case_metric)
            if suite_status:
                metric.update_status(status="RUN_SUCC")
            else:
                metric.update_status(status="RUN_FAILED")
        else:
            logger.info("Deploy failed on server")
            metric.update_status(status="DEPLOYE_FAILED")
    except Exception as e:
        logger.error(str(e))
        logger.error(traceback.format_exc())
        metric.update_status(status="RUN_FAILED")
    finally:
        api.save(metric)
        # time.sleep(10)
        env.tear_down()
        if metric.status != "RUN_SUCC":
            return False
        else:
            return True