예제 #1
0
 def test_binary_overrides_pocket(self):
     # If the binary is not published in the given pocket, no changes
     # are made.
     distroseries = self.factory.makeDistroSeries()
     das = self.factory.makeDistroArchSeries(distroseries=distroseries)
     bpn = self.factory.makeBinaryPackageName()
     self.factory.makeBinaryPackagePublishingHistory(
         archive=distroseries.main_archive,
         distroarchseries=das,
         pocket=PackagePublishingPocket.RELEASE,
         binarypackagename=bpn)
     policy = FromExistingOverridePolicy(distroseries.main_archive,
                                         distroseries,
                                         PackagePublishingPocket.PROPOSED)
     overrides = policy.calculateBinaryOverrides({
         (bpn, das.architecturetag):
         BinaryOverride()
     })
     self.assertEqual(0, len(overrides))
     policy = FromExistingOverridePolicy(distroseries.main_archive,
                                         distroseries,
                                         PackagePublishingPocket.RELEASE)
     overrides = policy.calculateBinaryOverrides({
         (bpn, das.architecturetag):
         BinaryOverride()
     })
     self.assertEqual(1, len(overrides))
     policy = FromExistingOverridePolicy(distroseries.main_archive,
                                         distroseries, None)
     overrides = policy.calculateBinaryOverrides({
         (bpn, das.architecturetag):
         BinaryOverride()
     })
     self.assertEqual(1, len(overrides))
예제 #2
0
 def test_binary(self):
     policy = ConstantOverridePolicy(
         component=self.factory.makeComponent(),
         section=self.factory.makeSection(),
         priority=PackagePublishingPriority.EXTRA,
         phased_update_percentage=50,
         new=True)
     bpn = self.factory.makeBinaryPackageName()
     self.assertEqual(
         {
             (bpn, None):
             BinaryOverride(component=policy.component,
                            section=policy.section,
                            priority=policy.priority,
                            phased_update_percentage=50,
                            new=True)
         },
         policy.calculateBinaryOverrides({
             (bpn, None):
             BinaryOverride(component=self.factory.makeComponent(),
                            section=self.factory.makeSection(),
                            priority=PackagePublishingPriority.REQUIRED,
                            phased_update_percentage=90,
                            new=False)
         }))
예제 #3
0
    def test_binary_overrides_can_include_deleted(self):
        # calculateBinaryOverrides can be asked to include Deleted
        # publications.
        distroseries = self.factory.makeDistroSeries()
        das = self.factory.makeDistroArchSeries(architecturetag='amd64',
                                                distroseries=distroseries)
        bpn = self.factory.makeBinaryPackageName()
        pocket = self.factory.getAnyPocket()
        bpph = self.factory.makeBinaryPackagePublishingHistory(
            archive=distroseries.main_archive,
            distroarchseries=das,
            pocket=pocket,
            binarypackagename=bpn,
            architecturespecific=True,
            status=PackagePublishingStatus.PUBLISHED)
        deleted_bpph = self.factory.makeBinaryPackagePublishingHistory(
            archive=distroseries.main_archive,
            distroarchseries=das,
            pocket=pocket,
            binarypackagename=bpn,
            architecturespecific=True,
            status=PackagePublishingStatus.DELETED)

        # With include_deleted=False the Published pub is found.
        policy = FromExistingOverridePolicy(distroseries.main_archive,
                                            distroseries, pocket)
        overrides = policy.calculateBinaryOverrides({
            (bpn, 'amd64'):
            BinaryOverride()
        })
        self.assertEqual(
            {
                (bpn, 'amd64'):
                BinaryOverride(component=bpph.component,
                               section=bpph.section,
                               priority=bpph.priority,
                               version=bpph.binarypackagerelease.version,
                               new=False)
            }, overrides)

        # But with include_deleted=True we get the newer Deleted pub instead.
        policy = FromExistingOverridePolicy(distroseries.main_archive,
                                            distroseries,
                                            pocket,
                                            include_deleted=True)
        overrides = policy.calculateBinaryOverrides({
            (bpn, 'amd64'):
            BinaryOverride()
        })
        self.assertEqual(
            {
                (bpn, 'amd64'):
                BinaryOverride(
                    component=deleted_bpph.component,
                    section=deleted_bpph.section,
                    priority=deleted_bpph.priority,
                    version=deleted_bpph.binarypackagerelease.version,
                    new=True)
            }, overrides)
