def test__close_bugs_for_sourcepublication__uses_right_distro(self):
        # If a source was originally uploaded to a different distro,
        # closing bugs based on a publication of the same source in a new
        # distro should work.

        # Create a source package that was originally uploaded to one
        # distro and publish it in a second distro.
        spr = self.factory.makeSourcePackageRelease(changelog_entry="blah")
        target_distro = self.factory.makeDistribution()
        target_distroseries = self.factory.makeDistroSeries(target_distro)
        bugs = self.makeChangelogWithBugs(
            spr, target_series=target_distroseries)
        target_spph = self.factory.makeSourcePackagePublishingHistory(
            sourcepackagerelease=spr, distroseries=target_distroseries,
            archive=target_distro.main_archive,
            pocket=PackagePublishingPocket.RELEASE)

        # The test depends on this pre-condition.
        self.assertNotEqual(spr.upload_distroseries.distribution,
                            target_distroseries.distribution)

        close_bugs_for_sourcepublication(target_spph, since_version="1.0")

        for bug, bugtask in bugs:
            self.assertEqual(BugTaskStatus.FIXRELEASED, bugtask.status)
    def test__close_bugs_for_sourcepublication__uses_right_distro(self):
        # If a source was originally uploaded to a different distro,
        # closing bugs based on a publication of the same source in a new
        # distro should work.

        # Create a source package that was originally uploaded to one
        # distro and publish it in a second distro.
        spr = self.factory.makeSourcePackageRelease(changelog_entry="blah")
        target_distro = self.factory.makeDistribution()
        target_distroseries = self.factory.makeDistroSeries(target_distro)
        bugs = self.makeChangelogWithBugs(spr,
                                          target_series=target_distroseries)
        target_spph = self.factory.makeSourcePackagePublishingHistory(
            sourcepackagerelease=spr,
            distroseries=target_distroseries,
            archive=target_distro.main_archive,
            pocket=PackagePublishingPocket.RELEASE)

        # The test depends on this pre-condition.
        self.assertNotEqual(spr.upload_distroseries.distribution,
                            target_distroseries.distribution)

        close_bugs_for_sourcepublication(target_spph, since_version="1.0")

        for bug, bugtask in bugs:
            self.assertEqual(BugTaskStatus.FIXRELEASED, bugtask.status)
