示例#1
0
    def run(self, complect_revision_id):
        """
        Run deploy process
        :param complect_revision_id:
        :return:
        """

        # Check complect_revision_id exists
        if complect_revision_id is None:
            raise ApiError(code="COMPLECT_REVISION_ID",
                           message="Complect revision id can't be null")

        # Query complect revision information, we need Complect deploy_target
        complect_revision_response = post_request(
            url=PROCESSOR_HOST,
            headers=HEADERS,
            request_data=get_info_request(
                method="complect_revision.fetch",
                id=complect_revision_id,
            ))

        complect_revision_result = complect_revision_response["result"]
        if complect_revision_result.get("errors", {}).get("code") \
                is not None:
            raise ApiError(
                code=complect_revision_result["errors"]["code"],
                message=complect_revision_result["errors"]["message"],
            )

        # Query complect by complect_id
        complect_id = complect_revision_result["response"]["complect_id"]
        with self.create_session() as session:
            complect_model = session.query(Complect).get(complect_id)
            deploy_target = complect_model.deploy_target

        response = post_request(
            url=PROCESSOR_HOST,
            headers=HEADERS,
            request_data=get_create_request(
                method="task.create",
                script="scripts.deploy.run",
                type=self.TASK_TYPE,
                extra={"complect_revision_id": complect_revision_id},
                args={
                    "complect_revision_id": complect_revision_id,
                    "target": deploy_target,
                }))
        result = response["result"]

        if not result["status"]:
            raise ApiError(code="UNHANDLED",
                           message=result["errors"]["message"])

        return result["response"]
示例#2
0
    def export(self, ids):
        """
        Экспортирование шаблонов
        """
        dictionaries = {}

        for dict_id in ids:
            dictionaries[dict_id] = {}

            suite = self.fetch(dict_id)

            dictionaries[dict_id][
                "name"] = suite["code"] or suite.dictionary_id  # noqa
            dictionaries[dict_id]["content"] = suite["content"]

        result = post_request(url=PROCESSOR_HOST,
                              headers=None,
                              request_data=get_create_request(
                                  method="task.create",
                                  script="scripts.dictionaries.export_run",
                                  type=TYPE,
                                  args={"dictionaries": dictionaries}))

        result = result["result"]
        if result["status"]:
            return result["response"]

        raise ApiError(code="UNHANDLED", message=result["errors"]["message"])
示例#3
0
    def _get_complect_revision_list(self, *, complect_id, offset, limit,
                                    order):
        result = post_request(url=PROCESSOR_HOST,
                              headers=HEADERS,
                              request_data=get_info_request(
                                  method="complect_revision.list",
                                  complect_id=complect_id,
                                  offset=offset,
                                  limit=limit,
                                  order=order))

        return result
示例#4
0
    def info(task_id):
        """
        Получение информации о задаче
        """
        result = post_request(
            url=PROCESSOR_HOST, headers=HEADERS,
            request_data=get_info_request(method="task.info", task_id=task_id)
        )

        result = result["result"]
        if result["status"]:
            return result["response"]

        raise ApiError(code="NOT_EXISTS", message=result["errors"]["message"])
示例#5
0
    def result(task_id):
        """
        Получение результата по задаче
        """
        result = post_request(
            url=PROCESSOR_HOST, headers=None,
            request_data=get_info_request(method="task.info", task_id=task_id)
        )

        result = result["result"]
        if result["status"]:
            return result["response"]

        raise ApiError(
            code="PROCESSOR_SERVICE", message=result["errors"]["message"]
        )
示例#6
0
    def result_list(offset=None, limit=None):
        """
        Получение списка задача/статус
        """
        result = post_request(
            url=PROCESSOR_HOST, headers=None,
            request_data=get_info_request(
                method="task.list", type=TYPE, offset=offset, limit=limit
            )
        )

        result = result["result"]
        if result["status"]:
            return result["response"]

        raise ApiError(code="NOT_EXISTS", message=result["errors"]["message"])
