예제 #1
0
파일: views.py 프로젝트: sputnik-load/salts
def get_results(request):
    results = TestResult.objects.extra(
        select={
            "http_net": "http_errors_perc || '/' || net_errors_perc",
            "duration": "to_char(dt_finish - dt_start, 'HH24:MI:SS')",
            "dt_finish":
            "to_char(dt_finish at time zone 'MSK', 'YYYY-MM-DD HH24:MI:SS')",
            "comment": "comments"
        })
    results = results.values("id", "test_name", "target", "version", "rps",
                             "q99", "q90", "q50", "graph_url", "generator",
                             "dt_finish", "session_id", "scenario_path",
                             "group", "test_status", "ticket_id", "user",
                             "duration", "http_net", "comment")
    results = user_filter(request, results)
    sort_param = request_get_value(request, "sort")
    if sort_param:
        order = request_get_value(request, "order")
        if not order:
            order = "asc"
        if order == "asc":
            results = results.order_by(sort_param)
        else:
            results = results.order_by("-%s" % sort_param)
    query = """SELECT tmp.id, STRING_AGG(tmp.name, ' ') gen_type_list FROM
                        ( SELECT trgt.testresult_id id, gt.name FROM salts_testresult_generator_types trgt
                          JOIN salts_generatortype gt ON trgt.generatortype_id = gt.id
                          GROUP BY testresult_id, name
                          ORDER BY testresult_id, name
                        ) tmp
                GROUP BY id
            """
    gen_types_results = TestResult.objects.raw(query)
    gen_types = {}
    for r in gen_types_results:
        gen_types[r.id] = r.gen_type_list
    results = list(results)
    for r in results:
        if r["id"] in gen_types:
            r["gen_type_list"] = gen_types[r["id"]]
        else:
            r["gen_type_list"] = ""
        r["generator"] = "%s / %s" % (r["generator"], r["gen_type_list"])
        r['edit_url'] = edit_page_url(request, r['user'])

    offset = request_get_value(request, "offset")
    limit = request_get_value(request, "limit")

    response_dict = {}
    response_dict["total"] = len(results)
    if offset and limit:
        offset = int(offset)
        limit = int(limit)
        results = results[offset:offset + limit]
    response_dict["rows"] = results

    response = HttpResponse(json.dumps(response_dict),
                            content_type="application/json")
    add_version(response)
    return response
예제 #2
0
파일: views.py 프로젝트: sputnik-load/salts
def get_tank_status(request):
    log.info("get_tank_status: request.GET: %s" % request.GET)
    tank_id = request.GET.get('tank_id')
    if tank_id:
        tanks = Tank.objects.filter(id=tank_id)
    else:
        tanks = Tank.objects.all()
    results = []
    for t in tanks:
        shooting = t.shooting_set.exclude(
            start__isnull=True).order_by('-start').first()
        if not shooting:
            continue
        username = ''
        if shooting.user:
            if shooting.user.username == 'ltbot':
                username = shooting.alt_name  # временно, для консольных
                # тестов, чтобы обойти
                # аутентификацию
            else:
                username = shooting.user.username
        scenario_path = shooting.scenario.scenario_path
        values = {'id': t.id, 'host': t.host,
                  'username': username,
                  'gitlab_url': '%s%s' % (LT_GITLAB,
                                          shooting.scenario.scenario_path),
                  'scenario_name': \
                    ini_manager.get_scenario_name(scenario_path),
                  'status': shooting.status,
                  'countdown': remainedtime(shooting),
                  'shooting_id': shooting.id,
                  'ticket_id': shooting.ticket_id}
        port = tank_manager.read_from_lock(t.id, 'web_console_port')
        if port:
            values['webconsole'] = "%s:%s" % (t.host, port)
        if shooting.ticket_id:
            values['ticket_url'] = '%s%s' % (LT_JIRA, shooting.ticket_id)
        if shooting.status in ['F', 'I']:
            tr = TestResult.objects.filter(session_id=shooting.session_id)
            if tr:
                values['test_result'] = tr[0].id
        results.append(values)
    sort_param = request_get_value(request, 'sort')
    if sort_param:
        order = request_get_value(request, 'order')
        if not order:
            order = 'asc'
        reverse = order == 'desc'
        results = sorted(results, key=itemgetter('id'), reverse=reverse)

    response_dict = {}
    response_dict['total'] = len(results)
    response_dict['rows'] = results
    response = HttpResponse(json.dumps(response_dict),
                            content_type='application/json')
    add_version(response)
    return response
예제 #3
0
 def get(self, request):
     response = None
     if request_get_value(request, 'a'):
         response = self.get_test_status(request)
     else:
         context = generate_context(request)
         response = render_to_response('run_test.html', context)
     add_version(response)
     return response
