Ejemplo n.º 1
0
def build_helper(
    event: Union[
        PullRequestGithubEvent,
        PullRequestCommentGithubEvent,
        PushGitHubEvent,
        ReleaseEvent,
    ],
    metadata=None,
    trigger=None,
    jobs=None,
    db_trigger=None,
):
    if not metadata:
        metadata = JobMetadataConfig(
            targets=[
                "fedora-29-x86_64",
                "fedora-30-x86_64",
                "fedora-31-x86_64",
                "fedora-rawhide-x86_64",
            ],
            owner="nobody",
        )
    jobs = jobs or []
    jobs.append(
        JobConfig(
            type=JobType.production_build,
            trigger=trigger or JobConfigTriggerType.pull_request,
            metadata=metadata,
        )
    )

    pkg_conf = PackageConfig(jobs=jobs, downstream_package_name="dummy")
    handler = KojiBuildJobHelper(
        service_config=ServiceConfig(),
        package_config=pkg_conf,
        job_config=pkg_conf.jobs[0],
        project=GitProject(repo=flexmock(), service=flexmock(), namespace=flexmock()),
        metadata=flexmock(
            trigger=event.trigger,
            pr_id=event.pr_id,
            git_ref=event.git_ref,
            commit_sha=event.commit_sha,
            identifier=event.identifier,
        ),
        db_trigger=db_trigger,
    )
    handler._api = PackitAPI(config=ServiceConfig(), package_config=pkg_conf)
    return handler
Ejemplo n.º 2
0
 def koji_build_helper(self) -> KojiBuildJobHelper:
     if not self._koji_build_helper:
         self._koji_build_helper = KojiBuildJobHelper(
             config=self.config,
             package_config=self.package_config,
             project=self.project,
             event=self.event,
             job=self.job_config,
         )
     return self._koji_build_helper
Ejemplo n.º 3
0
 def koji_build_helper(self) -> KojiBuildJobHelper:
     if not self._koji_build_helper:
         self._koji_build_helper = KojiBuildJobHelper(
             service_config=self.service_config,
             package_config=self.package_config,
             project=self.project,
             metadata=self.data,
             db_trigger=self.data.db_trigger,
             job_config=self.job_config,
         )
     return self._koji_build_helper
Ejemplo n.º 4
0
def test_koji_targets_overrides(jobs, job_config_trigger_type,
                                targets_override, build_targets):
    koji_build_helper = KojiBuildJobHelper(
        service_config=flexmock(),
        package_config=PackageConfig(jobs=jobs),
        job_config=jobs[0],
        project=flexmock(),
        metadata=flexmock(),
        db_trigger=flexmock(job_config_trigger_type=job_config_trigger_type),
        targets_override=targets_override,
    )
    assert koji_build_helper.build_targets == build_targets
Ejemplo n.º 5
0
def test_targets_for_koji_build(jobs, trigger, job_config_trigger_type,
                                build_targets, koji_targets):
    pr_id = 41 if trigger == TheJobTriggerType.pull_request else None
    koji_build_handler = KojiBuildJobHelper(
        service_config=flexmock(),
        package_config=PackageConfig(jobs=jobs),
        job_config=jobs[0],
        project=flexmock(),
        metadata=flexmock(trigger=trigger, pr_id=pr_id),
        db_trigger=flexmock(job_config_trigger_type=job_config_trigger_type),
    )

    assert koji_build_handler.package_config.jobs
    assert [j.type for j in koji_build_handler.package_config.jobs]

    assert koji_build_handler.configured_build_targets == build_targets
    assert koji_build_handler.build_targets == koji_targets
