Merge ~cjwatson/launchpad:oci-fix-job-events into launchpad:master

Proposed by Colin Watson
Status: Merged
Approved by: Colin Watson
Approved revision: 79f3b82c74509c9929ccbe5ebf4c5d450ef6307d
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~cjwatson/launchpad:oci-fix-job-events
Merge into: launchpad:master
Diff against target: 79 lines (+12/-20)
2 files modified
lib/lp/oci/model/ocirecipebuildjob.py (+10/-8)
lib/lp/oci/tests/test_ocirecipebuildjob.py (+2/-12)
Reviewer Review Type Date Requested Status
Tom Wardill (community) Approve
Review via email: mp+384952@code.launchpad.net

Commit message

Fix event notifications in OCIRegistryUploadJob.create

Description of the change

This modifies a build's registry upload status, rather than creating a build, so issue the correct event notifications that correspond to that. This affects which webhook deliveries are made.

To post a comment you must log in.
Revision history for this message
Tom Wardill (twom) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/lib/lp/oci/model/ocirecipebuildjob.py b/lib/lp/oci/model/ocirecipebuildjob.py
2index bd34c19..fc84c17 100644
3--- a/lib/lp/oci/model/ocirecipebuildjob.py
4+++ b/lib/lp/oci/model/ocirecipebuildjob.py
5@@ -17,7 +17,6 @@ from lazr.enum import (
6 DBEnumeratedType,
7 DBItem,
8 )
9-from lazr.lifecycle.event import ObjectCreatedEvent
10 import six
11 from storm.databases.postgres import JSON
12 from storm.locals import (
13@@ -26,7 +25,6 @@ from storm.locals import (
14 )
15 import transaction
16 from zope.component import getUtility
17-from zope.event import notify
18 from zope.interface import (
19 implementer,
20 provider,
21@@ -161,12 +159,16 @@ class OCIRegistryUploadJob(OCIRecipeBuildJobDerived):
22 @classmethod
23 def create(cls, build):
24 """See `IOCIRegistryUploadJobSource`"""
25- oci_build_job = OCIRecipeBuildJob(
26- build, cls.class_job_type, {})
27- job = cls(oci_build_job)
28- job.celeryRunOnCommit()
29- del get_property_cache(build).last_registry_upload_job
30- notify(ObjectCreatedEvent(build))
31+ edited_fields = set()
32+ with notify_modified(build, edited_fields) as before_modification:
33+ oci_build_job = OCIRecipeBuildJob(
34+ build, cls.class_job_type, {})
35+ job = cls(oci_build_job)
36+ job.celeryRunOnCommit()
37+ del get_property_cache(build).last_registry_upload_job
38+ upload_status = build.registry_upload_status
39+ if upload_status != before_modification.registry_upload_status:
40+ edited_fields.add("registry_upload_status")
41 return job
42
43 # Ideally we'd just override Job._set_status or similar, but
44diff --git a/lib/lp/oci/tests/test_ocirecipebuildjob.py b/lib/lp/oci/tests/test_ocirecipebuildjob.py
45index c0926a4..ef3af8a 100644
46--- a/lib/lp/oci/tests/test_ocirecipebuildjob.py
47+++ b/lib/lp/oci/tests/test_ocirecipebuildjob.py
48@@ -131,15 +131,6 @@ class TestOCIRegistryUploadJob(TestCaseWithFactory):
49 expected_payloads = [{
50 "recipe_build": Equals(
51 canonical_url(ocibuild, force_local_path=True)),
52- "action": Equals("created"),
53- "recipe": Equals(
54- canonical_url(ocibuild.recipe, force_local_path=True)),
55- "build_request": Is(None),
56- "status": Equals("Successfully built"),
57- "registry_upload_status": Equals("Pending")}]
58- expected_payloads += [{
59- "recipe_build": Equals(
60- canonical_url(ocibuild, force_local_path=True)),
61 "action": Equals("status-changed"),
62 "recipe": Equals(
63 canonical_url(ocibuild.recipe, force_local_path=True)),
64@@ -184,8 +175,7 @@ class TestOCIRegistryUploadJob(TestCaseWithFactory):
65 self.assertContentEqual([job], ocibuild.registry_upload_jobs)
66 self.assertIsNone(job.error_message)
67 self.assertEqual([], pop_notifications())
68- self.assertWebhookDeliveries(
69- ocibuild, ["Uploaded"], logger)
70+ self.assertWebhookDeliveries(ocibuild, ["Pending", "Uploaded"], logger)
71
72 def test_run_failed(self):
73 # A failed run sets the registry upload status to FAILED.
74@@ -203,4 +193,4 @@ class TestOCIRegistryUploadJob(TestCaseWithFactory):
75 self.assertEqual("An upload failure", job.error_message)
76 self.assertEqual([], pop_notifications())
77 self.assertWebhookDeliveries(
78- ocibuild, ["Failed to upload"], logger)
79+ ocibuild, ["Pending", "Failed to upload"], logger)

Subscribers

People subscribed via source and target branches

to status/vote changes: