From bdf03bc60b074865b0c5dbeeb21bdf2acefbc1e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nikola=20Forr=C3=B3?= Date: Fri, 18 Oct 2024 15:08:28 +0200 Subject: [PATCH 1/4] Do not create model for Koji build with missing dependencies MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nikola Forró --- packit_service/models.py | 4 ++ packit_service/worker/handlers/distgit.py | 49 ++++++++++++----------- 2 files changed, 29 insertions(+), 24 deletions(-) diff --git a/packit_service/models.py b/packit_service/models.py index d0eac61a5..205d77c02 100644 --- a/packit_service/models.py +++ b/packit_service/models.py @@ -2586,6 +2586,8 @@ class KojiBuildTargetModel(GroupAndTargetModelConnector, Base): # metadata is reserved to sqlalch data = Column(JSON) + sidetag = Column(String) + # it is a scratch build? scratch = Column(Boolean) koji_build_group_id = Column(Integer, ForeignKey("koji_build_groups.id")) @@ -2705,6 +2707,7 @@ def create( status: str, scratch: bool, koji_build_group: "KojiBuildGroupModel", + sidetag: Optional[str] = None, ) -> "KojiBuildTargetModel": with sa_session_transaction(commit=True) as session: build = cls() @@ -2713,6 +2716,7 @@ def create( build.web_url = web_url build.target = target build.scratch = scratch + build.sidetag = sidetag session.add(build) koji_build_group.koji_build_targets.append(build) diff --git a/packit_service/worker/handlers/distgit.py b/packit_service/worker/handlers/distgit.py index 7b4466181..891dd5c93 100644 --- a/packit_service/worker/handlers/distgit.py +++ b/packit_service/worker/handlers/distgit.py @@ -799,12 +799,30 @@ def _get_or_create_koji_group_model(self) -> KojiBuildGroupModel: ) for branch in self.get_branches(): + sidetag = None + if self.job_config.sidetag_group: + # we need Kerberos ticket to create a new sidetag + self.packit_api.init_kerberos_ticket() + sidetag = SidetagHelper.get_or_create_sidetag( + self.job_config.sidetag_group, + branch, + ) + # check if dependencies are satisfied within the sidetag + dependencies = set(self.job_config.dependencies or []) + if missing_dependencies := sidetag.get_missing_dependencies( + dependencies, + ): + raise PackitException( + f"Missing dependencies for Koji build: {missing_dependencies}", + ) + KojiBuildTargetModel.create( task_id=None, web_url=None, target=branch, status="queued", scratch=self.job_config.scratch, + sidetag=sidetag.koji_name if sidetag else None, koji_build_group=group, ) @@ -836,9 +854,13 @@ def is_already_triggered(self, branch: str) -> bool: return False def run(self) -> TaskResults: - errors = {} + try: + group = self._get_or_create_koji_group_model() + except PackitException as ex: + logger.debug(f"Koji build failed to be submitted: {ex}") + return TaskResults(success=True, details={}) - group = self._get_or_create_koji_group_model() + errors = {} for koji_build_model in group.grouped_targets: branch = koji_build_model.target @@ -862,33 +884,12 @@ def run(self) -> TaskResults: koji_build_model.set_status("pending") try: - sidetag = None - if self.job_config.sidetag_group: - # we need Kerberos ticket to create a new sidetag - self.packit_api.init_kerberos_ticket() - sidetag = SidetagHelper.get_or_create_sidetag( - self.job_config.sidetag_group, - branch, - ) - # skip submitting build for a branch if dependencies - # are not satisfied within a sidetag - dependencies = set(self.job_config.dependencies or []) - if missing_dependencies := sidetag.get_missing_dependencies( - dependencies, - ): - logger.debug( - f"Skipping downstream Koji build for branch {branch}, " - f"missing dependencies: {missing_dependencies}", - ) - koji_build_model.set_status("skipped") - continue - stdout = self.packit_api.build( dist_git_branch=koji_build_model.target, scratch=self.job_config.scratch, nowait=True, from_upstream=False, - koji_target=sidetag.koji_name if sidetag else None, + koji_target=koji_build_model.sidetag, ) if stdout: task_id, web_url = get_koji_task_id_and_url_from_stdout(stdout) From 12883ac2efd5b002fabdfe8d8998a20bbf82d40f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nikola=20Forr=C3=B3?= Date: Fri, 18 Oct 2024 15:09:46 +0200 Subject: [PATCH 2/4] Check DB as well as Koji for running or successful builds with the same NVR MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nikola Forró --- packit_service/models.py | 21 ++++++++++++++++++++ packit_service/worker/handlers/distgit.py | 24 +++++++++++++++-------- 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/packit_service/models.py b/packit_service/models.py index 205d77c02..fe587f3c5 100644 --- a/packit_service/models.py +++ b/packit_service/models.py @@ -2587,6 +2587,7 @@ class KojiBuildTargetModel(GroupAndTargetModelConnector, Base): data = Column(JSON) sidetag = Column(String) + nvr = Column(String) # it is a scratch build? scratch = Column(Boolean) @@ -2708,6 +2709,7 @@ def create( scratch: bool, koji_build_group: "KojiBuildGroupModel", sidetag: Optional[str] = None, + nvr: Optional[str] = None, ) -> "KojiBuildTargetModel": with sa_session_transaction(commit=True) as session: build = cls() @@ -2717,6 +2719,7 @@ def create( build.target = target build.scratch = scratch build.sidetag = sidetag + build.nvr = nvr session.add(build) koji_build_group.koji_build_targets.append(build) @@ -2738,6 +2741,24 @@ def __repr__(self): f"build_submitted_time={self.build_submitted_time})" ) + @classmethod + def get_all_successful_or_in_progress_by_nvr( + cls, + nvr: str, + ) -> set["KojiBuildTargetModel"]: + with sa_session_transaction() as session: + return set( + session.query(KojiBuildTargetModel) + .filter( + KojiBuildTargetModel.nvr == nvr, + KojiBuildTargetModel.scratch == False, # noqa + KojiBuildTargetModel.status.in_( + ("queued", "pending", "retry", "running", "success"), + ), + ) + .all(), + ) + @classmethod def get_all_projects(cls) -> set["GitProjectModel"]: """Get all git projects with a successful downstream koji build.""" diff --git a/packit_service/worker/handlers/distgit.py b/packit_service/worker/handlers/distgit.py index 891dd5c93..846bb0785 100644 --- a/packit_service/worker/handlers/distgit.py +++ b/packit_service/worker/handlers/distgit.py @@ -823,6 +823,7 @@ def _get_or_create_koji_group_model(self) -> KojiBuildGroupModel: status="queued", scratch=self.job_config.scratch, sidetag=sidetag.koji_name if sidetag else None, + nvr=self.packit_api.dg.get_nvr(branch), koji_build_group=group, ) @@ -832,12 +833,11 @@ def _get_or_create_koji_group_model(self) -> KojiBuildGroupModel: def get_branches(self) -> list[str]: """Get a list of branch (names) to be built in koji""" - def is_already_triggered(self, branch: str) -> bool: + def is_already_triggered(self, nvr: str) -> bool: """ Check if the build was already triggered (building or completed state). """ - nvr = self.packit_api.dg.get_nvr(branch) existing_build = self.koji_helper.get_build_info(nvr) if existing_build: @@ -872,13 +872,21 @@ def run(self) -> TaskResults: ) continue - if not self.job_config.scratch and self.is_already_triggered(branch): - logger.info( - f"Skipping downstream Koji build for branch {branch} " - f"that was already triggered.", + if not self.job_config.scratch: + existing_models = ( + KojiBuildTargetModel.get_all_successful_or_in_progress_by_nvr( + koji_build_model.nvr, + ) ) - koji_build_model.set_status("skipped") - continue + if existing_models - {koji_build_model} or self.is_already_triggered( + koji_build_model.nvr, + ): + logger.info( + f"Skipping downstream Koji build {koji_build_model.nvr} " + f"for branch {branch} that was already triggered.", + ) + koji_build_model.set_status("skipped") + continue logger.debug(f"Running downstream Koji build for {branch}") koji_build_model.set_status("pending") From 5124591aa51c87625292adf7797e51c73c8a80f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nikola=20Forr=C3=B3?= Date: Tue, 22 Oct 2024 19:08:46 +0200 Subject: [PATCH 3/4] Update tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nikola Forró --- tests/integration/test_dg_commit.py | 105 +++++++++++++++++++----- tests/integration/test_issue_comment.py | 34 ++++++-- tests/integration/test_koji_build.py | 16 ++-- tests/integration/test_pr_comment.py | 12 ++- 4 files changed, 129 insertions(+), 38 deletions(-) diff --git a/tests/integration/test_dg_commit.py b/tests/integration/test_dg_commit.py index a3c5cf0b5..e749caa21 100644 --- a/tests/integration/test_dg_commit.py +++ b/tests/integration/test_dg_commit.py @@ -18,6 +18,7 @@ JobType, PackageConfig, ) +from packit.distgit import DistGit from packit.exceptions import PackitException from packit.local_project import LocalProjectBuilder from packit.utils.koji_helper import KojiHelper @@ -262,6 +263,23 @@ def test_downstream_koji_build(sidetag_group): db_project_event, ) flexmock(PipelineModel).should_receive("create") + + if sidetag_group: + sidetag = "f40-build-side-12345" + + flexmock(SidetagModel).should_receive("get_or_create_for_updating").and_return( + flexmock(koji_name=sidetag), + ) + flexmock(SidetagGroupModel).should_receive("get_or_create").and_return( + flexmock(), + ) + flexmock(KojiHelper).should_receive("get_tag_info").and_return(None) + flexmock(PackitAPI).should_receive("init_kerberos_ticket").and_return(None) + flexmock(KojiHelper).should_receive("create_sidetag").and_return( + {"name": sidetag}, + ) + + nvr = "package-1.2.3-1.fc40" koji_build = flexmock( target="main", status="queued", @@ -278,11 +296,10 @@ def test_downstream_koji_build(sidetag_group): ) if sidetag_group: - koji_target = "f40-build-side-12345" - sidetag = flexmock(koji_name=None) + sidetag = "f40-build-side-12345" flexmock(SidetagModel).should_receive("get_or_create_for_updating").and_return( - sidetag, + flexmock(koji_name=sidetag), ) flexmock(SidetagGroupModel).should_receive("get_or_create").and_return( flexmock(), @@ -290,9 +307,32 @@ def test_downstream_koji_build(sidetag_group): flexmock(KojiHelper).should_receive("get_tag_info").and_return(None) flexmock(PackitAPI).should_receive("init_kerberos_ticket").and_return(None) flexmock(KojiHelper).should_receive("create_sidetag").and_return( - {"name": koji_target}, + {"name": sidetag}, ) + nvr = "package-1.2.3-1.fc40" + koji_build = flexmock( + target="main", + status="queued", + sidetag=sidetag if sidetag_group else None, + nvr=nvr, + set_status=lambda x: None, + set_task_id=lambda x: None, + set_web_url=lambda x: None, + set_build_logs_urls=lambda x: None, + set_data=lambda x: None, + ) + + flexmock(DistGit).should_receive("get_nvr").and_return(nvr) + + flexmock(KojiBuildTargetModel).should_receive("create").and_return(koji_build) + flexmock(KojiBuildTargetModel).should_receive( + "get_all_successful_or_in_progress_by_nvr", + ).and_return({koji_build}) + flexmock(KojiBuildGroupModel).should_receive("create").and_return( + flexmock(grouped_targets=[koji_build]), + ) + flexmock(LocalProjectBuilder, _refresh_the_state=lambda *args: None) flexmock(group).should_receive("apply_async").once() flexmock(Pushgateway).should_receive("push").times(2).and_return() @@ -301,11 +341,8 @@ def test_downstream_koji_build(sidetag_group): scratch=False, nowait=True, from_upstream=False, - koji_target=koji_target if sidetag_group else None, + koji_target=sidetag if sidetag_group else None, ).and_return("") - flexmock(DownstreamKojiBuildHandler).should_receive( - "is_already_triggered", - ).and_return(False) processing_results = SteveJobs().process_message(distgit_commit_event()) event_dict, job, job_config, package_config = get_parameters_from_results( processing_results, @@ -373,9 +410,14 @@ def test_downstream_koji_build_failure_no_issue(): db_project_event, ) flexmock(PipelineModel).should_receive("create") + + nvr = "package-1.2.3-1.fc40" + koji_build = flexmock( target="main", status="queued", + sidetag=None, + nvr=nvr, set_status=lambda x: None, set_task_id=lambda x: None, set_web_url=lambda x: None, @@ -383,7 +425,12 @@ def test_downstream_koji_build_failure_no_issue(): set_data=lambda x: None, ) + flexmock(DistGit).should_receive("get_nvr").and_return(nvr) + flexmock(KojiBuildTargetModel).should_receive("create").and_return(koji_build) + flexmock(KojiBuildTargetModel).should_receive( + "get_all_successful_or_in_progress_by_nvr", + ).and_return({koji_build}) flexmock(KojiBuildGroupModel).should_receive("create").and_return( flexmock(id=1, grouped_targets=[koji_build]), ) @@ -398,9 +445,6 @@ def test_downstream_koji_build_failure_no_issue(): from_upstream=False, koji_target=None, ).and_raise(PackitException, "Some error") - flexmock(DownstreamKojiBuildHandler).should_receive( - "is_already_triggered", - ).and_return(False) pagure_project_mock.should_receive("get_issue_list").times(0) pagure_project_mock.should_receive("create_issue").times(0) @@ -472,9 +516,14 @@ def test_downstream_koji_build_failure_issue_created(): db_project_event, ) flexmock(PipelineModel).should_receive("create") + + nvr = "package-1.2.3-1.fc40" + koji_build = flexmock( target="main", status="queued", + sidetag=None, + nvr=nvr, set_status=lambda x: None, set_task_id=lambda x: None, set_web_url=lambda x: None, @@ -482,7 +531,12 @@ def test_downstream_koji_build_failure_issue_created(): set_data=lambda x: None, ) + flexmock(DistGit).should_receive("get_nvr").and_return(nvr) + flexmock(KojiBuildTargetModel).should_receive("create").and_return(koji_build) + flexmock(KojiBuildTargetModel).should_receive( + "get_all_successful_or_in_progress_by_nvr", + ).and_return({koji_build}) flexmock(KojiBuildGroupModel).should_receive("create").and_return( flexmock(grouped_targets=[koji_build]), ) @@ -496,9 +550,6 @@ def test_downstream_koji_build_failure_issue_created(): from_upstream=False, koji_target=None, ).and_raise(PackitException, "Some error") - flexmock(DownstreamKojiBuildHandler).should_receive( - "is_already_triggered", - ).and_return(False) issue_project_mock = flexmock(GithubProject) issue_project_mock.should_receive("get_issue_list").and_return([]).once() @@ -577,9 +628,14 @@ def test_downstream_koji_build_failure_issue_comment(): db_project_event, ) flexmock(PipelineModel).should_receive("create") + + nvr = "package-1.2.3-1.fc40" + koji_build = flexmock( target="main", status="queued", + sidetag=None, + nvr=nvr, set_status=lambda x: None, set_task_id=lambda x: None, set_web_url=lambda x: None, @@ -587,7 +643,12 @@ def test_downstream_koji_build_failure_issue_comment(): set_data=lambda x: None, ) + flexmock(DistGit).should_receive("get_nvr").and_return(nvr) + flexmock(KojiBuildTargetModel).should_receive("create").and_return(koji_build) + flexmock(KojiBuildTargetModel).should_receive( + "get_all_successful_or_in_progress_by_nvr", + ).and_return({koji_build}) flexmock(KojiBuildGroupModel).should_receive("create").and_return( flexmock(grouped_targets=[koji_build]), ) @@ -602,9 +663,6 @@ def test_downstream_koji_build_failure_issue_comment(): from_upstream=False, koji_target=None, ).and_raise(PackitException, "Some error") - flexmock(DownstreamKojiBuildHandler).should_receive( - "is_already_triggered", - ).and_return(False) issue_project_mock = flexmock(GithubProject) issue_project_mock.should_receive("get_issue_list").and_return( @@ -766,9 +824,14 @@ def test_downstream_koji_build_where_multiple_branches_defined(jobs_config): db_project_event, ) flexmock(PipelineModel).should_receive("create") + + nvr = "package-1.2.3-1.fc40" + koji_build = flexmock( target="main", status="queued", + sidetag=None, + nvr=nvr, set_status=lambda x: None, set_task_id=lambda x: None, set_web_url=lambda x: None, @@ -776,7 +839,12 @@ def test_downstream_koji_build_where_multiple_branches_defined(jobs_config): set_data=lambda x: None, ) + flexmock(DistGit).should_receive("get_nvr").and_return(nvr) + flexmock(KojiBuildTargetModel).should_receive("create").and_return(koji_build) + flexmock(KojiBuildTargetModel).should_receive( + "get_all_successful_or_in_progress_by_nvr", + ).and_return({koji_build}) flexmock(KojiBuildGroupModel).should_receive("create").and_return( flexmock(grouped_targets=[koji_build]), ) @@ -798,9 +866,6 @@ def test_downstream_koji_build_where_multiple_branches_defined(jobs_config): from_upstream=False, koji_target=None, ).once().and_return("") - flexmock(DownstreamKojiBuildHandler).should_receive( - "is_already_triggered", - ).and_return(False) processing_results = SteveJobs().process_message(distgit_commit_event()) assert len(processing_results) == 1 diff --git a/tests/integration/test_issue_comment.py b/tests/integration/test_issue_comment.py index 9af499785..afe2f5347 100644 --- a/tests/integration/test_issue_comment.py +++ b/tests/integration/test_issue_comment.py @@ -368,9 +368,14 @@ def mock_repository_issue_retriggering(): db_project_event, ) flexmock(PipelineModel).should_receive("create") + + nvr_f37 = "package-1.2.3-1.fc37" + koji_build_f37 = flexmock( target="f37", status="queued", + sidetag=None, + nvr=nvr_f37, set_status=lambda x: None, set_task_id=lambda x: None, set_web_url=lambda x: None, @@ -378,9 +383,13 @@ def mock_repository_issue_retriggering(): set_data=lambda x: None, ) + nvr_f38 = "package-1.2.3-1.fc38" + koji_build_f38 = flexmock( target="f38", status="queued", + sidetag=None, + nvr=nvr_f38, set_status=lambda x: None, set_task_id=lambda x: None, set_web_url=lambda x: None, @@ -389,6 +398,12 @@ def mock_repository_issue_retriggering(): ) flexmock(KojiBuildTargetModel).should_receive("create") + flexmock(KojiBuildTargetModel).should_receive( + "get_all_successful_or_in_progress_by_nvr", + ).with_args(nvr_f37).and_return({koji_build_f37}) + flexmock(KojiBuildTargetModel).should_receive( + "get_all_successful_or_in_progress_by_nvr", + ).with_args(nvr_f38).and_return({koji_build_f38}) flexmock(KojiBuildGroupModel).should_receive("create").and_return( flexmock(grouped_targets=[koji_build_f38, koji_build_f37]), ) @@ -538,26 +553,30 @@ def test_issue_comment_retrigger_koji_build_handler( ) assert json.dumps(event_dict) - flexmock(PackitAPI).should_receive("build").with_args( + dg = flexmock(local_project=flexmock(git_url="an url")) + dg.should_receive("get_nvr").with_args("f37").and_return("package-1.2.3-1.fc37") + dg.should_receive("get_nvr").with_args("f38").and_return("package-1.2.3-1.fc38") + packit_api = flexmock(dg=dg) + packit_api.should_receive("build").with_args( dist_git_branch="f37", scratch=False, nowait=True, from_upstream=False, koji_target=None, ).and_return("") - flexmock(PackitAPI).should_receive("build").with_args( + packit_api.should_receive("build").with_args( dist_git_branch="f38", scratch=False, nowait=True, from_upstream=False, koji_target=None, ).and_return("") + flexmock(RetriggerDownstreamKojiBuildHandler).should_receive( + "packit_api", + ).and_return(packit_api) flexmock(RetriggerDownstreamKojiBuildHandler).should_receive( "local_project", ).and_return(flexmock()) - flexmock(RetriggerDownstreamKojiBuildHandler).should_receive( - "is_already_triggered", - ).and_return(False) results = run_retrigger_downstream_koji_build( package_config=package_config, @@ -583,6 +602,8 @@ def test_issue_comment_retrigger_koji_build_error_msg( flexmock(CeleryTask).should_receive("is_last_try").and_return(True) error_msg = "error abc" dg = flexmock(local_project=flexmock(git_url="an url")) + dg.should_receive("get_nvr").with_args("f37").and_return("package-1.2.3-1.fc37") + dg.should_receive("get_nvr").with_args("f38").and_return("package-1.2.3-1.fc38") packit_api = flexmock(dg=dg) packit_api.should_receive("build").with_args( dist_git_branch="f38", @@ -621,9 +642,6 @@ def test_issue_comment_retrigger_koji_build_error_msg( message=msg, comment_to_existing=msg, ).once() - flexmock(RetriggerDownstreamKojiBuildHandler).should_receive( - "is_already_triggered", - ).and_return(False) run_retrigger_downstream_koji_build( package_config=package_config, diff --git a/tests/integration/test_koji_build.py b/tests/integration/test_koji_build.py index 5c058893a..b7d9416a9 100644 --- a/tests/integration/test_koji_build.py +++ b/tests/integration/test_koji_build.py @@ -8,7 +8,6 @@ from flexmock import flexmock from ogr.services.github import GithubProject from ogr.services.pagure import PagureProject -from packit.api import PackitAPI from packit.config import JobConfigTriggerType from packit.exceptions import PackitException from packit.utils.koji_helper import KojiHelper @@ -165,9 +164,14 @@ def test_koji_build_error_msg(distgit_push_packit): db_project_event, ) flexmock(PipelineModel).should_receive("create") + + nvr = "package-1.2.3-1.fc40" + koji_build = flexmock( target="f36", status="queued", + sidetag=None, + nvr=nvr, set_status=lambda x: None, set_task_id=lambda x: None, set_web_url=lambda x: None, @@ -176,6 +180,9 @@ def test_koji_build_error_msg(distgit_push_packit): ) flexmock(KojiBuildTargetModel).should_receive("create").and_return(koji_build) + flexmock(KojiBuildTargetModel).should_receive( + "get_all_successful_or_in_progress_by_nvr", + ).and_return({koji_build}) flexmock(KojiBuildGroupModel).should_receive("create").and_return( flexmock(grouped_targets=[koji_build]), ) @@ -193,6 +200,7 @@ def test_koji_build_error_msg(distgit_push_packit): flexmock(CeleryTask).should_receive("is_last_try").and_return(True) error_msg = "error abc" dg = flexmock(local_project=flexmock(git_url="an url")) + dg.should_receive("get_nvr").and_return(nvr) packit_api = ( flexmock(dg=dg) .should_receive("build") @@ -224,9 +232,6 @@ def test_koji_build_error_msg(distgit_push_packit): message=msg, comment_to_existing=msg, ).once() - flexmock(DownstreamKojiBuildHandler).should_receive( - "is_already_triggered", - ).and_return(False) run_downstream_koji_build( package_config=package_config, @@ -245,9 +250,6 @@ def test_koji_build_error_msg(distgit_push_packit): ], ) def test_is_already_triggered(build_info, result): - flexmock(PackitAPI).should_receive("dg").and_return( - flexmock(get_nvr=lambda branch: "some-nvr"), - ) flexmock(KojiHelper).should_receive("get_build_info").and_return(build_info) assert ( diff --git a/tests/integration/test_pr_comment.py b/tests/integration/test_pr_comment.py index 0cbd90deb..631ee3245 100644 --- a/tests/integration/test_pr_comment.py +++ b/tests/integration/test_pr_comment.py @@ -2423,9 +2423,13 @@ def test_koji_build_retrigger_via_dist_git_pr_comment(pagure_pr_comment_added): ) flexmock(PipelineModel).should_receive("create") + nvr = "package-1.2.3-1.fc40" + koji_build = flexmock( target="the_distgit_branch", status="queued", + sidetag=None, + nvr=nvr, set_status=lambda x: None, set_task_id=lambda x: None, set_web_url=lambda x: None, @@ -2433,7 +2437,12 @@ def test_koji_build_retrigger_via_dist_git_pr_comment(pagure_pr_comment_added): set_data=lambda x: None, ) + flexmock(DistGit).should_receive("get_nvr").and_return(nvr) + flexmock(KojiBuildTargetModel).should_receive("create").and_return(koji_build) + flexmock(KojiBuildTargetModel).should_receive( + "get_all_successful_or_in_progress_by_nvr", + ).and_return({koji_build}) flexmock(KojiBuildGroupModel).should_receive("create").and_return( flexmock(grouped_targets=[koji_build]), ) @@ -2483,9 +2492,6 @@ def test_koji_build_retrigger_via_dist_git_pr_comment(pagure_pr_comment_added): ) flexmock(DownstreamKojiBuildHandler).should_receive("pre_check").and_return(True) - flexmock(DownstreamKojiBuildHandler).should_receive( - "is_already_triggered", - ).and_return(False) flexmock(LocalProjectBuilder, _refresh_the_state=lambda *args: flexmock()) flexmock(LocalProject, refresh_the_arguments=lambda: None) flexmock(celery_group).should_receive("apply_async").once() From 5ec4c47efac49e3243c9142379cd5c3b9c0a70df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nikola=20Forr=C3=B3?= Date: Sun, 20 Oct 2024 17:52:47 +0200 Subject: [PATCH 4/4] Add DB migration script MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nikola Forró --- ...be5bc358_add_sidetag_and_nvr_fields_to_.py | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 alembic/versions/adb6be5bc358_add_sidetag_and_nvr_fields_to_.py diff --git a/alembic/versions/adb6be5bc358_add_sidetag_and_nvr_fields_to_.py b/alembic/versions/adb6be5bc358_add_sidetag_and_nvr_fields_to_.py new file mode 100644 index 000000000..f06333419 --- /dev/null +++ b/alembic/versions/adb6be5bc358_add_sidetag_and_nvr_fields_to_.py @@ -0,0 +1,34 @@ +"""Add sidetag and nvr fields to KojiBuildTargetModel + +Revision ID: adb6be5bc358 +Revises: f376be1907e1 +Create Date: 2024-10-20 15:47:45.454965 + +""" + +import sqlalchemy as sa + +from alembic import op + +# revision identifiers, used by Alembic. +revision = "adb6be5bc358" +down_revision = "f376be1907e1" +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.add_column( + "koji_build_targets", + sa.Column("sidetag", sa.String(), nullable=True), + ) + op.add_column("koji_build_targets", sa.Column("nvr", sa.String(), nullable=True)) + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_column("koji_build_targets", "nvr") + op.drop_column("koji_build_targets", "sidetag") + # ### end Alembic commands ###