~launchpad-pqm/launchpad/devel

3147.5.55 by Celso Providelo
applying review comments, r=flacoste
1
= BuildQueue =
2
3
BuildQueue class represents the run-time-records of builds being
4
processed.
5
6
See buildd-queuebuilder.txt for more information about the BuildQueue
7
initialisation.
8
9
BuildQueue should provide all the information needed for dispatching
10
and collecting build results.
11
12
As soon as a build job is processed succesfully (dispatched &
13
collected) the BuildQueue record representing it is removed.
14
5152.5.12 by Celso Providelo
Workarounding race-condition when running slave-scanner and queue-builder in parallel, also improving buildqueue tests and lookup main lookup method.
15
    >>> from canonical.launchpad.webapp.testing import verifyObject
7675.509.139 by William Grant
Move (I)BuildQueue(Set) to lp.buildmaster.
16
    >>> from lp.buildmaster.interfaces.buildqueue import (
17
    ...     IBuildQueue, IBuildQueueSet)
3500.3.54 by Celso Providelo
gluing unrelated review comments about BuildQueue documentation, r=flacoste
18
19
Get an instance of Builder from the current sampledata using the
20
IBuildQueueSet zope utility. The zope utility itself will be
21
documented later on this document, we are only using it to retrive an
22
IBuildQueue record with the security proxies in place:
23
5152.5.12 by Celso Providelo
Workarounding race-condition when running slave-scanner and queue-builder in parallel, also improving buildqueue tests and lookup main lookup method.
24
    >>> bq = getUtility(IBuildQueueSet).get(1)
3500.3.54 by Celso Providelo
gluing unrelated review comments about BuildQueue documentation, r=flacoste
25
26
Instances returned by IBuildQueueSet provides the IBuildQueue interface:
3147.5.55 by Celso Providelo
applying review comments, r=flacoste
27
5152.5.12 by Celso Providelo
Workarounding race-condition when running slave-scanner and queue-builder in parallel, also improving buildqueue tests and lookup main lookup method.
28
    >>> verifyObject(IBuildQueue, bq)
29
    True
3147.5.55 by Celso Providelo
applying review comments, r=flacoste
30
3500.3.54 by Celso Providelo
gluing unrelated review comments about BuildQueue documentation, r=flacoste
31
The IBuild record related to this job is provided by the 'build'
32
attribute:
3147.5.55 by Celso Providelo
applying review comments, r=flacoste
33
10667.2.2 by Michael Nelson
Mass renaming of imports and references to IBuild/Build/IBuildSet
34
    >>> from lp.soyuz.interfaces.binarypackagebuild import IBinaryPackageBuildSet
35
    >>> build = getUtility(IBinaryPackageBuildSet).getByQueueEntry(bq)
7675.391.22 by Muharem Hrnjadovic
Fixed more breakage.
36
    >>> build.id
5152.5.12 by Celso Providelo
Workarounding race-condition when running slave-scanner and queue-builder in parallel, also improving buildqueue tests and lookup main lookup method.
37
    8
7675.687.143 by Michael Nelson
buildmaster.tests
38
    >>> build.status.name
5152.5.12 by Celso Providelo
Workarounding race-condition when running slave-scanner and queue-builder in parallel, also improving buildqueue tests and lookup main lookup method.
39
    'BUILDING'
3147.5.55 by Celso Providelo
applying review comments, r=flacoste
40
3500.3.54 by Celso Providelo
gluing unrelated review comments about BuildQueue documentation, r=flacoste
41
The static timestamps, representing when the record was initialised
42
(inserted) and when the job was dispatched are provided as datetime
43
instances:
3147.5.55 by Celso Providelo
applying review comments, r=flacoste
44
7675.391.22 by Muharem Hrnjadovic
Fixed more breakage.
45
    >>> bq.job.date_created
5821.6.34 by Celso Providelo
using get_transaction_timestamp where where it is possible.
46
    datetime.datetime(2005, 6, 15, 9, 14, 12, 820778, tzinfo=<UTC>)
3147.5.55 by Celso Providelo
applying review comments, r=flacoste
47
7675.390.5 by Muharem Hrnjadovic
Review changes, round 1.
48
    >>> bq.date_started
