~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/soyuz/tests/test_distroseriesdifferencejob.py

Merge db-devel.

Show diffs side-by-side

added added

removed removed

Lines of Context:
9
9
from psycopg2 import ProgrammingError
10
10
from zope.component import getUtility
11
11
from zope.interface.verify import verifyObject
 
12
from zope.security.proxy import removeSecurityProxy
12
13
 
13
14
from canonical.launchpad.interfaces.lpstorm import IMasterStore
14
15
from canonical.launchpad.scripts.tests import run_script
26
27
from lp.services.job.interfaces.job import JobStatus
27
28
from lp.soyuz.enums import PackagePublishingStatus
28
29
from lp.soyuz.interfaces.distributionjob import (
 
30
    DistributionJobType,
29
31
    IDistroSeriesDifferenceJobSource,
30
32
    )
 
33
from lp.soyuz.model.distributionjob import DistributionJob
31
34
from lp.soyuz.model.distroseriesdifferencejob import (
32
35
    create_job,
33
36
    DistroSeriesDifferenceJob,
52
55
        return getUtility(IDistroSeriesDifferenceJobSource)
53
56
 
54
57
    def makeDerivedDistroSeries(self):
55
 
        return self.factory.makeDistroSeries(
56
 
            previous_series=self.factory.makeDistroSeries())
 
58
        dsp = self.factory.makeDistroSeriesParent()
 
59
        return dsp.derived_series
57
60
 
58
61
    def test_baseline(self):
59
62
        verifyObject(IDistroSeriesDifferenceJobSource, self.getJobSource())
108
111
        dsdjob = create_job(distroseries, package)
109
112
        self.assertEqual(JobStatus.WAITING, dsdjob.job.status)
110
113
 
111
 
    def find_waiting_jobs_finds_waiting_jobs(self):
 
114
    def test_find_waiting_jobs_finds_waiting_jobs(self):
112
115
        sourcepackage = self.factory.makeSourcePackage()
113
116
        distroseries, sourcepackagename = (
114
117
            sourcepackage.distroseries, sourcepackage.distroseries)
115
118
        job = create_job(distroseries, sourcepackagename)
116
 
        self.assertContentEqual(
117
 
            [job], find_waiting_jobs(distroseries, sourcepackagename))
 
119
        found_jobs = find_waiting_jobs(distroseries, sourcepackagename)
 
120
        self.assertEqual([job], [
 
121
            DistroSeriesDifferenceJob(found_job)
 
122
            for found_job in found_jobs])
118
123
 
119
 
    def find_waiting_jobs_ignores_other_series(self):
 
124
    def test_find_waiting_jobs_ignores_other_series(self):
120
125
        sourcepackage = self.factory.makeSourcePackage()
121
126
        distroseries, sourcepackagename = (
122
127
            sourcepackage.distroseries, sourcepackage.distroseries)
125
130
        self.assertContentEqual(
126
131
            [], find_waiting_jobs(other_series, sourcepackagename))
127
132
 
128
 
    def find_waiting_jobs_ignores_other_packages(self):
 
133
    def test_find_waiting_jobs_ignores_other_packages(self):
129
134
        sourcepackage = self.factory.makeSourcePackage()
130
135
        distroseries, sourcepackagename = (
131
136
            sourcepackage.distroseries, sourcepackage.distroseries)
134
139
        self.assertContentEqual(
135
140
            [], find_waiting_jobs(distroseries, other_spn))
136
141
 
137
 
    def find_waiting_jobs_considers_only_waiting_jobs(self):
 
142
    def test_find_waiting_jobs_considers_only_waiting_jobs(self):
138
143
        sourcepackage = self.factory.makeSourcePackage()
139
144
        distroseries, sourcepackagename = (
140
145
            sourcepackage.distroseries, sourcepackage.distroseries)
147
152
            [], find_waiting_jobs(distroseries, sourcepackagename))
148
153
 
149
154
    def test_createForPackagedPublication_creates_jobs_for_its_child(self):
150
 
        derived_series = self.factory.makeDistroSeries(
151
 
            previous_series=self.makeDerivedDistroSeries())
 
155
        dsp = self.factory.makeDistroSeriesParent()
 
