Implement Ubuntu component relationship constraints (ogre model)

ubuntu/rebased
Iain Lane 5 years ago
parent 5718f8c903
commit 3bfc0321c9
No known key found for this signature in database
GPG Key ID: E352D5C51C5041D4

@ -898,7 +898,21 @@ class DependsPolicy(BasePolicy):
needed_for_dep = set() needed_for_dep = set()
for alternative in dep: for alternative in dep:
if target_suite.is_pkg_in_the_suite(alternative): alt_bin = self._britney.all_binaries[alternative]
component = binary_u.component
alt_component = alt_bin.component
# Don't check components when testing PPAs, as they do not have this concept
if self.options.adt_ppas:
component = None
# This relationship is good wrt. components if either the binary being
# considered doesn't have a component, or if the ogre model
# permits it (see UbuntuComponent)
relationship_is_allowed = component is None or component.allowed_component(alt_component)
if target_suite.is_pkg_in_the_suite(alternative) and relationship_is_allowed:
# dep can be satisfied in testing - ok # dep can be satisfied in testing - ok
is_ok = True is_ok = True
elif alternative in my_bins: elif alternative in my_bins:
@ -1745,6 +1759,7 @@ class LPBlockBugPolicy(BasePolicy):
The dates are expressed as the number of seconds from the Unix epoch The dates are expressed as the number of seconds from the Unix epoch
(1970-01-01 00:00:00 UTC). (1970-01-01 00:00:00 UTC).
""" """
def __init__(self, options, suite_info): def __init__(self, options, suite_info):
super().__init__('block-bugs', options, suite_info, {SuiteClass.PRIMARY_SOURCE_SUITE}) super().__init__('block-bugs', options, suite_info, {SuiteClass.PRIMARY_SOURCE_SUITE})
@ -1753,7 +1768,7 @@ class LPBlockBugPolicy(BasePolicy):
self.blocks = {} # srcpkg -> [(bug, date), ...] self.blocks = {} # srcpkg -> [(bug, date), ...]
filename = os.path.join(self.options.unstable, "Blocks") filename = os.path.join(self.options.unstable, "Blocks")
self.log("Loading user-supplied block data from %s" % filename) self.logger.info("Loading user-supplied block data from %s" % filename)
for line in open(filename): for line in open(filename):
ln = line.split() ln = line.split()
if len(ln) != 3: if len(ln) != 3:

@ -29,6 +29,7 @@ import sys
import time import time
from collections import defaultdict from collections import defaultdict
from datetime import datetime from datetime import datetime
from enum import Enum, unique
from functools import partial from functools import partial
from itertools import filterfalse, chain from itertools import filterfalse, chain
@ -955,3 +956,52 @@ def parse_builtusing(builtusing_raw, pkg_id=None, logger=None):
part = (bu, bu_version) part = (bu, bu_version)
nbu.append(part) nbu.append(part)
return nbu return nbu
@unique
class UbuntuComponent(Enum):
MAIN = 0
RESTRICTED = 1
UNIVERSE = 2
MULTIVERSE = 3
@classmethod
def get_component(cls, section):
"""Parse section and return component
Given a section, return component. Packages in MAIN have no
prefix, all others have <component>/ prefix.
"""
name2component = {
"restricted": cls.RESTRICTED,
"universe": cls.UNIVERSE,
"multiverse": cls.MULTIVERSE,
}
if "/" in section:
return name2component[section.split("/", 1)[0]]
return cls.MAIN
def allowed_component(self, dep):
"""Check if I can depend on the other component"""
component_dependencies = {
UbuntuComponent.MAIN: [UbuntuComponent.MAIN],
UbuntuComponent.RESTRICTED: [
UbuntuComponent.MAIN,
UbuntuComponent.RESTRICTED,
],
UbuntuComponent.UNIVERSE: [
UbuntuComponent.MAIN,
UbuntuComponent.UNIVERSE,
],
UbuntuComponent.MULTIVERSE: [
UbuntuComponent.MAIN,
UbuntuComponent.RESTRICTED,
UbuntuComponent.UNIVERSE,
UbuntuComponent.MULTIVERSE,
],
}
return dep in component_dependencies[self]

