Skip to content

Commit

Permalink
Merge pull request #852 from lbarcziova/koji-non-scratch-error
Browse files Browse the repository at this point in the history
Set error status when running non-scratch production build

Reviewed-by: https://github.com/apps/softwarefactory-project-zuul
  • Loading branch information
softwarefactory-project-zuul[bot] committed Oct 19, 2020
2 parents a1ba598 + a7a2a10 commit 45903cf
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 9 deletions.
1 change: 1 addition & 0 deletions packit_service/constants.py
Expand Up @@ -5,6 +5,7 @@
FAQ_URL_HOW_TO_RETRIGGER = (
f"{DOCS_URL}#how-to-re-trigger-packit-service-actions-in-your-pull-request"
)
KOJI_PRODUCTION_BUILDS_ISSUE = "https://pagure.io/releng/issue/9801"

SANDCASTLE_WORK_DIR = "/sandcastle"
SANDCASTLE_IMAGE = "docker.io/usercont/sandcastle"
Expand Down
11 changes: 10 additions & 1 deletion packit_service/worker/build/koji_build.py
Expand Up @@ -31,7 +31,7 @@

from packit_service import sentry_integration
from packit_service.config import ServiceConfig
from packit_service.constants import MSG_RETRIGGER
from packit_service.constants import MSG_RETRIGGER, KOJI_PRODUCTION_BUILDS_ISSUE
from packit_service.models import KojiBuildModel
from packit_service.service.urls import (
get_srpm_log_url_from_flask,
Expand Down Expand Up @@ -113,6 +113,15 @@ def supported_koji_targets(self):
return self._supported_koji_targets

def run_koji_build(self) -> TaskResults:
if not self.is_scratch:
msg = "Non-scratch builds not possible from upstream."
self.report_status_to_all(
description=msg,
state=CommitStatus.error,
url=KOJI_PRODUCTION_BUILDS_ISSUE,
)
return TaskResults(success=True, details={"msg": msg})

self.report_status_to_all(
description="Building SRPM ...", state=CommitStatus.pending
)
Expand Down
48 changes: 40 additions & 8 deletions tests/unit/test_koji_build.py
Expand Up @@ -38,6 +38,7 @@
from packit.exceptions import PackitCommandFailedError
from packit.upstream import Upstream
from packit_service import sentry_integration
from packit_service.constants import KOJI_PRODUCTION_BUILDS_ISSUE
from packit_service.config import ServiceConfig
from packit_service.models import SRPMBuildModel, KojiBuildModel
from packit_service.service.db_triggers import AddPullRequestDbTrigger
Expand Down Expand Up @@ -114,7 +115,7 @@ def test_koji_build_check_names(github_pr_event):
flexmock(AddPullRequestDbTrigger).should_receive("db_trigger").and_return(trigger)
helper = build_helper(
event=github_pr_event,
metadata=JobMetadataConfig(targets=["bright-future"]),
metadata=JobMetadataConfig(targets=["bright-future"], scratch=True),
db_trigger=trigger,
)
flexmock(koji_build).should_receive("get_all_koji_targets").and_return(
Expand Down Expand Up @@ -159,11 +160,13 @@ def test_koji_build_check_names(github_pr_event):


def test_koji_build_failed_kerberos(github_pr_event):
trigger = flexmock(job_config_trigger_type=JobConfigTriggerType.release, id=123)
trigger = flexmock(
job_config_trigger_type=JobConfigTriggerType.pull_request, id=123
)
flexmock(AddPullRequestDbTrigger).should_receive("db_trigger").and_return(trigger)
helper = build_helper(
event=github_pr_event,
metadata=JobMetadataConfig(targets=["bright-future"]),
metadata=JobMetadataConfig(targets=["bright-future"], scratch=True),
db_trigger=trigger,
)
flexmock(koji_build).should_receive("get_all_koji_targets").and_return(
Expand Down Expand Up @@ -214,7 +217,7 @@ def test_koji_build_target_not_supported(github_pr_event):
flexmock(AddPullRequestDbTrigger).should_receive("db_trigger").and_return(trigger)
helper = build_helper(
event=github_pr_event,
metadata=JobMetadataConfig(targets=["nonexisting-target"]),
metadata=JobMetadataConfig(targets=["nonexisting-target"], scratch=True),
db_trigger=trigger,
)
flexmock(koji_build).should_receive("get_all_koji_targets").and_return(
Expand Down Expand Up @@ -258,7 +261,9 @@ def test_koji_build_with_multiple_targets(github_pr_event):
flexmock(AddPullRequestDbTrigger).should_receive("db_trigger").and_return(trigger)
helper = build_helper(
event=github_pr_event,
metadata=JobMetadataConfig(targets=["bright-future", "dark-past"]),
metadata=JobMetadataConfig(
targets=["bright-future", "dark-past"], scratch=True
),
db_trigger=trigger,
)
flexmock(koji_build).should_receive("get_all_koji_targets").and_return(
Expand Down Expand Up @@ -302,7 +307,7 @@ def test_koji_build_failed(github_pr_event):
flexmock(AddPullRequestDbTrigger).should_receive("db_trigger").and_return(trigger)
helper = build_helper(
event=github_pr_event,
metadata=JobMetadataConfig(targets=["bright-future"]),
metadata=JobMetadataConfig(targets=["bright-future"], scratch=True),
db_trigger=trigger,
)
flexmock(koji_build).should_receive("get_all_koji_targets").and_return(
Expand Down Expand Up @@ -344,11 +349,13 @@ def test_koji_build_failed(github_pr_event):


def test_koji_build_failed_srpm(github_pr_event):
trigger = flexmock(job_config_trigger_type=JobConfigTriggerType.release, id=123)
trigger = flexmock(
job_config_trigger_type=JobConfigTriggerType.pull_request, id=123
)
flexmock(AddPullRequestDbTrigger).should_receive("db_trigger").and_return(trigger)
helper = build_helper(
event=github_pr_event,
metadata=JobMetadataConfig(targets=["bright-future"]),
metadata=JobMetadataConfig(targets=["bright-future"], scratch=True),
db_trigger=trigger,
)
srpm_build_url = get_srpm_log_url_from_flask(2)
Expand Down Expand Up @@ -378,6 +385,31 @@ def test_koji_build_failed_srpm(github_pr_event):
assert "SRPM build failed" in result["details"]["msg"]


def test_koji_build_non_scratch(github_pr_event):
trigger = flexmock(
job_config_trigger_type=JobConfigTriggerType.pull_request, id=123
)
flexmock(AddPullRequestDbTrigger).should_receive("db_trigger").and_return(trigger)
helper = build_helper(
event=github_pr_event,
metadata=JobMetadataConfig(targets=["bright-future"]),
db_trigger=trigger,
)
flexmock(StatusReporter).should_receive("set_status").with_args(
state=CommitStatus.error,
description="Non-scratch builds not possible from upstream.",
check_name="packit-stg/production-build-bright-future",
url=KOJI_PRODUCTION_BUILDS_ISSUE,
).and_return()

flexmock(GitProject).should_receive("set_commit_status").and_return().never()
flexmock(KojiBuildModel).should_receive("get_or_create").never()

result = helper.run_koji_build()
assert result["success"]
assert "Non-scratch builds not possible from upstream." in result["details"]["msg"]


@pytest.mark.parametrize(
"id_,result",
[
Expand Down

0 comments on commit 45903cf

Please sign in to comment.