Merge lp:~cjwatson/launchpad/snap-only-available-processors into lp:launchpad

Proposed by Colin Watson
Status: Merged
Merged at revision: 18873
Proposed branch: lp:~cjwatson/launchpad/snap-only-available-processors
Merge into: lp:launchpad
Diff against target: 94 lines (+28/-13)
2 files modified
lib/lp/snappy/model/snap.py (+2/-4)
lib/lp/snappy/tests/test_snap.py (+26/-9)
To merge this branch: bzr merge lp:~cjwatson/launchpad/snap-only-available-processors
Reviewer Review Type Date Requested Status
William Grant code Approve
Review via email: mp+362724@code.launchpad.net

Commit message

Restrict the default for processors in SnapSet.new to those listed by Snap.available_processors.

Description of the change

This doesn't matter on production because the set of build_by_default processors is very conservative, but it's a little less strange and makes some tests less conceptually confusing.

To post a comment you must log in.
Revision history for this message
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/snap.py'
2--- lib/lp/snappy/model/snap.py 2018-11-07 14:45:31 +0000
3+++ lib/lp/snappy/model/snap.py 2019-02-05 11:29:12 +0000
4@@ -1,4 +1,4 @@
5-# Copyright 2015-2018 Canonical Ltd. This software is licensed under the
6+# Copyright 2015-2019 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@@ -54,7 +54,6 @@
11 from lp.app.interfaces.security import IAuthorization
12 from lp.buildmaster.enums import BuildStatus
13 from lp.buildmaster.interfaces.buildqueue import IBuildQueueSet
14-from lp.buildmaster.interfaces.processor import IProcessorSet
15 from lp.buildmaster.model.buildfarmjob import BuildFarmJob
16 from lp.buildmaster.model.buildqueue import BuildQueue
17 from lp.buildmaster.model.processor import Processor
18@@ -964,8 +963,7 @@
19
20 if processors is None:
21 processors = [
22- p for p in getUtility(IProcessorSet).getAll()
23- if p.build_by_default]
24+ p for p in snap.available_processors if p.build_by_default]
25 snap.setProcessors(processors)
26
27 return snap
28
29=== modified file 'lib/lp/snappy/tests/test_snap.py'
30--- lib/lp/snappy/tests/test_snap.py 2019-01-25 11:47:20 +0000
31+++ lib/lp/snappy/tests/test_snap.py 2019-02-05 11:29:12 +0000
32@@ -1,4 +1,4 @@
33-# Copyright 2015-2018 Canonical Ltd. This software is licensed under the
34+# Copyright 2015-2019 Canonical Ltd. This software is licensed under the
35 # GNU Affero General Public License version 3 (see the file LICENSE).
36
37 """Test snap packages."""
38@@ -1912,15 +1912,22 @@
39 name="arm", restricted=True, build_by_default=False)
40
41 def test_new_default_processors(self):
42- # SnapSet.new creates a SnapArch for each Processor with
43+ # SnapSet.new creates a SnapArch for each available Processor with
44 # build_by_default set.
45- self.factory.makeProcessor(name="default", build_by_default=True)
46- self.factory.makeProcessor(name="nondefault", build_by_default=False)
47+ new_procs = [
48+ self.factory.makeProcessor(name="default", build_by_default=True),
49+ self.factory.makeProcessor(
50+ name="nondefault", build_by_default=False),
51+ ]
52 owner = self.factory.makePerson()
53+ distroseries = self.factory.makeDistroSeries()
54+ for processor in self.unrestricted_procs + [self.arm] + new_procs:
55+ self.factory.makeDistroArchSeries(
56+ distroseries=distroseries, architecturetag=processor.name,
57+ processor=processor)
58 snap = getUtility(ISnapSet).new(
59- registrant=owner, owner=owner,
60- distro_series=self.factory.makeDistroSeries(), name="snap",
61- branch=self.factory.makeAnyBranch())
62+ registrant=owner, owner=owner, distro_series=distroseries,
63+ name="snap", branch=self.factory.makeAnyBranch())
64 self.assertContentEqual(
65 ["386", "amd64", "hppa", "default"],
66 [processor.name for processor in snap.processors])
67@@ -2545,7 +2552,12 @@
68 ppa_admin = self.factory.makePerson(member_of=[ppa_admin_team])
69 self.factory.makeProcessor(
70 "arm", "ARM", "ARM", restricted=True, build_by_default=False)
71- snap = self.makeSnap()
72+ distroseries = self.factory.makeDistroSeries()
73+ for processor in getUtility(IProcessorSet).getAll():
74+ self.factory.makeDistroArchSeries(
75+ distroseries=distroseries, architecturetag=processor.name,
76+ processor=processor)
77+ snap = self.makeSnap(distroseries=distroseries)
78 self.assertProcessors(ppa_admin, snap, ["386", "hppa", "amd64"])
79
80 response = self.setProcessors(ppa_admin, snap, ["386", "arm"])
81@@ -2565,7 +2577,12 @@
82
83 def test_setProcessors_owner(self):
84 """The snap owner can enable/disable unrestricted processors."""
85- snap = self.makeSnap()
86+ distroseries = self.factory.makeDistroSeries()
87+ for processor in getUtility(IProcessorSet).getAll():
88+ self.factory.makeDistroArchSeries(
89+ distroseries=distroseries, architecturetag=processor.name,
90+ processor=processor)
91+ snap = self.makeSnap(distroseries=distroseries)
92 self.assertProcessors(self.person, snap, ["386", "hppa", "amd64"])
93
94 response = self.setProcessors(self.person, snap, ["386"])