Fix SourcePPA policy by inspecting build_link instead. (LP: #1648000)

broken-hint-logging
Robert Bruce Park 8 years ago
parent 5f4c2e735d
commit df495582e2

@ -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"""

@ -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."""

Loading…
Cancel
Save