Beispiel #1
0
def multiple_koji_builds(pr_model, different_pr_model, srpm_build_model):
    yield [
        KojiBuildModel.get_or_create(
            build_id=SampleValues.build_id,
            commit_sha=SampleValues.commit_sha,
            web_url=SampleValues.koji_web_url,
            target=SampleValues.target,
            status=SampleValues.status_pending,
            srpm_build=srpm_build_model,
            trigger_model=pr_model,
        ),
        KojiBuildModel.get_or_create(
            build_id=SampleValues.different_build_id,
            commit_sha=SampleValues.commit_sha,
            web_url=SampleValues.koji_web_url,
            target=SampleValues.different_target,
            status=SampleValues.status_pending,
            srpm_build=srpm_build_model,
            trigger_model=pr_model,
        ),
        # Completely different build
        KojiBuildModel.get_or_create(
            build_id=SampleValues.another_different_build_id,
            commit_sha=SampleValues.different_commit_sha,
            web_url=SampleValues.koji_web_url,
            target=SampleValues.target,
            status=SampleValues.status_pending,
            srpm_build=srpm_build_model,
            trigger_model=different_pr_model,
        ),
    ]
Beispiel #2
0
def multiple_koji_builds(pr_trigger_model, different_pr_trigger_model):
    srpm_build = SRPMBuildModel.create("asd\nqwe\n")
    yield [
        KojiBuildModel.get_or_create(
            build_id="123456",
            commit_sha="687abc76d67d",
            web_url="https://copr.something.somewhere/123456",
            target="fedora-42-x86_64",
            status="pending",
            srpm_build=srpm_build,
            trigger_model=pr_trigger_model,
        ),
        # Same build_id but different chroot
        KojiBuildModel.get_or_create(
            build_id="123456",
            commit_sha="687abc76d67d",
            web_url="https://copr.something.somewhere/123456",
            target="fedora-43-x86_64",
            status="pending",
            srpm_build=srpm_build,
            trigger_model=pr_trigger_model,
        ),
        # Completely different build
        KojiBuildModel.get_or_create(
            build_id="987654",
            commit_sha="987def76d67e",
            web_url="https://copr.something.somewhere/987654",
            target="fedora-43-x86_64",
            status="pending",
            srpm_build=srpm_build,
            trigger_model=different_pr_trigger_model,
        ),
    ]
def test_copr_and_koji_build_for_one_trigger(clean_before_and_after):
    pr1 = PullRequestModel.get_or_create(
        pr_id=1, namespace="the-namespace", repo_name="the-repo-name"
    )
    pr1_trigger = JobTriggerModel.get_or_create(
        type=JobTriggerModelType.pull_request, trigger_id=pr1.id
    )
    srpm_build = SRPMBuildModel.create("asd\nqwe\n")
    copr_build = CoprBuildModel.get_or_create(
        build_id="123456",
        commit_sha="687abc76d67d",
        project_name="SomeUser-hello-world-9",
        owner="packit",
        web_url="https://copr.something.somewhere/123456",
        target=TARGET,
        status="pending",
        srpm_build=srpm_build,
        trigger_model=pr1,
    )
    koji_build = KojiBuildModel.get_or_create(
        build_id="987654",
        commit_sha="687abc76d67d",
        web_url="https://copr.something.somewhere/123456",
        target=TARGET,
        status="pending",
        srpm_build=srpm_build,
        trigger_model=pr1,
    )

    assert copr_build in pr1_trigger.copr_builds
    assert koji_build in pr1_trigger.koji_builds

    assert copr_build.job_trigger.get_trigger_object() == pr1
    assert koji_build.job_trigger.get_trigger_object() == pr1
Beispiel #4
0
def a_koji_build_for_release(release_model, srpm_build_model):
    yield KojiBuildModel.get_or_create(
        build_id=SampleValues.build_id,
        commit_sha=SampleValues.commit_sha,
        web_url=SampleValues.koji_web_url,
        target=SampleValues.target,
        status=SampleValues.status_pending,
        srpm_build=srpm_build_model,
        trigger_model=release_model,
    )
Beispiel #5
0
def a_koji_build(pr_model):
    srpm_build = SRPMBuildModel.create("asd\nqwe\n")
    yield KojiBuildModel.get_or_create(
        build_id="123456",
        commit_sha="687abc76d67d",
        web_url="https://copr.something.somewhere/123456",
        target=TARGET,
        status="pending",
        srpm_build=srpm_build,
        trigger_model=pr_model,
    )
Beispiel #6
0
    def run_koji_build(self) -> TaskResults:
        if not self.is_scratch:
            msg = "Non-scratch builds not possible from upstream."
            self.report_status_to_all(
                description=msg,
                state=CommitStatus.error,
                url=KOJI_PRODUCTION_BUILDS_ISSUE,
            )
            return TaskResults(success=True, details={"msg": msg})

        self.report_status_to_all(
            description="Building SRPM ...", state=CommitStatus.pending
        )
        self.create_srpm_if_needed()

        if not self.srpm_model.success:
            msg = "SRPM build failed, check the logs for details."
            self.report_status_to_all(
                state=CommitStatus.failure,
                description=msg,
                url=get_srpm_log_url_from_flask(self.srpm_model.id),
            )
            return TaskResults(success=False, details={"msg": msg})

        try:
            # We need to do it manually
            # because we don't use PackitAPI.build, but PackitAPI.up.koji_build
            self.api.init_kerberos_ticket()
        except PackitCommandFailedError as ex:
            msg = f"Kerberos authentication error: {ex.stderr_output}"
            logger.error(msg)
            self.report_status_to_all(
                state=CommitStatus.error,
                description=msg,
                url=get_srpm_log_url_from_flask(self.srpm_model.id),
            )
            return TaskResults(success=False, details={"msg": msg})

        errors: Dict[str, str] = {}
        for target in self.build_targets:

            if target not in self.supported_koji_targets:
                msg = f"Target not supported: {target}"
                self.report_status_to_all_for_chroot(
                    state=CommitStatus.error,
                    description=msg,
                    url=get_srpm_log_url_from_flask(self.srpm_model.id),
                    chroot=target,
                )
                errors[target] = msg
                continue

            try:
                build_id, web_url = self.run_build(target=target)
            except Exception as ex:
                sentry_integration.send_to_sentry(ex)
                # TODO: Where can we show more info about failure?
                # TODO: Retry
                self.report_status_to_all_for_chroot(
                    state=CommitStatus.error,
                    description=f"Submit of the build failed: {ex}",
                    url=get_srpm_log_url_from_flask(self.srpm_model.id),
                    chroot=target,
                )
                errors[target] = str(ex)
                continue

            koji_build = KojiBuildModel.get_or_create(
                build_id=str(build_id),
                commit_sha=self.metadata.commit_sha,
                web_url=web_url,
                target=target,
                status="pending",
                srpm_build=self.srpm_model,
                trigger_model=self.db_trigger,
            )
            url = get_koji_build_info_url_from_flask(id_=koji_build.id)
            self.report_status_to_all_for_chroot(
                state=CommitStatus.pending,
                description="Building RPM ...",
                url=url,
                chroot=target,
            )

        if errors:
            return TaskResults(
                success=False,
                details={
                    "msg": "Koji build submit was not successful for all chroots.",
                    "errors": errors,
                },
            )

        # TODO: release the hounds!
        """
        celery_app.send_task(
            "task.babysit_koji_build",
            args=(build_metadata.build_id,),
            countdown=120,  # do the first check in 120s
        )
        """

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