156
        parent_dsp = self.factory.makeDistroSeriesParent(
 
157
            derived_series=dsp.parent_series)
152
158
        package = self.factory.makeSourcePackageName()
153
159
        # Create a job for the derived_series parent, which should create
154
160
        # two jobs. One for derived_series, and the other for its child.
155
161
        self.getJobSource().createForPackagePublication(
156
 
            derived_series.previous_series, package,
 
162
            dsp.parent_series, package,
157
163
            PackagePublishingPocket.RELEASE)
158
164
        jobs = (list(
159
 
            find_waiting_jobs(derived_series.previous_series, package)) +
160
 
            list(find_waiting_jobs(derived_series, package)))
 
165
            find_waiting_jobs(dsp.parent_series, package)) +
 
166
            list(find_waiting_jobs(dsp.derived_series, package)))
161
167
        self.assertEqual(2, len(jobs))
162
168
        self.assertEqual(package.id, jobs[0].metadata['sourcepackagename'])
163
169
        self.assertEqual(package.id, jobs[1].metadata['sourcepackagename'])
164
170
        # Lastly, a job was not created for the grandparent.
165
 
        jobs = list(
166
 
            find_waiting_jobs(derived_series.previous_series.previous_series,
167
 
                package))
 
171
        jobs = list(find_waiting_jobs(parent_dsp.parent_series, package))
168
172
        self.assertEqual(0, len(jobs))
169
173
 
170
174
    def test_createForPackagePublication_creates_job_for_derived_series(self):
193
197
            distroseries, package, PackagePublishingPocket.PROPOSED)
194
198
        self.assertContentEqual([], find_waiting_jobs(distroseries, package))
195
199
 
 
200
    def test_getPendingJobsForDifferences_finds_job(self):
 
201
        dsd = self.factory.makeDistroSeriesDifference()
 
202
        job = create_job(dsd.derived_series, dsd.source_package_name)
 
203
        self.assertEqual(
 
204
            {dsd: [job]},
 
205
            self.getJobSource().getPendingJobsForDifferences(
 
206
                dsd.derived_series, [dsd]))
 
207
 
 
208
    def test_getPendingJobsForDifferences_ignores_other_package(self):
 
209
        dsd = self.factory.makeDistroSeriesDifference()
 
210
        create_job(dsd.derived_series, self.factory.makeSourcePackageName())
 
211
        self.assertEqual(
 
212
            {},
 
213
            self.getJobSource().getPendingJobsForDifferences(
 
214
                dsd.derived_series, [dsd]))
 
215
 
 
216
    def test_getPendingJobsForDifferences_ignores_other_derived_series(self):
 
217
        dsd = self.factory.makeDistroSeriesDifference()
 
218
        create_job(self.makeDerivedDistroSeries(), dsd.source_package_name)
 
219
        self.assertEqual(
 
220
            {},
 
221
            self.getJobSource().getPendingJobsForDifferences(
 
222
                dsd.derived_series, [dsd]))
 
223
 
 
224
    def test_getPendingJobsForDifferences_ignores_other_parent_series(self):
 
225
        # XXX JeroenVermeulen 2011-05-26 bug=758906: Can't test this
 
226
        # until we can specify the right parent series when creating a
 
227
        # job.
 
228
        return
 
229
 
 
230
    def test_getPendingJobsForDifferences_ignores_non_pending_jobs(self):
 
231
        dsd = self.factory.makeDistroSeriesDifference()
 
232
        job = create_job(dsd.derived_series, dsd.source_package_name)
 
233
        removeSecurityProxy(job).job._status = JobStatus.COMPLETED
 
234
        self.assertEqual(
 
235
            {},
 
236
            self.getJobSource().getPendingJobsForDifferences(
 
237
                dsd.derived_series, [dsd]))
 
238
 
 
239
    def test_getPendingJobsForDifferences_ignores_other_job_types(self):
 
240
        # XXX JeroenVermeulen 2011-05-26 bug=758906: Once parent_series
 
241
        # is incorporated into the job type, set it to dsd.parent_series
 
242
        # on the fake job, or this test will become silently meaningless.
 
243
        dsd = self.factory.makeDistroSeriesDifference()
 
244
        DistributionJob(
 
245
            distribution=dsd.derived_series.distribution,
 
246
            distroseries=dsd.derived_series,
 
247
            job_type=DistributionJobType.INITIALISE_SERIES,
 
248
            metadata={"sourcepackagename": dsd.source_package_name.id})
 
249
        self.assertEqual(
 
250
            {},
 
251
            self.getJobSource().getPendingJobsForDifferences(
 
252
                dsd.derived_series, [dsd]))
 
253
 
196
254
    def test_cronscript(self):
197
255
        derived_series = self.makeDerivedDistroSeries()
198
256
        package = self.factory.makeSourcePackageName()
242
300
        self.assertEqual(1, ds_diff.count())
243
301
 
244
302
    def test_packageset_filter_passes_inherited_packages(self):
245
 
        derived_series = self.makeDerivedDistroSeries()
246
 
        previous_series = derived_series.previous_series
 
303
        dsp = self.factory.makeDistroSeriesParent()
247
304
        # Parent must have a packageset or the filter will pass anyway.
248
 
        self.factory.makePackageset(distroseries=previous_series)
 
305
        self.factory.makePackageset(distroseries=dsp.parent_series)
249
306
        package = self.factory.makeSourcePackageName()
250
307
        # Package is not in the packageset _but_ both the parent and
251
308
        # derived series have it.
252
309
        self.factory.makeSourcePackagePublishingHistory(
253
 
            distroseries=previous_series, sourcepackagename=package)
 
310
            distroseries=dsp.parent_series, sourcepackagename=package)
254
311
        self.factory.makeSourcePackagePublishingHistory(
255
 
            distroseries=derived_series, sourcepackagename=package)
256
 
        job = create_job(derived_series, package)
 
312
            distroseries=dsp.derived_series, sourcepackagename=package)
 
313
        job = create_job(dsp.derived_series, package)
257
314
        self.assertTrue(job.passesPackagesetFilter())
258
315
 
259
316
    def test_packageset_filter_passes_packages_unique_to_derived_series(self):
260
 
        derived_series = self.makeDerivedDistroSeries()
261
 
        previous_series = derived_series.previous_series
 
317
        dsp = self.factory.makeDistroSeriesParent()
262
318
        # Parent must have a packageset or the filter will pass anyway.
263
 
        self.factory.makePackageset(distroseries=previous_series)
 
319
        self.factory.makePackageset(distroseries=dsp.parent_series)
264
320
        package = self.factory.makeSourcePackageName()
265
321
        # Package exists in the derived series but not in the parent
266
322
        # series.
267
323
        self.factory.makeSourcePackagePublishingHistory(
268
 
            distroseries=derived_series, sourcepackagename=package)
269
 
        job = create_job(derived_series, package)
 
324
            distroseries=dsp.derived_series, sourcepackagename=package)
 
325
        job = create_job(dsp.derived_series, package)
270
326
        self.assertTrue(job.passesPackagesetFilter())
271
327
 
272
328
    def test_packageset_filter_passes_all_if_parent_has_no_packagesets(self):
273
329
        # Debian in particular has no packagesets.  If the parent series
274
330
        # has no packagesets, the packageset filter passes all packages.
275
 
        derived_series = self.makeDerivedDistroSeries()
276
 
        previous_series = derived_series.previous_series
 
331
        dsp = self.factory.makeDistroSeriesParent()
277
332
        package = self.factory.makeSourcePackageName()
278
333
        self.factory.makeSourcePackagePublishingHistory(
279
 
            distroseries=previous_series, sourcepackagename=package)
280
 
        job = create_job(derived_series, package)
 
334
            distroseries=dsp.parent_series, sourcepackagename=package)
 
335
        job = create_job(dsp.derived_series, package)
281
336
        self.assertTrue(job.passesPackagesetFilter())
282
337
 
283
 
    def makeInheritedPackageSet(self, derived_series, packages=()):
 
338
    def makeInheritedPackageSet(self, distro_series_parent, packages=()):
284
339
        """Simulate an inherited `Packageset`.
285
340
 
286
341
        Creates a packageset in the parent that has an equivalent in
287
342
        `derived_series`.
288
343
        """
289
 
        previous_series = derived_series.previous_series
290
344
        parent_packageset = self.factory.makePackageset(
291
 
            distroseries=previous_series, packages=packages)
292
 
        derived_packageset = self.factory.makePackageset(
293
 
            distroseries=derived_series, packages=packages,
294
 
            name=parent_packageset.name, owner=parent_packageset.owner,
295
 
            related_set=parent_packageset)
 
345
            distroseries=distro_series_parent.parent_series,
 
346
            packages=packages)
 
347
        self.factory.makePackageset(
 
348
            distroseries=distro_series_parent.derived_series,
 
349
            packages=packages, name=parent_packageset.name,
 
350
            owner=parent_packageset.owner, related_set=parent_packageset)
296
351
 
297
352
    def test_packageset_filter_passes_package_in_inherited_packageset(self):
298
 
        derived_series = self.makeDerivedDistroSeries()
299
 
        previous_series = derived_series.previous_series
 
353
        dsp = self.factory.makeDistroSeriesParent()
300
354
        # Package is in a packageset on the parent that the derived
301
355
        # series also has.
302
356
        package = self.factory.makeSourcePackageName()
303
 
        self.makeInheritedPackageSet(derived_series, [package])
 
357
        self.makeInheritedPackageSet(dsp, [package])
304
358
        # Package is in parent series and in a packageset that the
305
359
        # derived series inherited.
306
360
        self.factory.makeSourcePackagePublishingHistory(
307
 
            distroseries=previous_series, sourcepackagename=package)
308
 
        job = create_job(derived_series, package)
 
361
            distroseries=dsp.parent_series, sourcepackagename=package)
 
362
        job = create_job(dsp.derived_series, package)
309
363
        self.assertTrue(job.passesPackagesetFilter())
310
364
 
311
365
    def test_packageset_filter_blocks_unwanted_parent_package(self):
312
 
        derived_series = self.makeDerivedDistroSeries()
313
 
        previous_series = derived_series.previous_series
314
 
        self.makeInheritedPackageSet(derived_series)
 
366
        dsp = self.factory.makeDistroSeriesParent()
 
367
        self.makeInheritedPackageSet(dsp)
315
368
        package = self.factory.makeSourcePackageName()
316
369
        # Package is in the parent series but not in a packageset shared
317
370
        # between the derived series and the parent series.
318
371
        self.factory.makeSourcePackagePublishingHistory(
319
 
            distroseries=previous_series, sourcepackagename=package)
320
 
        job = create_job(derived_series, package)
 
372
            distroseries=dsp.parent_series, sourcepackagename=package)
 
373
        job = create_job(dsp.derived_series, package)
321
374
        self.assertFalse(job.passesPackagesetFilter())
322
375
 
323
376
 
334
387
        return getUtility(IDistroSeriesDifferenceJobSource)
335
388
 
336
389
    def makeDerivedDistroSeries(self):
337
 
        return self.factory.makeDistroSeries(
338
 
            previous_series=self.factory.makeDistroSeries())
 
390
        dsp = self.factory.makeDistroSeriesParent()
 
391
        return dsp
339
392
 
340
393
    def createPublication(self, source_package_name, versions, distroseries,
341
394
                          archive=None):
373
426
    def test_parent_gets_newer(self):
374
427
        # When a new source package is uploaded to the parent distroseries,
375
428
        # a job is created that updates the relevant DSD.
376
 
        derived_series = self.makeDerivedDistroSeries()
 
429
        dsp = self.makeDerivedDistroSeries()
 
430
        derived_series = dsp.derived_series
377
431
        source_package_name = self.factory.makeSourcePackageName()
378
432
        self.createPublication(
379
433
            source_package_name, ['1.0-1derived1', '1.0-1'], derived_series)
380
434
        self.createPublication(
381
 
            source_package_name, ['1.0-1'], derived_series.previous_series)
 
435
            source_package_name, ['1.0-1'], dsp.parent_series)
382
436
        # Creating the SPPHs has created jobs for us, so grab it off the
383
437
        # queue.
384
438
        jobs = find_waiting_jobs(derived_series, source_package_name)
391
445
        # Now create a 1.0-2 upload to the parent.
392
446
        self.createPublication(
393
447
            source_package_name, ['1.0-2', '1.0-1'],
394
 
            derived_series.previous_series)
 
448
            dsp.parent_series)
395
449
        jobs = find_waiting_jobs(derived_series, source_package_name)
396
450
        self.runJob(jobs[0])
397
451
        # And the DSD we have a hold of will have updated.
401
455
 
402
456
    def test_child_gets_newer(self):
403
457
        # When a new source is uploaded to the child distroseries, the DSD is
404
 
        # updated.
405
 
        derived_series = self.makeDerivedDistroSeries()
 
458
        # updated and auto-blacklisted.
 
459
        dsp = self.makeDerivedDistroSeries()
 
460
        derived_series = dsp.derived_series
406
461
        source_package_name = self.factory.makeSourcePackageName()
407
462
        self.createPublication(
408
463
            source_package_name, ['1.0-1'], derived_series)
409
464
        self.createPublication(
410
 
            source_package_name, ['1.0-1'], derived_series.previous_series)
 
465
            source_package_name, ['1.0-1'], dsp.parent_series)
411
466
        jobs = find_waiting_jobs(derived_series, source_package_name)
412
467
        self.runJob(jobs[0])
413
468
        ds_diff = self.findDSD(derived_series, source_package_name)
418
473
        jobs = find_waiting_jobs(derived_series, source_package_name)
419
474
        self.runJob(jobs[0])
420
475
        self.assertEqual(
421
 
            DistroSeriesDifferenceStatus.NEEDS_ATTENTION, ds_diff[0].status)
 
476
            DistroSeriesDifferenceStatus.BLACKLISTED_CURRENT,
 
477
            ds_diff[0].status)
422
478
        self.assertEqual('1.0-1', ds_diff[0].base_version)
423
479
 
424
480
    def test_child_is_synced(self):
425
481
        # If the source package gets 'synced' to the child from the parent,
426
482
        # the job correctly updates the DSD.
427
 
        derived_series = self.makeDerivedDistroSeries()
 
483
        dsp = self.makeDerivedDistroSeries()
 
484
        derived_series = dsp.derived_series
428
485
        source_package_name = self.factory.makeSourcePackageName()
429
486
        self.createPublication(
430
487
            source_package_name, ['1.0-1derived1', '1.0-1'], derived_series)
431
488
        self.createPublication(
432
 
            source_package_name, ['1.0-2', '1.0-1'],
433
 
            derived_series.previous_series)
 
489
            source_package_name, ['1.0-2', '1.0-1'], dsp.parent_series)
434
490
        jobs = find_waiting_jobs(derived_series, source_package_name)
435
491
        self.runJob(jobs[0])
436
492
        ds_diff = self.findDSD(derived_series, source_package_name)
445
501
    def test_only_in_child(self):
446
502
        # If a source package only exists in the child distroseries, the DSD
447
503
        # is created with the right type.
448
 
        derived_series = self.makeDerivedDistroSeries()
 
504
        dsp = self.makeDerivedDistroSeries()
 
505
        derived_series = dsp.derived_series
449
506
        source_package_name = self.factory.makeSourcePackageName()
450
507
        self.createPublication(
451
508
            source_package_name, ['1.0-0derived1'], derived_series)
459
516
    def test_only_in_parent(self):
460
517
        # If a source package only exists in the parent distroseries, the DSD
461
518
        # is created with the right type.
462
 
        derived_series = self.makeDerivedDistroSeries()
 
519
        dsp = self.makeDerivedDistroSeries()
 
520
        derived_series = dsp.derived_series
463
521
        source_package_name = self.factory.makeSourcePackageName()
464
522
        self.createPublication(
465
 
            source_package_name, ['1.0-1'],
466
 
            derived_series.previous_series)
 
523
            source_package_name, ['1.0-1'], dsp.parent_series)
467
524
        jobs = find_waiting_jobs(derived_series, source_package_name)
468
525
        self.runJob(jobs[0])
469
526
        ds_diff = self.findDSD(derived_series, source_package_name)
474
531
    def test_deleted_in_parent(self):
475
532
        # If a source package is deleted in the parent, a job is created, and
476
533
        # the DSD is updated correctly.
477
 
        derived_series = self.makeDerivedDistroSeries()
 
534
        dsp = self.makeDerivedDistroSeries()
 
535
        derived_series = dsp.derived_series
478
536
        source_package_name = self.factory.makeSourcePackageName()
479
537
        self.createPublication(
480
538
            source_package_name, ['1.0-1'], derived_series)
481
539
        spph = self.createPublication(
482
 
            source_package_name, ['1.0-1'], derived_series.previous_series)
 
540
            source_package_name, ['1.0-1'], dsp.parent_series)
483
541
        jobs = find_waiting_jobs(derived_series, source_package_name)
484
542
        self.runJob(jobs[0])
485
543
        ds_diff = self.findDSD(derived_series, source_package_name)
495
553
    def test_deleted_in_child(self):
496
554
        # If a source package is deleted in the child, a job is created, and
497
555
        # the DSD is updated correctly.
498
 
        derived_series = self.makeDerivedDistroSeries()
 
556
        dsp = self.makeDerivedDistroSeries()
 
557
        derived_series = dsp.derived_series
499
558
        source_package_name = self.factory.makeSourcePackageName()
500
559
        spph = self.createPublication(
501
560
            source_package_name, ['1.0-1'], derived_series)
502
561
        self.createPublication(
503
 
            source_package_name, ['1.0-1'], derived_series.previous_series)
 
562
            source_package_name, ['1.0-1'], dsp.parent_series)
504
563
        jobs = find_waiting_jobs(derived_series, source_package_name)
505
564
        self.runJob(jobs[0])
506
565
        ds_diff = self.findDSD(derived_series, source_package_name)
515
574
 
516
575
    def test_no_job_for_PPA(self):
517
576
        # If a source package is uploaded to a PPA, a job is not created.
518
 
        derived_series = self.makeDerivedDistroSeries()
 
577
        dsp = self.makeDerivedDistroSeries()
 
578
        derived_series = dsp.derived_series
519
579
        source_package_name = self.factory.makeSourcePackageName()
520
580
        ppa = self.factory.makeArchive()
521
581
        self.createPublication(
525
585
 
526
586
    def test_no_job_for_PPA_with_deleted_source(self):
527
587
        # If a source package is deleted from a PPA, no job is created.
528
 
        derived_series = self.makeDerivedDistroSeries()
 
588
        dsp = self.makeDerivedDistroSeries()
 
589
        derived_series = dsp.derived_series
529
590
        source_package_name = self.factory.makeSourcePackageName()
530
591
        ppa = self.factory.makeArchive()
531
592
        spph = self.createPublication(
536
597
 
537
598
    def test_update_deletes_diffs(self):
538
599
        # When a DSD is updated, the diffs are invalidated.
539
 
        derived_series = self.makeDerivedDistroSeries()
 
600
        dsp = self.makeDerivedDistroSeries()
 
601
        derived_series = dsp.derived_series
540
602
        source_package_name = self.factory.makeSourcePackageName()
541
603
        self.createPublication(
542
604
            source_package_name, ['1.0-1derived1', '1.0-1'], derived_series)
543
605
        self.createPublication(
544
 
            source_package_name, ['1.0-2', '1.0-1'],
545
 
            derived_series.previous_series)
 
606
            source_package_name, ['1.0-2', '1.0-1'], dsp.parent_series)
546
607
        spr = self.factory.makeSourcePackageRelease(
547
608
            sourcepackagename=source_package_name, version='1.0-1')
548
609
        self.factory.makeSourcePackagePublishingHistory(
549
610
            sourcepackagerelease=spr,
550
 
            archive=derived_series.previous_series.main_archive,
551
 
            distroseries=derived_series.previous_series,
 
611
            archive=dsp.parent_series.main_archive,
 
612
            distroseries=dsp.parent_series,
552
613
            status=PackagePublishingStatus.SUPERSEDED)
553
614
        jobs = find_waiting_jobs(derived_series, source_package_name)
554
615
        self.runJob(jobs[0])
558
619
        self.assertIsNot(None, ds_diff[0].parent_package_diff)
559
620
        self.createPublication(
560
621
            source_package_name, ['1.0-3', '1.0-2', '1.0-1'],
561
 
            derived_series.previous_series)
 
622
            dsp.parent_series)
562
623
        jobs = find_waiting_jobs(derived_series, source_package_name)
563
624
        self.runJob(jobs[0])
564
625
        # Since the diff showing the changes from 1.0-1 to 1.0-1derived1 is