def _create_srpm(self): # we want to get packit logs from the SRPM creation process # so we stuff them into a StringIO buffer stream = StringIO() handler = logging.StreamHandler(stream) packit_logger = logging.getLogger("packit") packit_logger.setLevel(logging.DEBUG) packit_logger.addHandler(handler) formatter = PackitFormatter(None, "%H:%M:%S") handler.setFormatter(formatter) srpm_success = True exception: Optional[Exception] = None extra_logs: str = "" try: self._srpm_path = Path( self.api.create_srpm(srpm_dir=self.api.up.local_project.working_dir) ) except SandcastleTimeoutReached as ex: exception = ex extra_logs = f"\nYou have reached 10-minute timeout while creating SRPM.\n" except ApiException as ex: exception = ex # this is an internal error: let's not expose anything to public extra_logs = ( "\nThere was a problem in the environment the packit-service is running in.\n" "Please hang tight, the help is coming." ) except Exception as ex: exception = ex # collect the logs now packit_logger.removeHandler(handler) stream.seek(0) srpm_logs = stream.read() if exception: logger.info(f"exception while running SRPM build: {exception}") logger.debug(f"{exception!r}") srpm_success = False # when do we NOT want to send stuff to sentry? sentry_integration.send_to_sentry(exception) # this needs to be done AFTER we gather logs # so that extra logs are after actual logs srpm_logs += extra_logs if hasattr(exception, "output"): output = getattr(exception, "output", "") # mypy srpm_logs += f"\nOutput of the command in the sandbox:\n{output}\n" srpm_logs += ( f"\nMessage: {exception}\nException: {exception!r}\n{self.msg_retrigger}" "\nPlease join the freenode IRC channel #packit for the latest info.\n" ) self._srpm_model = SRPMBuildModel.create(logs=srpm_logs, success=srpm_success)
def _run_copr_build_and_save_output(self): # we want to get packit logs from the SRPM creation process # so we stuff them into a StringIO buffer stream = StringIO() handler = logging.StreamHandler(stream) packit_logger = logging.getLogger("packit") packit_logger.setLevel(logging.DEBUG) packit_logger.addHandler(handler) formatter = PackitFormatter(None, "%H:%M:%S") handler.setFormatter(formatter) build_id, _ = self.api.run_copr_build( project=self.job_project, chroots=self.build_chroots, owner=self.job_owner, ) packit_logger.removeHandler(handler) stream.seek(0) logs = stream.read() return build_id, logs
def _create_srpm(self): """ Create SRPM. Returns: Task results if job is done because of merge conflicts, `None` otherwise. """ # we want to get packit logs from the SRPM creation process # so we stuff them into a StringIO buffer stream = StringIO() handler = logging.StreamHandler(stream) packit_logger = logging.getLogger("packit") packit_logger.setLevel(logging.DEBUG) packit_logger.addHandler(handler) formatter = PackitFormatter() handler.setFormatter(formatter) srpm_success = True exception: Optional[Exception] = None extra_logs: str = "" results: Optional[TaskResults] = None try: self._srpm_path = Path( self.api.create_srpm( srpm_dir=self.api.up.local_project.working_dir)) except SandcastleTimeoutReached as ex: exception = ex extra_logs = "\nYou have reached 10-minute timeout while creating SRPM.\n" except ApiException as ex: exception = ex # this is an internal error: let's not expose anything to public extra_logs = ( "\nThere was a problem in the environment the packit-service is running in.\n" "Please hang tight, the help is coming.") except PackitMergeException as ex: exception = ex results = TaskResults( success=True, details={ "msg": "Merge conflicts were detected, cannot build SRPM.", "exception": str(ex), }, ) except Exception as ex: exception = ex # collect the logs now packit_logger.removeHandler(handler) stream.seek(0) srpm_logs = stream.read() if exception: logger.info(f"exception while running SRPM build: {exception}") logger.debug(f"{exception!r}") srpm_success = False # when do we NOT want to send stuff to sentry? if not isinstance(exception, PackitMergeException): sentry_integration.send_to_sentry(exception) # this needs to be done AFTER we gather logs # so that extra logs are after actual logs srpm_logs += extra_logs if hasattr(exception, "output"): output = getattr(exception, "output", "") # mypy srpm_logs += f"\nOutput of the command in the sandbox:\n{output}\n" srpm_logs += ( f"\nMessage: {exception}\nException: {exception!r}\n{self.msg_retrigger}" "\nPlease join #packit on irc.libera.chat if you need help with the error above.\n" ) self._srpm_model, self.run_model = SRPMBuildModel.create_with_new_run( logs=srpm_logs, success=srpm_success, trigger_model=self.db_trigger, ) return results
def _run_copr_build_and_save_output(self) -> BuildMetadata: # we want to get packit logs from the SRPM creation process # so we stuff them into a StringIO buffer stream = StringIO() handler = logging.StreamHandler(stream) packit_logger = logging.getLogger("packit") packit_logger.setLevel(logging.DEBUG) packit_logger.addHandler(handler) formatter = PackitFormatter(None, "%H:%M:%S") handler.setFormatter(formatter) c = BuildMetadata() c.srpm_failed = False ex: Optional[Exception] = None # shut up pycharm extra_logs: str = "" try: c.copr_build_id, c.copr_web_url = self.api.run_copr_build( project=self.job_project, chroots=self.build_chroots, owner=self.job_owner, ) except SandcastleTimeoutReached as e: ex = e extra_logs = f"\nYou have reached 10-minute timeout while creating SRPM.\n" except ApiException as e: ex = e # this is an internal error: let's not expose anything to public extra_logs = ( "\nThere was a problem in the environment the packit-service is running in.\n" "Please hang tight, the help is coming.") except Exception as e: ex = e # shut up mypy # collect the logs now packit_logger.removeHandler(handler) stream.seek(0) c.srpm_logs = stream.read() if ex: logger.info(f"exception while running a copr build: {ex}") logger.debug(f"{ex!r}") c.srpm_failed = True # when do we NOT want to send stuff to sentry? sentry_integration.send_to_sentry(ex) # this needs to be done AFTER we gather logs # so that extra logs are after actual logs c.srpm_logs += extra_logs if hasattr(ex, "output"): output = getattr(ex, "output", "") # mypy c.srpm_logs += f"\nOutput of the command in the sandbox:\n{output}\n" c.srpm_logs += ( f"\nMessage: {ex}\nException: {ex!r}\n{self.msg_retrigger}" "\nPlease join the freenode IRC channel #packit for the latest info.\n" ) return c
def run_copr_build(self) -> HandlerResults: if not (self.job_copr_build or self.job_tests): msg = "No copr_build or tests job defined." # we can't report it to end-user at this stage return HandlerResults(success=False, details={"msg": msg}) try: self.report_status_to_all(description="Building SRPM ...", state="pending") # we want to get packit logs from the SRPM creation process # so we stuff them into a StringIO buffer stream = StringIO() handler = logging.StreamHandler(stream) packit_logger = logging.getLogger("packit") packit_logger.setLevel(logging.DEBUG) packit_logger.addHandler(handler) formatter = PackitFormatter(None, "%H:%M:%S") handler.setFormatter(formatter) build_id, _ = self.api.run_copr_build( project=self.job_project, chroots=self.build_chroots, owner=self.job_owner, ) packit_logger.removeHandler(handler) stream.seek(0) logs = stream.read() web_url = get_copr_build_url_for_values(self.job_owner, self.job_project, build_id) srpm_build = SRPMBuild.create(logs) status = "pending" description = "Building RPM ..." for chroot in self.build_chroots: copr_build = CoprBuild.get_or_create( pr_id=self.event.pr_id, build_id=str(build_id), commit_sha=self.event.commit_sha, repo_name=self.event.base_repo_name, namespace=self.event.base_repo_namespace, web_url=web_url, target=chroot, status=status, srpm_build=srpm_build, ) url = get_log_url(id_=copr_build.id) self.status_reporter.report( state=status, description=description, url=url, check_names=PRCheckName.get_build_check(chroot), ) if chroot in self.tests_chroots: self.status_reporter.report( state=status, description=description, url=url, check_names=PRCheckName.get_testing_farm_check(chroot), ) except SandcastleTimeoutReached: return self._process_timeout() except SandcastleCommandFailed as ex: return self._process_failed_command(ex) except ApiException as ex: return self._process_openshift_error(ex) except PackitSRPMException as ex: return self._process_failed_srpm_build(ex) except PackitCoprProjectException as ex: return self._process_copr_submit_exception(ex) except PackitCoprException as ex: return self._process_general_exception(ex) except Exception as ex: return self._process_general_exception(ex) self.copr_build_model.build_id = build_id self.copr_build_model.save() return HandlerResults(success=True, details={})