Esempio n. 1
0
def performance_test_get_by_performance_id_handler():
    """
    @api {get} /v1/monkey/test 根据 monkey id 和 测试场景 获取场景的设备测试信息列表
    @apiName GetAutotestListByMonkeyIdAndTestType
    @apiGroup 自动化测试
    @apiDescription 根据 monkey id 和 测试场景 获取场景的设备测试信息列表
    @apiParam {int} monkey_id 测试 id
    @apiParam {string} run_type 测试场景
    @apiParamExample {json} Request-Example:
    ?performance_id=260
    @apiSuccessExample {json} Success-Response:
    HTTP/1.1 200 OK
    {
      "code": 0,
      "data": [
        {
          "ZTEC880U": [
            {
              "cpu_average": 0.0,
              "cpu_top": 0.0,
              "creation_time": "2019-09-19 15:41:46",
              "heap_alloc_average": 0.0,
              "heap_alloc_top": 0.0,
              "heap_size_average": 0.0,
              "heap_size_top": 0.0,
              "id": 12,
              "modified_time": "2019-09-19 15:41:45",
              "performance_id": 260,
              "rss_top": 0.0,
              "run_time": 1,
              "run_type": "qjp"
            }
          ]
        }
      ],
      "message": "ok"
    }
    """
    monkey_id = request.args.get('monkey_id')
    run_type = request.args.get('run_type')
    if not monkey_id:
        raise FieldMissingException('monkey_id is required')

    if not run_type:
        raise FieldMissingException('run_type is required')

    response = {
        "code":
        0,
        "data":
        MonkeyBusiness.get_performance_by_monkey_id_and_type(
            monkey_id, run_type)
    }
    return response
Esempio n. 2
0
def monkey_device_release():
    """
    @api {post} /v1/monkey/device/release 释放 设备
    @apiName ReleaseMonkeyDevice
    @apiGroup 自动化测试
    @apiDescription 更新正在使用设备使用状态为空闲
    @apiParam {string} [serial] 设备序列号
    @apiParamExample {json} Request-Example:
    {
     "serial": "7189ac55"
    }
    @apiSuccessExample {json} Success-Response:
    HTTP/1.1 200 OK
    {
     "code": 0,
     "data": [],
     "message": "ok"
    }
    """
    serial = parse_json_form('monkey_device_using')
    if serial:
        ret, msg = MonkeyDeviceUsingBusiness.release_device(serial)
        return dict(code=ret, message=msg)
    else:
        raise FieldMissingException('serial is required')
Esempio n. 3
0
def monkey_cancel_status_handler():
    """
    @api {get} /v1/monkey/cancel 查询 monkey 测试中断状态
    @apiName GetCancelMonkeyStatus
    @apiGroup 自动化测试
    @apiDescription 查询 monkey 测试中断状态
    @apiParam {int} [monkey_id] Monkey ID
    @apiParam {int} [task_id] 具体设备测试项目的 ID
    @apiParamExample {json} Request-Example:
    {
        "task_id": 1
    }
    @apiSuccessExample {json} Success-Response:
     HTTP/1.1 200 OK
     {
        "code": 0,
        "data": {
            "cancel_status": 0,
            "id": 56
        },
        "message": "ok"
    }
    """
    task_id = request.args.get('task_id')
    if task_id:
        data = MonkeyDeviceStatusBusiness.query_cancel_status_by_id(task_id)
        return dict(data=data)
    else:
        raise FieldMissingException('task_id is required')
Esempio n. 4
0
def performance_name_by_monkey_get_handler():
    """
    @api {get} /v1/performance/name 根据 测试ID 获取场景列表
    @apiName GetPerformanceTestNameListByMonkeyId
    @apiGroup 自动化测试
    @apiDescription 根据 测试ID 获取场景列表
    @apiParam {int} [performance_id] 性能测试 id
    @apiParamExample {json} Request-Example:
    ?performance_id=260
    @apiSuccessExample {json} Success-Response:
     HTTP/1.1 200 OK
     {
      "code": 0,
      "data": ["Wechat-01", "Wechat-02"],
      "message": "ok"
    }
    """
    performance_id = request.args.get('performance_id')
    if not performance_id:
        raise FieldMissingException('performance_id is required')
    response = {
        "code": 0,
        "data":
        PerformanceTestBusiness.get_all_name_by_monkey_id(performance_id)
    }
    return response
