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={})
def monitor_not_submitted_copr_builds(self, number_of_builds: int, reason: str): """ Measure the time it took to set the failed status in case of event (e.g. failed SRPM) that prevents Copr build to be submitted. """ time = measure_time(end=datetime.now(timezone.utc), begin=self.metadata.task_accepted_time) for _ in range(number_of_builds): self.pushgateway.copr_build_not_submitted_time.labels( reason=reason).observe(time)
def run(self): if not self.build: # TODO: how could this happen? model = ("SRPMBuildDB" if self.copr_event.chroot == COPR_SRPM_CHROOT else "CoprBuildDB") msg = f"Copr build {self.copr_event.build_id} not in {model}." logger.warning(msg) return TaskResults(success=False, details={"msg": msg}) if self.build.status in [ PG_BUILD_STATUS_FAILURE, PG_BUILD_STATUS_SUCCESS, ]: msg = (f"Copr build {self.copr_event.build_id} is already" f" processed (status={self.copr_event.build.status}).") logger.info(msg) return TaskResults(success=True, details={"msg": msg}) self.set_end_time() self.set_srpm_url() if self.copr_event.chroot == COPR_SRPM_CHROOT: return self.handle_srpm_end() self.pushgateway.copr_builds_finished.inc() # if the build is needed only for test, it doesn't have the task_accepted_time if self.build.task_accepted_time: copr_build_time = measure_time(end=datetime.now(timezone.utc), begin=self.build.task_accepted_time) self.pushgateway.copr_build_finished_time.observe(copr_build_time) # https://pagure.io/copr/copr/blob/master/f/common/copr_common/enums.py#_42 if self.copr_event.status != COPR_API_SUCC_STATE: failed_msg = "RPMs failed to be built." self.copr_build_helper.report_status_to_all_for_chroot( state=BaseCommitStatus.failure, description=failed_msg, url=get_copr_build_info_url(self.build.id), chroot=self.copr_event.chroot, ) self.build.set_status(PG_BUILD_STATUS_FAILURE) return TaskResults(success=False, details={"msg": failed_msg}) self.report_successful_build() self.build.set_status(PG_BUILD_STATUS_SUCCESS) built_packages = self.copr_build_helper.get_built_packages( int(self.build.build_id), self.build.target) self.build.set_built_packages(built_packages) self.handle_testing_farm() return TaskResults(success=True, details={})
def push_initial_metrics(event: Event, handler: JobHandler, build_targets_len: int): pushgateway = Pushgateway() task_accepted_time = datetime.now(timezone.utc) response_time = measure_time(end=task_accepted_time, begin=event.created_at) pushgateway.initial_status_time.observe(response_time) if response_time > 15: pushgateway.no_status_after_15_s.inc() # set the time when the accepted status was set so that we can use it later for measurements event.task_accepted_time = task_accepted_time if isinstance(handler, CoprBuildHandler): for _ in range(build_targets_len): pushgateway.copr_builds_queued.inc() pushgateway.push()
def run(self): build_job_helper = CoprBuildJobHelper( 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, pushgateway=self.pushgateway, ) if self.copr_event.chroot == "srpm-builds": # we don't want to set check for this msg = "SRPM build in copr has finished." logger.debug(msg) return TaskResults(success=True, details={"msg": msg}) if not self.build: # TODO: how could this happen? msg = f"Copr build {self.copr_event.build_id} not in CoprBuildDB." logger.warning(msg) return TaskResults(success=False, details={"msg": msg}) if self.build.status in [ PG_COPR_BUILD_STATUS_FAILURE, PG_COPR_BUILD_STATUS_SUCCESS, ]: msg = (f"Copr build {self.copr_event.build_id} is already" f" processed (status={self.copr_event.build.status}).") logger.info(msg) return TaskResults(success=True, details={"msg": msg}) self.pushgateway.copr_builds_finished.inc() # if the build is needed only for test, it doesn't have the task_accepted_time if self.build.task_accepted_time: copr_build_time = measure_time(end=datetime.now(timezone.utc), begin=self.build.task_accepted_time) self.pushgateway.copr_build_finished_time.observe(copr_build_time) end_time = (datetime.utcfromtimestamp(self.copr_event.timestamp) if self.copr_event.timestamp else None) self.build.set_end_time(end_time) self.set_srpm_url(build_job_helper) url = get_copr_build_info_url(self.build.id) # https://pagure.io/copr/copr/blob/master/f/common/copr_common/enums.py#_42 if self.copr_event.status != COPR_API_SUCC_STATE: failed_msg = "RPMs failed to be built." build_job_helper.report_status_to_all_for_chroot( state=BaseCommitStatus.failure, description=failed_msg, url=url, chroot=self.copr_event.chroot, ) self.build.set_status(PG_COPR_BUILD_STATUS_FAILURE) return TaskResults(success=False, details={"msg": failed_msg}) if (build_job_helper.job_build and build_job_helper.job_build.trigger == JobConfigTriggerType.pull_request and self.copr_event.pr_id and isinstance(self.project, (GithubProject, GitlabProject)) and not self.was_last_packit_comment_with_congratulation() and self.job_config.notifications.pull_request.successful_build): msg = ( f"Congratulations! One of the builds has completed. :champagne:\n\n" "You can install the built RPMs by following these steps:\n\n" "* `sudo yum install -y dnf-plugins-core` on RHEL 8\n" "* `sudo dnf install -y dnf-plugins-core` on Fedora\n" f"* `dnf copr enable {self.copr_event.owner}/{self.copr_event.project_name}`\n" "* And now you can install the packages.\n" "\nPlease note that the RPMs should be used only in a testing environment." ) self.project.get_pr(self.copr_event.pr_id).comment(msg) build_job_helper.report_status_to_build_for_chroot( state=BaseCommitStatus.success, description="RPMs were built successfully.", url=url, chroot=self.copr_event.chroot, ) build_job_helper.report_status_to_test_for_chroot( state=BaseCommitStatus.pending, description="RPMs were built successfully.", url=url, chroot=self.copr_event.chroot, ) self.build.set_status(PG_COPR_BUILD_STATUS_SUCCESS) built_packages = build_job_helper.get_built_packages( int(self.build.build_id), self.build.target) self.build.set_built_packages(built_packages) if (build_job_helper.job_tests and self.copr_event.chroot in build_job_helper.tests_targets): signature( TaskName.testing_farm.value, kwargs={ "package_config": dump_package_config(self.package_config), "job_config": dump_job_config(build_job_helper.job_tests), "event": self.data.get_dict(), "chroot": self.copr_event.chroot, "build_id": self.build.id, }, ).apply_async() else: logger.debug("Testing farm not in the job config.") return TaskResults(success=True, details={})