示例#7
0
    def run(self, profile_id, ids):
        """
        Запуск
        """
        if len(ids) > MAX_COUNT_TESTCASE_TO_RUN:
            raise ApiError(
                code="COUNT_TESTCASES",
                message="Количество тесткейсов превышает допустимое количество"
                        " {} для одного запуска".format(
                            MAX_COUNT_TESTCASE_TO_RUN
                        )
            )

        def form_items(items):
            res = []
            for item, _ in items:
                res.append(item.to_short_dict())

            return res

        filter_q = [
            Testcase.profile_id == profile_id, Testcase.testcase_id.in_(ids)
        ]
        testcases, _ = self.testcase.filter(
            filter_q=filter_q, limit=len(ids),
            form_items=form_items  # TODO: ? Так оно точно работает?
        )

        profile = ProfileRpc(
            tracer=self.tracer, create_session=self.create_session
        )
        profile_info = profile.fetch(profile_id)

        result = post_request(
            url=PROCESSOR_HOST, headers=None,
            request_data=get_create_request(
                method="task.create", script="scripts.testcase.run",
                type=TYPE, args={
                    "ids": ids, "testcases": testcases,
                    "profile_info": profile_info
                }
            )
        )

        return result["result"]["response"]
示例#8
0
    def list_(cls, extra=None, offset=None, limit=None, order=None):
        """
        Get deploy task's list
        """
        result = post_request(url=PROCESSOR_HOST,
                              headers=HEADERS,
                              request_data=get_info_request(method="task.list",
                                                            type=cls.TASK_TYPE,
                                                            extra=extra,
                                                            offset=offset,
                                                            limit=limit,
                                                            order=order))

        result = result["result"]
        if result["status"]:
            return result["response"]

        raise ApiError(code="NOT_EXISTS", message=result["errors"]["message"])
示例#9
0
    def list_(extra=None, offset=None, limit=None, order=None):
        """
        Получение списка задач по типу
        """

        result = post_request(
            url=PROCESSOR_HOST, headers=HEADERS,
            request_data=get_info_request(
                method="task.list", type="compiler",
                extra=extra,
                offset=offset, limit=limit, order=order
            )
        )

        result = result["result"]
        if result["status"]:
            return result["response"]

        raise ApiError(code="NOT_EXISTS", message=result["errors"]["message"])
示例#10
0
    def create(self, complect_id, try_create_revision=False):
        """
        Создание задачи
        """
        if complect_id is None:
            raise ApiError(
                code="INVALID_COMPLECT_ID", message="Complect id can't be null"
            )

        with self.create_session() as session:
            tiny_complect = session.query(Complect).options(
                load_only("compiler_target")
            ).get(complect_id)

        if tiny_complect is None:
            raise ApiError(
                code="NOT_EXISTS",
                message="Can't find complect with id=%r" % complect_id
            )

        response = post_request(
            url=PROCESSOR_HOST,
            headers=HEADERS,
            request_data=get_create_request(
                method="task.create",
                script="scripts.processor.run",
                type="compiler",
                extra={"complect_id": complect_id},
                args={
                    "complect_id": complect_id,
                    "target": tiny_complect.compiler_target,
                    "try_create_revision": try_create_revision,
                }
            )
        )

        result = response["result"]
        if result["status"]:
            return result["response"]

        raise ApiError(code="UNHANDLED", message=result["errors"]["message"])
示例#11
0
    def import_file(profile_ids, file_name, data):
        """
        Импортирование словарей из файла
        """
        result = post_request(url=PROCESSOR_HOST,
                              headers=None,
                              request_data=get_create_request(
                                  method="task.create",
                                  script="scripts.dictionary.import_run",
                                  type=TYPE,
                                  args={
                                      "profile_ids": profile_ids,
                                      "file_name": file_name,
                                      "data": data,
                                  }))

        result = result["result"]
        if result["status"]:
            return result["response"]

        raise ApiError(code="UNHANDLED", message=result["errors"]["message"])
示例#12
0
    def export(self, ids):
        """
        Экспортирование шаблонов
        """
        suites = {}
        template_rpc = TemplateRpc(
            tracer=self.tracer, create_session=self.create_session
        )

        for suite_id in ids:
            suites[suite_id] = {}

            suite = self.fetch(suite_id)

            suites[suite_id]["name"] = suite["title"] or suite_id

            suites[suite_id]["templates"] = []
            templates = template_rpc.list(suite_id=suite_id)

            for template in templates["items"]:
                suites[suite_id]["templates"].append(template["content"])

        result = post_request(
            url=PROCESSOR_HOST, headers=None,
            request_data=get_create_request(
                method="task.create",
                script="scripts.suite.export_run",
                type=TYPE,
                args={"suites": suites}
            )
        )

        result = result["result"]
        if result["status"]:
            return result["response"]

        raise ApiError(code="UNHANDLED", message=result["errors"]["message"])