Esempio n. 1
0
    def test_can_find_build_in_derived_distro_parent(self):
        # If a derived distribution inherited its binaries from its
        # parent then findBuiltOrPublishedBySourceAndArchive() should
        # look in the parent to find the build.
        dsp = self.factory.makeDistroSeriesParent()
        parent_archive = dsp.parent_series.main_archive

        # Create a built, published package in the parent archive.
        spr = self.factory.makeSourcePackageRelease(architecturehintlist='any')
        parent_source_pub = self.factory.makeSourcePackagePublishingHistory(
            sourcepackagerelease=spr,
            archive=parent_archive,
            distroseries=dsp.parent_series)
        das = self.factory.makeDistroArchSeries(
            distroseries=dsp.parent_series,
            processor=self.factory.makeProcessor(supports_virtualized=True))
        orig_build = getUtility(IBinaryPackageBuildSet).new(
            spr,
            parent_archive,
            das,
            PackagePublishingPocket.RELEASE,
            status=BuildStatus.FULLYBUILT)
        bpr = self.factory.makeBinaryPackageRelease(build=orig_build)
        self.factory.makeBinaryPackagePublishingHistory(
            binarypackagerelease=bpr,
            distroarchseries=das,
            archive=parent_archive)

        # Make an architecture in the derived series with the same
        # archtag as the parent.
        das_derived = self.factory.makeDistroArchSeries(
            dsp.derived_series,
            architecturetag=das.architecturetag,
            processor=das.processor)
        # Now copy the package to the derived series, with binary.
        derived_archive = dsp.derived_series.main_archive
        getUtility(ISourcePackageFormatSelectionSet).add(
            dsp.derived_series, SourcePackageFormat.FORMAT_1_0)

        do_copy([parent_source_pub],
                derived_archive,
                dsp.derived_series,
                PackagePublishingPocket.RELEASE,
                include_binaries=True,
                check_permissions=False)

        # Searching for the build in the derived series architecture
        # should automatically pick it up from the parent.
        found_build = getUtility(
            IBinaryPackageBuildSet).findBuiltOrPublishedBySourceAndArchive(
                spr, derived_archive).get(das_derived.architecturetag)
        self.assertEqual(orig_build, found_build)
 def syncSource(self, spph, target_distroseries, requester):
     """Sync `spph` into `target_distroseries`."""
     getUtility(ISourcePackageFormatSelectionSet).add(
         target_distroseries, SourcePackageFormat.FORMAT_1_0)
     target_archive = target_distroseries.main_archive
     self.makeUploader(requester, target_archive, spph.component)
     [synced_spph] = do_copy(
         [spph], target_archive, target_distroseries,
         pocket=spph.pocket, person=requester, close_bugs=False)
     return synced_spph
    def test_can_find_build_in_derived_distro_parent(self):
        # If a derived distribution inherited its binaries from its
        # parent then getBuildByArch() should look in the parent to find
        # the build.
        dsp = self.factory.makeDistroSeriesParent()
        parent_archive = dsp.parent_series.main_archive

        # Create a built, published package in the parent archive.
        spr = self.factory.makeSourcePackageRelease(
            architecturehintlist='any')
        parent_source_pub = self.factory.makeSourcePackagePublishingHistory(
            sourcepackagerelease=spr, archive=parent_archive,
            distroseries=dsp.parent_series)
        das = self.factory.makeDistroArchSeries(
            distroseries=dsp.parent_series, supports_virtualized=True)
        orig_build = spr.createBuild(
            das, PackagePublishingPocket.RELEASE, parent_archive,
            status=BuildStatus.FULLYBUILT)
        bpr = self.factory.makeBinaryPackageRelease(build=orig_build)
        self.factory.makeBinaryPackagePublishingHistory(
            binarypackagerelease=bpr, distroarchseries=das,
            archive=parent_archive)

        # Make an architecture in the derived series with the same
        # archtag as the parent.
        das_derived = self.factory.makeDistroArchSeries(
            dsp.derived_series, architecturetag=das.architecturetag,
            processor=das.processor, supports_virtualized=True)
        # Now copy the package to the derived series, with binary.
        derived_archive = dsp.derived_series.main_archive
        getUtility(ISourcePackageFormatSelectionSet).add(
            dsp.derived_series, SourcePackageFormat.FORMAT_1_0)

        do_copy(
            [parent_source_pub], derived_archive, dsp.derived_series,
            PackagePublishingPocket.RELEASE, include_binaries=True,
            check_permissions=False)

        # Searching for the build in the derived series architecture
        # should automatically pick it up from the parent.
        found_build = spr.getBuildByArch(das_derived, derived_archive)
        self.assertEqual(orig_build, found_build)
