Merge lp:~cjwatson/launchpad/composeBuildRequest-deferred into lp:launchpad

Proposed by Colin Watson
Status: Merged
Merged at revision: 18379
Proposed branch: lp:~cjwatson/launchpad/composeBuildRequest-deferred
Merge into: lp:launchpad
Prerequisite: lp:~cjwatson/launchpad/archive-dependencies-unittest
Diff against target: 804 lines (+151/-107)
9 files modified
lib/lp/code/model/recipebuilder.py (+8/-5)
lib/lp/code/model/tests/test_recipebuilder.py (+44/-23)
lib/lp/snappy/model/snapbuildbehaviour.py (+2/-2)
lib/lp/snappy/tests/test_snapbuildbehaviour.py (+4/-4)
lib/lp/soyuz/model/binarypackagebuildbehaviour.py (+12/-8)
lib/lp/soyuz/model/livefsbuildbehaviour.py (+10/-8)
lib/lp/soyuz/tests/test_archive.py (+9/-3)
lib/lp/soyuz/tests/test_binarypackagebuildbehaviour.py (+38/-45)
lib/lp/soyuz/tests/test_livefsbuildbehaviour.py (+24/-9)
To merge this branch: bzr merge lp:~cjwatson/launchpad/composeBuildRequest-deferred
Reviewer Review Type Date Requested Status
William Grant code Approve
Review via email: mp+323401@code.launchpad.net

Commit message

Prepare for get_sources_list_for_building returning a Deferred.

Description of the change

get_sources_list_for_building will soon need to return a Deferred so that it can asynchronously fetch archive signing keys from the keyserver.