예제 #4
0
    def get_test_status(self, request):
        b_value = request_get_value(request, 'b')
        scen_ids = []
        if b_value:
            jsonstr = bin2jsonstr(b_value)
            scen_ids = json.loads(jsonstr)
        scenarios = Scenario.objects.filter(
            group_id__in=User.objects.get(id=request.user.id).groups.all(),
            status='A')
        if scen_ids:
            scenarios = scenarios.filter(id__in=scen_ids)
        sh = Shooting.objects.filter(scenario_id__in=scenarios.values('id'))
        sh_max = sh.values('scenario_id').annotate(max_finish=Max('finish'))
        tr = TestResult.objects.filter(
            scenario_path__in=scenarios.values('scenario_path'))
        tr_max = tr.values('scenario_path').annotate(
            max_finish=Max('dt_finish'))
        active_sh = self.active_shootings()
        sort = request_get_value(request, "sort")
        if sort:
            order = request_get_value(request, "order")
            reverse = ""
            if not order:
                order = "asc"
            if order == "desc":
                reverse = "-"
            scenarios = scenarios.order_by("%sid" % reverse)
        response_dict = {}
        response_dict["total"] = len(scenarios)
        offset = request_get_value(request, "offset")
        limit = request_get_value(request, "limit")
        if offset and limit:
            offset = int(offset)
            limit = int(limit)
            scenarios = scenarios[offset:offset + limit]

        results = []
        # tanks = self.get_active_tanks(request.META["HTTP_HOST"])
        tanks = self.get_active_tanks()
        for s in scenarios:
            values = {}
            values["id"] = s.id
            values["test_name"] = ini_manager.get_scenario_name(
                s.scenario_path)
            if not ini_manager.get_used_for_web(s.scenario_path):
                log.warning("The {path} config is not used "
                            "via web.".format(path=s.scenario_path))
                continue
            values["default_data"] = self.get_default_data(s.scenario_path)
            values["tank_host"] = {"id": "-1", "name": ""}
            if "error" not in values["default_data"]:
                try:
                    values["tank_host"] = self.select_tank_host(
                        tanks, active_sh, values["default_data"]["hostname"],
                        values["default_data"]["port"], s.scenario_path)
                    values["last"] = {}
                    shs = sh_max.filter(scenario_id=s.id)
                    trs = tr_max.filter(scenario_path=s.scenario_path)
                    if shs and trs:
                        trs = TestResult.objects.filter(
                            scenario_path=s.scenario_path,
                            dt_finish=trs[0]["max_finish"])
                        values["last"] = {
                            "tr_id": trs[0].id,
                            "finish": shs[0]["max_finish"]
                        }
                except IniCtrlWarning, exc:
                    values["default_data"]["error"] = {
                        "name": exc.name,
                        "params": exc.params
                    }
            results.append(values)
예제 #5
0
파일: views.py 프로젝트: sputnik-load/salts
def user_filter(request, results):
    scenario_id = request_get_value(request, "scid")
    scenario_path = request_get_value(request, "scpath")
    target = request_get_value(request, "trg")
    gen_type = request_get_value(request, "gt")
    generator = request_get_value(request, "gen")
    test_group = request_get_value(request, "tg")
    test_search = request_get_value(request, "ts")
    status = request_get_value(request, "st")
    task_id = request_get_value(request, "tid")
    spe = request_get_value(request, "spe")
    from_time = request_get_value(request, "from")
    to_time = request_get_value(request, "to")
    rps_value = request_get_value(request, "rps")
    if scenario_id:
        try:
            s = Scenario.objects.get(id=scenario_id)
            scenario_path = s.scenario_path
        except Scenario.DoesNotExist:
            log.warning("The scid=%s parameter from request does not exist.",
                        scenario_id)
    if scenario_path:
        results = results.filter(scenario_path=scenario_path)
    if target:
        results = results.filter(target__contains=target)
    if test_group:
        results = results.filter(group=test_group)
    if test_search:
        results = results.filter(test_name__contains=test_search)
    if gen_type:
        results = results.filter(generator_types__name__contains=gen_type)
    if generator:
        results = results.filter(generator__contains=generator)
    if rps_value:
        results = results.filter(rps=rps_value)
    if status:
        status = status.split(",")
        for (i, item) in enumerate(status):
            if item == "unknown":
                status[i] = u"unk"
            if item == "debug":
                status[i] = u"dbg"
        results = results.filter(test_status__in=status)
    if task_id:
        results = results.filter(ticket_id=task_id)
    if spe:
        results = results.filter(user=spe)
    if from_time:
        from_time = from_time.replace("_", " ")
        results = results.filter(dt_finish__gte=from_time)
    if to_time:
        to_time = to_time.replace("_", " ")
        results = results.filter(dt_finish__lte=to_time)
    return results