Merge ~hloeung/ubuntu-repository-cache:master into ubuntu-repository-cache:master

Proposed by Haw Loeung
Status: Merged
Approved by: Haw Loeung
Approved revision: 5db7c3ee0a53166ca5ac7deddf3665de242b32a3
Merged at revision: 2d0d0fb344d4047121007fccd8debee545299731
Proposed branch: ~hloeung/ubuntu-repository-cache:master
Merge into: ubuntu-repository-cache:master
Diff against target: 50 lines (+22/-8)
1 file modified
lib/ubuntu_repository_cache/metadata_sync.py (+22/-8)
Reviewer Review Type Date Requested Status
Thomas Cuthbert (community) Approve
Canonical IS Reviewers Pending
Review via email: mp+429345@code.launchpad.net

Commit message

Make it more resilient around DNS failures on upstream metadata sync

To post a comment you must log in.
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

This merge proposal is being monitored by mergebot. Change the status to Approved to merge.

Revision history for this message
Thomas Cuthbert (tcuthbert) wrote :

LGTM +1 with some comments inline that are nonblocking.

review: Approve
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

Change successfully merged at revision 2d0d0fb344d4047121007fccd8debee545299731

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/lib/ubuntu_repository_cache/metadata_sync.py b/lib/ubuntu_repository_cache/metadata_sync.py
2index 8cdb85f..b2da773 100644
3--- a/lib/ubuntu_repository_cache/metadata_sync.py
4+++ b/lib/ubuntu_repository_cache/metadata_sync.py
5@@ -152,9 +152,23 @@ def mirror_archive(hostname, apache_root, local_unit, log, mirror_series, rsync_
6 dest = '/'.join((apache_data, 'ubuntu_{}_u{}'.format(now.isoformat(sep='_'), local_unit.split('/')[-1])))
7 log('Performing sync to %s' % dest)
8
9- # The archive may have multiple IP addresses, try each several times.
10- archive_ips = [i for i in socket.gethostbyname_ex(hostname)[-1]]
11- archive_ip_iterator = cycle(archive_ips)
12+ max_retries = 5
13+ for attempt in range(1, max_retries):
14+ try:
15+ # The archive may have multiple IP addresses, try each several times.
16+ archive_ips = [i for i in socket.gethostbyname_ex(hostname)[-1]]
17+ archive_ip_iterator = cycle(archive_ips)
18+ except socket.gaierror as e:
19+ # Save the exact exception and reuse when we need to
20+ # reraise it after exhausting all available attempts.
21+ exp = e
22+ # Exponential backoff.
23+ sleep = random.randint(attempt, 10 * attempt)
24+ time.sleep(sleep)
25+ else:
26+ break
27+ else:
28+ raise exp
29
30 content_mirrored = False
31
32@@ -400,13 +414,13 @@ def clean_metadata_dir(apache_root, log, keep=None):
33 keep.add(entry)
34 count += 1
35
36+ # We want to make sure it isn't the directory
37+ # ubuntu_active points to (LP#1799595).
38+ active = os.path.realpath('/'.join((apache_data, 'ubuntu_active')))
39+ # We also want to make sure it isn't ubuntu_next, in-progress sync.
40+ ubuntu_next = os.path.realpath('/'.join((apache_data, 'ubuntu_next')))
41 for entry in [os.path.realpath(p) for p in glob.glob(glob_path)]:
42 if entry not in keep:
43- # We want to make sure it isn't the directory
44- # ubuntu_active points to (LP#1799595).
45- active = os.path.realpath('/'.join((apache_data, 'ubuntu_active')))
46- # We also want to make sure it isn't ubuntu_next, in-progress sync.
47- ubuntu_next = os.path.realpath('/'.join((apache_data, 'ubuntu_next')))
48 if entry == active:
49 log('ubuntu_active points to {}, skipping'.format(entry))
50 elif entry == ubuntu_next:

Subscribers

People subscribed via source and target branches