Esempio n. 4
0
 def syncSource(self, spph, target_distroseries, requester):
     """Sync `spph` into `target_distroseries`."""
     getUtility(ISourcePackageFormatSelectionSet).add(
         target_distroseries, SourcePackageFormat.FORMAT_1_0)
     target_archive = target_distroseries.main_archive
     self.makeUploader(requester, target_archive, spph.component)
     [synced_spph] = do_copy([spph],
                             target_archive,
                             target_distroseries,
                             pocket=spph.pocket,
                             person=requester,
                             close_bugs=False)
     return synced_spph
    def attemptCopy(self):
        """Attempt to perform the copy.

        :raise CannotCopy: If the copy fails for a reason that the user
            can deal with.
        """
        reason = self.target_archive.checkUploadToPocket(
            self.target_distroseries,
            self.target_pocket,
            person=self.requester)
        if reason:
            # Wrap any forbidden-pocket error in CannotCopy.
            raise CannotCopy(unicode(reason))

        source_package = self.findSourcePublication()

        # If there's a PackageUpload associated with this job then this
        # job has just been released by an archive admin from the queue.
        # We don't need to check any policies, but the admin may have
        # set overrides which we will get from the job's metadata.
        pu = getUtility(IPackageUploadSet).getByPackageCopyJobIDs(
            [self.context.id]).any()
        if pu is None:
            source_name = getUtility(ISourcePackageNameSet)[self.package_name]
            self._checkPolicies(source_name,
                                source_package.sourcepackagerelease.component,
                                self.auto_approve)

        # The package is free to go right in, so just copy it now.
        ancestry = self.target_archive.getPublishedSources(
            name=self.package_name,
            distroseries=self.target_distroseries,
            pocket=self.target_pocket,
            exact_match=True)
        override = self.getSourceOverride()
        copy_policy = self.getPolicyImplementation()
        send_email = copy_policy.send_email(self.target_archive)
        copied_publications = do_copy(
            sources=[source_package],
            archive=self.target_archive,
            series=self.target_distroseries,
            pocket=self.target_pocket,
            include_binaries=self.include_binaries,
            check_permissions=True,
            person=self.requester,
            overrides=[override],
            send_email=send_email,
            announce_from_person=self.requester,
            sponsored=self.sponsored,
            packageupload=pu,
            unembargo=self.unembargo,
            phased_update_percentage=self.phased_update_percentage)

        # Add a PackageDiff for this new upload if it has ancestry.
        if copied_publications and not ancestry.is_empty():
            from_spr = None
            for publication in copied_publications:
                if ISourcePackagePublishingHistory.providedBy(publication):
                    from_spr = publication.sourcepackagerelease
                    break
            if from_spr:
                for ancestor in ancestry:
                    to_spr = ancestor.sourcepackagerelease
                    if from_spr != to_spr:
                        try:
                            to_spr.requestDiffTo(self.requester, from_spr)
                        except PackageDiffAlreadyRequested:
                            pass
                        break

        if pu is not None:
            # A PackageUpload will only exist if the copy job had to be
            # held in the queue because of policy/ancestry checks.  If one
            # does exist we need to make sure it gets moved to DONE.
            pu.setDone()

        if copied_publications:
            self.logger.debug("Packages copied to %s:" %
                              self.target_archive.displayname)
            for copy in copied_publications:
                self.logger.debug(copy.displayname)
    def _copy_publishing_records(self, distroarchseries_lists):
        """Copy the publishing records from the parent arch series
        to the given arch series in ourselves.

        We copy all PENDING and PUBLISHED records as PENDING into our own
        publishing records.

        We copy only the RELEASE pocket in the PRIMARY archive.
        """
        archive_set = getUtility(IArchiveSet)

        for parent in self.derivation_parents:
            spns = self.source_names_by_parent.get(parent.id, None)
            if spns is not None and len(spns) == 0:
                # Some packagesets where selected but not a single
                # source from this parent: we skip the copy since
                # calling copy with spns=[] would copy all the packagesets
                # from this parent.
                continue
            # spns=None means no packagesets selected so we need to consider
            # all sources.

            distroarchseries_list = distroarchseries_lists[parent]
            for archive in parent.distribution.all_distro_archives:
                if archive.purpose != ArchivePurpose.PRIMARY:
                    continue

                target_archive = archive_set.getByDistroPurpose(
                    self.distroseries.distribution, archive.purpose)
                if archive.purpose is ArchivePurpose.PRIMARY:
                    assert target_archive is not None, (
                        "Target archive doesn't exist?")
                if self._use_cloner(target_archive, archive):
                    origin = PackageLocation(
                        archive, parent.distribution, parent,
                        PackagePublishingPocket.RELEASE)
                    destination = PackageLocation(
                        target_archive, self.distroseries.distribution,
                        self.distroseries, PackagePublishingPocket.RELEASE)
                    processors = None
                    if self.rebuild:
                        processors = [
                            das[1].processor for das in distroarchseries_list]
                        distroarchseries_list = ()
                    getUtility(IPackageCloner).clonePackages(
                        origin, destination, distroarchseries_list,
                        processors, spns, self.rebuild)
                else:
                    # There is only one available pocket in an unreleased
                    # series.
                    target_pocket = PackagePublishingPocket.RELEASE
                    sources = archive.getPublishedSources(
                        distroseries=parent, pocket=INIT_POCKETS,
                        status=(PackagePublishingStatus.PENDING,
                                PackagePublishingStatus.PUBLISHED),
                        name=spns)
                    # XXX: rvb 2011-06-23 bug=801112: do_copy is atomic (all
                    # or none of the sources will be copied). This might
                    # lead to a partially initialised series if there is a
                    # single conflict in the destination series.
                    try:
                        sources_published = do_copy(
                            sources, target_archive, self.distroseries,
                            target_pocket, include_binaries=not self.rebuild,
                            check_permissions=False, strict_binaries=False,
                            close_bugs=False, create_dsd_job=False,
                            person=None)
                        if self.rebuild:
                            rebuilds = []
                            for pubrec in sources_published:
                                builds = pubrec.createMissingBuilds(
                                   list(self.distroseries.architectures))
                                rebuilds.extend(builds)
                            self._rescore_rebuilds(rebuilds)
                    except CannotCopy as error:
                        raise InitializationError(error)
