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
diff --git a/files/archive-to-swift.py b/files/archive-to-swift.py
index 535c7f5..1d480b4 100755
--- a/files/archive-to-swift.py
+++ b/files/archive-to-swift.py
@@ -114,13 +114,20 @@ class SwiftCloudStorage(CloudStorage):
114 segment_name = '{}/{}/{}/{}/{:08d}'.format(file_name, mtime, file_size, self.segment_size, segment_id)114 segment_name = '{}/{}/{}/{}/{:08d}'.format(file_name, mtime, file_size, self.segment_size, segment_id)
115 segment_id += 1115 segment_id += 1
116 log.info("Uploading segment {}".format(segment_id))116 log.info("Uploading segment {}".format(segment_id))
117 try:117 max_retries = 10
118 self.swift.put_object(segment_bucket,118 for attempt in range(max_retries):
119 self.expand_path(segment_name),119 try:
120 data,120 self.swift.put_object(segment_bucket,
121 content_type="application/octet-stream")121 self.expand_path(segment_name),
122 except swiftclient.ClientException:122 data,
123 log.info("Segment upload failed!")123 content_type="application/octet-stream")
124 except swiftclient.ClientException:
125 log.info("Segment upload failed on attempt {} - retrying".format(attempt))
126 else:
127 log.info("Segment upload succeeded on attempt {}".format(attempt))
128 break
129 else:
130 log.info("Segment upload failed too many times ({}) - aborting upload".format(attempt))
124 return Status.FAILURE131 return Status.FAILURE
125132
126 # New we have all the part uploaded, create the manifest133 # New we have all the part uploaded, create the manifest
@@ -156,18 +163,24 @@ class SwiftCloudStorage(CloudStorage):
156163
157 try:164 try:
158 with open(path, "rb") as obj:165 with open(path, "rb") as obj:
159 try:166 max_retries = 10
160 self.swift.put_object(self.bucket,167 for attempt in range(max_retries):
161 self.expand_path(file_name),168 try:
162 obj,169 self.swift.put_object(self.bucket,
163 content_type="application/octet-stream")170 self.expand_path(file_name),
164 except swiftclient.ClientException:171 obj,
165 log.info("Upload failed")172 content_type="application/octet-stream")
173 except swiftclient.ClientException:
174 log.info("Upload failed on attempt {} - retrying".format(attempt))
175 else:
176 log.info("Upload succeeded on attempt {}".format(attempt))
177 return Status.SUCCESS
178 else:
179 log.info("Upload failed too many times ({}) - aborting upload".format(attempt))
166 return Status.FAILURE180 return Status.FAILURE
167 except IOError:181 except IOError:
168 log.info("Unable to read {}".format(path))182 log.info("Unable to read {}".format(path))
169 return Status.FAILURE183 return Status.FAILURE
170 return Status.SUCCESS
171184
172 def delete(self, name):185 def delete(self, name):
173 """ Delete an object from cloud storage186 """ Delete an object from cloud storage

Subscribers

People subscribed via source and target branches