From 1e942f291817808903307fca7a9af54b58d26ca4 Mon Sep 17 00:00:00 2001 From: Doug Hellmann Date: Thu, 1 Dec 2016 16:01:56 -0500 Subject: [PATCH] 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 --- openstack_releases/cmds/validate.py | 12 +++++++++--- openstack_releases/tests/test_validate.py | 22 ++++++++++++++++++++-- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/openstack_releases/cmds/validate.py b/openstack_releases/cmds/validate.py index 97017e90f7..c933282d59 100644 --- a/openstack_releases/cmds/validate.py +++ b/openstack_releases/cmds/validate.py @@ -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): diff --git a/openstack_releases/tests/test_validate.py b/openstack_releases/tests/test_validate.py index 1a16be56f3..c6725dbae2 100644 --- a/openstack_releases/tests/test_validate.py +++ b/openstack_releases/tests/test_validate.py @@ -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):