5821.6.34 by Celso Providelo
using get_transaction_timestamp where where it is possible.
49
    datetime.datetime(2005, 6, 15, 9, 20, 12, 820778, tzinfo=<UTC>)
3147.5.55 by Celso Providelo
applying review comments, r=flacoste
50
51
Check Builder foreign key, which indicated which builder 'is processing'
52
the job in question:
53
3500.3.54 by Celso Providelo
gluing unrelated review comments about BuildQueue documentation, r=flacoste
54
The 'builder' attribute provides the IBuilder instance of the builder
55
currently processing this job:
56
5152.5.12 by Celso Providelo
Workarounding race-condition when running slave-scanner and queue-builder in parallel, also improving buildqueue tests and lookup main lookup method.
57
    >>> bq.builder.name
58
    u'bob'
3147.5.55 by Celso Providelo
applying review comments, r=flacoste
59
60
'logtail' is a text field which stores up to 1 Kbyte of the last
61
logged actions during the build process, it is updated according the
62
frequency set in buildd-slavescanner, normally 10 seconds, see
63
buildd-slavescanner.txt for further information:
64
5152.5.12 by Celso Providelo
Workarounding race-condition when running slave-scanner and queue-builder in parallel, also improving buildqueue tests and lookup main lookup method.
65
    >>> bq.logtail
66
    u'Dummy sampledata entry, not processing'
3147.5.55 by Celso Providelo
applying review comments, r=flacoste
67
68
'lastscore' is the heuristic index generated by queuebuilder to order
69
the dispatching process, see more information in
70
buildd-queuebuilder.txt:
71
5152.5.12 by Celso Providelo
Workarounding race-condition when running slave-scanner and queue-builder in parallel, also improving buildqueue tests and lookup main lookup method.
72
    >>> bq.lastscore
73
    1
3147.5.55 by Celso Providelo
applying review comments, r=flacoste
74
75
'manual' is a boolean, which is meant to suppress the auto-scoring
76
procedure, i.e., when it is set the job do not get re-scored, it is
77
used to manually reorder jobs via the web UI:
78
5152.5.12 by Celso Providelo
Workarounding race-condition when running slave-scanner and queue-builder in parallel, also improving buildqueue tests and lookup main lookup method.
79
    >>> bq.manual
80
    False
3147.5.55 by Celso Providelo
applying review comments, r=flacoste
81
3691.454.27 by Robert Collins
Delegate log file naming in the build slave scanner to the BuildQueue
82
BuildQueue provides the name for the logfile resulting from the build:
83
5152.5.12 by Celso Providelo
Workarounding race-condition when running slave-scanner and queue-builder in parallel, also improving buildqueue tests and lookup main lookup method.
84
    >>> bq.getLogFileName()
85
    u'buildlog_ubuntu-hoary-i386.mozilla-firefox_0.9_BUILDING.txt'
86
3147.5.55 by Celso Providelo
applying review comments, r=flacoste
87
BuildQueue provides a method to handle "manual scoring" procedure
88
properly, in order to retain the manually set score we need to
89
set 'manual' attribute atomically. For this we use manualScore:
90
5152.5.12 by Celso Providelo
Workarounding race-condition when running slave-scanner and queue-builder in parallel, also improving buildqueue tests and lookup main lookup method.
91
    >>> pending_bq = getUtility(IBuildQueueSet).get(2)
92
93
    >>> pending_bq.manual, pending_bq.lastscore
94
    (False, 10)
95
    >>> pending_bq.manualScore(1000)
96
97
    >>> pending_bq.manual, pending_bq.lastscore
98
    (True, 1000)
3147.5.55 by Celso Providelo
applying review comments, r=flacoste
99
100
7675.420.16 by Michael Nelson
Refactored to adapt on the job rather than the job type and added tests.
101
The BuildQueue item is responsible for providing the required build behavior
102
for the item.
103
7675.420.18 by Michael Nelson
Tidying up some stray comments.
104
    >>> from zope.security.proxy import isinstance
105
    >>> from lp.soyuz.model.binarypackagebuildbehavior import (
106
    ...     BinaryPackageBuildBehavior)
107
    >>> isinstance(bq.required_build_behavior, BinaryPackageBuildBehavior)