예제 #4
0
 def test_phased_update_percentage(self):
     # A policy with a phased_update_percentage applies it to new binary
     # overrides.
     universe = getUtility(IComponentSet)['universe']
     distroseries = self.factory.makeDistroSeries()
     pocket = self.factory.getAnyPocket()
     bpn = self.factory.makeBinaryPackageName()
     bpns = []
     expected = {}
     distroarchseries = self.factory.makeDistroArchSeries(
         distroseries=distroseries)
     bpb = self.factory.makeBinaryPackageBuild(
         distroarchseries=distroarchseries)
     bpr = self.factory.makeBinaryPackageRelease(build=bpb,
                                                 binarypackagename=bpn,
                                                 architecturespecific=True)
     bpph = self.factory.makeBinaryPackagePublishingHistory(
         binarypackagerelease=bpr,
         distroarchseries=distroarchseries,
         archive=distroseries.main_archive,
         pocket=pocket)
     bpns.append((bpn, distroarchseries.architecturetag))
     expected[(bpn, distroarchseries.architecturetag)] = BinaryOverride(
         component=bpph.component,
         section=bpph.section,
         priority=bpph.priority,
         phased_update_percentage=50,
         version=bpph.binarypackagerelease.version,
         new=False)
     distroarchseries = self.factory.makeDistroArchSeries(
         distroseries=distroseries)
     bpns.append((bpn, distroarchseries.architecturetag))
     expected[(bpn, distroarchseries.architecturetag)] = BinaryOverride(
         component=universe, phased_update_percentage=50, new=True)
     distroseries.nominatedarchindep = distroarchseries
     policy = FallbackOverridePolicy([
         FromExistingOverridePolicy(distroseries.main_archive,
                                    distroseries,
                                    pocket,
                                    phased_update_percentage=50),
         UnknownOverridePolicy(distroseries.main_archive,
                               distroseries,
                               pocket,
                               phased_update_percentage=50)
     ])
     overrides = policy.calculateBinaryOverrides(
         dict(((bpn, das), BinaryOverride()) for bpn, das in bpns))
     self.assertEqual(2, len(overrides))
     self.assertEqual(expected, overrides)
예제 #5
0
 def test_ubuntu_override_policy_binaries(self):
     # The Ubuntu policy incorporates both the existing and the unknown
     # policy.
     universe = getUtility(IComponentSet)['universe']
     distroseries = self.factory.makeDistroSeries()
     pocket = self.factory.getAnyPocket()
     bpn = self.factory.makeBinaryPackageName()
     bpns = []
     expected = {}
     for i in range(3):
         distroarchseries = self.factory.makeDistroArchSeries(
             distroseries=distroseries)
         bpb = self.factory.makeBinaryPackageBuild(
             distroarchseries=distroarchseries)
         bpr = self.factory.makeBinaryPackageRelease(
             build=bpb, binarypackagename=bpn, architecturespecific=True)
         bpph = self.factory.makeBinaryPackagePublishingHistory(
             binarypackagerelease=bpr,
             distroarchseries=distroarchseries,
             archive=distroseries.main_archive,
             pocket=pocket)
         bpns.append((bpn, distroarchseries.architecturetag))
         expected[(bpn,
                   distroarchseries.architecturetag)] = (BinaryOverride(
                       component=bpph.component,
                       section=bpph.section,
                       priority=bpph.priority,
                       new=False,
                       version=bpph.binarypackagerelease.version))
     for i in range(2):
         distroarchseries = self.factory.makeDistroArchSeries(
             distroseries=distroseries)
         bpns.append((bpn, distroarchseries.architecturetag))
         expected[bpn, distroarchseries.architecturetag] = BinaryOverride(
             component=universe, new=True)
     distroseries.nominatedarchindep = distroarchseries
     policy = FallbackOverridePolicy([
         FromExistingOverridePolicy(distroseries.main_archive, distroseries,
                                    pocket),
         UnknownOverridePolicy(distroseries.main_archive, distroseries,
                               pocket)
     ])
     overrides = policy.calculateBinaryOverrides(
         dict(((bpn, das), BinaryOverride()) for bpn, das in bpns))
     self.assertEqual(5, len(overrides))
     self.assertEqual(expected, overrides)
