From 5c74268d754b818790416c0fbefb59066b8245a6 Mon Sep 17 00:00:00 2001 From: Robert Bruce Park Date: Mon, 5 Dec 2016 06:14:38 -0700 Subject: [PATCH] Better debug logging for sourceppa problems. --- policies/sourceppa.py | 11 +++++++---- tests/test_sourceppa.py | 4 ++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/policies/sourceppa.py b/policies/sourceppa.py index 8df5c75..228182a 100644 --- a/policies/sourceppa.py +++ b/policies/sourceppa.py @@ -11,9 +11,11 @@ from policies.policy import BasePolicy, PolicyVerdict LAUNCHPAD_URL = 'https://api.launchpad.net/1.0/' PRIMARY = LAUNCHPAD_URL + 'ubuntu/+archive/primary' IGNORE = [ + None, '', - 'https://api.launchpad.net/1.0/ubuntu/+archive/primary', - 'https://api.launchpad.net/1.0/debian/+archive/primary', + 'IndexError', + LAUNCHPAD_URL + 'ubuntu/+archive/primary', + LAUNCHPAD_URL + 'debian/+archive/primary', ] @@ -68,11 +70,12 @@ class SourcePPAPolicy(BasePolicy): 'exact_match': 'true', }) try: - return data['entries'][0]['copy_source_archive_link'] or '' + return data['entries'][0]['copy_source_archive_link'] # IndexError means no packages in -proposed matched this name/version, # which is expected to happen when bileto runs britney. except IndexError: - return '' + self.log('SourcePPA getPackageUploads IndexError (%s %s)' % (pkg, version)) + return 'IndexError' def initialise(self, britney): """Load cached source ppa data""" diff --git a/tests/test_sourceppa.py b/tests/test_sourceppa.py index 35ffd5f..aeb35d6 100755 --- a/tests/test_sourceppa.py +++ b/tests/test_sourceppa.py @@ -63,7 +63,7 @@ class T(unittest.TestCase): context.getcode.return_value = 200 context.read.return_value = b'{"entries": []}' pol = SourcePPAPolicy(FakeOptions) - self.assertEqual(pol.lp_get_source_ppa('hello', '1.0'), '') + self.assertEqual(pol.lp_get_source_ppa('hello', '1.0'), 'IndexError') @patch('policies.sourceppa.urllib.request.urlopen') def test_lp_rest_api_no_source_ppa(self, urlopen): @@ -72,7 +72,7 @@ class T(unittest.TestCase): context.getcode.return_value = 200 context.read.return_value = b'{"entries": [{"copy_source_archive_link": null, "other_stuff": "ignored"}]}' pol = SourcePPAPolicy(FakeOptions) - self.assertEqual(pol.lp_get_source_ppa('hello', '1.0'), '') + self.assertEqual(pol.lp_get_source_ppa('hello', '1.0'), None) @patch('policies.sourceppa.urllib.request.urlopen') def test_lp_rest_api_with_source_ppa(self, urlopen):