Esempio n. 5
0
def monkey_error_log_index_handler():
    """
    @api {get} /v1/monkey/errorlog 查询 Monkey error log 列表
    @apiName GetMonkeyErrorLog
    @apiGroup 自动化测试
    @apiDescription 查询 Monkey 测试的错误日志
    @apiParam {int} [page_size] 分页-单页大小
    @apiParam {int} [page_index] 分页-页数
    @apiParam {int} [monkey_id] Monkey 的 ID
    @apiParam {int} [task_id] 单个设备的测试 ID
    @apiParamExample {json} Request-Example:
    {
        "page_size": 10,
        "page_index": 1,
        "monkey_id": 1
    }
    @apiSuccessExample {json} Success-Response:
     HTTP/1.1 200 OK
     {
        "code": 0,
        "data": [
            {
                "error_count": 1,
                "error_message": "['oom:\\n', '//OOM: com.mengtuiapp.mall (pid 28586)(dump time: 2019-07-03 12:13:56']",
                "error_type": "OOM",
                "id": 5,
                "monkey_id": 29
            }
        ],
        "message": "ok"
    }
    """
    page_size, page_index = parse_list_args2()
    page_size = page_size or 10
    page_index = page_index or 1

    monkey_id = request.args.get('monkey_id')
    task_id = request.args.get('task_id')

    if monkey_id:
        current_app.logger.info(
            'get error log <monkey_id> : {}'.format(monkey_id))
        error_logs = MonkeyErrorLogBusiness.query_json_by_monkey_id(
            monkey_id, page_size, page_index)
        count = MonkeyErrorLogBusiness.query_count_by_monkey_id(monkey_id)
    elif task_id:
        current_app.logger.info('get error log <task_id> : {}'.format(task_id))
        error_logs = MonkeyErrorLogBusiness.query_json_by_task_id(
            task_id, page_size, page_index)
        count = MonkeyErrorLogBusiness.query_count_by_task_id(task_id)
    else:
        raise FieldMissingException('no monkey id or task id found!')
    response = {
        "data": error_logs,
        "page_size": page_size,
        "page_index": page_index,
        "total": count
    }
    return response
Esempio n. 6
0
def performance_test_calculate_handler(id):
    if not id:
        raise FieldMissingException('id missing!')

    response = {
        "code": PerformanceTestBusiness.calculate_average(id),
        "data": []
    }
    return response
Esempio n. 7
0
def performance_name_by_device_get_handler():
    """
    @api {get} /v1/performance/device 根据 performance_id 获取场景列表
    @apiName GetPerformanceTestNameList
    @apiGroup 自动化测试
    @apiDescription 根据 performance_id 获取场景列表
    @apiParam {int} [performance_id] 性能测试 id
    @apiParamExample {json} Request-Example:
    ?performance_id=260
    @apiSuccessExample {json} Success-Response:
     HTTP/1.1 200 OK
     {
      "code": 0,
      "data": [
        {
          "id": 8,
          "name": "Wechat-01"
        },
        {
          "id": 9,
          "name": "Wechat-02"
        },
        {
          "id": 10,
          "name": "QQ-01"
        },
        {
          "id": 11,
          "name": "QQ-02"
        },
        {
          "id": 12,
          "name": "qjp"
        },
        {
          "id": 13,
          "name": "WPS"
        }
      ],
      "message": "ok"
    }
    """
    performance_id = request.args.get('performance_id')
    if not performance_id:
        raise FieldMissingException('performance_id is required')
    response = {
        "code": 0,
        "data": PerformanceTestBusiness.get_all_name(performance_id)
    }
    return response
Esempio n. 8
0
    def check_log_data(cls):

        record_id = request.args.get('record_id')
        if not record_id:
            raise FieldMissingException('miss record_id')
        deploy_record = DeployRecord.query.filter(DeployRecord.status == DeployRecord.ACTIVE,
                                                  DeployRecord.id == record_id).first()
        service_id = deploy_record.server_id
        node_id = deploy_record.node_id
        version = deploy_record.version

        if service_id and node_id and version:

            url = str(DeployBusiness.get_url()) + '/api/v1/deploy/all-result'

            header = {"api": DeployBusiness.get_token()}
            params = {"service_id": service_id, "node_id": node_id, "version": version}
            ret = requests.get(url=url, params=params, headers=header)
            ret = json.loads(ret.content)

            if ret and 'result' in ret:
                return ret['code'], ret['result'], ret['message']

        return 101, [], 'can not find object'