예제 #6
0
 def test_binaries(self):
     # Binaries are overridden with the component from their
     # corresponding source override, if one was provided.
     bpn = self.factory.makeBinaryPackageName()
     other_bpn = self.factory.makeBinaryPackageName()
     component = self.factory.makeComponent()
     random_component = self.factory.makeComponent()
     self.assertEqual(
         {(bpn, None): BinaryOverride(component=component, new=True)},
         FromSourceOverridePolicy().calculateBinaryOverrides({
             (bpn, None):
             BinaryOverride(
                 component=random_component,
                 source_override=SourceOverride(component=component)),
             (other_bpn, None):
             BinaryOverride(component=random_component)
         }))
예제 #7
0
 def test_unknown_binaries(self):
     # If the unknown policy is used, it does no checks, just returns the
     # defaults.
     bpph = self.factory.makeBinaryPackagePublishingHistory()
     distroseries = bpph.distroarchseries.distroseries
     distroseries.nominatedarchindep = bpph.distroarchseries
     policy = UnknownOverridePolicy(distroseries.main_archive, distroseries,
                                    bpph.pocket)
     overrides = policy.calculateBinaryOverrides({
         (bpph.binarypackagerelease.binarypackagename, None):
         BinaryOverride()
     })
     universe = getUtility(IComponentSet)['universe']
     expected = {
         (bpph.binarypackagerelease.binarypackagename, None):
         BinaryOverride(component=universe, new=True)
     }
     self.assertEqual(expected, overrides)
예제 #8
0
 def test_ubuntu_override_policy_binaries(self):
     # The Ubuntu policy incorporates both the existing and the unknown
     # policy.
     universe = getUtility(IComponentSet)['universe']
     distroseries = self.factory.makeDistroSeries()
     pocket = self.factory.getAnyPocket()
     bpn = self.factory.makeBinaryPackageName()
     bpns = []
     expected = []
     for i in xrange(3):
         distroarchseries = self.factory.makeDistroArchSeries(
             distroseries=distroseries)
         bpb = self.factory.makeBinaryPackageBuild(
             distroarchseries=distroarchseries)
         bpr = self.factory.makeBinaryPackageRelease(
             build=bpb, binarypackagename=bpn,
             architecturespecific=True)
         bpph = self.factory.makeBinaryPackagePublishingHistory(
             binarypackagerelease=bpr, distroarchseries=distroarchseries,
             archive=distroseries.main_archive, pocket=pocket)
         bpns.append((bpn, distroarchseries.architecturetag))
         expected.append(
             BinaryOverride(
                 bpn, distroarchseries, bpph.component, bpph.section,
                 bpph.priority, None))
     for i in xrange(2):
         distroarchseries = self.factory.makeDistroArchSeries(
             distroseries=distroseries)
         bpns.append((bpn, distroarchseries.architecturetag))
         expected.append(
             BinaryOverride(
                 bpn, distroarchseries, universe, None, None, None))
     distroseries.nominatedarchindep = distroarchseries
     policy = UbuntuOverridePolicy()
     overrides = policy.calculateBinaryOverrides(
         distroseries.main_archive, distroseries, pocket, bpns)
     self.assertEqual(5, len(overrides))
     key = attrgetter("binary_package_name.name",
         "distro_arch_series.architecturetag",
         "component.name")
     sorted_expected = sorted(expected, key=key)
     sorted_overrides = sorted(overrides, key=key)
     self.assertEqual(sorted_expected, sorted_overrides)