108
    True
7675.420.16 by Michael Nelson
Refactored to adapt on the job rather than the job type and added tests.
109
110
8137.17.24 by Barry Warsaw
thread merge
111
== Dispatching and Reseting jobs ==
112
113
The sampledata contains an active job, being built by the 'bob'
114
builder.
115
7675.450.1 by Tim Penhey
Change the import locations to reflect the moves on devel.
116
    >>> from lp.buildmaster.interfaces.builder import IBuilderSet
8137.17.24 by Barry Warsaw
thread merge
117
118
    >>> bob = getUtility(IBuilderSet)['bob']
119
    >>> job = bob.currentjob
120
121
    >>> print job.builder.name
122
    bob
7675.390.5 by Muharem Hrnjadovic
Review changes, round 1.
123
    >>> job.date_started is not None
8137.17.24 by Barry Warsaw
thread merge
124
    True
125
    >>> print job.logtail
126
    Dummy sampledata entry, not processing
10667.2.2 by Michael Nelson
Mass renaming of imports and references to IBuild/Build/IBuildSet
127
    >>> build = getUtility(IBinaryPackageBuildSet).getByQueueEntry(job)
7675.687.143 by Michael Nelson
buildmaster.tests
128
    >>> print build.status.name
8137.17.24 by Barry Warsaw
thread merge
129
    BUILDING
130
    >>> print job.lastscore
131
    1
132
133
IBuildQueue.reset() will reset the job, enabling it to be dispatched
134
to another build. The score value of the job is preserved.
135
136
    >>> job.reset()
137
138
    >>> print bob.currentjob
139
    None
140
141
    >>> print job.builder
142
    None
7675.390.5 by Muharem Hrnjadovic
Review changes, round 1.
143
    >>> print job.date_started
8137.17.24 by Barry Warsaw
thread merge
144
    None
145
    >>> print job.logtail
146
    None
7675.687.143 by Michael Nelson
buildmaster.tests
147
    >>> print build.status.name
8137.17.24 by Barry Warsaw
thread merge
148
    NEEDSBUILD
149
    >>> print job.lastscore
150
    1
151
152
On the flip-side, IBuildQueue.markAsBuilding() will assign the job to
153
the specified builder.
154
155
    >>> job.markAsBuilding(bob)
156
157
    >>> bob.currentjob == job
158
    True
159
160
    >>> print job.builder.name
161
    bob
7675.390.5 by Muharem Hrnjadovic
Review changes, round 1.
162
    >>> job.date_started is not None
8137.17.24 by Barry Warsaw
thread merge
163
    True
7675.687.143 by Michael Nelson
buildmaster.tests
164
    >>> print build.status.name
8137.17.24 by Barry Warsaw
thread merge
165
    BUILDING
166
167
168
== BuildQueueSet utility ==
169
3147.5.55 by Celso Providelo
applying review comments, r=flacoste
170
Now perform the tests for the BuildQueue zope utility, BuildQueueSet.
171
Check if the instance returned as utility corresponds to its
172
respective interface:
173
5152.5.12 by Celso Providelo
Workarounding race-condition when running slave-scanner and queue-builder in parallel, also improving buildqueue tests and lookup main lookup method.
174
    >>> bqset = getUtility(IBuildQueueSet)
175
    >>> verifyObject(IBuildQueueSet, bqset)
176
    True
3147.5.55 by Celso Providelo
applying review comments, r=flacoste
177
3500.3.54 by Celso Providelo
gluing unrelated review comments about BuildQueue documentation, r=flacoste
178
IBuildQueueSet utility is iterable:
3147.5.55 by Celso Providelo
applying review comments, r=flacoste
179
5152.5.12 by Celso Providelo
Workarounding race-condition when running slave-scanner and queue-builder in parallel, also improving buildqueue tests and lookup main lookup method.
180
    >>> for bq in bqset:
181
    ...     bq.id
182
    1
183
    2
3147.5.55 by Celso Providelo
applying review comments, r=flacoste
184
3500.3.54 by Celso Providelo
gluing unrelated review comments about BuildQueue documentation, r=flacoste
185
Also provides a getter:
3147.5.55 by Celso Providelo
applying review comments, r=flacoste
186
5152.5.12 by Celso Providelo
Workarounding race-condition when running slave-scanner and queue-builder in parallel, also improving buildqueue tests and lookup main lookup method.
187
    >>> bqset[1].id