Example #3
0
def _do_direct_copy(source,
                    archive,
                    series,
                    pocket,
                    include_binaries,
                    override=None,
                    close_bugs=True,
                    create_dsd_job=True,
                    close_bugs_since_version=None,
                    creator=None,
                    sponsor=None,
                    packageupload=None,
                    phased_update_percentage=None,
                    logger=None):
    """Copy publishing records to another location.

    Copy each item of the given list of `SourcePackagePublishingHistory`
    to the given destination if they are not yet available (previously
    copied).

    Also copy published binaries for each source if requested to. Again,
    only copy binaries that were not yet copied before.

    :param source: an `ISourcePackagePublishingHistory`.
    :param archive: the target `IArchive`.
    :param series: the target `IDistroSeries`, if None is given the same
        current source distroseries will be used as destination.
    :param pocket: the target `PackagePublishingPocket`.
    :param include_binaries: optional boolean, controls whether or
        not the published binaries for each given source should be also
        copied along with the source.
    :param override: An `IOverride` as per do_copy().
    :param close_bugs: A boolean indicating whether or not bugs on the
        copied publication should be closed.
    :param create_dsd_job: A boolean indicating whether or not a dsd job
         should be created for the new source publication.
    :param close_bugs_since_version: If close_bugs is True,
        then this parameter says which changelog entries to parse looking
        for bugs to close.  See `close_bugs_for_sourcepackagerelease`.
    :param creator: the requester `IPerson`.
    :param sponsor: the sponsor `IPerson`, if this copy is being sponsored.
    :param packageupload: The `IPackageUpload` that caused this publication
        to be created.
    :param phased_update_percentage: The phased update percentage to apply
        to the copied publication.
    :param logger: An optional logger.

    :return: a list of `ISourcePackagePublishingHistory` and
        `BinaryPackagePublishingHistory` corresponding to the copied
        publications.
    """
    from lp.soyuz.scripts.processaccepted import (
        close_bugs_for_sourcepublication)

    copies = []
    custom_files = []

    # Copy source if it's not yet copied.
    source_in_destination = archive.getPublishedSources(
        name=source.sourcepackagerelease.name,
        exact_match=True,
        version=source.sourcepackagerelease.version,
        status=active_publishing_status,
        distroseries=series,
        pocket=pocket)
    policy = archive.getOverridePolicy(
        phased_update_percentage=phased_update_percentage)
    if source_in_destination.is_empty():
        # If no manual overrides were specified and the archive has an
        # override policy then use that policy to get overrides.
        if override is None and policy is not None:
            package_names = (source.sourcepackagerelease.sourcepackagename, )
            # Only one override can be returned so take the first
            # element of the returned list.
            overrides = policy.calculateSourceOverrides(
                archive, series, pocket, package_names)
            # Only one override can be returned so take the first
            # element of the returned list.
            assert len(overrides) == 1, (
                "More than one override encountered, something is wrong.")
            override = overrides[0]
        source_copy = source.copyTo(series,
                                    pocket,
                                    archive,
                                    override,
                                    create_dsd_job=create_dsd_job,
                                    creator=creator,
                                    sponsor=sponsor,
                                    packageupload=packageupload)
        if close_bugs:
            close_bugs_for_sourcepublication(source_copy,
                                             close_bugs_since_version)
        copies.append(source_copy)
    else:
        source_copy = source_in_destination.first()
    if source_copy.packageupload is not None:
        custom_files.extend(source_copy.packageupload.customfiles)

    if include_binaries:
        # Copy missing binaries for the matching architectures in the
        # destination series. ISPPH.getBuiltBinaries() return only unique
        # publication per binary package releases (i.e. excludes irrelevant
        # arch-indep publications) and IBPPH.copy is prepared to expand
        # arch-indep publications.
        binary_copies = getUtility(IPublishingSet).copyBinaries(
            archive, series, pocket, source.getBuiltBinaries(), policy=policy)

        if binary_copies is not None:
            copies.extend(binary_copies)
            binary_uploads = set(bpph.binarypackagerelease.build.package_upload
                                 for bpph in binary_copies)
            for binary_upload in binary_uploads:
                if binary_upload is not None:
                    custom_files.extend(binary_upload.customfiles)

    if custom_files:
        # Custom uploads aren't modelled as publication history records, so
        # we have to send these through the upload queue.
        custom_copier = CustomUploadsCopier(series,
                                            target_pocket=pocket,
                                            target_archive=archive)
        for custom in custom_files:
            if custom_copier.isCopyable(custom):
                custom_copier.copyUpload(custom)

    # Always ensure the needed builds exist in the copy destination
    # after copying the binaries.
    # XXX cjwatson 2012-06-22 bug=869308: Fails to honour P-a-s.
    source_copy.createMissingBuilds(logger=logger)

    return copies