Esempio n. 7
0
    def attemptCopy(self):
        """Attempt to perform the copy.

        :raise CannotCopy: If the copy fails for a reason that the user
            can deal with.
        """
        reason = self.target_archive.checkUploadToPocket(
            self.target_distroseries, self.target_pocket, person=self.requester
        )
        if reason:
            # Wrap any forbidden-pocket error in CannotCopy.
            raise CannotCopy(unicode(reason))

        source_package = self.findSourcePublication()

        # If there's a PackageUpload associated with this job then this
        # job has just been released by an archive admin from the queue.
        # We don't need to check any policies, but the admin may have
        # set overrides which we will get from the job's metadata.
        pu = getUtility(IPackageUploadSet).getByPackageCopyJobIDs([self.context.id]).any()
        if pu is None:
            source_name = getUtility(ISourcePackageNameSet)[self.package_name]
            self._checkPolicies(source_name, source_package.sourcepackagerelease.component, self.auto_approve)

        # The package is free to go right in, so just copy it now.
        ancestry = self.target_archive.getPublishedSources(
            name=self.package_name, distroseries=self.target_distroseries, pocket=self.target_pocket, exact_match=True
        )
        override = self.getSourceOverride()
        copy_policy = self.getPolicyImplementation()
        send_email = copy_policy.send_email(self.target_archive)
        copied_publications = do_copy(
            sources=[source_package],
            archive=self.target_archive,
            series=self.target_distroseries,
            pocket=self.target_pocket,
            include_binaries=self.include_binaries,
            check_permissions=True,
            person=self.requester,
            overrides=[override],
            send_email=send_email,
            announce_from_person=self.requester,
            sponsored=self.sponsored,
            packageupload=pu,
            unembargo=self.unembargo,
            phased_update_percentage=self.phased_update_percentage,
        )

        # Add a PackageDiff for this new upload if it has ancestry.
        if copied_publications and not ancestry.is_empty():
            from_spr = None
            for publication in copied_publications:
                if ISourcePackagePublishingHistory.providedBy(publication):
                    from_spr = publication.sourcepackagerelease
                    break
            if from_spr:
                for ancestor in ancestry:
                    to_spr = ancestor.sourcepackagerelease
                    if from_spr != to_spr:
                        try:
                            to_spr.requestDiffTo(self.requester, from_spr)
                        except PackageDiffAlreadyRequested:
                            pass
                        break

        if pu is not None:
            # A PackageUpload will only exist if the copy job had to be
            # held in the queue because of policy/ancestry checks.  If one
            # does exist we need to make sure it gets moved to DONE.
            pu.setDone()

        if copied_publications:
            self.logger.debug("Packages copied to %s:" % self.target_archive.displayname)
            for copy in copied_publications:
                self.logger.debug(copy.displayname)