예제 #9
0
    def test_binary_overrides_can_cross_archs(self):
        # calculateBinaryOverrides can be asked to ignore the archtag
        # and look for ancestry in any architecture.
        distroseries = self.factory.makeDistroSeries()
        amd64 = self.factory.makeDistroArchSeries(architecturetag='amd64',
                                                  distroseries=distroseries)
        i386 = self.factory.makeDistroArchSeries(architecturetag='i386',
                                                 distroseries=distroseries)
        distroseries.nominatedarchindep = i386
        bpn = self.factory.makeBinaryPackageName()
        pocket = self.factory.getAnyPocket()
        bpph = self.factory.makeBinaryPackagePublishingHistory(
            archive=distroseries.main_archive,
            distroarchseries=amd64,
            pocket=pocket,
            binarypackagename=bpn,
            architecturespecific=True)
        bpph_override = BinaryOverride(
            component=bpph.component,
            section=bpph.section,
            priority=bpph.priority,
            version=bpph.binarypackagerelease.version,
            new=False)

        # With any_arch=False only amd64 is found.
        policy = FromExistingOverridePolicy(distroseries.main_archive,
                                            distroseries, pocket)
        overrides = policy.calculateBinaryOverrides({
            (bpn, 'i386'):
            BinaryOverride(),
            (bpn, 'amd64'):
            BinaryOverride(),
            (bpn, None):
            BinaryOverride()
        })
        self.assertEqual({(bpn, 'amd64'): bpph_override}, overrides)

        # But with any_arch=True we get the amd64 overrides everywhere.
        policy = FromExistingOverridePolicy(distroseries.main_archive,
                                            distroseries,
                                            pocket,
                                            any_arch=True)
        overrides = policy.calculateBinaryOverrides({
            (bpn, 'i386'):
            BinaryOverride(),
            (bpn, 'amd64'):
            BinaryOverride(),
            (bpn, None):
            BinaryOverride()
        })
        self.assertEqual(
            {
                (bpn, 'i386'): bpph_override,
                (bpn, 'amd64'): bpph_override,
                (bpn, None): bpph_override
            }, overrides)
예제 #10
0
 def test_phased_update_percentage(self):
     # A policy with a phased_update_percentage applies it to new binary
     # overrides.
     universe = getUtility(IComponentSet)['universe']
     distroseries = self.factory.makeDistroSeries()
     pocket = self.factory.getAnyPocket()
     bpn = self.factory.makeBinaryPackageName()
     bpns = []
     expected = []
     distroarchseries = self.factory.makeDistroArchSeries(
         distroseries=distroseries)
     bpb = self.factory.makeBinaryPackageBuild(
         distroarchseries=distroarchseries)
     bpr = self.factory.makeBinaryPackageRelease(
         build=bpb, binarypackagename=bpn, architecturespecific=True)
     bpph = self.factory.makeBinaryPackagePublishingHistory(
         binarypackagerelease=bpr, distroarchseries=distroarchseries,
         archive=distroseries.main_archive, pocket=pocket)
     bpns.append((bpn, distroarchseries.architecturetag))
     expected.append(
         BinaryOverride(
             bpn, distroarchseries, bpph.component, bpph.section,
             bpph.priority, 50))
     distroarchseries = self.factory.makeDistroArchSeries(
         distroseries=distroseries)
     bpns.append((bpn, distroarchseries.architecturetag))
     expected.append(
         BinaryOverride(bpn, distroarchseries, universe, None, None, 50))
     distroseries.nominatedarchindep = distroarchseries
     policy = UbuntuOverridePolicy(phased_update_percentage=50)
     overrides = policy.calculateBinaryOverrides(
         distroseries.main_archive, distroseries, pocket, bpns)
     self.assertEqual(2, len(overrides))
     key = attrgetter("binary_package_name.name",
         "distro_arch_series.architecturetag",
         "component.name")
     sorted_expected = sorted(expected, key=key)
     sorted_overrides = sorted(overrides, key=key)
     self.assertEqual(sorted_expected, sorted_overrides)
예제 #11
0
 def test_no_binary_overrides(self):
     # if the given binary is not published in the given distroarchseries,
     # an empty list is returned.
     distroseries = self.factory.makeDistroSeries()
     das = self.factory.makeDistroArchSeries(distroseries=distroseries)
     distroseries.nominatedarchindep = das
     bpn = self.factory.makeBinaryPackageName()
     pocket = self.factory.getAnyPocket()
     policy = FromExistingOverridePolicy(distroseries.main_archive,
                                         distroseries, pocket)
     overrides = policy.calculateBinaryOverrides({
         (bpn, None):
         BinaryOverride()
     })
     self.assertEqual({}, overrides)
예제 #12
0
 def test_binary_overrides(self):
     # When a binary is published in the given distroarchseries, the
     # overrides are returned.
     bpph = self.factory.makeBinaryPackagePublishingHistory()
     distroseries = bpph.distroarchseries.distroseries
     distroseries.nominatedarchindep = bpph.distroarchseries
     policy = FromExistingOverridePolicy()
     overrides = policy.calculateBinaryOverrides(
         distroseries.main_archive, distroseries, bpph.pocket,
         ((bpph.binarypackagerelease.binarypackagename, None),))
     expected = [
         BinaryOverride(
             bpph.binarypackagerelease.binarypackagename,
             bpph.distroarchseries, bpph.component, bpph.section,
             bpph.priority, None)]
     self.assertEqual(expected, overrides)