def _do_direct_copy(source, archive, series, pocket, include_binaries,
                    override=None, close_bugs=True, create_dsd_job=True,
                    close_bugs_since_version=None, creator=None,
                    sponsor=None, packageupload=None,
                    phased_update_percentage=None, logger=None):
    """Copy publishing records to another location.

    Copy each item of the given list of `SourcePackagePublishingHistory`
    to the given destination if they are not yet available (previously
    copied).

    Also copy published binaries for each source if requested to. Again,
    only copy binaries that were not yet copied before.

    :param source: an `ISourcePackagePublishingHistory`.
    :param archive: the target `IArchive`.
    :param series: the target `IDistroSeries`, if None is given the same
        current source distroseries will be used as destination.
    :param pocket: the target `PackagePublishingPocket`.
    :param include_binaries: optional boolean, controls whether or
        not the published binaries for each given source should be also
        copied along with the source.
    :param override: An `IOverride` as per do_copy().
    :param close_bugs: A boolean indicating whether or not bugs on the
        copied publication should be closed.
    :param create_dsd_job: A boolean indicating whether or not a dsd job
         should be created for the new source publication.
    :param close_bugs_since_version: If close_bugs is True,
        then this parameter says which changelog entries to parse looking
        for bugs to close.  See `close_bugs_for_sourcepackagerelease`.
    :param creator: the requester `IPerson`.
    :param sponsor: the sponsor `IPerson`, if this copy is being sponsored.
    :param packageupload: The `IPackageUpload` that caused this publication
        to be created.
    :param phased_update_percentage: The phased update percentage to apply
        to the copied publication.
    :param logger: An optional logger.

    :return: a list of `ISourcePackagePublishingHistory` and
        `BinaryPackagePublishingHistory` corresponding to the copied
        publications.
    """
    from lp.soyuz.scripts.processaccepted import (
        close_bugs_for_sourcepublication)

    copies = []
    custom_files = []

    # Copy source if it's not yet copied.
    source_in_destination = archive.getPublishedSources(
        name=source.sourcepackagerelease.name, exact_match=True,
        version=source.sourcepackagerelease.version,
        status=active_publishing_status,
        distroseries=series, pocket=pocket)
    policy = archive.getOverridePolicy(
        phased_update_percentage=phased_update_percentage)
    if source_in_destination.is_empty():
        # If no manual overrides were specified and the archive has an
        # override policy then use that policy to get overrides.
        if override is None and policy is not None:
            package_names = (source.sourcepackagerelease.sourcepackagename,)
            # Only one override can be returned so take the first
            # element of the returned list.
            overrides = policy.calculateSourceOverrides(
                archive, series, pocket, package_names)
            # Only one override can be returned so take the first
            # element of the returned list.
            assert len(overrides) == 1, (
                "More than one override encountered, something is wrong.")
            override = overrides[0]
        source_copy = source.copyTo(
            series, pocket, archive, override, create_dsd_job=create_dsd_job,
            creator=creator, sponsor=sponsor, packageupload=packageupload)
        if close_bugs:
            close_bugs_for_sourcepublication(
                source_copy, close_bugs_since_version)
        copies.append(source_copy)
    else:
        source_copy = source_in_destination.first()
    if source_copy.packageupload is not None:
        custom_files.extend(source_copy.packageupload.customfiles)

    if include_binaries:
        # Copy missing binaries for the matching architectures in the
        # destination series. ISPPH.getBuiltBinaries() return only unique
        # publication per binary package releases (i.e. excludes irrelevant
        # arch-indep publications) and IBPPH.copy is prepared to expand
        # arch-indep publications.
        binary_copies = getUtility(IPublishingSet).copyBinaries(
            archive, series, pocket, source.getBuiltBinaries(), policy=policy)

        if binary_copies is not None:
            copies.extend(binary_copies)
            binary_uploads = set(
                bpph.binarypackagerelease.build.package_upload
                for bpph in binary_copies)
            for binary_upload in binary_uploads:
                if binary_upload is not None:
                    custom_files.extend(binary_upload.customfiles)

    if custom_files:
        # Custom uploads aren't modelled as publication history records, so
        # we have to send these through the upload queue.
        custom_copier = CustomUploadsCopier(
            series, target_pocket=pocket, target_archive=archive)
        for custom in custom_files:
            if custom_copier.isCopyable(custom):
                custom_copier.copyUpload(custom)

    # Always ensure the needed builds exist in the copy destination
    # after copying the binaries.
    # XXX cjwatson 2012-06-22 bug=869308: Fails to honour P-a-s.
    source_copy.createMissingBuilds(logger=logger)

    return copies