Merge ~barryprice/container-log-archive-charm/+git/container-log-archive-charm:master into container-log-archive-charm:master

Proposed by Barry Price
Status: Merged
Approved by: Barry Price
Approved revision: 28e9bf6cae53d127a493cc7937e98fbce98250b5
Merged at revision: 141e8604f9ec6cbcad433f43a8b108d32196bd7b
Proposed branch: ~barryprice/container-log-archive-charm/+git/container-log-archive-charm:master
Merge into: container-log-archive-charm:master
Diff against target: 65 lines (+28/-15)
1 file modified
files/archive-to-swift.py (+28/-15)
Reviewer Review Type Date Requested Status
Tom Haddon Approve
Canonical IS Reviewers Pending
Review via email: mp+399339@code.launchpad.net

Commit message

Add retry logic to swift uploads, cRT#129788

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
Tom Haddon (mthaddon) wrote :

One minor comment inline

Revision history for this message
Tom Haddon (mthaddon) wrote :

LGTM, thx

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

Change successfully merged at revision 141e8604f9ec6cbcad433f43a8b108d32196bd7b

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/files/archive-to-swift.py b/files/archive-to-swift.py
2index 535c7f5..1d480b4 100755
3--- a/files/archive-to-swift.py
4+++ b/files/archive-to-swift.py
5@@ -114,13 +114,20 @@ class SwiftCloudStorage(CloudStorage):
6 segment_name = '{}/{}/{}/{}/{:08d}'.format(file_name, mtime, file_size, self.segment_size, segment_id)
7 segment_id += 1
8 log.info("Uploading segment {}".format(segment_id))
9- try:
10- self.swift.put_object(segment_bucket,
11- self.expand_path(segment_name),
12- data,
13- content_type="application/octet-stream")
14- except swiftclient.ClientException:
15- log.info("Segment upload failed!")
16+ max_retries = 10
17+ for attempt in range(max_retries):
18+ try:
19+ self.swift.put_object(segment_bucket,
20+ self.expand_path(segment_name),
21+ data,
22+ content_type="application/octet-stream")
23+ except swiftclient.ClientException:
24+ log.info("Segment upload failed on attempt {} - retrying".format(attempt))
25+ else:
26+ log.info("Segment upload succeeded on attempt {}".format(attempt))
27+ break
28+ else:
29+ log.info("Segment upload failed too many times ({}) - aborting upload".format(attempt))
30 return Status.FAILURE
31
32 # New we have all the part uploaded, create the manifest
33@@ -156,18 +163,24 @@ class SwiftCloudStorage(CloudStorage):
34
35 try:
36 with open(path, "rb") as obj:
37- try:
38- self.swift.put_object(self.bucket,
39- self.expand_path(file_name),
40- obj,
41- content_type="application/octet-stream")
42- except swiftclient.ClientException:
43- log.info("Upload failed")
44+ max_retries = 10
45+ for attempt in range(max_retries):
46+ try:
47+ self.swift.put_object(self.bucket,
48+ self.expand_path(file_name),
49+ obj,
50+ content_type="application/octet-stream")
51+ except swiftclient.ClientException:
52+ log.info("Upload failed on attempt {} - retrying".format(attempt))
53+ else:
54+ log.info("Upload succeeded on attempt {}".format(attempt))
55+ return Status.SUCCESS
56+ else:
57+ log.info("Upload failed too many times ({}) - aborting upload".format(attempt))
58 return Status.FAILURE
59 except IOError:
60 log.info("Unable to read {}".format(path))
61 return Status.FAILURE
62- return Status.SUCCESS
63
64 def delete(self, name):
65 """ Delete an object from cloud storage

Subscribers

People subscribed via source and target branches