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 <yehuda@redhat.com>
(cherry picked from commit c41ebab9cf)
This commit is contained in:
Yehuda Sadeh 2015-04-24 13:49:59 -07:00
parent 366fdee269
commit 5d72a43ffa

View file

@ -64,22 +64,31 @@ def nuke_prefixed_buckets_on_conn(prefix, name, conn):
print 'prefix=',prefix print 'prefix=',prefix
if bucket.name.startswith(prefix): if bucket.name.startswith(prefix):
print 'Cleaning bucket {bucket}'.format(bucket=bucket) print 'Cleaning bucket {bucket}'.format(bucket=bucket)
try: success = False
# bucket.set_canned_acl('private') for i in xrange(2):
for key in bucket.list_versions(): try:
print 'Cleaning bucket {bucket} key {key}'.format( for key in bucket.list_versions():
bucket=bucket, print 'Cleaning bucket {bucket} key {key}'.format(
key=key, bucket=bucket,
) key=key,
# key.set_canned_acl('private') )
bucket.delete_key(key.name, version_id = key.version_id) # key.set_canned_acl('private')
bucket.delete() bucket.delete_key(key.name, version_id = key.version_id)
except boto.exception.S3ResponseError as e: bucket.delete()
if e.error_code != 'AccessDenied': success = True
print 'GOT UNWANTED ERROR', e.error_code except boto.exception.S3ResponseError as e:
raise if e.error_code != 'AccessDenied':
# seems like we're not the owner of the bucket; ignore print 'GOT UNWANTED ERROR', e.error_code
pass 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): def nuke_prefixed_buckets(prefix):
# If no regions are specified, use the simple method # 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.' print 'Done with cleanup of test buckets.'
class TargetConfig: class TargetConfig:
def __init__(self, cfg, section): def __init__(self, cfg, section):
self.port = None self.port = None