188
    1
3147.5.55 by Celso Providelo
applying review comments, r=flacoste
189
3500.3.54 by Celso Providelo
gluing unrelated review comments about BuildQueue documentation, r=flacoste
190
a 'get' method:
3147.5.55 by Celso Providelo
applying review comments, r=flacoste
191
5152.5.12 by Celso Providelo
Workarounding race-condition when running slave-scanner and queue-builder in parallel, also improving buildqueue tests and lookup main lookup method.
192
    >>> bqset.get(2).id
193
    2
3147.5.55 by Celso Providelo
applying review comments, r=flacoste
194
3500.3.54 by Celso Providelo
gluing unrelated review comments about BuildQueue documentation, r=flacoste
195
and a full counter:
3147.5.55 by Celso Providelo
applying review comments, r=flacoste
196
5152.5.12 by Celso Providelo
Workarounding race-condition when running slave-scanner and queue-builder in parallel, also improving buildqueue tests and lookup main lookup method.
197
    >>> bqset.count()
198
    2
3147.5.55 by Celso Providelo
applying review comments, r=flacoste
199
3500.3.54 by Celso Providelo
gluing unrelated review comments about BuildQueue documentation, r=flacoste
200
IBuildQueueSet provides a method to retrieve the active job:
3147.5.55 by Celso Providelo
applying review comments, r=flacoste
201
5152.5.12 by Celso Providelo
Workarounding race-condition when running slave-scanner and queue-builder in parallel, also improving buildqueue tests and lookup main lookup method.
202
    >>> for bq in bqset.getActiveBuildJobs():
203
    ...     bq.id, bq.builder.name
204
    (1, u'bob')
3147.5.55 by Celso Providelo
applying review comments, r=flacoste
205
206
Another method to fetch the BuildQueue being processed for a builder,
207
there should be only one since the builders are sigle-task
208
applications:
209
5152.5.12 by Celso Providelo
Workarounding race-condition when running slave-scanner and queue-builder in parallel, also improving buildqueue tests and lookup main lookup method.
210
    >>> current_job = bqset.getByBuilder(bob)
8137.17.24 by Barry Warsaw
thread merge
211
    >>> print current_job.builder.name
212
    bob
3147.5.55 by Celso Providelo
applying review comments, r=flacoste
213
214
BuildQueueSet provides a method used in the builddmaster context to
5152.5.12 by Celso Providelo
Workarounding race-condition when running slave-scanner and queue-builder in parallel, also improving buildqueue tests and lookup main lookup method.
215
calculate retrieve every instance for a set of distroarchseriess
216
corresponding to a build record in NEEDSBUILD state.
217
218
Use all architectures available in ubuntu/hoary, i.e, i386 and hppa:
219
11692.6.2 by Curtis Hovey
Use deglober to fixing simple glob imports in doctests.
220
    >>> from lp.registry.interfaces.distribution import IDistributionSet
5152.5.12 by Celso Providelo
Workarounding race-condition when running slave-scanner and queue-builder in parallel, also improving buildqueue tests and lookup main lookup method.
221
    >>> ubuntu = getUtility(IDistributionSet)['ubuntu']
222
    >>> hoary = ubuntu['hoary']
223
    >>> archseries = [arch for arch in hoary.architectures]
224
225
Create a new Builds and corresponding BuildQueues in ubuntu/hoary/hppa
226
for testing if we will also be able to deal with more than one architecture.
227
9113.7.7 by Jonathan Lange
Update all the rest of the imports of PackagePublishingPocket.
228
    >>> from lp.registry.interfaces.pocket import (
5152.5.12 by Celso Providelo
Workarounding race-condition when running slave-scanner and queue-builder in parallel, also improving buildqueue tests and lookup main lookup method.
229
    ...     PackagePublishingPocket)
230
    >>> alsa_hoary = hoary.getSourcePackage('alsa-utils')
6665.1.11 by Bjorn Tillenius
fix test failures.
231
    >>> alsa_spr = alsa_hoary['1.0.9a-4'].sourcepackagerelease
