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>
This commit is contained in:
Yehuda Sadeh 2015-04-24 13:49:59 -07:00
parent 1e9ba11d9e
commit c41ebab9cf

View file

@ -64,8 +64,9 @@ def nuke_prefixed_buckets_on_conn(prefix, name, conn):
print 'prefix=',prefix
if bucket.name.startswith(prefix):
print 'Cleaning bucket {bucket}'.format(bucket=bucket)
success = False
for i in xrange(2):
try:
# bucket.set_canned_acl('private')
for key in bucket.list_versions():
print 'Cleaning bucket {bucket} key {key}'.format(
bucket=bucket,
@ -74,13 +75,21 @@ def nuke_prefixed_buckets_on_conn(prefix, name, conn):
# 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're not the owner of the bucket; ignore
# 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
if targets.main.master == None:
@ -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