mirror of
https://git.launchpad.net/~ubuntu-release/britney/+git/britney2-ubuntu
synced 2025-05-25 09:21:30 +00:00
sourceppa: Retry 5 times on HTTP 503s
We get these quite frequently from the LP API - have a few attempts.
This commit is contained in:
parent
41d51369f5
commit
9661362880
@ -5,6 +5,7 @@ import urllib.request
|
|||||||
import urllib.parse
|
import urllib.parse
|
||||||
|
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
|
from urllib.error import HTTPError
|
||||||
|
|
||||||
from britney2.policies.policy import BasePolicy, PolicyVerdict
|
from britney2.policies.policy import BasePolicy, PolicyVerdict
|
||||||
|
|
||||||
@ -65,6 +66,17 @@ class SourcePPAPolicy(BasePolicy):
|
|||||||
return self.query_lp_rest_api(obj, query, retries - 1)
|
return self.query_lp_rest_api(obj, query, retries - 1)
|
||||||
else:
|
else:
|
||||||
raise
|
raise
|
||||||
|
except HTTPError as e:
|
||||||
|
if e.code != 503:
|
||||||
|
raise
|
||||||
|
|
||||||
|
# 503s are transient
|
||||||
|
if retries > 1:
|
||||||
|
self.log("Caught error 503 downloading '%s', will retry %d more times."
|
||||||
|
% (url, retries))
|
||||||
|
return self.query_lp_rest_api(obj, query, retries - 1)
|
||||||
|
else:
|
||||||
|
raise
|
||||||
|
|
||||||
def lp_get_source_ppa(self, pkg, version):
|
def lp_get_source_ppa(self, pkg, version):
|
||||||
"""Ask LP what source PPA pkg was copied from"""
|
"""Ask LP what source PPA pkg was copied from"""
|
||||||
|
@ -109,6 +109,21 @@ class T(unittest.TestCase):
|
|||||||
pol.lp_get_source_ppa('hello', '1.0')
|
pol.lp_get_source_ppa('hello', '1.0')
|
||||||
self.assertEqual(urlopen.call_count, 5)
|
self.assertEqual(urlopen.call_count, 5)
|
||||||
|
|
||||||
|
@patch('britney2.policies.sourceppa.urllib.request.urlopen')
|
||||||
|
def test_lp_rest_api_unavailable(self, urlopen):
|
||||||
|
"""If we get a 503 connecting to LP, we try 5 times"""
|
||||||
|
from urllib.error import HTTPError
|
||||||
|
# test that we're retried 5 times on 503
|
||||||
|
urlopen.side_effect = HTTPError(None,
|
||||||
|
503,
|
||||||
|
'Service Temporarily Unavailable',
|
||||||
|
None,
|
||||||
|
None)
|
||||||
|
pol = SourcePPAPolicy(FakeOptions, {})
|
||||||
|
with self.assertRaises(HTTPError):
|
||||||
|
pol.lp_get_source_ppa('hello', '1.0')
|
||||||
|
self.assertEqual(urlopen.call_count, 5)
|
||||||
|
|
||||||
def test_approve_ppa(self):
|
def test_approve_ppa(self):
|
||||||
"""Approve packages by their PPA."""
|
"""Approve packages by their PPA."""
|
||||||
shortppa = 'team/ubuntu/ppa'
|
shortppa = 'team/ubuntu/ppa'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user