5226.1.27 by Celso Providelo
fixing test failures.
232
    >>> print alsa_spr.title
233
    alsa-utils - 1.0.9a-4
234
5152.5.12 by Celso Providelo
Workarounding race-condition when running slave-scanner and queue-builder in parallel, also improving buildqueue tests and lookup main lookup method.
235
    >>> alsa_build = alsa_spr.createBuild(
236
    ...     hoary['hppa'], PackagePublishingPocket.RELEASE,
237
    ...     hoary.main_archive)
10130.11.12 by William Grant
Rename createBuildQueueEntry to queueBuild.
238
    >>> alsa_build.queueBuild().lastscore = 500
5152.5.12 by Celso Providelo
Workarounding race-condition when running slave-scanner and queue-builder in parallel, also improving buildqueue tests and lookup main lookup method.
239
240
    >>> pmount_hoary = hoary.getSourcePackage('pmount')
241
    >>> pmount_spr = pmount_hoary.currentrelease.sourcepackagerelease
5226.1.27 by Celso Providelo
fixing test failures.
242
    >>> print pmount_spr.title
243
    pmount - 0.1-2
244
5152.5.12 by Celso Providelo
Workarounding race-condition when running slave-scanner and queue-builder in parallel, also improving buildqueue tests and lookup main lookup method.
245
    >>> pmount_build = pmount_spr.createBuild(
246
    ...     hoary['hppa'], PackagePublishingPocket.RELEASE,
247
    ...     hoary.main_archive)
10130.11.12 by William Grant
Rename createBuildQueueEntry to queueBuild.
248
    >>> pmount_build.queueBuild().lastscore = 1500
5152.5.12 by Celso Providelo
Workarounding race-condition when running slave-scanner and queue-builder in parallel, also improving buildqueue tests and lookup main lookup method.
249
250
Materialize the changes in database:
251
252
    >>> from canonical.database.sqlbase import flush_database_updates
253
    >>> flush_database_updates()
254
255
Note that the results are ordered by descending BuildQueue.lastscore
256
and restricted
257
10667.2.2 by Michael Nelson
Mass renaming of imports and references to IBuild/Build/IBuildSet
258
    >>> for bq in getUtility(IBinaryPackageBuildSet).calculateCandidates(archseries):
259
    ...     build = getUtility(IBinaryPackageBuildSet).getByQueueEntry(bq)
5152.5.12 by Celso Providelo
Workarounding race-condition when running slave-scanner and queue-builder in parallel, also improving buildqueue tests and lookup main lookup method.
260
    ...     print "%s (%s, %d)" % (build.title, bq.lastscore, bq.id)
261
    hppa build of pmount 0.1-2 in ubuntu hoary RELEASE (1500, 4)
262
    i386 build of alsa-utils 1.0.9a-4ubuntu1 in ubuntu hoary RELEASE (1000, 2)
5226.1.27 by Celso Providelo
fixing test failures.
263
    hppa build of alsa-utils 1.0.9a-4 in ubuntu hoary RELEASE (500, 3)
5152.5.12 by Celso Providelo
Workarounding race-condition when running slave-scanner and queue-builder in parallel, also improving buildqueue tests and lookup main lookup method.
264
6251.1.2 by Muharem Hrnjadovic
review comments
265
Language packs will have a score of zero so they are processed
266
after other packages in the queue. First we need to create a fake
267
language pack build.
6251.1.1 by Muharem Hrnjadovic
lang pack scoring fixed
268
269
    >>> from zope.security.proxy import removeSecurityProxy
11692.6.2 by Curtis Hovey
Use deglober to fixing simple glob imports in doctests.
270
    >>> from lp.soyuz.interfaces.section import ISectionSet
6251.1.1 by Muharem Hrnjadovic
lang pack scoring fixed
271
    >>> section_set = getUtility(ISectionSet)
272
    >>> [transl_section] = [s for s in section_set
273
    ...     if s.name == u'translations']
274
    >>> na_hoary = hoary.getSourcePackage('netapplet')
275
    >>> na_spr = removeSecurityProxy(
276
    ...     na_hoary.currentrelease.sourcepackagerelease)
