Merge ~cjwatson/launchpad:livefs-request-build-consider-metadata into launchpad:master

Proposed by Colin Watson
Status: Merged
Approved by: Colin Watson
Approved revision: 8181003da83a11609b86b76f1b9c665c60c99917
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~cjwatson/launchpad:livefs-request-build-consider-metadata
Merge into: launchpad:master
Diff against target: 108 lines (+50/-6)
2 files modified
lib/lp/soyuz/model/livefs.py (+20/-5)
lib/lp/soyuz/tests/test_livefs.py (+30/-1)
Reviewer Review Type Date Requested Status
Tom Wardill (community) Approve
Review via email: mp+379901@code.launchpad.net

Commit message

Consider metadata_override in LiveFS.requestBuild

Description of the change

While I'm here, also fix the comparison of unique_key; it was previously using a plain equality test, which in SQL returns NULL if one side or the other is NULL.

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/soyuz/model/livefs.py b/lib/lp/soyuz/model/livefs.py
2index 0ec68b4..921d3b4 100644
3--- a/lib/lp/soyuz/model/livefs.py
4+++ b/lib/lp/soyuz/model/livefs.py
5@@ -1,4 +1,4 @@
6-# Copyright 2014-2019 Canonical Ltd. This software is licensed under the
7+# Copyright 2014-2020 Canonical Ltd. This software is licensed under the
8 # GNU Affero General Public License version 3 (see the file LICENSE).
9
10 __metaclass__ = type
11@@ -7,10 +7,13 @@ __all__ = [
12 ]
13
14 from datetime import timedelta
15+import json
16 import math
17
18 from lazr.lifecycle.event import ObjectCreatedEvent
19 import pytz
20+import six
21+from storm.expr import Cast
22 from storm.locals import (
23 Bool,
24 DateTime,
25@@ -55,6 +58,7 @@ from lp.services.database.interfaces import (
26 )
27 from lp.services.database.stormexpr import (
28 Greatest,
29+ IsDistinctFrom,
30 NullsLast,
31 )
32 from lp.services.features import getFeatureFlag
33@@ -183,14 +187,25 @@ class LiveFS(Storm, WebhookTargetMixin):
34 # See rationale in `LiveFSBuildArchiveOwnerMismatch` docstring.
35 raise LiveFSBuildArchiveOwnerMismatch()
36
37- pending = IStore(self).find(
38- LiveFSBuild,
39+ clauses = [
40 LiveFSBuild.livefs_id == self.id,
41 LiveFSBuild.archive_id == archive.id,
42 LiveFSBuild.distro_arch_series_id == distro_arch_series.id,
43 LiveFSBuild.pocket == pocket,
44- LiveFSBuild.unique_key == unique_key,
45- LiveFSBuild.status == BuildStatus.NEEDSBUILD)
46+ Not(IsDistinctFrom(LiveFSBuild.unique_key, unique_key)),
47+ # Cast to jsonb in order to compare the JSON structures rather
48+ # than their encoding, since the latter might differ in
49+ # insignificant ways.
50+ Not(IsDistinctFrom(
51+ Cast(LiveFSBuild.metadata_override, "jsonb"),
52+ Cast(
53+ None if metadata_override is None
54+ else six.ensure_text(
55+ json.dumps(metadata_override, ensure_ascii=False)),
56+ "jsonb"))),
57+ LiveFSBuild.status == BuildStatus.NEEDSBUILD,
58+ ]
59+ pending = IStore(self).find(LiveFSBuild, *clauses)
60 if pending.any() is not None:
61 raise LiveFSBuildAlreadyPending
62
63diff --git a/lib/lp/soyuz/tests/test_livefs.py b/lib/lp/soyuz/tests/test_livefs.py
64index 315b96a..70e276d 100644
65--- a/lib/lp/soyuz/tests/test_livefs.py
66+++ b/lib/lp/soyuz/tests/test_livefs.py
67@@ -1,4 +1,4 @@
68-# Copyright 2014-2019 Canonical Ltd. This software is licensed under the
69+# Copyright 2014-2020 Canonical Ltd. This software is licensed under the
70 # GNU Affero General Public License version 3 (see the file LICENSE).
71
72 """Test live filesystems."""
73@@ -246,6 +246,35 @@ class TestLiveFS(TestCaseWithFactory):
74 self.factory.makeDistroArchSeries(
75 distroseries=livefs.distro_series),
76 PackagePublishingPocket.RELEASE)
77+ # We can specify a unique key.
78+ livefs.requestBuild(
79+ livefs.owner, livefs.distro_series.main_archive, distroarchseries,
80+ PackagePublishingPocket.RELEASE, unique_key="foo")
81+ livefs.requestBuild(
82+ livefs.owner, livefs.distro_series.main_archive, distroarchseries,
83+ PackagePublishingPocket.RELEASE, unique_key="bar")
84+ self.assertRaises(
85+ LiveFSBuildAlreadyPending, livefs.requestBuild,
86+ livefs.owner, livefs.distro_series.main_archive, distroarchseries,
87+ PackagePublishingPocket.RELEASE, unique_key="bar")
88+ # We can apply different metadata overrides.
89+ livefs.requestBuild(
90+ livefs.owner, livefs.distro_series.main_archive, distroarchseries,
91+ PackagePublishingPocket.RELEASE,
92+ metadata_override={"proposed": True})
93+ livefs.requestBuild(
94+ livefs.owner, livefs.distro_series.main_archive, distroarchseries,
95+ PackagePublishingPocket.RELEASE,
96+ metadata_override={"project": "foo", "proposed": True})
97+ livefs.requestBuild(
98+ livefs.owner, livefs.distro_series.main_archive, distroarchseries,
99+ PackagePublishingPocket.RELEASE,
100+ metadata_override={"project": "foo"})
101+ self.assertRaises(
102+ LiveFSBuildAlreadyPending, livefs.requestBuild,
103+ livefs.owner, livefs.distro_series.main_archive, distroarchseries,
104+ PackagePublishingPocket.RELEASE,
105+ metadata_override={"project": "foo", "proposed": True})
106 # Changing the status of the old build allows a new build.
107 old_build.updateStatus(BuildStatus.BUILDING)
108 old_build.updateStatus(BuildStatus.FULLYBUILT)

Subscribers

People subscribed via source and target branches

to status/vote changes: