455
476
self.assertEqual(
456
477
{}, job_source.getPendingJobsPerPackage(dsd.derived_series))
479
def test_copying_to_main_archive_ancestry_overrides(self):
480
# The job will complete right away for auto-approved copies to a
481
# main archive and apply any ancestry overrides.
482
publisher = SoyuzTestPublisher()
483
publisher.prepareBreezyAutotest()
484
distroseries = publisher.breezy_autotest
486
target_archive = self.factory.makeArchive(
487
distroseries.distribution, purpose=ArchivePurpose.PRIMARY)
488
source_archive = self.factory.makeArchive()
490
# Publish a package in the source archive with some overridable
491
# properties set to known values.
492
source_package = publisher.getPubSource(
493
distroseries=distroseries, sourcename="libc",
494
component='universe', section='web',
495
version="2.8-1", status=PackagePublishingStatus.PUBLISHED,
496
archive=source_archive)
498
# Now put the same named package in the target archive with
499
# different override values.
500
ancestry_package = publisher.getPubSource(
501
distroseries=distroseries, sourcename="libc",
502
component='restricted', section='games',
503
version="2.8-0", status=PackagePublishingStatus.PUBLISHED,
504
archive=target_archive)
506
# Now, run the copy job, which should auto-approve the copy and
507
# override the package with the existing values in the
510
source = getUtility(IPlainPackageCopyJobSource)
513
package_version="2.8-1",
514
source_archive=source_archive,
515
target_archive=target_archive,
516
target_distroseries=distroseries,
517
target_pocket=PackagePublishingPocket.RELEASE,
518
include_binaries=False)
522
new_publication = target_archive.getPublishedSources(
523
name='libc', version='2.8-1').one()
524
self.assertEqual('restricted', new_publication.component.name)
525
self.assertEqual('games', new_publication.section.name)
527
def test_copying_to_main_archive_manual_overrides(self):
528
# Test processing a packagecopyjob that has manual overrides.
529
publisher = SoyuzTestPublisher()
530
publisher.prepareBreezyAutotest()
531
distroseries = publisher.breezy_autotest
533
target_archive = self.factory.makeArchive(
534
distroseries.distribution, purpose=ArchivePurpose.PRIMARY)
535
source_archive = self.factory.makeArchive()
537
# Publish a package in the source archive with some overridable
538
# properties set to known values.
539
source_package = publisher.getPubSource(
540
distroseries=distroseries, sourcename="copyme",
541
component='universe', section='web',
542
version="2.8-1", status=PackagePublishingStatus.PUBLISHED,
543
archive=source_archive)
545
# Now, run the copy job, which should raise an error because
546
# there's no ancestry.
547
source = getUtility(IPlainPackageCopyJobSource)
549
package_name="copyme",
550
package_version="2.8-1",
551
source_archive=source_archive,
552
target_archive=target_archive,
553
target_distroseries=distroseries,
554
target_pocket=PackagePublishingPocket.RELEASE,
555
include_binaries=False)
557
self.assertRaises(SuspendJobException, self.runJob, job)
558
# Simulate the job runner suspending after getting a
559
# SuspendJobException
561
self.layer.txn.commit()
562
self.layer.switchDbUser("launchpad_main")
564
# Add some overrides to the job.
565
package = source_package.sourcepackagerelease.sourcepackagename
566
restricted = getUtility(IComponentSet)['restricted']
567
editors = getUtility(ISectionSet)['editors']
568
override = SourceOverride(package, restricted, editors)
569
job.addSourceOverride(override)
571
# Accept the upload to release the job then run it.
572
pu = getUtility(IPackageUploadSet).getByPackageCopyJobIDs(
573
[removeSecurityProxy(job).context.id]).one()
577
# The copied source should have the manual overrides, not the
579
new_publication = target_archive.getPublishedSources(
580
name='copyme', version='2.8-1').one()
581
self.assertEqual('restricted', new_publication.component.name)
582
self.assertEqual('editors', new_publication.section.name)
584
def test_copying_to_main_archive_with_no_ancestry(self):
585
# The job should suspend itself and create a packageupload with
586
# a reference to the package_copy_job.
587
publisher = SoyuzTestPublisher()
588
publisher.prepareBreezyAutotest()
589
distroseries = publisher.breezy_autotest
591
target_archive = self.factory.makeArchive(
592
distroseries.distribution, purpose=ArchivePurpose.PRIMARY)
593
source_archive = self.factory.makeArchive()
595
# Publish a package in the source archive with some overridable
596
# properties set to known values.
597
source_package = publisher.getPubSource(
598
distroseries=distroseries, sourcename="copyme",
599
component='multiverse', section='web',
600
version="2.8-1", status=PackagePublishingStatus.PUBLISHED,
601
archive=source_archive)
603
# There is no package of the same name already in the target
605
existing_sources = target_archive.getPublishedSources(name='copyme')
606
self.assertEqual(None, existing_sources.any())
608
# Now, run the copy job.
610
source = getUtility(IPlainPackageCopyJobSource)
612
package_name="copyme",
613
package_version="2.8-1",
614
source_archive=source_archive,
615
target_archive=target_archive,
616
target_distroseries=distroseries,
617
target_pocket=PackagePublishingPocket.RELEASE,
618
include_binaries=False)
620
# The job should be suspended and there's a PackageUpload with
621
# its package_copy_job set.
622
self.assertRaises(SuspendJobException, self.runJob, job)
623
pu = Store.of(target_archive).find(
625
PackageUpload.package_copy_job_id == job.id).one()
626
pcj = removeSecurityProxy(job).context
627
self.assertEqual(pcj, pu.package_copy_job)
629
# The job metadata should contain default overrides from the
630
# UnknownOverridePolicy policy.
631
self.assertEqual('universe', pcj.metadata['component_override'])
633
def test_copying_to_main_archive_unapproved(self):
634
# Uploading to a series that is in a state that precludes auto
635
# approval will cause the job to suspend and a packageupload
636
# created in the UNAPPROVED state.
637
publisher = SoyuzTestPublisher()
638
publisher.prepareBreezyAutotest()
639
distroseries = publisher.breezy_autotest
640
# The series is frozen so it won't auto-approve new packages.
641
distroseries.status = SeriesStatus.FROZEN
643
target_archive = self.factory.makeArchive(
644
distroseries.distribution, purpose=ArchivePurpose.PRIMARY)
645
source_archive = self.factory.makeArchive()
647
# Publish a package in the source archive.
648
source_package = publisher.getPubSource(
649
distroseries=distroseries, sourcename="copyme",
650
version="2.8-1", status=PackagePublishingStatus.PUBLISHED,
651
component='multiverse', section='web',
652
archive=source_archive)
654
# Now put the same named package in the target archive so it has
656
ancestry_package = publisher.getPubSource(
657
distroseries=distroseries, sourcename="copyme",
658
version="2.8-0", status=PackagePublishingStatus.PUBLISHED,
659
component='main', section='games',
660
archive=target_archive)
662
# Now, run the copy job.
663
source = getUtility(IPlainPackageCopyJobSource)
665
package_name="copyme",
666
package_version="2.8-1",
667
source_archive=source_archive,
668
target_archive=target_archive,
669
target_distroseries=distroseries,
670
target_pocket=PackagePublishingPocket.RELEASE,
671
include_binaries=False)
673
# The job should be suspended and there's a PackageUpload with
674
# its package_copy_job set in the UNAPPROVED queue.
675
self.assertRaises(SuspendJobException, self.runJob, job)
677
pu = Store.of(target_archive).find(
679
PackageUpload.package_copy_job_id == job.id).one()
680
pcj = removeSecurityProxy(job).context
681
self.assertEqual(pcj, pu.package_copy_job)
682
self.assertEqual(PackageUploadStatus.UNAPPROVED, pu.status)
684
# The job's metadata should contain the override ancestry from
685
# the target archive.
686
self.assertEqual('main', pcj.metadata['component_override'])
688
def test_copying_after_job_released(self):
689
# The first pass of the job may have created a PackageUpload and
690
# suspended the job. Here we test the second run to make sure
691
# that it actually copies the package.
692
publisher = SoyuzTestPublisher()
693
publisher.prepareBreezyAutotest()
694
distroseries = publisher.breezy_autotest
696
target_archive = self.factory.makeArchive(
697
distroseries.distribution, purpose=ArchivePurpose.PRIMARY)
698
source_archive = self.factory.makeArchive()
700
# Publish a package in the source archive.
701
source_package = publisher.getPubSource(
702
distroseries=distroseries, sourcename="copyme",
703
version="2.8-1", status=PackagePublishingStatus.PUBLISHED,
704
archive=source_archive)
706
source = getUtility(IPlainPackageCopyJobSource)
708
package_name="copyme",
709
package_version="2.8-1",
710
source_archive=source_archive,
711
target_archive=target_archive,
712
target_distroseries=distroseries,
713
target_pocket=PackagePublishingPocket.RELEASE,
714
include_binaries=False)
716
# Run the job so it gains a PackageUpload.
717
self.assertRaises(SuspendJobException, self.runJob, job)
718
# Simulate the job runner suspending after getting a
719
# SuspendJobException
721
self.layer.txn.commit()
722
self.layer.switchDbUser("launchpad_main")
724
# Accept the upload to release the job then run it.
725
pu = getUtility(IPackageUploadSet).getByPackageCopyJobIDs(
726
[removeSecurityProxy(job).context.id]).one()
730
existing_sources = target_archive.getPublishedSources(name='copyme')
731
self.assertIsNot(None, existing_sources.any())
458
733
def test_findMatchingDSDs_matches_all_DSDs_for_job(self):
459
734
# findMatchingDSDs finds matching DSDs for any of the packages