Пример #1
0
    def _process_openshift_error(self, ex: ApiException):
        sentry_integration.send_to_sentry(ex)

        error_message = f"({ex.status})\nReason: {ex.reason}\n"
        if ex.headers:
            error_message += f"HTTP response headers: {ex.headers}\n"

        if ex.body:
            try:
                json_content = json.loads(ex.body)
                formatted_json = json.dumps(json_content, indent=2)
                error_message += f"HTTP response body:\n{formatted_json}\n"
            except json.JSONDecodeError:
                error_message += f"HTTP response body: {ex.body}\n"

        msg = (
            f"There was a problem in the environment the service is running in:\n"
            f"```\n"
            f"{error_message}\n"
            f"```\n")

        logger.error(msg)
        comment_msg = (
            f"{msg}\n"
            f"{self.msg_retrigger}\n\n"
            "Please, contact "
            "[Packit team](https://github.com/orgs/packit-service/teams/the-packit-team) "
            "if the re-trigger did not help.")
        self.project.pr_comment(self.event.pr_id, comment_msg)

        self.report_status_to_all(
            state="error",
            description="Build failed, check the comments for details.",
        )
        return HandlerResults(success=False, details={"msg": msg})
Пример #2
0
    def run(self) -> HandlerResults:
        """
        Sync the upstream release to dist-git as a pull request.
        """

        self.local_project = LocalProject(
            git_project=self.project,
            working_dir=self.config.command_handler_work_dir)

        self.api = PackitAPI(self.config, self.package_config,
                             self.local_project)

        errors = []
        for branch in get_branches(
                self.job.metadata.get("dist-git-branch", "master")):
            try:
                self.api.sync_release(dist_git_branch=branch,
                                      version=self.event.tag_name)
            except Exception as ex:
                sentry_integration.send_to_sentry(ex)
                errors.append(
                    f"Propose update for branch {branch} failed: {ex}")

        if errors:
            return HandlerResults(
                success=False,
                details={
                    "msg": "Propose update failed.",
                    "errors": errors
                },
            )

        return HandlerResults(success=True, details={})
Пример #3
0
 def _process_failed_srpm_build(self, ex):
     sentry_integration.send_to_sentry(ex)
     msg = f"Failed to create a SRPM: {ex}"
     self.status_reporter.report(
         state="failure",
         description=str(ex),
         check_names=PRCheckName.get_srpm_build_check(),
     )
     self.status_reporter.report_tests_failed_because_of_the_build(
         test_check_names=self.test_check_names
     )
     return HandlerResults(success=False, details={"msg": msg})
Пример #4
0
 def _process_failed_srpm_build(self, ex):
     sentry_integration.send_to_sentry(ex)
     msg = (
         f"There was an error while creating SRPM. {self.msg_retrigger}\n"
         "\nOutput:"
         "\n```\n"
         f"{ex}"
         "\n```")
     self.project.pr_comment(self.event.pr_id, msg)
     short_msg = "Failed to create SRPM."
     self.report_status_to_all(description=short_msg, state="error")
     return HandlerResults(success=False, details={"msg": short_msg})
Пример #5
0
    def run(self) -> HandlerResults:
        """
        Sync the upstream release to dist-git as a pull request.
        """

        self.local_project = LocalProject(
            git_project=self.project,
            working_dir=self.config.command_handler_work_dir)

        self.api = PackitAPI(self.config, self.package_config,
                             self.local_project)

        errors = {}
        for branch in get_branches(
                self.job.metadata.get("dist-git-branch", "master")):
            try:
                self.api.sync_release(dist_git_branch=branch,
                                      version=self.event.tag_name)
            except Exception as ex:
                sentry_integration.send_to_sentry(ex)
                errors[branch] = str(ex)

        if errors:
            branch_errors = ""
            for branch, err in sorted(
                    errors.items(), key=lambda branch_error: branch_error[0]):
                err_without_new_lines = err.replace("\n", " ")
                branch_errors += f"| `{branch}` | `{err_without_new_lines}` |\n"

            body_msg = (
                f"Packit failed on creating pull-requests in dist-git:\n\n"
                f"| dist-git branch | error |\n"
                f"| --------------- | ----- |\n"
                f"{branch_errors}\n\n"
                "You can re-trigger the update by adding `/packit propose-update`"
                " to the issue comment.\n")

            self.project.create_issue(
                title=
                f"[packit] Propose update failed for release {self.event.tag_name}",
                body=body_msg,
            )

            return HandlerResults(
                success=False,
                details={
                    "msg": "Propose update failed.",
                    "errors": errors
                },
            )

        return HandlerResults(success=True, details={})
Пример #6
0
 def _process_general_exception(self, ex):
     sentry_integration.send_to_sentry(ex)
     msg = f"There was an error while running a copr build:\n```\n{ex}\n```\n"
     logger.error(msg)
     self.project.pr_comment(self.event.pr_id, f"{msg}\n{MSG_RETRIGGER}")
     self.status_reporter.report(
         state="failure",
         description="Build failed, check latest comment for details.",
         check_names=self.build_check_names,
     )
     self.status_reporter.report_tests_failed_because_of_the_build(
         test_check_names=self.test_check_names
     )
     return HandlerResults(success=False, details={"msg": msg})
Пример #7
0
 def _process_general_exception(self, ex):
     sentry_integration.send_to_sentry(ex)
     msg = f"There was an error while running a copr build:\n```\n{ex}\n```\n"
     logger.error(msg)
     self.project.pr_comment(self.event.pr_id, f"{msg}\n{self.msg_retrigger}")
     self.report_status_to_build(
         state="failure",
         description="Build failed, check latest comment for details.",
     )
     self.report_status_to_tests(
         state="error",
         description="Build failed, check latest comment for details.",
     )
     return HandlerResults(success=False, details={"msg": msg})
