def copr_build(): proj = GitProject(id=1, repo_name="bar", namespace="foo") pr = PullRequest(id=1, pr_id=123) pr.project = proj c = CoprBuild(id=1) c.pr = pr return c
def copr_build(): proj = GitProject(id=1, repo_name="bar", namespace="foo") pr = PullRequest(id=1, pr_id=123) pr.project = proj c = CoprBuild(id=1) c.pr = pr c.commit_sha = "0011223344" return c
def test_get_copr_build(a_copr_build): assert a_copr_build.id b = CoprBuild.get_by_build_id(a_copr_build.build_id, TARGET) assert b.id == a_copr_build.id # let's make sure passing int works as well b = CoprBuild.get_by_build_id(int(a_copr_build.build_id), TARGET) assert b.id == a_copr_build.id b2 = CoprBuild.get_by_id(b.id) assert b2.id == a_copr_build.id
def test_get_by_build_id(multiple_copr_builds): # these are not iterable and thus should be accessible directly build_a = CoprBuild.get_by_build_id(str(123456), "fedora-42-x86_64") assert build_a.project_name == "SomeUser-hello-world-9" assert build_a.target == "fedora-42-x86_64" build_b = CoprBuild.get_by_build_id(str(123456), "fedora-43-x86_64") assert build_b.project_name == "SomeUser-hello-world-9" assert build_b.target == "fedora-43-x86_64" build_c = CoprBuild.get_by_build_id(str(987654), "fedora-43-x86_64") assert build_c.project_name == "SomeUser-random-text-7"
def get(self): """ List all Copr builds. """ # Return relevant info thats concise # Usecases like the packit-dashboard copr-builds table builds_list = CoprBuild.get_all() result = [] checklist = [] for build in builds_list: if int(build.build_id) not in checklist: build_dict = { "project": build.project_name, "owner": build.owner, "repo_name": build.pr.project.repo_name, "build_id": build.build_id, "status": build.status, "chroots": [], "build_submitted_time": optional_time(build.build_submitted_time), "repo_namespace": build.pr.project.namespace, "web_url": build.web_url, } # same_buildid_builds are copr builds created due to the same trigger # multiple identical builds are created which differ only in target # so we merge them into one same_buildid_builds = CoprBuild.get_all_by_build_id( str(build.build_id)) for sbid_build in same_buildid_builds: build_dict["chroots"].append(sbid_build.target) checklist.append(int(build.build_id)) result.append(build_dict) first, last = indices() resp = make_response(dumps(result[first:last]), HTTPStatus.PARTIAL_CONTENT) resp.headers[ "Content-Range"] = f"copr-builds {first + 1}-{last}/{len(result)}" resp.headers["Content-Type"] = "application/json" return resp
def multiple_copr_builds(): with get_sa_session() as session: session.query(CoprBuild).delete() srpm_build = SRPMBuild.create("asd\nqwe\n") yield [ CoprBuild.get_or_create( pr_id=1, build_id="123456", commit_sha="687abc76d67d", repo_name="lithium", namespace="nirvana", project_name="SomeUser-hello-world-9", owner="packit", web_url="https://copr.something.somewhere/123456", target="fedora-42-x86_64", status="pending", srpm_build=srpm_build, ), # Same build_id but different chroot CoprBuild.get_or_create( pr_id=1, build_id="123456", commit_sha="687abc76d67d", repo_name="lithium", namespace="nirvana", project_name="SomeUser-hello-world-9", owner="packit", web_url="https://copr.something.somewhere/123456", target="fedora-43-x86_64", status="pending", srpm_build=srpm_build, ), # Completely different build CoprBuild.get_or_create( pr_id=4, build_id="987654", commit_sha="987def76d67e", repo_name="cockpit-project", namespace="cockpit", project_name="SomeUser-random-text-7", owner="cockpit-project", web_url="https://copr.something.somewhere/987654", target="fedora-43-x86_64", status="pending", srpm_build=srpm_build, ), ] clean_db()
def test_copr_build_for_release(release_event): # status is set for each build-target (4x): # - Building SRPM ... # - Building RPM ... branch_build_job = JobConfig( type=JobType.build, trigger=JobConfigTriggerType.release, metadata={ "branch": "build-branch", "owner": "nobody", "targets": [ "fedora-29-x86_64", "fedora-30-x86_64", "fedora-31-x86_64", "fedora-rawhide-x86_64", ], }, ) helper = build_helper(jobs=[branch_build_job], event=release_event) flexmock(GitProject).should_receive("set_commit_status").and_return().times(8) flexmock(RedisCoprBuild).should_receive("create").and_return(FakeCoprBuildModel()) flexmock(SRPMBuild).should_receive("create").and_return(SRPMBuild()) flexmock(CoprBuild).should_receive("get_or_create").and_return(CoprBuild(id=1)) flexmock(PackitAPI).should_receive("run_copr_build").and_return(1, None).once() assert helper.run_copr_build()["success"]
def test_copr_build_fails_in_packit(pull_request_event): # status is set for each build-target (4x): # - Building SRPM ... # - Build failed, check latest comment for details. helper = build_helper(event=pull_request_event) templ = "packit-stg/rpm-build-fedora-{ver}-x86_64" for v in ["29", "30", "31", "rawhide"]: flexmock(GitProject).should_receive("set_commit_status").with_args( "528b803be6f93e19ca4130bf4976f2800a3004c4", CommitStatus.pending, "", "Building SRPM ...", templ.format(ver=v), trim=True, ).and_return().once() for v in ["29", "30", "31", "rawhide"]: flexmock(GitProject).should_receive("set_commit_status").with_args( "528b803be6f93e19ca4130bf4976f2800a3004c4", CommitStatus.failure, "https://localhost:5000/srpm-build/2/logs", "SRPM build failed, check the logs for details.", templ.format(ver=v), trim=True, ).and_return().once() flexmock(RedisCoprBuild).should_receive("create").and_return(FakeCoprBuildModel()) flexmock(SRPMBuild).should_receive("create").and_return(SRPMBuild(id=2)) flexmock(CoprBuild).should_receive("get_or_create").and_return(CoprBuild(id=1)) flexmock(sentry_integration).should_receive("send_to_sentry").and_return().once() flexmock(PackitAPI).should_receive("run_copr_build").and_raise( FailedCreateSRPM, "some error" ) assert not helper.run_copr_build()["success"]
def from_build_id( cls, topic: str, build_id: int, chroot: str, status: int, owner: str, project_name: str, pkg: str, ) -> Optional["CoprBuildEvent"]: """ Return cls instance or None if build_id not in CoprBuildDB""" # pg build_pg = CoprBuild.get_by_build_id(str(build_id), chroot) build = None if not build_pg: # let's try redis now build = CoprBuildDB().get_build(build_id) if not build: logger.warning(f"Build id: {build_id} not in CoprBuildDB") return None return cls( topic, build_id, build, chroot, status, owner, project_name, pkg, build_pg=build_pg, )
def test_copr_build_check_names(): metadata = {"owner": "nobody", "targets": ["bright-future-x86_64"]} handler = build_handler(metadata) flexmock(BuildStatusReporter).should_receive("set_status").with_args( state="pending", description="Building SRPM ...", check_name="packit-stg/rpm-build-bright-future-x86_64", url="", ).and_return() flexmock(BuildStatusReporter).should_receive("set_status").with_args( state="pending", description="Building RPM ...", check_name="packit-stg/rpm-build-bright-future-x86_64", url="https://localhost:5000/copr-build/1/logs", ).and_return() flexmock(GitProject).should_receive( "set_commit_status").and_return().never() flexmock(RedisCoprBuild).should_receive("create").and_return( FakeCoprBuildModel()) flexmock(SRPMBuild).should_receive("create").and_return(SRPMBuild()) flexmock(CoprBuild).should_receive("get_or_create").and_return( CoprBuild(id=1)) flexmock(PackitAPI).should_receive("run_copr_build").and_return(1, None) assert handler.run_copr_build()["success"]
def run_copr_build(self) -> HandlerResults: if not (self.job_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}) self.report_status_to_all(description="Building SRPM ...", state=CommitStatus.pending) build_metadata = self._run_copr_build_and_save_output() srpm_build_model = SRPMBuild.create(build_metadata.srpm_logs) if build_metadata.srpm_failed: msg = "SRPM build failed, check the logs for details." self.report_status_to_all( state=CommitStatus.failure, description=msg, url=get_srpm_log_url(srpm_build_model.id), ) return HandlerResults(success=False, details={"msg": msg}) for chroot in self.build_chroots: copr_build = CoprBuild.get_or_create( pr_id=self.pr_id, build_id=str(build_metadata.copr_build_id), commit_sha=self.event.commit_sha, repo_name=self.project.repo, namespace=self.project.namespace, project_name=self.job_project, owner=self.job_owner, web_url=build_metadata.copr_web_url, target=chroot, status="pending", srpm_build=srpm_build_model, ) url = get_log_url(id_=copr_build.id) self.report_status_to_all_for_chroot( state=CommitStatus.pending, description="Building RPM ...", url=url, chroot=chroot, ) self.copr_build_model.build_id = build_metadata.copr_build_id self.copr_build_model.save() # release the hounds! celery_app.send_task( "task.babysit_copr_build", args=(build_metadata.copr_build_id, ), countdown=120, # do the first check in 120s ) return HandlerResults(success=True, details={})
def test_get_logs(client): chroot = "foo-1-x86_64" state = "pending" build_id = 2 project = GitProject() project.namespace = "john-foo" project.repo_name = "bar" pr = PullRequest() pr.pr_id = 234 pr.project = project srpm_build = SRPMBuild() srpm_build.logs = "asd<br>qwe" c = CoprBuild() c.target = chroot c.build_id = str(build_id) c.srpm_build = srpm_build c.status = state c.web_url = ( "https://copr.fedorainfracloud.org/coprs/john-foo-bar/john-foo-bar/build/2/" ) c.build_logs_url = "https://localhost:5000/build/2/foo-1-x86_64/logs" c.pr = pr flexmock(CoprBuild).should_receive("get_by_id").and_return(c) url = f"/copr-build/1/logs" logs_url = get_log_url(1) assert logs_url.endswith(url) resp = client.get(url) expected = ( "<html><head>" f"<title>Build {c.pr.project.namespace}/{c.pr.project.repo_name}" f" #{c.pr.pr_id}</title></head><body>" f"COPR Build ID: {c.build_id}<br>" f"State: {c.status}<br><br>" f'Build web interface URL: <a href="{c.web_url}">{c.web_url}</a><br>' f'Build logs: <a href="{c.build_logs_url}">{c.build_logs_url}</a><br>' "SRPM creation logs:<br><br>" f"<pre>{c.srpm_build.logs}</pre>" "<br></body></html>" ) assert resp.data == expected.encode()
def test_copr_build_no_targets(pull_request_event): # status is set for each build-target (fedora-stable => 2x): # - Building SRPM ... # - Building RPM ... helper = build_helper(event=pull_request_event, metadata={"owner": "nobody"}) flexmock(GitProject).should_receive("set_commit_status").and_return().times(4) flexmock(RedisCoprBuild).should_receive("create").and_return(FakeCoprBuildModel()) flexmock(SRPMBuild).should_receive("create").and_return(SRPMBuild()) flexmock(CoprBuild).should_receive("get_or_create").and_return(CoprBuild(id=1)) flexmock(PackitAPI).should_receive("run_copr_build").and_return(1, None).once() assert helper.run_copr_build()["success"]
def get(self, id): """A specific copr build details. From copr_build hash, filled by worker.""" builds_list = CoprBuild.get_all_by_build_id(str(id)) if bool(builds_list.first()): build = builds_list[0] build_dict = { "project": build.project_name, "owner": build.owner, "repo_name": build.pr.project.repo_name, "build_id": build.build_id, "status": build.status, "chroots": [], "build_submitted_time": optional_time(build.build_submitted_time), "build_start_time": build.build_start_time, "build_finished_time": build.build_finished_time, "pr_id": build.pr.pr_id, "commit_sha": build.commit_sha, "repo_namespace": build.pr.project.namespace, "web_url": build.web_url, "srpm_logs": build.srpm_build.logs, "git_repo": f"https://github.com/{build.pr.project.namespace}" "{build.pr.project.repo_name}", # For backwards compatability with the redis API "ref": build.commit_sha, "https_url": f"https://github.com/{build.pr.project.namespace}/" "{build.pr.project.repo_name}.git", } # merge chroots into one for sbid_build in builds_list: build_dict["chroots"].append(sbid_build.target) build = make_response(dumps(build_dict)) build.headers["Content-Type"] = "application/json" return build if build else ("", HTTPStatus.NO_CONTENT) else: return ("", HTTPStatus.NO_CONTENT)
def test_copr_build_success(): # status is set for each build-target (4x): # - Building SRPM ... # - Building RPM ... handler = build_handler() flexmock(GitProject).should_receive( "set_commit_status").and_return().times(8) flexmock(RedisCoprBuild).should_receive("create").and_return( FakeCoprBuildModel()) flexmock(SRPMBuild).should_receive("create").and_return(SRPMBuild()) flexmock(CoprBuild).should_receive("get_or_create").and_return( CoprBuild(id=1)) flexmock(PackitAPI).should_receive("run_copr_build").and_return( 1, None).once() assert handler.run_copr_build()["success"]
def a_copr_build(): with get_sa_session() as session: session.query(CoprBuild).delete() srpm_build = SRPMBuild.create("asd\nqwe\n") yield CoprBuild.get_or_create( pr_id=1, build_id="123456", commit_sha="687abc76d67d", repo_name="lithium", namespace="nirvana", web_url="https://copr.something.somewhere/123456", target=TARGET, status="pending", srpm_build=srpm_build, ) clean_db()
def test_copr_build_success_set_test_check(pull_request_event): # status is set for each build-target (4x): # - Building SRPM ... # - Building RPM ... # status is set for each test-target (4x): # - Building SRPM ... # - Building RPM ... test_job = JobConfig( type=JobType.tests, trigger=JobConfigTriggerType.pull_request, metadata={} ) helper = build_helper(jobs=[test_job], event=pull_request_event) flexmock(GitProject).should_receive("set_commit_status").and_return().times(16) flexmock(RedisCoprBuild).should_receive("create").and_return(FakeCoprBuildModel()) flexmock(SRPMBuild).should_receive("create").and_return(SRPMBuild()) flexmock(CoprBuild).should_receive("get_or_create").and_return(CoprBuild(id=1)) flexmock(PackitAPI).should_receive("run_copr_build").and_return(1, None).once() assert helper.run_copr_build()["success"]
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 packit_build_752(): with get_sa_session() as session: session.query(CoprBuild).delete() srpm_build = SRPMBuild.create("asd\nqwe\n") yield CoprBuild.get_or_create( pr_id=752, build_id=str(BUILD_ID), commit_sha="687abc76d67d", repo_name="packit", namespace="packit-service", project_name="packit-service-packit-752", owner="packit", web_url=("https://download.copr.fedorainfracloud.org/" "results/packit/packit-service-packit-752"), target="fedora-rawhide-x86_64", status="pending", srpm_build=srpm_build, ) clean_db()
def get_build_logs_by_id(id_): build = CoprBuild.get_by_id(id_) if build: response = ( "<html><head>" f"<title>Build {build.pr.project.namespace}/{build.pr.project.repo_name}" f" #{build.pr.pr_id}</title></head><body>" f"COPR Build ID: {build.build_id}<br>" f"State: {build.status}<br><br>" f'Build web interface URL: <a href="{build.web_url}">{build.web_url}</a><br>' ) if build.build_logs_url: response += (f'Build logs: <a href="{build.build_logs_url}">' f"{build.build_logs_url}</a><br>") response += ("SRPM creation logs:<br><br>" f"<pre>{build.srpm_build.logs}</pre>" "<br></body></html>") return response return f"We can't find any info about COPR build {id_}.\n"
def test_copr_build_fails_in_packit(): # status is set for each build-target (4x): # - Building SRPM ... # - Build failed, check latest comment for details. handler = build_handler() flexmock(GitProject, pr_comment=lambda *args, **kw: None) flexmock(GitProject).should_receive( "set_commit_status").and_return().times(8) flexmock(GitProject).should_receive("pr_comment").and_return().once() flexmock(RedisCoprBuild).should_receive("create").and_return( FakeCoprBuildModel()) flexmock(SRPMBuild).should_receive("create").and_return(SRPMBuild()) flexmock(CoprBuild).should_receive("get_or_create").and_return( CoprBuild(id=1)) flexmock(sentry_integration).should_receive( "send_to_sentry").and_return().once() flexmock(PackitAPI).should_receive("run_copr_build").and_raise( FailedCreateSRPM, "some error") assert not handler.run_copr_build()["success"]
def run(self): if self.event.chroot == "srpm-builds": # we don't want to set the check status for this msg = "SRPM build in copr has started" logger.debug(msg) return HandlerResults(success=True, details={"msg": msg}) # TODO: drop the code below once we move to PG completely; the build is present in event # pg build_pg = CoprBuild.get_by_build_id( str(self.event.build_id), self.event.chroot ) if not build_pg: logger.info( f"build {self.event.build_id} is not in pg, falling back to redis" ) # redis - old school build = CoprBuildDB().get_build(self.event.build_id) if not build: # TODO: how could this happen? msg = f"Copr build {self.event.build_id} not in CoprBuildDB" logger.warning(msg) return HandlerResults(success=False, details={"msg": msg}) if build_pg: url = get_log_url(build_pg.id) build_pg.set_status("pending") copr_build_logs = get_copr_build_logs_url(self.event) build_pg.set_build_logs_url(copr_build_logs) else: url = copr_url_from_event(self.event) self.build_job_helper.report_status_to_all_for_chroot( description="RPM build has started...", state=CommitStatus.pending, url=url, chroot=self.event.chroot, ) msg = f"Build on {self.event.chroot} in copr has started..." return HandlerResults(success=True, details={"msg": msg})
def run(self): if self.event.chroot == "srpm-builds": # we don't want to set check for this msg = "SRPM build in copr has finished" logger.debug(msg) return HandlerResults(success=True, details={"msg": msg}) # TODO: drop the code below once we move to PG completely; the build is present in event # pg build_pg = CoprBuild.get_by_build_id( str(self.event.build_id), self.event.chroot ) if not build_pg: logger.info( f"build {self.event.build_id} is not in pg, falling back to redis" ) # redis - old school build = CoprBuildDB().get_build(self.event.build_id) if not build: # TODO: how could this happen? msg = f"Copr build {self.event.build_id} not in CoprBuildDB" logger.warning(msg) return HandlerResults(success=False, details={"msg": msg}) if build_pg: url = get_log_url(build_pg.id) else: url = copr_url_from_event(self.event) # https://pagure.io/copr/copr/blob/master/f/common/copr_common/enums.py#_42 if self.event.status != 1: failed_msg = "RPMs failed to be built." self.build_job_helper.report_status_to_all_for_chroot( state=CommitStatus.failure, description=failed_msg, url=url, chroot=self.event.chroot, ) if build_pg: build_pg.set_status("failure") return HandlerResults(success=False, details={"msg": failed_msg}) if ( self.build_job_helper.job_build and self.build_job_helper.job_build.trigger == TheJobTriggerType.pull_request and not self.was_last_build_successful() and self.package_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.event.owner}/{self.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.pr_comment(pr_id=self.event.pr_id, body=msg) self.build_job_helper.report_status_to_build_for_chroot( state=CommitStatus.success, description="RPMs were built successfully.", url=url, chroot=self.event.chroot, ) self.build_job_helper.report_status_to_test_for_chroot( state=CommitStatus.pending, description="RPMs were built successfully.", url=url, chroot=self.event.chroot, ) if build_pg: build_pg.set_status("success") if ( self.build_job_helper.job_tests and self.event.chroot in self.build_job_helper.tests_chroots ): testing_farm_handler = GithubTestingFarmHandler( config=self.config, job_config=self.build_job_helper.job_tests, event=self.event, chroot=self.event.chroot, ) testing_farm_handler.run() else: logger.debug("Testing farm not in the job config.") return HandlerResults(success=True, details={})
def run_copr_build(self) -> HandlerResults: if not (self.job_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") build_id, logs = self._run_copr_build_and_save_output() web_url = get_copr_build_url_for_values( self.job_owner, self.job_project, build_id ) srpm_build_model = SRPMBuild.create(logs) 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="pending", srpm_build=srpm_build_model, ) url = get_log_url(id_=copr_build.id) self.report_status_to_all_for_chroot( state="pending", description="Building RPM ...", url=url, chroot=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={})
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={})
def test_copr_build_set_status(a_copr_build): assert a_copr_build.status == "pending" a_copr_build.set_status("awesome") assert a_copr_build.status == "awesome" b = CoprBuild.get_by_build_id(a_copr_build.build_id, TARGET) assert b.status == "awesome"
def test_get_all(multiple_copr_builds): builds_list = CoprBuild.get_all() assert len(builds_list) == 3 # we just wanna check if result is iterable # order doesn't matter, so all of them are set to pending in supplied data assert builds_list[1].status == "pending"
def test_copr_build_set_build_logs_url(a_copr_build): url = "https://copr.fp.o/logs/12456/build.log" a_copr_build.set_build_logs_url(url) assert a_copr_build.build_logs_url == url b = CoprBuild.get_by_build_id(a_copr_build.build_id, TARGET) assert b.build_logs_url == url
def test_get_all_build_id(multiple_copr_builds): builds_list = CoprBuild.get_all_by_build_id(str(123456)) assert len(list(builds_list)) == 2 # both should have the same project_name assert builds_list[1].project_name == builds_list[0].project_name assert builds_list[1].project_name == "SomeUser-hello-world-9"