1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
|
# Copyright 2010 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
__metaclass__ = type
import transaction
from zope.component import getUtility
from zope.security.proxy import removeSecurityProxy
from canonical.launchpad.scripts.tests import run_script
from canonical.testing import (
DatabaseFunctionalLayer,
LaunchpadZopelessLayer,
)
from lp.buildmaster.enums import BuildStatus
from lp.registry.interfaces.distroseriesparent import IDistroSeriesParentSet
from lp.registry.interfaces.pocket import PackagePublishingPocket
from lp.soyuz.enums import SourcePackageFormat
from lp.soyuz.interfaces.distributionjob import (
IInitializeDistroSeriesJobSource,
InitializationCompleted,
InitializationPending,
)
from lp.soyuz.interfaces.packageset import IPackagesetSet
from lp.soyuz.interfaces.processor import IProcessorFamilySet
from lp.soyuz.interfaces.publishing import PackagePublishingStatus
from lp.soyuz.interfaces.sourcepackageformat import (
ISourcePackageFormatSelectionSet,
)
from lp.soyuz.model.initializedistroseriesjob import InitializeDistroSeriesJob
from lp.soyuz.scripts.initialize_distroseries import InitializationError
from lp.soyuz.tests.test_publishing import SoyuzTestPublisher
from lp.testing import TestCaseWithFactory
class InitializeDistroSeriesJobTests(TestCaseWithFactory):
"""Test case for InitializeDistroSeriesJob."""
layer = DatabaseFunctionalLayer
@property
def job_source(self):
return getUtility(IInitializeDistroSeriesJobSource)
def test_getOopsVars(self):
parent = self.factory.makeDistroSeries()
distroseries = self.factory.makeDistroSeries()
job = self.job_source.create(distroseries, [parent.id])
vars = job.getOopsVars()
naked_job = removeSecurityProxy(job)
self.assertIn(
('distribution_id', distroseries.distribution.id), vars)
self.assertIn(('distroseries_id', distroseries.id), vars)
self.assertIn(('distribution_job_id', naked_job.context.id), vars)
self.assertIn(('parent_distroseries_ids', [parent.id]), vars)
def _getJobs(self):
"""Return the pending InitializeDistroSeriesJobs as a list."""
return list(InitializeDistroSeriesJob.iterReady())
def _getJobCount(self):
"""Return the number of InitializeDistroSeriesJobs in the
queue."""
return len(self._getJobs())
def test___repr__(self):
parent1 = self.factory.makeDistroSeries()
parent2 = self.factory.makeDistroSeries()
distroseries = self.factory.makeDistroSeries()
packageset1 = self.factory.makePackageset()
packageset2 = self.factory.makePackageset()
overlays = (True, False)
overlay_pockets = (u'Updates', u'Release')
overlay_components = (u"main", u"universe")
arches = (u'i386', u'amd64')
archindep_archtag = u'amd64'
packagesets = (packageset1.id, packageset2.id)
rebuild = False
job = self.job_source.create(
distroseries, [parent1.id, parent2.id], arches, archindep_archtag,
packagesets, rebuild, overlays, overlay_pockets,
overlay_components)
expected = ("<InitializeDistroSeriesJob for "
"distribution: {distroseries.distribution.name}, "
"distroseries: {distroseries.name}, "
"parent[overlay?/pockets/components]: "
"{parent1.name}[True/Updates/main],"
"{parent2.name}[False/Release/universe], "
"architectures: (u'i386', u'amd64'), "
"archindep_archtag: amd64, "
"packagesets: [u'{packageset1.name}', u'{packageset2.name}'], "
"rebuild: False>".format(
distroseries=distroseries,
parent1=parent1,
parent2=parent2,
packageset1=packageset1,
packageset2=packageset2))
self.assertEqual(
expected,
repr(job)
)
def test_create_with_existing_pending_job(self):
parent = self.factory.makeDistroSeries()
distroseries = self.factory.makeDistroSeries()
# If there's already a pending InitializeDistroSeriesJob for a
# DistroSeries, InitializeDistroSeriesJob.create() raises an
# exception.
job = self.job_source.create(distroseries, [parent.id])
exception = self.assertRaises(
InitializationPending, self.job_source.create,
distroseries, [parent.id])
self.assertEqual(job, exception.job)
def test_create_with_existing_completed_job(self):
parent = self.factory.makeDistroSeries()
distroseries = self.factory.makeDistroSeries()
# If there's already a completed InitializeDistroSeriesJob for a
# DistroSeries, InitializeDistroSeriesJob.create() raises an
# exception.
job = self.job_source.create(distroseries, [parent.id])
job.start()
job.complete()
exception = self.assertRaises(
InitializationCompleted, self.job_source.create,
distroseries, [parent.id])
self.assertEqual(job, exception.job)
def test_create_with_existing_failed_job(self):
parent = self.factory.makeDistroSeries()
distroseries = self.factory.makeDistroSeries()
# If there's already a failed InitializeDistroSeriesJob for a
# DistroSeries, InitializeDistroSeriesJob.create() schedules a new
# job.
job = self.job_source.create(distroseries, [parent.id])
job.start()
job.fail()
self.job_source.create(distroseries, [parent.id])
def test_run_with_previous_series_already_set(self):
# InitializationError is raised if a parent series already exists
# for this series.
parent = self.factory.makeDistroSeries()
distroseries = self.factory.makeDistroSeries()
getUtility(IDistroSeriesParentSet).new(
distroseries, parent, initialized=True)
job = self.job_source.create(distroseries, [parent.id])
expected_message = (
"Series {child.name} has already been initialised"
".").format(child=distroseries)
self.assertRaisesWithContent(
InitializationError, expected_message, job.run)
def test_arguments(self):
"""Test that InitializeDistroSeriesJob specified with arguments can
be gotten out again."""
parent = self.factory.makeDistroSeries()
distroseries = self.factory.makeDistroSeries()
arches = (u'i386', u'amd64')
archindep_archtag = u'amd64'
packagesets = (u'1', u'2', u'3')
overlays = (True, )
overlay_pockets = ('Updates', )
overlay_components = ('restricted', )
job = self.job_source.create(
distroseries, [parent.id], arches, archindep_archtag, packagesets,
False, overlays, overlay_pockets, overlay_components)
naked_job = removeSecurityProxy(job)
self.assertEqual(naked_job.distroseries, distroseries)
self.assertEqual(naked_job.arches, arches)
self.assertEqual(naked_job.archindep_archtag, archindep_archtag)
self.assertEqual(naked_job.packagesets, packagesets)
self.assertEqual(naked_job.rebuild, False)
self.assertEqual(naked_job.parents, (parent.id, ))
self.assertEqual(naked_job.overlays, overlays)
self.assertEqual(naked_job.overlay_pockets, overlay_pockets)
self.assertEqual(naked_job.overlay_components, overlay_components)
def test_parent(self):
parent = self.factory.makeDistroSeries()
distroseries = self.factory.makeDistroSeries()
job = self.job_source.create(distroseries, [parent.id])
naked_job = removeSecurityProxy(job)
self.assertEqual((parent.id, ), naked_job.parents)
def test_get(self):
# InitializeDistroSeriesJob.get() returns the initialization job for
# the given distroseries. There should only ever be one.
parent = self.factory.makeDistroSeries()
distroseries = self.factory.makeDistroSeries()
another_distroseries = self.factory.makeDistroSeries()
self.assertIs(None, self.job_source.get(distroseries))
self.job_source.create(distroseries, [parent.id])
self.job_source.create(another_distroseries, [parent.id])
job = self.job_source.get(distroseries)
self.assertIsInstance(job, InitializeDistroSeriesJob)
self.assertEqual(job.distroseries, distroseries)
def test_error_description_when_no_error(self):
# The InitializeDistroSeriesJob.error_description property returns
# None when no error description is recorded.
parent = self.factory.makeDistroSeries()
distroseries = self.factory.makeDistroSeries()
job = self.job_source.create(distroseries, [parent.id])
self.assertIs(None, removeSecurityProxy(job).error_description)
def test_error_description_set_when_notifying_about_user_errors(self):
# error_description is set by notifyUserError().
parent = self.factory.makeDistroSeries()
distroseries = self.factory.makeDistroSeries()
job = self.job_source.create(distroseries, [parent.id])
message = "This is an example message."
job.notifyUserError(InitializationError(message))
self.assertEqual(message, removeSecurityProxy(job).error_description)
class InitializeDistroSeriesJobTestsWithPackages(TestCaseWithFactory):
"""Test case for InitializeDistroSeriesJob."""
layer = LaunchpadZopelessLayer
@property
def job_source(self):
return getUtility(IInitializeDistroSeriesJobSource)
def setupDas(self, parent, proc, arch_tag):
pf = getUtility(IProcessorFamilySet).getByName(proc)
parent_das = self.factory.makeDistroArchSeries(
distroseries=parent, processorfamily=pf,
architecturetag=arch_tag)
lf = self.factory.makeLibraryFileAlias()
transaction.commit()
parent_das.addOrUpdateChroot(lf)
parent_das.supports_virtualized = True
return parent_das
def _create_child(self):
pf = self.factory.makeProcessorFamily()
pf.addProcessor('x86', '', '')
parent = self.factory.makeDistroSeries()
parent_das = self.factory.makeDistroArchSeries(
distroseries=parent, processorfamily=pf)
lf = self.factory.makeLibraryFileAlias()
# Since the LFA needs to be in the librarian, commit.
transaction.commit()
parent_das.addOrUpdateChroot(lf)
parent_das.supports_virtualized = True
parent.nominatedarchindep = parent_das
publisher = SoyuzTestPublisher()
publisher.prepareBreezyAutotest()
packages = {'udev': '0.1-1', 'libc6': '2.8-1'}
for package in packages.keys():
publisher.getPubBinaries(
distroseries=parent, binaryname=package,
version=packages[package],
status=PackagePublishingStatus.PUBLISHED)
test1 = getUtility(IPackagesetSet).new(
u'test1', u'test 1 packageset', parent.owner,
distroseries=parent)
self.test1_packageset_id = str(test1.id)
test1.addSources('udev')
parent.updatePackageCount()
child = self.factory.makeDistroSeries()
getUtility(ISourcePackageFormatSelectionSet).add(
child, SourcePackageFormat.FORMAT_1_0)
# Make sure everything hits the database, switching db users aborts.
transaction.commit()
return parent, child
def test_job(self):
parent, child = self._create_child()
job = self.job_source.create(child, [parent.id])
self.layer.switchDbUser('initializedistroseries')
job.run()
child.updatePackageCount()
self.assertEqual(parent.sourcecount, child.sourcecount)
self.assertEqual(parent.binarycount, child.binarycount)
def test_job_with_arguments(self):
parent, child = self._create_child()
arch = parent.nominatedarchindep.architecturetag
job = self.job_source.create(
child, [parent.id], packagesets=(self.test1_packageset_id,),
arches=(arch,), rebuild=True)
self.layer.switchDbUser('initializedistroseries')
job.run()
child.updatePackageCount()
builds = child.getBuildRecords(
build_state=BuildStatus.NEEDSBUILD,
pocket=PackagePublishingPocket.RELEASE)
self.assertEqual(child.sourcecount, 1)
self.assertEqual(child.binarycount, 0)
self.assertEqual(builds.count(), 1)
def test_job_with_none_arguments(self):
parent, child = self._create_child()
job = self.job_source.create(
child, [parent.id], archindep_archtag=None, packagesets=None,
arches=None, overlays=None, overlay_pockets=None,
overlay_components=None, rebuild=True)
self.layer.switchDbUser('initializedistroseries')
job.run()
child.updatePackageCount()
self.assertEqual(parent.sourcecount, child.sourcecount)
def test_job_with_none_archindep_archtag_argument(self):
parent, child = self._create_child()
job = self.job_source.create(
child, [parent.id], archindep_archtag=None, packagesets=None,
arches=None, overlays=None, overlay_pockets=None,
overlay_components=None, rebuild=True)
self.layer.switchDbUser('initializedistroseries')
job.run()
self.assertEqual(
parent.nominatedarchindep.architecturetag,
child.nominatedarchindep.architecturetag)
def test_job_with_archindep_archtag_argument(self):
parent, child = self._create_child()
self.setupDas(parent, 'amd64', 'amd64')
self.setupDas(parent, 'powerpc', 'hppa')
job = self.job_source.create(
child, [parent.id], archindep_archtag='amd64', packagesets=None,
arches=None, overlays=None, overlay_pockets=None,
overlay_components=None, rebuild=True)
self.layer.switchDbUser('initializedistroseries')
job.run()
self.assertEqual(
'amd64',
child.nominatedarchindep.architecturetag)
def test_cronscript(self):
run_script(
'cronscripts/run_jobs.py', ['-v', 'initializedistroseries'])
|