def test_unknown_sources(self): # If the unknown policy is used, it does no checks, just returns the # defaults. spph = self.factory.makeSourcePackagePublishingHistory() policy = UnknownOverridePolicy() overrides = policy.calculateSourceOverrides( spph.distroseries.main_archive, spph.distroseries, spph.pocket, (spph.sourcepackagerelease.sourcepackagename,)) universe = getUtility(IComponentSet)['universe'] expected = [ SourceOverride( spph.sourcepackagerelease.sourcepackagename, universe, None)] self.assertEqual(expected, overrides)
def test_fallback_sources(self): # The fallback policy runs through a sequence of policies until # all overrides are fulfilled. universe = getUtility(IComponentSet)['universe'] spns = [self.factory.makeSourcePackageName()] expected = {spns[0]: SourceOverride(component=universe, new=True)} distroseries = self.factory.makeDistroSeries() pocket = self.factory.getAnyPocket() for i in range(8): spph = self.factory.makeSourcePackagePublishingHistory( distroseries=distroseries, archive=distroseries.main_archive, pocket=pocket) spns.append(spph.sourcepackagerelease.sourcepackagename) expected[spph.sourcepackagerelease.sourcepackagename] = ( SourceOverride(component=spph.component, section=spph.section, version=spph.sourcepackagerelease.version, new=False)) spns.append(self.factory.makeSourcePackageName()) expected[spns[-1]] = SourceOverride(component=universe, new=True) policy = FallbackOverridePolicy([ FromExistingOverridePolicy(distroseries.main_archive, distroseries, pocket), UnknownOverridePolicy(distroseries.main_archive, distroseries, pocket) ]) overrides = policy.calculateSourceOverrides( dict((spn, SourceOverride()) for spn in spns)) self.assertEqual(10, len(overrides)) self.assertEqual(expected, overrides)
def test_getComponentOverride_default_component(self): # getComponentOverride also accepts a component object (as # opposed to a component's name). component = getUtility(IComponentSet)['universe'] component_name = UnknownOverridePolicy.getComponentOverride(component) self.assertEqual('universe', component_name)
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() overrides = policy.calculateBinaryOverrides( distroseries.main_archive, distroseries, bpph.pocket, ((bpph.binarypackagerelease.binarypackagename, None),)) universe = getUtility(IComponentSet)['universe'] expected = [ BinaryOverride( bpph.binarypackagerelease.binarypackagename, bpph.distroarchseries, universe, None, None, None)] self.assertEqual(expected, overrides)
def processUnknownFile(self, uploaded_file, override=None): """Apply a set of actions for newly-uploaded (unknown) files. Here we use the override, if specified, or simply default to the policy defined in UnknownOverridePolicy. In the case of a PPA, files are not touched. They are always overridden to 'main' at publishing time, though. All files are also marked as new unless it's a PPA file, which are never considered new as they are auto-accepted. COPY archive build uploads are also auto-accepted, otherwise they would sit in the NEW queue since it's likely there's no ancestry. """ if self.is_ppa or self.policy.archive.is_copy: return # All newly-uploaded, non-PPA files must be marked as new so that # the upload goes to the correct queue. PPA uploads are always # auto-accepted so they are never new. uploaded_file.new = True if self.is_partner: # Don't override partner uploads. return # Use the specified override, or delegate to UnknownOverridePolicy. if override: uploaded_file.component_name = override.component.name return component_name_override = UnknownOverridePolicy.getComponentOverride( uploaded_file.component_name) uploaded_file.component_name = component_name_override
def test_getComponentOverride_return_component(self): # Passing return_component=True to getComponentOverride makes it # return the Component object (as opposed to the component's # name). universe_component = getUtility(IComponentSet)['universe'] component = UnknownOverridePolicy.getComponentOverride( universe_component, return_component=True) self.assertEqual(universe_component, component)
def _checkPolicies(self, source_name, source_component=None, auto_approve=False): # This helper will only return if it's safe to carry on with the # copy, otherwise it raises SuspendJobException to tell the job # runner to suspend the job. override_policy = FromExistingOverridePolicy() ancestry = override_policy.calculateSourceOverrides( self.target_archive, self.target_distroseries, self.target_pocket, [source_name]) copy_policy = self.getPolicyImplementation() if len(ancestry) == 0: # We need to get the default overrides and put them in the # metadata. defaults = UnknownOverridePolicy().calculateSourceOverrides( self.target_archive, self.target_distroseries, self.target_pocket, [source_name], source_component) self.addSourceOverride(defaults[0]) if auto_approve: auto_approve = self.target_archive.canAdministerQueue( self.requester, self.getSourceOverride().component, self.target_pocket, self.target_distroseries) approve_new = auto_approve or copy_policy.autoApproveNew( self.target_archive, self.target_distroseries, self.target_pocket) if not approve_new: # There's no existing package with the same name and the # policy says unapproved, so we poke it in the NEW queue. self._createPackageUpload() raise SuspendJobException else: # Put the existing override in the metadata. self.addSourceOverride(ancestry[0]) if auto_approve: auto_approve = self.target_archive.canAdministerQueue( self.requester, self.getSourceOverride().component, self.target_pocket, self.target_distroseries) # The package is not new (it has ancestry) so check the copy # policy for existing packages. approve_existing = auto_approve or copy_policy.autoApprove( self.target_archive, self.target_distroseries, self.target_pocket) if not approve_existing: self._createPackageUpload(unapproved=True) raise SuspendJobException
def test_unknown_sources(self): # The unknown policy uses a default component based on the # pre-override component. for component in ('contrib', 'non-free'): self.factory.makeComponent(component) distroseries = self.factory.makeDistroSeries() spns = [self.factory.makeSourcePackageName() for i in range(3)] policy = UnknownOverridePolicy(distroseries.main_archive, distroseries, PackagePublishingPocket.RELEASE) overrides = policy.calculateSourceOverrides( dict((spn, SourceOverride( component=getUtility(IComponentSet)[component])) for spn, component in zip(spns, ('main', 'contrib', 'non-free')))) expected = dict( (spn, SourceOverride(component=getUtility(IComponentSet)[component], new=True)) for spn, component in zip(spns, ('universe', 'multiverse', 'multiverse'))) self.assertEqual(expected, overrides)
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)
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)
def test_getComponentOverride_default_name(self): # getComponentOverride returns the default component name when an # unknown component name is passed. component_name = UnknownOverridePolicy.getComponentOverride('no-name') self.assertEqual('universe', component_name)