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
Exemple #2
0
    def run(self) -> TaskResults:
        logger.debug(f"Testing farm {self.pipeline_id} result:\n{self.result}")

        test_run_model = TFTTestRunModel.get_by_pipeline_id(
            pipeline_id=self.pipeline_id)
        if not test_run_model:
            logger.warning(
                f"Unknown pipeline_id received from the testing-farm: "
                f"{self.pipeline_id}")

        if test_run_model:
            test_run_model.set_status(self.result, created=self.created)

        if self.result == TestingFarmResult.running:
            status = BaseCommitStatus.running
            summary = self.summary or "Tests are running ..."
        elif self.result == TestingFarmResult.passed:
            status = BaseCommitStatus.success
            summary = self.summary or "Tests passed ..."
        elif self.result == TestingFarmResult.error:
            status = BaseCommitStatus.error
            summary = self.summary or "Error ..."
        else:
            status = BaseCommitStatus.failure
            summary = self.summary or "Tests failed ..."

        if self.result == TestingFarmResult.running:
            self.pushgateway.test_runs_started.inc()
        else:
            self.pushgateway.test_runs_finished.inc()
            test_run_time = measure_time(end=datetime.now(timezone.utc),
                                         begin=test_run_model.submitted_time)
            self.pushgateway.test_run_finished_time.observe(test_run_time)

        if test_run_model:
            test_run_model.set_web_url(self.log_url)

        trigger = JobTriggerModel.get_or_create(
            type=self.db_trigger.job_trigger_model_type,
            trigger_id=self.db_trigger.id,
        )
        status_reporter = StatusReporter.get_instance(
            project=self.project,
            commit_sha=self.data.commit_sha,
            trigger_id=trigger.id if trigger else None,
            pr_id=self.data.pr_id,
        )
        status_reporter.report(
            state=status,
            description=summary,
            url=get_testing_farm_info_url(test_run_model.id)
            if test_run_model else self.log_url,
            links_to_external_services={"Testing Farm": self.log_url},
            check_names=TestingFarmJobHelper.get_test_check(self.copr_chroot),
        )

        return TaskResults(success=True, details={})
Exemple #3
0
 def status_reporter(self) -> StatusReporter:
     if not self._status_reporter:
         trigger = JobTriggerModel.get_or_create(
             type=self.db_trigger.job_trigger_model_type,
             trigger_id=self.db_trigger.id,
         )
         self._status_reporter = StatusReporter.get_instance(
             project=self.project,
             commit_sha=self.metadata.commit_sha,
             trigger_id=trigger.id if trigger else None,
             pr_id=self.metadata.pr_id,
         )
     return self._status_reporter
Exemple #4
0
def branch_trigger_model(branch_model):
    yield JobTriggerModel.get_or_create(
        type=JobTriggerModelType.branch_push, trigger_id=branch_model.id
    )
Exemple #5
0
def release_trigger_model(release_model):
    yield JobTriggerModel.get_or_create(
        type=JobTriggerModelType.release, trigger_id=release_model.id
    )
Exemple #6
0
def different_pr_trigger_model(different_pr_model):
    yield JobTriggerModel.get_or_create(
        type=JobTriggerModelType.pull_request, trigger_id=different_pr_model.id
    )
Exemple #7
0
def pr_trigger_model(pr_model):
    yield JobTriggerModel.get_or_create(
        type=JobTriggerModelType.pull_request, trigger_id=pr_model.id
    )