Esempio n. 8
0
    def _copy_publishing_records(self, distroarchseries_lists):
        """Copy the publishing records from the parent arch series
        to the given arch series in ourselves.

        We copy all PENDING and PUBLISHED records as PENDING into our own
        publishing records.

        We copy only the RELEASE pocket in the PRIMARY archive.
        """
        archive_set = getUtility(IArchiveSet)

        for parent in self.derivation_parents:
            spns = self.source_names_by_parent.get(parent.id, None)
            if spns is not None and len(spns) == 0:
                # Some packagesets where selected but not a single
                # source from this parent: we skip the copy since
                # calling copy with spns=[] would copy all the packagesets
                # from this parent.
                continue
            # spns=None means no packagesets selected so we need to consider
            # all sources.

            distroarchseries_list = distroarchseries_lists[parent]
            for archive in parent.distribution.all_distro_archives:
                if archive.purpose != ArchivePurpose.PRIMARY:
                    continue

                target_archive = archive_set.getByDistroPurpose(
                    self.distroseries.distribution, archive.purpose)
                if archive.purpose is ArchivePurpose.PRIMARY:
                    assert target_archive is not None, (
                        "Target archive doesn't exist?")
                if self._use_cloner(target_archive, archive):
                    origin = PackageLocation(archive, parent.distribution,
                                             parent,
                                             PackagePublishingPocket.RELEASE)
                    destination = PackageLocation(
                        target_archive, self.distroseries.distribution,
                        self.distroseries, PackagePublishingPocket.RELEASE)
                    processors = None
                    if self.rebuild:
                        processors = [
                            das[1].processor for das in distroarchseries_list
                        ]
                        distroarchseries_list = ()
                    getUtility(IPackageCloner).clonePackages(
                        origin, destination, distroarchseries_list, processors,
                        spns, self.rebuild)
                else:
                    # There is only one available pocket in an unreleased
                    # series.
                    target_pocket = PackagePublishingPocket.RELEASE
                    sources = archive.getPublishedSources(
                        distroseries=parent,
                        pocket=INIT_POCKETS,
                        status=(PackagePublishingStatus.PENDING,
                                PackagePublishingStatus.PUBLISHED),
                        name=spns)
                    # XXX: rvb 2011-06-23 bug=801112: do_copy is atomic (all
                    # or none of the sources will be copied). This might
                    # lead to a partially initialised series if there is a
                    # single conflict in the destination series.
                    try:
                        sources_published = do_copy(
                            sources,
                            target_archive,
                            self.distroseries,
                            target_pocket,
                            include_binaries=not self.rebuild,
                            check_permissions=False,
                            strict_binaries=False,
                            close_bugs=False,
                            create_dsd_job=False,
                            person=None)
                        if self.rebuild:
                            rebuilds = []
                            for pubrec in sources_published:
                                builds = pubrec.createMissingBuilds(
                                    list(self.distroseries.architectures))
                                rebuilds.extend(builds)
                            self._rescore_rebuilds(rebuilds)
                    except CannotCopy as error:
                        raise InitializationError(error)