@ -2191,12 +2191,12 @@ class AT(TestAutopkgtestBase):
self.assertEqual(exc['lightgreen']['policy_info']['autopkgtest'], self.assertEqual(exc['lightgreen']['policy_info']['autopkgtest'],
{'lightgreen': { {'lightgreen': {
'amd64': ['RUNNING-ALWAYSFAIL', 'amd64': ['RUNNING-ALWAYSFAIL',
'https://autopkgtest.ubuntu.com/status/pending', 'https://autopkgtest.ubuntu.com/running',
None, None,
None, None,
None], None],
'i386': ['RUNNING-ALWAYSFAIL', 'i386': ['RUNNING-ALWAYSFAIL',
'https://autopkgtest.ubuntu.com/status/pending', 'https://autopkgtest.ubuntu.com/running',
None, None,
None, None,
None]}, None]},

@ -0,0 +1,115 @@
#!/usr/bin/python3
# (C) 2014 - 2016 Canonical Ltd.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
import os
import sys
import unittest
PROJECT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.insert(0, PROJECT_DIR)
from britney2.utils import UbuntuComponent # noqa: E402
class UtilTests(unittest.TestCase):
def test_get_component(self):
self.assertEqual(
UbuntuComponent.get_component("utils"), UbuntuComponent.MAIN
)
self.assertEqual(
UbuntuComponent.get_component("utils"), UbuntuComponent.MAIN
)
self.assertEqual(
UbuntuComponent.get_component("restricted/admin"),
UbuntuComponent.RESTRICTED,
)
self.assertEqual(
UbuntuComponent.get_component("universe/web"),
UbuntuComponent.UNIVERSE,
)
self.assertEqual(
UbuntuComponent.get_component("multiverse/libs"),
UbuntuComponent.MULTIVERSE,
)
def test_allowed_component(self):
allowed_component = UbuntuComponent.allowed_component
self.assertTrue(
allowed_component(UbuntuComponent.MAIN, UbuntuComponent.MAIN)
)
self.assertFalse(
allowed_component(UbuntuComponent.MAIN, UbuntuComponent.UNIVERSE)
)
self.assertFalse(
allowed_component(UbuntuComponent.MAIN, UbuntuComponent.MULTIVERSE)
)
self.assertFalse(
allowed_component(UbuntuComponent.MAIN, UbuntuComponent.RESTRICTED)
)
self.assertTrue(
allowed_component(UbuntuComponent.RESTRICTED, UbuntuComponent.MAIN)
)
self.assertFalse(
allowed_component(
UbuntuComponent.RESTRICTED, UbuntuComponent.UNIVERSE
)
)
self.assertFalse(
allowed_component(
UbuntuComponent.RESTRICTED, UbuntuComponent.MULTIVERSE
)
)
self.assertTrue(
allowed_component(
UbuntuComponent.RESTRICTED, UbuntuComponent.RESTRICTED
)
)
self.assertTrue(
allowed_component(UbuntuComponent.UNIVERSE, UbuntuComponent.MAIN)
)
self.assertTrue(
allowed_component(
UbuntuComponent.UNIVERSE, UbuntuComponent.UNIVERSE
)
)
self.assertFalse(
allowed_component(
UbuntuComponent.UNIVERSE, UbuntuComponent.MULTIVERSE
)
)
self.assertFalse(
allowed_component(
UbuntuComponent.UNIVERSE, UbuntuComponent.RESTRICTED
)
)
self.assertTrue(
allowed_component(UbuntuComponent.MULTIVERSE, UbuntuComponent.MAIN)
)
self.assertTrue(
allowed_component(
UbuntuComponent.MULTIVERSE, UbuntuComponent.UNIVERSE
)
)
self.assertTrue(
allowed_component(
UbuntuComponent.MULTIVERSE, UbuntuComponent.MULTIVERSE
)
)
self.assertTrue(
allowed_component(
UbuntuComponent.MULTIVERSE, UbuntuComponent.RESTRICTED
)
)
if __name__ == "__main__":
unittest.main()
Loading…
Cancel
Save