11573.3.16
by Jonathan Lange
Add the first attempt at an integration test for the binary package build behaviour. |
1 |
# Copyright 2010 Canonical Ltd. This software is licensed under the
|
2 |
# GNU Affero General Public License version 3 (see the file LICENSE).
|
|
3 |
||
4 |
"""Tests for BinaryPackageBuildBehavior."""
|
|
5 |
||
6 |
__metaclass__ = type |
|
7 |
||
11593.3.120
by Julian Edwards
re-add revno 11801 which was backed out in devel due to test failures resulting from a twisted bug |
8 |
import gzip |
9 |
import os |
|
11818.1.1
by Julian Edwards
Remove leftover builddmaster.root directory so we don't break test isolation. |
10 |
import shutil |
11593.3.120
by Julian Edwards
re-add revno 11801 which was backed out in devel due to test failures resulting from a twisted bug |
11 |
import tempfile |
14550.1.1
by Steve Kowalik
Run format-imports over lib/lp and lib/canonical/launchpad |
12 |
|
13 |
from storm.store import Store |
|
14 |
from testtools.deferredruntest import AsynchronousDeferredRunTest |
|
11583.3.4
by Jonathan Lange
Review changes. |
15 |
import transaction |
11583.3.1
by Jonathan Lange
Bust up buildd-slavescanner.txt and move it into unit tests. |
16 |
from twisted.internet import defer |
11593.3.120
by Julian Edwards
re-add revno 11801 which was backed out in devel due to test failures resulting from a twisted bug |
17 |
from zope.component import getUtility |
11573.3.16
by Jonathan Lange
Add the first attempt at an integration test for the binary package build behaviour. |
18 |
from zope.security.proxy import removeSecurityProxy |
19 |
||
11818.1.1
by Julian Edwards
Remove leftover builddmaster.root directory so we don't break test isolation. |
20 |
from canonical.config import config |
11593.3.120
by Julian Edwards
re-add revno 11801 which was backed out in devel due to test failures resulting from a twisted bug |
21 |
from canonical.launchpad.interfaces.librarian import ILibraryFileAliasSet |
11705.2.16
by Jonathan Lange
And so it goes. |
22 |
from canonical.testing.layers import LaunchpadZopelessLayer |
14550.1.1
by Steve Kowalik
Run format-imports over lib/lp and lib/canonical/launchpad |
23 |
from lp.buildmaster.enums import BuildStatus |
11593.3.120
by Julian Edwards
re-add revno 11801 which was backed out in devel due to test failures resulting from a twisted bug |
24 |
from lp.buildmaster.tests.mock_slaves import ( |
25 |
AbortedSlave, |
|
26 |
AbortingSlave, |
|
27 |
BuildingSlave, |
|
28 |
OkSlave, |
|
29 |
WaitingSlave, |
|
30 |
)
|
|
11573.3.24
by Jonathan Lange
Finish gutting the rest of buildd-slavescanner. |
31 |
from lp.registry.interfaces.pocket import ( |
32 |
PackagePublishingPocket, |
|
33 |
pocketsuffix, |
|
34 |
)
|
|
35 |
from lp.registry.interfaces.series import SeriesStatus |
|
11593.3.120
by Julian Edwards
re-add revno 11801 which was backed out in devel due to test failures resulting from a twisted bug |
36 |
from lp.services.job.interfaces.job import JobStatus |
12070.1.4
by Tim Penhey
Move FakeLogger and BufferLogger to lp.services.log.logging and delete the QuietFakeLogger. |
37 |
from lp.services.log.logger import BufferLogger |
11573.3.18
by Jonathan Lange
Move the first of the crazy buildd-slavescanner.txt behaviour testing examples |
38 |
from lp.soyuz.adapters.archivedependencies import ( |
39 |
get_sources_list_for_building, |
|
40 |
)
|
|
14550.1.1
by Steve Kowalik
Run format-imports over lib/lp and lib/canonical/launchpad |
41 |
from lp.soyuz.enums import ArchivePurpose |
11705.2.24
by Jonathan Lange
Clean up a bunch of stuff that I didn't actually need |
42 |
from lp.testing import TestCaseWithFactory |
11705.2.16
by Jonathan Lange
And so it goes. |
43 |
|
44 |
||
45 |
class TestBinaryBuildPackageBehavior(TestCaseWithFactory): |
|
11573.3.18
by Jonathan Lange
Move the first of the crazy buildd-slavescanner.txt behaviour testing examples |
46 |
"""Tests for the BinaryPackageBuildBehavior.
|
47 |
||
48 |
In particular, these tests are about how the BinaryPackageBuildBehavior
|
|
49 |
interacts with the build slave. We test this by using a test double that
|
|
50 |
implements the same interface as `BuilderSlave` but instead of actually
|
|
51 |
making XML-RPC calls, just records any method invocations along with
|
|
52 |
interesting parameters.
|
|
53 |
"""
|
|
11573.3.16
by Jonathan Lange
Add the first attempt at an integration test for the binary package build behaviour. |
54 |
|
11705.2.16
by Jonathan Lange
And so it goes. |
55 |
layer = LaunchpadZopelessLayer |
56 |
run_tests_with = AsynchronousDeferredRunTest |
|
11573.3.16
by Jonathan Lange
Add the first attempt at an integration test for the binary package build behaviour. |
57 |
|
58 |
def setUp(self): |
|
59 |
super(TestBinaryBuildPackageBehavior, self).setUp() |
|
60 |
self.layer.switchDbUser('testadmin') |
|
61 |
||
11583.3.4
by Jonathan Lange
Review changes. |
62 |
def assertExpectedInteraction(self, ignored, call_log, builder, build, |
11593.3.120
by Julian Edwards
re-add revno 11801 which was backed out in devel due to test failures resulting from a twisted bug |
63 |
chroot, archive, archive_purpose, |
64 |
component=None, extra_urls=None, |
|
65 |
filemap_names=None): |
|
11583.3.4
by Jonathan Lange
Review changes. |
66 |
expected = self.makeExpectedInteraction( |
67 |
builder, build, chroot, archive, archive_purpose, component, |
|
68 |
extra_urls, filemap_names) |
|
69 |
self.assertEqual(call_log, expected) |
|
70 |
||
71 |
def makeExpectedInteraction(self, builder, build, chroot, archive, |
|
11593.3.120
by Julian Edwards
re-add revno 11801 which was backed out in devel due to test failures resulting from a twisted bug |
72 |
archive_purpose, component=None, |
11583.3.4
by Jonathan Lange
Review changes. |
73 |
extra_urls=None, filemap_names=None): |
74 |
"""Build the log of calls that we expect to be made to the slave.
|
|
75 |
||
11573.3.18
by Jonathan Lange
Move the first of the crazy buildd-slavescanner.txt behaviour testing examples |
76 |
:param builder: The builder we are using to build the binary package.
|
77 |
:param build: The build being done on the builder.
|
|
78 |
:param chroot: The `LibraryFileAlias` for the chroot in which we are
|
|
79 |
building.
|
|
80 |
:param archive: The `IArchive` into which we are building.
|
|
81 |
:param archive_purpose: The ArchivePurpose we are sending to the
|
|
82 |
builder. We specify this separately from the archive because
|
|
83 |
sometimes the behavior object has to give a different purpose
|
|
84 |
in order to trick the slave into building correctly.
|
|
11583.3.4
by Jonathan Lange
Review changes. |
85 |
:return: A list of the calls we expect to be made.
|
11573.3.18
by Jonathan Lange
Move the first of the crazy buildd-slavescanner.txt behaviour testing examples |
86 |
"""
|
87 |
job = removeSecurityProxy(builder.current_build_behavior).buildfarmjob |
|
88 |
build_id = job.generateSlaveBuildCookie() |
|
89 |
ds_name = build.distro_arch_series.distroseries.name |
|
90 |
suite = ds_name + pocketsuffix[build.pocket] |
|
91 |
archives = get_sources_list_for_building( |
|
92 |
build, build.distro_arch_series, |
|
93 |
build.source_package_release.name) |
|
11573.3.19
by Jonathan Lange
Move more tests to unit test style. |
94 |
arch_indep = build.distro_arch_series.isNominatedArchIndep |
11593.3.120
by Julian Edwards
re-add revno 11801 which was backed out in devel due to test failures resulting from a twisted bug |
95 |
if component is None: |
96 |
component = build.current_component.name |
|
11573.3.19
by Jonathan Lange
Move more tests to unit test style. |
97 |
if filemap_names is None: |
98 |
filemap_names = [] |
|
99 |
if extra_urls is None: |
|
100 |
extra_urls = [] |
|
101 |
||
11583.3.4
by Jonathan Lange
Review changes. |
102 |
upload_logs = [ |
11583.3.5
by Jonathan Lange
Change the OkSlave to log less about cacheFile & sendFileToSlave, |
103 |
('ensurepresent', url, '', '') |
11583.3.4
by Jonathan Lange
Review changes. |
104 |
for url in [chroot.http_url] + extra_urls] |
11573.3.19
by Jonathan Lange
Move more tests to unit test style. |
105 |
|
11583.3.4
by Jonathan Lange
Review changes. |
106 |
extra_args = { |
107 |
'arch_indep': arch_indep, |
|
108 |
'arch_tag': build.distro_arch_series.architecturetag, |
|
109 |
'archive_private': archive.private, |
|
110 |
'archive_purpose': archive_purpose.name, |
|
111 |
'archives': archives, |
|
112 |
'build_debug_symbols': archive.build_debug_symbols, |
|
113 |
'ogrecomponent': component, |
|
114 |
'suite': suite, |
|
115 |
}
|
|
116 |
build_log = [ |
|
11573.3.19
by Jonathan Lange
Move more tests to unit test style. |
117 |
('build', build_id, 'binarypackage', chroot.content.sha1, |
11583.3.4
by Jonathan Lange
Review changes. |
118 |
filemap_names, extra_args)] |
11981.1.4
by Julian Edwards
Fix another failing test |
119 |
if builder.virtualized: |
120 |
result = [('echo', 'ping')] + upload_logs + build_log |
|
121 |
else: |
|
122 |
result = upload_logs + build_log |
|
123 |
return result |
|
11573.3.18
by Jonathan Lange
Move the first of the crazy buildd-slavescanner.txt behaviour testing examples |
124 |
|
11583.3.1
by Jonathan Lange
Bust up buildd-slavescanner.txt and move it into unit tests. |
125 |
def startBuild(self, builder, candidate): |
126 |
builder = removeSecurityProxy(builder) |
|
127 |
candidate = removeSecurityProxy(candidate) |
|
128 |
return defer.maybeDeferred( |
|
12070.1.4
by Tim Penhey
Move FakeLogger and BufferLogger to lp.services.log.logging and delete the QuietFakeLogger. |
129 |
builder.startBuild, candidate, BufferLogger()) |
11583.3.1
by Jonathan Lange
Bust up buildd-slavescanner.txt and move it into unit tests. |
130 |
|
11573.3.18
by Jonathan Lange
Move the first of the crazy buildd-slavescanner.txt behaviour testing examples |
131 |
def test_non_virtual_ppa_dispatch(self): |
132 |
# When the BinaryPackageBuildBehavior dispatches PPA builds to
|
|
133 |
# non-virtual builders, it stores the chroot on the server and
|
|
134 |
# requests a binary package build, lying to say that the archive
|
|
135 |
# purpose is "PRIMARY" because this ensures that the package mangling
|
|
136 |
# tools will run over the built packages.
|
|
11573.3.16
by Jonathan Lange
Add the first attempt at an integration test for the binary package build behaviour. |
137 |
archive = self.factory.makeArchive(virtualized=False) |
11573.3.18
by Jonathan Lange
Move the first of the crazy buildd-slavescanner.txt behaviour testing examples |
138 |
slave = OkSlave() |
11573.3.16
by Jonathan Lange
Add the first attempt at an integration test for the binary package build behaviour. |
139 |
builder = self.factory.makeBuilder(virtualized=False) |
140 |
builder.setSlaveForTesting(slave) |
|
141 |
build = self.factory.makeBinaryPackageBuild( |
|
142 |
builder=builder, archive=archive) |
|
143 |
lf = self.factory.makeLibraryFileAlias() |
|
11583.3.4
by Jonathan Lange
Review changes. |
144 |
transaction.commit() |
11573.3.16
by Jonathan Lange
Add the first attempt at an integration test for the binary package build behaviour. |
145 |
build.distro_arch_series.addOrUpdateChroot(lf) |
146 |
candidate = build.queueBuild() |
|
11583.3.1
by Jonathan Lange
Bust up buildd-slavescanner.txt and move it into unit tests. |
147 |
d = self.startBuild(builder, candidate) |
11573.3.18
by Jonathan Lange
Move the first of the crazy buildd-slavescanner.txt behaviour testing examples |
148 |
d.addCallback( |
11583.3.4
by Jonathan Lange
Review changes. |
149 |
self.assertExpectedInteraction, slave.call_log, |
150 |
builder, build, lf, archive, ArchivePurpose.PRIMARY, 'universe') |
|
11573.3.19
by Jonathan Lange
Move more tests to unit test style. |
151 |
return d |
152 |
||
11593.3.120
by Julian Edwards
re-add revno 11801 which was backed out in devel due to test failures resulting from a twisted bug |
153 |
def test_virtual_ppa_dispatch(self): |
154 |
# Make sure the builder slave gets reset before a build is
|
|
155 |
# dispatched to it.
|
|
156 |
archive = self.factory.makeArchive(virtualized=True) |
|
157 |
slave = OkSlave() |
|
158 |
builder = self.factory.makeBuilder( |
|
159 |
virtualized=True, vm_host="foohost") |
|
160 |
builder.setSlaveForTesting(slave) |
|
161 |
build = self.factory.makeBinaryPackageBuild( |
|
162 |
builder=builder, archive=archive) |
|
163 |
lf = self.factory.makeLibraryFileAlias() |
|
164 |
transaction.commit() |
|
165 |
build.distro_arch_series.addOrUpdateChroot(lf) |
|
166 |
candidate = build.queueBuild() |
|
167 |
d = self.startBuild(builder, candidate) |
|
168 |
def check_build(ignored): |
|
169 |
# We expect the first call to the slave to be a resume call,
|
|
170 |
# followed by the rest of the usual calls we expect.
|
|
171 |
expected_resume_call = slave.call_log.pop(0) |
|
172 |
self.assertEqual('resume', expected_resume_call) |
|
173 |
self.assertExpectedInteraction( |
|
174 |
ignored, slave.call_log, |
|
175 |
builder, build, lf, archive, ArchivePurpose.PPA) |
|
176 |
return d.addCallback(check_build) |
|
177 |
||
11573.3.19
by Jonathan Lange
Move more tests to unit test style. |
178 |
def test_partner_dispatch_no_publishing_history(self): |
179 |
archive = self.factory.makeArchive( |
|
180 |
virtualized=False, purpose=ArchivePurpose.PARTNER) |
|
181 |
slave = OkSlave() |
|
182 |
builder = self.factory.makeBuilder(virtualized=False) |
|
183 |
builder.setSlaveForTesting(slave) |
|
184 |
build = self.factory.makeBinaryPackageBuild( |
|
185 |
builder=builder, archive=archive) |
|
186 |
lf = self.factory.makeLibraryFileAlias() |
|
11583.3.4
by Jonathan Lange
Review changes. |
187 |
transaction.commit() |
11573.3.19
by Jonathan Lange
Move more tests to unit test style. |
188 |
build.distro_arch_series.addOrUpdateChroot(lf) |
189 |
candidate = build.queueBuild() |
|
11583.3.1
by Jonathan Lange
Bust up buildd-slavescanner.txt and move it into unit tests. |
190 |
d = self.startBuild(builder, candidate) |
11573.3.19
by Jonathan Lange
Move more tests to unit test style. |
191 |
d.addCallback( |
11583.3.4
by Jonathan Lange
Review changes. |
192 |
self.assertExpectedInteraction, slave.call_log, |
11593.3.120
by Julian Edwards
re-add revno 11801 which was backed out in devel due to test failures resulting from a twisted bug |
193 |
builder, build, lf, archive, ArchivePurpose.PARTNER) |
11573.3.19
by Jonathan Lange
Move more tests to unit test style. |
194 |
return d |
195 |
||
11573.3.24
by Jonathan Lange
Finish gutting the rest of buildd-slavescanner. |
196 |
def test_dont_dispatch_release_builds(self): |
197 |
archive = self.factory.makeArchive(purpose=ArchivePurpose.PRIMARY) |
|
198 |
builder = self.factory.makeBuilder() |
|
11573.3.19
by Jonathan Lange
Move more tests to unit test style. |
199 |
distroseries = self.factory.makeDistroSeries( |
11573.3.24
by Jonathan Lange
Finish gutting the rest of buildd-slavescanner. |
200 |
status=SeriesStatus.CURRENT, distribution=archive.distribution) |
11573.3.19
by Jonathan Lange
Move more tests to unit test style. |
201 |
distro_arch_series = self.factory.makeDistroArchSeries( |
11573.3.24
by Jonathan Lange
Finish gutting the rest of buildd-slavescanner. |
202 |
distroseries=distroseries) |
203 |
build = self.factory.makeBinaryPackageBuild( |
|
204 |
builder=builder, archive=archive, |
|
205 |
distroarchseries=distro_arch_series, |
|
206 |
pocket=PackagePublishingPocket.RELEASE) |
|
11573.3.19
by Jonathan Lange
Move more tests to unit test style. |
207 |
lf = self.factory.makeLibraryFileAlias() |
11583.3.4
by Jonathan Lange
Review changes. |
208 |
transaction.commit() |
11573.3.24
by Jonathan Lange
Finish gutting the rest of buildd-slavescanner. |
209 |
build.distro_arch_series.addOrUpdateChroot(lf) |
210 |
candidate = build.queueBuild() |
|
211 |
behavior = candidate.required_build_behavior |
|
11593.3.120
by Julian Edwards
re-add revno 11801 which was backed out in devel due to test failures resulting from a twisted bug |
212 |
behavior.setBuilder(builder) |
11573.3.24
by Jonathan Lange
Finish gutting the rest of buildd-slavescanner. |
213 |
e = self.assertRaises( |
12070.1.4
by Tim Penhey
Move FakeLogger and BufferLogger to lp.services.log.logging and delete the QuietFakeLogger. |
214 |
AssertionError, behavior.verifyBuildRequest, BufferLogger()) |
11583.3.4
by Jonathan Lange
Review changes. |
215 |
expected_message = ( |
11573.3.24
by Jonathan Lange
Finish gutting the rest of buildd-slavescanner. |
216 |
"%s (%s) can not be built for pocket %s: invalid pocket due " |
217 |
"to the series status of %s." % ( |
|
218 |
build.title, build.id, build.pocket.name, |
|
11583.3.4
by Jonathan Lange
Review changes. |
219 |
build.distro_series.name)) |
220 |
self.assertEqual(expected_message, str(e)) |
|
11573.3.19
by Jonathan Lange
Move more tests to unit test style. |
221 |
|
11573.3.24
by Jonathan Lange
Finish gutting the rest of buildd-slavescanner. |
222 |
def test_dont_dispatch_security_builds(self): |
223 |
archive = self.factory.makeArchive(purpose=ArchivePurpose.PRIMARY) |
|
224 |
builder = self.factory.makeBuilder() |
|
225 |
build = self.factory.makeBinaryPackageBuild( |
|
226 |
builder=builder, archive=archive, |
|
227 |
pocket=PackagePublishingPocket.SECURITY) |
|
228 |
lf = self.factory.makeLibraryFileAlias() |
|
11583.3.4
by Jonathan Lange
Review changes. |
229 |
transaction.commit() |
11573.3.24
by Jonathan Lange
Finish gutting the rest of buildd-slavescanner. |
230 |
build.distro_arch_series.addOrUpdateChroot(lf) |
231 |
candidate = build.queueBuild() |
|
232 |
behavior = candidate.required_build_behavior |
|
11593.3.120
by Julian Edwards
re-add revno 11801 which was backed out in devel due to test failures resulting from a twisted bug |
233 |
behavior.setBuilder(builder) |
11573.3.24
by Jonathan Lange
Finish gutting the rest of buildd-slavescanner. |
234 |
e = self.assertRaises( |
12070.1.4
by Tim Penhey
Move FakeLogger and BufferLogger to lp.services.log.logging and delete the QuietFakeLogger. |
235 |
AssertionError, behavior.verifyBuildRequest, BufferLogger()) |
11573.3.24
by Jonathan Lange
Finish gutting the rest of buildd-slavescanner. |
236 |
self.assertEqual( |
237 |
'Soyuz is not yet capable of building SECURITY uploads.', |
|
238 |
str(e)) |
|
11593.3.120
by Julian Edwards
re-add revno 11801 which was backed out in devel due to test failures resulting from a twisted bug |
239 |
|
240 |
def test_verifyBuildRequest(self): |
|
241 |
# Don't allow a virtual build on a non-virtual builder.
|
|
242 |
archive = self.factory.makeArchive(purpose=ArchivePurpose.PPA) |
|
243 |
builder = self.factory.makeBuilder(virtualized=False) |
|
244 |
build = self.factory.makeBinaryPackageBuild( |
|
245 |
builder=builder, archive=archive, |
|
246 |
pocket=PackagePublishingPocket.RELEASE) |
|
247 |
lf = self.factory.makeLibraryFileAlias() |
|
248 |
transaction.commit() |
|
249 |
build.distro_arch_series.addOrUpdateChroot(lf) |
|
250 |
candidate = build.queueBuild() |
|
251 |
behavior = candidate.required_build_behavior |
|
252 |
behavior.setBuilder(builder) |
|
253 |
e = self.assertRaises( |
|
12070.1.4
by Tim Penhey
Move FakeLogger and BufferLogger to lp.services.log.logging and delete the QuietFakeLogger. |
254 |
AssertionError, behavior.verifyBuildRequest, BufferLogger()) |
11593.3.120
by Julian Edwards
re-add revno 11801 which was backed out in devel due to test failures resulting from a twisted bug |
255 |
self.assertEqual( |
256 |
'Attempt to build virtual item on a non-virtual builder.', |
|
257 |
str(e)) |
|
258 |
||
259 |
||
11705.2.16
by Jonathan Lange
And so it goes. |
260 |
class TestBinaryBuildPackageBehaviorBuildCollection(TestCaseWithFactory): |
11593.3.120
by Julian Edwards
re-add revno 11801 which was backed out in devel due to test failures resulting from a twisted bug |
261 |
"""Tests for the BinaryPackageBuildBehavior.
|
262 |
||
263 |
Using various mock slaves, we check how updateBuild() behaves in
|
|
264 |
various scenarios.
|
|
265 |
"""
|
|
266 |
||
267 |
# XXX: These tests replace part of the old buildd-slavescanner.txt
|
|
268 |
# It was checking that each call to updateBuild was sending 3 (!)
|
|
269 |
# emails but this behaviour is so ill-defined and dependent on the
|
|
270 |
# sample data that I've not replicated that here. We need to
|
|
271 |
# examine that behaviour separately somehow, but the old tests gave
|
|
272 |
# NO clue as to what, exactly, they were testing.
|
|
273 |
||
11705.2.16
by Jonathan Lange
And so it goes. |
274 |
layer = LaunchpadZopelessLayer |
275 |
run_tests_with = AsynchronousDeferredRunTest |
|
11593.3.120
by Julian Edwards
re-add revno 11801 which was backed out in devel due to test failures resulting from a twisted bug |
276 |
|
11818.1.2
by Julian Edwards
unfuck stupid blanket cleanup |
277 |
def _cleanup(self): |
278 |
if os.path.exists(config.builddmaster.root): |
|
279 |
shutil.rmtree(config.builddmaster.root) |
|
280 |
||
11593.3.120
by Julian Edwards
re-add revno 11801 which was backed out in devel due to test failures resulting from a twisted bug |
281 |
def setUp(self): |
282 |
super(TestBinaryBuildPackageBehaviorBuildCollection, self).setUp() |
|
283 |
self.layer.switchDbUser('testadmin') |
|
284 |
||
285 |
self.builder = self.factory.makeBuilder() |
|
286 |
self.build = self.factory.makeBinaryPackageBuild( |
|
287 |
builder=self.builder, pocket=PackagePublishingPocket.RELEASE) |
|
288 |
lf = self.factory.makeLibraryFileAlias() |
|
289 |
transaction.commit() |
|
290 |
self.build.distro_arch_series.addOrUpdateChroot(lf) |
|
291 |
self.candidate = self.build.queueBuild() |
|
292 |
self.candidate.markAsBuilding(self.builder) |
|
293 |
self.behavior = self.candidate.required_build_behavior |
|
294 |
self.behavior.setBuilder(self.builder) |
|
11818.1.1
by Julian Edwards
Remove leftover builddmaster.root directory so we don't break test isolation. |
295 |
# This is required so that uploaded files from the buildd don't
|
296 |
# hang around between test runs.
|
|
11818.1.2
by Julian Edwards
unfuck stupid blanket cleanup |
297 |
self.addCleanup(self._cleanup) |
11593.3.120
by Julian Edwards
re-add revno 11801 which was backed out in devel due to test failures resulting from a twisted bug |
298 |
|
299 |
def assertBuildProperties(self, build): |
|
300 |
"""Check that a build happened by making sure some of its properties
|
|
301 |
are set."""
|
|
11705.2.16
by Jonathan Lange
And so it goes. |
302 |
self.assertIsNot(None, build.builder) |
303 |
self.assertIsNot(None, build.date_finished) |
|
304 |
self.assertIsNot(None, build.duration) |
|
305 |
self.assertIsNot(None, build.log) |
|
11593.3.120
by Julian Edwards
re-add revno 11801 which was backed out in devel due to test failures resulting from a twisted bug |
306 |
|
307 |
def test_packagefail_collection(self): |
|
308 |
# When a package fails to build, make sure the builder notes are
|
|
309 |
# stored and the build status is set as failed.
|
|
310 |
waiting_slave = WaitingSlave('BuildStatus.PACKAGEFAIL') |
|
311 |
self.builder.setSlaveForTesting(waiting_slave) |
|
312 |
||
313 |
def got_update(ignored): |
|
314 |
self.assertBuildProperties(self.build) |
|
315 |
self.assertEqual(BuildStatus.FAILEDTOBUILD, self.build.status) |
|
316 |
||
317 |
d = self.builder.updateBuild(self.candidate) |
|
318 |
return d.addCallback(got_update) |
|
319 |
||
320 |
def test_depwait_collection(self): |
|
321 |
# Package build was left in dependency wait.
|
|
322 |
DEPENDENCIES = 'baz (>= 1.0.1)' |
|
323 |
waiting_slave = WaitingSlave('BuildStatus.DEPFAIL', DEPENDENCIES) |
|
324 |
self.builder.setSlaveForTesting(waiting_slave) |
|
325 |
||
326 |
def got_update(ignored): |
|
327 |
self.assertBuildProperties(self.build) |
|
328 |
self.assertEqual(BuildStatus.MANUALDEPWAIT, self.build.status) |
|
329 |
self.assertEqual(DEPENDENCIES, self.build.dependencies) |
|
330 |
||
331 |
d = self.builder.updateBuild(self.candidate) |
|
332 |
return d.addCallback(got_update) |
|
333 |
||
334 |
def test_chrootfail_collection(self): |
|
335 |
# There was a chroot problem for this build.
|
|
336 |
waiting_slave = WaitingSlave('BuildStatus.CHROOTFAIL') |
|
337 |
self.builder.setSlaveForTesting(waiting_slave) |
|
338 |
||
339 |
def got_update(ignored): |
|
340 |
self.assertBuildProperties(self.build) |
|
341 |
self.assertEqual(BuildStatus.CHROOTWAIT, self.build.status) |
|
342 |
||
343 |
d = self.builder.updateBuild(self.candidate) |
|
344 |
return d.addCallback(got_update) |
|
345 |
||
346 |
def test_builderfail_collection(self): |
|
347 |
# The builder failed after we dispatched the build.
|
|
348 |
waiting_slave = WaitingSlave('BuildStatus.BUILDERFAIL') |
|
349 |
self.builder.setSlaveForTesting(waiting_slave) |
|
350 |
||
351 |
def got_update(ignored): |
|
352 |
self.assertEqual( |
|
353 |
"Builder returned BUILDERFAIL when asked for its status", |
|
354 |
self.builder.failnotes) |
|
11705.2.16
by Jonathan Lange
And so it goes. |
355 |
self.assertIs(None, self.candidate.builder) |
11593.3.120
by Julian Edwards
re-add revno 11801 which was backed out in devel due to test failures resulting from a twisted bug |
356 |
self.assertEqual(BuildStatus.NEEDSBUILD, self.build.status) |
357 |
job = self.candidate.specific_job.job |
|
358 |
self.assertEqual(JobStatus.WAITING, job.status) |
|
359 |
||
360 |
d = self.builder.updateBuild(self.candidate) |
|
361 |
return d.addCallback(got_update) |
|
362 |
||
363 |
def test_building_collection(self): |
|
364 |
# The builder is still building the package.
|
|
365 |
self.builder.setSlaveForTesting(BuildingSlave()) |
|
11705.2.16
by Jonathan Lange
And so it goes. |
366 |
|
11593.3.120
by Julian Edwards
re-add revno 11801 which was backed out in devel due to test failures resulting from a twisted bug |
367 |
def got_update(ignored): |
368 |
# The fake log is returned from the BuildingSlave() mock.
|
|
369 |
self.assertEqual("This is a build log", self.candidate.logtail) |
|
370 |
||
371 |
d = self.builder.updateBuild(self.candidate) |
|
372 |
return d.addCallback(got_update) |
|
373 |
||
374 |
def test_aborted_collection(self): |
|
375 |
# The builder aborted the job.
|
|
376 |
self.builder.setSlaveForTesting(AbortedSlave()) |
|
377 |
||
378 |
def got_update(ignored): |
|
379 |
self.assertEqual(BuildStatus.NEEDSBUILD, self.build.status) |
|
380 |
||
381 |
d = self.builder.updateBuild(self.candidate) |
|
382 |
return d.addCallback(got_update) |
|
383 |
||
384 |
def test_aborting_collection(self): |
|
385 |
# The builder is in the process of aborting.
|
|
386 |
self.builder.setSlaveForTesting(AbortingSlave()) |
|
387 |
||
388 |
def got_update(ignored): |
|
389 |
self.assertEqual( |
|
390 |
"Waiting for slave process to be terminated", |
|
391 |
self.candidate.logtail) |
|
392 |
||
393 |
d = self.builder.updateBuild(self.candidate) |
|
394 |
return d.addCallback(got_update) |
|
395 |
||
12019.10.1
by Julian Edwards
Discard builds when they complete if the source is not published. |
396 |
def test_collection_for_deleted_source(self): |
12019.10.3
by Julian Edwards
Review comments from gmb |
397 |
# If we collected a build for a superseded/deleted source then
|
398 |
# the build should get marked superseded as the build results
|
|
399 |
# get discarded.
|
|
12019.10.1
by Julian Edwards
Discard builds when they complete if the source is not published. |
400 |
self.builder.setSlaveForTesting(WaitingSlave('BuildStatus.OK')) |
401 |
spr = removeSecurityProxy(self.build.source_package_release) |
|
402 |
pub = self.build.current_source_publication |
|
403 |
pub.requestDeletion(spr.creator) |
|
404 |
||
405 |
def got_update(ignored): |
|
406 |
self.assertEqual( |
|
407 |
BuildStatus.SUPERSEDED, self.build.status) |
|
408 |
||
409 |
d = self.builder.updateBuild(self.candidate) |
|
410 |
return d.addCallback(got_update) |
|
411 |
||
11593.3.120
by Julian Edwards
re-add revno 11801 which was backed out in devel due to test failures resulting from a twisted bug |
412 |
def test_uploading_collection(self): |
413 |
# After a successful build, the status should be UPLOADING.
|
|
414 |
self.builder.setSlaveForTesting(WaitingSlave('BuildStatus.OK')) |
|
415 |
||
416 |
def got_update(ignored): |
|
417 |
self.assertEqual(self.build.status, BuildStatus.UPLOADING) |
|
418 |
# We do not store any upload log information when the binary
|
|
419 |
# upload processing succeeded.
|
|
11705.2.16
by Jonathan Lange
And so it goes. |
420 |
self.assertIs(None, self.build.upload_log) |
11593.3.120
by Julian Edwards
re-add revno 11801 which was backed out in devel due to test failures resulting from a twisted bug |
421 |
|
422 |
d = self.builder.updateBuild(self.candidate) |
|
423 |
return d.addCallback(got_update) |
|
424 |
||
425 |
def test_givenback_collection(self): |
|
426 |
waiting_slave = WaitingSlave('BuildStatus.GIVENBACK') |
|
427 |
self.builder.setSlaveForTesting(waiting_slave) |
|
428 |
score = self.candidate.lastscore |
|
429 |
||
11705.2.16
by Jonathan Lange
And so it goes. |
430 |
def got_update(ignored): |
431 |
self.assertIs(None, self.candidate.builder) |
|
432 |
self.assertIs(None, self.candidate.date_started) |
|
11593.3.120
by Julian Edwards
re-add revno 11801 which was backed out in devel due to test failures resulting from a twisted bug |
433 |
self.assertEqual(score, self.candidate.lastscore) |
434 |
self.assertEqual(BuildStatus.NEEDSBUILD, self.build.status) |
|
435 |
job = self.candidate.specific_job.job |
|
436 |
self.assertEqual(JobStatus.WAITING, job.status) |
|
437 |
||
438 |
d = self.builder.updateBuild(self.candidate) |
|
439 |
return d.addCallback(got_update) |
|
440 |
||
441 |
def test_log_file_collection(self): |
|
442 |
self.builder.setSlaveForTesting(WaitingSlave('BuildStatus.OK')) |
|
443 |
self.build.status = BuildStatus.FULLYBUILT |
|
444 |
old_tmps = sorted(os.listdir('/tmp')) |
|
445 |
||
11892.6.5
by Julian Edwards
fix test_binarypackagebuildbehavior when getting log files to test with |
446 |
def got_log(logfile_lfa_id): |
447 |
# Grabbing logs should not leave new files in /tmp (bug #172798)
|
|
448 |
logfile_lfa = getUtility(ILibraryFileAliasSet)[logfile_lfa_id] |
|
449 |
new_tmps = sorted(os.listdir('/tmp')) |
|
450 |
self.assertEqual(old_tmps, new_tmps) |
|
451 |
||
452 |
# The new librarian file is stored compressed with a .gz
|
|
453 |
# extension and text/plain file type for easy viewing in
|
|
454 |
# browsers, as it decompresses and displays the file inline.
|
|
11892.6.19
by Julian Edwards
merge devel |
455 |
self.assertTrue( |
456 |
logfile_lfa.filename.endswith('_FULLYBUILT.txt.gz')) |
|
11892.6.5
by Julian Edwards
fix test_binarypackagebuildbehavior when getting log files to test with |
457 |
self.assertEqual('text/plain', logfile_lfa.mimetype) |
458 |
self.layer.txn.commit() |
|
459 |
||
460 |
# LibrarianFileAlias does not implement tell() or seek(), which
|
|
461 |
# are required by gzip.open(), so we need to read the file out
|
|
462 |
# of the librarian first.
|
|
463 |
fd, fname = tempfile.mkstemp() |
|
464 |
self.addCleanup(os.remove, fname) |
|
465 |
tmp = os.fdopen(fd, 'wb') |
|
466 |
tmp.write(logfile_lfa.read()) |
|
467 |
tmp.close() |
|
468 |
uncompressed_file = gzip.open(fname).read() |
|
469 |
||
470 |
# Now make a temp filename that getFile() can write to.
|
|
11892.6.20
by Julian Edwards
Fix test failures due to jml's TestTools changes |
471 |
fd, tmp_orig_file_name = tempfile.mkstemp() |
11892.6.5
by Julian Edwards
fix test_binarypackagebuildbehavior when getting log files to test with |
472 |
self.addCleanup(os.remove, tmp_orig_file_name) |
473 |
||
474 |
# Check that the original file from the slave matches the
|
|
11892.6.14
by Julian Edwards
Some minor review changes |
475 |
# uncompressed file in the librarian.
|
11892.6.5
by Julian Edwards
fix test_binarypackagebuildbehavior when getting log files to test with |
476 |
def got_orig_log(ignored): |
477 |
orig_file_content = open(tmp_orig_file_name).read() |
|
478 |
self.assertEqual(orig_file_content, uncompressed_file) |
|
479 |
||
480 |
d = removeSecurityProxy(self.builder.slave).getFile( |
|
481 |
'buildlog', tmp_orig_file_name) |
|
482 |
return d.addCallback(got_orig_log) |
|
483 |
||
484 |
d = self.build.getLogFromSlave(self.build) |
|
485 |
return d.addCallback(got_log) |
|
11593.3.120
by Julian Edwards
re-add revno 11801 which was backed out in devel due to test failures resulting from a twisted bug |
486 |
|
487 |
def test_private_build_log_storage(self): |
|
488 |
# Builds in private archives should have their log uploaded to
|
|
489 |
# the restricted librarian.
|
|
490 |
self.builder.setSlaveForTesting(WaitingSlave('BuildStatus.OK')) |
|
491 |
||
12019.10.2
by Julian Edwards
Fix test busted by the change, which was depending on removed sources. |
492 |
# Go behind Storm's back since the field validator on
|
493 |
# Archive.private prevents us from setting it to True with
|
|
494 |
# existing published sources.
|
|
495 |
Store.of(self.build).execute(""" |
|
496 |
UPDATE archive SET private=True,buildd_secret='foo'
|
|
497 |
WHERE archive.id = %s""" % self.build.archive.id) |
|
498 |
Store.of(self.build).invalidate() |
|
11593.3.120
by Julian Edwards
re-add revno 11801 which was backed out in devel due to test failures resulting from a twisted bug |
499 |
|
500 |
def got_update(ignored): |
|
501 |
# Librarian needs a commit. :(
|
|
502 |
self.layer.txn.commit() |
|
503 |
self.assertTrue(self.build.log.restricted) |
|
504 |
||
505 |
d = self.builder.updateBuild(self.candidate) |
|
506 |
return d.addCallback(got_update) |