def check_copr_build(build_id: int) -> bool: """ Check the copr_build with given id and refresh the status if needed. Used in the babysit task. :param build_id: id of the copr_build (CoprBuildModel.build.id) :return: True if in case of successful run, False when we need to retry """ logger.debug(f"Getting copr build ID {build_id} from DB.") builds = CoprBuildModel.get_all_by_build_id(build_id) if not builds: logger.warning(f"Copr build {build_id} not in DB.") return True copr_client = CoprClient.create_from_config_file() build_copr = copr_client.build_proxy.get(build_id) if not build_copr.ended_on: logger.info("The copr build is still in progress.") return False logger.info(f"The status is {build_copr.state!r}.") for build in builds: if build.status != "pending": logger.info(f"DB state says {build.status!r}, " "things were taken care of already, skipping.") continue chroot_build = copr_client.build_chroot_proxy.get( build_id, build.target) event = CoprBuildEvent( topic=FedmsgTopic.copr_build_finished.value, build_id=build_id, build=build, chroot=build.target, status=(COPR_API_SUCC_STATE if chroot_build.state == COPR_SUCC_STATE else COPR_API_FAIL_STATE), owner=build.owner, project_name=build.project_name, pkg=build_copr.source_package.get( "name", ""), # this seems to be the SRPM name timestamp=chroot_build.ended_on, ) job_configs = get_config_for_handler_kls( handler_kls=CoprBuildEndHandler, event=event, package_config=event.get_package_config(), ) for job_config in job_configs: CoprBuildEndHandler( package_config=event.package_config, job_config=job_config, data=EventData.from_event_dict(event.get_dict()), copr_event=event, ).run() return True
def run_copr_build_end_handler(event: dict, package_config: dict, job_config: dict): handler = CoprBuildEndHandler( package_config=load_package_config(package_config), job_config=load_job_config(job_config), data=EventData.from_event_dict(event), copr_event=CoprBuildEvent.from_event_dict(event), ) return get_handlers_task_results(handler.run_job(), event)
def babysit_copr_build(self, build_id: int): """ check status of a copr build and update it in DB """ logger.debug(f"getting copr build ID {build_id} from DB") builds = CoprBuild.get_all_by_build_id(build_id) if builds: copr_client = CoprClient.create_from_config_file() build_copr = copr_client.build_proxy.get(build_id) if not build_copr.ended_on: logger.info("The copr build is still in progress") self.retry() logger.info(f"The status is {build_copr.state}") # copr doesn't tell status of how a build in the chroot went: # https://bugzilla.redhat.com/show_bug.cgi?id=1813227 for build in builds: if build.status != "pending": logger.info( f"DB state says {build.status}, " "things were taken care of already, skipping." ) continue event = CoprBuildEvent( topic=FedmsgTopic.copr_build_finished.value, build_id=build_id, build={}, chroot=build.target, status=( COPR_API_SUCC_STATE if build_copr.state == COPR_SUCC_STATE else COPR_API_FAIL_STATE ), owner=build.owner, project_name=build.project_name, pkg=build_copr.source_package.get( "name", "" ), # this seems to be the SRPM name build_pg=build, ) CoprBuildEndHandler( ServiceConfig.get_service_config(), job_config=None, event=event ).run() else: logger.warning(f"Copr build {build_id} not in DB.")
def parse_copr_event(event) -> Optional[CoprBuildEvent]: """ this corresponds to copr build event e.g:""" topic = event.get("topic") if topic not in { "org.fedoraproject.prod.copr.build.start", "org.fedoraproject.prod.copr.build.end", }: return None logger.info(f"Copr event; {event.get('what')}") build_id = event.get("build") chroot = event.get("chroot") status = event.get("status") owner = event.get("owner") project_name = event.get("copr") pkg = event.get("pkg") return CoprBuildEvent.from_build_id(topic, build_id, chroot, status, owner, project_name, pkg)