Merge lp:~cjwatson/launchpad/no-logtail-only-webhooks into lp:launchpad

Proposed by Colin Watson on 2018-01-23
Status: Merged
Merged at revision: 18533
Proposed branch: lp:~cjwatson/launchpad/no-logtail-only-webhooks
Merge into: lp:launchpad
Diff against target: 60 lines (+21/-3)
2 files modified
lib/lp/snappy/model/snapbuild.py (+4/-2)
lib/lp/snappy/tests/test_snapbuild.py (+17/-1)
To merge this branch: bzr merge lp:~cjwatson/launchpad/no-logtail-only-webhooks
Reviewer Review Type Date Requested Status
William Grant code 2018-01-23 Approve on 2018-01-23
Review via email: mp+336479@code.launchpad.net

Commit Message

Only emit snap:build:0.1 webhooks from SnapBuild.updateStatus if the status has changed.

To post a comment you must log in.
William Grant (wgrant) :
review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/snappy/model/snapbuild.py'
2--- lib/lp/snappy/model/snapbuild.py 2017-04-27 16:22:37 +0000
3+++ lib/lp/snappy/model/snapbuild.py 2018-01-23 13:39:53 +0000
4@@ -1,4 +1,4 @@
5-# Copyright 2015-2017 Canonical Ltd. This software is licensed under the
6+# Copyright 2015-2018 Canonical Ltd. This software is licensed under the
7 # GNU Affero General Public License version 3 (see the file LICENSE).
8
9 __metaclass__ = type
10@@ -335,6 +335,7 @@
11 date_started=None, date_finished=None,
12 force_invalid_transition=False):
13 """See `IBuildFarmJob`."""
14+ old_status = self.status
15 super(SnapBuild, self).updateStatus(
16 status, builder=builder, slave_status=slave_status,
17 date_started=date_started, date_finished=date_finished,
18@@ -343,7 +344,8 @@
19 revision_id = slave_status.get("revision_id")
20 if revision_id is not None:
21 self.revision_id = unicode(revision_id)
22- notify(SnapBuildStatusChangedEvent(self))
23+ if status != old_status:
24+ notify(SnapBuildStatusChangedEvent(self))
25
26 def notify(self, extra_info=None):
27 """See `IPackageBuild`."""
28
29=== modified file 'lib/lp/snappy/tests/test_snapbuild.py'
30--- lib/lp/snappy/tests/test_snapbuild.py 2017-10-20 13:35:42 +0000
31+++ lib/lp/snappy/tests/test_snapbuild.py 2018-01-23 13:39:53 +0000
32@@ -1,4 +1,4 @@
33-# Copyright 2015-2017 Canonical Ltd. This software is licensed under the
34+# Copyright 2015-2018 Canonical Ltd. This software is licensed under the
35 # GNU Affero General Public License version 3 (see the file LICENSE).
36
37 """Test snap package build features."""
38@@ -255,6 +255,22 @@
39 hook.id, hook.target),
40 repr(delivery))
41
42+ def test_updateStatus_no_change_does_not_trigger_webhooks(self):
43+ # An updateStatus call that changes details such as the revision_id
44+ # but that doesn't change the build's status attribute does not
45+ # trigger webhooks.
46+ hook = self.factory.makeWebhook(
47+ target=self.build.snap, event_types=["snap:build:0.1"])
48+ builder = self.factory.makeBuilder()
49+ self.build.updateStatus(BuildStatus.BUILDING)
50+ self.assertEqual(1, hook.deliveries.count())
51+ self.build.updateStatus(
52+ BuildStatus.BUILDING, builder=builder,
53+ slave_status={"revision_id": "1"})
54+ self.assertEqual(1, hook.deliveries.count())
55+ self.build.updateStatus(BuildStatus.UPLOADING)
56+ self.assertEqual(2, hook.deliveries.count())
57+
58 def test_updateStatus_failure_does_not_trigger_store_uploads(self):
59 # A failed SnapBuild does not trigger store uploads.
60 self.build.snap.store_series = self.factory.makeSnappySeries()