Skip to content

Commit

Permalink
Implement koji_build trigger for bodhi_update job (#2475)
Browse files Browse the repository at this point in the history
Implement `koji_build` trigger for `bodhi_update` job

Fixes #2379.
I purposefully didn't implement removing sidetags from DB after a successful update creation because I want to see first how exactly the Bodhi workflow works - at which point is the sidetag removed from Koji etc. Maybe it would be enough to leave it to the periodic cleanup: #2412

Reviewed-by: Laura Barcziová
  • Loading branch information
softwarefactory-project-zuul[bot] authored Jul 29, 2024
2 parents 889e754 + fc57245 commit 2103bec
Show file tree
Hide file tree
Showing 18 changed files with 604 additions and 47 deletions.
34 changes: 34 additions & 0 deletions alembic/versions/64a51b961c28_bodhi_updates_from_sidetags.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"""Bodhi updates from sidetags
Revision ID: 64a51b961c28
Revises: e05e1b04de87
Create Date: 2024-07-23 14:47:21.313545
"""

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = "64a51b961c28"
down_revision = "e05e1b04de87"
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.alter_column("bodhi_update_targets", "koji_nvr", new_column_name="koji_nvrs")
op.add_column(
"bodhi_update_targets", sa.Column("sidetag", sa.String(), nullable=True)
)
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column("bodhi_update_targets", "sidetag")
op.alter_column("bodhi_update_targets", "koji_nvrs", new_column_name="koji_nvr")
# ### end Alembic commands ###
17 changes: 14 additions & 3 deletions packit_service/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2048,7 +2048,8 @@ class BodhiUpdateTargetModel(GroupAndTargetModelConnector, Base):
status = Column(String)
target = Column(String)
web_url = Column(String)
koji_nvr = Column(String)
koji_nvrs = Column(String)
sidetag = Column(String)
alias = Column(String)
submitted_time = Column(DateTime, default=datetime.utcnow)
update_creation_time = Column(DateTime)
Expand Down Expand Up @@ -2089,14 +2090,16 @@ def create(
cls,
target: str,
status: str,
koji_nvr: str,
koji_nvrs: str,
bodhi_update_group: "BodhiUpdateGroupModel",
sidetag: Optional[str] = None,
) -> "BodhiUpdateTargetModel":
with sa_session_transaction(commit=True) as session:
update = cls()
update.status = status
update.target = target
update.koji_nvr = koji_nvr
update.koji_nvrs = koji_nvrs
update.sidetag = sidetag
session.add(update)

bodhi_update_group.bodhi_update_targets.append(update)
Expand Down Expand Up @@ -3540,6 +3543,14 @@ def get_by_name(cls, name: str) -> Optional["SidetagGroupModel"]:
with sa_session_transaction() as session:
return session.query(cls).filter_by(name=name).first()

def get_sidetag_by_target(self, target: str) -> Optional["SidetagModel"]:
with sa_session_transaction() as session:
return (
session.query(SidetagModel)
.filter_by(sidetag_group_id=self.id, target=target)
.first()
)


class SidetagModel(Base):
__tablename__ = "sidetags"
Expand Down
4 changes: 2 additions & 2 deletions packit_service/service/api/bodhi_updates.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def get(self):
"status": update.status,
"branch": update.target,
"web_url": update.web_url,
"koji_nvr": update.koji_nvr,
"koji_nvrs": update.koji_nvrs,
"alias": update.alias,
"pr_id": update.get_pr_id(),
"branch_name": update.get_branch_name(),
Expand Down Expand Up @@ -77,7 +77,7 @@ def get(self, id):
"status": update.status,
"branch": update.target,
"web_url": update.web_url,
"koji_nvr": update.koji_nvr,
"koji_nvrs": update.koji_nvrs,
"alias": update.alias,
"submitted_time": optional_timestamp(update.submitted_time),
"update_creation_time": optional_timestamp(update.update_creation_time),
Expand Down
10 changes: 9 additions & 1 deletion packit_service/worker/checker/bodhi.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from packit_service.worker.handlers.mixin import (
GetKojiBuildData,
GetKojiBuildDataFromKojiBuildEventMixin,
GetKojiBuildDataFromKojiBuildTagEventMixin,
GetKojiBuildDataFromKojiServiceMixin,
GetKojiBuildEventMixin,
)
Expand All @@ -28,7 +29,7 @@
IssueCommentGitlabEvent,
)

from packit_service.worker.events.koji import KojiBuildEvent
from packit_service.worker.events.koji import KojiBuildEvent, KojiBuildTagEvent
from packit_service.worker.reporting import report_in_issue_repository

logger = logging.getLogger(__name__)
Expand All @@ -45,6 +46,7 @@ def pre_check(self) -> bool:
if self.data.event_type in (
PullRequestCommentPagureEvent.__name__,
KojiBuildEvent.__name__,
KojiBuildTagEvent.__name__,
):
for koji_build_data in self:
if koji_build_data.state != KojiBuildState.complete:
Expand Down Expand Up @@ -99,6 +101,12 @@ class IsKojiBuildCompleteAndBranchConfiguredCheckEvent(
): ...


class IsKojiBuildCompleteAndBranchConfiguredCheckSidetag(
IsKojiBuildCompleteAndBranchConfigured,
GetKojiBuildDataFromKojiBuildTagEventMixin,
): ...


class IsKojiBuildCompleteAndBranchConfiguredCheckService(
IsKojiBuildCompleteAndBranchConfigured, GetKojiBuildDataFromKojiServiceMixin
): ...
Expand Down
7 changes: 6 additions & 1 deletion packit_service/worker/checker/distgit.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
)
from packit_service.worker.events.new_hotness import NewHotnessUpdateEvent
from packit_service.worker.events.pagure import PullRequestCommentPagureEvent
from packit_service.worker.events.koji import KojiBuildTagEvent
from packit_service.worker.handlers.mixin import GetProjectToSyncMixin
from packit_service.worker.mixin import (
GetPagurePullRequestMixin,
Expand All @@ -42,7 +43,10 @@ def pre_check(self) -> bool:

class PermissionOnDistgit(Checker, GetPagurePullRequestMixin):
def pre_check(self) -> bool:
if self.data.event_type in (PushPagureEvent.__name__,):
if self.data.event_type in (
PushPagureEvent.__name__,
KojiBuildTagEvent.__name__,
):
if self.data.git_ref not in (
configured_branches := get_branches(
*self.job_config.dist_git_branches,
Expand All @@ -56,6 +60,7 @@ def pre_check(self) -> bool:
)
return False

if self.data.event_type in (PushPagureEvent.__name__,):
if self.pull_request:
pr_author = self.get_pr_author()
logger.debug(f"PR author: {pr_author}")
Expand Down
2 changes: 1 addition & 1 deletion packit_service/worker/events/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ def _add_project_object_and_event(self):
self._db_project_object,
self._db_project_event,
) = ProjectEventModel.add_koji_build_tag_event(
task_id=str(self.event_dict.get("event_dict", {}).get("task_id")),
task_id=str(self.event_dict.get("task_id")),
koji_tag_name=self.tag_name,
namespace=self.project.namespace,
repo_name=self.project.repo,
Expand Down
14 changes: 14 additions & 0 deletions packit_service/worker/events/koji.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,5 +382,19 @@ def commit_sha(self) -> Optional[str]: # type:ignore
def nvr(self) -> str:
return f"{self.package_name}-{self.version}-{self.release}"

@classmethod
def from_event_dict(cls, event: dict) -> "KojiBuildTagEvent":
return KojiBuildTagEvent(
build_id=event.get("build_id"),
tag_id=event.get("tag_id"),
tag_name=event.get("tag_name"),
project_url=event.get("project_url"),
package_name=event.get("package_name"),
epoch=event.get("epoch"),
version=event.get("version"),
release=event.get("release"),
owner=event.get("owner"),
)

def get_non_serializable_attributes(self):
return super().get_non_serializable_attributes() + ["_koji_helper"]
1 change: 1 addition & 0 deletions packit_service/worker/handlers/abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ class TaskName(str, enum.Enum):
# downstream_koji_build_report = "task.run_downstream_koji_build_report_handler"
sync_from_downstream = "task.run_sync_from_downstream_handler"
bodhi_update = "task.bodhi_update"
bodhi_update_from_sidetag = "task.bodhi_update_from_sidetag"
retrigger_bodhi_update = "task.retrigger_bodhi_update"
issue_comment_retrigger_bodhi_update = "task.issue_comment_retrigger_bodhi_update"
github_fas_verification = "task.github_fas_verification"
Expand Down
Loading

0 comments on commit 2103bec

Please sign in to comment.