277
    >>> na_spr.section = transl_section
278
279
The build score for the fake language pack is zero.
280
281
    >>> na_build = na_spr.createBuild(
282
    ...     hoary['i386'], PackagePublishingPocket.RELEASE,
283
    ...     hoary.main_archive)
10130.11.12 by William Grant
Rename createBuildQueueEntry to queueBuild.
284
    >>> na_build.queueBuild().lastscore
6251.1.1 by Muharem Hrnjadovic
lang pack scoring fixed
285
    0
286
6251.1.2 by Muharem Hrnjadovic
review comments
287
The fake language pack will be queued behind the other source packages
288
as intended.
6251.1.1 by Muharem Hrnjadovic
lang pack scoring fixed
289
10667.2.2 by Michael Nelson
Mass renaming of imports and references to IBuild/Build/IBuildSet
290
    >>> for bq in getUtility(IBinaryPackageBuildSet).calculateCandidates(archseries):
291
    ...     build = getUtility(IBinaryPackageBuildSet).getByQueueEntry(bq)
6251.1.1 by Muharem Hrnjadovic
lang pack scoring fixed
292
    ...     print "%s (%s, %d)" % (build.title, bq.lastscore, bq.id)
293
    hppa build of pmount 0.1-2 in ubuntu hoary RELEASE (1500, 4)
294
    i386 build of alsa-utils 1.0.9a-4ubuntu1 in ubuntu hoary RELEASE (1000, 2)
295
    hppa build of alsa-utils 1.0.9a-4 in ubuntu hoary RELEASE (500, 3)
296
    i386 build of netapplet 1.0-1 in ubuntu hoary RELEASE (0, 5)
297
6285.1.7 by Muharem Hrnjadovic
reverted changes to lib/canonical/launchpad/doc/buildqueue.txt
298
5152.5.12 by Celso Providelo
Workarounding race-condition when running slave-scanner and queue-builder in parallel, also improving buildqueue tests and lookup main lookup method.
299
Restricting the domain to only hoary/hppa:
300
301
    >>> archseries = [hoary['hppa']]
10667.2.2 by Michael Nelson
Mass renaming of imports and references to IBuild/Build/IBuildSet
302
    >>> for bq in getUtility(IBinaryPackageBuildSet).calculateCandidates(archseries):
303
    ...     build = getUtility(IBinaryPackageBuildSet).getByQueueEntry(bq)
5152.5.12 by Celso Providelo
Workarounding race-condition when running slave-scanner and queue-builder in parallel, also improving buildqueue tests and lookup main lookup method.
304
    ...     print "%s (%s, %d)" % (build.title, bq.lastscore, bq.id)
305
    hppa build of pmount 0.1-2 in ubuntu hoary RELEASE (1500, 4)
5226.1.27 by Celso Providelo
fixing test failures.
306
    hppa build of alsa-utils 1.0.9a-4 in ubuntu hoary RELEASE (500, 3)
5152.5.12 by Celso Providelo
Workarounding race-condition when running slave-scanner and queue-builder in parallel, also improving buildqueue tests and lookup main lookup method.
307
308
This method asserts a valid 'archseries' argument, None or an empty
309
list will result in a AssertionFailure.
310
10667.2.2 by Michael Nelson
Mass renaming of imports and references to IBuild/Build/IBuildSet
311
    >>> getUtility(IBinaryPackageBuildSet).calculateCandidates(None).count()
5152.5.12 by Celso Providelo
Workarounding race-condition when running slave-scanner and queue-builder in parallel, also improving buildqueue tests and lookup main lookup method.
312
    Traceback (most recent call last):
313
    ...
314
    AssertionError: Given 'archseries' cannot be None/empty.
315
10667.2.2 by Michael Nelson
Mass renaming of imports and references to IBuild/Build/IBuildSet
316
    >>> getUtility(IBinaryPackageBuildSet).calculateCandidates([]).count()
5152.5.12 by Celso Providelo
Workarounding race-condition when running slave-scanner and queue-builder in parallel, also improving buildqueue tests and lookup main lookup method.
317
    Traceback (most recent call last):
318
    ...
319
    AssertionError: Given 'archseries' cannot be None/empty.