Merge "ignore launchpad connection errors"

This commit is contained in:
Jenkins
2016-12-05 12:20:07 +00:00
committed by Gerrit Code Review
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

@@ -38,7 +38,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(
@@ -49,7 +51,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(
@@ -60,6 +64,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):