forked from TrueCloudLab/s3-tests
Refactor bucket nuking in cleanup.
This commit is contained in:
parent
f30f9d0aca
commit
f58641d0bf
1 changed files with 31 additions and 28 deletions
|
@ -47,40 +47,43 @@ def choose_bucket_prefix(template, max_len=30):
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def nuke_bucket(bucket):
|
||||||
|
try:
|
||||||
|
bucket.set_canned_acl('private')
|
||||||
|
# TODO: deleted_cnt and the while loop is a work around for rgw
|
||||||
|
# not sending the
|
||||||
|
deleted_cnt = 1
|
||||||
|
while deleted_cnt:
|
||||||
|
deleted_cnt = 0
|
||||||
|
for key in bucket.list():
|
||||||
|
print 'Cleaning bucket {bucket} key {key}'.format(
|
||||||
|
bucket=bucket,
|
||||||
|
key=key,
|
||||||
|
)
|
||||||
|
key.set_canned_acl('private')
|
||||||
|
key.delete()
|
||||||
|
deleted_cnt += 1
|
||||||
|
bucket.delete()
|
||||||
|
except boto.exception.S3ResponseError as e:
|
||||||
|
# TODO workaround for buggy rgw that fails to send
|
||||||
|
# error_code, remove
|
||||||
|
if (e.status == 403
|
||||||
|
and e.error_code is None
|
||||||
|
and e.body == ''):
|
||||||
|
e.error_code = 'AccessDenied'
|
||||||
|
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
|
||||||
|
|
||||||
def nuke_prefixed_buckets():
|
def nuke_prefixed_buckets():
|
||||||
for name, conn in s3.items():
|
for name, conn in s3.items():
|
||||||
print 'Cleaning buckets from connection {name}'.format(name=name)
|
print 'Cleaning buckets from connection {name}'.format(name=name)
|
||||||
for bucket in conn.get_all_buckets():
|
for bucket in conn.get_all_buckets():
|
||||||
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:
|
nuke_bucket(bucket)
|
||||||
bucket.set_canned_acl('private')
|
|
||||||
# TODO: deleted_cnt and the while loop is a work around for rgw
|
|
||||||
# not sending the
|
|
||||||
deleted_cnt = 1
|
|
||||||
while deleted_cnt:
|
|
||||||
deleted_cnt = 0
|
|
||||||
for key in bucket.list():
|
|
||||||
print 'Cleaning bucket {bucket} key {key}'.format(
|
|
||||||
bucket=bucket,
|
|
||||||
key=key,
|
|
||||||
)
|
|
||||||
key.set_canned_acl('private')
|
|
||||||
key.delete()
|
|
||||||
deleted_cnt += 1
|
|
||||||
bucket.delete()
|
|
||||||
except boto.exception.S3ResponseError as e:
|
|
||||||
# TODO workaround for buggy rgw that fails to send
|
|
||||||
# error_code, remove
|
|
||||||
if (e.status == 403
|
|
||||||
and e.error_code is None
|
|
||||||
and e.body == ''):
|
|
||||||
e.error_code = 'AccessDenied'
|
|
||||||
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
|
|
||||||
|
|
||||||
print 'Done with cleanup of test buckets.'
|
print 'Done with cleanup of test buckets.'
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue