Beispiel #1
0
    def get(self, id):
        """A specific copr build details for one chroot."""
        build = CoprBuildModel.get_by_id(int(id))
        if not build:
            return response_maker(
                {"error": "No info about build stored in DB"},
                status=HTTPStatus.NOT_FOUND.value,
            )

        build_dict = {
            "build_id": build.build_id,
            "status": build.status,
            "chroot": build.target,
            "build_submitted_time":
            optional_timestamp(build.build_submitted_time),
            "build_start_time": optional_timestamp(build.build_start_time),
            "build_finished_time":
            optional_timestamp(build.build_finished_time),
            "commit_sha": build.commit_sha,
            "web_url": build.web_url,
            "build_logs_url": build.build_logs_url,
            "copr_project": build.project_name,
            "copr_owner": build.owner,
            "srpm_build_id": build.get_srpm_build().id,
            "run_ids": sorted(run.id for run in build.runs),
            "built_packages": build.built_packages,
        }

        build_dict.update(get_project_info_from_build(build))
        return response_maker(build_dict)
Beispiel #2
0
    def run(self) -> TaskResults:
        # TODO: once we turn handlers into respective celery tasks, we should iterate
        #       here over *all* matching jobs and do them all, not just the first one
        testing_farm_helper = TestingFarmJobHelper(
            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.data.event_type in (
                PullRequestCommentGithubEvent.__name__,
                MergeRequestCommentGitlabEvent.__name__,
                PullRequestCommentPagureEvent.__name__,
        ):
            logger.debug(f"Test job config: {testing_farm_helper.job_tests}")
            return testing_farm_helper.run_testing_farm_on_all()

        if self.build_id:
            copr_build_id = CoprBuildModel.get_by_id(self.build_id).build_id
        else:
            copr_build_id = testing_farm_helper.latest_copr_build.build_id
        logger.info(f"Running testing farm for {copr_build_id}:{self.chroot}.")
        return testing_farm_helper.run_testing_farm(
            build_id=int(copr_build_id), chroot=self.chroot)
def test_get_copr_build(clean_before_and_after, a_copr_build_for_pr):
    assert a_copr_build_for_pr.id
    b = CoprBuildModel.get_by_build_id(a_copr_build_for_pr.build_id, TARGET)
    assert b.id == a_copr_build_for_pr.id
    # let's make sure passing int works as well
    b = CoprBuildModel.get_by_build_id(int(a_copr_build_for_pr.build_id), TARGET)
    assert b.id == a_copr_build_for_pr.id
    b2 = CoprBuildModel.get_by_id(b.id)
    assert b2.id == a_copr_build_for_pr.id
Beispiel #4
0
 def db_trigger(self) -> Optional[AbstractTriggerDbType]:
     if not self._db_trigger:
         # copr build end
         if self.build_id:
             build = CoprBuildModel.get_by_id(self.build_id)
             self._db_trigger = build.job_trigger.get_trigger_object()
         # '/packit test' comment
         else:
             self._db_trigger = self.data.db_trigger
     return self._db_trigger
Beispiel #5
0
 def db_trigger(self) -> Optional[AbstractTriggerDbType]:
     if not self._db_trigger:
         # copr build end
         if self.build_id:
             build = CoprBuildModel.get_by_id(self.build_id)
             self._db_trigger = build.get_trigger_object()
         # other events
         else:
             self._db_trigger = self.data.db_trigger
     return self._db_trigger
Beispiel #6
0
    def run_with_copr_builds(self, targets: List[str], failed: Dict):
        targets_without_builds = []
        targets_with_builds = {}

        for target in targets:
            if self.build_id:
                copr_build = CoprBuildModel.get_by_id(self.build_id)
            else:
                copr_build = self.testing_farm_job_helper.get_latest_copr_build(
                    target=target, commit_sha=self.data.commit_sha)

            if copr_build:
                targets_with_builds[target] = copr_build
            else:
                targets_without_builds.append(target)

        # Trigger copr build for targets missing build
        if targets_without_builds:
            logger.info(
                f"Missing Copr build for targets {targets_without_builds} in "
                f"{self.testing_farm_job_helper.job_owner}/"
                f"{self.testing_farm_job_helper.job_project}"
                f" and commit:{self.data.commit_sha}, running a new Copr build."
            )

            for missing_target in targets_without_builds:
                self.testing_farm_job_helper.report_status_to_test_for_chroot(
                    state=BaseCommitStatus.pending,
                    description="Missing Copr build for this target, "
                    "running a new Copr build.",
                    url="",
                    chroot=missing_target,
                )

            event_data = self.data.get_dict()
            event_data["targets_override"] = targets_without_builds
            self.run_copr_build_handler(event_data,
                                        len(targets_without_builds))

        for target, copr_build in targets_with_builds.items():
            if copr_build.status != PG_COPR_BUILD_STATUS_SUCCESS:
                logger.info(
                    "The latest build was not successful, not running tests for it."
                )
                self.testing_farm_job_helper.report_status_to_test_for_chroot(
                    state=BaseCommitStatus.failure,
                    description="The latest build was not successful, "
                    "not running tests for it.",
                    chroot=target,
                    url=get_copr_build_info_url(copr_build.id),
                )
                continue

            logger.info(f"Running testing farm for {copr_build}:{target}.")
            self.run_for_target(target=target, build=copr_build, failed=failed)
Beispiel #7
0
def test_merged_runs(clean_before_and_after, few_runs):
    for i, run_id in enumerate(few_runs, 1):
        merged_run = RunModel.get_merged_run(run_id)
        srpm_build_id = merged_run.srpm_build_id

        # for different_pr (i=1) there are Copr builds twice, since the second
        # run of TFT from the same Copr build produces new row with same SRPM
        # and Copr IDs, but different Testing Farm IDs
        # ^ handled in API by iterating over set of IDs instead of list
        assert len(merged_run.copr_build_id) == 2 * i

        for copr_build in map(lambda ids: CoprBuildModel.get_by_id(ids[0]),
                              merged_run.copr_build_id):
            assert copr_build.get_srpm_build().id == srpm_build_id

        assert len(merged_run.test_run_id) == 2 * i
Beispiel #8
0
def test_get_copr_build(clean_before_and_after, a_copr_build_for_pr):
    assert a_copr_build_for_pr.id

    # pass in a build_id and a target
    b = CoprBuildModel.get_by_build_id(a_copr_build_for_pr.build_id,
                                       SampleValues.target)
    assert b.id == a_copr_build_for_pr.id
    # let's make sure passing int works as well
    b2 = CoprBuildModel.get_by_build_id(int(a_copr_build_for_pr.build_id),
                                        SampleValues.target)
    assert b2.id == a_copr_build_for_pr.id

    # pass in a build_id and without a target
    b3 = CoprBuildModel.get_by_build_id(a_copr_build_for_pr.build_id, None)
    assert b3.commit_sha == a_copr_build_for_pr.commit_sha

    b4 = CoprBuildModel.get_by_id(b.id)
    assert b4.id == a_copr_build_for_pr.id
 def db_trigger(self) -> Optional[AbstractTriggerDbType]:
     if not self._db_trigger:
         build = CoprBuildModel.get_by_id(self.build_id)
         self._db_trigger = build.job_trigger.get_trigger_object()
     return self._db_trigger
Beispiel #10
0
def copr_build_info(id_):
    log_service_versions()
    build = CoprBuildModel.get_by_id(id_)
    if build:
        return _get_build_info(build, build_description="Copr build")
    return f"We can't find any info about Copr build {id_}.\n", 404
Beispiel #11
0
def get_build_logs_by_id(id_):
    log_service_versions()
    build = CoprBuildModel.get_by_id(id_)
    if build:
        return _get_build_logs_for_build(build)
    return f"We can't find any info about COPR build {id_}.\n"