From df495582e2ce08e4316b46ad4f16380dea3fea06 Mon Sep 17 00:00:00 2001 From: Robert Bruce Park Date: Tue, 28 Feb 2017 14:34:10 -0800 Subject: [PATCH] Fix SourcePPA policy by inspecting build_link instead. (LP: #1648000) --- britney2/policies/sourceppa.py | 17 ++++++++++++----- tests/test_sourceppa.py | 14 +++++++------- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/britney2/policies/sourceppa.py b/britney2/policies/sourceppa.py index 01a5955..71c9e66 100644 --- a/britney2/policies/sourceppa.py +++ b/britney2/policies/sourceppa.py @@ -47,21 +47,28 @@ class SourcePPAPolicy(BasePolicy, Rest): if cached is not None: return cached - data = self.query_lp_rest_api('%s/%s' % (self.options.distribution, self.options.series), { - 'ws.op': 'getPackageUploads', - 'archive': PRIMARY, + data = self.query_lp_rest_api('%s/+archive/primary' % self.options.distribution, { + 'ws.op': 'getPublishedSources', 'pocket': 'Proposed', - 'name': pkg, + 'source_name': pkg, 'version': version, 'exact_match': 'true', + 'distro_series': '/%s/%s' % (self.options.distribution, self.options.series), }) try: - return data['entries'][0]['copy_source_archive_link'] + sourcepub = data['entries'][0]['self_link'] # IndexError means no packages in -proposed matched this name/version, # which is expected to happen when bileto runs britney. except IndexError: self.log('SourcePPA getPackageUploads IndexError (%s %s)' % (pkg, version)) return 'IndexError' + data = self.query_lp_rest_api(sourcepub, {'ws.op': 'getPublishedBinaries'}) + for binary in data['entries']: + link = binary['build_link'] or '' + if '/+archive/' in link: + ppa, _, buildid = link.partition('/+build/') + return ppa + return '' def initialise(self, britney): """Load cached source ppa data""" diff --git a/tests/test_sourceppa.py b/tests/test_sourceppa.py index 5e002f3..2cfcbd4 100755 --- a/tests/test_sourceppa.py +++ b/tests/test_sourceppa.py @@ -70,18 +70,18 @@ class T(unittest.TestCase): """Identify when package has no source PPA""" context = urlopen.return_value.__enter__.return_value context.getcode.return_value = 200 - context.read.return_value = b'{"entries": [{"copy_source_archive_link": null, "other_stuff": "ignored"}]}' + context.read.return_value = b'{"entries": [{"self_link": "https://api.launchpad.net/1.0/ubuntu/+archive/primary/+sourcepub/12345", "build_link": "https://api.launchpad.net/1.0/ubuntu/+source/gcc-5/5.4.1-7ubuntu1/+build/12066956", "other_stuff": "ignored"}]}' pol = SourcePPAPolicy(FakeOptions, {}) - self.assertEqual(pol.lp_get_source_ppa('hello', '1.0'), None) + self.assertEqual(pol.lp_get_source_ppa('hello', '1.0'), '') @patch('britney2.policies.sourceppa.urllib.request.urlopen') def test_lp_rest_api_with_source_ppa(self, urlopen): """Identify source PPA""" context = urlopen.return_value.__enter__.return_value context.getcode.return_value = 200 - context.read.return_value = b'{"entries": [{"copy_source_archive_link": "https://api.launchpad.net/1.0/team/ubuntu/ppa", "other_stuff": "ignored"}]}' + context.read.return_value = b'{"entries": [{"self_link": "https://api.launchpad.net/1.0/ubuntu/+archive/primary/+sourcepub/12345", "build_link": "https://api.launchpad.net/1.0/~ci-train-ppa-service/+archive/ubuntu/2516/+build/12063031", "other_stuff": "ignored"}]}' pol = SourcePPAPolicy(FakeOptions, {}) - self.assertEqual(pol.lp_get_source_ppa('hello', '1.0'), 'https://api.launchpad.net/1.0/team/ubuntu/ppa') + self.assertEqual(pol.lp_get_source_ppa('hello', '1.0'), 'https://api.launchpad.net/1.0/~ci-train-ppa-service/+archive/ubuntu/2516') @patch('britney2.policies.sourceppa.urllib.request.urlopen') def test_lp_rest_api_errors(self, urlopen): @@ -141,12 +141,12 @@ class T(unittest.TestCase): context = urlopen.return_value.__enter__.return_value context.getcode.return_value = 200 - context.read.return_value = b'{"entries": [{"copy_source_archive_link": "https://api.launchpad.net/1.0/team/ubuntu/ppa", "other_stuff": "ignored"}]}' + context.read.return_value = b'{"entries": [{"self_link": "https://api.launchpad.net/1.0/ubuntu/+archive/primary/+sourcepub/12345", "build_link": "https://api.launchpad.net/1.0/~ci-train-ppa-service/+archive/ubuntu/2516/+build/12063031", "other_stuff": "ignored"}]}' urlopen.side_effect = l() pol = SourcePPAPolicy(FakeOptions, {}) pol.lp_get_source_ppa('hello', '1.0') - self.assertEqual(urlopen.call_count, 4) - self.assertEqual(pol.lp_get_source_ppa('hello', '1.0'), 'https://api.launchpad.net/1.0/team/ubuntu/ppa') + self.assertEqual(urlopen.call_count, 5) + self.assertEqual(pol.lp_get_source_ppa('hello', '1.0'), 'https://api.launchpad.net/1.0/~ci-train-ppa-service/+archive/ubuntu/2516') def test_approve_ppa(self): """Approve packages by their PPA."""