Ejemplo n.º 6
0
    def run(self):
        build = KojiBuildModel.get_by_build_id(
            build_id=str(self.koji_event.build_id))

        if not build:
            msg = f"Koji build {self.koji_event.build_id} not found in the database."
            logger.warning(msg)
            return TaskResults(success=False, details={"msg": msg})

        logger.debug(
            f"Build on {build.target} in koji changed state "
            f"from {self.koji_event.old_state} to {self.koji_event.state}.")

        build.set_build_start_time(
            datetime.utcfromtimestamp(self.koji_event.start_time) if self.
            koji_event.start_time else None)

        build.set_build_finished_time(
            datetime.utcfromtimestamp(self.koji_event.completion_time) if self.
            koji_event.completion_time else None)

        url = get_koji_build_info_url_from_flask(build.id)
        build_job_helper = KojiBuildJobHelper(
            service_config=self.service_config,
            package_config=self.package_config,
            project=self.project,
            metadata=self.data,
            db_trigger=self.db_trigger,
            job_config=self.job_config,
        )

        if self.koji_event.state == KojiBuildState.open:
            build.set_status("pending")
            build_job_helper.report_status_to_all_for_chroot(
                description="RPM build is in progress...",
                state=CommitStatus.pending,
                url=url,
                chroot=build.target,
            )
        elif self.koji_event.state == KojiBuildState.closed:
            build.set_status("success")
            build_job_helper.report_status_to_all_for_chroot(
                description="RPMs were built successfully.",
                state=CommitStatus.success,
                url=url,
                chroot=build.target,
            )
        elif self.koji_event.state == KojiBuildState.failed:
            build.set_status("failed")
            build_job_helper.report_status_to_all_for_chroot(
                description="RPMs failed to be built.",
                state=CommitStatus.failure,
                url=url,
                chroot=build.target,
            )
        elif self.koji_event.state == KojiBuildState.canceled:
            build.set_status("error")
            build_job_helper.report_status_to_all_for_chroot(
                description="RPMs build was canceled.",
                state=CommitStatus.error,
                url=url,
                chroot=build.target,
            )
        else:
            logger.debug(
                f"We don't react to this koji build state change: {self.koji_event.state}"
            )

        koji_build_logs = self.koji_event.get_koji_build_logs_url()
        build.set_build_logs_url(koji_build_logs)
        koji_rpm_task_web_url = self.koji_event.get_koji_build_logs_url()
        build.set_web_url(koji_rpm_task_web_url)

        msg = (f"Build on {build.target} in koji changed state "
               f"from {self.koji_event.old_state} to {self.koji_event.state}.")
        return TaskResults(success=True, details={"msg": msg})
Ejemplo n.º 7
0
    def run(self):
        build = KojiBuildModel.get_by_build_id(
            build_id=str(self.koji_task_event.build_id)
        )

        if not build:
            msg = (
                f"Koji build {self.koji_task_event.build_id} not found in the database."
            )
            logger.warning(msg)
            return TaskResults(success=False, details={"msg": msg})

        logger.debug(
            f"Build on {build.target} in koji changed state "
            f"from {self.koji_task_event.old_state} to {self.koji_task_event.state}."
        )

        build.set_build_start_time(
            datetime.utcfromtimestamp(self.koji_task_event.start_time)
            if self.koji_task_event.start_time
            else None
        )

        build.set_build_finished_time(
            datetime.utcfromtimestamp(self.koji_task_event.completion_time)
            if self.koji_task_event.completion_time
            else None
        )

        url = get_koji_build_info_url(build.id)
        build_job_helper = KojiBuildJobHelper(
            service_config=self.service_config,
            package_config=self.package_config,
            project=self.project,
            metadata=self.data,
            db_trigger=self.db_trigger,
            job_config=self.job_config,
        )

        new_commit_status = {
            KojiTaskState.free: BaseCommitStatus.pending,
            KojiTaskState.open: BaseCommitStatus.running,
            KojiTaskState.closed: BaseCommitStatus.success,
            KojiTaskState.canceled: BaseCommitStatus.error,
            KojiTaskState.assigned: None,
            KojiTaskState.failed: BaseCommitStatus.failure,
        }.get(self.koji_task_event.state)

        description = {
            KojiTaskState.free: "RPM build has been submitted...",
            KojiTaskState.open: "RPM build is in progress...",
            KojiTaskState.closed: "RPM build succeeded.",
            KojiTaskState.canceled: "RPM build was canceled.",
            KojiTaskState.assigned: None,
            KojiTaskState.failed: "RPM build failed.",
        }.get(self.koji_task_event.state)

        if not (new_commit_status and description):
            logger.debug(
                f"We don't react to this koji build state change: {self.koji_task_event.state}"
            )
        else:
            build.set_status(new_commit_status.value)
            build_job_helper.report_status_to_all_for_chroot(
                description=description,
                state=new_commit_status,
                url=url,
                chroot=build.target,
            )

        koji_build_logs = KojiTaskEvent.get_koji_build_logs_url(
            rpm_build_task_id=int(build.build_id),
            koji_logs_url=self.service_config.koji_logs_url,
        )
        build.set_build_logs_url(koji_build_logs)
        koji_rpm_task_web_url = KojiTaskEvent.get_koji_rpm_build_web_url(
            rpm_build_task_id=int(build.build_id),
            koji_web_url=self.service_config.koji_web_url,
        )
        build.set_web_url(koji_rpm_task_web_url)

        msg = (
            f"Build on {build.target} in koji changed state "
            f"from {self.koji_task_event.old_state} to {self.koji_task_event.state}."
        )
        return TaskResults(success=True, details={"msg": msg})