예제 #13
0
 def test_binary_overrides_skips_unknown_arch(self):
     # If calculateBinaryOverrides is passed with an archtag that
     # does not correspond to an ArchSeries of the distroseries,
     # an empty list is returned.
     distroseries = self.factory.makeDistroSeries()
     das = self.factory.makeDistroArchSeries(architecturetag='amd64',
                                             distroseries=distroseries)
     distroseries.nominatedarchindep = das
     bpn = self.factory.makeBinaryPackageName()
     pocket = self.factory.getAnyPocket()
     policy = FromExistingOverridePolicy(distroseries.main_archive,
                                         distroseries, pocket)
     overrides = policy.calculateBinaryOverrides({
         (bpn, 'i386'):
         BinaryOverride()
     })
     self.assertEqual({}, overrides)
예제 #14
0
 def test_binary_overrides_constant_query_count(self):
     # The query count is constant, no matter how many bpn-das pairs are
     # checked.
     bpns = []
     distroarchseries = self.factory.makeDistroArchSeries()
     distroseries = distroarchseries.distroseries
     distroseries.nominatedarchindep = distroarchseries
     pocket = self.factory.getAnyPocket()
     for i in range(10):
         bpph = self.factory.makeBinaryPackagePublishingHistory(
             distroarchseries=distroarchseries,
             archive=distroseries.main_archive,
             pocket=pocket)
         bpns.append((bpph.binarypackagerelease.binarypackagename, None))
     flush_database_caches()
     distroseries.main_archive
     bulk.reload(bpn[0] for bpn in bpns)
     policy = FromExistingOverridePolicy(distroseries.main_archive,
                                         distroseries, pocket)
     with StormStatementRecorder() as recorder:
         policy.calculateBinaryOverrides(
             dict(((bpn, das), BinaryOverride()) for bpn, das in bpns))
     self.assertThat(recorder, HasQueryCount(Equals(4)))
예제 #15
0
 def test_binary_overrides(self):
     # When a binary is published in the given distroarchseries, the
     # overrides are returned. None means nominatedarchindep,
     # whatever that is in the target series.
     distroseries = self.factory.makeDistroSeries()
     bpph1 = self.factory.makeBinaryPackagePublishingHistory(
         archive=distroseries.main_archive,
         distroarchseries=self.factory.makeDistroArchSeries(distroseries))
     bpph2 = self.factory.makeBinaryPackagePublishingHistory(
         archive=distroseries.main_archive,
         pocket=bpph1.pocket,
         distroarchseries=self.factory.makeDistroArchSeries(distroseries))
     distroseries.nominatedarchindep = bpph1.distroarchseries
     policy = FromExistingOverridePolicy(distroseries.main_archive,
                                         distroseries, bpph1.pocket)
     overrides = policy.calculateBinaryOverrides({
         (bpph1.binarypackagerelease.binarypackagename, bpph1.distroarchseries.architecturetag):
         BinaryOverride(),
         (bpph2.binarypackagerelease.binarypackagename, bpph2.distroarchseries.architecturetag):
         BinaryOverride(),
         (bpph2.binarypackagerelease.binarypackagename, None):
         BinaryOverride(),
     })
     expected = {
         (bpph1.binarypackagerelease.binarypackagename, bpph1.distroarchseries.architecturetag):
         BinaryOverride(component=bpph1.component,
                        section=bpph1.section,
                        priority=bpph1.priority,
                        new=False,
                        version=bpph1.binarypackagerelease.version),
         (bpph2.binarypackagerelease.binarypackagename, bpph2.distroarchseries.architecturetag):
         BinaryOverride(component=bpph2.component,
                        section=bpph2.section,
                        priority=bpph2.priority,
                        new=False,
                        version=bpph2.binarypackagerelease.version),
         (bpph2.binarypackagerelease.binarypackagename, None):
         BinaryOverride(component=bpph2.component,
                        section=bpph2.section,
                        priority=bpph2.priority,
                        new=False,
                        version=bpph2.binarypackagerelease.version),
     }
     self.assertEqual(expected, overrides)