From 5d72a43ffa08814243f854a1578abe60e6ac39d1 Mon Sep 17 00:00:00 2001 From: Yehuda Sadeh Date: Fri, 24 Apr 2015 13:49:59 -0700 Subject: [PATCH] s3tests: cleanup, set bucket acls if permission denied retry bucket removal after setting the bucket permissions if we're getting pemission denied. This will make sure the bucket gets removed. Signed-off-by: Yehuda Sadeh (cherry picked from commit c41ebab9cf93617f06084cf88c297188b4aa9f67) --- s3tests/functional/__init__.py | 42 ++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/s3tests/functional/__init__.py b/s3tests/functional/__init__.py index 6d0d680..a575ceb 100644 --- a/s3tests/functional/__init__.py +++ b/s3tests/functional/__init__.py @@ -64,22 +64,31 @@ def nuke_prefixed_buckets_on_conn(prefix, name, conn): print 'prefix=',prefix if bucket.name.startswith(prefix): print 'Cleaning bucket {bucket}'.format(bucket=bucket) - try: - # bucket.set_canned_acl('private') - for key in bucket.list_versions(): - print 'Cleaning bucket {bucket} key {key}'.format( - bucket=bucket, - key=key, - ) - # key.set_canned_acl('private') - bucket.delete_key(key.name, version_id = key.version_id) - bucket.delete() - except boto.exception.S3ResponseError as e: - if e.error_code != 'AccessDenied': - print 'GOT UNWANTED ERROR', e.error_code - raise - # seems like we're not the owner of the bucket; ignore - pass + success = False + for i in xrange(2): + try: + for key in bucket.list_versions(): + print 'Cleaning bucket {bucket} key {key}'.format( + bucket=bucket, + key=key, + ) + # key.set_canned_acl('private') + bucket.delete_key(key.name, version_id = key.version_id) + bucket.delete() + success = True + except boto.exception.S3ResponseError as e: + if e.error_code != 'AccessDenied': + print 'GOT UNWANTED ERROR', e.error_code + raise + # seems like we don't have permissions set appropriately, we'll + # modify permissions and retry + pass + + if success: + return + + bucket.set_canned_acl('private') + def nuke_prefixed_buckets(prefix): # If no regions are specified, use the simple method @@ -106,7 +115,6 @@ def nuke_prefixed_buckets(prefix): print 'Done with cleanup of test buckets.' - class TargetConfig: def __init__(self, cfg, section): self.port = None