2929from retry import RetryResult
3030
3131
32- retry_429 = RetryErrors (exceptions .TooManyRequests )
3332HTTP = httplib2 .Http ()
3433
3534
35+ def _bad_copy (bad_request ):
36+ """Predicate: pass only exceptions for a failed copyTo."""
37+ err_msg = bad_request .message
38+ return (err_msg .startswith ('No file found in request. (POST' ) and
39+ 'copyTo' in err_msg )
40+
41+
42+ retry_429 = RetryErrors (exceptions .TooManyRequests )
43+ retry_bad_copy = RetryErrors (exceptions .BadRequest ,
44+ error_predicate = _bad_copy )
45+
46+
3647class Config (object ):
3748 """Run-time configuration to be modified at set-up.
3849
@@ -188,7 +199,8 @@ def test_copy_existing_file(self):
188199 blob .upload_from_filename (filename )
189200 self .case_blobs_to_delete .append (blob )
190201
191- new_blob = self .bucket .copy_blob (blob , self .bucket , 'CloudLogoCopy' )
202+ new_blob = retry_bad_copy (self .bucket .copy_blob )(
203+ blob , self .bucket , 'CloudLogoCopy' )
192204 self .case_blobs_to_delete .append (new_blob )
193205
194206 base_contents = blob .download_as_string ()
@@ -214,7 +226,8 @@ def setUpClass(cls):
214226
215227 # Copy main blob onto remaining in FILENAMES.
216228 for filename in cls .FILENAMES [1 :]:
217- new_blob = cls .bucket .copy_blob (blob , cls .bucket , filename )
229+ new_blob = retry_bad_copy (cls .bucket .copy_blob )(
230+ blob , cls .bucket , filename )
218231 cls .suite_blobs_to_delete .append (new_blob )
219232
220233 @classmethod
@@ -275,7 +288,8 @@ def setUpClass(cls):
275288 blob .upload_from_filename (simple_path )
276289 cls .suite_blobs_to_delete = [blob ]
277290 for filename in cls .FILENAMES [1 :]:
278- new_blob = cls .bucket .copy_blob (blob , cls .bucket , filename )
291+ new_blob = retry_bad_copy (cls .bucket .copy_blob )(
292+ blob , cls .bucket , filename )
279293 cls .suite_blobs_to_delete .append (new_blob )
280294
281295 @classmethod
0 commit comments