ignore launchpad connection errors

If we can't connect to the launchpad API, emit a warning but continue. 99%
of the time we don't need to check the launchpad name anyway, so failing
because LP is down is just frustrating and not useful to anyone.

Change-Id: I21b1b910894645ea1743c36bc1d92130cc92129e
Signed-off-by: Doug Hellmann <doug@doughellmann.com>
This commit is contained in:
Doug Hellmann 2016-12-01 16:01:56 -05:00
parent 64928ca48c
commit 1e942f2918
2 changed files with 29 additions and 5 deletions

View File

@ -76,9 +76,15 @@ def validate_launchpad(deliverable_info, mk_warning, mk_error):
except KeyError:
mk_error('No launchpad project given')
else:
lp_resp = requests.get('https://api.launchpad.net/1.0/' + lp_name)
if (lp_resp.status_code // 100) == 4:
mk_error('Launchpad project %s does not exist' % lp_name)
try:
lp_resp = requests.get('https://api.launchpad.net/1.0/' + lp_name)
except requests.exceptions.ConnectionError as e:
# The flakey Launchpad API failed. Don't punish the user for that.
mk_warning('Could not verify launchpad project %s (%s)' %
(lp_name, e))
else:
if (lp_resp.status_code // 100) == 4:
mk_error('Launchpad project %s does not exist' % lp_name)
def validate_team(deliverable_info, team_data, mk_warning, mk_error):

View File

@ -37,7 +37,9 @@ class TestValidateLaunchpad(base.BaseTestCase):
self.assertEqual(0, len(warnings))
self.assertEqual(1, len(errors))
def test_invalid_launchpad_name(self):
@mock.patch('requests.get')
def test_invalid_launchpad_name(self, get):
get.return_value = mock.Mock(status_code=404)
warnings = []
errors = []
validate.validate_launchpad(
@ -48,7 +50,9 @@ class TestValidateLaunchpad(base.BaseTestCase):
self.assertEqual(0, len(warnings))
self.assertEqual(1, len(errors))
def test_valid_launchpad_name(self):
@mock.patch('requests.get')
def test_valid_launchpad_name(self, get):
get.return_value = mock.Mock(status_code=200)
warnings = []
errors = []
validate.validate_launchpad(
@ -59,6 +63,20 @@ class TestValidateLaunchpad(base.BaseTestCase):
self.assertEqual(0, len(warnings))
self.assertEqual(0, len(errors))
@mock.patch('requests.get')
def test_launchpad_timeout(self, get):
import requests
get.side_effect = requests.exceptions.ConnectionError('testing')
warnings = []
errors = []
validate.validate_launchpad(
{'launchpad': 'oslo.config'},
warnings.append,
errors.append,
)
self.assertEqual(1, len(warnings))
self.assertEqual(0, len(errors))
class TestValidateTeam(base.BaseTestCase):