From 16cca9c55d10ea5a90db85e52c1e8a64320b1b9c Mon Sep 17 00:00:00 2001 From: Robert Bruce Park Date: Fri, 24 Mar 2017 11:17:09 -0700 Subject: [PATCH] Change SourcePPAPolicy from a blacklist to a whitelist. --- britney2/policies/sourceppa.py | 18 +++++++----------- tests/data/sourceppa.json | 6 +++--- tests/test_autopkgtest.py | 18 ++++++++++-------- tests/test_sourceppa.py | 18 ++++++++++++++++-- 4 files changed, 36 insertions(+), 24 deletions(-) diff --git a/britney2/policies/sourceppa.py b/britney2/policies/sourceppa.py index 71c9e66..55a0e2d 100644 --- a/britney2/policies/sourceppa.py +++ b/britney2/policies/sourceppa.py @@ -13,12 +13,9 @@ from britney2.policies.policy import BasePolicy, PolicyVerdict LAUNCHPAD_URL = 'https://api.launchpad.net/1.0/' PRIMARY = LAUNCHPAD_URL + 'ubuntu/+archive/primary' -IGNORE = [ - None, - '', - 'IndexError', - LAUNCHPAD_URL + 'ubuntu/+archive/primary', - LAUNCHPAD_URL + 'debian/+archive/primary', +INCLUDE = [ + '~bileto-ppa-service/', + '~ci-train-ppa-service/', ] @@ -85,9 +82,9 @@ class SourcePPAPolicy(BasePolicy, Rest): accept = excuse.is_valid britney_excuses = self.britney.excuses version = source_data_srcdist.version - sourceppa = self.lp_get_source_ppa(source_name, version) + sourceppa = self.lp_get_source_ppa(source_name, version) or '' self.source_ppas_by_pkg[source_name][version] = sourceppa - if sourceppa in IGNORE: + if not [team for team in INCLUDE if team in sourceppa]: return PolicyVerdict.PASS shortppa = sourceppa.replace(LAUNCHPAD_URL, '') @@ -107,9 +104,8 @@ class SourcePPAPolicy(BasePolicy, Rest): friend_exc.is_valid = False friend_exc.addreason('source-ppa') friend_exc.policy_info['source-ppa'] = sourceppa_info - self.log("Blocking %s because %s from %s" % (friend, source_name, shortppa)) - friend_exc.addhtml("Blocking because %s from the same PPA %s is invalid" % - (friend, shortppa)) + self.log("Grouping %s with PPA %s" % (friend, shortppa)) + friend_exc.addhtml("Grouped with PPA %s" % shortppa) return PolicyVerdict.REJECTED_PERMANENTLY return PolicyVerdict.PASS diff --git a/tests/data/sourceppa.json b/tests/data/sourceppa.json index 70e5538..7e1cee8 100644 --- a/tests/data/sourceppa.json +++ b/tests/data/sourceppa.json @@ -1,7 +1,7 @@ { - "pal": {"2.0": "https://api.launchpad.net/1.0/team/ubuntu/ppa"}, - "buddy": {"2.0": "https://api.launchpad.net/1.0/team/ubuntu/ppa"}, - "friend": {"2.0": "https://api.launchpad.net/1.0/team/ubuntu/ppa"}, + "pal": {"2.0": "https://api.launchpad.net/1.0/~ci-train-ppa-service/+archive/NNNN"}, + "buddy": {"2.0": "https://api.launchpad.net/1.0/~ci-train-ppa-service/+archive/NNNN"}, + "friend": {"2.0": "https://api.launchpad.net/1.0/~ci-train-ppa-service/+archive/NNNN"}, "noppa": {"2.0": ""}, "unused": {"2.0": ""} } diff --git a/tests/test_autopkgtest.py b/tests/test_autopkgtest.py index b4cdfab..bc736ae 100755 --- a/tests/test_autopkgtest.py +++ b/tests/test_autopkgtest.py @@ -2181,8 +2181,9 @@ class T(TestBase): def test_sourceppa_policy(self): '''Packages from same source PPA get rejected for failed peer policy''' - self.sourceppa_cache['green'] = {'2': 'team/ubuntu/ppa'} - self.sourceppa_cache['red'] = {'2': 'team/ubuntu/ppa'} + ppa = 'devel/~ci-train-ppa-service/+archive/NNNN' + self.sourceppa_cache['green'] = {'2': ppa} + self.sourceppa_cache['red'] = {'2': ppa} with open(os.path.join(self.data.path, 'data/series-proposed/Blocks'), 'w') as f: f.write('green 12345 1471505000\ndarkgreen 98765 1471500000\n') @@ -2197,19 +2198,20 @@ class T(TestBase): {'green': [('reason', 'block')], 'red': [('reason', 'source-ppa')]} )[1] - self.assertEqual(exc['red']['policy_info']['source-ppa'], {'red': 'team/ubuntu/ppa', 'green': 'team/ubuntu/ppa'}) + self.assertEqual(exc['red']['policy_info']['source-ppa'], {'red': ppa, 'green': ppa}) with open(os.path.join(self.data.path, 'data/series-proposed/SourcePPA')) as f: res = json.load(f) - self.assertEqual(res, {'red': {'2': 'team/ubuntu/ppa'}, - 'green': {'2': 'team/ubuntu/ppa'}, + self.assertEqual(res, {'red': {'2': ppa}, + 'green': {'2': ppa}, 'gcc-5': {'1': ''}}) def test_sourceppa_missingbuild(self): '''Packages from same source PPA get rejected for failed peer FTBFS''' - self.sourceppa_cache['green'] = {'2': 'team/ubuntu/ppa'} - self.sourceppa_cache['red'] = {'2': 'team/ubuntu/ppa'} + ppa = 'devel/~ci-train-ppa-service/+archive/ZZZZ' + self.sourceppa_cache['green'] = {'2': ppa} + self.sourceppa_cache['red'] = {'2': ppa} self.data.add_src('green', True, {'Version': '2', 'Testsuite': 'autopkgtest'}) self.data.add('libgreen1', True, {'Version': '2', 'Source': 'green', 'Architecture': 'i386'}, add_src=False) @@ -2221,7 +2223,7 @@ class T(TestBase): 'on-unimportant-architectures': []})], 'red': [('reason', 'source-ppa')]} )[1] - self.assertEqual(exc['red']['policy_info']['source-ppa'], {'red': 'team/ubuntu/ppa', 'green': 'team/ubuntu/ppa'}) + self.assertEqual(exc['red']['policy_info']['source-ppa'], {'red': ppa, 'green': ppa}) if __name__ == '__main__': unittest.main() diff --git a/tests/test_sourceppa.py b/tests/test_sourceppa.py index 2cfcbd4..180c024 100755 --- a/tests/test_sourceppa.py +++ b/tests/test_sourceppa.py @@ -150,7 +150,7 @@ class T(unittest.TestCase): def test_approve_ppa(self): """Approve packages by their PPA.""" - shortppa = 'team/ubuntu/ppa' + shortppa = '~ci-train-ppa-service/+archive/NNNN' pol = SourcePPAPolicy(FakeOptions, {}) pol.filename = CACHE_FILE pol.initialise(FakeBritney()) @@ -159,9 +159,23 @@ class T(unittest.TestCase): self.assertEqual(pol.apply_policy_impl(output, None, pkg, None, FakeData, FakeExcuse), PolicyVerdict.PASS) self.assertEqual(output, dict(pal=shortppa, buddy=shortppa, friend=shortppa)) + def test_ignore_ppa(self): + """Ignore packages in non-bileto PPAs.""" + shortppa = '~kernel-or-whatever/+archive/ppa' + pol = SourcePPAPolicy(FakeOptions, {}) + pol.filename = CACHE_FILE + pol.initialise(FakeBritney()) + for name, versions in pol.cache.items(): + for version in versions: + pol.cache[name][version] = shortppa + output = {} + for pkg in ('pal', 'buddy', 'friend', 'noppa'): + self.assertEqual(pol.apply_policy_impl(output, None, pkg, None, FakeData, FakeExcuse), PolicyVerdict.PASS) + self.assertEqual(output, dict()) + def test_reject_ppa(self): """Reject packages by their PPA.""" - shortppa = 'team/ubuntu/ppa' + shortppa = '~ci-train-ppa-service/+archive/NNNN' pol = SourcePPAPolicy(FakeOptions, {}) pol.filename = CACHE_FILE brit = FakeBritney()