composeBuildRequest and friends already returned a Deferred in the SnapBuildBehaviour case, so this mainly just extends that to all build types.

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/code/model/recipebuilder.py'
2--- lib/lp/code/model/recipebuilder.py 2016-04-04 12:34:35 +0000
3+++ lib/lp/code/model/recipebuilder.py 2017-04-28 17:42:31 +0000
4@@ -1,4 +1,4 @@
5-# Copyright 2010-2016 Canonical Ltd. This software is licensed under the
6+# Copyright 2010-2017 Canonical Ltd. This software is licensed under the
7 # GNU Affero General Public License version 3 (see the file LICENSE).
8
9 """Code to build recipes on the buildfarm."""
10@@ -8,6 +8,7 @@
11 'RecipeBuildBehaviour',
12 ]
13
14+from twisted.internet import defer
15 from zope.component import adapter
16 from zope.interface import implementer
17 from zope.security.proxy import removeSecurityProxy
18@@ -40,6 +41,7 @@
19 # in this list.
20 ALLOWED_STATUS_NOTIFICATIONS = ['PACKAGEFAIL', 'DEPFAIL', 'CHROOTFAIL']
21
22+ @defer.inlineCallbacks
23 def _extraBuildArgs(self, distroarchseries, logger=None):
24 """
25 Return the extra arguments required by the slave for the given build.
26@@ -65,7 +67,7 @@
27 args["ogrecomponent"] = get_primary_current_component(
28 self.build.archive, self.build.distroseries,
29 None).name
30- args['archives'] = get_sources_list_for_building(
31+ args['archives'] = yield get_sources_list_for_building(
32 self.build, distroarchseries, None,
33 tools_source=config.builddmaster.bzr_builder_sources_list,
34 logger=logger)
35@@ -73,8 +75,9 @@
36 args['distroseries_name'] = self.build.distroseries.name
37 if self.build.recipe.base_git_repository is not None:
38 args['git'] = True
39- return args
40+ defer.returnValue(args)
41
42+ @defer.inlineCallbacks
43 def composeBuildRequest(self, logger):
44 das = self.build.distroseries.getDistroArchSeriesByProcessor(
45 self._builder.processor)
46@@ -83,8 +86,8 @@
47 "Unable to find distroarchseries for %s in %s" %
48 (self._builder.processor.name,
49 self.build.distroseries.displayname))
50- args = self._extraBuildArgs(das, logger=logger)
51- return ("sourcepackagerecipe", das, {}, args)
52+ args = yield self._extraBuildArgs(das, logger=logger)
53+ defer.returnValue(("sourcepackagerecipe", das, {}, args))
54
55 def verifyBuildRequest(self, logger):
56 """Assert some pre-build checks.
57
58=== modified file 'lib/lp/code/model/tests/test_recipebuilder.py'
59--- lib/lp/code/model/tests/test_recipebuilder.py 2016-10-14 16:16:18 +0000
60+++ lib/lp/code/model/tests/test_recipebuilder.py 2017-04-28 17:42:31 +0000
61@@ -1,4 +1,4 @@
62-# Copyright 2010-2016 Canonical Ltd. This software is licensed under the
63+# Copyright 2010-2017 Canonical Ltd. This software is licensed under the
64 # GNU Affero General Public License version 3 (see the file LICENSE).
65
66 """Test RecipeBuildBehaviour."""
67@@ -8,7 +8,9 @@
68 import shutil
69 import tempfile
70
71+from testtools.deferredruntest import AsynchronousDeferredRunTest
72 import transaction
73+from twisted.internet import defer
74 from twisted.trial.unittest import TestCase as TrialTestCase
75 from zope.component import getUtility
76 from zope.security.proxy import removeSecurityProxy
77@@ -49,7 +51,7 @@
78 from lp.testing.mail_helpers import pop_notifications
79
80
81-class TestRecipeBuilder(TestCaseWithFactory):
82+class TestRecipeBuilderBase(TestCaseWithFactory):
83
84 layer = LaunchpadZopelessLayer
85
86@@ -88,6 +90,9 @@
87 job = IBuildFarmJobBehaviour(spb)
88 return job
89
90+
91+class TestRecipeBuilder(TestRecipeBuilderBase):
92+
93 def test_providesInterface(self):
94 # RecipeBuildBehaviour provides IBuildFarmJobBehaviour.
95 recipe_builder = RecipeBuildBehaviour(None)
96@@ -130,22 +135,34 @@
97 AssertionError, job.verifyBuildRequest, BufferLogger())
98 self.assertIn('invalid pocket due to the series status of', str(e))
99
100+ def test_getByID(self):
101+ job = self.makeJob()
102+ transaction.commit()
103+ self.assertEqual(
104+ job.build, SourcePackageRecipeBuild.getByID(job.build.id))
105+
106+
107+class TestAsyncRecipeBuilder(TestRecipeBuilderBase):
108+
109+ run_tests_with = AsynchronousDeferredRunTest.make_factory(timeout=30)
110+
111 def _setBuilderConfig(self):
112 """Setup a temporary builder config."""
113 self.pushConfig(
114 "builddmaster",
115 bzr_builder_sources_list="deb http://foo %(series)s main")
116
117+ @defer.inlineCallbacks
118 def test_extraBuildArgs(self):
119 # _extraBuildArgs will return a sane set of additional arguments
120 self._setBuilderConfig()
121 job = self.makeJob()
122 distroarchseries = job.build.distroseries.architectures[0]
123- expected_archives = get_sources_list_for_building(
124+ expected_archives = yield get_sources_list_for_building(
125 job.build, distroarchseries, None)
126 expected_archives.insert(
127 0, "deb http://foo %s main" % job.build.distroseries.name)
128- args = job._extraBuildArgs(distroarchseries)
129+ args = yield job._extraBuildArgs(distroarchseries)
130 self.assertEqual({
131 'archive_private': False,
132 'arch_tag': 'i386',
133@@ -161,6 +178,7 @@
134 'distroseries_name': job.build.distroseries.name,
135 }, args)
136
137+ @defer.inlineCallbacks
138 def test_extraBuildArgs_private_archive(self):
139 # If the build archive is private, the archive_private flag is
140 # True. This tells launchpad-buildd to redact credentials from
141@@ -169,10 +187,11 @@
142 archive = self.factory.makeArchive(private=True)
143 job = self.makeJob(archive=archive)
144 distroarchseries = job.build.distroseries.architectures[0]
145- extra_args = job._extraBuildArgs(distroarchseries)
146+ extra_args = yield job._extraBuildArgs(distroarchseries)
147 self.assertEqual(
148 True, extra_args['archive_private'])
149
150+ @defer.inlineCallbacks
151 def test_extraBuildArgs_team_owner_no_email(self):
152 # If the owner of the recipe is a team without a preferred email, the
153 # registrant is used.
154@@ -185,11 +204,12 @@
155
156 job = self.makeJob(recipe_registrant, recipe_owner)
157 distroarchseries = job.build.distroseries.architectures[0]
158- extra_args = job._extraBuildArgs(distroarchseries)
159+ extra_args = yield job._extraBuildArgs(distroarchseries)
160 self.assertEqual(
161 "Launchpad Package Builder", extra_args['author_name'])
162 self.assertEqual("noreply@launchpad.net", extra_args['author_email'])
163
164+ @defer.inlineCallbacks
165 def test_extraBuildArgs_team_owner_with_email(self):
166 # If the owner of the recipe is a team that has an email set, we use
167 # that.
168@@ -201,10 +221,11 @@
169
170 job = self.makeJob(recipe_registrant, recipe_owner)
171 distroarchseries = job.build.distroseries.architectures[0]
172- extra_args = job._extraBuildArgs(distroarchseries)
173+ extra_args = yield job._extraBuildArgs(distroarchseries)
174 self.assertEqual("Vikings", extra_args['author_name'])
175 self.assertEqual("everyone@vikings.r.us", extra_args['author_email'])
176
177+ @defer.inlineCallbacks
178 def test_extraBuildArgs_owner_deactivated(self):
179 # If the owner is deactivated, they have no preferred email.
180 self._setBuilderConfig()
181@@ -213,11 +234,12 @@
182 owner.deactivate(comment='deactivating')
183 job = self.makeJob(owner)
184 distroarchseries = job.build.distroseries.architectures[0]
185- extra_args = job._extraBuildArgs(distroarchseries)
186+ extra_args = yield job._extraBuildArgs(distroarchseries)
187 self.assertEqual(
188 "Launchpad Package Builder", extra_args['author_name'])
189 self.assertEqual("noreply@launchpad.net", extra_args['author_email'])
190
191+ @defer.inlineCallbacks
192 def test_extraBuildArgs_withBadConfigForBzrBuilderPPA(self):
193 # Ensure _extraBuildArgs doesn't blow up with a badly formatted
194 # bzr_builder_sources_list in the config.
195@@ -227,9 +249,10 @@
196 # (note the missing 's' in %(series)
197 job = self.makeJob()
198 distroarchseries = job.build.distroseries.architectures[0]
199- expected_archives = get_sources_list_for_building(
200+ expected_archives = yield get_sources_list_for_building(
201 job.build, distroarchseries, None)
202 logger = BufferLogger()
203+ extra_args = yield job._extraBuildArgs(distroarchseries, logger)
204 self.assertEqual({
205 'archive_private': False,
206 'arch_tag': 'i386',
207@@ -243,26 +266,29 @@
208 'lp://dev/~joe/someapp/pkg\n',
209 'archives': expected_archives,
210 'distroseries_name': job.build.distroseries.name,
211- }, job._extraBuildArgs(distroarchseries, logger))
212+ }, extra_args)
213 self.assertIn(
214 "Exception processing build tools sources.list entry:",
215 logger.getLogBuffer())
216
217+ @defer.inlineCallbacks
218 def test_extraBuildArgs_withNoBZrBuilderConfigSet(self):
219 # Ensure _extraBuildArgs doesn't blow up when
220 # bzr_builder_sources_list isn't set.
221 job = self.makeJob()
222 distroarchseries = job.build.distroseries.architectures[0]
223- args = job._extraBuildArgs(distroarchseries)
224- expected_archives = get_sources_list_for_building(
225+ args = yield job._extraBuildArgs(distroarchseries)
226+ expected_archives = yield get_sources_list_for_building(
227 job.build, distroarchseries, None)
228 self.assertEqual(args["archives"], expected_archives)
229
230+ @defer.inlineCallbacks
231 def test_extraBuildArgs_git(self):
232 job = self.makeJob(git=True)
233 distroarchseries = job.build.distroseries.architectures[0]
234- expected_archives = get_sources_list_for_building(
235+ expected_archives = yield get_sources_list_for_building(
236 job.build, distroarchseries, None)
237+ extra_args = yield job._extraBuildArgs(distroarchseries)
238 self.assertEqual({
239 'archive_private': False,
240 'arch_tag': 'i386',
241@@ -278,14 +304,9 @@
242 'archives': expected_archives,
243 'distroseries_name': job.build.distroseries.name,
244 'git': True,
245- }, job._extraBuildArgs(distroarchseries))
246-
247- def test_getByID(self):
248- job = self.makeJob()
249- transaction.commit()
250- self.assertEquals(
251- job.build, SourcePackageRecipeBuild.getByID(job.build.id))
252-
253+ }, extra_args)
254+
255+ @defer.inlineCallbacks
256 def test_composeBuildRequest(self):
257 job = self.makeJob()
258 test_publisher = SoyuzTestPublisher()
259@@ -295,9 +316,9 @@
260 builder.processor = das.processor
261 job.setBuilder(builder, None)
262 build_request = yield job.composeBuildRequest(None)
263+ extra_args = yield job._extraBuildArgs(das)
264 self.assertEqual(
265- ('sourcepackagerecipe', das, {}, job._extraBuildArgs(das)),
266- build_request)
267+ ('sourcepackagerecipe', das, {}, extra_args), build_request)
268
269
270 class TestBuildNotifications(TrialTestCase):
271
272=== modified file 'lib/lp/snappy/model/snapbuildbehaviour.py'
273--- lib/lp/snappy/model/snapbuildbehaviour.py 2016-12-05 23:11:57 +0000
274+++ lib/lp/snappy/model/snapbuildbehaviour.py 2017-04-28 17:42:31 +0000
275@@ -1,4 +1,4 @@
276-# Copyright 2015-2016 Canonical Ltd. This software is licensed under the
277+# Copyright 2015-2017 Canonical Ltd. This software is licensed under the
278 # GNU Affero General Public License version 3 (see the file LICENSE).
279
280 """An `IBuildFarmJobBehaviour` for `SnapBuild`.
281@@ -99,7 +99,7 @@
282 args["arch_tag"] = build.distro_arch_series.architecturetag
283 # XXX cjwatson 2015-08-03: Allow tools_source to be overridden at
284 # some more fine-grained level.
285- args["archives"] = get_sources_list_for_building(
286+ args["archives"] = yield get_sources_list_for_building(
287 build, build.distro_arch_series, None,
288 tools_source=config.snappy.tools_source, logger=logger)
289 args["archive_private"] = build.archive.private
290
291=== modified file 'lib/lp/snappy/tests/test_snapbuildbehaviour.py'
292--- lib/lp/snappy/tests/test_snapbuildbehaviour.py 2017-01-27 12:44:41 +0000
293+++ lib/lp/snappy/tests/test_snapbuildbehaviour.py 2017-04-28 17:42:31 +0000
294@@ -168,7 +168,7 @@
295
296
297 class TestAsyncSnapBuildBehaviour(TestSnapBuildBehaviourBase):
298- run_tests_with = AsynchronousDeferredRunTest
299+ run_tests_with = AsynchronousDeferredRunTest.make_factory(timeout=30)
300
301 def setUp(self):
302 super(TestAsyncSnapBuildBehaviour, self).setUp()
303@@ -211,7 +211,7 @@
304 # job for a Bazaar branch.
305 branch = self.factory.makeBranch()
306 job = self.makeJob(branch=branch)
307- expected_archives = get_sources_list_for_building(
308+ expected_archives = yield get_sources_list_for_building(
309 job.build, job.build.distro_arch_series, None)
310 args = yield job._extraBuildArgs()
311 self.assertEqual({
312@@ -230,7 +230,7 @@
313 # job for a Git branch.
314 [ref] = self.factory.makeGitRefs()
315 job = self.makeJob(git_ref=ref)
316- expected_archives = get_sources_list_for_building(
317+ expected_archives = yield get_sources_list_for_building(
318 job.build, job.build.distro_arch_series, None)
319 args = yield job._extraBuildArgs()
320 self.assertEqual({
321@@ -252,7 +252,7 @@
322 ref = self.factory.makeGitRefRemote(
323 repository_url=url, path=u"refs/heads/master")
324 job = self.makeJob(git_ref=ref)
325- expected_archives = get_sources_list_for_building(
326+ expected_archives = yield get_sources_list_for_building(
327 job.build, job.build.distro_arch_series, None)
328 args = yield job._extraBuildArgs()
329 self.assertEqual({
330
331=== modified file 'lib/lp/soyuz/model/binarypackagebuildbehaviour.py'
332--- lib/lp/soyuz/model/binarypackagebuildbehaviour.py 2016-04-04 12:34:35 +0000
333+++ lib/lp/soyuz/model/binarypackagebuildbehaviour.py 2017-04-28 17:42:31 +0000
334@@ -1,4 +1,4 @@
335-# Copyright 2009-2016 Canonical Ltd. This software is licensed under the
336+# Copyright 2009-2017 Canonical Ltd. This software is licensed under the
337 # GNU Affero General Public License version 3 (see the file LICENSE).
338
339 """Builder behaviour for binary package builds."""
340@@ -9,6 +9,7 @@
341 'BinaryPackageBuildBehaviour',
342 ]
343
344+from twisted.internet import defer
345 from zope.interface import implementer
346
347 from lp.buildmaster.interfaces.builder import CannotBuild
348@@ -81,10 +82,12 @@
349 'password': self.build.archive.buildd_secret}
350 return filemap
351
352+ @defer.inlineCallbacks
353 def composeBuildRequest(self, logger):
354- return (
355- "binarypackage", self.build.distro_arch_series,
356- self.determineFilesToSend(), self._extraBuildArgs(self.build))
357+ args = yield self._extraBuildArgs(self.build, logger=logger)
358+ defer.returnValue(
359+ ("binarypackage", self.build.distro_arch_series,
360+ self.determineFilesToSend(), args))
361
362 def verifyBuildRequest(self, logger):
363 """Assert some pre-build checks.
364@@ -130,7 +133,8 @@
365 (build.title, build.id, build.pocket.name,
366 build.distro_series.name))
367
368- def _extraBuildArgs(self, build):
369+ @defer.inlineCallbacks
370+ def _extraBuildArgs(self, build, logger=None):
371 """
372 Return the extra arguments required by the slave for the given build.
373 """
374@@ -160,9 +164,9 @@
375 args["ogrecomponent"] = (
376 build.current_component.name)
377
378- args['archives'] = get_sources_list_for_building(
379- build, das, build.source_package_release.name)
380+ args['archives'] = yield get_sources_list_for_building(
381+ build, das, build.source_package_release.name, logger=logger)
382 args['archive_private'] = build.archive.private
383 args['build_debug_symbols'] = build.archive.build_debug_symbols
384
385- return args
386+ defer.returnValue(args)
387
388=== modified file 'lib/lp/soyuz/model/livefsbuildbehaviour.py'
389--- lib/lp/soyuz/model/livefsbuildbehaviour.py 2016-03-31 14:58:46 +0000
390+++ lib/lp/soyuz/model/livefsbuildbehaviour.py 2017-04-28 17:42:31 +0000
391@@ -1,4 +1,4 @@
392-# Copyright 2014 Canonical Ltd. This software is licensed under the
393+# Copyright 2014-2017 Canonical Ltd. This software is licensed under the
394 # GNU Affero General Public License version 3 (see the file LICENSE).
395
396 """An `IBuildFarmJobBehaviour` for `LiveFSBuild`.
397@@ -11,6 +11,7 @@
398 'LiveFSBuildBehaviour',
399 ]
400
401+from twisted.internet import defer
402 from zope.component import adapter
403 from zope.interface import implementer
404 from zope.security.proxy import removeSecurityProxy
405@@ -73,7 +74,8 @@
406 raise CannotBuild(
407 "Missing chroot for %s" % build.distro_arch_series.displayname)
408
409- def _extraBuildArgs(self):
410+ @defer.inlineCallbacks
411+ def _extraBuildArgs(self, logger=None):
412 """
413 Return the extra arguments required by the slave for the given build.
414 """
415@@ -88,15 +90,15 @@
416 args["pocket"] = build.pocket.name.lower()
417 args["arch_tag"] = build.distro_arch_series.architecturetag
418 args["datestamp"] = build.version
419- args["archives"] = get_sources_list_for_building(
420- build, build.distro_arch_series, None)
421+ args["archives"] = yield get_sources_list_for_building(
422+ build, build.distro_arch_series, None, logger=logger)
423 args["archive_private"] = build.archive.private
424- return args
425+ defer.returnValue(args)
426
427+ @defer.inlineCallbacks
428 def composeBuildRequest(self, logger):
429- return (
430- "livefs", self.build.distro_arch_series, {},
431- self._extraBuildArgs())
432+ args = yield self._extraBuildArgs(logger=logger)
433+ defer.returnValue(("livefs", self.build.distro_arch_series, {}, args))
434
435 def verifySuccessfulBuild(self):
436 """See `IBuildFarmJobBehaviour`."""
437
438=== modified file 'lib/lp/soyuz/tests/test_archive.py'
439--- lib/lp/soyuz/tests/test_archive.py 2017-04-28 17:42:31 +0000
440+++ lib/lp/soyuz/tests/test_archive.py 2017-04-28 17:42:31 +0000
441@@ -11,6 +11,7 @@
442 import doctest
443
444 from pytz import UTC
445+from testtools.deferredruntest import AsynchronousDeferredRunTest
446 from testtools.matchers import (
447 AllMatch,
448 DocTestMatches,
449@@ -21,6 +22,7 @@
450 )
451 from testtools.testcase import ExpectedException
452 import transaction
453+from twisted.internet import defer
454 from zope.component import getUtility
455 from zope.security.interfaces import Unauthorized
456 from zope.security.proxy import removeSecurityProxy
457@@ -1746,7 +1748,9 @@
458 class TestArchiveDependencies(TestCaseWithFactory):
459
460 layer = LaunchpadZopelessLayer
461+ run_tests_with = AsynchronousDeferredRunTest.make_factory(timeout=30)
462
463+ @defer.inlineCallbacks
464 def test_private_sources_list(self):
465 """Entries for private dependencies include credentials."""
466 p3a = self.factory.makeArchive(name='p3a', private=True)
467@@ -1760,7 +1764,7 @@
468 PackagePublishingPocket.RELEASE)
469 build = self.factory.makeBinaryPackageBuild(archive=p3a,
470 distroarchseries=bpph.distroarchseries)
471- sources_list = get_sources_list_for_building(
472+ sources_list = yield get_sources_list_for_building(
473 build, build.distro_arch_series,
474 build.source_package_release.name)
475 matches = MatchesRegex(
476@@ -1945,6 +1949,7 @@
477 class TestOverlays(TestCaseWithFactory):
478
479 layer = LaunchpadZopelessLayer
480+ run_tests_with = AsynchronousDeferredRunTest.make_factory(timeout=30)
481
482 def _createDep(self, test_publisher, derived_series, parent_series,
483 parent_distro, component_name=None, pocket=None,
484@@ -1978,6 +1983,7 @@
485 component=component)
486 return depseries, depdistro
487
488+ @defer.inlineCallbacks
489 def test_overlay_dependencies(self):
490 # sources.list is properly generated for a complex overlay structure.
491 # Pocket dependencies and component dependencies are taken into
492@@ -2012,8 +2018,8 @@
493 self._createDep(
494 test_publisher, series11, 'series12', 'depdistro4', 'multiverse',
495 PackagePublishingPocket.UPDATES)
496- sources_list = get_sources_list_for_building(build,
497- build.distro_arch_series, build.source_package_release.name)
498+ sources_list = yield get_sources_list_for_building(
499+ build, build.distro_arch_series, build.source_package_release.name)
500
501 self.assertThat(
502 "\n".join(sources_list),
503
504=== modified file 'lib/lp/soyuz/tests/test_binarypackagebuildbehaviour.py'
505--- lib/lp/soyuz/tests/test_binarypackagebuildbehaviour.py 2016-04-07 00:04:42 +0000
506+++ lib/lp/soyuz/tests/test_binarypackagebuildbehaviour.py 2017-04-28 17:42:31 +0000
507@@ -1,4 +1,4 @@
508-# Copyright 2010-2016 Canonical Ltd. This software is licensed under the
509+# Copyright 2010-2017 Canonical Ltd. This software is licensed under the
510 # GNU Affero General Public License version 3 (see the file LICENSE).
511
512 """Tests for BinaryPackageBuildBehaviour."""
513@@ -55,9 +55,6 @@
514 from lp.soyuz.adapters.archivedependencies import (
515 get_sources_list_for_building,
516 )
517-from lp.soyuz.model.binarypackagebuildbehaviour import (
518- BinaryPackageBuildBehaviour,
519- )
520 from lp.soyuz.enums import ArchivePurpose
521 from lp.testing import TestCaseWithFactory
522 from lp.testing.dbuser import switch_dbuser
523@@ -75,21 +72,22 @@
524 """
525
526 layer = LaunchpadZopelessLayer
527- run_tests_with = AsynchronousDeferredRunTest
528+ run_tests_with = AsynchronousDeferredRunTest.make_factory(timeout=30)
529
530 def setUp(self):
531 super(TestBinaryBuildPackageBehaviour, self).setUp()
532 switch_dbuser('testadmin')
533
534- def assertExpectedInteraction(self, ignored, call_log, builder, build,
535- chroot, archive, archive_purpose,
536- component=None, extra_uploads=None,
537- filemap_names=None):
538- expected = self.makeExpectedInteraction(
539+ @defer.inlineCallbacks
540+ def assertExpectedInteraction(self, call_log, builder, build, chroot,
541+ archive, archive_purpose, component=None,
542+ extra_uploads=None, filemap_names=None):
543+ expected = yield self.makeExpectedInteraction(
544 builder, build, chroot, archive, archive_purpose, component,
545 extra_uploads, filemap_names)
546 self.assertEqual(expected, call_log)
547
548+ @defer.inlineCallbacks
549 def makeExpectedInteraction(self, builder, build, chroot, archive,
550 archive_purpose, component=None,
551 extra_uploads=None, filemap_names=None):
552@@ -109,7 +107,7 @@
553 das = build.distro_arch_series
554 ds_name = das.distroseries.name
555 suite = ds_name + pocketsuffix[build.pocket]
556- archives = get_sources_list_for_building(
557+ archives = yield get_sources_list_for_building(
558 build, das, build.source_package_release.name)
559 arch_indep = das.isNominatedArchIndep
560 if component is None:
561@@ -138,8 +136,9 @@
562 ('build', build.build_cookie, 'binarypackage',
563 chroot.content.sha1, filemap_names, extra_args)]
564 result = upload_logs + build_log
565- return result
566+ defer.returnValue(result)
567
568+ @defer.inlineCallbacks
569 def test_non_virtual_ppa_dispatch(self):
570 # When the BinaryPackageBuildBehaviour dispatches PPA builds to
571 # non-virtual builders, it stores the chroot on the server and
572@@ -159,14 +158,14 @@
573 bq = build.queueBuild()
574 bq.markAsBuilding(builder)
575 interactor = BuilderInteractor()
576- d = interactor._startBuild(
577+ yield interactor._startBuild(
578 bq, vitals, builder, slave,
579 interactor.getBuildBehaviour(bq, builder, slave), BufferLogger())
580- d.addCallback(
581- self.assertExpectedInteraction, slave.call_log, builder, build,
582- lf, archive, ArchivePurpose.PRIMARY, 'universe')
583- return d
584+ yield self.assertExpectedInteraction(
585+ slave.call_log, builder, build, lf, archive,
586+ ArchivePurpose.PRIMARY, 'universe')
587
588+ @defer.inlineCallbacks
589 def test_non_virtual_ppa_dispatch_with_primary_ancestry(self):
590 # If there is a primary component override, it is honoured for
591 # non-virtual PPA builds too.
592@@ -188,14 +187,14 @@
593 bq = build.queueBuild()
594 bq.markAsBuilding(builder)
595 interactor = BuilderInteractor()
596- d = interactor._startBuild(
597+ yield interactor._startBuild(
598 bq, vitals, builder, slave,
599 interactor.getBuildBehaviour(bq, builder, slave), BufferLogger())
600- d.addCallback(
601- self.assertExpectedInteraction, slave.call_log, builder, build,
602- lf, archive, ArchivePurpose.PRIMARY, 'main')
603- return d
604+ yield self.assertExpectedInteraction(
605+ slave.call_log, builder, build, lf, archive,
606+ ArchivePurpose.PRIMARY, 'main')
607
608+ @defer.inlineCallbacks
609 def test_virtual_ppa_dispatch(self):
610 archive = self.factory.makeArchive(virtualized=True)
611 slave = OkSlave()
612@@ -211,14 +210,13 @@
613 bq = build.queueBuild()
614 bq.markAsBuilding(builder)
615 interactor = BuilderInteractor()
616- d = interactor._startBuild(
617+ yield interactor._startBuild(
618 bq, vitals, builder, slave,
619 interactor.getBuildBehaviour(bq, builder, slave), BufferLogger())
620- d.addCallback(
621- self.assertExpectedInteraction, slave.call_log, builder, build,
622- lf, archive, ArchivePurpose.PPA)
623- return d
624+ yield self.assertExpectedInteraction(
625+ slave.call_log, builder, build, lf, archive, ArchivePurpose.PPA)
626
627+ @defer.inlineCallbacks
628 def test_private_source_dispatch(self):
629 archive = self.factory.makeArchive(private=True)
630 slave = OkSlave()
631@@ -243,16 +241,15 @@
632 bq = build.queueBuild()
633 bq.markAsBuilding(builder)
634 interactor = BuilderInteractor()
635- d = interactor._startBuild(
636+ yield interactor._startBuild(
637 bq, vitals, builder, slave,
638 interactor.getBuildBehaviour(bq, builder, slave), BufferLogger())
639- d.addCallback(
640- self.assertExpectedInteraction, slave.call_log, builder, build,
641- lf, archive, ArchivePurpose.PPA,
642+ yield self.assertExpectedInteraction(
643+ slave.call_log, builder, build, lf, archive, ArchivePurpose.PPA,
644 extra_uploads=[(sprf_url, 'buildd', u'sekrit')],
645 filemap_names=[sprf.libraryfile.filename])
646- return d
647
648+ @defer.inlineCallbacks
649 def test_partner_dispatch_no_publishing_history(self):
650 archive = self.factory.makeArchive(
651 virtualized=False, purpose=ArchivePurpose.PARTNER)
652@@ -268,13 +265,12 @@
653 bq = build.queueBuild()
654 bq.markAsBuilding(builder)
655 interactor = BuilderInteractor()
656- d = interactor._startBuild(
657+ yield interactor._startBuild(
658 bq, vitals, builder, slave,
659 interactor.getBuildBehaviour(bq, builder, slave), BufferLogger())
660- d.addCallback(
661- self.assertExpectedInteraction, slave.call_log, builder, build,
662- lf, archive, ArchivePurpose.PARTNER)
663- return d
664+ yield self.assertExpectedInteraction(
665+ slave.call_log, builder, build, lf, archive,
666+ ArchivePurpose.PARTNER)
667
668 def test_dont_dispatch_release_builds(self):
669 archive = self.factory.makeArchive(purpose=ArchivePurpose.PRIMARY)
670@@ -318,18 +314,15 @@
671 'Soyuz is not yet capable of building SECURITY uploads.',
672 str(e))
673
674+ @defer.inlineCallbacks
675 def test_arch_indep(self):
676 # BinaryPackageBuild.arch_indep is passed through to the slave.
677 build = self.factory.makeBinaryPackageBuild(arch_indep=False)
678- self.assertIs(
679- False,
680- BinaryPackageBuildBehaviour(build)._extraBuildArgs(build)[
681- 'arch_indep'])
682+ extra_args = yield IBuildFarmJobBehaviour(build)._extraBuildArgs(build)
683+ self.assertFalse(extra_args['arch_indep'])
684 build = self.factory.makeBinaryPackageBuild(arch_indep=True)
685- self.assertIs(
686- True,
687- BinaryPackageBuildBehaviour(build)._extraBuildArgs(build)[
688- 'arch_indep'])
689+ extra_args = yield IBuildFarmJobBehaviour(build)._extraBuildArgs(build)
690+ self.assertTrue(extra_args['arch_indep'])
691
692 def test_verifyBuildRequest(self):
693 # Don't allow a virtual build on a non-virtual builder.
694
695=== modified file 'lib/lp/soyuz/tests/test_livefsbuildbehaviour.py'
696--- lib/lp/soyuz/tests/test_livefsbuildbehaviour.py 2016-03-31 14:07:33 +0000
697+++ lib/lp/soyuz/tests/test_livefsbuildbehaviour.py 2017-04-28 17:42:31 +0000
698@@ -1,4 +1,4 @@
699-# Copyright 2014-2016 Canonical Ltd. This software is licensed under the
700+# Copyright 2014-2017 Canonical Ltd. This software is licensed under the
701 # GNU Affero General Public License version 3 (see the file LICENSE).
702
703 """Test live filesystem build behaviour."""
704@@ -9,7 +9,9 @@
705
706 import fixtures
707 import pytz
708+from testtools.deferredruntest import AsynchronousDeferredRunTest
709 import transaction
710+from twisted.internet import defer
711 from twisted.trial.unittest import TestCase as TrialTestCase
712 from zope.component import getUtility
713 from zope.security.proxy import Proxy
714@@ -46,12 +48,12 @@
715 from lp.testing.layers import LaunchpadZopelessLayer
716
717
718-class TestLiveFSBuildBehaviour(TestCaseWithFactory):
719+class TestLiveFSBuildBehaviourBase(TestCaseWithFactory):
720
721 layer = LaunchpadZopelessLayer
722
723 def setUp(self):
724- super(TestLiveFSBuildBehaviour, self).setUp()
725+ super(TestLiveFSBuildBehaviourBase, self).setUp()
726 self.useFixture(FeatureFixture({LIVEFS_FEATURE_FLAG: u"on"}))
727
728 def makeJob(self, pocket=PackagePublishingPocket.RELEASE, **kwargs):
729@@ -68,6 +70,9 @@
730 name=u"test-livefs", **kwargs)
731 return IBuildFarmJobBehaviour(build)
732
733+
734+class TestLiveFSBuildBehaviour(TestLiveFSBuildBehaviourBase):
735+
736 def test_provides_interface(self):
737 # LiveFSBuildBehaviour provides IBuildFarmJobBehaviour.
738 job = LiveFSBuildBehaviour(None)
739@@ -157,13 +162,20 @@
740 e = self.assertRaises(CannotBuild, job.verifyBuildRequest, logger)
741 self.assertIn("Missing chroot", str(e))
742
743+
744+class TestAsyncLiveFSBuildBehaviour(TestLiveFSBuildBehaviourBase):
745+
746+ run_tests_with = AsynchronousDeferredRunTest.make_factory(timeout=30)
747+
748+ @defer.inlineCallbacks
749 def test_extraBuildArgs(self):
750 # _extraBuildArgs returns a reasonable set of additional arguments.
751 job = self.makeJob(
752 date_created=datetime(2014, 4, 25, 10, 38, 0, tzinfo=pytz.UTC),
753 metadata={"project": "distro", "subproject": "special"})
754- expected_archives = get_sources_list_for_building(
755+ expected_archives = yield get_sources_list_for_building(
756 job.build, job.build.distro_arch_series, None)
757+ extra_args = yield job._extraBuildArgs()
758 self.assertEqual({
759 "archive_private": False,
760 "archives": expected_archives,
761@@ -173,35 +185,38 @@
762 "project": "distro",
763 "subproject": "special",
764 "series": "unstable",
765- }, job._extraBuildArgs())
766+ }, extra_args)
767
768+ @defer.inlineCallbacks
769 def test_extraBuildArgs_proposed(self):
770 # _extraBuildArgs returns appropriate arguments if asked to build a
771 # job for -proposed.
772 job = self.makeJob(
773 pocket=PackagePublishingPocket.PROPOSED,
774 metadata={"project": "distro"})
775- args = job._extraBuildArgs()
776+ args = yield job._extraBuildArgs()
777 self.assertEqual("unstable", args["series"])
778 self.assertEqual("proposed", args["pocket"])
779
780+ @defer.inlineCallbacks
781 def test_extraBuildArgs_no_security_proxy(self):
782 # _extraBuildArgs returns an object without security wrapping, even
783 # if values in the metadata are (say) lists and hence get proxied by
784 # Zope.
785 job = self.makeJob(metadata={"lb_args": ["--option=value"]})
786- args = job._extraBuildArgs()
787+ args = yield job._extraBuildArgs()
788 self.assertEqual(["--option=value"], args["lb_args"])
789 self.assertIsNot(Proxy, type(args["lb_args"]))
790
791+ @defer.inlineCallbacks
792 def test_composeBuildRequest(self):
793 job = self.makeJob()
794 lfa = self.factory.makeLibraryFileAlias(db_only=True)
795 job.build.distro_arch_series.addOrUpdateChroot(lfa)
796 build_request = yield job.composeBuildRequest(None)
797+ args = yield job._extraBuildArgs()
798 self.assertEqual(
799- ('livefs', job.build.distro_arch_series, {},
800- job._extraBuildArgs()), build_request)
801+ ('livefs', job.build.distro_arch_series, {}, args), build_request)
802
803
804 class MakeLiveFSBuildMixin: