~launchpad-pqm/launchpad/devel

« back to all changes in this revision

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

  • Committer: Launchpad Patch Queue Manager
  • Date: 2011-07-20 19:37:38 UTC
  • mfrom: (13474.2.6 reject-syncs-bug-812825)
  • Revision ID: launchpad@pqm.canonical.com-20110720193738-f2wn3z83lin1j3pv
[r=julian-edwards][bug=812825] Fix a problem where package copy job
        syncs to distros can be left stranded in the ACCEPTED upload
        queue if the job fails or raises CannotCopy.

Show diffs side-by-side

added added

removed removed

Lines of Context:
103
103
        """Helper to switch to the right DB user and run the job."""
104
104
        self.layer.txn.commit()
105
105
        self.layer.switchDbUser(self.dbuser)
 
106
        # Set the state to RUNNING.
 
107
        job.start()
 
108
        # Commit the RUNNING state.
 
109
        self.layer.txn.commit()
106
110
        job.run()
107
111
 
108
112
 
926
930
            self.assertEqual(
927
931
                policy, naked_job.getPolicyImplementation().enum_value)
928
932
 
 
933
    def test_rejects_PackageUpload_when_job_fails(self):
 
934
        # If a PCJ with a PU fails when running then we need to ensure the
 
935
        # PU gets rejected.
 
936
        target_archive = self.factory.makeArchive(
 
937
            purpose=ArchivePurpose.PRIMARY)
 
938
        source_archive = self.factory.makeArchive()
 
939
        source_pub = self.factory.makeSourcePackagePublishingHistory(
 
940
            sourcepackagename="copyme",
 
941
            version="1.0",
 
942
            archive=source_archive,
 
943
            status=PackagePublishingStatus.PUBLISHED)
 
944
        job_source = getUtility(IPlainPackageCopyJobSource)
 
945
        requester = self.factory.makePerson()
 
946
        job = job_source.create(
 
947
            package_name="copyme",
 
948
            package_version="1.0",
 
949
            source_archive=source_archive,
 
950
            target_archive=target_archive,
 
951
            target_distroseries=source_pub.distroseries,
 
952
            target_pocket=PackagePublishingPocket.RELEASE,
 
953
            include_binaries=False,
 
954
            requester=requester)
 
955
 
 
956
        # Run the job so it gains a PackageUpload.
 
957
        self.assertRaises(SuspendJobException, self.runJob, job)
 
958
        # Simulate the job runner suspending after getting a
 
959
        # SuspendJobException
 
960
        job.suspend()
 
961
        self.layer.txn.commit()
 
962
        self.layer.switchDbUser("launchpad_main")
 
963
 
 
964
        # Accept the upload to release the job then run it.
 
965
        pu = getUtility(IPackageUploadSet).getByPackageCopyJobIDs(
 
966
            [removeSecurityProxy(job).context.id]).one()
 
967
        pu.acceptFromQueue()
 
968
        self.runJob(job)
 
969
 
 
970
        # The copy will have failed because the requester has no permission
 
971
        # to upload to the archive we created. The job should have set the
 
972
        # PU status to REJECTED.
 
973
        self.assertEqual(PackageUploadStatus.REJECTED, pu.status)
 
974
 
929
975
 
930
976
class TestPlainPackageCopyJobPermissions(TestCaseWithFactory):
931
977