Пример #8
0
 def _process_copr_submit_exception(self, ex):
     sentry_integration.send_to_sentry(ex)
     msg = (f"There was an error while submitting a Copr build:\n"
            f"```\n"
            f"{ex}\n"
            f"```\n"
            f"Check carefully your configuration.\n")
     logger.error(msg)
     self.project.pr_comment(self.event.pr_id,
                             f"{msg}\n{self.msg_retrigger}")
     self.report_status_to_all(
         state="error",
         description=
         "Submit of the build failed, check comments for details.",
     )
     return HandlerResults(success=False, details={"msg": msg})
Пример #9
0
 def _process_failed_command(self, ex):
     max_log_size = 1024 * 16  # is 16KB enough?
     if len(ex.output) > max_log_size:
         output = "Earlier output was truncated\n\n" + ex.output[-max_log_size:]
     else:
         output = ex.output
     msg = (
         f"There was an error while creating SRPM. {self.msg_retrigger}\n"
         "\nOutput:"
         "\n```\n"
         f"{output}"
         "\n```"
         f"\nReturn code: {ex.rc}"
     )
     self.project.pr_comment(self.event.pr_id, msg)
     sentry_integration.send_to_sentry(output)
     msg = "Failed to create SRPM."
     self.report_status_to_all(
         state="error", description=msg,
     )
     return HandlerResults(success=False, details={"msg": msg})
Пример #10
0
 def _process_failed_command(self, ex):
     max_log_size = 1024 * 16  # is 16KB enough?
     if len(ex.output) > max_log_size:
         output = "Earlier output was truncated\n\n" + ex.output[-max_log_size:]
     else:
         output = ex.output
     msg = (
         f"There was an error while creating a SRPM. {MSG_RETRIGGER}\n"
         "\nOutput:"
         "\n```\n"
         f"{output}"
         "\n```"
         f"\nReturn code: {ex.rc}"
     )
     self.project.pr_comment(self.event.pr_id, msg)
     sentry_integration.send_to_sentry(output)
     msg = "Failed to create a SRPM."
     self.status_reporter.report(
         state="failure",
         description=msg,
         check_names=PRCheckName.get_srpm_build_check(),
     )
     return HandlerResults(success=False, details={"msg": msg})
Пример #11
0
    def run_testing_farm(self, chroot: str) -> HandlerResults:
        if chroot not in self.tests_chroots:
            # Leaving here just to be sure that we will discover this situation if it occurs.
            # Currently not possible to trigger this situation.
            msg = f"Target '{chroot}' not defined for tests but triggered."
            logger.error(msg)
            send_to_sentry(PackitConfigException(msg))
            return HandlerResults(
                success=False,
                details={"msg": msg},
            )

        if chroot not in self.build_chroots:
            self.report_missing_build_chroot(chroot)
            return HandlerResults(
                success=False,
                details={
                    "msg":
                    f"Target '{chroot}' not defined for build. "
                    f"Cannot run tests without build."
                },
            )

        self.report_status_to_test_for_chroot(
            state="pending",
            description="Build succeeded. Submitting the tests ...",
            chroot=chroot,
        )

        pipeline_id = str(uuid.uuid4())
        logger.debug(f"Pipeline id: {pipeline_id}")
        payload: dict = {
            "pipeline": {
                "id": pipeline_id
            },
            "api": {
                "token": self.config.testing_farm_secret
            },
        }

        stg = "-stg" if self.config.deployment == Deployment.stg else ""
        copr_repo_name = (
            f"packit/{self.project.namespace}-{self.project.repo}-"
            f"{self.event.pr_id}{stg}")

        payload["artifact"] = {
            "repo-name": self.event.base_repo_name,
            "repo-namespace": self.event.base_repo_namespace,
            "copr-repo-name": copr_repo_name,
            "copr-chroot": chroot,
            "commit-sha": self.event.commit_sha,
            "git-url": self.event.project_url,
            "git-ref": self.base_ref,
        }

        logger.debug("Sending testing farm request...")
        logger.debug(payload)

        req = self.send_testing_farm_request(TESTING_FARM_TRIGGER_URL, "POST",
                                             {}, json.dumps(payload))
        logger.debug(f"Request sent: {req}")
        if not req:
            msg = "Failed to post request to testing farm API."
            logger.debug("Failed to post request to testing farm API.")
            self.report_status_to_test_for_chroot(
                state="failure",
                description=msg,
                chroot=chroot,
            )
            return HandlerResults(success=False, details={"msg": msg})
        else:
            logger.debug(
                f"Submitted to testing farm with return code: {req.status_code}"
            )
            """
            Response:
            {
                "id": "9fa3cbd1-83f2-4326-a118-aad59f5",
                "success": true,
                "url": "https://console-testing-farm.apps.ci.centos.org/pipeline/<id>"
            }
            """

            # success set check on pending
            if req.status_code != 200:
                # something went wrong
                if req.json() and "message" in req.json():
                    msg = req.json()["message"]
                else:
                    msg = f"Failed to submit tests: {req.reason}"
                    logger.error(msg)
                self.report_status_to_test_for_chroot(
                    state="failure",
                    description=msg,
                    chroot=chroot,
                )
                return HandlerResults(success=False, details={"msg": msg})

            self.report_status_to_test_for_chroot(
                state="pending",
                description="Tests are running ...",
                url=req.json()["url"],
                chroot=chroot,
            )

        return HandlerResults(success=True, details={})